wang-hao-jie
2021-12-02 dfd4959471c057749b4db755ea141fca76e73357
xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/OrderTaskController.java
@@ -5,13 +5,10 @@
import cn.exrick.xboot.core.common.utils.SecurityUtil;
import cn.exrick.xboot.core.common.vo.PageVo;
import cn.exrick.xboot.core.common.vo.Result;
import cn.exrick.xboot.your.entity.Area;
import cn.exrick.xboot.your.entity.OrderDetail;
import cn.exrick.xboot.your.entity.OrderTask;
import cn.exrick.xboot.your.service.IAreaService;
import cn.exrick.xboot.your.service.ICustomerService;
import cn.exrick.xboot.your.service.IOrderDetailService;
import cn.exrick.xboot.your.service.IOrderTaskService;
import cn.exrick.xboot.core.entity.User;
import cn.exrick.xboot.core.service.UserService;
import cn.exrick.xboot.your.entity.*;
import cn.exrick.xboot.your.service.*;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -53,6 +50,15 @@
    @Autowired
    private SecurityUtil securityUtil;
    @Autowired
    private UserService userService;
    @Autowired
    private IAreaSectionService iAreaSectionService;
    @Autowired
    private ICarService iCarService;
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<OrderTask> get(@PathVariable String id) {
@@ -61,12 +67,27 @@
        return new ResultUtil<OrderTask>().setData(orderTask);
    }
    public Area getArea(String userId){
        QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
        wrapper.eq("user_id",userId);
        Area area = iAreaService.getOne(wrapper);
        if(area==null){
            QueryWrapper<Car> carQueryWrapper = new QueryWrapper<Car>();
            carQueryWrapper.eq("user_id",userId);
            Car one = iCarService.getOne(carQueryWrapper);
            QueryWrapper<Area> wrapper3 = new QueryWrapper<Area>();
            wrapper3.eq("user_id",one.getFollowUserId());
            area = iAreaService.getOne(wrapper);
            return area;
        }
        return area;
    }
    @RequestMapping(value = "/getByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日任务统计信息")
    public Result<Object> getAll() {
        QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
        wrapper.eq("user_id",securityUtil.getCurrUser().getId());
        Area area = iAreaService.getOne(wrapper);
        Area area = getArea(securityUtil.getCurrUser().getId());
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
        }
@@ -75,22 +96,27 @@
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        wrapper2.eq("area_id",area.getId());
        wrapper2.eq("send_date",format);
        int count = iOrderTaskService.count(wrapper2);
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        int sum = iOrderTaskService.sum(area.getId(),format);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("count",count);
        map.put("count",list.size());
        map.put("sum",sum);
        map.put("name","");
        if(list.size()>0){
            String areaSectionId = list.get(0).getAreaSectionId();
            AreaSection a = iAreaSectionService.getById(areaSectionId);
            map.put("name",a.getName());
            list.clear();
        }
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/getTodayOrder", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日任务详情")
    public Result<List<OrderTask>> getTodayOrder() {
        QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
        wrapper.eq("user_id",securityUtil.getCurrUser().getId());
        Area area = iAreaService.getOne(wrapper);
        Area area = getArea(securityUtil.getCurrUser().getId());
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
        }
@@ -114,9 +140,7 @@
                return ResultUtil.error("此商户已配送");
            }
        }else{
            QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
            wrapper.eq("user_id",securityUtil.getCurrUser().getId());
            Area area = iAreaService.getOne(wrapper);
            Area area = getArea(securityUtil.getCurrUser().getId());
            if(area==null){
                return ResultUtil.error("请联系管理员绑定片区配送员");
            }
@@ -125,7 +149,7 @@
            String format = DateUtil.format(new Date(), "yyyy-MM-dd");
            wrapper2.eq("area_id",area.getId());
            wrapper2.eq("send_date",format);
            wrapper2.ne("status",0);
            wrapper2.eq("status",0);
            wrapper2.orderByAsc("seq");
            List<OrderTask> list = iOrderTaskService.list(wrapper2);
            if(list.size()>0){
@@ -143,6 +167,96 @@
        return new ResultUtil<OrderTask>().setData(orderTask);
    }
    @RequestMapping(value = "/getTodayOtherInfo", method = RequestMethod.GET)
    @ApiOperation(value = "获取其它信息")
    public Result<Object> getTodayOtherInfo() {
        Area area = getArea(securityUtil.getCurrUser().getId());
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
        }
        QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        wrapper2.eq("area_id",area.getId());
        wrapper2.eq("send_date",format);
        wrapper2.ne("status",0);
        wrapper2.orderByAsc("seq");
        int count = iOrderTaskService.count(wrapper2);
        QueryWrapper<OrderTask> wrapper4 = new QueryWrapper<OrderTask>();
        wrapper4.eq("area_id",area.getId());
        wrapper4.eq("send_date",format);
        int count2 = iOrderTaskService.count(wrapper4);
        Map<String,Object> map = new HashMap<>();
        map.put("num",count+"/"+count2);
        QueryWrapper<OrderTask> wrapper5 = new QueryWrapper<OrderTask>();
        wrapper5.ne("status",0);
        wrapper5.eq("send_date",format);
        PageVo page = new PageVo();
        page.setSort("updateTime");
        page.setOrder("desc");
        page.setPageSize(1);
        page.setPageNumber(0);
        IPage<OrderTask> data = iOrderTaskService.page(PageUtil.initMpPage(page), wrapper5);
        String content = "";
        if(data.getRecords().size()>0){
            String userId = data.getRecords().get(0).getUserId();
            User user = userService.get(userId);
            QueryWrapper<OrderTask> wrapper6 = new QueryWrapper<OrderTask>();
            wrapper6.eq("user_id",userId);
            wrapper6.eq("send_date",format);
            wrapper6.ne("status",0);
            int count6 = iOrderTaskService.count(wrapper6);
            if(count6>0){
                content+=user.getNickname()+"已配送"+count6+"单";
            }
        }
        map.put("content",content);
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/addImg", method = RequestMethod.POST)
    @ApiOperation(value = "上传门头照")
    public Object saveOrUpdate(String orderId,String imgUrl) {
        OrderTask orderTask = iOrderTaskService.getById(orderId);
        orderTask.setImg(imgUrl);
        iOrderTaskService.saveOrUpdate(orderTask);
        return ResultUtil.success("添加成功");
    }
    @RequestMapping(value = "/signFor", method = RequestMethod.POST)
    @ApiOperation(value = "签收")
    public Object signFor(String orderId,int status,String content,String customerReceiveId) {
        if(status==1){
            if(StrUtil.isEmpty(customerReceiveId)){
                return ResultUtil.error("正常签收,接货人id必填");
            }
        }
        OrderTask orderTask = iOrderTaskService.getById(orderId);
        orderTask.setStatus(status);
        orderTask.setUserId(securityUtil.getCurrUser().getId());
        if(StrUtil.isNotEmpty(customerReceiveId)){
            orderTask.setCustomerReceiveId(customerReceiveId);
        }
        if(!StrUtil.isEmpty(content)){
            orderTask.setRemarks(content);
        }else{
            if(status==2){
                return ResultUtil.error("请填写异常签收原因");
            }
        }
        iOrderTaskService.saveOrUpdate(orderTask);
        return ResultUtil.success("添加成功");
    }
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<OrderTask>> getByPage(PageVo page) {