中扬CRM客户关系管理系统
#
Junjie
2023-09-08 155bb21ac78455a0c5b3a2302528ade7a5a6fb19
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
package com.zy.crm.manager.controller;
 
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.CompanyTarget;
import com.zy.crm.manager.entity.Order;
import com.zy.crm.manager.service.CompanyTargetService;
import com.zy.crm.manager.service.OrderService;
import com.zy.crm.manager.utils.WordUtils;
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 {
 
    @Autowired
    private CompanyTargetService companyTargetService;
    @Autowired
    private OrderService orderService;
 
    //获取团队数据
    @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.selectByYear(year);//获取公司全年目标数据
        if (companyTarget == null) {
            return R.error();
        }
        map.put("yearTarget", formatter.format(Double.parseDouble(companyTarget.getTarget())));//全年交易目标
 
        //获取全年交易成功金额
        Double successMoney = orderService.selectMoneyByYearAndStatus(year, 1);
        //获取全年未交易成功金额
        Double progressMoney = orderService.selectMoneyByYearAndStatus(year, 0);
        //获取全年交易失败金额
        Double failedMoney = orderService.selectMoneyByYearAndStatus(year, 2);
        //全年交易率
        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100;
 
        map.put("successMoney", formatter.format(successMoney));//全年交易成功金额
        map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额
        map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率
        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);
 
        User user = getUser();
        String yearTarget = "0";//获取个人全年目标数据
        if (user.getTarget() != null) {
            yearTarget = formatter.format(Double.parseDouble(user.getTarget()));
        }
        map.put("yearTarget", yearTarget);//全年交易目标
 
        //获取全年交易成功金额
        Double successMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 1);
        //获取全年未交易成功金额
        Double progressMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 0);
        //获取全年交易失败金额
        Double failedMoney = orderService.selectMoneyByUserAndYearAndStatus(user.getId(), year, 2);
        //全年交易率
        double yearTransactionRate = successMoney == 0 ? successMoney : (successMoney / (successMoney + progressMoney + failedMoney)) * 100;
 
        map.put("successMoney", formatter.format(successMoney));//全年交易成功金额
        map.put("progressMoney", formatter.format(progressMoney));//全年未交易成功金额
        map.put("yearTransactionRate", String.format("%.2f", yearTransactionRate));//全年交易率
 
        //获取全年跟踪数量
        Integer progressCount = orderService.selectCountByUserYearAndStatus(user.getId(), year, 0);
        //获取全年成交数量
        Integer successCount = orderService.selectCountByUserYearAndStatus(user.getId(), year, 1);
        map.put("progressCount", progressCount);
        map.put("successCount", successCount);
 
        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();
        return R.ok().add(list);
    }
 
}