中扬CRM客户关系管理系统
#
luxiaotao1123
2022-09-16 48e6a7175d35994d54d2dd86d7ee12f3f0cc50f3
#
11个文件已修改
169 ■■■■ 已修改文件
src/main/java/com/zy/crm/common/utils/ListUtils.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/common/utils/TreeUtils.java 105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/controller/NodeController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/controller/TagController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/system/controller/DeptController.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/system/mapper/UserMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/system/service/UserService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/system/service/impl/UserServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserMapper.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/cstmr/cstmr.js 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/cstmr/cstmr.html 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/common/utils/ListUtils.java
@@ -9,7 +9,7 @@
 */
public class ListUtils {
    public static List<Map> deepCopy(List<Map> src) throws IOException, ClassNotFoundException {
    public static List<Map<String, Object>> deepCopy(List<Map<String, Object>> src) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);
@@ -17,7 +17,7 @@
        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        @SuppressWarnings("unchecked")
        List<Map> dest = (List<Map>) in.readObject();
        List<Map<String, Object>> dest = (List<Map<String, Object>>) in.readObject();
        return dest;
    }
src/main/java/com/zy/crm/common/utils/TreeUtils.java
@@ -2,15 +2,17 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.zy.crm.system.entity.Dept;
import com.zy.crm.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import com.zy.crm.manager.entity.Node;
import com.zy.crm.manager.entity.Tag;
import com.zy.crm.manager.service.NodeService;
import com.zy.crm.manager.service.TagService;
import com.zy.crm.system.entity.Dept;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.DeptService;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.*;
@@ -27,6 +29,8 @@
    private NodeService nodeService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private UserService userService;
    /******************************** 归类树 *********************************/
@@ -34,15 +38,15 @@
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="tagTree",key="#id")
    public ArrayList<Map> getTree(String id, Long hostId){
        ArrayList<Map> result = new ArrayList<>();
    public ArrayList<Map<String, Object>> getTree(String id, Long hostId){
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        Tag tag = tagService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", tag.getName());
        map.put("id", tag.getId());
        map.put("spread", true);
        List<Map> childrens = new ArrayList<>();
        List<Map<String, Object>> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealTag(tag, childrens, hostId);
        result.add(map);
@@ -54,7 +58,7 @@
    /**
     * 递归获取子节点数据
     */
    public void dealTag(Tag parent, List<Map> list, Long hostId) {
    public void dealTag(Tag parent, List<Map<String, Object>> list, Long hostId) {
        Wrapper<Tag> wrapper = new EntityWrapper<Tag>()
                .eq("parent_id", parent.getId())
                .eq("status", "1");
@@ -67,7 +71,7 @@
            map.put("title", tag.getName());
            map.put("id", tag.getId());
            map.put("spread", true);
            List<Map> childrens = new ArrayList<>();
            List<Map<String, Object>> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealTag(tag, childrens, hostId);
            list.add(map);
@@ -80,15 +84,15 @@
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="nodeTree",key="#id")
    public ArrayList<Map> getNodeTree(String id, Long hostId){
        ArrayList<Map> result = new ArrayList<>();
    public ArrayList<Map<String, Object>> getNodeTree(String id, Long hostId){
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        Node node = nodeService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", node.getName());
        map.put("id", node.getId());
        map.put("spread", true);
        List<Map> childrens = new ArrayList<>();
        List<Map<String, Object>> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealNode(node, childrens, hostId);
        result.add(map);
@@ -100,7 +104,7 @@
    /**
     * 递归获取子节点数据
     */
    public void dealNode(Node parent, List<Map> list, Long hostId) {
    public void dealNode(Node parent, List<Map<String, Object>> list, Long hostId) {
        Wrapper<Node> wrapper = new EntityWrapper<Node>()
                .eq("parent_id", parent.getId())
                .eq("status", "1");
@@ -113,7 +117,7 @@
            map.put("title", node.getName());
            map.put("id", node.getId());
            map.put("spread", true);
            List<Map> childrens = new ArrayList<>();
            List<Map<String, Object>> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealNode(node, childrens, hostId);
            list.add(map);
@@ -126,15 +130,15 @@
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="deptTree",key="#id")
    public ArrayList<Map> getDeptTree(String id, Long hostId){
        ArrayList<Map> result = new ArrayList<>();
    public ArrayList<Map<String, Object>> getDeptTree(String id, Long hostId){
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        Dept dept = deptService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", dept.getName());
        map.put("id", dept.getId());
        map.put("spread", true);
        List<Map> childrens = new ArrayList<>();
        List<Map<String, Object>> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealDept(dept, childrens, hostId);
        result.add(map);
@@ -146,10 +150,10 @@
    /**
     * 递归获取子节点数据
     */
    public void dealDept(Dept parent, List<Map> list, Long hostId) {
    public void dealDept(Dept parent, List<Map<String, Object>> list, Long hostId) {
        Wrapper<Dept> wrapper = new EntityWrapper<Dept>()
                .eq("parent_id", parent.getId())
                .eq("status", "1");
                .eq("status", 1);
        if (hostId != null) {
            wrapper.eq("host_id", hostId);
        }
@@ -159,13 +163,64 @@
            map.put("title", dept.getName());
            map.put("id", dept.getId());
            map.put("spread", true);
            List<Map> childrens = new ArrayList<>();
            List<Map<String, Object>> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealDept(dept, childrens, hostId);
            list.add(map);
        }
    }
    /******************************** 部门 + 员工 树 *********************************/
    /**
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="deptUserTree",key="#id")
    public ArrayList<Map<String, Object>> getDeptUserTree(String id, Long hostId){
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        Dept dept = deptService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", dept.getName());
        map.put("id", dept.getId());
        map.put("spread", true);
        map.put("type", 0);
        List<Map<String, Object>> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealUserDept(dept, childrens, hostId);
        result.add(map);
        return result;
    }
    public void dealUserDept(Dept parent, List<Map<String, Object>> list, Long hostId) {
        Wrapper<Dept> wrapper = new EntityWrapper<Dept>()
                .eq("parent_id", parent.getId())
                .eq("status", 1);
        if (hostId != null) {
            wrapper.eq("host_id", hostId);
        }
        List<Dept> depts = deptService.selectList(wrapper);
        List<User> users = userService.getUserByDept(hostId, parent.getId());
        for (User user : users) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", user.getNickname());
            map.put("id", user.getId());
            map.put("type", 1);
            list.add(map);
        }
        for (Dept dept : depts) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", dept.getName());
            map.put("id", dept.getId());
            map.put("spread", true);
            List<Map<String, Object>> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealUserDept(dept, childrens, hostId);
            list.add(map);
        }
    }
    // -------------------------------------------------------------------------------------------------------
@@ -173,12 +228,12 @@
     * 条件筛选
     */
    @SuppressWarnings("unchecked")
    public void remove(String condition, List<Map> list) {
        Iterator<Map> iterator = list.iterator();
    public void remove(String condition, List<Map<String, Object>> list) {
        Iterator<Map<String, Object>> iterator = list.iterator();
        while (iterator.hasNext()) {
            Map map = iterator.next();
            Map<String, Object> map = iterator.next();
            if (map.get("children") != null) {
                List<Map> children = (List<Map>) map.get("children");
                List<Map<String, Object>> children = (List<Map<String, Object>>) map.get("children");
                if (children.size() > 0) {
                    remove(condition, children);
                } else {
src/main/java/com/zy/crm/manager/controller/NodeController.java
@@ -238,9 +238,9 @@
    @PostMapping(value = "/node/tree/auth")
    @ManagerAuth
    public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
        ArrayList<Map> tree = treeUtils.getNodeTree(String.valueOf(getOriginNode().getId()), getHostId());
        ArrayList<Map<String, Object>> tree = treeUtils.getNodeTree(String.valueOf(getOriginNode().getId()), getHostId());
        // 深拷贝
        List<Map> result = ListUtils.deepCopy(tree);
        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
        if (!Cools.isEmpty(condition)) {
            treeUtils.remove(condition, result);
            treeUtils.remove(condition, result);
src/main/java/com/zy/crm/manager/controller/TagController.java
@@ -181,9 +181,9 @@
    @PostMapping(value = "/tag/tree/auth")
    @ManagerAuth
    public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
        ArrayList<Map> tree = treeUtils.getTree(String.valueOf(getOriginTag().getId()), getHostId());
        ArrayList<Map<String, Object>> tree = treeUtils.getTree(String.valueOf(getOriginTag().getId()), getHostId());
        // 深拷贝
        List<Map> result = ListUtils.deepCopy(tree);
        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
        if (!Cools.isEmpty(condition)) {
            treeUtils.remove(condition, result);
            treeUtils.remove(condition, result);
src/main/java/com/zy/crm/system/controller/DeptController.java
@@ -172,9 +172,22 @@
    @PostMapping(value = "/dept/tree/auth")
    @ManagerAuth
    public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
        ArrayList<Map> tree = treeUtils.getDeptTree(String.valueOf(getDeptId()), getHostId());
        ArrayList<Map<String, Object>> tree = treeUtils.getDeptTree(String.valueOf(getDeptId()), getHostId());
        // 深拷贝
        List<Map> result = ListUtils.deepCopy(tree);
        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
        if (!Cools.isEmpty(condition)) {
            treeUtils.remove(condition, result);
            treeUtils.remove(condition, result);
        }
        return R.ok(result);
    }
    @PostMapping(value = "/dept/user/tree/auth")
    @ManagerAuth
    public R deptUserTree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
        ArrayList<Map<String, Object>> tree = treeUtils.getDeptUserTree(String.valueOf(getDeptId()), getHostId());
        // 深拷贝
        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
        if (!Cools.isEmpty(condition)) {
            treeUtils.remove(condition, result);
            treeUtils.remove(condition, result);
src/main/java/com/zy/crm/system/mapper/UserMapper.java
@@ -2,11 +2,10 @@
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zy.crm.system.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import com.zy.crm.system.entity.User;
import java.util.List;
@@ -16,7 +15,6 @@
    List<User> listByPage(Page page, @Param("hostId")Long hostId, @Param("deptId") String deptId, @Param("username") Object username, @Param("mobile") Object mobile);
    @Select("select sys_user.* from sys_user left join sys_dept on sys_user.dept_id = sys_dept.id where sys_dept.parent_id = 1")
    List<User> getUserByDept(Long deptId);
    List<User> getUserByDept(@Param("hostId")Long hostId, @Param("deptId")Long deptId);
}
src/main/java/com/zy/crm/system/service/UserService.java
@@ -10,6 +10,6 @@
    Page<User> getPage(Page page, Long hostId, String deptId, Object username, Object mobile);
    List<User> getUserByDept(Long deptParentId);
    List<User> getUserByDept(Long hostId, Long deptParentId);
}
src/main/java/com/zy/crm/system/service/impl/UserServiceImpl.java
@@ -18,7 +18,7 @@
    }
    @Override
    public List<User> getUserByDept(Long dept) {
        return this.baseMapper.getUserByDept(dept);
    public List<User> getUserByDept(Long hostId, Long dept) {
        return this.baseMapper.getUserByDept(hostId, dept);
    }
}
src/main/resources/mapper/UserMapper.xml
@@ -38,4 +38,17 @@
        ORDER BY su.create_time DESC
    </select>
    <select id="getUserByDept" resultMap="BaseResultMap">
        SELECT
        *
        FROM sys_user
        where 1=1
        <if test="hostId != null and hostId != ''">
            and host_id = #{hostId}
        </if>
        <if test="deptId != null and deptId != ''">
            and dept_id = #{deptId}
        </if>
    </select>
</mapper>
src/main/webapp/static/js/cstmr/cstmr.js
@@ -18,9 +18,10 @@
    // 树形图
    var organizationTree;
    var selObj;
    window.loadTree = function(condition){
        $.ajax({
            url: baseUrl+"/dept/tree/auth",
            url: baseUrl+"/dept/user/tree/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                'condition': condition
@@ -37,6 +38,10 @@
                            selObj = obj;
                            $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                            $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                            tableIns.reload({
                                where: {dept_id: obj.data.id},
                                page: {curr: 1}
                            });
                        }
                    });
                    treeData = res.data;
src/main/webapp/views/cstmr/cstmr.html
@@ -99,8 +99,9 @@
<script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/cstmr/cstmr.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/layui/lay/modules/cascader/citys-data.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/cstmr/cstmr.js" charset="utf-8"></script>
</body>
<!-- 表单弹窗 -->
<script type="text/html" id="editDialog">