skyouc
9 天以前 0696db2f8a83d32d8c00ba55967694ed1a76f4d0
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/QlyIsptItemServiceImpl.java
@@ -6,9 +6,13 @@
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.manager.controller.params.IsptItemsParams;
import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem;
import com.vincent.rsf.server.manager.entity.AsnOrderItem;
import com.vincent.rsf.server.manager.entity.QlyInspect;
import com.vincent.rsf.server.manager.enums.QlyIsptResult;
import com.vincent.rsf.server.manager.enums.QlyIsptStatus;
import com.vincent.rsf.server.manager.mapper.QlyIsptItemMapper;
import com.vincent.rsf.server.manager.entity.QlyIsptItem;
import com.vincent.rsf.server.manager.service.AsnOrderItemService;
import com.vincent.rsf.server.manager.service.QlyInspectService;
import com.vincent.rsf.server.manager.service.QlyIsptItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -26,6 +30,8 @@
    @Autowired
    private QlyInspectService qlyInspectService;
    @Autowired
    private AsnOrderItemService asnOrderItemService;
    /**
     * @author Ryan
@@ -42,18 +48,30 @@
        }
        List<QlyIsptItem> isptItem =  params.getIsptItem();
        List<Long> list = isptItem.stream().map(QlyIsptItem::getId).collect(Collectors.toList());
        if (params.getType().equals("2") || params.getType().equals("1")) {
            if (!this.update(new LambdaUpdateWrapper<QlyIsptItem>()
                    .set(QlyIsptItem::getIsptResult, params.getType())
                    .in(QlyIsptItem::getId, list))) {
                throw new CoolException("修改失败!!");
            }
        if (Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val || Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_DEFECT.val) {
            //1:合格, 2:不合格, 0: 其它(默认)
            isptItem.forEach(item -> {
                if (Short.parseShort(params.getType()) == QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val) {
                    //TODO 先捡后收为送货数量,先收后捡为收货数量
                    item.setSafeQty(item.getDlyQty());
                    item.setDisQty(0.0);
                } else {
                    item.setSafeQty(0.0);
                    item.setDisQty(item.getDlyQty());
                }
                if (!this.update(new LambdaUpdateWrapper<QlyIsptItem>()
                        .set(QlyIsptItem::getSafeQty, item.getSafeQty())
                        .set(QlyIsptItem::getIsptResult, Short.parseShort(params.getType()))
                        .set(QlyIsptItem::getDisQty, item.getDisQty())
                        .in(QlyIsptItem::getId, item.getId()))) {
                    throw new CoolException("修改失败!!");
                }
            });
        } else {
            if (!this.updateBatchById(isptItem)) {
                throw new CoolException("明细修改失败");
            }
        }
        List<QlyIsptItem> isptItems = this.list(new LambdaQueryWrapper<QlyIsptItem>().in(QlyIsptItem::getId, list));
        if (isptItems.isEmpty()) {
            throw new CoolException("数据错误:明细不存在!!");
@@ -62,18 +80,39 @@
        for (Long key : listMap.keySet()) {
            QlyInspect inspect = qlyInspectService.getById(key);
            List<QlyIsptItem> items = listMap.get(key);
            items.forEach(qlyIsptItem -> {
                AsnOrderItem orderItem = asnOrderItemService.getById(qlyIsptItem.getAsnItemId());
                if (qlyIsptItem.getSafeQty().compareTo(orderItem.getAnfme()) >= 0.00) {
                    orderItem.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val)
                            .setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_DONE.val);
                } else if (qlyIsptItem.getSafeQty().compareTo(0.00) > 0.00 && qlyIsptItem.getSafeQty().compareTo(orderItem.getAnfme()) < 0.00) {
                    orderItem.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_SECTION.val);
                    if (Double.compare(qlyIsptItem.getSafeQty() + qlyIsptItem.getDisQty(), orderItem.getAnfme()) >= 0.00 ) {
                        orderItem.setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_DONE.val);
                    } else {
                        orderItem.setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_ING.val);
                    }
                } else {
                    orderItem.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_DEFECT.val)
                            .setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_DONE.val);
                }
                if (!asnOrderItemService.updateById(orderItem)) {
                    throw new CoolException("收货单明细修改失败!!");
                }
            });
            Double safeQty = items.stream().mapToDouble(QlyIsptItem::getSafeQty).sum();
            Double rcptQty = items.stream().mapToDouble(QlyIsptItem::getSafeQty).sum();
            Double disQty = items.stream().mapToDouble(QlyIsptItem::getDisQty).sum();
            Double qlyQty = safeQty + disQty;
            //安全数量,质检数量
            inspect.setSafeQty(safeQty)
                    .setIsptQty(qlyQty);
            if (Double.compare(disQty, 0) > 0) {
                inspect.setIsptResult(Short.parseShort("4"));
                inspect.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_SECTION.val);
            }
            if (Double.compare(safeQty, rcptQty) == 0) {
                inspect.setIsptResult(Short.parseShort("1"));
            if (Double.compare(safeQty, inspect.getDlyQty()) == 0) {
//                inspect.setIsptStatus(QlyIsptStatus.QLY_ISPT_STAS_DONE.val);
                inspect.setIsptResult(QlyIsptResult.QLY_ISPT_RESULT_EXCELLENT.val);
            }
            if (!qlyInspectService.updateById(inspect)) {
                throw new CoolException("质检数量修改失败!!");