wjli
2024-04-12 e8f0b3422d307c686b3a81269f9e9e4fb34a846e
xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/OrderTaskController.java
@@ -31,7 +31,9 @@
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author whj
@@ -178,6 +180,7 @@
        }
    }
    @RequestMapping(value = "/getByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日任务统计信息")
    public Result<Object> getAll(String sendTime) {
@@ -197,14 +200,20 @@
        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();
        String name = area.getName();
        Map<String, List<OrderTask>> collect = list.stream().collect(Collectors.groupingBy(OrderTask::getAreaSectionId));
        for (Map.Entry<String, List<OrderTask>> stringListEntry : collect.entrySet()) {
            String key = stringListEntry.getKey();
            List<OrderTask> value = stringListEntry.getValue();
            if(value.size()>0){
                AreaSection a = iAreaSectionService.getById(key);
                name+=a.getName();
            }
        }
        if(name.equals(area.getName())){
            map.put("name", "");
        }else {
            map.put("name", name);
        }
        return new ResultUtil<Object>().setData(map);
    }
@@ -231,26 +240,28 @@
        map.put("name", "");
        map.put("sectons", null);
        if (list.size() > 0) {
            Area areaName = iAreaService.getById(list.get(0).getAreaId());
            List<String> temp = new ArrayList<>();
            List<String> tempIds = new ArrayList<>();
            List<AreaSection> areaSections = new ArrayList<>();
            for(int i=0;i<list.size();i++){
                if(!temp.contains(list.get(i).getAreaSectionId())){
                if(!tempIds.contains(list.get(i).getAreaSectionId())){
                    tempIds.add(list.get(i).getAreaSectionId());
                    AreaSection a = iAreaSectionService.getById(list.get(i).getAreaSectionId());
                    temp.add(a.getName());
                    areaSections.add(a);
                }
            }
            map.put("name", areaName + StringUtils.join(temp,"-"));
            map.put("name", area.getName() + StringUtils.join(temp,"-"));
            map.put("sectons",areaSections);
            temp.clear();
            areaSections.clear();
            tempIds.clear();
            //areaSections.clear();
            list.clear();
        }
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/getTodayOrder", method = RequestMethod.GET)
   /* @RequestMapping(value = "/getTodayOrder", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日配送任务详情列表")
    public Result<List<OrderTask>> getTodayOrder(String sendTime) {
        Area area = getArea(securityUtil.getCurrUser().getId());
@@ -271,6 +282,31 @@
        for (OrderTask obj : list) {
            obj.setCode(obj.getLinker());
        }
        return new ResultUtil<List<OrderTask>>().setData(list);
    }*/
    @RequestMapping(value = "/getTodayOrder", method = RequestMethod.GET)
    @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 = 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("area_section_id").orderByAsc("seq").orderByAsc("status");
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        return new ResultUtil<List<OrderTask>>().setData(list);
    }
@@ -559,6 +595,55 @@
        return ResultUtil.success("添加成功");
    }
    @RequestMapping(value = "/signForX", method = RequestMethod.POST)
    @ApiOperation(value = "签收")
    public Object signForX(String orderId, int status, String content, String customerReceiveId, int time, String carId,String img) {
        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());
        orderTask.setTime(time);
        orderTask.setCarId(carId);
        if (StrUtil.isNotEmpty(customerReceiveId)) {
            orderTask.setCustomerReceiveId(customerReceiveId);
        }
        if(StrUtil.isNotEmpty(img)){
            if(StrUtil.isNotEmpty(orderTask.getImg())){
                String imgO = orderTask.getImg();
                orderTask.setImg(imgO+","+img);
            }else{
                orderTask.setImg(img);
            }
        }
        if (!StrUtil.isEmpty(content)) {
            orderTask.setRemarks(content);
        } 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);
@@ -805,4 +890,87 @@
        ;
        return new ResultUtil<List<OrderStatusCount>>().setData(data);
    }
    @Autowired
    private ISignCountService iSignCountService;
    @RequestMapping(value = "/getStatusCounts", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日任务统计信息")
    public Result<Object> getStatusCounts() {
        System.err.println("执行存储数据定时任务时间: " + LocalDateTime.now());
       OrderStatusCount orderStatusCount = new OrderStatusCount();
        List<OrderStatusCount> StatusCounts = new ArrayList<>();
        List<OrderStatusCount> temps = iOrderTaskService.countStatus(orderStatusCount);
        for (OrderStatusCount statusCount : temps) {
            if("丰南02车".equals(statusCount.getLine())){
                StatusCounts.add(statusCount);
            }
        }
        if (StatusCounts != null && StatusCounts.size() != 0) {
            List<SignCount> list = iSignCountService.list();
            for (OrderStatusCount statusCount : StatusCounts) {
                SignCount signCount = new SignCount();
                boolean flag = false;
                for (SignCount signCountS : list) {
                    if (signCountS.getTaskId().equals(statusCount.getId())) {
                        signCount.setId(signCountS.getId());
                        signCount.setCarName(statusCount.getCarName());
                        signCount.setAmount(statusCount.getAmount());
                        signCount.setSignCount(statusCount.getSignCount());
                        signCount.setAbnormalSign(statusCount.getAbnormalSign());
                        signCount.setBatch(statusCount.getBatch());
                        signCount.setLine(statusCount.getLine());
                        signCount.setNotSignCount(statusCount.getNotSignCount());
                        String SendDate=getBeforeOneDayByStringDate(statusCount.getSendDate());
                        signCount.setSendDate(SendDate);
                        signCount.setProportion(statusCount.getProportion());
                        signCount.setUserName(statusCount.getUserName());
                        signCount.setTaskId(statusCount.getId());
                        iSignCountService.saveOrUpdate(signCount);
                        System.out.println("更新成功");
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                signCount.setCarName(statusCount.getCarName());
                signCount.setAmount(statusCount.getAmount());
                signCount.setSignCount(statusCount.getSignCount());
                signCount.setAbnormalSign(statusCount.getAbnormalSign());
                signCount.setBatch(statusCount.getBatch());
                signCount.setLine(statusCount.getLine());
                signCount.setNotSignCount(statusCount.getNotSignCount());
                String SendDate=getBeforeOneDayByStringDate(statusCount.getSendDate());
                signCount.setSendDate(SendDate);
                signCount.setProportion(statusCount.getProportion());
                signCount.setUserName(statusCount.getUserName());
                signCount.setTaskId(statusCount.getId());
                if (iSignCountService.saveOrUpdate(signCount)) {
                    System.out.println("定时存储成功");
                }
            }
        }
        return null;
    }
    private String getBeforeOneDayByStringDate(String dateString) {
        String times = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date d;
        try {
            d = format.parse(dateString);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(d);
            calendar.add(Calendar.DAY_OF_MONTH, -1);  // 在当前日基础上-1
            String format1 = format.format(calendar.getTime());
            times = format1;
            //获取String类型的时间
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return times;
    }
}