| | |
| | | |
| | | import cn.hutool.core.lang.Assert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.pinyin.PinyinUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.ruoyi.production.dto.ProductWorkOrderDto; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderFileMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductionMachineRecordMapper; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | import com.ruoyi.production.pojo.ProductWorkOrderFile; |
| | | import com.ruoyi.production.pojo.ProductionMachineRecord; |
| | | import com.ruoyi.production.service.ProductWorkOrderService; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | @Autowired |
| | | private ProductWorkOrderFileMapper productWorkOrderFileMapper; |
| | | @Autowired |
| | | private ProductionMachineRecordMapper productionMachineRecordMapper; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Value("${file.temp-dir}") |
| | | private String tempDir; |
| | |
| | | if (CollectionUtils.isNotEmpty(productWorkOrderFiles)) { |
| | | productWorkOrderFiles.forEach(productWorkOrderFile -> { |
| | | Map<String, Object> image = new HashMap<>(); |
| | | PictureRenderData pictureRenderData = Pictures.ofLocal( productWorkOrderFile.getUrl()).sizeInCm(17, 20).create(); |
| | | PictureRenderData pictureRenderData = Pictures.ofLocal(productWorkOrderFile.getUrl()).sizeInCm(17, 20).create(); |
| | | image.put("url", pictureRenderData); |
| | | images.add(image); |
| | | }); |
| | | } |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/work-order-template.docx"); |
| | | |
| | | // 日期时间格式化器 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| | | |
| | | // 格式化日期时间字段 |
| | | String planStartTimeStr = formatDateTime(productWorkOrderDto.getPlanStartTime(), formatter); |
| | | String planEndTimeStr = formatDateTime(productWorkOrderDto.getPlanEndTime(), formatter); |
| | | String actualStartTimeStr = formatDateTime(productWorkOrderDto.getActualStartTime(), formatter); |
| | | String actualEndTimeStr = formatDateTime(productWorkOrderDto.getActualEndTime(), formatter); |
| | | |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("process", productWorkOrderDto.getProcessName()); |
| | |
| | | put("model", productWorkOrderDto.getModel()); |
| | | put("completeQuantity", productWorkOrderDto.getCompleteQuantity()); |
| | | put("scrapQty", productWorkOrderDto.getScrapQty()); |
| | | put("planStartTime", productWorkOrderDto.getPlanStartTime()); |
| | | put("planEndTime", productWorkOrderDto.getPlanEndTime()); |
| | | put("actualStartTime", productWorkOrderDto.getActualStartTime()); |
| | | put("actualEndTime", productWorkOrderDto.getActualEndTime()); |
| | | put("planStartTime", planStartTimeStr); |
| | | put("planEndTime", planEndTimeStr); |
| | | put("actualStartTime", actualStartTimeStr); |
| | | put("actualEndTime", actualEndTimeStr); |
| | | put("twoCode", Pictures.ofLocal(codePath).create()); |
| | | put("deviceName", productWorkOrderDto.getDeviceName()); |
| | | put("images", images.isEmpty()?null:images); |
| | | put("images", images.isEmpty() ? null : images); |
| | | }}); |
| | | |
| | | try { |
| | |
| | | |
| | | @Override |
| | | public ProductWorkOrderDto getProductWorkOrderById(Long id) { |
| | | return productWorkOrderMapper.getProductWorkOrderFlowCard(id); |
| | | } |
| | | |
| | | @Override |
| | | public String generateProductWorkOrder(String datePrefix,String processName, String npsNo) { |
| | | datePrefix = StrUtil.isBlank(datePrefix) ? LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) : datePrefix; |
| | | processName = StrUtil.isBlank(processName) ? "未知" : processName; |
| | | Assert.notNull(npsNo, "生产订单号编号不能为空"); |
| | | ProductWorkOrder lastWorkOrder = productWorkOrderMapper.selectMax(datePrefix); |
| | | int sequenceNumber = 1; // 默认序号 |
| | | if (lastWorkOrder != null && lastWorkOrder.getWorkOrderNo() != null) { |
| | | String lastNo = lastWorkOrder.getWorkOrderNo().toString(); |
| | | if (lastNo.startsWith(datePrefix)) { |
| | | String seqStr = lastNo.substring(datePrefix.length()); |
| | | try { |
| | | sequenceNumber = Integer.parseInt(seqStr) + 1; |
| | | } catch (NumberFormatException e) { |
| | | sequenceNumber = 1; |
| | | ProductWorkOrderDto productWorkOrderDto = productWorkOrderMapper.getProductWorkOrderFlowCard(id); |
| | | // 合并工单排产人员与机台上机操作员,去重后作为报工弹窗默认班组成员 |
| | | Set<Long> userIdSet = new LinkedHashSet<>(); |
| | | if (productWorkOrderDto != null && StrUtil.isNotBlank(productWorkOrderDto.getUserIds())) { |
| | | for (String uid : productWorkOrderDto.getUserIds().split(",")) { |
| | | if (StrUtil.isNotBlank(uid)) { |
| | | userIdSet.add(Long.parseLong(uid.trim())); |
| | | } |
| | | } |
| | | } |
| | | String processPinyin = StringUtils.getProcessNo(processName); |
| | | return StrUtil.format("{}{}{}",processPinyin,npsNo,String.format("%03d", sequenceNumber)); |
| | | List<ProductionMachineRecord> machineRecords = productionMachineRecordMapper.selectList( |
| | | Wrappers.<ProductionMachineRecord>lambdaQuery() |
| | | .eq(ProductionMachineRecord::getWorkOrderId, id) |
| | | .isNotNull(ProductionMachineRecord::getOperatorId)); |
| | | for (ProductionMachineRecord machineRecord : machineRecords) { |
| | | if (StrUtil.isNotBlank(machineRecord.getOperatorId())) { |
| | | for (String uid : machineRecord.getOperatorId().split(",")) { |
| | | if (StrUtil.isNotBlank(uid)) { |
| | | userIdSet.add(Long.parseLong(uid.trim())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | List<ProductWorkOrderDto.ReportPerson> reportPersons = new ArrayList<>(); |
| | | for (Long userId : userIdSet) { |
| | | ProductWorkOrderDto.ReportPerson reportPerson = new ProductWorkOrderDto.ReportPerson(); |
| | | reportPerson.setUserId(userId); |
| | | SysUser sysUser = sysUserMapper.selectUserById(userId); |
| | | if (sysUser != null) { |
| | | reportPerson.setUserName(sysUser.getNickName()); |
| | | } |
| | | reportPersons.add(reportPerson); |
| | | } |
| | | if (productWorkOrderDto != null) { |
| | | productWorkOrderDto.setReportPersons(reportPersons); |
| | | } |
| | | return productWorkOrderDto; |
| | | } |
| | | |
| | | @Override |
| | | public String generateProductWorkOrder(String processName, String npsNo) { |
| | | processName = StrUtil.isBlank(processName) ? "未知" : processName; |
| | | Assert.notNull(npsNo, "生产订单号编号不能为空"); |
| | | Integer maxNo = productWorkOrderMapper.selectMax(npsNo); |
| | | int sequenceNumber = maxNo + 1; // 默认序号 |
| | | String processPinyin = StringUtils.getProcessNo(processName); |
| | | return StrUtil.format("{}{}", processPinyin, npsNo, String.format("%03d", sequenceNumber)); |
| | | } |
| | | |
| | | /** |
| | | * 格式化 LocalDateTime 为字符串 |
| | | */ |
| | | private String formatDateTime(LocalDateTime dateTime, DateTimeFormatter formatter) { |
| | | if (dateTime == null) { |
| | | return ""; |
| | | } |
| | | return dateTime.format(formatter); |
| | | } |
| | | |
| | | } |