From 08db83852d3f00d1be9703e6adb4373395fe1466 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期四, 27 七月 2023 21:04:56 +0800
Subject: [PATCH] #售前规划申请单需求多选

---
 src/main/java/com/zy/crm/manager/controller/PlanController.java   |   36 +++++++
 src/main/webapp/static/js/plan/plan.js                            |   31 +++++-
 src/main/java/com/zy/crm/common/utils/SetOfUtils.java             |  154 ++++++++++++++++++++++++++++++
 src/main/java/com/zy/crm/manager/entity/Plan.java                 |   15 ++-
 src/main/java/com/zy/crm/common/entity/RouteCollectCountType.java |   42 ++++++++
 5 files changed, 268 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/zy/crm/common/entity/RouteCollectCountType.java b/src/main/java/com/zy/crm/common/entity/RouteCollectCountType.java
new file mode 100644
index 0000000..f7d3baf
--- /dev/null
+++ b/src/main/java/com/zy/crm/common/entity/RouteCollectCountType.java
@@ -0,0 +1,42 @@
+package com.zy.crm.common.entity;
+
+public enum RouteCollectCountType {
+
+    INTERSECTION(0, "浜ら泦"),   // 浜ら泦
+    DIFFERENCESET(1, "宸泦"),   // 宸泦
+    UNION(2, "骞堕泦"),  //骞堕泦
+    DEDUPLICATIONUNION(3, "鍘婚噸骞堕泦"),  //鍘婚噸骞堕泦
+    ;
+
+    public Integer id;
+    public String desc;
+    RouteCollectCountType(Integer id, String desc) {
+        this.id = id;
+        this.desc = desc;
+    }
+
+    public static RouteCollectCountType get(Short id) {
+        if (null == id) {
+            return null;
+        }
+        for (RouteCollectCountType type : RouteCollectCountType.values()) {
+            if (type.id.equals(id.intValue())) {
+                return type;
+            }
+        }
+        return null;
+    }
+
+    public static RouteCollectCountType get(RouteCollectCountType type) {
+        if (null == type) {
+            return null;
+        }
+        for (RouteCollectCountType crnLiftPosType : RouteCollectCountType.values()) {
+            if (crnLiftPosType == type) {
+                return crnLiftPosType;
+            }
+        }
+        return null;
+    }
+
+}
diff --git a/src/main/java/com/zy/crm/common/utils/SetOfUtils.java b/src/main/java/com/zy/crm/common/utils/SetOfUtils.java
new file mode 100644
index 0000000..217ee67
--- /dev/null
+++ b/src/main/java/com/zy/crm/common/utils/SetOfUtils.java
@@ -0,0 +1,154 @@
+package com.zy.crm.common.utils;
+
+
+import com.zy.crm.common.entity.RouteCollectCountType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Created by Monkey D. Luffy on 2023/7/18
+ */
+public class SetOfUtils {
+
+//    姝e簭
+    public static final List<Integer> TRACK_POSITION_POSITIVE_SEQUENCE = new ArrayList<Integer>() {{
+        add(1);add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);add(11);add(12);
+    }};
+//    鍙嶅簭
+    public static final List<Integer> TRACK_POSITION_REVERSE_SEQUENCE = new ArrayList<Integer>() {{
+        add(12);add(11);add(10);add(9);add(8);add(7);add(6);add(5);add(4);add(3);add(2);add(1);
+    }};
+
+    public static String zerofill(String msg, Integer count){
+        if (msg.length() == count){
+            return msg;
+        } else if (msg.length() > count){
+            return msg.substring(0, 16);
+        } else {
+            StringBuilder msgBuilder = new StringBuilder(msg);
+            for (int i = 0; i<count-msg.length(); i++){
+                msgBuilder.insert(0,"0");
+            }
+            return msgBuilder.toString();
+        }
+    }
+
+    // 鑾峰彇褰撳墠灏忚溅鏈璧扮殑璺嚎闆嗗悎
+    public static List<Integer> getRoute(Integer groupStart,Integer groupEnd){
+        boolean sign = groupStart < groupEnd;
+        List<Integer> result = new ArrayList<>();
+        List<Integer> groupRoute = null;
+        if (sign){
+            groupRoute = TRACK_POSITION_POSITIVE_SEQUENCE;
+        }else {
+            groupRoute = TRACK_POSITION_REVERSE_SEQUENCE;
+        }
+        if (groupRoute.contains(groupStart) && groupRoute.contains(groupEnd)) {
+            sign = false;
+            for (Integer route : groupRoute) {
+                if (route.equals(groupStart)){
+                    sign=true;
+                }
+                if (route.equals(groupEnd)){
+                    result.add(route);
+                    break;
+                }
+                if (sign){
+                    result.add(route);
+                }
+            }
+        }else {
+            return null;
+        }
+        return result;
+    }
+
+    //鏄惁鏈変氦闆�
+    public static boolean getRouteBoolean(List<Integer> groupCurrent,List<Integer> groupOther){
+        for (Integer positionCurrent : groupCurrent){
+            for (Integer positionOther : groupOther){
+                if (positionCurrent.equals(positionOther)){
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    //闆嗗悎杩愮畻
+    public static List<Integer> getRouteIntersection(List<Integer> groupCurrent, List<Integer> groupOther, RouteCollectCountType routeCollectCountType){
+        switch (routeCollectCountType){
+            case INTERSECTION:
+                //浜ら泦
+                return groupCurrent.stream().filter(item -> groupOther.contains(item)).collect(toList());
+            case DIFFERENCESET:
+                //宸泦
+                return groupCurrent.stream().filter(item -> !groupOther.contains(item)).collect(toList());
+            case UNION:
+                //骞堕泦
+                groupCurrent.addAll(groupOther);
+                return groupCurrent;
+            case DEDUPLICATIONUNION:
+                //鍘婚噸骞堕泦
+                groupCurrent.addAll(groupOther);
+                return groupCurrent.stream().distinct().collect(toList());
+            default:
+                return null;
+        }
+    }
+
+    //闆嗗悎杩愮畻
+    public static List<String> getRouteIntersectionString(List<String> groupCurrent, List<String> groupOther, RouteCollectCountType routeCollectCountType){
+        switch (routeCollectCountType){
+            case INTERSECTION:
+                //浜ら泦
+                List<String> intersection = groupCurrent.stream().filter(item -> groupOther.contains(item)).collect(toList());
+                return intersection;
+            case DIFFERENCESET:
+                //宸泦
+                List<String> reduce1 = groupCurrent.stream().filter(item -> !groupOther.contains(item)).collect(toList());
+                return reduce1;
+            case UNION:
+                //骞堕泦
+                List<String> listAll = groupCurrent.parallelStream().collect(toList());
+                List<String> listAll2 = groupOther.parallelStream().collect(toList());
+                listAll.addAll(listAll2);
+                return listAll;
+            case DEDUPLICATIONUNION:
+                //鍘婚噸骞堕泦
+                List<String> listAll1 = groupCurrent.parallelStream().collect(toList());
+                List<String> listAll21 = groupOther.parallelStream().collect(toList());
+                listAll1.addAll(listAll21);
+                List<String> listAllDistinct = listAll1.stream().distinct().collect(toList());
+                return listAllDistinct;
+            default:
+                return null;
+        }
+    }
+
+    public static void main(String[] arge){
+        List<Integer> routeCurrent = getRoute(2, 9);  //鑾峰彇褰撳墠灏忚溅璺緞
+        List<Integer> routeOther = getRoute(12, 5);  //鑾峰彇鍏跺畠灏忚溅璺緞
+        System.out.println("褰撳墠灏忚溅璺緞:\t"+routeCurrent);
+        System.out.println("鍏跺畠灏忚溅璺緞:\t"+routeOther);
+
+        boolean routeBoolean = getRouteBoolean(routeCurrent, routeOther);  //鏄惁鏈変氦闆�
+        System.out.println("鏄惁鏈変氦闆�:\t"+routeBoolean);
+
+        List<Integer> routeIntersection = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.INTERSECTION);//浜ら泦
+        System.out.println("璺緞浜ら泦锛歕t"+routeIntersection);
+
+        List<Integer> routeIntersection1 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.DIFFERENCESET);//宸泦
+        System.out.println("璺緞宸泦锛歕t"+routeIntersection1);
+
+        List<Integer> routeIntersection2 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.UNION);//骞堕泦
+        System.out.println("璺緞骞堕泦锛歕t"+routeIntersection2);
+
+        List<Integer> routeIntersection3 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.DEDUPLICATIONUNION);//鍘婚噸骞堕泦
+        System.out.println("璺緞鍘婚噸骞堕泦锛歕t"+routeIntersection3);
+    }
+
+}
diff --git a/src/main/java/com/zy/crm/manager/controller/PlanController.java b/src/main/java/com/zy/crm/manager/controller/PlanController.java
index 859bd71..c3dc7a5 100644
--- a/src/main/java/com/zy/crm/manager/controller/PlanController.java
+++ b/src/main/java/com/zy/crm/manager/controller/PlanController.java
@@ -12,7 +12,9 @@
 import com.core.common.R;
 import com.core.domain.KeyValueVo;
 import com.core.exception.CoolException;
+import com.zy.crm.common.entity.RouteCollectCountType;
 import com.zy.crm.common.model.SettleDto;
+import com.zy.crm.common.utils.SetOfUtils;
 import com.zy.crm.common.web.BaseController;
 import com.zy.crm.manager.controller.result.FollowerTableVo;
 import com.zy.crm.manager.entity.Plan;
@@ -38,6 +40,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
+
+import static java.util.stream.Collectors.toList;
 
 @RestController
 public class PlanController extends BaseController {
@@ -145,11 +149,43 @@
 	@RequestMapping(value = "/plan/update/auth")
 	@ManagerAuth
     public R update(@RequestParam Map<String, Object> param){
+        String planNeed = null;
+        Integer id = null;
+        for (Map.Entry<String, Object> entry : param.entrySet()){
+            String val = String.valueOf(entry.getValue());
+            if (Cools.isEmpty(val)){
+                continue;
+            }
+            if (entry.getKey().equals("planNeed")){
+                planNeed = val;
+            }
+            if (entry.getKey().equals("id")){
+                try{
+                    id = Integer.parseInt(val);
+                }catch (Exception e){
+                    return R.error();
+                }
+            }
+        }
         if (Cools.isEmpty(param) || Cools.isEmpty(param.get("id"))){
             return R.error();
         }
+        List<String> planNeedbs = new ArrayList<>(Arrays.asList(planNeed.split("-")));
+        if (planNeedbs.get(0).equals("[object Object]")){
+            planNeedbs.remove(0);
+            Plan plan1 = planService.selectById(id);
+            List<String> planNeedas = Arrays.asList(plan1.getPlanNeed().split("-"));
+            List<String> routeIntersectionString = SetOfUtils.getRouteIntersectionString(planNeedas, planNeedbs, RouteCollectCountType.DEDUPLICATIONUNION);
+            planNeed="";
+            for (String planNeedss:routeIntersectionString){
+                planNeed=planNeed==""? planNeedss:planNeed + "-" + planNeedss;
+            }
+        }
+
+
         // pre
         Plan plan = JSON.parseObject(JSON.toJSONString(param), Plan.class);
+        plan.setPlanNeed(planNeed);
         param.entrySet().removeIf(next -> this.fields.contains(next.getKey()));
         plan.setUpdateBy(getUserId());
         plan.setUpdateTime(new Date());
diff --git a/src/main/java/com/zy/crm/manager/entity/Plan.java b/src/main/java/com/zy/crm/manager/entity/Plan.java
index 0514720..25e5a1c 100644
--- a/src/main/java/com/zy/crm/manager/entity/Plan.java
+++ b/src/main/java/com/zy/crm/manager/entity/Plan.java
@@ -104,7 +104,7 @@
      */
     @ApiModelProperty(value= "鏂规鎵�闇�")
     @TableField("plan_need")
-    private Long planNeed;
+    private String planNeed;
 
     /**
      * 绔嬮」 1: 鏄�  0: 鍚�
@@ -299,11 +299,16 @@
 
     public String getPlanNeed$(){
         PlanNeedService service = SpringUtils.getBean(PlanNeedService.class);
-        PlanNeed planNeed = service.selectById(this.planNeed);
-        if (!Cools.isEmpty(planNeed)){
-            return String.valueOf(planNeed.getName());
+        String[] planNeeds = this.planNeed.split("-");
+        String name="";
+        for (String planNeeda : planNeeds){
+            PlanNeed planNeed = service.selectById(Integer.parseInt(planNeeda));
+            if (!Cools.isEmpty(planNeed)){
+//                return String.valueOf(planNeed.getName());
+                name = name+planNeed.getName()+";";
+            }
         }
-        return null;
+        return name;
     }
 
     public String getBeItem$(){
diff --git a/src/main/webapp/static/js/plan/plan.js b/src/main/webapp/static/js/plan/plan.js
index 5c60d0f..dc3df76 100644
--- a/src/main/webapp/static/js/plan/plan.js
+++ b/src/main/webapp/static/js/plan/plan.js
@@ -257,7 +257,12 @@
                                                         data.field.orderId = orderSel.getValue()[0] ? orderSel.getValue()[0].value : null;
                                                         data.field.cstmrId = cstmrSel.getValue()[0] ? cstmrSel.getValue()[0].value : null;
                                                         data.field.userId = userSel.getValue()[0] ? userSel.getValue()[0].value : null;
-                                                        data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
+                                                        // data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
+                                                        var planNeedValue= planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
+                                                        for (var i=1;i<planNeedSel.getValue().length;i++){
+                                                            planNeedValue =planNeedSel.getValue()[i] ? planNeedValue+"-"+planNeedSel.getValue()[i].value : planNeedValue;
+                                                        }
+                                                        data.field.planNeed = planNeedValue;
 
                                                         delete data.field.select;delete data.field.planTypeName;
 
@@ -511,7 +516,20 @@
                             if (plan.orderId) { orderSel.setValue([{name: plan.orderId$, value: plan.orderId}]); }
                             if (plan.cstmrId) { cstmrSel.setValue([{name: plan.cstmrId$, value: plan.cstmrId}]); }
                             if (plan.userId) { userSel.setValue([{name: plan.userId$, value: plan.userId}]); }
-                            if (plan.planNeed) { planNeedSel.setValue([{name: plan.planNeed$, value: plan.planNeed}]); }
+                            // console.log(plan);
+                            // console.log(plan.planNeed);
+                            // console.log(plan.planNeed.split("-"));
+                            // console.log(plan.planNeed.split("-").length);
+                            let split = plan.planNeed.split("-");
+                            // console.log(split);
+                            // console.log(split.length);
+                            if (plan.planNeed) {
+                                var planNeedValue1=split[0];
+                                for (var i=1;i<split.length;i++){
+                                    planNeedValue1 = planNeedSel+"-" +split[i];
+                                }
+                                planNeedSel.setValue([{name: plan.planNeed$, value: planNeedValue1}]);
+                            }
                             layDateRender(plan);
                             plan['planTypeName'] = plan.planType$;
                             form.val('detail', plan);
@@ -519,8 +537,12 @@
                                 data.field.orderId = orderSel.getValue()[0] ? orderSel.getValue()[0].value : null;
                                 data.field.cstmrId = cstmrSel.getValue()[0] ? cstmrSel.getValue()[0].value : null;
                                 data.field.userId = userSel.getValue()[0] ? userSel.getValue()[0].value : null;
-                                data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
-
+                                // data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
+                                var planNeedValue= planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
+                                for (var i=1;i<planNeedSel.getValue().length;i++){
+                                    planNeedValue =planNeedSel.getValue()[i] ? planNeedValue+"-"+planNeedSel.getValue()[i].value : planNeedValue;
+                                }
+                                data.field.planNeed = planNeedValue;
                                 delete data.field.select;delete data.field.planTypeName;
 
                                 if (!data.field.orderId) {
@@ -725,7 +747,6 @@
             autoRow: true,
             filterable: true,
             remoteSearch: true,
-            radio: true,
             remoteMethod: function (val, cb, show) {
                 $.ajax({
                     url: baseUrl + "/planNeed/all/get/kv",

--
Gitblit v1.9.1