xuhy
2023-05-16 f0b4d0e6bc47a18f4e10ca4c007dcaa01c9c9647
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TBranchOfficeController.java
@@ -7,9 +7,10 @@
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.controller.resp.TBranchOfficeResp;
import com.stylefeng.guns.modular.system.controller.resp.TDriverResp;
import com.stylefeng.guns.modular.system.enums.StatusEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.ITRegionService;
import com.stylefeng.guns.modular.system.service.ITSystemConfigService;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
@@ -22,8 +23,8 @@
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.ITBranchOfficeService;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -47,12 +48,19 @@
    @Autowired
    private ITRegionService tRegionService;
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private ITDriverWorkService tDriverWorkService;
    @Autowired
    private RedisUtil redisUtil;
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
    public String index(Model model) {
        model.addAttribute("userType", Objects.requireNonNull(ShiroKit.getUser()).getRoleType());
        return PREFIX + "tBranchOffice.html";
    }
@@ -206,6 +214,9 @@
    @ResponseBody
    public Object list(String branchOfficeName,String principal,String principalPhone,Integer operatingBusiness ,Integer status) {
        List<TBranchOfficeResp> tBranchOfficeRespList = tBranchOfficeService.getPageList(branchOfficeName,principal,principalPhone,operatingBusiness,status);
        for (TBranchOfficeResp tBranchOfficeResp : tBranchOfficeRespList) {
            tBranchOfficeResp.setUserType(Objects.requireNonNull(ShiroKit.getUser()).getRoleType());
        }
        // 分公司查询优惠券,订单,司机等信息
        tBranchOfficeService.queryOtherInfo(tBranchOfficeRespList);
        return tBranchOfficeRespList;
@@ -231,7 +242,7 @@
    @ResponseBody
    public Object start(Integer id) {
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(id);
        tBranchOffice.setStatus(1);
        tBranchOffice.setStatus(StatusEnum.NORMAL.getCode());
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }
@@ -243,8 +254,25 @@
    @ResponseBody
    public Object updateStatus(Integer id) {
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(id);
        tBranchOffice.setStatus(2);
        tBranchOffice.setStatus(StatusEnum.FREEZE.getCode());
        tBranchOfficeService.updateById(tBranchOffice);
        List<TDriver> list = tDriverService.selectList(new EntityWrapper<TDriver>()
                .eq("branchOfficeId", tBranchOffice.getId()));
        for (TDriver tDriver : list) {
            String value = redisUtil.getValue("DRIVER_" + tDriver.getPhone());
            redisUtil.remove(value);
            redisUtil.remove("DRIVER_" + tDriver.getPhone());
            TDriverWork tDriverWork = tDriverWorkService.selectOne(new EntityWrapper<TDriverWork>()
                    .eq("driverId", tDriver.getId())
                    .eq("status", 1)
                    .orderBy("workTime", false)
                    .last("LIMIT 1"));
            if(Objects.nonNull(tDriverWork)){
                tDriverWork.setStatus(2);
                tDriverWork.setOffWorkTime(new Date());
                tDriverWorkService.updateById(tDriverWork);
            }
        }
        return SUCCESS_TIP;
    }
@@ -272,7 +300,8 @@
        if(Objects.nonNull(o)){
            return o;
        }
        tBranchOffice.setStatus(1);
        tBranchOffice.setPrincipal(tBranchOffice.getPrincipal().replace(" ",""));
        tBranchOffice.setStatus(StatusEnum.NORMAL.getCode());
        tBranchOfficeService.insert(tBranchOffice);
        return SUCCESS_TIP;
@@ -284,7 +313,9 @@
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tBranchOfficeId) {
        tBranchOfficeService.deleteById(tBranchOfficeId);
        TBranchOffice tBranchOffice = tBranchOfficeService.selectById(tBranchOfficeId);
        tBranchOffice.setStatus(StatusEnum.DELETE.getCode());
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }
@@ -305,6 +336,7 @@
        if(Objects.nonNull(o)){
            return o;
        }
        tBranchOffice.setPrincipal(tBranchOffice.getPrincipal().replace(" ",""));
        tBranchOfficeService.updateById(tBranchOffice);
        return SUCCESS_TIP;
    }