| | |
| | | package com.stylefeng.guns.modular.system.controller.general; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.GunsApplication; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.common.constant.state.Order; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp; |
| | | import com.stylefeng.guns.modular.system.controller.util.HttpUtils; |
| | | import com.stylefeng.guns.modular.system.enums.OrderStateEnum; |
| | | import com.stylefeng.guns.modular.system.enums.StatusEnum; |
| | | import com.stylefeng.guns.modular.system.model.TAgent; |
| | | import com.stylefeng.guns.modular.system.model.TDriver; |
| | | import com.stylefeng.guns.modular.system.model.TDriverWork; |
| | | import com.stylefeng.guns.modular.system.model.TOrder; |
| | | import com.stylefeng.guns.modular.system.pojo.GaoDePoJo; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.DateUtil; |
| | | import com.stylefeng.guns.modular.system.util.RedisUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.Period; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 控制器 |
| | |
| | | @RequestMapping("/tHomePage") |
| | | public class THomePageController extends BaseController { |
| | | |
| | | private final static Logger log = LoggerFactory.getLogger(THomePageController.class); |
| | | |
| | | @Autowired |
| | | private IUserService userService; |
| | | @Autowired |
| | |
| | | private ITOrderService tOrderService; |
| | | @Autowired |
| | | private ITRevenueService tRevenueService; |
| | | @Autowired |
| | | private ITDriverWorkService tDriverWorkService; |
| | | @Autowired |
| | | private GaoDePoJo gaoDePoJo; |
| | | @Autowired |
| | | private HttpUtils httpUtils; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | private String PREFIX = "/system/tHomePage/"; |
| | | |
| | |
| | | @RequestMapping("/map") |
| | | public String map(Integer agentId,Integer type,Model model) { |
| | | |
| | | if(Objects.nonNull(agentId)){ |
| | | // 查询统计在线司机,待接单,服务中,已完成,已取消 |
| | | Map<String,Integer> map = new HashMap<>(4); |
| | | int serverCount = tDriverService.selectCount(new EntityWrapper<TDriver>() |
| | | .eq("agentId", agentId) |
| | | .eq("serverStatus", 2)); |
| | | tOrderService.getDataStatisticsCount(agentId,map); |
| | | model.addAttribute("map",map); |
| | | |
| | | // 查询服务中的订单列表 |
| | | List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerList(agentId); |
| | | model.addAttribute("serverList",orderServerRespList); |
| | | |
| | | // 查询今天所有订单 |
| | | List<TOrder> allList = tOrderService.getDataStatisticsAllList(agentId); |
| | | |
| | | // TODO 拿到所有司机地址 |
| | | |
| | | }else { |
| | | // TODO 查询广东全区域数据 |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | |
| | | // 查询所有代理商 |
| | | List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .ne("status", StatusEnum.DELETE.getCode()) |
| | | .ne("principal","")); |
| | | model.addAttribute("agentList",agentList); |
| | | // 查询广东省广州市的地址解析 |
| | | Map<String, String> map = geocode("广东省广州市"); |
| | | model.addAttribute("addressLon",map.get("addressLon")); |
| | | model.addAttribute("addressLat",map.get("addressLat")); |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .eq("provinceCode", "440000")); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | // 查询统计在线司机,待接单,服务中,已完成,已取消 |
| | | List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>() |
| | | .in("agentId", ids)); |
| | | 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); |
| | | List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>()); |
| | | // 查询司机 |
| | | for (TOrderServerResp tOrderServerResp : orderServerRespList) { |
| | | TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId()); |
| | | tOrderServerResp.setAvatar(tDriver.getAvatar()); |
| | | tOrderServerResp.setDriverName(tDriver.getName()); |
| | | List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) && |
| | | (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode()) |
| | | || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) |
| | | || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | // 驾龄 |
| | | Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime())); |
| | | tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1)); |
| | | // 代驾次数 |
| | | tOrderServerResp.setValetDrivingCount(collect.size()); |
| | | // 行驶时间 |
| | | long goTime = 0; |
| | | for (TOrder tOrder : collect) { |
| | | // 下车时间 |
| | | Date getoffTime = tOrder.getGetoffTime(); |
| | | // 上车时间 |
| | | Date boardingTime = tOrder.getBoardingTime(); |
| | | long minutes = Duration.between(DateUtil.dateToLocalDate(getoffTime), DateUtil.dateToLocalDate(boardingTime)).toMinutes(); |
| | | goTime += Math.abs(minutes); |
| | | } |
| | | tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue()); |
| | | // 行驶里程 |
| | | int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum(); |
| | | tOrderServerResp.setMileageTraveled(sum/1000); |
| | | } |
| | | model.addAttribute("serverList",orderServerRespList); |
| | | // 查询今天所有订单 |
| | | List<TOrder> allList = tOrderService.getDataStatisticsAllListByIds(ids,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<>(); |
| | | AtomicInteger count = new AtomicInteger(0); |
| | | for (TDriver tDriver : onLineDriver) { |
| | | |
| | | String value1 = redisUtil.getValue("DRIVER_" + tDriver.getPhone()); |
| | | String value2 = redisUtil.getValue(value1); |
| | | if(ToolUtil.isNotEmpty(value2)){ |
| | | count.addAndGet(1); |
| | | } |
| | | |
| | | 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("onLineDriverCount",count.get()); |
| | | // 拿到所有在线司机地址 |
| | | model.addAttribute("onLineDriver",list1); |
| | | return PREFIX + "tHomePageMap.html"; |
| | | } |
| | | |
| | | @RequestMapping("/getMap") |
| | | @ResponseBody |
| | | public Object getMap(Integer agentId,Integer type,Model model) { |
| | | Integer objectId = Objects.requireNonNull(ShiroKit.getUser()).getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | // 查询所有代理商 |
| | | List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .ne("status", StatusEnum.DELETE.getCode()) |
| | | .ne("principal","")); |
| | | |
| | | map.put("agentList",agentList); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 查询当前代理商 |
| | | TAgent tAgent = tAgentService.selectById(agentId); |
| | | Map<String, String> mapAddress = geocode(tAgent.getProvinceName()+tAgent.getCityName()); |
| | | map.put("addressLon",mapAddress.get("addressLon")); |
| | | map.put("addressLat",mapAddress.get("addressLat")); |
| | | // 查询统计在线司机,待接单,服务中,已完成,已取消 |
| | | List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>() |
| | | .eq("agentId", agentId)); |
| | | List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>()); |
| | | List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | tOrderService.getDataStatisticsCountByIdsGetMap(allIds,map); |
| | | |
| | | // 查询服务中的订单列表 |
| | | List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds); |
| | | List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>()); |
| | | // 查询司机 |
| | | for (TOrderServerResp tOrderServerResp : orderServerRespList) { |
| | | TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId()); |
| | | tOrderServerResp.setAvatar(tDriver.getAvatar()); |
| | | tOrderServerResp.setDriverName(tDriver.getName()); |
| | | List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) && |
| | | (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode()) |
| | | || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) |
| | | || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | // 驾龄 |
| | | if(Objects.nonNull(tDriver.getFirstCertificateTime())){ |
| | | Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime())); |
| | | tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1)); |
| | | }else { |
| | | tOrderServerResp.setDrivingExperience(0); |
| | | } |
| | | // 代驾次数 |
| | | tOrderServerResp.setValetDrivingCount(collect.size()); |
| | | // 行驶时间 |
| | | long goTime = 0; |
| | | for (TOrder tOrder : collect) { |
| | | // 下车时间 |
| | | Date getoffTime = tOrder.getGetoffTime(); |
| | | // 上车时间 |
| | | Date boardingTime = tOrder.getBoardingTime(); |
| | | long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes(); |
| | | goTime += Math.abs(minutes); |
| | | } |
| | | tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue()); |
| | | // 行驶里程 |
| | | if(CollectionUtils.isEmpty(collect)){ |
| | | tOrderServerResp.setMileageTraveled(0); |
| | | }else { |
| | | int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum(); |
| | | tOrderServerResp.setMileageTraveled(sum/1000); |
| | | } |
| | | } |
| | | map.put("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); |
| | | } |
| | | map.put("allList",list); |
| | | List<List<String>> list1 = new ArrayList<>(); |
| | | 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); |
| | | } |
| | | map.put("onLineDriverCount",list1.size()); |
| | | // 拿到所有在线司机地址 |
| | | map.put("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()); |
| | | // 查询统计在线司机,待接单,服务中,已完成,已取消 |
| | | List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>() |
| | | .in("agentId", ids)); |
| | | |
| | | Map<String, String> mapAddress = geocode("广东省广州市"); |
| | | map.put("addressLon",mapAddress.get("addressLon")); |
| | | map.put("addressLat",mapAddress.get("addressLat")); |
| | | |
| | | List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>()); |
| | | List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | tOrderService.getDataStatisticsCountByIdsGetMap(allIds,map); |
| | | |
| | | // 查询服务中的订单列表 |
| | | List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds); |
| | | List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>()); |
| | | // 查询司机 |
| | | for (TOrderServerResp tOrderServerResp : orderServerRespList) { |
| | | TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId()); |
| | | tOrderServerResp.setAvatar(tDriver.getAvatar()); |
| | | tOrderServerResp.setDriverName(tDriver.getName()); |
| | | List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) && |
| | | (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode()) |
| | | || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) |
| | | || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | // 驾龄 |
| | | if(Objects.nonNull(tDriver.getFirstCertificateTime())){ |
| | | Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime())); |
| | | tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1)); |
| | | }else { |
| | | tOrderServerResp.setDrivingExperience(0); |
| | | } |
| | | // 代驾次数 |
| | | tOrderServerResp.setValetDrivingCount(collect.size()); |
| | | // 行驶时间 |
| | | long goTime = 0; |
| | | for (TOrder tOrder : collect) { |
| | | // 下车时间 |
| | | Date getoffTime = tOrder.getGetoffTime(); |
| | | // 上车时间 |
| | | Date boardingTime = tOrder.getBoardingTime(); |
| | | long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes(); |
| | | goTime += Math.abs(minutes); |
| | | } |
| | | tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue()); |
| | | // 行驶里程 |
| | | if(CollectionUtils.isEmpty(collect)){ |
| | | tOrderServerResp.setMileageTraveled(0); |
| | | }else { |
| | | int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum(); |
| | | tOrderServerResp.setMileageTraveled(sum/1000); |
| | | } |
| | | } |
| | | map.put("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); |
| | | } |
| | | map.put("allList",list); |
| | | List<List<String>> list1 = new ArrayList<>(); |
| | | 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); |
| | | } |
| | | map.put("onLineDriverCount",list1.size()); |
| | | // 拿到所有在线司机地址 |
| | | map.put("onLineDriver",list1); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @RequestMapping("/getServerOrder") |
| | | @ResponseBody |
| | | public Object getServerOrder(Integer agentId,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | // 查询服务中的订单列表 |
| | | List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(ids); |
| | | List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>()); |
| | | // 查询司机 |
| | | for (TOrderServerResp tOrderServerResp : orderServerRespList) { |
| | | TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId()); |
| | | tOrderServerResp.setAvatar(tDriver.getAvatar()); |
| | | tOrderServerResp.setDriverName(tDriver.getName()); |
| | | List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) && |
| | | (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode()) |
| | | || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) |
| | | || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | // 驾龄 |
| | | if(Objects.nonNull(tDriver.getFirstCertificateTime())){ |
| | | Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime())); |
| | | tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1)); |
| | | }else { |
| | | tOrderServerResp.setDrivingExperience(0); |
| | | } |
| | | // 代驾次数 |
| | | tOrderServerResp.setValetDrivingCount(collect.size()); |
| | | // 行驶时间 |
| | | long goTime = 0; |
| | | for (TOrder tOrder : collect) { |
| | | // 下车时间 |
| | | Date getoffTime = tOrder.getGetoffTime(); |
| | | // 上车时间 |
| | | Date boardingTime = tOrder.getBoardingTime(); |
| | | long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes(); |
| | | goTime += Math.abs(minutes); |
| | | } |
| | | tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue()); |
| | | // 行驶里程 |
| | | if(CollectionUtils.isEmpty(collect)){ |
| | | tOrderServerResp.setMileageTraveled(0); |
| | | }else { |
| | | int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum(); |
| | | tOrderServerResp.setMileageTraveled(sum/1000); |
| | | } |
| | | } |
| | | map.put("serverList",orderServerRespList); |
| | | }else { |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | // 查询服务中的订单列表 |
| | | List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(ids); |
| | | List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>()); |
| | | // 查询司机 |
| | | for (TOrderServerResp tOrderServerResp : orderServerRespList) { |
| | | TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId()); |
| | | tOrderServerResp.setAvatar(tDriver.getAvatar()); |
| | | tOrderServerResp.setDriverName(tDriver.getName()); |
| | | List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) && |
| | | (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode()) |
| | | || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) |
| | | || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | // 驾龄 |
| | | if(Objects.nonNull(tDriver.getFirstCertificateTime())){ |
| | | Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime())); |
| | | tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1)); |
| | | }else { |
| | | tOrderServerResp.setDrivingExperience(0); |
| | | } |
| | | // 代驾次数 |
| | | tOrderServerResp.setValetDrivingCount(collect.size()); |
| | | // 行驶时间 |
| | | long goTime = 0; |
| | | for (TOrder tOrder : collect) { |
| | | // 下车时间 |
| | | Date getoffTime = tOrder.getGetoffTime(); |
| | | // 上车时间 |
| | | Date boardingTime = tOrder.getBoardingTime(); |
| | | long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes(); |
| | | goTime += Math.abs(minutes); |
| | | } |
| | | tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue()); |
| | | // 行驶里程 |
| | | if(CollectionUtils.isEmpty(collect)){ |
| | | tOrderServerResp.setMileageTraveled(0); |
| | | }else { |
| | | int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum(); |
| | | tOrderServerResp.setMileageTraveled(sum/1000); |
| | | } |
| | | } |
| | | map.put("serverList",orderServerRespList); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RequestMapping("/statistics") |
| | | public String statistics(Integer agentId,String dayDate,String yearDate,String monthDate,Integer type,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | if(Objects.isNull(type)){ |
| | | type = 1; |
| | | } |
| | | model.addAttribute("txt",new SimpleDateFormat("yyyy年MM月dd日").format(new Date()) + DateUtil.getWeekDay(new Date()) + ",欢迎" + |
| | | Objects.requireNonNull(ShiroKit.getUser()).getName() + "登录"); |
| | | // 查询所有代理商 |
| | | List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .ne("status", StatusEnum.DELETE.getCode()) |
| | | .ne("principal","")); |
| | | model.addAttribute("agentList",agentList); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 统计代理商 |
| | | tAgentService.getDataStatistics(agentId,model); |
| | | tAgentService.getDataStatistics(agentId,model,map); |
| | | |
| | | // 统计司机数 |
| | | tDriverService.getDataStatistics(agentId,model); |
| | | tDriverService.getDataStatistics(agentId,model,map); |
| | | |
| | | // TODO 订单统计:按今天,昨天,本周,本月 |
| | | // 订单统计本月 |
| | | tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map); |
| | | |
| | | // 订单统计,每年按月份 |
| | | tOrderService.getDataStatisticsByYear(agentId,yearDate,model); |
| | | tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map); |
| | | |
| | | // 业绩排名 performanceTable |
| | | if (1 == type){ |
| | | // 单量 |
| | | tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model); |
| | | tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map); |
| | | }else { |
| | | // 收入、佣金 |
| | | tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model); |
| | | tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map); |
| | | } |
| | | |
| | | }else { |
| | | // TODO 查询广东全区域数据 |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | 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); |
| | | } |
| | | } |
| | | return PREFIX + "tHomePageStatistics.html"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 首页统计通过代理商查询 |
| | | */ |
| | | @RequestMapping("/statisticsByAgentId") |
| | | @ResponseBody |
| | | public Map<String, Object> statisticsByAgentId(Integer agentId, String dayDate, String yearDate, String monthDate, Integer type, Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 首页统计通过代理商查询订单量 今天,昨天,本周,本月 |
| | | */ |
| | | @RequestMapping("/statisticsMonthByAgentId") |
| | | @ResponseBody |
| | | public Map<String, Object> statisticsMonthByAgentId(Integer agentId, String dayDate,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | dayDate = new SimpleDateFormat("yyyy-MM").format(new Date()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 订单统计本月 |
| | | tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map); |
| | | }else { |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .eq("provinceCode", "440000")); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | // 订单统计本月 |
| | | tOrderService.getStatisticsOrderByMonthIds(ids,dayDate,model,map); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 首页统计通过代理商查询订单量 按年 |
| | | */ |
| | | @RequestMapping("/statisticsYearByAgentId") |
| | | @ResponseBody |
| | | public Map<String, Object> statisticsYearByAgentId(Integer agentId, String yearDate,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | if(!StringUtils.hasLength(yearDate)){ |
| | | yearDate = new SimpleDateFormat("yyyy").format(new Date()); |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 订单统计,每年按月份 |
| | | tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map); |
| | | }else { |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .eq("provinceCode", "440000")); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | tOrderService.getDataStatisticsByYearByIds(ids,yearDate,model,map); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 首页统计通过代理商查询订单量,收入,佣金 按年 |
| | | */ |
| | | @RequestMapping("/statisticsOrderByAgentId") |
| | | @ResponseBody |
| | | public Map<String, Object> statisticsOrderByAgentId(Integer agentId, String monthDate,Integer type,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | if(Objects.isNull(type)){ |
| | | type = 1; |
| | | } |
| | | if(!StringUtils.hasLength(monthDate)){ |
| | | monthDate = new SimpleDateFormat("yyyy-MM").format(new Date()); |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 业绩排名 performanceTable |
| | | if (1 == type){ |
| | | // 单量 |
| | | tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map); |
| | | }else { |
| | | // 收入、佣金 |
| | | tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map); |
| | | } |
| | | }else { |
| | | // 业绩排名 performanceTable |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | List<TAgent> tAgentList = tAgentService.selectList(null); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | if (1 == type){ |
| | | // 单量 |
| | | tOrderService.getDataStatisticsOrderCountByIds(ids,monthDate,model,map); |
| | | }else { |
| | | // 收入、佣金 |
| | | tRevenueService.getDataStatisticsIncomeOrCommissionByIds(ids,monthDate,type,model,map); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 首页统计通过代理商查询司机数量 |
| | | */ |
| | | @RequestMapping("/statisticsDriverByAgentId") |
| | | @ResponseBody |
| | | public Map<String, Object> statisticsDriverByAgentId(Integer agentId,Model model) { |
| | | Integer objectId = ShiroKit.getUser().getObjectId(); |
| | | Integer roleType = ShiroKit.getUser().getRoleType(); |
| | | if(roleType == 3 && Objects.nonNull(objectId)){ |
| | | agentId = objectId; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(Objects.nonNull(agentId)){ |
| | | // 统计司机数 |
| | | tDriverService.getDataStatistics(agentId,model,map); |
| | | tAgentService.getDataStatistics(agentId,model,map); |
| | | }else { |
| | | // 统计司机数 |
| | | // 查询广东全区域数据 查询广东所有的代理商 |
| | | List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>() |
| | | .eq("provinceCode", "440000")); |
| | | List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList()); |
| | | tDriverService.getDataStatisticsByIds(ids,model,map); |
| | | tAgentService.getDataStatisticsByIds(ids,model,map); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | private Map<String,String> geocode(String address){ |
| | | Map<String,String> map = new HashMap<>(2); |
| | | try { |
| | | String url = "https://restapi.amap.com/v3/geocode/geo?address=" + address + "&key=" + gaoDePoJo.getKey(); |
| | | url = url.trim().replace("#", "").replace(" ", ""); |
| | | String result = httpUtils.get(url); |
| | | log.info("地址解析结果:{}", result); |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | if (jsonObject.getString("status").equals("1")) { |
| | | String geocodes = jsonObject.getString("geocodes"); |
| | | JSONArray objects = JSONObject.parseArray(geocodes); |
| | | String string = objects.getString(0); |
| | | JSONObject geocodesObject = JSONObject.parseObject(string); |
| | | log.info("地址数据:{}", geocodesObject); |
| | | String location = geocodesObject.getString("location"); |
| | | String[] split = location.split(","); |
| | | map.put("addressLon",split[0]); |
| | | map.put("addressLat",split[1]); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("解析地址失败============:{}", e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | } |