Browse Source

优化代码打印日志

dev_shibei_match
jianjun 5 years ago
parent
commit
a4a50b60a5
  1. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java
  2. 12
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  3. 49
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java
  4. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/redis/IndexCodeFieldReRedis.java

@ -51,4 +51,12 @@ public class IndexCodeFieldReRedis {
hashOperations.putAll(RedisKeys.getIndexCodeFieldReKey(), records); hashOperations.putAll(RedisKeys.getIndexCodeFieldReKey(), records);
redisTemplate.expire(RedisKeys.getIndexCodeFieldReKey(), 1, TimeUnit.DAYS); redisTemplate.expire(RedisKeys.getIndexCodeFieldReKey(), 1, TimeUnit.DAYS);
} }
/**
* desc:删除指标字段关系缓存
* @return
*/
public Boolean deleteIndexCodeFromRedis() {
return redisTemplate.delete(RedisKeys.getIndexCodeFieldReKey());
}
} }

12
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java

@ -1,5 +1,6 @@
package com.epmet.service.indexcal.impl; package com.epmet.service.indexcal.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
@ -104,17 +105,18 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
Map<String, String> indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap(); Map<String, String> indexCodeFieldReList = indexCodeFieldReService.getIndexCodeFieldReMap();
if (CollectionUtils.isEmpty(indexCodeFieldReList)) { if (CollectionUtils.isEmpty(indexCodeFieldReList)) {
log.error("cpcIndexCalculate have any indexcodefieldre"); log.error("cpcIndexCalculate have any indexcodefieldre");
return; throw new RenException("指标code与字段关系记录不存在");
} }
//计算最大最小值 //计算最大最小值
Map<String, Object> minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId()); Map<String, Object> minAndMaxMap = factIndexPartyAblityCpcMonthlyDao.getExtremeValue(formDTO.getCustomerId());
if (CollectionUtils.isEmpty(minAndMaxMap)) { if (CollectionUtils.isEmpty(minAndMaxMap)) {
log.error("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId()); log.error("cpcIndexCalculate getExtremeValue customerId:{} have not any fact record", formDTO.getCustomerId());
return; throw new RenException("指标原始数据记录不存在");
} }
//指标集合 //指标集合
Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = getIndexDetailMap(formDTO); Map<String, List<IndexGroupDetailEntity>> groupIndexDetailsMap = getIndexDetailMap(formDTO);
if (groupIndexDetailsMap == null) { if (groupIndexDetailsMap == null) {
log.error("calculatePartScore");
return; return;
} }
@ -152,7 +154,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
IndexInputVO<BigDecimal> value = entry.getValue(); IndexInputVO<BigDecimal> value = entry.getValue();
String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode); String fieldName = indexCodeFieldReService.getFieldNameByIndexCode(indexCode);
if (StringUtils.isBlank(fieldName)) { if (StringUtils.isBlank(fieldName)) {
log.error("cpcIndexCalculate fieldName error"); log.error("calculateScore indexCode:{} get fieldName return blank", indexCode);
continue; continue;
} }
@ -179,9 +181,9 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
value.getIndexValueVOs().add(currentUserIndexValue); value.getIndexValueVOs().add(currentUserIndexValue);
} }
} }
log.warn("计算的参数:{}", indexMap); log.info("计算的参数:{}", JSON.toJSONString(indexMap));
HashMap<String, BigDecimal> result = calculateScore(indexMap); HashMap<String, BigDecimal> result = calculateScore(indexMap);
log.warn("计算的结果:{}", result); log.info("计算的结果:{}", result);
//处理结果 //处理结果
saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result); saveCpcScore(formDTO, scoreEntityMap, parentIndexCode, result);

49
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateServiceImpl.java

@ -1,14 +1,15 @@
package com.epmet.service.screen.impl; package com.epmet.service.screen.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao;
import com.epmet.dao.screen.IndexGroupDao;
import com.epmet.dao.screen.IndexGroupDetailDao;
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.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.redis.IndexCodeFieldReRedis;
import com.epmet.service.indexcal.CpcIndexCalculateService;
import com.epmet.service.indexcal.GridCorreLationService; import com.epmet.service.indexcal.GridCorreLationService;
import com.epmet.service.screen.IndexCalculateCommunityService;
import com.epmet.service.screen.IndexCalculateService; import com.epmet.service.screen.IndexCalculateService;
import com.epmet.util.DimIdGenerator; import com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,16 +30,17 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
@Autowired @Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@Autowired @Autowired
private FactIndexPartyAblityCpcMonthlyDao factIndexPartyAblityCpcMonthlyDao;
@Autowired
private GridCorreLationService gridCorreLationService; private GridCorreLationService gridCorreLationService;
@Autowired @Autowired
private IndexGroupDao indexGroupDao; private CpcIndexCalculateService cpcIndexCalculateService;
@Autowired
private IndexCodeFieldReRedis indexCodeFieldReRedis;
@Autowired @Autowired
private IndexGroupDetailDao indexGroupDetailDao; private IndexCalculateCommunityService indexCalculateCommunityService;
@Override @Override
public Boolean indexCalculate(IndexCalculateForm formDTO) { public Boolean indexCalculate(IndexCalculateForm formDTO) {
try {
if (StringUtils.isBlank(formDTO.getMonthId())) { if (StringUtils.isBlank(formDTO.getMonthId())) {
//默认 当前月份-1 //默认 当前月份-1
formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1))); formDTO.setMonthId(DimIdGenerator.getMonthDimId(DateUtils.addDateMonths(new Date(), -1)));
@ -47,27 +49,46 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) { if (CollectionUtils.isEmpty(formDTO.getCustomerIds())) {
Result<List<String>> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds(); Result<List<String>> externalCustomerIdsResult = epmetCommonServiceOpenFeignClient.getExternalCustomerIds();
if (!externalCustomerIdsResult.success()) { if (!externalCustomerIdsResult.success()) {
log.error("cpcIndexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail"); log.error("indexCalculate epmetCommonServiceOpenFeignClient.getExternalCustomerIds return fail");
return false; return false;
} }
formDTO.setCustomerIds(externalCustomerIdsResult.getData()); formDTO.setCustomerIds(externalCustomerIdsResult.getData());
} }
formDTO.getCustomerIds().forEach(customerId -> { formDTO.getCustomerIds().forEach(customerId -> {
CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO(customerId, formDTO.getMonthId()); CalculateCommonFormDTO calculateCommonFormDTO = new CalculateCommonFormDTO(customerId, formDTO.getMonthId());
//计算党员 //计算党员相关的
Boolean flag = false;
try { try {
//Map<String, BigDecimal> list = factIndexPartyAblityCpcMonthlyDao.getCountByMonthId(customerId, formDTO.getMonthId(), (pageNo - 1) * pageSize, pageSize); CalculateCommonFormDTO param = new CalculateCommonFormDTO(customerId, formDTO.getMonthId());
flag = cpcIndexCalculateService.cpcIndexCalculate(param);
log.info("indexCalculate cpcIndexCalculate return result:{}", flag);
} catch (Exception e) { } catch (Exception e) {
log.error("indexCalculate cpcIndexCalculate exception", e);
} }
//计算网格 //计算网格
//TODO try {
gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO); flag = gridCorreLationService.calculateGridCorreLation(calculateCommonFormDTO);
log.info("indexCalculate calculateGridCorreLation return result:{}", flag);
} catch (Exception e) {
log.error("indexCalculate calculateGridCorreLation exception", e);
}
//计算社区 //计算社区
//TODO try {
indexCalculateCommunityService.calAll(customerId, formDTO.getMonthId());
log.info("indexCalculate calAll return result:{}", flag);
} catch (Exception e) {
log.error("indexCalculate calAll exception", e);
}
}); });
indexCodeFieldReRedis.deleteIndexCodeFromRedis();
} catch (Exception e) {
log.error("indexCalculate exception,param:{}", JSON.toJSONString(formDTO));
} finally {
//清除缓存
indexCodeFieldReRedis.deleteIndexCodeFromRedis();
}
return true; return true;
} }
} }

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java

@ -66,12 +66,18 @@ public class BigDecimalScoreCalculator extends ScoreCalculator {
@Override @Override
public BigDecimal getMaxFromSourceArray() { public BigDecimal getMaxFromSourceArray() {
if (this.sourceArrary == null){
return null;
}
BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary; BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary;
return intSourceArrary[intSourceArrary.length - 1]; return intSourceArrary[intSourceArrary.length - 1];
} }
@Override @Override
public BigDecimal getMinFromSourceArray() { public BigDecimal getMinFromSourceArray() {
if (this.sourceArrary == null){
return null;
}
BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary; BigDecimal[] intSourceArrary = (BigDecimal[]) this.sourceArrary;
return intSourceArrary[0]; return intSourceArrary[0];
} }

Loading…
Cancel
Save