| | |
| | | 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.exception.ServiceException; |
| | | import com.ruoyi.common.utils.MatrixToImageWriter; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.production.dto.ProductWorkOrderDto; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderFileMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderRapporteurMapper; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | import com.ruoyi.production.pojo.ProductWorkOrderFile; |
| | | import com.ruoyi.production.pojo.ProductWorkOrderRapporteur; |
| | | import com.ruoyi.production.service.ProductWorkOrderService; |
| | | import com.ruoyi.quality.pojo.QualityInspectParam; |
| | | import lombok.AllArgsConstructor; |
| | | 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.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | private ProductWorkOrderMapper productWorkOrdermapper; |
| | | @Autowired |
| | | private ProductWorkOrderFileMapper productWorkOrderFileMapper; |
| | | @Autowired |
| | | private ProductWorkOrderRapporteurMapper productWorkOrderRapporteurMapper; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Value("${file.temp-dir}") |
| | | private String tempDir; |
| | | |
| | | @Override |
| | | public IPage<ProductWorkOrderDto> listPage(Page<ProductWorkOrderDto> page, ProductWorkOrderDto productWorkOrder) { |
| | | return productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder); |
| | | if (productWorkOrder != null && Integer.valueOf(2).equals(productWorkOrder.getType())) { |
| | | productWorkOrder.setCurrentUserId(SecurityUtils.getUserId()); |
| | | } |
| | | IPage<ProductWorkOrderDto> pageData = productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder); |
| | | List<ProductWorkOrderDto> records = pageData.getRecords(); |
| | | if (CollectionUtils.isEmpty(records)) { |
| | | return pageData; |
| | | } |
| | | |
| | | List<Long> workOrderIds = records.stream() |
| | | .map(ProductWorkOrderDto::getId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(workOrderIds)) { |
| | | return pageData; |
| | | } |
| | | |
| | | List<ProductWorkOrderRapporteur> rapporteurs = productWorkOrderRapporteurMapper.selectList(Wrappers.<ProductWorkOrderRapporteur>lambdaQuery() |
| | | .in(ProductWorkOrderRapporteur::getWorkOrderId, workOrderIds)); |
| | | |
| | | final Map<Long, List<Long>> rapporteurMap = CollectionUtils.isNotEmpty(rapporteurs) |
| | | ? rapporteurs.stream() |
| | | .filter(item -> item.getWorkOrderId() != null && item.getUserId() != null) |
| | | .collect(Collectors.groupingBy( |
| | | ProductWorkOrderRapporteur::getWorkOrderId, |
| | | LinkedHashMap::new, |
| | | Collectors.mapping(ProductWorkOrderRapporteur::getUserId, Collectors.toList()) |
| | | )) |
| | | : new LinkedHashMap<>(); |
| | | |
| | | records.forEach(item -> { |
| | | List<Long> userIds = rapporteurMap.get(item.getId()); |
| | | item.setReportWorkersId(userIds == null ? new Long[0] : userIds.toArray(new Long[0])); |
| | | }); |
| | | return pageData; |
| | | } |
| | | |
| | | @Override |
| | | public int updateProductWorkOrder(ProductWorkOrderDto productWorkOrderDto) { |
| | | return productWorkOrdermapper.updateById(productWorkOrderDto); |
| | | int rows = productWorkOrdermapper.updateById(productWorkOrderDto); |
| | | if (rows <= 0 || productWorkOrderDto.getId() == null) { |
| | | return rows; |
| | | } |
| | | |
| | | productWorkOrderRapporteurMapper.delete(Wrappers.<ProductWorkOrderRapporteur>lambdaQuery() |
| | | .eq(ProductWorkOrderRapporteur::getWorkOrderId, productWorkOrderDto.getId())); |
| | | |
| | | Long[] rapporteurIds = productWorkOrderDto.getReportWorkersId(); |
| | | if (rapporteurIds == null || rapporteurIds.length == 0) { |
| | | return rows; |
| | | } |
| | | |
| | | List<Long> candidateUserIds = Arrays.stream(rapporteurIds) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(candidateUserIds)) { |
| | | return rows; |
| | | } |
| | | |
| | | List<Long> existUserIds = sysUserMapper.selectUserByIds(candidateUserIds).stream() |
| | | .map(SysUser::getUserId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | if (existUserIds.size() != candidateUserIds.size()) { |
| | | List<Long> invalidUserIds = candidateUserIds.stream() |
| | | .filter(id -> !existUserIds.contains(id)) |
| | | .collect(Collectors.toList()); |
| | | throw new ServiceException("报工人不存在: " + invalidUserIds); |
| | | } |
| | | |
| | | List<ProductWorkOrderRapporteur> rapporteurList = candidateUserIds.stream() |
| | | .map(userId -> { |
| | | ProductWorkOrderRapporteur rapporteur = new ProductWorkOrderRapporteur(); |
| | | rapporteur.setWorkOrderId(productWorkOrderDto.getId()); |
| | | rapporteur.setUserId(userId); |
| | | return rapporteur; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!rapporteurList.isEmpty()) { |
| | | rapporteurList.forEach(productWorkOrderRapporteurMapper::insert); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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); |
| | | }); |
| | |
| | | put("actualStartTime", productWorkOrderDto.getActualStartTime()); |
| | | put("actualEndTime", productWorkOrderDto.getActualEndTime()); |
| | | put("twoCode", Pictures.ofLocal(codePath).create()); |
| | | put("images", images.isEmpty()?null:images); |
| | | put("images", images.isEmpty() ? null : images); |
| | | }}); |
| | | |
| | | try { |