puzhibing
2023-06-12 d4f8078c2a062864dab885d6bd54fbe1195f85e2
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
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.stylefeng.guns.modular.system.controller.system;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp;
import com.stylefeng.guns.modular.system.enums.StatusEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.DateUtil;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 总览信息
 *
 * @author fengshuonan
 * @Date 2017年3月4日23:05:54
 */
@Controller
@RequestMapping("/blackboard")
public class BlackboardController extends BaseController {
 
    @Autowired
    private ILoginLogService loginLogService;
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private IRoleService roleService;
 
    @Autowired
    private IDeptService deptService;
 
    @Autowired
    private ITCompanyService companyService;
    @Autowired
    private ITAgentService tAgentService;
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private ITOrderService tOrderService;
    @Autowired
    private ITRevenueService tRevenueService;
    @Autowired
    private ITDriverWorkService tDriverWorkService;
    @Autowired
    private RedisUtil redisUtil;
 
    private ResultUtil resultUtil;
 
    /**
     * 跳转到黑板
     */
    @RequestMapping("")
    public String blackboard(Model model,Integer type,Integer agentId,String dayDate,String yearDate,String monthDate) {
        //查询当前用户是否有"首页"菜单的权限
        Integer id = ShiroKit.getUser().getId();
        User user = userService.selectById(id);
        Integer menuNum = userService.getMenuNumByRole(user.getRoleid());
        if (menuNum > 0){
            return "/home.html";
        } else {
            //查询登录次数
//            int count = loginLogService.selectCount(new EntityWrapper<LoginLog>().eq("userid", ShiroKit.getUser().getId()));
//            model.addAttribute("loginNum", count);
//
//            Role role = roleService.selectById(user.getRoleid());
//            Dept dept = deptService.selectById(user.getDeptid());
//
//            model.addAttribute("deptName",dept==null?"顶级":dept.getFullname());
//            model.addAttribute("roleName", role.getName());
//            model.addAttribute("userName", user.getName());
//            model.addAttribute("date", DateUtil.getTime(new Date()));
//            model.addAttribute("user", user);
            if(Objects.isNull(type)){
                type = 1;
            }
            Integer objectId = ShiroKit.getUser().getObjectId();
            Integer roleType = ShiroKit.getUser().getRoleType();
            if(roleType != 1){
                if(roleType == 3 && Objects.nonNull(objectId)){
                    // 查询所有代理商
                    List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                            .ne("status", StatusEnum.DELETE.getCode())
                            .ne("principal","")
                            .eq("id",objectId));
                    model.addAttribute("agentList",agentList);
                    agentId = objectId;
                }
            }else {
                // 查询所有代理商
                List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                        .ne("status", StatusEnum.DELETE.getCode())
                        .ne("principal",""));
                model.addAttribute("agentList",agentList);
            }
            model.addAttribute("txt",new SimpleDateFormat("yyyy年MM月dd日").format(new Date()) + DateUtil.getWeekDay(new Date()) + ",欢迎" +
                    Objects.requireNonNull(ShiroKit.getUser()).getName() + "登录");
            Map<String, Object> map = new HashMap<>();
            if(Objects.nonNull(agentId)){
                // 统计代理商
                tAgentService.getDataStatistics(agentId,model,map);
 
                // 统计司机数
                tDriverService.getDataStatistics(agentId,model,map);
 
                // 订单统计本月
                tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map);
 
                // 订单统计,每年按月份
                tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map);
 
                // 业绩排名 performanceTable
                if (1 == type){
                    // 单量
                    tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map);
                }else {
                    // 收入、佣金
                    tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map);
                }
 
                // 查询统计在线司机,待接单,服务中,已完成,已取消
                List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>()
                        .eq("agentId", agentId)
                        .eq("serverStatus", 2));
                model.addAttribute("onLineDriverCount",onLineDriver.size());
                tOrderService.getDataStatisticsCount(agentId,model);
                // 查询服务中的订单列表
                List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerList(agentId);
                // 查询司机
                for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                    TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                    tOrderServerResp.setAvatar(tDriver.getAvatar());
                    tOrderServerResp.setDriverName(tDriver.getName());
                }
                model.addAttribute("serverList",orderServerRespList);
                // 查询今天所有订单
                List<TOrder> allList = tOrderService.getDataStatisticsAllList(agentId,type);
                List<List<String>> list = new ArrayList<>(allList.size());
                for (TOrder tOrder : allList) {
                    List<String> obj = new ArrayList<>(3);
                    obj.add(tOrder.getStartLng());
                    obj.add(tOrder.getStartLat());
                    obj.add(String.valueOf(tOrder.getState()));
                    list.add(obj);
                }
                model.addAttribute("allList",list);
                List<List<String>> list1 = new ArrayList<>(allList.size());
                for (TDriver tDriver : onLineDriver) {
                    List<String> obj = new ArrayList<>(3);
                    String value = redisUtil.getValue("DRIVER" + tDriver.getId());
                    if(ToolUtil.isEmpty(value)){
                        continue;
                    }
                    obj.add(value.split(",")[0]);// 经度
                    obj.add(value.split(",")[1]);// 纬度
                    obj.add(String.valueOf(tDriver.getServerStatus()));// 服务状态
                    list1.add(obj);
                }
                // 拿到所有在线司机地址
                model.addAttribute("onLineDriver",list1);
 
            }else {
                // 查询广东全区域数据 查询广东所有的代理商
                List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                        .eq("provinceCode", "440000"));
                List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
                // 统计代理商
                tAgentService.getDataStatisticsByIds(ids,model,map);
 
                // 统计司机数
                tDriverService.getDataStatisticsByIds(ids,model,map);
 
                // 订单统计本月
                tOrderService.getStatisticsOrderByMonthIds(ids,dayDate,model,map);
 
                // 订单统计,每年按月份
                tOrderService.getDataStatisticsByYearByIds(ids,yearDate,model,map);
 
                // 业绩排名 performanceTable
                if (1 == type){
                    // 单量
                    tOrderService.getDataStatisticsOrderCountByIds(ids,monthDate,model,map);
                }else {
                    // 收入、佣金
                    tRevenueService.getDataStatisticsIncomeOrCommissionByIds(ids,monthDate,type,model,map);
                }
 
                // 查询统计在线司机,待接单,服务中,已完成,已取消
                List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>()
                        .in("agentId", ids)
                        .eq("serverStatus", 2));
 
                model.addAttribute("onLineDriverCount",onLineDriver.size());
 
                List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>());
                List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList());
 
                tOrderService.getDataStatisticsCountByIds(allIds,model);
                // 查询服务中的订单列表 所有
                List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds);
                // 查询司机
                for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                    TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                    tOrderServerResp.setAvatar(tDriver.getAvatar());
                    tOrderServerResp.setDriverName(tDriver.getName());
                }
                model.addAttribute("serverList",orderServerRespList);
                // 查询今天所有订单  所有
                List<TOrder> allList = tOrderService.getDataStatisticsAllListByIds(allIds,type);
                List<List<String>> list = new ArrayList<>(allList.size());
                for (TOrder tOrder : allList) {
                    List<String> obj = new ArrayList<>(3);
                    obj.add(tOrder.getStartLng());
                    obj.add(tOrder.getStartLat());
                    obj.add(String.valueOf(tOrder.getState()));
                    list.add(obj);
                }
                model.addAttribute("allList",list);
                List<List<String>> list1 = new ArrayList<>(allList.size());
                for (TDriver tDriver : onLineDriver) {
                    List<String> obj = new ArrayList<>(3);
                    String value = redisUtil.getValue("DRIVER" + tDriver.getId());
                    if(ToolUtil.isEmpty(value)){
                        continue;
                    }
                    obj.add(value.split(",")[0]);// 经度
                    obj.add(value.split(",")[1]);// 纬度
                    obj.add(String.valueOf(tDriver.getServerStatus()));// 服务状态
                    list1.add(obj);
                }
                // 拿到所有在线司机地址
                model.addAttribute("onLineDriver",list1);
 
            }
            return "/blackboardBlank.html";
        }
    }
 
    /**
     * 根据当前登录账户id获取对应公司详细信息
     * @param uid
     * @return
     */
    @RequestMapping(value = "/getCompanyInfoByUserId", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil getCompanyInfoByUserId(String uid){
        try {
            User user = userService.selectById(uid);
//            resultUtil = companyService.selectCompanyInfoById(user.getObjectId().toString());
        }catch (Exception e){
            e.printStackTrace();
            resultUtil = ResultUtil.runErr();
        }
        return resultUtil;
    }
 
 
}