puzhibing
2023-02-24 b4d8cb69ff3a3d35a10a7e5c487ff683b31cc9f1
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java
@@ -1,19 +1,25 @@
package com.stylefeng.guns.modular.system.controller.general;
import com.alibaba.fastjson.JSONObject;
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.shiro.ShiroUser;
import com.stylefeng.guns.modular.system.controller.resp.TDriverResp;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
import com.stylefeng.guns.modular.system.model.TAgent;
import com.stylefeng.guns.modular.system.model.TAppUser;
import com.stylefeng.guns.modular.system.controller.util.*;
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 io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.core.util.UuidUtil;
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.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,10 +29,10 @@
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.model.TDriver;
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;
@@ -34,6 +40,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 控制器
@@ -50,12 +57,35 @@
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private ITRegionService tRegionService;
    @Autowired
    private ITAgentService tAgentService;
    @Autowired
    private ITBranchOfficeService tBranchOfficeService;
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private HttpUtils httpUtils;
    @Autowired
    private TokenUtils tokenUtils;
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tDriver.html";
    }
    /**
     * 跳转到佣金首页
     */
    @RequestMapping("/commission")
    public String commissionIndex() {
        return PREFIX + "tDriverCommission.html";
    }
    /**
@@ -69,10 +99,31 @@
    /**
     * 跳转到修改
     */
    @RequestMapping("/tDriver_update/{tDriverId}")
    public String tDriverUpdate(@PathVariable Integer tDriverId, Model model) {
    @RequestMapping("/tDriver_update")
    public String tDriverUpdate( Integer tDriverId, Model model) {
        TDriver tDriver = tDriverService.selectById(tDriverId);
        model.addAttribute("item",tDriver);
        TDriverResp tDriverResp = new TDriverResp();
        BeanUtils.copyProperties(tDriver,tDriverResp);
        // 查询邀请人
        TDriver tDriver1 = tDriverService.selectById(tDriver.getInviterId());
        if(Objects.nonNull(tDriver1)){
            tDriverResp.setInviterName(tDriver1.getName());
            tDriverResp.setInviterPhone(tDriver1.getPhone());
        }
        // 查询区域
        TRegion district = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", tDriver.getAreaCode())
                .last("LIMIT 1"));
        TRegion city = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", tDriver.getCityCode())
                .last("LIMIT 1"));
        tDriverResp.setArea(tDriver.getProvinceName()+"/"+tDriver.getCityName()+"/"+tDriver.getAreaName());
        if(Objects.nonNull(district) && Objects.nonNull(city)){
            tDriverResp.setAreaId(city.getParentId()+"/"+city.getId()+"/"+district.getId());
        }
        model.addAttribute("item",tDriverResp);
        LogObjectHolder.me().set(tDriver);
        return PREFIX + "tDriver_edit.html";
    }
@@ -139,9 +190,39 @@
     */
    @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(String area,String areaId,Model model) {
        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>().in("parent_id", provinceIds));
        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]);
            model.addAttribute("districtName",split[2]);
            String[] split1 = areaId.split("/");
            model.addAttribute("provinceId",split1[0]);
            model.addAttribute("cityId",split1[1]);
            model.addAttribute("districtId",split1[2]);
        }
        return PREFIX + "tDriverArea.html";
    }
    /**
@@ -151,6 +232,17 @@
    @ResponseBody
    public Object list(String createTime,String phone,Integer status) {
        EntityWrapper<TDriver> wrapper = tDriverService.getPageList(createTime,phone,status);
        wrapper.ne("isException",2);
        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);
        wrapper.ne("isException",2);
        List<TDriver> tDrivers = tDriverService.selectList(wrapper);
        return tDriverService.getTDriverResp(tDrivers);
@@ -174,6 +266,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);
    }
    /**
@@ -200,6 +310,12 @@
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TDriver tDriver) {
        int count = tDriverService.selectCount(new EntityWrapper<TDriver>().eq("phone", tDriver.getPhone()));
        if(count>0){
            return "该司机已存在!";
        }
        tDriverService.addOrUpdate(tDriver);
        tDriverService.insert(tDriver);
        return SUCCESS_TIP;
    }
@@ -252,6 +368,9 @@
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TDriver tDriver) {
//        Object ocr = ocr("E:\\071bf986db0b00355c0ed190bbd3b16.png");
//        System.err.println(ocr);
        tDriverService.addOrUpdate(tDriver);
        tDriverService.updateById(tDriver);
        return SUCCESS_TIP;
    }
@@ -265,6 +384,24 @@
        return tDriverService.selectById(tDriverId);
    }
    @ApiOperation(value = "省查询",notes="省查询")
    @RequestMapping(value = "/areaProvince")
    @ResponseBody
    public Object areaProvince(Model model) {
        return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
    }
    @ApiOperation(value = "市区查询",notes="市区查询")
    @RequestMapping(value = "/areaCity")
    @ResponseBody
    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;
    }
    @ApiOperation(value = "导出司机列表",notes="导出司机列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),