From 0d15a761181fded7a6512e4146e5156725fde1f7 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期六, 19 十一月 2022 09:00:00 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java |   55 ++++++++
 src/main/resources/mapper/PlanMapper.xml                           |   60 +++++++++
 src/main/java/com/zy/crm/manager/controller/PlanController.java    |   50 ++------
 src/main/webapp/static/js/plan/plan.js                             |  140 ++---------------------
 src/main/java/com/zy/crm/manager/service/PlanService.java          |    9 +
 src/main/java/com/zy/crm/manager/entity/Plan.java                  |   12 +-
 src/main/java/com/zy/crm/manager/mapper/PlanMapper.java            |   12 +
 7 files changed, 161 insertions(+), 177 deletions(-)

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 29631d1..2936d2e 100644
--- a/src/main/java/com/zy/crm/manager/controller/PlanController.java
+++ b/src/main/java/com/zy/crm/manager/controller/PlanController.java
@@ -7,7 +7,6 @@
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
-import com.core.common.DateUtils;
 import com.core.common.R;
 import com.core.domain.KeyValueVo;
 import com.zy.crm.common.web.BaseController;
@@ -33,33 +32,19 @@
         return R.ok(planService.selectById(String.valueOf(id)));
     }
 
-    @RequestMapping(value = "/plan/list/auth")
+    @RequestMapping(value = "/plan/page/auth")
     @ManagerAuth
-    public R list(@RequestParam(defaultValue = "1")Integer curr,
-                  @RequestParam(defaultValue = "10")Integer limit,
-                  @RequestParam(required = false)String orderByField,
-                  @RequestParam(required = false)String orderByType,
-                  @RequestParam(required = false)String condition,
-                  @RequestParam Map<String, Object> param){
-        EntityWrapper<Plan> wrapper = new EntityWrapper<>();
-        excludeTrash(param);
-        convert(param, wrapper);
-        allLike(Plan.class, param.keySet(), wrapper, condition);
-        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
-        return R.ok(planService.selectPage(new Page<>(curr, limit), wrapper));
-    }
-
-    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
-        for (Map.Entry<String, Object> entry : map.entrySet()){
-            String val = String.valueOf(entry.getValue());
-            if (val.contains(RANGE_TIME_LINK)){
-                String[] dates = val.split(RANGE_TIME_LINK);
-                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
-                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
-            } else {
-                wrapper.like(entry.getKey(), val);
-            }
-        }
+    public R page(@RequestParam(defaultValue = "1") Integer curr,
+                  @RequestParam(defaultValue = "10") Integer limit,
+                  @RequestParam(required = false) String condition,
+                  @RequestParam(required = false, value = "dept_id") Long deptId,
+                  @RequestParam(required = false, value = "user_id") Long userId) {
+        return R.ok(planService.getPage(new Page<>(curr, limit)
+                , getHostId()
+                , deptId == null ? null : String.valueOf(deptId)
+                , userId == null ? getUserId() : userId
+                , condition)
+        );
     }
 
     @RequestMapping(value = "/plan/add/auth")
@@ -86,17 +71,6 @@
             planService.deleteById(id);
         }
         return R.ok();
-    }
-
-    @RequestMapping(value = "/plan/export/auth")
-    @ManagerAuth
-    public R export(@RequestBody JSONObject param){
-        EntityWrapper<Plan> wrapper = new EntityWrapper<>();
-        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
-        Map<String, Object> map = excludeTrash(param.getJSONObject("plan"));
-        convert(map, wrapper);
-        List<Plan> list = planService.selectList(wrapper);
-        return R.ok(exportSupport(list, fields));
     }
 
     @RequestMapping(value = "/planQuery/auth")
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 f73dec4..355652f 100644
--- a/src/main/java/com/zy/crm/manager/entity/Plan.java
+++ b/src/main/java/com/zy/crm/manager/entity/Plan.java
@@ -113,6 +113,12 @@
     private Integer beItem;
 
     /**
+     * 琛ㄥ崟鍐呭
+     */
+    @ApiModelProperty(value= "琛ㄥ崟鍐呭")
+    private String form;
+
+    /**
      * 瑙勫垝鍛�
      */
     @ApiModelProperty(value= "瑙勫垝鍛�")
@@ -125,12 +131,6 @@
     @TableField("finish_time")
     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     private Date finishTime;
-
-    /**
-     * 琛ㄥ崟鍐呭
-     */
-    @ApiModelProperty(value= "琛ㄥ崟鍐呭")
-    private String form;
 
     /**
      * 鏇存敼鏂规 1: 鏄�  0: 鍚�
diff --git a/src/main/java/com/zy/crm/manager/mapper/PlanMapper.java b/src/main/java/com/zy/crm/manager/mapper/PlanMapper.java
index bbd587a..9199dc0 100644
--- a/src/main/java/com/zy/crm/manager/mapper/PlanMapper.java
+++ b/src/main/java/com/zy/crm/manager/mapper/PlanMapper.java
@@ -1,12 +1,22 @@
 package com.zy.crm.manager.mapper;
 
-import com.zy.crm.manager.entity.Plan;
 import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.zy.crm.manager.entity.Plan;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
+
+import java.util.List;
 
 @Mapper
 @Repository
 public interface PlanMapper extends BaseMapper<Plan> {
 
+    Plan selectByUuid(@Param("hostId") Long hostId, @Param("uuid") String uuid);
+
+    Plan selectPlanByNewestUuid(@Param("hostId") Long hostId);
+
+    List<Plan> listByPage(Page<Plan> page, @Param("hostId")Long hostId, @Param("deptId") String deptId, @Param("userId") Long userId , @Param("condition") String condition);
+
 }
diff --git a/src/main/java/com/zy/crm/manager/service/PlanService.java b/src/main/java/com/zy/crm/manager/service/PlanService.java
index cf0f278..bb6ba37 100644
--- a/src/main/java/com/zy/crm/manager/service/PlanService.java
+++ b/src/main/java/com/zy/crm/manager/service/PlanService.java
@@ -1,8 +1,15 @@
 package com.zy.crm.manager.service;
 
-import com.zy.crm.manager.entity.Plan;
+import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.IService;
+import com.zy.crm.manager.entity.Plan;
 
 public interface PlanService extends IService<Plan> {
 
+    Plan selectByUuid(Long hostId, String uuid);
+
+    String getUuid(Long hostId);
+
+    Page<Plan> getPage(Page<Plan> page, Long hostId, String deptId, Long userId, String condition);
+
 }
diff --git a/src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java b/src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java
index d9cae79..b374ea7 100644
--- a/src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java
+++ b/src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java
@@ -1,12 +1,61 @@
 package com.zy.crm.manager.service.impl;
 
-import com.zy.crm.manager.mapper.PlanMapper;
-import com.zy.crm.manager.entity.Plan;
-import com.zy.crm.manager.service.PlanService;
+import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.core.common.Cools;
+import com.zy.crm.manager.entity.Plan;
+import com.zy.crm.manager.mapper.PlanMapper;
+import com.zy.crm.manager.service.PlanService;
 import org.springframework.stereotype.Service;
 
 @Service("planService")
 public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements PlanService {
 
+    @Override
+    public Plan selectByUuid(Long hostId, String uuid) {
+        return this.baseMapper.selectByUuid(hostId, uuid);
+    }
+
+    @Override
+    public String getUuid(Long hostId) {
+        String uuid = null;
+        int times = 0;
+        while (Cools.isEmpty(uuid)) {
+            if (times > 100) { break; }
+            String nextUuid = getNextUuid(hostId);
+            if (selectByUuid(hostId, nextUuid) == null) {
+                uuid = nextUuid;
+            }
+            times ++;
+        }
+        return uuid;
+    }
+
+    @Override
+    public Page<Plan> getPage(Page<Plan> page, Long hostId, String deptId, Long userId, String condition) {
+        return page.setRecords(baseMapper.listByPage(page, hostId, deptId, userId, condition));
+    }
+
+    private String getNextUuid(Long hostId) {
+        Plan plan = this.baseMapper.selectPlanByNewestUuid(hostId);
+        if (plan == null) {
+            return "0001";
+        }
+        return zerofill(String.valueOf(Integer.parseInt(plan.getUuid()) + 1), 4);
+    }
+
+    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();
+        }
+    }
+
 }
diff --git a/src/main/resources/mapper/PlanMapper.xml b/src/main/resources/mapper/PlanMapper.xml
index be12701..20b1160 100644
--- a/src/main/resources/mapper/PlanMapper.xml
+++ b/src/main/resources/mapper/PlanMapper.xml
@@ -16,9 +16,9 @@
         <result column="apple_time" property="appleTime" />
         <result column="plan_need" property="planNeed" />
         <result column="be_item" property="beItem" />
+        <result column="form" property="form" />
         <result column="planner" property="planner" />
         <result column="finish_time" property="finishTime" />
-        <result column="form" property="form" />
         <result column="change" property="change" />
         <result column="change_time" property="changeTime" />
         <result column="change_reason" property="changeReason" />
@@ -37,4 +37,62 @@
 
     </resultMap>
 
+    <select id="selectByUuid" resultMap="BaseResultMap">
+        select * from man_plan
+        where 1=1
+        and uuid = #{uuid}
+        <if test="hostId != null">
+            and host_id = #{hostId}
+        </if>
+    </select>
+
+    <select id="selectPlanByNewestUuid" resultMap="BaseResultMap">
+        select top 1 * from man_plan
+        where 1=1
+        <if test="hostId != null">
+            and host_id = #{hostId}
+        </if>
+        order by uuid + 0 desc
+    </select>
+
+    <select id="listByPage" resultMap="BaseResultMap">
+        SELECT
+        mp.*
+        FROM man_plan mp
+        LEFT JOIN sys_dept sd ON mp.dept_id = sd.id
+        WHERE 1=1
+        <choose>
+            <when test="deptId != null and deptId != ''">
+                AND (CHARINDEX(','+#{deptId}+',', ','+sd.path+',') > 0 OR sd.id = #{deptId})
+            </when>
+            <otherwise>
+                and
+                (
+                user_id = #{userId}
+                or
+                mp.id in
+                (
+                    select
+                    order_id
+                    from man_order_foll
+                    where 1=1
+                    and user_id = #{userId}
+                    )
+                )
+            </otherwise>
+        </choose>
+        <if test="hostId != null">
+            and mp.host_id = #{hostId}
+        </if>
+        <if test="condition != null and condition != ''">
+            and (
+            mp.uuid like concat('%',#{condition},'%')
+            or mp.name like concat('%',#{condition},'%')
+            or mp.planner like concat('%',#{condition},'%')
+            or mp.remarks like concat('%',#{condition},'%')
+            )
+        </if>
+        ORDER BY mp.create_time DESC
+    </select>
+
 </mapper>
diff --git a/src/main/webapp/static/js/plan/plan.js b/src/main/webapp/static/js/plan/plan.js
index 659d3ea..d0b73ea 100644
--- a/src/main/webapp/static/js/plan/plan.js
+++ b/src/main/webapp/static/js/plan/plan.js
@@ -18,7 +18,7 @@
     tableIns = table.render({
         elem: '#plan',
         headers: {token: localStorage.getItem('token')},
-        url: baseUrl+'/plan/list/auth',
+        url: baseUrl+'/plan/page/auth',
         page: true,
         limit: 15,
         limits: [15, 30, 50, 100, 200, 500],
@@ -27,17 +27,18 @@
         height: 'full-120',
         cols: [[
             {type: 'checkbox'}
-            ,{field: 'id', align: 'center',title: 'ID'}
-            ,{field: 'hostId$', align: 'center',title: '鎵�灞炲晢鎴�'}
-            ,{field: 'deptId$', align: 'center',title: '鎵�灞為儴闂�'}
-            ,{field: 'planType$', align: 'center',title: '涓氬姟绫诲瀷'}
+            // ,{field: 'id', align: 'center',title: 'ID'}
+            // ,{field: 'hostId$', align: 'center',title: '鎵�灞炲晢鎴�'}
             ,{field: 'userId$', align: 'center',title: '涓氬姟鍛�'}
+            ,{field: 'planType$', align: 'center',title: '涓氬姟绫诲瀷'}
+            ,{field: 'name', align: 'center',title: '鍞墠瑙勫垝鐢宠鍗曞悕绉�'}
+            ,{field: 'planNeed$', align: 'center',title: '鎵�闇�'}
+            ,{field: 'deptId$', align: 'center',title: '鎵�灞為儴闂�'}
             ,{field: 'orderId$', align: 'center',title: '璺熻釜椤圭洰'}
             ,{field: 'cstmrId$', align: 'center',title: '鐢叉柟鍗曚綅'}
             ,{field: 'uuid', align: 'center',title: '瑙勫垝鍗曚唬鍙�'}
-            ,{field: 'name', align: 'center',title: '瑙勫垝鍗曞悕绉�'}
             ,{field: 'appleTime$', align: 'center',title: '鐢宠鏃ユ湡'}
-            ,{field: 'planNeed$', align: 'center',title: '鏂规鎵�闇�'}
+
             ,{field: 'beItem$', align: 'center',title: '绔嬮」'}
             ,{field: 'planner', align: 'center',title: '瑙勫垝鍛�'}
             ,{field: 'finishTime$', align: 'center',title: '瀹屾垚鏃堕棿'}
@@ -47,13 +48,11 @@
             ,{field: 'changeReason', align: 'center',title: '鏇存敼鏂规鍘熷洜'}
             ,{field: 'planBonus', align: 'center',title: '瑙勬牸濂栭噾'}
             ,{field: 'planLeaderBonus', align: 'center',title: '瑙勬牸缁勯暱濂栭噾'}
-            ,{field: 'files', align: 'center',title: '闄勪欢'}
-            ,{field: 'settle$', align: 'center',title: '杩涘害'}
-            ,{field: 'settleMsg', align: 'center',title: '瀹℃牳杩涘害'}
-            ,{field: 'comment', align: 'center',title: '璇勮'}
-            ,{field: 'status$', align: 'center',title: '鐘舵��'}
-            ,{field: 'createBy$', align: 'center',title: '娣诲姞浜哄憳'}
-            ,{field: 'createTime$', align: 'center',title: '娣诲姞鏃堕棿'}
+            // ,{field: 'files', align: 'center',title: '闄勪欢'}
+            // ,{field: 'settle$', align: 'center',title: '杩涘害'}
+            // ,{field: 'settleMsg', align: 'center',title: '瀹℃牳杩涘害'}
+            // ,{field: 'comment', align: 'center',title: '璇勮'}
+            // ,{field: 'status$', align: 'center',title: '鐘舵��'}
             ,{field: 'updateBy$', align: 'center',title: '淇敼浜哄憳'}
             ,{field: 'updateTime$', align: 'center',title: '淇敼鏃堕棿'}
             ,{field: 'memo', align: 'center',title: '娉ㄩ噴'}
@@ -280,34 +279,6 @@
     }
     layDateRender();
 
-    window.loadHostSel = function () {
-        return xmSelect.render({
-            el: '#hostXmlSel',
-            autoRow: true,
-            filterable: true,
-            remoteSearch: true,
-            radio: true,
-            remoteMethod: function (val, cb, show) {
-                $.ajax({
-                    url: baseUrl + "/host/all/get/kv",
-                    headers: {'token': localStorage.getItem('token')},
-                    data: {
-                        condition: val
-                    },
-                    method: 'POST',
-                    success: function (res) {
-                        if (res.code === 200) {
-                            cb(res.data)
-                        } else {
-                            cb([]);
-                            layer.msg(res.msg, {icon: 2});
-                        }
-                    }
-                });
-            }
-        });
-    }
-
     window.loadDeptSel = function () {
         return xmSelect.render({
             el: '#deptXmlSel',
@@ -346,62 +317,6 @@
             remoteMethod: function (val, cb, show) {
                 $.ajax({
                     url: baseUrl + "/planType/all/get/kv",
-                    headers: {'token': localStorage.getItem('token')},
-                    data: {
-                        condition: val
-                    },
-                    method: 'POST',
-                    success: function (res) {
-                        if (res.code === 200) {
-                            cb(res.data)
-                        } else {
-                            cb([]);
-                            layer.msg(res.msg, {icon: 2});
-                        }
-                    }
-                });
-            }
-        });
-    }
-
-    window.loadUserSel = function () {
-        return xmSelect.render({
-            el: '#userXmlSel',
-            autoRow: true,
-            filterable: true,
-            remoteSearch: true,
-            radio: true,
-            remoteMethod: function (val, cb, show) {
-                $.ajax({
-                    url: baseUrl + "/user/all/get/kv",
-                    headers: {'token': localStorage.getItem('token')},
-                    data: {
-                        condition: val
-                    },
-                    method: 'POST',
-                    success: function (res) {
-                        if (res.code === 200) {
-                            cb(res.data)
-                        } else {
-                            cb([]);
-                            layer.msg(res.msg, {icon: 2});
-                        }
-                    }
-                });
-            }
-        });
-    }
-
-    window.loadUserSel = function () {
-        return xmSelect.render({
-            el: '#userXmlSel',
-            autoRow: true,
-            filterable: true,
-            remoteSearch: true,
-            radio: true,
-            remoteMethod: function (val, cb, show) {
-                $.ajax({
-                    url: baseUrl + "/user/all/get/kv",
                     headers: {'token': localStorage.getItem('token')},
                     data: {
                         condition: val
@@ -503,35 +418,6 @@
             }
         });
     }
-
-    window.loadUserSel = function () {
-        return xmSelect.render({
-            el: '#userXmlSel',
-            autoRow: true,
-            filterable: true,
-            remoteSearch: true,
-            radio: true,
-            remoteMethod: function (val, cb, show) {
-                $.ajax({
-                    url: baseUrl + "/user/all/get/kv",
-                    headers: {'token': localStorage.getItem('token')},
-                    data: {
-                        condition: val
-                    },
-                    method: 'POST',
-                    success: function (res) {
-                        if (res.code === 200) {
-                            cb(res.data)
-                        } else {
-                            cb([]);
-                            layer.msg(res.msg, {icon: 2});
-                        }
-                    }
-                });
-            }
-        });
-    }
-
 
 
 });

--
Gitblit v1.9.1