Browse Source

Merge remote-tracking branch 'remotes/origin/dev_screen_data' into dev_temp

dev_shibei_match
jianjun 5 years ago
parent
commit
da406ec1e1
  1. 51
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
  2. 35
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java
  3. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java
  4. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java
  5. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
  6. 5
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml
  7. 28
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java
  8. 17
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/MathUtilTest.java

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

@ -115,6 +115,7 @@ public class IndexCalculateController {
/**
* 指标计算
*
* @param formDTO
*/
private void indexCalculate(CalculateCommonFormDTO formDTO) {
@ -137,29 +138,34 @@ public class IndexCalculateController {
/**
* 提交异步计算
*
* @param formDTO
* @return
*/
private void submitCalculate(CalculateCommonFormDTO formDTO) {
Future<?> future = singleThreadPool.submit(() -> {
long start = System.currentTimeMillis();
Boolean aBoolean = indexCalculateService.indexCalculate(formDTO);
if (aBoolean) {
log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", formDTO.getCustomerId(), (System.currentTimeMillis() - start) / 1000);
}
try {
long start = System.currentTimeMillis();
Boolean aBoolean = indexCalculateService.indexCalculate(formDTO);
if (aBoolean) {
log.error("客户Id:{},全部指标计算完成,总耗时:{}秒", formDTO.getCustomerId(), (System.currentTimeMillis() - start) / 1000);
}
redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId()));
futureMap.remove(formDTO.getCustomerId());
redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId()));
futureMap.remove(formDTO.getCustomerId());
//测试代码
//try {
// Thread.sleep(20000l);
// System.out.println(System.currentTimeMillis());
//} catch (InterruptedException e) {
// e.printStackTrace();
//}
//redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId()));
//futureMap.remove(formDTO.getCustomerId());
//测试代码
//try {
// Thread.sleep(20000l);
// System.out.println(System.currentTimeMillis());
//} catch (InterruptedException e) {
// e.printStackTrace();
//}
//redisUtils.delete(RedisKeys.getCustomerStatsCalFlag(formDTO.getCustomerId()));
//futureMap.remove(formDTO.getCustomerId());
} catch (Exception e) {
log.warn("submitCalculate exception", e);
}
});
futureMap.put(formDTO.getCustomerId(), future);
@ -172,6 +178,7 @@ public class IndexCalculateController {
/**
* 终止计算
*
* @param form
* @return
*/
@ -194,10 +201,14 @@ public class IndexCalculateController {
@PostMapping("reAll")
public Result<Boolean> calculateAll(@RequestBody CalculateCommonFormDTO formDTO) {
long start = System.currentTimeMillis();
Boolean aBoolean = indexCalculateService.indexCalculate(formDTO);
HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ",calculateAll全部指标计算完成,是否成功:" + aBoolean + ",总耗时:" + (System.currentTimeMillis() - start) / 1000 + "秒");
if (aBoolean) {
return new Result<Boolean>().ok(true);
try {
Boolean aBoolean = indexCalculateService.indexCalculate(formDTO);
HttpClientManager.getInstance().sendAlarmMsg(EnvEnum.getCurrentEnv().getName() + "客户Id:" + formDTO.getCustomerId() + ",calculateAll全部指标计算完成,是否成功:" + aBoolean + ",总耗时:" + (System.currentTimeMillis() - start) / 1000 + "秒");
if (aBoolean) {
return new Result<Boolean>().ok(true);
}
} catch (Exception e) {
return new Result<Boolean>().error(e.getMessage());
}
return new Result<Boolean>().error("指标计算失败");
}

35
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenCustomerAgencyDao.java

@ -34,8 +34,8 @@ import java.util.List;
@Mapper
public interface ScreenCustomerAgencyDao extends BaseDao<ScreenCustomerAgencyEntity> {
/**
*14组织层级
* 1) 根据CUSTOMER_ID 进行查询如果有数据则先进行物理删除, 一次删除1000条
* 14组织层级
* 1) 根据CUSTOMER_ID 进行查询如果有数据则先进行物理删除, 一次删除1000条
*
* @param customerId
* @return java.util.Integer
@ -46,24 +46,25 @@ public interface ScreenCustomerAgencyDao extends BaseDao<ScreenCustomerAgencyEnt
/**
* 14组织层级
* 2) 在批量新增
* 2) 在批量新增
*
* @param list
* @param customerId
* @Author zhangyong
* @Date 10:52 2020-08-18
**/
void batchInsertCustomerAgency(@Param("list") List<CustomerAgencyFormDTO> list, @Param("customerId")String customerId);
void batchInsertCustomerAgency(@Param("list") List<CustomerAgencyFormDTO> list, @Param("customerId") String customerId);
/**
* 返回当前客户下未匹配到的 社区级 组织信息
* @param customerId 客户id
* @param agencyIds 组织id集合
*
* @param customerId 客户id
* @param agencyIds 组织id集合
* @return java.util.List<com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity>
* @Author zhangyong
* @Date 14:38 2020-09-04
**/
List<ScreenCustomerAgencyEntity> selectListMismatcCommunityAgencyInfo(@Param("customerId")String customerId, @Param("agencyIds") String[] agencyIds);
List<ScreenCustomerAgencyEntity> selectListMismatcCommunityAgencyInfo(@Param("customerId") String customerId, @Param("agencyIds") String[] agencyIds);
/**
* 根据客户id查询区/街道 组织名称id
@ -73,24 +74,32 @@ public interface ScreenCustomerAgencyDao extends BaseDao<ScreenCustomerAgencyEnt
* @Author zhangyong
* @Date 16:57 2020-09-03
**/
List<ScreenCustomerAgencyEntity> selectListAgencyInfo(@Param("customerId")String customerId);
List<ScreenCustomerAgencyEntity> selectListAgencyInfo(@Param("customerId") String customerId);
/**
* @Description 根据agencyId查询上级组织Id
* @param agencyId
* @Description 根据agencyId查询上级组织Id
* @author zxc
* @date 2020/9/8 3:36 下午
*/
String selectPid(@Param("agencyId")String agencyId);
String selectPid(@Param("agencyId") String agencyId);
/**
* 返回当前客户下未匹配到的 街道区县级 组织信息
* @param customerId 客户id
* @param agencyIds 组织id集合
*
* @param customerId 客户id
* @param agencyIds 组织id集合
* @return java.util.List<com.epmet.entity.evaluationindex.screen.ScreenCustomerAgencyEntity>
* @Author zhangyong
* @Date 14:38 2020-09-04
**/
List<ScreenCustomerAgencyEntity> selectListMismatcStreetAndDistrictAgencyInfo(@Param("customerId")String customerId, @Param("agencyIds") String[] agencyIds);
List<ScreenCustomerAgencyEntity> selectListMismatcStreetAndDistrictAgencyInfo(@Param("customerId") String customerId, @Param("agencyIds") String[] agencyIds);
/**
* desc:获取客户的组织条数
*
* @param customerId
* @return
*/
int selectCountByCustomerId(@Param("customerId") String customerId);
}

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

@ -75,8 +75,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
//获取指标权重
List<IndexGroupDetailEntity> parentIndexDetails = indexGroupDetailService.getDetailListByParentCode(formDTO.getCustomerId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode());
if (CollectionUtils.isEmpty(parentIndexDetails)) {
log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId());
throw new RenException("客户【党员相关】指标权重信息不存在");
log.error("cpcIndexCalculate customerId:{} have not init index", formDTO.getCustomerId());
throw new RenException("客户Id:" + formDTO.getCustomerId() + "【党员相关】指标权重信息不存在");
}
Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o));
int pageNo = NumConstant.ONE;

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateServiceImpl.java

@ -6,6 +6,7 @@ import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.evaluationindex.screen.ScreenCustomerAgencyDao;
import com.epmet.dto.indexcal.CalculateCommonFormDTO;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.redis.IndexCalRedis;
@ -47,6 +48,8 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
private DeptScoreService deptScoreService;
@Autowired
private FactIndexCollectService factIndexCollectService;
@Autowired
private ScreenCustomerAgencyDao screenCustomerAgencyDao;
@Override
@ -91,6 +94,12 @@ public class IndexCalculateServiceImpl implements IndexCalculateService {
Boolean flag;
long start = System.currentTimeMillis();
try {
//校验是否含有组织数据
int agencyCount = screenCustomerAgencyDao.selectCountByCustomerId(formDTO.getCustomerId());
if (agencyCount < 1) {
log.info("客户id:{},组织结构数据缺失,请先上传后再计算", formDTO.getCustomerId());
throw new RenException("组织结构数据缺失,请先上传后再计算");
}
//计算党员相关的
try {

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java

@ -64,6 +64,10 @@ public class BatchScoreCalculator {
} else {
normalizeValue = scoreCalculator.normalize(getFinalSampleValue(vo.getSampleValue(), threshold));
}
//反正切函数 [-pi/2,pi/2]
if (idx.getScoreCalculator().getMaxValue().compareTo(idx.getScoreCalculator().getMinValue()) == 0) {
normalizeValue = new BigDecimal(Math.atan(new Double(vo.getSampleValue().toString())) / Math.PI * 100).setScale(6, RoundingMode.HALF_UP);
}
BigDecimal score = normalizeValue.multiply(weight).setScale(6, RoundingMode.HALF_UP);
CalculateResult result = scoreCountOfSamples.get(sampleId);

5
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenCustomerAgencyDao.xml

@ -128,4 +128,9 @@
</foreach>
</if>
</select>
<select id="selectCountByCustomerId" resultType="int">
select count(*) from screen_customer_agency
where DEL_FLAG = '0' and CUSTOMER_ID = #{customerId}
</select>
</mapper>

28
epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

@ -257,5 +257,33 @@ public class DemoScoreCal {
System.err.println("-----------------2222222222---------------");
}
@Test
public void testMath() {
// 每个指标需要单独的分支计算器,因为每个指标的最大最小值是不同的
ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(new BigDecimal(8), new BigDecimal(8), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator<Integer> sc2 = new BigDecimalScoreCalculator(new BigDecimal(10), new BigDecimal(10), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
List<SampleValue<Integer>> index1SampleValues = Arrays.asList(new SampleValue<>("id1", 4), new SampleValue<>("id2", 1), new SampleValue<>("id3", 8));
List<SampleValue<Integer>> index2SampleValues = Arrays.asList(new SampleValue<>("id1", 1), new SampleValue<>("id2", 8), new SampleValue<>("id3", 3));
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", "a:bbb2", index1SampleValues, new BigDecimal(10), new BigDecimal(1), false, sc1);
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", "a:bbb2", index2SampleValues, new BigDecimal(10), new BigDecimal(1), false, sc2);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
HashMap<String, CalculateResult> result = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS);
System.err.println("--------------------------------");
result.forEach((key, value) -> {
System.out.println(key.concat("的总得分为:") + value.getTotalScore());
//System.out.println(JSON.toJSONString(indexInputVOS));
value.getDetails().forEach(o -> System.out.println(JSON.toJSONString(o)));
});
System.err.println("--------------------------------");
}
}

17
epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/MathUtilTest.java

@ -0,0 +1,17 @@
package com.epmet.stats.test.normalizing;
public class MathUtilTest {
public static void main(String[] args) {
double tan = Math.atan(4);
double tan2 = Math.atan(1);
double tan3 = Math.atan(8);
double tan4 = Math.atan(3);
System.out.println((tan / Math.PI));
System.out.println((tan2 / Math.PI));
System.out.println((tan3 / Math.PI));
System.out.println((tan4 / Math.PI * 200));
}
}
Loading…
Cancel
Save