|
@@ -0,0 +1,131 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.dto.AlgorithmDTO;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.BigDecimalUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.vo.AlgorithmVO;
|
|
|
+import com.diagbot.vo.QcResultAlgVO;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 评分算法
|
|
|
+ * @author: gaodm
|
|
|
+ * @time: 2020/4/14 9:52
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class AlgorithmFacade {
|
|
|
+ private final static List<Integer> types = Arrays.asList(0, 1, 2, 3);
|
|
|
+
|
|
|
+ //获取评分结果和等级
|
|
|
+ public AlgorithmDTO getAlgorithmRes(AlgorithmVO algorithmVO) {
|
|
|
+ AlgorithmDTO algorithmDTO = new AlgorithmDTO();
|
|
|
+ BigDecimal score = this.getScore(algorithmVO);
|
|
|
+ algorithmDTO.setScore(score);
|
|
|
+ algorithmDTO.setLevel(this.getLevel(score));
|
|
|
+ return algorithmDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ //评结果分数
|
|
|
+ private BigDecimal getScore(AlgorithmVO algorithmVO) {
|
|
|
+ if (!types.contains(algorithmVO.getType())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "操作类型只有0,1,2,3!");
|
|
|
+ }
|
|
|
+ //处理数据
|
|
|
+ dataDeal(algorithmVO);
|
|
|
+ BigDecimal res = cal(algorithmVO);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ //评等级
|
|
|
+ private String getLevel(BigDecimal score) {
|
|
|
+ String level = "甲";
|
|
|
+ //得分>90分为甲级
|
|
|
+ if (BigDecimalUtil.compareTo(score, new BigDecimal(90)) == 3) {
|
|
|
+ level = "甲";
|
|
|
+ }
|
|
|
+ //得分≤90分且得分>80分为乙级
|
|
|
+ if (BigDecimalUtil.compareTo(score, new BigDecimal(90)) == 5
|
|
|
+ && BigDecimalUtil.compareTo(score, new BigDecimal(80)) == 3) {
|
|
|
+ level = "乙";
|
|
|
+ }
|
|
|
+ //得分≤80分为丙级
|
|
|
+ if (BigDecimalUtil.compareTo(score, new BigDecimal(80)) == 5) {
|
|
|
+ level = "丙";
|
|
|
+ }
|
|
|
+
|
|
|
+ return level;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ private void dataDeal(AlgorithmVO algorithmVO) {
|
|
|
+ List<QcResultAlgVO> qcResultAlgVOList = algorithmVO.getQcResultAlgVOList();
|
|
|
+ //新增
|
|
|
+ if (algorithmVO.getType().equals(1)) {
|
|
|
+ if (null == algorithmVO.getOptResultAlgVO()) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "新增操作条目不能为空!");
|
|
|
+ }
|
|
|
+ //验证和操作数据
|
|
|
+ if (ListUtil.isNotEmpty(qcResultAlgVOList)) {
|
|
|
+ for (QcResultAlgVO qcResultAlgVO : qcResultAlgVOList) {
|
|
|
+ if (qcResultAlgVO.getCasesId().equals(algorithmVO.getOptResultAlgVO().getCasesId())
|
|
|
+ && qcResultAlgVO.getCasesEntryId().equals(algorithmVO.getOptResultAlgVO().getCasesEntryId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "不能重复加入已经评分的条目");
|
|
|
+ } else {
|
|
|
+ if (algorithmVO.getOptResultAlgVO().getCasesId().equals(qcResultAlgVO.getCasesId())) {
|
|
|
+ algorithmVO.getOptResultAlgVO().setCasesScore(qcResultAlgVO.getCasesScore());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qcResultAlgVOList.add(algorithmVO.getOptResultAlgVO());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //修改
|
|
|
+ if (algorithmVO.getType().equals(2)) {
|
|
|
+ if (null == algorithmVO.getOptResultAlgVO()) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "修改操作条目不能为空!");
|
|
|
+ }
|
|
|
+ //操作数据
|
|
|
+ if (ListUtil.isNotEmpty(qcResultAlgVOList)) {
|
|
|
+ for (QcResultAlgVO qcResultAlgVO : qcResultAlgVOList) {
|
|
|
+ if (qcResultAlgVO.getId().equals(algorithmVO.getOptResultAlgVO().getId())) {
|
|
|
+ qcResultAlgVOList.remove(qcResultAlgVO);
|
|
|
+ qcResultAlgVOList.add(algorithmVO.getOptResultAlgVO());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除
|
|
|
+ if (algorithmVO.getType().equals(3)) {
|
|
|
+ if (null == algorithmVO.getOptResultAlgVO()) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "删除操作条目不能为空!");
|
|
|
+ }
|
|
|
+ //操作数据
|
|
|
+ if (ListUtil.isNotEmpty(qcResultAlgVOList)) {
|
|
|
+ for (QcResultAlgVO qcResultAlgVO : qcResultAlgVOList) {
|
|
|
+ if (qcResultAlgVO.getId().equals(algorithmVO.getOptResultAlgVO().getId())) {
|
|
|
+ qcResultAlgVOList.remove(qcResultAlgVO);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算
|
|
|
+ private BigDecimal cal(AlgorithmVO algorithmVO) {
|
|
|
+ BigDecimal res = new BigDecimal(100);
|
|
|
+ Map<Long, BigDecimal> caseMap = new HashMap<>();
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|