| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | 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; |
| | |
| | | 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 { |
| | |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | @Autowired |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) { |
| | |
| | | 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); |
| | | if(StrUtil.isEmpty(productProcess.getNo())){ |
| | | String no = "GX" + String.format("%08d", productProcess.getId()); |
| | | productProcess.setNo(no); |
| | | productProcessMapper.updateById(productProcess); |
| | | } |
| | | |
| | | }); |
| | | |
| | | return AjaxResult.success(true); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |