xuefei
2023-08-08 6c764f473b1e0e9dd2fb13034fe0d7295ab3724e
xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/OrderTaskController.java
@@ -11,6 +11,7 @@
import cn.exrick.xboot.core.service.UserService;
import cn.exrick.xboot.your.entity.*;
import cn.exrick.xboot.your.service.*;
import cn.exrick.xboot.your.vo.OrderListVo;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
@@ -19,12 +20,14 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -206,6 +209,49 @@
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/getTodayCount", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日任务统计信息")
    public Result<Object> getAllNew(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("area_id", area.getId());
        wrapper2.eq("send_date", format);
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        int sum = iOrderTaskService.sum(area.getId(), format);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("count", list.size());
        map.put("sum", sum);
        map.put("name", "");
        map.put("sectons", null);
        if (list.size() > 0) {
            List<String> temp = new ArrayList<>();
            List<String> tempIds = new ArrayList<>();
            List<AreaSection> areaSections = new ArrayList<>();
            for(int i=0;i<list.size();i++){
                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", area.getName() + StringUtils.join(temp,"-"));
            map.put("sectons",areaSections);
            temp.clear();
            tempIds.clear();
            //areaSections.clear();
            list.clear();
        }
        return new ResultUtil<Object>().setData(map);
    }
    @RequestMapping(value = "/getTodayOrder", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日配送任务详情列表")
    public Result<List<OrderTask>> getTodayOrder(String sendTime) {
@@ -230,6 +276,86 @@
        return new ResultUtil<List<OrderTask>>().setData(list);
    }
    @RequestMapping(value = "/getTodayOrderByHulue", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日配送任务详情列表,忽略某订单,客户端专用接口")
    public Result<OrderListVo> getTodayOrderFromHulue(String orderId, String sendTime,String areaSectionId) {
        //忽略订单
        if (!StrUtil.isEmpty(orderId)) {
            OrderTask orderTask = iOrderTaskService.getById(orderId);
            int seq = orderTask.getSeq();
            orderTask.setSeq(1000+seq);
            iOrderTaskService.saveOrUpdate(orderTask);
        }
        //获取订单列表
        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);
        if(!StrUtil.isEmpty(areaSectionId)){
            wrapper2.eq("area_section_id", areaSectionId);
        }
        wrapper2.orderByAsc("area_section_id").orderByAsc("seq").orderByAsc("status");
        List<OrderTask> list = iOrderTaskService.list(wrapper2);
        int num = 0;
        for (OrderTask obj : list) {
            obj.setCode(obj.getLinker());
            if(obj.getStatus()==1){
                num++;
            }
        }
        String percent = getPercent(num,list.size());
        OrderListVo vo = new OrderListVo();
        vo.setOrderTasks(list);
        vo.setPercent(percent);
        return new ResultUtil<OrderListVo>().setData(vo);
    }
    public String getPercent(int num,int totalNum){
        if(totalNum>0){
            BigDecimal number = new BigDecimal(0);
            number=BigDecimal.valueOf((int)num);
            BigDecimal total = new BigDecimal(0);
            total=BigDecimal.valueOf((int)totalNum);
            BigDecimal divide = number.divide(total,2,BigDecimal.ROUND_HALF_UP);
            double bfb = divide.doubleValue();
            int bfbInt = (int)(bfb*100);
            return bfbInt+ "%";
        }else{
            return 0+ "%";
        }
    }
    @RequestMapping(value = "/getOneMonthOrderPercent", method = RequestMethod.GET)
    @ApiOperation(value = "获取本月配送百分比")
    public Result<String> getMonthPercent(){
        Area area = getArea(securityUtil.getCurrUser().getId());
        if (area == null) {
            return ResultUtil.error("请联系管理员绑定该车辆");
        }
        String todayFormat = DateUtil.format(new Date(), "yyyy-MM-dd");
        String monthFormat = DateUtil.format(DateUtil.beginOfMonth(new Date()),"yyyy-MM-dd");
        QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
        wrapper2.eq("area_id", area.getId());
        wrapper2.between("send_date",monthFormat,todayFormat);
        int allOrders = iOrderTaskService.count(wrapper2);
        wrapper2.eq("status",1);
        int doOrders = iOrderTaskService.count(wrapper2);
        return new ResultUtil<String>().setData(getPercent(doOrders,allOrders));
    }
    @RequestMapping(value = "/getTodayOrderDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取当前配送商户详情")
    public Result<OrderTask> getTodayOrderDetail(String orderId, String sendTime) {
@@ -250,6 +376,53 @@
            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 {
                return new ResultUtil<OrderTask>().setData(null);
            }
        }
        orderTask.setCustomer(iCustomerService.getById(orderTask.getCustomerId()));
        QueryWrapper<OrderDetail> wrapper3 = new QueryWrapper<OrderDetail>();
        wrapper3.eq("order_id", orderTask.getId());
        orderTask.setOrderDetails(iOrderDetailService.list(wrapper3));
        return new ResultUtil<OrderTask>().setData(orderTask);
    }
    @RequestMapping(value = "/getTodayOrderDetailByAreaSection", method = RequestMethod.GET)
    @ApiOperation(value = "获取当前配送商户详情")
    public Result<OrderTask> getTodayOrderDetail(String orderId, String sendTime,String areaSectionId) {
        OrderTask orderTask = new OrderTask();
        if (!StrUtil.isEmpty(orderId)) {
            orderTask = iOrderTaskService.getById(orderId);
            if (orderTask.getStatus() != 0) {
                return ResultUtil.error("此商户已配送");
            }
        } else {
            Area area = getArea(securityUtil.getCurrUser().getId());
            if (area == null) {
                return ResultUtil.error("请联系管理员绑定该车辆");
            }
            QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
            String format = getFormatDate(sendTime);
            wrapper2.eq("area_id", area.getId());
            wrapper2.eq("send_date", format);
            wrapper2.eq("status", 0);
            if(!StrUtil.isEmpty(areaSectionId)){
                wrapper2.eq("area_section_Id", areaSectionId);
            }
            //wrapper2.orderByAsc("seq");
            PageVo page = new PageVo();
@@ -388,6 +561,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);