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().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 agentList = tAgentService.selectList(new EntityWrapper() .ne("status", StatusEnum.DELETE.getCode()) .ne("principal","") .eq("id",objectId)); model.addAttribute("agentList",agentList); agentId = objectId; } }else { // 查询所有代理商 List agentList = tAgentService.selectList(new EntityWrapper() .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 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 onLineDriver = tDriverService.selectList(new EntityWrapper() .eq("agentId", agentId) .eq("serverStatus", 2)); model.addAttribute("onLineDriverCount",onLineDriver.size()); tOrderService.getDataStatisticsCount(agentId,model); // 查询服务中的订单列表 List 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 allList = tOrderService.getDataStatisticsAllList(agentId,type); List> list = new ArrayList<>(allList.size()); for (TOrder tOrder : allList) { List 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> list1 = new ArrayList<>(allList.size()); for (TDriver tDriver : onLineDriver) { List 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 tAgentList = tAgentService.selectList(new EntityWrapper() .eq("provinceCode", "440000")); List 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 onLineDriver = tDriverService.selectList(new EntityWrapper() .in("agentId", ids) .eq("serverStatus", 2)); model.addAttribute("onLineDriverCount",onLineDriver.size()); List tAgentAllList = tAgentService.selectList(new EntityWrapper()); List allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList()); tOrderService.getDataStatisticsCountByIds(allIds,model); // 查询服务中的订单列表 所有 List 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 allList = tOrderService.getDataStatisticsAllListByIds(allIds,type); List> list = new ArrayList<>(allList.size()); for (TOrder tOrder : allList) { List 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> list1 = new ArrayList<>(allList.size()); for (TDriver tDriver : onLineDriver) { List 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; } }