gaodm 5 năm trước cách đây
mục cha
commit
e5e589d91a

+ 20 - 0
src/main/java/com/diagbot/dto/AlgorithmDTO.java

@@ -0,0 +1,20 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/4/14 13:07
+ */
+@Getter
+@Setter
+public class AlgorithmDTO {
+    //得分
+    private BigDecimal score;
+    //等级
+    private String level;
+}

+ 131 - 0
src/main/java/com/diagbot/facade/AlgorithmFacade.java

@@ -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;
+    }
+}

+ 61 - 0
src/main/java/com/diagbot/util/BigDecimalUtil.java

@@ -0,0 +1,61 @@
+package com.diagbot.util;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description: 大数工具类
+ * @author: gaodm
+ * @time: 2020/4/14 10:21
+ */
+public class BigDecimalUtil {
+
+    public static int scale = 2;
+    public static int roundingMode = BigDecimal.ROUND_HALF_UP;
+
+    public static boolean isEquals(BigDecimal a, BigDecimal b, int scaleInt) {
+        return a.setScale(scaleInt, roundingMode).equals(
+                b.setScale(scaleInt, roundingMode)
+        );
+    }
+
+    public static boolean isEquals(BigDecimal a, BigDecimal b) {
+        if (a == null && b == null) {
+            return true;
+        }
+        if ((a == null && b != null) || (a != null && b == null)) {
+            return false;
+        }
+        return a.setScale(scale, roundingMode).equals(
+                b.setScale(scale, roundingMode)
+        );
+    }
+
+    public static Integer compareTo(BigDecimal a, BigDecimal b) {
+        Integer res = 1;
+        if (a.compareTo(b) == -1) {
+            res = 1;
+            //System.out.println("a小于b");
+        }
+
+        if (a.compareTo(b) == 0) {
+            res = 2;
+            //System.out.println("a等于b");
+        }
+
+        if (a.compareTo(b) == 1) {
+            res = 3;
+            //System.out.println("a大于b");
+        }
+
+        if (a.compareTo(b) > -1) {
+            res = 4;
+            //System.out.println("a大于等于b");
+        }
+
+        if (a.compareTo(b) < 1) {
+            res = 5;
+            //System.out.println("a小于等于b");
+        }
+        return res;
+    }
+}

+ 22 - 0
src/main/java/com/diagbot/vo/AlgorithmVO.java

@@ -0,0 +1,22 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/4/14 9:53
+ */
+@Getter
+@Setter
+public class AlgorithmVO {
+    //操作类型(0:基础评分,1:新增条目评分,2:删除条目,3:修改条目)
+    private Integer type;
+    //操作条目
+    private QcResultAlgVO optResultAlgVO;
+    //扣分条目
+    private List<QcResultAlgVO> qcResultAlgVOList;
+}

+ 28 - 0
src/main/java/com/diagbot/vo/QcResultAlgVO.java

@@ -0,0 +1,28 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/4/14 10:01
+ */
+@Getter
+@Setter
+public class QcResultAlgVO {
+    //结果明细ID
+    private Long id;
+    //模块ID
+    private Long casesId;
+    //模块分数
+    private BigDecimal casesScore;
+    //所属条目ID
+    private Long casesEntryId;
+    //条目分值
+    private BigDecimal score;
+    //单项否决(1-单项否决 0-非)
+    private Integer isReject;
+}