kongdeqiang
2023-02-10 93a3a1de1d52c014368a1200139fa46969a80c66
xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/OrderTaskController.java
@@ -5,17 +5,15 @@
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.core.entity.Department;
import cn.exrick.xboot.core.entity.User;
import cn.exrick.xboot.core.service.DepartmentService;
import cn.exrick.xboot.core.service.UserService;
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.your.entity.*;
import cn.exrick.xboot.your.service.*;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
@@ -25,6 +23,9 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -58,6 +59,21 @@
    @Autowired
    private UserService userService;
    @Autowired
    private IAreaSectionService iAreaSectionService;
    @Autowired
    private ICarService iCarService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private IEventLogService iEventLogService;
    @Autowired
    private IOrderLogService iOrderLogService;
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<OrderTask> get(@PathVariable String id) {
@@ -66,83 +82,146 @@
        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);
//            if(one==null){
//                return null;
//            }
//            if(StrUtil.isEmpty(one.getFollowUserId())){
//                return null;
//            }
//
//            QueryWrapper<Area> wrapper3 = new QueryWrapper<Area>();
//            wrapper3.eq("user_id",one.getFollowUserId());
//            area = iAreaService.getOne(wrapper3);
//            return area;
//        }
//        return area;
//    }
    private String getFormatDate(String sendTime) {
        if (StrUtil.isNotEmpty(sendTime)) {
            return sendTime;
        } else {
            return DateUtil.format(new Date(), "yyyy-MM-dd");
        }
    }
    public Area getArea(String userId) {
        QueryWrapper<Car> carQueryWrapper = new QueryWrapper<Car>();
        carQueryWrapper.eq("user_id", userId).or().eq("follow_user_id", userId);
        Car one = iCarService.getOne(carQueryWrapper);
        if (one == null) {
            return null;
        } else {
            QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
            wrapper.eq("car_id", one.getId());
            Area area = iAreaService.getOne(wrapper);
            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);
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
    public Result<Object> getAll(String sendTime) {
        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);
        int count = iOrderTaskService.count(wrapper2);
        String format = getFormatDate(sendTime);
        wrapper2.eq("area_id", area.getId());
        wrapper2.eq("send_date", format);
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        int sum = iOrderTaskService.sum(area.getId(),format);
        int sum = iOrderTaskService.sum(area.getId(), format);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("count",count);
        map.put("sum",sum);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("count", list.size());
        map.put("sum", sum);
        map.put("name", "");
        if (list.size() > 0) {
            OrderTask orderTask = list.get(0);
            String areaSectionId = orderTask.getAreaSectionId();
            AreaSection a = iAreaSectionService.getById(areaSectionId);
            Area area2 = iAreaService.getById(orderTask.getAreaId());
            map.put("name", area2.getName() + 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);
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
    @ApiOperation(value = "获取今日配送任务详情列表")
    public Result<List<OrderTask>> getTodayOrder(String sendTime) {
        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("a.area_id",area.getId());
        wrapper2.eq("a.send_date",format);
        wrapper2.orderByAsc("a.seq");
        List<OrderTask> list = iOrderTaskService.list2(wrapper2);
        String format = getFormatDate(sendTime);
//        wrapper2.eq("a.area_id",area.getId());
//        wrapper2.eq("a.send_date",format);
//        wrapper2.orderByAsc("a.seq").orderByAsc("a.status");
        //List<OrderTask> list = iOrderTaskService.list2(wrapper2);
        wrapper2.eq("area_id", area.getId());
        wrapper2.eq("send_date", format);
        wrapper2.orderByAsc("seq").orderByAsc("status");
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        for (OrderTask obj : list) {
            obj.setCode(obj.getLinker());
        }
        return new ResultUtil<List<OrderTask>>().setData(list);
    }
    @RequestMapping(value = "/getTodayOrderDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取当前配送商户详情")
    public Result<OrderTask> getTodayOrderDetail(String orderId) {
    public Result<OrderTask> getTodayOrderDetail(String orderId, String sendTime) {
        OrderTask orderTask = new OrderTask();
        if(!StrUtil.isEmpty(orderId)){
        if (!StrUtil.isEmpty(orderId)) {
            orderTask = iOrderTaskService.getById(orderId);
            if(orderTask.getStatus()!=0){
            if (orderTask.getStatus() != 0) {
                return ResultUtil.error("此商户已配送");
            }
        }else{
            QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
            wrapper.eq("user_id",securityUtil.getCurrUser().getId());
            Area area = iAreaService.getOne(wrapper);
            if(area==null){
                return ResultUtil.error("请联系管理员绑定片区配送员");
        } else {
            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.eq("status",0);
            wrapper2.orderByAsc("seq");
            List<OrderTask> list = iOrderTaskService.list(wrapper2);
            if(list.size()>0){
            String format = getFormatDate(sendTime);
            wrapper2.eq("area_id", area.getId());
            wrapper2.eq("send_date", format);
            wrapper2.eq("status", 0);
            //wrapper2.orderByAsc("seq");
            PageVo page = new PageVo();
            page.setSort("seq");
            page.setOrder("asc");
            page.setPageSize(1);
            page.setPageNumber(0);
            List<OrderTask> list = iOrderTaskService.page(PageUtil.initMpPage(page), wrapper2).getRecords();
            //List<OrderTask> list = iOrderTaskService.list(wrapper2);
            if (list.size() > 0) {
                orderTask = list.get(0);
            }else{
            } else {
                return new ResultUtil<OrderTask>().setData(null);
            }
        }
        orderTask.setCustomer(iCustomerService.getById(orderTask.getCustomerId()));
        QueryWrapper<OrderDetail> wrapper3 = new QueryWrapper<OrderDetail>();
        wrapper3.eq("order_id",orderTask.getId());
        wrapper3.eq("order_id", orderTask.getId());
        orderTask.setOrderDetails(iOrderDetailService.list(wrapper3));
        return new ResultUtil<OrderTask>().setData(orderTask);
@@ -150,36 +229,34 @@
    @RequestMapping(value = "/getTodayOtherInfo", method = RequestMethod.GET)
    @ApiOperation(value = "获取其它信息")
    public Result<Object> getTodayOtherInfo() {
    public Result<Object> getTodayOtherInfo(String sendTime) {
        QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
        wrapper.eq("user_id",securityUtil.getCurrUser().getId());
        Area area = iAreaService.getOne(wrapper);
        if(area==null){
            return ResultUtil.error("请联系管理员绑定片区配送员");
        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);
        String format = getFormatDate(sendTime);
        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);
        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);
        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);
        wrapper5.ne("status", 0);
        wrapper5.eq("send_date", format);
        PageVo page = new PageVo();
        page.setSort("updateTime");
@@ -188,26 +265,35 @@
        page.setPageNumber(0);
        IPage<OrderTask> data = iOrderTaskService.page(PageUtil.initMpPage(page), wrapper5);
        String content = "";
        if(data.getRecords().size()>0){
        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);
            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+"单";
            if (count6 > 0) {
                content += user.getNickname() + "已配送" + count6 + "单";
            }
        }
        map.put("content",content);
        map.put("content", content);
        map.put("lng", "");
        map.put("lat", "");
        String deptId = securityUtil.getCurrUser().getDepartmentId();
        if (StrUtil.isNotEmpty(deptId)) {
            Department department = departmentService.get(deptId);
            map.put("lng", department.getLng());
            map.put("lat", department.getLat());
        }
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/addImg", method = RequestMethod.POST)
    @ApiOperation(value = "上传门头照")
    public Object saveOrUpdate(String orderId,String imgUrl) {
    public Object saveOrUpdate(String orderId, String imgUrl) {
        OrderTask orderTask = iOrderTaskService.getById(orderId);
        orderTask.setImg(imgUrl);
        iOrderTaskService.saveOrUpdate(orderTask);
@@ -216,35 +302,79 @@
    @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)){
    public Object signFor(String orderId, int status, String content, String customerReceiveId, int time, String carId) {
        if (status == 1) {
            if (StrUtil.isEmpty(customerReceiveId)) {
                return ResultUtil.error("正常签收,接货人id必填");
            }
        }
        if (StrUtil.isEmpty(carId)) {
            return ResultUtil.error("车辆id不能为空");
        }
        OrderTask orderTask = iOrderTaskService.getById(orderId);
        orderTask.setStatus(status);
        orderTask.setUserId(securityUtil.getCurrUser().getId());
        if(StrUtil.isNotEmpty(customerReceiveId)){
        orderTask.setTime(time);
        orderTask.setCarId(carId);
        if (StrUtil.isNotEmpty(customerReceiveId)) {
            orderTask.setCustomerReceiveId(customerReceiveId);
        }
        if(!StrUtil.isEmpty(content)){
        if (!StrUtil.isEmpty(content)) {
            orderTask.setRemarks(content);
        }else{
            if(status==2){
        } else {
            if (status == 2) {
                return ResultUtil.error("请填写异常签收原因");
            }
        }
        iOrderTaskService.saveOrUpdate(orderTask);
        Car car = iCarService.getById(orderTask.getCarId());
        EventLog eventLog = new EventLog();
        eventLog.setCarNo(car.getCarNo());
        eventLog.setRefId(orderId);
        eventLog.setType(6);//6:配送完成
        iEventLogService.saveOrUpdate(eventLog);
        saveLog();
        return ResultUtil.success("添加成功");
    }
    private void saveLog() {
        QueryWrapper<OrderLog> wp = new QueryWrapper<>();
        wp.eq("type", 2);
        OrderLog one = iOrderLogService.getOne(wp);
        if (one != null) {
            one.setNum(one.getNum() + 1);
        } else {
            one = new OrderLog();
            one.setNum(1);
            one.setType(2);
        }
        iOrderLogService.saveOrUpdate(one);
    }
    @RequestMapping(value = "/getTaKan", method = RequestMethod.GET)
    @ApiOperation(value = "获取踏勘商户")
    public Result<List<Customer>> getTaKan() {
        Area area = getArea(securityUtil.getCurrUser().getId());
        if (area == null) {
            return ResultUtil.error("请联系管理员绑定该车辆");
        }
        QueryWrapper<Customer> wrapper2 = new QueryWrapper<Customer>();
        wrapper2.eq("area_id", area.getId());
        wrapper2.eq("kstatus", 0);
        List<Customer> list = iCustomerService.list(wrapper2);
        return new ResultUtil<List<Customer>>().setData(list);
    }
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<OrderTask>> getByPage(PageVo page) {
        IPage<OrderTask> data = iOrderTaskService.page(PageUtil.initMpPage(page));
        IPage<OrderTask> data = iOrderTaskService.page2(PageUtil.initMpPage(page));
        return new ResultUtil<IPage<OrderTask>>().setData(data);
    }
@@ -267,4 +397,25 @@
        }
        return ResultUtil.success("批量通过id删除数据成功");
    }
    @GetMapping("/outExcel")//  导出的不是中间表
    @ApiOperation(value = "导出签收统计信息表", notes = "导出签收统计信息表")
    public void export1(OrderStatusCount orderStatusCount, HttpServletResponse response) throws IOException {
        List<OrderStatusCount> orderStatus = this.iOrderTaskService.countStatus(orderStatusCount);
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("签收数量统计报表", "UTF-8");
        String fileName2 = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
//        response.setHeader("Content-dispostion", "attachment;filename="+fileName+".xls");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName2 + ".xlsx");
        EasyExcel.write(response.getOutputStream(), OrderStatusCount.class).
                sheet(0).doWrite(orderStatus);
    }
    @GetMapping(value = "/count")
    public Result<List<OrderStatusCount>> getAll(OrderStatusCount orderStatusCount) {
        List<OrderStatusCount> data = this.iOrderTaskService.countStatus(orderStatusCount);
        ;
        return new ResultUtil<List<OrderStatusCount>>().setData(data);
    }
}