中扬CRM客户关系管理系统
LSH
2024-03-27 92459e3e326488acae77e068c37eb4b96eae5ebf
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.*;
import com.zy.crm.manager.service.*;
import com.zy.crm.system.entity.Role;
import com.zy.crm.system.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
@RestController
public class DashboardController extends BaseController {
 
    Integer PBN = 6;
 
    @Autowired
    private CompanyTargetService companyTargetService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private PlanService planService;
    @Autowired
    private PriOnline2Service priOnline2Service;
    @Autowired
    private PriQuoteService priQuoteService;
    @Autowired
    private BusinessTripService businessTripService;
    @Autowired
    private BusinessTripOtherService businessTripOtherService;
    @Autowired
    private ReimburseOnlineService reimburseOnlineService;
    @Autowired
    private CompanyMoneyService companyMoneyService;
    @Autowired
    private ProcessPermissionsService processPermissionsService;
    @Autowired
    private PlanTypeService planTypeService;
 
    //获取团队数据
    @RequestMapping(value = "/dashboard/companyData/auth")
    @ManagerAuth
    public R getCompanyData() {
        HashMap<String, Object> map = new HashMap<>();
 
        NumberFormat formatter = new DecimalFormat("#,###");
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        String year = format.format(date);
        CompanyTarget companyTarget = companyTargetService.selectCompanyByYear(year);//获取公司全年目标数据
        if (companyTarget == null) {
            return R.error();
        }
        double whole = Double.parseDouble(companyTarget.getTarget());
        map.put("yearTarget", formatter.format(whole));//全年交易目标
 
        //获取全年交易成功金额
        Double successMoney = orderService.selectMoneyByYearAndStatus(year, 1);
        //获取全年未交易成功金额
//        double v = whole - orderService.selectMoneyByYearAndStatus(year, 0);
        double v = whole - orderService.selectMoneyByYearAndStatus(year, 1);
        Double progressMoney =  v > 0? v : 0D;
        //获取全年交易失败金额
        Double failedMoney = orderService.selectMoneyByYearAndStatus(year, 2);
        //全年完成率
//        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100;
        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / Double.parseDouble(companyTarget.getTarget())) * 100;
 
        Double successMoney1 = companyMoneyService.selectMoneyReceivablesAll(null, year);
 
        Double successMoney2 = companyMoneyService.selectMoneyActualReceiptsAll(null, year);
 
        map.put("successMoney", formatter.format(successMoney));//全年交易成功金额
        map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额
        map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率
        map.put("receivablesMoney", successMoney1/10000);//应收款
        map.put("actualReceiptsMoney",successMoney2/10000);//实际收款
        return R.ok().add(map);
    }
 
    //获取员工个人数据
    @RequestMapping(value = "/dashboard/personData/auth")
    @ManagerAuth
    public R getPersonData() {
        HashMap<String, Object> map = new HashMap<>();
 
        NumberFormat formatter = new DecimalFormat("#,###");
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        String year = format.format(date);
 
        Double yearTarget = 0D;//获取个人全年目标数据
        CompanyTarget person = companyTargetService.selectPersonByYear(year, getUserId());
        if (person != null) {
            yearTarget = Double.parseDouble(person.getTarget());
        }
        map.put("yearTarget", formatter.format(yearTarget));//全年交易目标
 
        //获取全年交易成功金额
        Double successMoney = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 1);
        //获取全年未交易成功金额
        double v = yearTarget - orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 1);
        Double progressMoney = v > 0? v : 0D;
        Double progressMoney2 = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 0);
        //获取全年交易失败金额
        Double failedMoney = orderService.selectMoneyByUserAndYearAndStatus(getUserId(), year, 2);
        //全年完成率
//        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100;
        double yearTransactionRate = yearTarget==0? 0 : successMoney == 0 ? successMoney : (successMoney / yearTarget) * 100;
 
        map.put("successMoney", formatter.format(successMoney));//全年交易成功金额
        map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额
        map.put("progressMoney2", formatter.format(progressMoney2));//跟踪项目金额
        map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率
 
        //获取全年跟踪数量
        Integer progressCount = orderService.selectCountByUserYearAndStatus(getUserId(), year, 0);
        //获取全年成交数量
        Integer successCount = orderService.selectCountByUserYearAndStatus(getUserId(), year, 1);
        map.put("progressCount", progressCount);
        map.put("successCount", successCount);
 
        //获取待处理任务数量
        int planPendingTaskCount = planService.selectPendingTaskCount(getUserId());
        map.put("planPendingTaskCount", planPendingTaskCount);
        int priOnlinePendingTaskCount = priOnline2Service.selectCount(new EntityWrapper<PriOnline2>().eq("member_id", getUserId()).lt("settle",2));
        map.put("priOnlinePendingTaskCount", priOnlinePendingTaskCount);
        int priQuotePendingTaskCount = priQuoteService.selectCount(new EntityWrapper<PriQuote>().eq("member_id", getUserId()).lt("settle",4));
        map.put("priQuotePendingTaskCount", priQuotePendingTaskCount);
        int businessTripCount = businessTripService.selectCount(new EntityWrapper<BusinessTrip>().eq("member_id", getUserId()).lt("settle", 2));
        int businessTripOtherCount = businessTripOtherService.selectCount(new EntityWrapper<BusinessTripOther>().eq("member_id", getUserId()).lt("settle",2));
        int businessTripPendingTaskCount = businessTripCount+businessTripOtherCount;
        map.put("businessTripPendingTaskCount", businessTripPendingTaskCount);
        int reimburseOnlinePendingTaskCount = reimburseOnlineService.selectCount(new EntityWrapper<ReimburseOnline>().eq("member_id", getUserId()).lt("settle",6));
        map.put("reimburseOnlinePendingTaskCount", reimburseOnlinePendingTaskCount);
        int planPriOnlinePendingTaskCount = 0;
        List<ProcessPermissions> processPermissionsList = processPermissionsService.selectList(new EntityWrapper<ProcessPermissions>().eq("process_memo", 4).or().eq("process_memo", 5));//2:核价流程
        int type =0;
        for (ProcessPermissions processPermissions:processPermissionsList){
            if (getUserId().equals(processPermissions.getUserId())){
                type=PBN-processPermissions.getProcessMemo();
                break;
            }
        }
        if (type!=0){
            EntityWrapper<Plan> wrapper = new EntityWrapper<>();
            wrapper.eq("status",1);
            wrapper.eq("assistant_host_sign",0);
            List<Long> typeList = new ArrayList<>();
            List<PlanType> planTypes = planTypeService.selectList(new EntityWrapper<PlanType>().eq("type", type));
            for (PlanType planType : planTypes){
                typeList.add(planType.getId());
            }
            wrapper.in("plan_type",typeList);
            List<Plan> plans = planService.selectList(wrapper);
            planPriOnlinePendingTaskCount=plans.size();
        }
        map.put("planPriOnlinePendingTaskCount", planPriOnlinePendingTaskCount);
 
        Double successMoney1 = companyMoneyService.selectMoneyReceivablesAll(getUserId(), year);
        map.put("successMoney1", successMoney1==null? 0:successMoney1);
 
        Double successMoney2 = companyMoneyService.selectMoneyActualReceiptsAll(getUserId(), year);
        map.put("successMoney2", successMoney2==null? 0:successMoney2);
 
 
        return R.ok().add(map);
    }
 
    //获取员工排行榜
    @RequestMapping(value = "/dashboard/staffRank/auth")
    @ManagerAuth
    public R getStaffRank() {
        ArrayList<HashMap<String, Object>> list = new ArrayList<>();
        NumberFormat formatter = new DecimalFormat("#,###");
        for (Order order : orderService.selectTopMoney()) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("username", order.getUserId$());
            map.put("money", formatter.format(order.getMoney()));
            list.add(map);
        }
        return R.ok().add(list);
    }
 
    //获取当前年度12个月的交易成功数据
    @RequestMapping(value = "/dashboard/currentMonthData/auth")
    @ManagerAuth
    public R getCurrentMonthData() {
        List<Double> list = orderService.selectCurrentYearMonthSuccess();
        List<Double> lists = new ArrayList<>();
        int i = 0;
        Double[] money=new Double[]{0.0,0.0,0.0,0.0};
        for (Double d : list){
            if (i<3){
                money[0] = money[0]+d;
            }else if (i<6){
                money[1] = money[1]+d;
            }else if (i<9){
                money[2] = money[2]+d;
            }else if (i<12){
                money[3] = money[3]+d;
            }
            i++;
        }
        for (Double d : money){
            double d1=d/3;
            lists.add(d1);
            lists.add(d1);
            lists.add(d1);
        }
        return R.ok().add(lists);
    }
 
    @RequestMapping("/dashboard/popup/auth")
    public R popup(String token) {
        String item = "false";
        if (Cools.isEmpty(token)){
            return R.ok(item);
        }
        try{
            User user = getUser(token);
            if (Cools.isEmpty(user) || Cools.isEmpty(user.getRoleId())){
                return R.ok(item);
            }
            if (user.getRoleId()<2){
                item="true";
            }else if (user.getRoleId()<3){
                item="true2";
            }
        }catch (Exception ignored){ }
        return R.ok(item);
    }
 
    @RequestMapping("/dashboard/user/id/popup/auth")
    public R popupUserId(String token) {
        Long item = 0L;
        if (Cools.isEmpty(token)){
            return R.ok(item);
        }
        try{
            User user = getUser(token);
            if (Cools.isEmpty(user) || Cools.isEmpty(user.getId())){
                return R.ok(item);
            }
            item = user.getId();
        }catch (Exception ignored){ }
        return R.ok(item);
    }
 
}