| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | |
| | | import cn.hutool.core.lang.Assert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.deepoove.poi.data.PictureRenderData; |
| | | import com.deepoove.poi.data.Pictures; |
| | | import com.ruoyi.common.utils.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.common.utils.MatrixToImageWriter; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.production.dto.ProductWorkOrderDto; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderFileMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | import com.ruoyi.production.pojo.ProductWorkOrderFile; |
| | | import com.ruoyi.production.service.ProductWorkOrderService; |
| | | import com.ruoyi.quality.pojo.QualityInspectParam; |
| | | import lombok.AllArgsConstructor; |
| | | 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.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | public class ProductWorkOrderServiceImpl extends ServiceImpl<ProductWorkOrderMapper, ProductWorkOrder> implements ProductWorkOrderService { |
| | | |
| | | @Autowired |
| | | private ProductWorkOrderMapper productWorkOrdermapper; |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | @Autowired |
| | | private ProductWorkOrderFileMapper productWorkOrderFileMapper; |
| | | |
| | |
| | | |
| | | @Override |
| | | public IPage<ProductWorkOrderDto> listPage(Page<ProductWorkOrderDto> page, ProductWorkOrderDto productWorkOrder) { |
| | | return productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder); |
| | | return productWorkOrderMapper.pageProductWorkOrder(page, productWorkOrder); |
| | | } |
| | | |
| | | @Override |
| | | public int updateProductWorkOrder(ProductWorkOrderDto productWorkOrderDto) { |
| | | return productWorkOrdermapper.updateById(productWorkOrderDto); |
| | | return productWorkOrderMapper.updateById(productWorkOrderDto); |
| | | } |
| | | |
| | | @Override |
| | | public void down(HttpServletResponse response, ProductWorkOrder productWorkOrder) { |
| | | ProductWorkOrderDto productWorkOrderDto = productWorkOrdermapper.getProductWorkOrderFlowCard(productWorkOrder.getId()); |
| | | ProductWorkOrderDto productWorkOrderDto = productWorkOrderMapper.getProductWorkOrderFlowCard(productWorkOrder.getId()); |
| | | String codePath; |
| | | try { |
| | | codePath = new MatrixToImageWriter().code(productWorkOrderDto.getId().toString(), 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("images", images.isEmpty()?null:images); |
| | | put("deviceName", productWorkOrderDto.getDeviceName()); |
| | | put("images", images.isEmpty() ? null : images); |
| | | }}); |
| | | |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ProductWorkOrderDto getProductWorkOrderById(Long id) { |
| | | return productWorkOrderMapper.getProductWorkOrderFlowCard(id); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | } |