刘小明
2024-08-26 0c479f17e5f9ff3ad638f3af783cf22b0a77fbd0
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java
@@ -1,26 +1,21 @@
package com.dy.pmsProduct.order;
import cn.hutool.core.codec.Base64;
import com.dy.common.webFilter.UserTokenContext;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoOth.OthFileMapper;
import com.dy.pmsGlobal.daoPr.*;
import com.dy.pmsGlobal.dyFile.FileOperate;
import com.dy.pmsGlobal.pojoBa.BaUser;
import com.dy.pmsGlobal.pojoPlt.PltProduct;
import com.dy.pmsGlobal.pojoPr.*;
import com.dy.pmsGlobal.util.UserUtil;
import com.dy.pmsProduct.order.QueryVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
@@ -30,10 +25,6 @@
    private PrOrderMapper orderDao;
    private PrOrderItemMapper orderItemDao;
    private UserUtil userUtil;
    private FileOperate fileOperate;
    private OthFileMapper othFileMapper;
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl;
    @Autowired
    public void setOrderDao(PrOrderMapper orderDao) {
@@ -49,17 +40,6 @@
    public void setUserUtil(UserUtil userUtil) {
        this.userUtil = userUtil;
    }
    @Autowired
    public void setFileOperate(FileOperate fileOperate) {
        this.fileOperate = fileOperate;
    }
    @Autowired
    public void setOthFileMapper(OthFileMapper othFileMapper) {
        this.othFileMapper = othFileMapper;
    }
    @Transactional
    public int save(PrOrder p) {
        p.id = null;
@@ -67,6 +47,7 @@
        if (orderDao.exists(p.name, p.id)) {
            throw new RuntimeException("订单名称不能重复");
        }
        extractedCheck(p);
        p.setDeleted(false);
        BaUser loginUser = userUtil.getUser(UserTokenContext.get());
        if (loginUser != null) {
@@ -82,6 +63,7 @@
        if (orderDao.exists(p.name, p.id)) {
            throw new RuntimeException("订单名称不能重复");
        }
        extractedCheck(p);
        int count = orderDao.updateByPrimaryKeySelective(p);
        if (count > 0) {
            saveOrderItems(p);
@@ -114,6 +96,7 @@
    public PrOrder selectById(String proId) {
        PrOrder pro = orderDao.selectByPrimaryKey(Long.valueOf(proId));
        changeRate(pro);
        return pro;
    }
@@ -162,11 +145,54 @@
                }
            }
        }
        prOrder.setItems(items);
    }
    public List<PrOrder> selectAll(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        return orderDao.selectAll(params);
        List<PrOrder> orderList = orderDao.selectAll(params);
        for (PrOrder prOrder : orderList) {
            changeRate(prOrder);
        }
        return orderList;
    }
    /**
     * 只更新状态,不更新其他字段
     * @param order
     * 更新状态  如果有在执行中的任务,不让暂停
     * @return
     */
   @Transactional
    public int updateStatus(PrOrder order) {
        if(order.status == OrderStatusEnum.NORMAL.getCode()){
            PrOrder prOrder = orderDao.selectByPrimaryKey(order.id);
            prOrder.status = order.status;
            extractedCheck(prOrder);
        }
       PrOrder param = new PrOrder();
        param.id =order.id;
        param.status = order.status;
        return orderDao.updateByPrimaryKeySelective(param);
    }
    //如果交期小于当前时间,不允许设置为正常
    private void extractedCheck(PrOrder order) {
        if(order.status == OrderStatusEnum.NORMAL.getCode()){
            String deliveryDateStr = order.getDeliveryDate();
            LocalDate endDate = LocalDate.parse(deliveryDateStr, DateTimeFormatter.ISO_LOCAL_DATE);
            LocalDate nextDay = endDate.plusDays(1);
            LocalDate today = LocalDate.now(); // 获取当前日期
            if (nextDay.isBefore(today)) {
                throw new RuntimeException("交付日期必须大于等于当前日期,请修改交付日期");
            }
        }
        //如果有在生产的任务不能设置为暂停 或 结束
 /*
        PrProductionProcess process = processDao.selectByPrimaryKey(order.processId);
        if(process == null || !process.proId.equals(order.proId)){
            throw new RuntimeException("产品与生产流程不匹配");
        }
        //开始日期要小于结束日期
        if(order.startDate.compareTo(order.endDate) > 0){
            throw new RuntimeException("开始日期不能大于结束日期");
        }*/
    }
}