From 1b6c4cd60f3882c400d30af367bd4c5960fbd4a1 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期一, 10 四月 2023 15:02:24 +0800
Subject: [PATCH] 优化管理

---
 management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java |  315 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 258 insertions(+), 57 deletions(-)

diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java
index 907dfaa..f139140 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java
@@ -1,16 +1,18 @@
 package com.stylefeng.guns.modular.system.controller.general;
 
+import cn.hutool.core.util.CreditCodeUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.stylefeng.guns.core.base.controller.BaseController;
+import com.stylefeng.guns.core.base.tips.SuccessTip;
 import com.stylefeng.guns.core.shiro.ShiroKit;
 import com.stylefeng.guns.core.shiro.ShiroUser;
+import com.stylefeng.guns.modular.system.controller.resp.TDriverCommissionResp;
 import com.stylefeng.guns.modular.system.controller.resp.TDriverResp;
-import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
-import com.stylefeng.guns.modular.system.controller.util.UUIDUtil;
+import com.stylefeng.guns.modular.system.controller.util.*;
+import com.stylefeng.guns.modular.system.enums.UserTypeEnum;
 import com.stylefeng.guns.modular.system.model.*;
-import com.stylefeng.guns.modular.system.service.ITAgentService;
-import com.stylefeng.guns.modular.system.service.ITBranchOfficeService;
-import com.stylefeng.guns.modular.system.service.ITRegionService;
+import com.stylefeng.guns.modular.system.service.*;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiModelProperty;
@@ -19,7 +21,9 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.shiro.subject.Subject;
 import org.springframework.beans.BeanUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -28,16 +32,18 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import com.stylefeng.guns.core.log.LogObjectHolder;
 import org.springframework.web.bind.annotation.RequestParam;
-import com.stylefeng.guns.modular.system.service.ITDriverService;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * 控制器
@@ -62,6 +68,14 @@
 
     @Autowired
     private ITBranchOfficeService tBranchOfficeService;
+    @Autowired
+    private RedisTemplate<String,String> redisTemplate;
+    @Autowired
+    private HttpUtils httpUtils;
+    @Autowired
+    private TokenUtils tokenUtils;
+    @Autowired
+    private ITRechargeRecordService tRechargeRecordService;
 
     /**
      * 跳转到首页
@@ -69,6 +83,14 @@
     @RequestMapping("")
     public String index() {
         return PREFIX + "tDriver.html";
+    }
+
+    /**
+     * 跳转到佣金首页
+     */
+    @RequestMapping("/commission")
+    public String commissionIndex() {
+        return PREFIX + "tDriverCommission.html";
     }
 
     /**
@@ -173,18 +195,98 @@
      */
     @RequestMapping("/driverDetail")
     public String driverDetail(Integer tDriverId, Model model) {
-        tDriverService.detail(tDriverId,model);
+        tDriverService.auditPage(tDriverId,model);
         return PREFIX + "tDriverDetail.html";
     }
 
     /**
-     * 跳转区域页面
+     * 佣金跳转详情页面
      */
-    @RequestMapping("/areaPage")
-    public String areaDetail(Model model) {
+    @RequestMapping("/commission/driverCommissionDetail")
+    public String driverCommissionDetail(Integer tDriverId, Model model) {
+        tDriverService.driverCommissionDetail(tDriverId,model);
+        return PREFIX + "tDriverCommissionDetail.html";
+    }
+
+    /**
+     * 跳转区域页面编辑
+     */
+    @RequestMapping("/areaPageUpdate")
+    public String areaPageUpdate(String area,String areaId,Model model) {
+
+        String[] split = area.split("/");
+        model.addAttribute("provinceName",split[0]);
+        model.addAttribute("cityName",split[1]);
+        model.addAttribute("districtName",split[2]);
+
+        String[] split1 = areaId.split("/");
+        model.addAttribute("provinceId",split1[0]);
+        model.addAttribute("cityId",split1[1]);
+        model.addAttribute("districtId",split1[2]);
+
+
         List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
-        model.addAttribute("province",tRegions);
-        return PREFIX + "tDriverArea.html";
+        model.addAttribute("provinceList",tRegions);
+        List<Integer> provinceIds = tRegions.stream().map(TRegion::getId).collect(Collectors.toList());
+
+
+        // 查询市
+        List<TRegion> tRegions1 = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", split1[0]));
+        model.addAttribute("cityList",tRegions1);
+
+        // 查询区
+        List<Integer> cityIds = tRegions1.stream().map(TRegion::getId).collect(Collectors.toList());
+        List<TRegion> tRegions2 = tRegionService.selectList(new EntityWrapper<TRegion>().in("parent_id", cityIds));
+        model.addAttribute("districtList",tRegions2);
+
+        return PREFIX + "tDriverAreaUpdate.html";
+    }
+
+    /**
+     * 跳转区域页面新增
+     */
+    @RequestMapping("/areaPageAdd")
+    public String areaPageAdd(String area,String areaId,Model model) {
+        String[] split1 = areaId.split("/");
+        List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
+        model.addAttribute("provinceList",tRegions);
+        List<Integer> provinceIds = tRegions.stream().map(TRegion::getId).collect(Collectors.toList());
+        // 查询市
+        List<TRegion> tRegions1 = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", split1[0]));
+        model.addAttribute("cityList",tRegions1);
+
+        // 查询区
+        List<Integer> cityIds = tRegions1.stream().map(TRegion::getId).collect(Collectors.toList());
+        List<TRegion> tRegions2 = tRegionService.selectList(new EntityWrapper<TRegion>().in("parent_id", cityIds));
+        model.addAttribute("districtList",tRegions2);
+
+        if(StringUtils.hasLength(area) && StringUtils.hasLength(areaId)){
+            String[] split = area.split("/");
+            model.addAttribute("provinceName",split[0]);
+            model.addAttribute("cityName",split[1]);
+            if(split.length>2){
+                model.addAttribute("districtName",split[2]);
+            }else {
+                model.addAttribute("districtName","");
+            }
+
+            model.addAttribute("provinceId",split1[0]);
+            model.addAttribute("cityId",split1[1]);
+            if(split1.length>2) {
+                model.addAttribute("districtId", split1[2]);
+            }else {
+                model.addAttribute("districtId", "");
+            }
+        }else {
+            model.addAttribute("provinceName","");
+            model.addAttribute("cityName","split[1]");
+            model.addAttribute("districtName","");
+
+            model.addAttribute("provinceId","");
+            model.addAttribute("cityId","split1[1]");
+            model.addAttribute("districtId", "");
+        }
+        return PREFIX + "tDriverAreaAdd.html";
     }
 
     /**
@@ -195,8 +297,19 @@
     public Object list(String createTime,String phone,Integer status) {
         EntityWrapper<TDriver> wrapper = tDriverService.getPageList(createTime,phone,status);
         wrapper.ne("isException",2);
+        wrapper.orderBy("createTime",false);
         List<TDriver> tDrivers = tDriverService.selectList(wrapper);
         return tDriverService.getTDriverResp(tDrivers);
+    }
+    /**
+     * 获取佣金列表
+     */
+    @RequestMapping(value = "/commission/list")
+    @ResponseBody
+    public Object commissionList(String name,String phone,Integer status) {
+        EntityWrapper<TDriver> wrapper = tDriverService.getCommissionPageList(name,phone,status);
+        List<TDriver> tDrivers = tDriverService.selectList(wrapper);
+        return tDriverService.getTDriverCommissionResp(tDrivers);
     }
     /**
      * 获取异常列表
@@ -206,8 +319,35 @@
     public Object exceptionList(String createTime,String phone,Integer status) {
         EntityWrapper<TDriver> wrapper = tDriverService.getPageList(createTime,phone,status);
         wrapper.eq("isException",2);
+        wrapper.orderBy("createTime",false);
         List<TDriver> tDrivers = tDriverService.selectList(wrapper);
         return tDriverService.getTDriverResp(tDrivers);
+    }
+
+    /**
+     * 佣金关联列表
+     */
+    @RequestMapping(value = "/commission/connect/list")
+    @ResponseBody
+    public Object commissionConnectList(String driverId) {
+
+        // 查询当前用户的用户信息
+        TDriver tDriver = tDriverService.selectById(driverId);
+
+        EntityWrapper<TDriver> wrapper = new EntityWrapper<>();
+        if(StringUtils.hasLength(driverId)){
+            wrapper.eq("inviterId",driverId);
+        }
+        wrapper.orderBy("createTime",false);
+        List<TDriver> list = tDriverService.selectList(wrapper);
+        List<TDriverCommissionResp> commissionResp = tDriverService.getTDriverCommissionResp(list);
+        for (TDriverCommissionResp tDriverCommissionResp : commissionResp) {
+            if(Objects.nonNull(tDriver)){
+                tDriverCommissionResp.setInviterName(tDriver.getName());
+                tDriverCommissionResp.setInviterPhone(tDriver.getPhone());
+            }
+        }
+        return commissionResp;
     }
 
     /**
@@ -217,6 +357,24 @@
     @ResponseBody
     public Object listBack(String condition) {
         return tDriverService.selectList(null);
+    }
+    /**
+     * ocr
+     */
+    @RequestMapping(value = "/ocr")
+    @ResponseBody
+    public Object ocr(String imgUrl) {
+        /*String accessToken = redisTemplate.opsForValue().get(TokenUtils.ACCESS_TOKEN_CACHE_KEY);
+        if (!StringUtils.hasLength(accessToken)) {
+            accessToken = tokenUtils.getSimpleAccessToken();
+        }
+        File file = new File(imgUrl);
+        String url = Constant.OCR_URL.replace("MODE", "scan").replace("ACCESS_TOKEN", accessToken);
+        String result = httpUtils.registRequest(url, file);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        System.err.println(jsonObject);
+        return jsonObject;*/
+        return tDriverService.ocr(imgUrl);
     }
 
     /**
@@ -246,53 +404,17 @@
 
         int count = tDriverService.selectCount(new EntityWrapper<TDriver>().eq("phone", tDriver.getPhone()));
         if(count>0){
-            return "该司机已存在!";
+            return new SuccessTip(500,"该司机已存在!");
         }
-
-        // 对省市区做处理
-        String[] split = tDriver.getAreaId().split("/");
-        // 查询省市
-        // 黑龙江省/大兴安岭地区
-        // 702/852
-        TRegion province = tRegionService.selectById(split[0]);
-        tDriver.setProvinceName(province.getName());
-        tDriver.setProvinceCode(province.getCode());
-
-        TRegion city = tRegionService.selectById(split[1]);
-        tDriver.setCityName(city.getName());
-        tDriver.setCityCode(city.getCode());
-
-        TRegion area = tRegionService.selectById(split[2]);
-        tDriver.setAreaName(area.getName());
-        tDriver.setAreaCode(area.getCode());
-
+        Object o = tDriverService.addOrUpdate(tDriver);
+        if(Objects.nonNull(o)){
+            return o;
+        }
+        // 默认值板块
         tDriver.setCode(UUIDUtil.getNumberRandom(16));
         tDriver.setBalance(BigDecimal.ZERO);
         tDriver.setBackgroundBalance(BigDecimal.ZERO);
-
-        // 通过省市查询代理商
-        TAgent tAgent = tAgentService.selectOne(new EntityWrapper<TAgent>().eq("provinceCode", province.getCode())
-                .eq("cityCode", city.getCode())
-                .last("LIMIT 1"));
-        if(Objects.nonNull(tAgent)){
-            tDriver.setAgentId(tAgent.getId());
-        }
-        // 查询邀约人(司机端)
-        TDriver emergencyDriver = tDriverService.selectOne(new EntityWrapper<TDriver>().eq("phone", tDriver.getEmergencyPhone())
-                .last("LIMIT 1"));
-        if(Objects.nonNull(emergencyDriver)){
-            tDriver.setInviterId(emergencyDriver.getId());
-            tDriver.setInviterType(2);
-        }
-        // 通过省市区查询分公司
-        TBranchOffice tBranchOffice = tBranchOfficeService.selectOne(new EntityWrapper<TBranchOffice>().eq("provinceCode", province.getCode())
-                .eq("cityCode", city.getCode())
-                .eq("districtCode", area.getCode())
-                .last("LIMIT 1"));
-        if(Objects.nonNull(tBranchOffice)){
-            tDriver.setBranchOfficeId(tBranchOffice.getId());
-        }
-
+        tDriver.setCommission(BigDecimal.ZERO);
         tDriverService.insert(tDriver);
         return SUCCESS_TIP;
     }
@@ -331,11 +453,25 @@
      */
     @ApiOperation(value = "充值余额")
     @RequestMapping(value = "/recharge-balance")
+    @Transactional(rollbackFor = Exception.class)
     @ResponseBody
     public Object rechargeBalance(Integer id, String money) {
         TDriver tDriver = tDriverService.selectById(id);
         tDriver.setBackgroundBalance(new BigDecimal(money).add(tDriver.getBackgroundBalance()));
         tDriverService.updateById(tDriver);
+
+        // 添加充值记录
+        TRechargeRecord tRechargeRecord = new TRechargeRecord();
+        tRechargeRecord.setType(UserTypeEnum.AGENT.getCode());
+        tRechargeRecord.setUserId(id);
+        tRechargeRecord.setCode(UUIDUtil.getNumberRandom(16));
+        tRechargeRecord.setAmount(new BigDecimal(money));
+        tRechargeRecord.setPayType(2);
+        tRechargeRecord.setPayTime(new Date());
+        tRechargeRecord.setPayStatus(2);
+        tRechargeRecord.setCreateTime(new Date());
+        tRechargeRecord.setAgentId(Objects.requireNonNull(ShiroKit.getUser()).getId());
+        tRechargeRecordService.insert(tRechargeRecord);
         return SUCCESS_TIP;
     }
 
@@ -345,6 +481,17 @@
     @RequestMapping(value = "/update")
     @ResponseBody
     public Object update(TDriver tDriver) {
+        TDriver driver = tDriverService.selectOne(new EntityWrapper<TDriver>().eq("phone", tDriver.getPhone())
+                .last("LIMIT 1"));
+        if(Objects.nonNull(driver) && !tDriver.getId().equals(driver.getId())){
+            return new SuccessTip(500,"该司机已存在!");
+        }
+//        Object ocr = ocr("E:\\071bf986db0b00355c0ed190bbd3b16.png");
+//        System.err.println(ocr);
+        Object o = tDriverService.addOrUpdate(tDriver);
+        if(Objects.nonNull(o)){
+            return o;
+        }
         tDriverService.updateById(tDriver);
         return SUCCESS_TIP;
     }
@@ -368,8 +515,10 @@
     @ApiOperation(value = "市区查询",notes="市区查询")
     @RequestMapping(value = "/areaCity")
     @ResponseBody
-    public Object areaCity(Integer parentId) {
-        return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id",parentId));
+    public Object areaCity(Integer parentId,Model model) {
+        List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", parentId));
+        model.addAttribute("list",tRegions);
+        return tRegions;
     }
 
 
@@ -504,4 +653,56 @@
             e.printStackTrace();
         }
     }
+    @ApiOperation(value = "导出司机异常列表",notes="导出司机异常列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+    })
+    @RequestMapping(value = "/export-commission")
+    @ResponseBody
+    public void exportCommission(String name,String phone,Integer status,HttpServletResponse response) {
+        try {
+            Date date = new Date();
+            DateFormat format = new SimpleDateFormat("yyyyMMdd");
+            String time1 = format.format(date);
+            String fileName = "CommissionInfo"+time1+".xls";
+            String[] title = new String[] {"姓名","手机号","所属代理商","推广人数","关联人数",
+                    "累计获得佣金","可提现佣金","已提现金额","状态"};
+            EntityWrapper<TDriver> wrapper = tDriverService.getCommissionPageList(name,phone,status);
+//            wrapper.ne("isException",2);
+            // 是否异常
+            List<TDriver> list = tDriverService.selectList(wrapper);
+
+            List<TDriverCommissionResp> commissionResp = tDriverService.getTDriverCommissionResp(list);
+
+            String[][] values = new String[commissionResp.size()][];
+            for (int i = 0; i < commissionResp.size(); i++) {
+                TDriverCommissionResp d = commissionResp.get(i);
+                values[i] = new String[title.length];
+                values[i][0] = d.getName();
+                values[i][1] = d.getPhone();
+                values[i][2] = d.getAgentName();
+                values[i][3] = String.valueOf(Objects.isNull(d.getNumberPromoters()) ? 0:d.getNumberPromoters());
+                values[i][4] = String.valueOf(d.getConnectedPersons());
+                values[i][5] = String.valueOf(d.getAccumulatedCommission());
+                values[i][6] = String.valueOf(Objects.isNull(d.getCommission())?0:d.getCommission());
+                values[i][7] = String.valueOf(d.getWithdrawnAmount());
+                Integer status1 = d.getStatus();
+                if(1 == status1){
+                    values[i][8] = "正常";
+                }else if(2 == status1){
+                    values[i][8] = "冻结";
+                }else if(3 == status1){
+                    values[i][8] = "已删除";
+                }
+            }
+            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
+            ExcelUtil.setResponseHeader(response, fileName);
+            OutputStream os = response.getOutputStream();
+            wb.write(os);
+            os.flush();
+            os.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }

--
Gitblit v1.7.1