From cf757d7c54982301405b83ef18b1381672f69de1 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期日, 06 十月 2024 21:52:38 +0800 Subject: [PATCH] 指标值查询 --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemDerService.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java | 27 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemService.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java | 20 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetFieldDTO.java | 42 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dto/QuerySourceValueDTO.java | 24 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/AtomItemHandler.java | 39 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetService.java | 3 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/ind/IndItemApiImpl.java | 36 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemValueVO.java | 22 + iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/ind/IndItemValueDao.xml | 22 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java | 242 ++++++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/impl/IndItemValueServiceImpl.java | 21 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemAtomServiceImpl.java | 10 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/IndItemValueService.java | 7 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/DerItemHandler.java | 51 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetServiceImpl.java | 17 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemSaveReqVO.java | 39 - iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemCalService.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemAtomService.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndStatFuncEnum.java | 31 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeLimitEnum.java | 41 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemRespVO.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetFieldService.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/CalItemHandler.java | 178 +++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dao/IndItemValueDao.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemDerServiceImpl.java | 6 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/IndItemCollector.java | 84 ++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetFieldServiceImpl.java | 9 /dev/null | 42 -- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetDTO.java | 39 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/controller/admin/IndItemController.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVO.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemCalServiceImpl.java | 6 36 files changed, 987 insertions(+), 113 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/ind/IndItemApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/ind/IndItemApiImpl.java new file mode 100644 index 0000000..7bf2fb6 --- /dev/null +++ b/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); + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndStatFuncEnum.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndStatFuncEnum.java new file mode 100644 index 0000000..f4a2a0e --- /dev/null +++ b/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; + } +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeLimitEnum.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeLimitEnum.java new file mode 100644 index 0000000..001bb29 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeEnum.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeEnum.java deleted file mode 100644 index 004bb39..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.iailab.module.data.common.enums; - -/** - * @author PanZhibao - * @Description - * @createTime 2024年05月25日 - */ -public enum IndTimeRangeEnum { - - LAST_YEAR("LAST_YEAR", "LAST_YEAR"), - THIS_YEAR("THIS_YEAR", "THIS_YEAR"), - LAST_MONTH_12("LAST_MONTH_12", "LAST_MONTH_12"), - YESTERDAY("YESTERDAY", "YESTERDAY"), - TODAY("TODAY", "TODAY"), - LAST_DAY_7("LAST_DAY_7", "LAST_DAY_7"), - LAST_DAY_30("LAST_DAY_30", "LAST_DAY_30"); - - private String code; - - private String name; - - IndTimeRangeEnum(String code, String name) { - this.code = code; - this.name = name; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java index e90d204..34f7723 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java +++ b/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; + } } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/IndItemCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/IndItemCollector.java new file mode 100644 index 0000000..2abeda0 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/AtomItemHandler.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/AtomItemHandler.java new file mode 100644 index 0000000..76b80d4 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/CalItemHandler.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/CalItemHandler.java new file mode 100644 index 0000000..5775d02 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/DerItemHandler.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/handler/DerItemHandler.java new file mode 100644 index 0000000..404f4c5 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java new file mode 100644 index 0000000..54c1faa --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetDTO.java new file mode 100644 index 0000000..7394a8d --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetFieldDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/dto/IndDataSetFieldDTO.java new file mode 100644 index 0000000..6731eb7 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetFieldService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetFieldService.java index c57a331..4b2b0c0 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetFieldService.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetService.java index 0e443bd..bc1d9c9 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/IndDataSetService.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetFieldServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetFieldServiceImpl.java index 3d41248..474b0eb 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetFieldServiceImpl.java +++ b/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); + } } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetServiceImpl.java index 5abbbad..9036965 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/data/service/impl/IndDataSetServiceImpl.java +++ b/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; + } } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/controller/admin/IndItemController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/controller/admin/IndItemController.java index b2fd87d..15f37fe 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/controller/admin/IndItemController.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemAtomService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemAtomService.java index 4914761..c122533 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemAtomService.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemCalService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemCalService.java index 229ebad..6f99630 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemCalService.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemDerService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemDerService.java index 2b8e5d3..a38cdf3 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemDerService.java +++ b/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); } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemService.java index 78e600d..593bdcd 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/IndItemService.java +++ b/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); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemAtomServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemAtomServiceImpl.java index a444eb7..6566e74 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemAtomServiceImpl.java +++ b/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 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemCalServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemCalServiceImpl.java index e0149da..da7a480 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemCalServiceImpl.java +++ b/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 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemDerServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemDerServiceImpl.java index ea70a55..5e76dce 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemDerServiceImpl.java +++ b/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 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java index e0c6981..0408818 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java +++ b/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); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVo.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVO.java similarity index 91% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVo.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVO.java index e62a24e..0c04368 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemAtomVo.java +++ b/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 { /** * 主键 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVo.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVO.java similarity index 87% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVo.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVO.java index b6d62bd..801c517 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemCalVo.java +++ b/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 { /** * 主键 diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVo.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVO.java similarity index 93% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVo.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVO.java index 3e96667..af9424d 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemDerVo.java +++ b/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 { /** * 主键 */ diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemRespVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemRespVO.java index f93780e..acd8d65 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemRespVO.java +++ b/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; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemSaveReqVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemSaveReqVO.java index f8842d2..0658f90 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemSaveReqVO.java +++ b/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; } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemValueVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/vo/IndItemValueVO.java new file mode 100644 index 0000000..4562bd4 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dao/IndItemValueDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dao/IndItemValueDao.java index 3718045..678f7cc 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dao/IndItemValueDao.java +++ b/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); } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dto/QuerySourceValueDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/dto/QuerySourceValueDTO.java new file mode 100644 index 0000000..7a168f6 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/IndItemValueService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/IndItemValueService.java index b173334..621b442 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/IndItemValueService.java +++ b/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); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/impl/IndItemValueServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/impl/IndItemValueServiceImpl.java index 5efbb4c..9a9e4e5 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/value/service/impl/IndItemValueServiceImpl.java +++ b/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); + } } \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/ind/IndItemValueDao.xml b/iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/ind/IndItemValueDao.xml new file mode 100644 index 0000000..ec9a3eb --- /dev/null +++ b/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> \ No newline at end of file -- Gitblit v1.9.3