Browse Source

导入指标调整

dev_shibei_match
jianjun 5 years ago
parent
commit
b21973d9e8
  1. 12
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
  2. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  3. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCodeFieldReServiceImpl.java
  4. 54
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java
  5. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/Pinyin4jUtil.java

12
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java

@ -1,16 +1,21 @@
package com.epmet.controller; package com.epmet.controller;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.dto.screen.form.IndexCalculateForm; import com.epmet.dto.screen.form.IndexCalculateForm;
import com.epmet.service.indexcal.CpcIndexCalculateService; import com.epmet.service.indexcal.CpcIndexCalculateService;
import com.epmet.service.screen.IndexCalculateService; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
/** /**
* 指标计算controller * 指标计算controller
* *
@ -50,8 +55,11 @@ public class IndexCalculateController {
* @return * @return
*/ */
@PostMapping("cpc") @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)); return new Result().ok(cpcIndexCalculateService.cpcIndexCalculate(formDTO));
} }

3
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()); String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(index.getIndexCode());
if (StringUtils.isBlank(fieldName)) {
continue;
}
//最小值key //最小值key
String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN); String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN);
//最大值key //最大值key

9
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.entity.screen.IndexCodeFieldReEntity;
import com.epmet.redis.IndexCodeFieldReRedis; import com.epmet.redis.IndexCodeFieldReRedis;
import com.epmet.service.indexcal.IndexCodeFieldReService; import com.epmet.service.indexcal.IndexCodeFieldReService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j
@Service @Service
public class IndexCodeFieldReServiceImpl implements IndexCodeFieldReService { public class IndexCodeFieldReServiceImpl implements IndexCodeFieldReService {
@Autowired @Autowired
@ -41,6 +44,10 @@ public class IndexCodeFieldReServiceImpl implements IndexCodeFieldReService {
if (CollectionUtils.isEmpty(indexCodeFieldReMap)) { if (CollectionUtils.isEmpty(indexCodeFieldReMap)) {
return null; return null;
} }
return indexCodeFieldReMap.get(indexCode); String fieldName = indexCodeFieldReMap.get(indexCode);
if (StringUtils.isEmpty(fieldName)){
log.error("indexCode:{} 在index_code_re表中不存在记录",indexCode);
}
return fieldName;
} }
} }

54
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; package com.epmet.service.screen.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.ConvertUtils; 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.IndexGroupEntity;
import com.epmet.entity.screen.IndexGroupTemplateEntity; import com.epmet.entity.screen.IndexGroupTemplateEntity;
import com.epmet.service.screen.IndexGroupService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,6 +49,7 @@ import java.util.stream.Collectors;
* @author generator generator@elink-cn.com * @author generator generator@elink-cn.com
* @since v1.0.0 2020-08-19 * @since v1.0.0 2020-08-19
*/ */
@Slf4j
@Service @Service
public class IndexGroupServiceImpl extends BaseServiceImpl<IndexGroupDao, IndexGroupEntity> implements IndexGroupService { public class IndexGroupServiceImpl extends BaseServiceImpl<IndexGroupDao, IndexGroupEntity> implements IndexGroupService {
@Autowired @Autowired
@ -67,30 +70,49 @@ private IndexGroupTemplateDao indexGroupTemplateDao;
} }
Map<String, IndexGroupTemplateEntity> groupMap = groupTempList.stream().collect(Collectors.toMap(IndexGroupTemplateEntity::getId, o -> o)); Map<String, IndexGroupTemplateEntity> groupMap = groupTempList.stream().collect(Collectors.toMap(IndexGroupTemplateEntity::getId, o -> o));
Map<String,IndexGroupEntity> groupEntityMap = new HashMap<>(); Map<String,IndexGroupEntity> groupEntityMap = new HashMap<>();
Map<String,String> groupNewIdMap = new HashMap<>();
groupDetailTempList.forEach(groupDetailTemp->{ List<IndexGroupEntity> insertGroupList = new ArrayList<>();
String indexGroupId = groupDetailTemp.getIndexGroupId(); groupMap.forEach((oldGroupTempId,o)->{
IndexGroupTemplateEntity group = groupMap.get(indexGroupId); IndexGroupEntity newGroupEntity = ConvertUtils.sourceToTarget(o, IndexGroupEntity.class);
if (group == null){ String newGroupId = UniqueIdGenerator.generate();
System.out.println(JSON.toJSONString(groupDetailTemp)); 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); IndexGroupDetailEntity entity = ConvertUtils.sourceToTarget(groupDetailTemp, IndexGroupDetailEntity.class);
entity.setId(UniqueIdGenerator.generate()); 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); entity.setCustomerId(customerId);
indexGroupDetailDao.insert(entity); indexGroupDetailDao.insert(entity);
}); });
this.insertBatch(groupEntityMap.values(),10); this.insertBatch(insertGroupList,10);
/* List<IndexGroupEntity> groupEntityList = groupTempList.stream().map(groupTemp -> { /* List<IndexGroupEntity> groupEntityList = groupTempList.stream().map(groupTemp -> {

1
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[]{"qi"});
duoyinMap.put('参',new String[]{"can"}); duoyinMap.put('参',new String[]{"can"});
duoyinMap.put('均',new String[]{"jun"}); duoyinMap.put('均',new String[]{"jun"});
duoyinMap.put('会',new String[]{"hui"});
} }
/** /**

Loading…
Cancel
Save