From 709a4a10be56952ead6340e4822fce41a66e47cd Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 26 七月 2023 18:39:28 +0800
Subject: [PATCH] Merge branch '1.1' of http://120.76.84.145:10101/gitblit/r/java/SuperSaveDriving into dev

---
 management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/THomePageController.java |  589 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 583 insertions(+), 6 deletions(-)

diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/THomePageController.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/THomePageController.java
index 4e36492..2d9c748 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/THomePageController.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/THomePageController.java
@@ -1,17 +1,43 @@
 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.baomidou.mybatisplus.mapper.Wrapper;
+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.modular.system.service.IUserService;
+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.util.Date;
-import java.util.Objects;
+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;
 
 /**
  * 控制器
@@ -23,8 +49,26 @@
 @RequestMapping("/tHomePage")
 public class THomePageController extends BaseController {
 
+    private final static Logger log = LoggerFactory.getLogger(THomePageController.class);
+
     @Autowired
     private IUserService userService;
+    @Autowired
+    private ITAgentService tAgentService;
+    @Autowired
+    private ITDriverService tDriverService;
+    @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/";
 
@@ -32,18 +76,551 @@
      * 跳转到地图
      */
     @RequestMapping("/map")
-    public String map() {
+    public String map(Integer agentId,Integer type,Model model) {
+
+        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"));
+        // 查询广东全区域数据 查询广东所有的代理商
+        Wrapper<TAgent> status = new EntityWrapper<TAgent>().eq("status", 1);
+        if(null != agentId){
+            status.eq("id", agentId);
+        }
+        List<TAgent> tAgentList = tAgentService.selectList(status);
+        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) {
+        Map<String, Object> maps = new HashMap<>();
+
+        Wrapper<TOrder> last = new EntityWrapper<TOrder>().eq("state", 301).eq("status", 1);
+        if(null != agentId){
+            last.eq("agentId", agentId);
+        }
+        List<TOrder> tOrders = tOrderService.selectList(last.last(" and UNIX_TIMESTAMP(createTime) + 7200 >= UNIX_TIMESTAMP(NOW())"));
+        List<Map<String, Object>> cancel = new ArrayList<>();
+        for (TOrder order : tOrders) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("lonLat", order.getStartLng() + "," + order.getStartLat());
+            cancel.add(map);
+        }
+        maps.put("cancel", cancel);
+        Wrapper<TDriver> eq = new EntityWrapper<TDriver>().eq("serverStatus", 1).eq("approvalStatus", 2).eq("status", 1);
+        if(null != agentId){
+            eq.eq("agentId", agentId);
+        }
+        List<TDriver> tDrivers = tDriverService.selectList(eq);
+        List<Map<String, Object>> leisure = new ArrayList<>();
+        for (TDriver tDriver : tDrivers) {
+            String value = redisUtil.getValue("DRIVER" + tDriver.getId());
+            if(ToolUtil.isEmpty(value)){
+                continue;
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", tDriver.getName());
+            map.put("lonLat", value);
+            leisure.add(map);
+        }
+        maps.put("leisure", leisure);
+
+        Wrapper<TOrder> en = new EntityWrapper<TOrder>().in("state", Arrays.asList(103, 104, 105, 106)).eq("status", 1);
+        if(null != agentId){
+            en.eq("agentId", agentId);
+        }
+        List<TOrder> tOrders1 = tOrderService.selectList(en);
+        List<Map<String, Object>> receivedOrder = new ArrayList<>();
+        for (TOrder order : tOrders1) {
+            String value = redisUtil.getValue("DRIVER" + order.getDriverId());
+            if(ToolUtil.isEmpty(value)){
+                continue;
+            }
+            TDriver tDriver = tDriverService.selectById(order.getDriverId());
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", tDriver.getName());
+            map.put("lonLat", value);
+            receivedOrder.add(map);
+        }
+        maps.put("receivedOrder", receivedOrder);
+
+
+        Wrapper<TOrder> en1 = new EntityWrapper<TOrder>().eq("state", 102).eq("status", 1);
+        if(null != agentId){
+            en1.eq("agentId", agentId);
+        }
+        List<TOrder> tOrders2 = tOrderService.selectList(en1);
+        List<Map<String, Object>> service = new ArrayList<>();
+        for (TOrder order : tOrders2) {
+            TDriver tDriver = tDriverService.selectById(order.getDriverId());
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", tDriver.getName());
+            map.put("lonLat", order.getStartLng() + "," + order.getStartLat());
+            service.add(map);
+        }
+        maps.put("service", service);
+
+
+        List<TOrder> tOrders3 = tOrderService.selectList(new EntityWrapper<TOrder>().eq("state", 101).eq("hallOrder", 1).eq("status", 1));
+        List<Map<String, Object>> lobby = new ArrayList<>();
+        for (TOrder order : tOrders3) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("lonLat", order.getStartLng() + "," + order.getStartLat());
+            lobby.add(map);
+        }
+        maps.put("lobby", lobby);
+        return maps;
+    }
+
+    @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(Model model) {
+    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,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);
+            }
+
+        }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);
+            }
+        }
         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;
+    }
+
 }

--
Gitblit v1.7.1