中扬CRM客户关系管理系统
LSH
2024-03-26 7e408b4de778506c1544fa8f34ff289dd8b8c8df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.zy.crm.manager.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.core.common.SpringUtils;
import com.zy.crm.common.entity.UserYear;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.Plan;
import com.zy.crm.manager.entity.PlanType;
import com.zy.crm.manager.entity.ProcessPermissions;
import com.zy.crm.manager.service.PlanService;
import com.zy.crm.manager.service.PlanTypeService;
import com.zy.crm.manager.service.ProcessPermissionsService;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.*;
 
@RestController
public class BIController extends BaseController {
 
    @Autowired
    private PlanService planService;
    @Autowired
    private PlanTypeService planTypeService;
    @Autowired
    private UserService userService;
    @Autowired
    private ProcessPermissionsService processPermissionsService;
 
    @RequestMapping(value = "/pending/approval/auth")
    //@ManagerAuth
    public R get() {
        // 传入用户id查询规划单 区分,通过区分出来的规划单类型查询 规划申请单
        //
        PlanType planType = new PlanType();
        planType.setType(2);
        planType.setHostId(1L);
        User planLeader = planTypeService.findPlanLeader(planType);
        EntityWrapper<Plan> wrapper = new EntityWrapper<>();
        wrapper.setSqlSelect("user_id","director","count(id) as count");
        wrapper.eq("director",planLeader.getId()).eq("settle",1).eq("assistant_host_sign",0).groupBy("user_id,director");
        List<Map<String, Object>> maps = planService.selectMaps(wrapper);
        for (Map<String, Object> map : maps) {
            String user_id = map.get("user_id").toString();
            UserService service = SpringUtils.getBean(UserService.class);
            User user = service.selectById(user_id);
            if (!Cools.isEmpty(user)) {
                map.put("userId$",String.valueOf(user.getNickname()));
            }
        }
        return R.ok().add(maps);
    }
 
    @RequestMapping(value = "/pending/user/approval/auth")
    //@ManagerAuth
    public R getPlanByUser() {
        PlanType planType = new PlanType();
        planType.setType(2);
        planType.setHostId(1L);
        User planLeader = planTypeService.findPlanLeader(planType);
        List<User> users = userService.selectList(new EntityWrapper<User>().eq("dept_id", planLeader.getDeptId()));
        List<ProcessPermissions> processPermissionsList = processPermissionsService.selectList(new EntityWrapper<ProcessPermissions>().eq("process_memo", 101));
        for (ProcessPermissions processPermissions:processPermissionsList){
            User user = userService.selectById(processPermissions.getUserId());
            users.add(user);
        }
        List<Map<String, Object>> result = new ArrayList<>();
 
        for (User user:users){
            if (user.getUsername().equals("周夏天") || user.getUsername().equals("梁昌民")) {
                continue;
            }
            List<Plan> plans = planService.selctPlanListByDirector(user.getId());
            String userList = "";
            for (Plan plan:plans){
                if (plans.indexOf(plan)==plans.size()-1){
                    userList = userList+plan.getUserId$();
                    continue;
                }
                userList = plan.getUserId$() +","+ userList;
            }
            int director = planService.selectCount(new EntityWrapper<Plan>().eq("director", user.getId()));
 
 
            Map<String, Object> map = new HashMap<>();
            map.put("user", user.getNickname());
            map.put("value", userList);
            map.put("anfme", director);
            result.add(map);
        }
        return R.ok().add(result);
    }
 
 
    @RequestMapping(value = "/pending/sum/auth")
    //@ManagerAuth
    public R getAllPlan() {
        EntityWrapper<Plan> wrapper = new EntityWrapper<>();
        wrapper.setSqlSelect("count(0) count","MONTH(create_time) month");
        wrapper.groupBy("MONTH(create_time)");
        List<Map<String, Object>> maps = planService.selectMaps(wrapper);
        return R.ok().add(maps);
    }
 
    @RequestMapping(value = "/user/sumyear/auth")
    //@ManagerAuth
    public R getUserYear() {
        PlanType planType = new PlanType();
        planType.setType(2);
        planType.setHostId(1L);
        User planLeader = planTypeService.findPlanLeader(planType);
        List<User> users = userService.selectList(new EntityWrapper<User>().eq("dept_id", planLeader.getDeptId()));
        List<Map<String, Object>> maps = new ArrayList<>();
        for (User user : users) {
            if (user.getUsername().equals("周夏天") || user.getUsername().equals("梁昌民")) {
                continue;
            }
            Map<String, Object> map = new HashMap<>();
            map.put("user", user);
            map.put("obj", planService.selectUserYear(user.getId()));
            maps.add(map);
        }
        return R.ok().add(maps);
    }
 
}