From b21973d9e8be166a02c48238b8a9cf44e9c85dc7 Mon Sep 17 00:00:00 2001 From: jianjun Date: Wed, 2 Sep 2020 10:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=8C=87=E6=A0=87=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IndexCalculateController.java | 12 ++++- .../impl/CpcIndexCalculateServiceImpl.java | 3 ++ .../impl/IndexCodeFieldReServiceImpl.java | 9 +++- .../screen/impl/IndexGroupServiceImpl.java | 54 +++++++++++++------ .../java/com/epmet/util/Pinyin4jUtil.java | 1 + 5 files changed, 60 insertions(+), 19 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java index de9f746130..09276f3184 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java @@ -1,16 +1,21 @@ package com.epmet.controller; +import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.screen.form.IndexCalculateForm; import com.epmet.service.indexcal.CpcIndexCalculateService; import com.epmet.service.screen.IndexCalculateService; +import com.epmet.util.DimIdGenerator; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; + /** * 指标计算controller * @@ -50,8 +55,11 @@ public class IndexCalculateController { * @return */ @PostMapping("cpc") - public Result cpc(CalculateCommonFormDTO formDTO) { - + public Result cpc(@RequestBody CalculateCommonFormDTO formDTO) { + if (StringUtils.isBlank(formDTO.getMonthId())) { + //默认 当前月份-1 + formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); + } return new Result().ok(cpcIndexCalculateService.cpcIndexCalculate(formDTO)); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java index dabeade3f1..588882b83f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -228,6 +228,9 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { //获取指标对应的列名 String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode()); + if (StringUtils.isBlank(fieldName)) { + continue; + } //最小值key String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN); //最大值key diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCodeFieldReServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCodeFieldReServiceImpl.java index 94189a9c77..5d5e58920c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCodeFieldReServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCodeFieldReServiceImpl.java @@ -4,15 +4,18 @@ import com.epmet.dao.screen.IndexCodeFieldReDao; import com.epmet.entity.screen.IndexCodeFieldReEntity; import com.epmet.redis.IndexCodeFieldReRedis; import com.epmet.service.indexcal.IndexCodeFieldReService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +@Slf4j @Service public class IndexCodeFieldReServiceImpl implements IndexCodeFieldReService { @Autowired @@ -41,6 +44,10 @@ public class IndexCodeFieldReServiceImpl implements IndexCodeFieldReService { if (CollectionUtils.isEmpty(indexCodeFieldReMap)) { return null; } - return indexCodeFieldReMap.get(indexCode); + String fieldName = indexCodeFieldReMap.get(indexCode); + if (StringUtils.isEmpty(fieldName)){ + log.error("indexCode:{} 在index_code_re表中不存在记录",indexCode); + } + return fieldName; } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java index a575ed7b72..3d6e1d3289 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java @@ -17,7 +17,6 @@ package com.epmet.service.screen.impl; -import com.alibaba.fastjson.JSON; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.ConvertUtils; @@ -31,11 +30,14 @@ import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; import com.epmet.entity.screen.IndexGroupEntity; import com.epmet.entity.screen.IndexGroupTemplateEntity; import com.epmet.service.screen.IndexGroupService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -47,6 +49,7 @@ import java.util.stream.Collectors; * @author generator generator@elink-cn.com * @since v1.0.0 2020-08-19 */ +@Slf4j @Service public class IndexGroupServiceImpl extends BaseServiceImpl implements IndexGroupService { @Autowired @@ -67,30 +70,49 @@ private IndexGroupTemplateDao indexGroupTemplateDao; } Map groupMap = groupTempList.stream().collect(Collectors.toMap(IndexGroupTemplateEntity::getId, o -> o)); Map groupEntityMap = new HashMap<>(); + Map groupNewIdMap = new HashMap<>(); - groupDetailTempList.forEach(groupDetailTemp->{ - String indexGroupId = groupDetailTemp.getIndexGroupId(); - IndexGroupTemplateEntity group = groupMap.get(indexGroupId); - if (group == null){ - System.out.println(JSON.toJSONString(groupDetailTemp)); + List insertGroupList = new ArrayList<>(); + groupMap.forEach((oldGroupTempId,o)->{ + IndexGroupEntity newGroupEntity = ConvertUtils.sourceToTarget(o, IndexGroupEntity.class); + String newGroupId = UniqueIdGenerator.generate(); + newGroupEntity.setId(newGroupId); + newGroupEntity.setCustomerId(customerId); + String oldPid = newGroupEntity.getParentIndexGroupId(); + String newPid = groupNewIdMap.get(oldPid); + /*if (StringUtils.isBlank(newPid)){ + newPid = UniqueIdGenerator.generate(); + groupNewIdMap.put(oldPid,newPid); + }*/ + //newGroupEntity.setParentIndexGroupId(newPid); + groupNewIdMap.put(oldGroupTempId,newGroupId); + //groupEntityMap.put(newGroupId,newGroupEntity); + insertGroupList.add(newGroupEntity); + }); + insertGroupList.forEach(o-> { + String parentIndexGroupId = groupNewIdMap.get(o.getParentIndexGroupId()); + if (StringUtils.isBlank(parentIndexGroupId)){ + parentIndexGroupId = "0"; } + o.setParentIndexGroupId(parentIndexGroupId); + }); + groupDetailTempList.forEach(groupDetailTemp->{ + String oldIndexGroupId = groupDetailTemp.getIndexGroupId(); + System.out.println(oldIndexGroupId); - IndexGroupEntity groupEntity = groupEntityMap.get(indexGroupId); - if (groupEntity == null){ - groupEntity = ConvertUtils.sourceToTarget(group, IndexGroupEntity.class); - String groupId = UniqueIdGenerator.generate(); - groupEntity.setId(groupId); - groupEntity.setCustomerId(customerId); - groupEntityMap.put(indexGroupId,groupEntity); - } IndexGroupDetailEntity entity = ConvertUtils.sourceToTarget(groupDetailTemp, IndexGroupDetailEntity.class); entity.setId(UniqueIdGenerator.generate()); - entity.setIndexGroupId(groupEntity.getId()); + String newGroupId = groupNewIdMap.get(oldIndexGroupId); + if (StringUtils.isBlank(newGroupId)){ + log.error("新旧id映射关系有误"); + return; + } + entity.setIndexGroupId(newGroupId); entity.setCustomerId(customerId); indexGroupDetailDao.insert(entity); }); - this.insertBatch(groupEntityMap.values(),10); + this.insertBatch(insertGroupList,10); /* List groupEntityList = groupTempList.stream().map(groupTemp -> { diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java index 727de4bbeb..b3a9ac1760 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java @@ -29,6 +29,7 @@ public class Pinyin4jUtil { duoyinMap.put('期',new String[]{"qi"}); duoyinMap.put('参',new String[]{"can"}); duoyinMap.put('均',new String[]{"jun"}); + duoyinMap.put('会',new String[]{"hui"}); } /**