zss
2024-10-24 a00890e840b80a741f62eb6cb31b46f13be6202f
inspect-server/src/main/java/com/yuanchu/mom/service/impl/WarehouseServiceImpl.java
@@ -1,5 +1,7 @@
package com.yuanchu.mom.service.impl;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.dto.HistoryDto;
@@ -20,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Administrator
@@ -42,6 +45,8 @@
    private WarehouseCellService warehouseCellService;
    private InsSampleMapper insSampleMapper;
    private InsOrderStateMapper insOrderStateMapper;
    private InsProductMapper insProductMapper;
@@ -98,11 +103,37 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int upShelf(WarehouseShelf warehouseShelf) {
        warehouseCellMapper.update(null, Wrappers.<WarehouseCell>lambdaUpdate()
                .eq(WarehouseCell::getShelfId, warehouseShelf.getWarehouseId())
                .gt(WarehouseCell::getRow, warehouseShelf.getRow())
                .gt(WarehouseCell::getCol, warehouseShelf.getCol())
                .set(WarehouseCell::getState, 0));
        WarehouseShelf shelf = warehouseShelfMapper.selectById(warehouseShelf.getId());
        if (shelf.getCol()>=warehouseShelf.getCol() && shelf.getRow() >= warehouseShelf.getRow()) {
            //如果维护的数据小于原有的行列数可以进行修改
            warehouseCellMapper.update(null, Wrappers.<WarehouseCell>lambdaUpdate()
                    .eq(WarehouseCell::getShelfId, warehouseShelf.getId())
                    .and(true, wrapper -> wrapper.gt(WarehouseCell::getRow, warehouseShelf.getRow())
                            .or()
                            .gt(WarehouseCell::getCol, warehouseShelf.getCol()))
                    .set(WarehouseCell::getState, 0));
        }else {
            //如果维护的数据大于原有的行列数需要进行额外添加
            List<WarehouseCell> cells = new ArrayList<>();
            for (int i = 1; i < warehouseShelf.getRow() + 1; i++) {
                for (int a = 1; a < warehouseShelf.getCol() + 1; a++) {
                    WarehouseCell cell = new WarehouseCell();
                    cell.setRow(i);
                    cell.setCol(a);
                    cell.setState(1);
                    cell.setShelfId(warehouseShelf.getId());
                    WarehouseCell warehouseCell = warehouseCellMapper.selectOne(Wrappers.<WarehouseCell>lambdaQuery()
                            .eq(WarehouseCell::getShelfId, warehouseShelf.getId())
                            .eq(WarehouseCell::getRow, i)
                            .eq(WarehouseCell::getCol, a));
                    if (ObjectUtils.isNotEmpty(warehouseCell)){
                        cell.setId(warehouseCell.getId());
                    }
                    cells.add(cell);
                }
            }
            warehouseCellService.saveOrUpdateBatch(cells);
        }
        warehouseShelfMapper.updateById(warehouseShelf);
        return 0;
    }
@@ -139,7 +170,7 @@
    }
    @Override
    public int outWarehouse(String sampleCode) {
    public int outWarehouse(String sampleCode, boolean a) {
        List<InsSample> samples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getSampleCode, sampleCode).select(InsSample::getId,InsSample::getCellId));
        if(samples.size()!=1){
            throw new ErrorException("样品编号输入有误");
@@ -147,6 +178,21 @@
        if(samples.get(0).getCellId()==null){
            throw new ErrorException("样品 " + sampleCode + " 未入库");
        }
        if (!a) {
            //判断该订单是否站点任务有(继续试验或者是结束试验)
            List<InsOrderState> orderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery()
                    .eq(InsOrderState::getInsOrderId, samples.get(0).getInsOrderId())
                    .eq(InsOrderState::getInsState, 5));
            List<Integer> orderIds = new ArrayList<Integer>();
            orderIds.add(6);
            if (CollectionUtils.isEmpty(orderStates)) {
                List<Integer> collect = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery()
                        .eq(InsOrderState::getInsOrderId, samples.get(0).getInsOrderId())).stream().map(InsOrderState::getInsState).distinct().collect(Collectors.toList());
                if (collect.size()!=0 && !collect.containsAll(orderIds)) {
                    throw new ErrorException("该样品的检验任务还没有结束试验或继续试验,暂时无法出库!");
                }
            }
        }
        WarehouseHistory history = new WarehouseHistory();
        history.setState(2);
        history.setInsSampleId(samples.get(0).getId());