iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/ind/IndItemApiImpl.java
对比新文件 @@ -0,0 +1,36 @@ package com.iailab.module.data.api.ind; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO; import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; import com.iailab.module.data.ind.collection.IndItemCollector; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @RestController // 提供 RESTful API 接口,给 Feign 调用 @Validated public class IndItemApiImpl implements IndItemApi { @Autowired private IndItemCollector indItemCollector; public List<ApiIndItemValueDTO> queryIndItemDefaultValue(String itemNo){ List<IndItemValueVO> list = indItemCollector.queryValue(itemNo); return ConvertUtils.sourceToTarget(list, ApiIndItemValueDTO.class); } @Override public List<ApiIndItemValueDTO> queryIndItemHistoryValue(ApiIndItemQueryDTO dto) { List<IndItemValueVO> list = indItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd()); return ConvertUtils.sourceToTarget(list, ApiIndItemValueDTO.class); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndStatFuncEnum.java
对比新文件 @@ -0,0 +1,31 @@ package com.iailab.module.data.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; @Getter @AllArgsConstructor public enum IndStatFuncEnum { SUM("SUM", "求和"), COUNT("COUNT", "计数"), AVG("AVG", "平均值"), MAX("MAX", "最大值"), MIN("MIN", "最小值"); private String code; private String desc; public static IndStatFuncEnum getEumByCode(String code) { if (code == null) { return null; } for (IndStatFuncEnum statusEnum : IndStatFuncEnum.values()) { if (statusEnum.getCode().equals(code)) { return statusEnum; } } return null; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeLimitEnum.java
对比新文件 @@ -0,0 +1,41 @@ package com.iailab.module.data.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author PanZhibao * @Description * @createTime 2024年05月25日 */ @Getter @AllArgsConstructor public enum IndTimeLimitEnum { TODAY("TODAY", "今天"), YESTERDAY("YESTERDAY", "昨天"), LAST_DAY_7("LAST_DAY_7", "最近7天"), LAST_DAY_30("LAST_DAY_30", "最近30天"), THIS_MONTH("THIS_MONTH", "当前月"), LAST_MONTH_12("LAST_MONTH_12", "最近12个月"), THIS_YEAR_MONTH("THIS_YEAR_MONTH", "当年月份"), LAST_YEAR("LAST_YEAR", "去年"), THIS_YEAR("THIS_YEAR_MONTH", "今年"), CUSTOM("CUSTOM", "自定义"); private String code; private String desc; public static IndTimeLimitEnum getEumByCode(String code) { if (code == null) { return null; } for (IndTimeLimitEnum statusEnum : IndTimeLimitEnum.values()) { if (statusEnum.getCode().equals(code)) { return statusEnum; } } return null; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeEnum.java
文件已删除 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java
@@ -14,11 +14,25 @@ @AllArgsConstructor public enum ItemTypeEnum { ATOM("ATOM"), ATOM("ATOM", "原子指标"), DER("DER"), DER("DER", "派生指标"), CAL("CAL"); CAL("CAL", "复合指标"); private String code; private String desc; public static ItemTypeEnum getEumByCode(String code) { if (code == null) { return null; } for (ItemTypeEnum statusEnum : ItemTypeEnum.values()) { if (statusEnum.getCode().equals(code)) { return statusEnum; } } return null; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/IndItemCollector.java
对比新文件 @@ -0,0 +1,84 @@ package com.iailab.module.data.ind.collection; import com.iailab.module.data.common.enums.ItemTypeEnum; import com.iailab.module.data.ind.collection.handler.AtomItemHandler; import com.iailab.module.data.ind.collection.handler.CalItemHandler; import com.iailab.module.data.ind.collection.handler.DerItemHandler; import com.iailab.module.data.ind.item.entity.IndItemEntity; import com.iailab.module.data.ind.item.service.IndItemService; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Slf4j @Component public class IndItemCollector { @Autowired private IndItemService indItemService; @Autowired private AtomItemHandler atomItemHandler; @Autowired private DerItemHandler derItemHandler; @Autowired private CalItemHandler calItemHandler; public List<IndItemValueVO> queryValue(String itemNo) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); IndItemEntity indItem = indItemService.getInfoByNo(itemNo); if (indItem == null) { return result; } ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(indItem.getItemType()); switch (itemType) { case ATOM: result = atomItemHandler.queryValue(indItem.getId()); break; case DER: result = derItemHandler.queryValue(itemNo); break; case CAL: result = calItemHandler.queryValue(itemNo); break; default: break; } return result; } public List<IndItemValueVO> queryValue(String itemNo, Date startTime, Date endTime) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); IndItemEntity indItem = indItemService.getInfoByNo(itemNo); if (indItem == null) { return result; } ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(indItem.getItemType()); switch (itemType) { case ATOM: result = atomItemHandler.queryValue(indItem.getId()); break; case DER: result = derItemHandler.queryValue(itemNo, startTime, endTime); break; case CAL: result = calItemHandler.queryValue(itemNo, startTime, endTime); break; default: break; } return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/AtomItemHandler.java
对比新文件 @@ -0,0 +1,39 @@ package com.iailab.module.data.ind.collection.handler; import com.iailab.module.data.ind.collection.utils.IndSqlUtils; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import com.iailab.module.data.ind.value.service.IndItemValueService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Slf4j @Component public class AtomItemHandler { @Autowired private IndSqlUtils indSqlUtils; @Autowired private IndItemValueService indItemValueService; public List<IndItemValueVO> queryValue(String itemId) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); try { QuerySourceValueDTO queryDto = indSqlUtils.getAtomSql(itemId); return indItemValueService.getSourceValue(queryDto); } catch (Exception ex) { ex.printStackTrace(); } return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/CalItemHandler.java
对比新文件 @@ -0,0 +1,178 @@ package com.iailab.module.data.ind.collection.handler; import com.alibaba.cloud.commons.lang.StringUtils; import com.iailab.framework.common.constant.CommonConstant; import com.iailab.module.data.common.enums.ItemTypeEnum; import com.iailab.module.data.common.enums.JsErrorCode; import com.iailab.module.data.common.utils.JavaScriptHandler; import com.iailab.module.data.ind.item.entity.IndItemEntity; import com.iailab.module.data.ind.item.service.IndItemCalService; import com.iailab.module.data.ind.item.service.IndItemService; import com.iailab.module.data.ind.item.vo.IndItemCalVO; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.service.IndItemValueService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.*; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Slf4j @Component public class CalItemHandler { @Autowired private JavaScriptHandler javaScriptHandler; public static final String regex = "[+\\-\\*\\/\\(\\)\\&\\|\\>\\<]"; @Autowired private IndItemCalService indItemCalService; @Autowired private AtomItemHandler atomItemHandler; @Autowired private DerItemHandler derItemHandler; @Autowired private IndItemService indItemService; public List<IndItemValueVO> queryValue(String itemId) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); try { IndItemCalVO indItem = indItemCalService.getByItemId(itemId); String expression = indItem.getExpression(); if (StringUtils.isBlank(expression)) { return result; } String[] arr = expression.split(regex); int dataLength = 0; List<List<IndItemValueVO>> valueMix = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { String s = arr[i]; if (StringUtils.isBlank(s)) { continue; } IndItemEntity subItem = indItemService.getInfoByNo(s); ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(subItem.getItemType()); switch (itemType) { case ATOM: valueMix.add(atomItemHandler.queryValue(subItem.getId())); break; case DER: valueMix.add(derItemHandler.queryValue(subItem.getId())); break; default: break; } } dataLength = valueMix.get(0).size(); for (int i = 0; i < dataLength; i++) { Map<String, IndItemValueVO> dataMap = new HashMap<>(); for (int j = 0; j < valueMix.size(); j++) { IndItemValueVO valueDTO = valueMix.get(j).get(i); dataMap.put(valueDTO.getItemNo(), valueDTO); } IndItemValueVO itemValue = this.singleCompute(indItem, dataMap); result.add(itemValue); } } catch (Exception ex) { ex.printStackTrace(); } return result; } public List<IndItemValueVO> queryValue(String itemId, Date startTime, Date endTime) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); try { IndItemCalVO indItem = indItemCalService.getByItemId(itemId); String expression = indItem.getExpression(); if (StringUtils.isBlank(expression)) { return result; } String[] arr = expression.split(regex); int dataLength = 0; List<List<IndItemValueVO>> valueMix = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { String s = arr[i]; if (StringUtils.isBlank(s)) { continue; } IndItemEntity subItem = indItemService.getInfoByNo(s); ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(subItem.getItemType()); switch (itemType) { case ATOM: valueMix.add(atomItemHandler.queryValue(subItem.getId())); break; case DER: valueMix.add(derItemHandler.queryValue(subItem.getId(), startTime, endTime)); break; default: break; } } dataLength = valueMix.get(0).size(); for (int i = 0; i < dataLength; i++) { Map<String, IndItemValueVO> dataMap = new HashMap<>(); for (int j = 0; j < valueMix.size(); j++) { IndItemValueVO valueDTO = valueMix.get(j).get(i); dataMap.put(valueDTO.getItemNo(), valueDTO); } IndItemValueVO itemValue = this.singleCompute(indItem, dataMap); result.add(itemValue); } } catch (Exception ex) { ex.printStackTrace(); } return result; } private IndItemValueVO singleCompute(IndItemCalVO dto, Map<String, IndItemValueVO> dataMap) { IndItemValueVO resultDto = new IndItemValueVO(); String dataTime = ""; BigDecimal dataValue = CommonConstant.ZERO_VALUE; String expression = dto.getExpression(); String[] arr = expression.split(regex); for (int i = 0; i < arr.length; i++) { String s = arr[i]; if (StringUtils.isNotBlank(s) && dataMap.containsKey(s)) { dataTime = dataMap.get(s).getDataTime(); if (dataMap.get(s) == null || dataMap.get(s).getDataValue() == null) { resultDto.setDataTime(dataTime); return resultDto; } expression = expression.replace(s, dataMap.get(s).getDataValue().toString()); } } expression = expression.replace("&", "&&"); expression = expression.replace("|", "||"); expression = expression.replace("False", "false"); expression = expression.replace("True", "true"); log.info("ItemId=" + dto.getItemId() + ";expression=" + expression); String result = javaScriptHandler.eval(expression); log.info("result=" + result); if (result == null) { return null; } else if (result.contains(JsErrorCode.Infinity.name()) || result.contains(JsErrorCode.NaN.name())) { log.info("计算异常,使用默认值"); } else { dataValue = new BigDecimal(result); } resultDto.setDataTime(dataTime); resultDto.setDataValue(dataValue); return resultDto; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/DerItemHandler.java
对比新文件 @@ -0,0 +1,51 @@ package com.iailab.module.data.ind.collection.handler; import com.iailab.module.data.ind.collection.utils.IndSqlUtils; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import com.iailab.module.data.ind.value.service.IndItemValueService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Slf4j @Component public class DerItemHandler { @Autowired private IndSqlUtils indSqlUtils; @Autowired private IndItemValueService indItemValueService; public List<IndItemValueVO> queryValue(String itemId) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); try { QuerySourceValueDTO queryDto = indSqlUtils.getDerSql(itemId); return indItemValueService.getSourceValue(queryDto); } catch (Exception ex) { ex.printStackTrace(); } return result; } public List<IndItemValueVO> queryValue(String itemId, Date startTime, Date endTime) { List<IndItemValueVO> result = new ArrayList<IndItemValueVO>(); try { QuerySourceValueDTO queryDto = indSqlUtils.getDerSql(itemId, startTime, endTime); return indItemValueService.getSourceValue(queryDto); } catch (Exception ex) { ex.printStackTrace(); } return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java
对比新文件 @@ -0,0 +1,242 @@ package com.iailab.module.data.ind.collection.utils; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.data.common.enums.IndStatFuncEnum; import com.iailab.module.data.common.enums.IndTimeLimitEnum; import com.iailab.module.data.ind.data.dto.IndDataSetDTO; import com.iailab.module.data.ind.data.service.IndDataSetService; import com.iailab.module.data.ind.item.service.IndItemAtomService; import com.iailab.module.data.ind.item.service.IndItemDerService; import com.iailab.module.data.ind.item.vo.IndItemAtomVO; import com.iailab.module.data.ind.item.vo.IndItemDerVO; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Calendar; import java.util.Date; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Component public class IndSqlUtils { @Autowired private IndItemAtomService indItemAtomService; @Autowired private IndDataSetService indDataSetService; @Autowired private IndItemDerService indItemDerService; public final static String PATTERN_YEAR = "yyyy"; public final static String PATTERN_MON = "yyyy-MM"; public final static String PATTERN_DATE = "yyyy-MM-dd"; public QuerySourceValueDTO getAtomSql(String itemId) { QuerySourceValueDTO result = new QuerySourceValueDTO(); IndItemAtomVO indItem = indItemAtomService.getByItemId(itemId); if (indItem == null) { return result; } IndDataSetDTO dataSet = indDataSetService.getDet(indItem.getDataSet()); if (dataSet == null) { return result; } result.setDataSource(indItem.getDataSource()); StringBuilder selectSql = new StringBuilder(); IndStatFuncEnum statFun = IndStatFuncEnum.getEumByCode(indItem.getStatFunc()); switch (statFun) { case AVG: selectSql.append("AVG("); break; case COUNT: selectSql.append("COUNT("); break; case MAX: selectSql.append("MAX("); break; case MIN: selectSql.append("MIN("); break; case SUM: selectSql.append("SUM("); break; default: selectSql.append("("); break; } selectSql.append(indItem.getUsingField()); selectSql.append(") data_value"); result.setSelectSql(selectSql.toString()); result.setViewSql(dataSet.getQuerySql()); return result; } public QuerySourceValueDTO getDerSql(String itemId) { QuerySourceValueDTO result = getAtomSql(itemId); IndItemDerVO indItem = indItemDerService.getByItemId(itemId); if (indItem == null) { return result; } result = getAtomSql(indItem.getAtomItemId()); // 拼接SELECT StringBuilder selectSql = new StringBuilder(); selectSql.append(indItem.getDimension()); selectSql.append(", "); selectSql.append(result.getSelectSql()); selectSql.append(", "); selectSql.append(indItem.getTimeLabel()); selectSql.append(" data_time"); result.setSelectSql(selectSql.toString()); // 拼接WHERE StringBuilder whereSql = new StringBuilder(); whereSql.append(" "); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); IndTimeLimitEnum timeLimit = IndTimeLimitEnum.getEumByCode(indItem.getTimeLimit()); switch (timeLimit) { case TODAY: whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("'"); break; case YESTERDAY: calendar.add(Calendar.DAY_OF_YEAR, -1); whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("'"); break; case LAST_DAY_7: whereSql.append(indItem.getTimeLabel()); whereSql.append(" <= '"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("' AND >= '"); calendar.add(Calendar.DAY_OF_YEAR, -7); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("'"); break; case LAST_DAY_30: whereSql.append(indItem.getTimeLabel()); whereSql.append(" <= '"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("' AND >= '"); calendar.add(Calendar.DAY_OF_YEAR, -30); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE)); whereSql.append("'"); break; case THIS_MONTH: whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); whereSql.append("'"); break; case LAST_MONTH_12: whereSql.append(indItem.getTimeLabel()); whereSql.append(" <= '"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); whereSql.append("' AND >= '"); calendar.add(Calendar.MONTH, -12); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); whereSql.append("'"); break; case THIS_YEAR_MONTH: calendar.set(Calendar.MONTH, 11); whereSql.append(" <= '"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); whereSql.append("' AND >= '"); calendar.set(Calendar.MONTH, 0); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); whereSql.append("'"); break; case LAST_YEAR: calendar.add(Calendar.YEAR, -1); whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_YEAR)); whereSql.append("'"); break; case THIS_YEAR: whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_YEAR)); whereSql.append("'"); break; case CUSTOM: whereSql.append(" <= '"); whereSql.append(DateUtils.format(indItem.getTimeEnd(), PATTERN_MON)); whereSql.append("' AND >= '"); whereSql.append(DateUtils.format(indItem.getTimeStart(), PATTERN_MON)); whereSql.append("'"); break; default: break; } result.setWhereSql(whereSql.toString()); // 拼接GROUP StringBuilder groupSql = new StringBuilder(); groupSql.append(" GROUP BY "); groupSql.append(indItem.getDimension()); result.setGroupSql(groupSql.toString()); // 拼接ORDER StringBuilder orderBySql = new StringBuilder(); orderBySql.append(indItem.getTimeLabel()); result.setOrderBySql(orderBySql.toString()); return result; } public QuerySourceValueDTO getDerSql(String itemId, Date startTime, Date endTime) { QuerySourceValueDTO result = getAtomSql(itemId); IndItemDerVO indItem = indItemDerService.getByItemId(itemId); if (indItem == null) { return result; } result = getAtomSql(indItem.getAtomItemId()); // 拼接SELECT StringBuilder selectSql = new StringBuilder(); selectSql.append(indItem.getDimension()); selectSql.append(", "); selectSql.append(result.getSelectSql()); selectSql.append(", "); selectSql.append(indItem.getTimeLabel()); selectSql.append(" data_time"); result.setSelectSql(selectSql.toString()); // 拼接WHERE StringBuilder whereSql = new StringBuilder(); whereSql.append(" "); whereSql.append(indItem.getTimeLabel()); whereSql.append(" <= '"); whereSql.append(DateUtils.format(endTime, PATTERN_MON)); whereSql.append("' AND >= '"); whereSql.append(DateUtils.format(startTime, PATTERN_MON)); whereSql.append("'"); result.setWhereSql(whereSql.toString()); // 拼接GROUP StringBuilder groupSql = new StringBuilder(); groupSql.append(" GROUP BY "); groupSql.append(indItem.getDimension()); result.setGroupSql(groupSql.toString()); // 拼接ORDER StringBuilder orderBySql = new StringBuilder(); orderBySql.append(indItem.getTimeLabel()); result.setOrderBySql(orderBySql.toString()); return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetDTO.java
对比新文件 @@ -0,0 +1,39 @@ package com.iailab.module.data.ind.data.dto; import lombok.Data; import java.io.Serializable; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Data public class IndDataSetDTO implements Serializable { private static final long serialVersionUID = 1L; private String id; /** * 名称 */ private String name; /** * 数据源 */ private String dataSource; /** * 查询语句 */ private String querySql; /** * 字段 */ private List<IndDataSetFieldDTO> fieldList; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetFieldDTO.java
对比新文件 @@ -0,0 +1,42 @@ package com.iailab.module.data.ind.data.dto; import lombok.Data; import java.io.Serializable; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Data public class IndDataSetFieldDTO implements Serializable { private static final long serialVersionUID = 1L; private String id; /** * 数据集ID */ private String dataSetId; /** * 英文名 */ private String fieldCode; /** * 中文名 */ private String fieldName; /** * 数据类型 */ private String fieldType; /** * 排序 */ private Integer sort; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetFieldService.java
@@ -7,6 +7,8 @@ import com.iailab.module.data.ind.data.vo.IndDataSetFieldSaveReqVO; import com.iailab.module.data.ind.data.vo.IndDataSetPageReqVO; import java.util.List; /** * @author PanZhibao * @Description @@ -23,4 +25,6 @@ IndDataSetFieldEntity get(String id); void delete(String id); List<IndDataSetFieldEntity> list(String dataSetId); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetService.java
@@ -2,6 +2,7 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.BaseService; import com.iailab.module.data.ind.data.dto.IndDataSetDTO; import com.iailab.module.data.ind.data.entity.IndDataSetEntity; import com.iailab.module.data.ind.data.vo.IndDataSetPageReqVO; import com.iailab.module.data.ind.data.vo.IndDataSetSaveReqVO; @@ -26,4 +27,6 @@ void delete(String id); List<IndDataSetEntity> list(IndDataSetPageReqVO reqVO); IndDataSetDTO getDet(String id); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetFieldServiceImpl.java
@@ -1,5 +1,6 @@ package com.iailab.module.data.ind.data.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; @@ -10,6 +11,7 @@ import com.iailab.module.data.ind.data.vo.IndDataSetFieldSaveReqVO; import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; /** @@ -48,4 +50,11 @@ public void delete(String id) { baseDao.deleteById(id); } @Override public List<IndDataSetFieldEntity> list(String dataSetId) { QueryWrapper<IndDataSetFieldEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("data_set_id", dataSetId).orderByAsc("sort"); return baseDao.selectList(queryWrapper); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetServiceImpl.java
@@ -3,12 +3,17 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.data.ind.category.entity.IndItemCategoryEntity; import com.iailab.module.data.ind.data.dao.IndDataSetDao; import com.iailab.module.data.ind.data.dto.IndDataSetDTO; import com.iailab.module.data.ind.data.dto.IndDataSetFieldDTO; import com.iailab.module.data.ind.data.entity.IndDataSetEntity; import com.iailab.module.data.ind.data.service.IndDataSetFieldService; import com.iailab.module.data.ind.data.service.IndDataSetService; import com.iailab.module.data.ind.data.vo.IndDataSetPageReqVO; import com.iailab.module.data.ind.data.vo.IndDataSetSaveReqVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,6 +28,9 @@ */ @Service public class IndDataSetServiceImpl extends BaseServiceImpl<IndDataSetDao, IndDataSetEntity> implements IndDataSetService { @Autowired private IndDataSetFieldService indDataSetFieldService; @Override @@ -59,4 +67,13 @@ public void delete(String id) { baseDao.deleteById(id); } @Override public IndDataSetDTO getDet(String id) { IndDataSetDTO result = new IndDataSetDTO(); IndDataSetEntity dataSet = baseDao.selectById(id); result = ConvertUtils.sourceToTarget(dataSet, IndDataSetDTO.class); result.setFieldList(ConvertUtils.sourceToTarget(indDataSetFieldService.list(id), IndDataSetFieldDTO.class)); return result; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/controller/admin/IndItemController.java
@@ -95,11 +95,11 @@ if (ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())){ respVO.setAtomItem(indItemAtomService.getByItemId(entity.getId())); }else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())){ IndItemDerVo derItem = indItemDerService.getByItemId(entity.getId()); IndItemDerVO derItem = indItemDerService.getByItemId(entity.getId()); respVO.setDerItem(derItem); respVO.setAtomItem(indItemAtomService.get(derItem.getAtomItemId())); }else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())){ respVO.setCalItem(indItemCalService.getByItemId(entity.getId()) == null ? new IndItemCalVo() : indItemCalService.getByItemId(entity.getId())); respVO.setCalItem(indItemCalService.getByItemId(entity.getId()) == null ? new IndItemCalVO() : indItemCalService.getByItemId(entity.getId())); } return success(respVO); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemAtomService.java
@@ -2,7 +2,7 @@ import com.iailab.framework.common.service.BaseService; import com.iailab.module.data.ind.item.entity.IndItemAtomEntity; import com.iailab.module.data.ind.item.vo.IndItemAtomVo; import com.iailab.module.data.ind.item.vo.IndItemAtomVO; /** * @author PanZhibao @@ -11,9 +11,9 @@ */ public interface IndItemAtomService extends BaseService<IndItemAtomEntity> { IndItemAtomVo getByItemId(String itemId); IndItemAtomVO getByItemId(String itemId); IndItemAtomVo get(String id); IndItemAtomVO get(String id); void deleteByItemId(String itemId); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemCalService.java
@@ -2,7 +2,7 @@ import com.iailab.framework.common.service.BaseService; import com.iailab.module.data.ind.item.entity.IndItemCalEntity; import com.iailab.module.data.ind.item.vo.IndItemCalVo; import com.iailab.module.data.ind.item.vo.IndItemCalVO; /** * @author PanZhibao @@ -11,7 +11,7 @@ */ public interface IndItemCalService extends BaseService<IndItemCalEntity> { IndItemCalVo getByItemId(String itemId); IndItemCalVO getByItemId(String itemId); void deleteByItemId(String itemId); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemDerService.java
@@ -2,7 +2,7 @@ import com.iailab.framework.common.service.BaseService; import com.iailab.module.data.ind.item.entity.IndItemDerEntity; import com.iailab.module.data.ind.item.vo.IndItemDerVo; import com.iailab.module.data.ind.item.vo.IndItemDerVO; /** * @author PanZhibao @@ -11,7 +11,7 @@ */ public interface IndItemDerService extends BaseService<IndItemDerEntity> { IndItemDerVo getByItemId(String itemId); IndItemDerVO getByItemId(String itemId); void deleteByItemId(String itemId); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemService.java
@@ -24,6 +24,8 @@ IndItemEntity get(String id); IndItemEntity getInfoByNo(String no); void delete(String id); List<IndItemRespVO> getList(IndItemPageReqVO reqVO); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemAtomServiceImpl.java
@@ -6,7 +6,7 @@ import com.iailab.module.data.ind.item.dao.IndItemAtomDao; import com.iailab.module.data.ind.item.entity.IndItemAtomEntity; import com.iailab.module.data.ind.item.service.IndItemAtomService; import com.iailab.module.data.ind.item.vo.IndItemAtomVo; import com.iailab.module.data.ind.item.vo.IndItemAtomVO; import org.springframework.stereotype.Service; /** @@ -17,13 +17,13 @@ @Service public class IndItemAtomServiceImpl extends BaseServiceImpl<IndItemAtomDao, IndItemAtomEntity> implements IndItemAtomService { @Override public IndItemAtomVo getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemAtomEntity>().eq("item_id", itemId)), IndItemAtomVo.class); public IndItemAtomVO getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemAtomEntity>().eq("item_id", itemId)), IndItemAtomVO.class); } @Override public IndItemAtomVo get(String id) { return BeanUtils.toBean(baseDao.selectById(id), IndItemAtomVo.class); public IndItemAtomVO get(String id) { return BeanUtils.toBean(baseDao.selectById(id), IndItemAtomVO.class); } @Override iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemCalServiceImpl.java
@@ -6,7 +6,7 @@ import com.iailab.module.data.ind.item.dao.IndItemCalDao; import com.iailab.module.data.ind.item.entity.IndItemCalEntity; import com.iailab.module.data.ind.item.service.IndItemCalService; import com.iailab.module.data.ind.item.vo.IndItemCalVo; import com.iailab.module.data.ind.item.vo.IndItemCalVO; import org.springframework.stereotype.Service; /** @@ -17,8 +17,8 @@ @Service public class IndItemCalServiceImpl extends BaseServiceImpl<IndItemCalDao, IndItemCalEntity> implements IndItemCalService { @Override public IndItemCalVo getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemCalEntity>().eq("item_id", itemId)), IndItemCalVo.class); public IndItemCalVO getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemCalEntity>().eq("item_id", itemId)), IndItemCalVO.class); } @Override iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemDerServiceImpl.java
@@ -6,7 +6,7 @@ import com.iailab.module.data.ind.item.dao.IndItemDerDao; import com.iailab.module.data.ind.item.entity.IndItemDerEntity; import com.iailab.module.data.ind.item.service.IndItemDerService; import com.iailab.module.data.ind.item.vo.IndItemDerVo; import com.iailab.module.data.ind.item.vo.IndItemDerVO; import org.springframework.stereotype.Service; /** @@ -17,8 +17,8 @@ @Service public class IndItemDerServiceImpl extends BaseServiceImpl<IndItemDerDao, IndItemDerEntity> implements IndItemDerService { @Override public IndItemDerVo getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemDerEntity>().eq("item_id", itemId)), IndItemDerVo.class); public IndItemDerVO getByItemId(String itemId) { return BeanUtils.toBean(baseDao.selectOne(new QueryWrapper<IndItemDerEntity>().eq("item_id", itemId)), IndItemDerVO.class); } @Override iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java
@@ -1,6 +1,7 @@ package com.iailab.module.data.ind.item.service.impl; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; @@ -44,30 +45,31 @@ @Autowired private DaSequenceNumService daSequenceNumService; @Override public PageResult<IndItemEntity> page(IndItemPageReqVO reqVO) { return baseDao.selectPage(reqVO); } @Override @DSTransactional(rollbackFor= Exception.class) @DSTransactional(rollbackFor = Exception.class) public void create(IndItemSaveReqVO createReqVO) { IndItemEntity entity = BeanUtils.toBean(createReqVO, IndItemEntity.class); entity.setId(UUID.randomUUID().toString()); if(ItemTypeEnum.ATOM.getCode().equals(createReqVO.getItemType())){ if (ItemTypeEnum.ATOM.getCode().equals(createReqVO.getItemType())) { IndItemAtomEntity atomEntity = BeanUtils.toBean(createReqVO.getAtomItem(), IndItemAtomEntity.class); atomEntity.setId(UUID.randomUUID().toString()); atomEntity.setItemId(entity.getId()); indItemAtomService.insert(atomEntity); entity.setItemNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.IND_A.name())); }else if (ItemTypeEnum.DER.getCode().equals(createReqVO.getItemType())){ } else if (ItemTypeEnum.DER.getCode().equals(createReqVO.getItemType())) { IndItemDerEntity derEntity = BeanUtils.toBean(createReqVO.getDerItem(), IndItemDerEntity.class); derEntity.setId(UUID.randomUUID().toString()); derEntity.setItemId(entity.getId()); indItemDerServiceImpl.insert(derEntity); entity.setItemNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.IND_D.name())); }else if (ItemTypeEnum.CAL.getCode().equals(createReqVO.getItemType())){ } else if (ItemTypeEnum.CAL.getCode().equals(createReqVO.getItemType())) { IndItemCalEntity calEntity = BeanUtils.toBean(createReqVO.getCalItem(), IndItemCalEntity.class); calEntity.setId(UUID.randomUUID().toString()); calEntity.setItemId(entity.getId()); @@ -79,7 +81,7 @@ } @Override @DSTransactional(rollbackFor= Exception.class) @DSTransactional(rollbackFor = Exception.class) public void update(IndItemSaveReqVO updateReqVO) { IndItemEntity entity = BeanUtils.toBean(updateReqVO, IndItemEntity.class); entity.setUpdateTime(new Date()); @@ -92,14 +94,21 @@ } @Override @DSTransactional(rollbackFor= Exception.class) public IndItemEntity getInfoByNo(String no) { QueryWrapper<IndItemEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("item_no", no); return baseDao.selectOne(queryWrapper); } @Override @DSTransactional(rollbackFor = Exception.class) public void delete(String id) { IndItemEntity entity = get(id); if(ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())){ if (ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())) { indItemAtomService.deleteByItemId(id); }else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())){ } else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())) { indItemDerServiceImpl.deleteByItemId(id); }else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())){ } else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())) { indItemCalServiceImpl.deleteByItemId(id); } baseDao.deleteById(id); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVO.java
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVo.java 修改 @@ -12,7 +12,7 @@ * @createTime 2024年09月11日 */ @Data public class IndItemAtomVo implements Serializable { public class IndItemAtomVO implements Serializable { /** * 主键 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVO.java
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVo.java 修改 @@ -13,7 +13,7 @@ * @createTime 2024年09月11日 */ @Data public class IndItemCalVo implements Serializable { public class IndItemCalVO implements Serializable { /** * 主键 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVO.java
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVo.java 修改 @@ -13,7 +13,7 @@ * @createTime 2024年09月11日 */ @Data public class IndItemDerVo implements Serializable { public class IndItemDerVO implements Serializable { /** * 主键 */ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemRespVO.java
@@ -68,9 +68,9 @@ private String atomItemId; private IndItemAtomVo atomItem; private IndItemAtomVO atomItem; private IndItemDerVo derItem; private IndItemDerVO derItem; private IndItemCalVo calItem; private IndItemCalVO calItem; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemSaveReqVO.java
@@ -18,72 +18,45 @@ @Schema(description = "ID") private String id; /** * 指标编码 */ @Schema(description = "编码") private String itemNo; /** * 指标名称 */ @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "名称不能为空") private String itemName; /** * 指标类型 */ @Schema(description = "指标类型", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "指标类型不能为空") private String itemType; /** * 指标分类 */ @Schema(description = "指标分类", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "指标分类不能为空") private String itemCategory; /** * 转换系数 */ @Schema(description = "系数") private BigDecimal coefficient; /** * 指标精度 */ @Schema(description = "指标精度") private Integer precision; /** * 时间粒度 */ @Schema(description = "时间粒度") private String timeGranularity; /** * 数量单位 */ @Schema(description = "数量单位") private String unit; /** * 备注 */ @Schema(description = "备注") private String remark; /** * 状态 */ @Schema(description = "状态(0正常 1停用)") private Integer status; private IndItemAtomVo atomItem; @Schema(description = "原子指标") private IndItemAtomVO atomItem; private IndItemDerVo derItem; @Schema(description = "派生指标") private IndItemDerVO derItem; private IndItemCalVo calItem; @Schema(description = "计算指标") private IndItemCalVO calItem; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemValueVO.java
对比新文件 @@ -0,0 +1,22 @@ package com.iailab.module.data.ind.item.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.math.BigDecimal; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Schema(description = "数据平台 - ") @Data public class IndItemValueVO { private String itemNo; private String dataTime; private BigDecimal dataValue; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dao/IndItemValueDao.java
@@ -4,9 +4,13 @@ import com.iailab.framework.mybatis.core.mapper.BaseMapperX; import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; import com.iailab.framework.tenant.core.db.dynamic.TenantDS; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import com.iailab.module.data.ind.value.entity.IndItemValueEntity; import com.iailab.module.data.ind.value.vo.IndItemValuePageReqVO; import org.apache.ibatis.annotations.Mapper; import java.util.List; /** * @author PanZhibao @@ -24,4 +28,6 @@ .leIfPresent(IndItemValueEntity::getDataTime, reqVO.getEndTime()) .orderByDesc(IndItemValueEntity::getDataTime)); } List<IndItemValueVO> getSourceValue(QuerySourceValueDTO dto); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dto/QuerySourceValueDTO.java
对比新文件 @@ -0,0 +1,24 @@ package com.iailab.module.data.ind.value.dto; import lombok.Data; /** * @author PanZhibao * @Description * @createTime 2024年10月04日 */ @Data public class QuerySourceValueDTO { private String dataSource; private String selectSql; private String viewSql; private String whereSql; private String groupSql; private String orderBySql; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/IndItemValueService.java
@@ -2,9 +2,14 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.BaseService; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import com.iailab.module.data.ind.value.entity.IndItemValueEntity; import com.iailab.module.data.ind.value.vo.IndItemValuePageReqVO; import com.iailab.module.data.ind.value.vo.IndItemValueSaveReqVO; import java.util.List; import java.util.Map; /** * @author PanZhibao @@ -22,4 +27,6 @@ IndItemValueEntity get(String id); void delete(String id); List<IndItemValueVO> getSourceValue(QuerySourceValueDTO dto); } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/impl/IndItemValueServiceImpl.java
@@ -3,13 +3,18 @@ import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.data.ind.item.vo.IndItemValueVO; import com.iailab.module.data.ind.value.dao.IndItemValueDao; import com.iailab.module.data.ind.value.dto.QuerySourceValueDTO; import com.iailab.module.data.ind.value.entity.IndItemValueEntity; import com.iailab.module.data.ind.value.service.IndItemValueService; import com.iailab.module.data.ind.value.vo.IndItemValuePageReqVO; import com.iailab.module.data.ind.value.vo.IndItemValueSaveReqVO; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.UUID; /** @@ -47,4 +52,20 @@ public void delete(String id) { baseDao.deleteById(id); } /** * 根据配置的数据源动态查询 * @param dto * @return */ @Override public List<IndItemValueVO> getSourceValue(QuerySourceValueDTO dto) { if (StringUtils.isEmpty(dto.getDataSource())) { log.warn("数据源不能为空"); return null; } return baseDao.getSourceValue(dto); } } iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/ind/IndItemValueDao.xml
对比新文件 @@ -0,0 +1,22 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.iailab.module.data.ind.value.dao.IndItemValueDao"> <select id="getSourceValue" parameterType="map" resultType="com.iailab.module.data.ind.item.vo.IndItemValueVO"> select ${selectSql} from ( ${viewSql} ) ind_t <where> <if test="whereSql != null and whereSql != ''"> and ${whereSql} </if> </where> <if test="orderBySql != null and orderBySql != ''"> order by ${orderBySql} </if> </select> </mapper>