buhuazhen
12 小时以前 ca9c106255ff6283286c78ce621251839eb98189
src/main/java/com/ruoyi/production/service/impl/ProductProcessServiceImpl.java
@@ -7,6 +7,8 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.pojo.Customer;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.mapper.DeviceLedgerMapper;
import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.ProductProcessDto;
import com.ruoyi.production.mapper.ProcessRouteItemMapper;
@@ -23,6 +25,8 @@
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess> implements ProductProcessService {
@@ -32,6 +36,8 @@
    private ProcessRouteItemMapper processRouteItemMapper;
    @Autowired
    private ProductProcessRouteItemMapper productProcessRouteItemMapper;
    @Autowired
    private DeviceLedgerMapper deviceLedgerMapper;
    @Override
    public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) {
@@ -69,8 +75,26 @@
                if (ObjectUtils.isEmpty(productProcess.getName())) {
                    throw new RuntimeException("工序名称不能为空");
                }
                if (ObjectUtils.isEmpty(productProcess.getDeviceName())) {
                    throw new RuntimeException("工序机台不能为空");
                }
            });
            this.saveOrUpdateBatch(productProcessList);
            // 通过机台名称查询机台信息
            List<String> deviceNames = productProcessList.stream().map(ProductProcess::getDeviceName).collect(Collectors.toList());
            List<DeviceLedger> deviceLedgerList = deviceLedgerMapper.selectList(Wrappers.<DeviceLedger>lambdaQuery().in(DeviceLedger::getDeviceName, deviceNames));
            if(CollectionUtils.isEmpty(deviceLedgerList)){
                throw new RuntimeException("工序机台不能为空");
            }
            Map<String, DeviceLedger> deviceNameMap = deviceLedgerList.stream().collect(Collectors.toMap(DeviceLedger::getDeviceName, deviceLedger -> deviceLedger));
            productProcessList.forEach(productProcess -> {
                DeviceLedger deviceLedger = deviceNameMap.get(productProcess.getDeviceName());
                productProcess.setDeviceLeaderId(deviceLedger.getId());
                this.save(productProcess);
                String no = "GX" + String.format("%08d", productProcess.getId());
                productProcess.setNo(no);
                productProcessMapper.updateById(productProcess);
            });
            return AjaxResult.success(true);
        }catch (Exception e){
            e.printStackTrace();