| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | |
| | | 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.constant.Constants; |
| | | 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.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; |
| | |
| | | |
| | | @Override |
| | | public IPage<ProductWorkOrderDto> listPage(Page<ProductWorkOrderDto> page, ProductWorkOrderDto productWorkOrder) { |
| | | return productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId) || SecurityUtils.hasRole(Constants.SUPER_ADMIN); |
| | | return productWorkOrdermapper.pageProductWorkOrder(page, productWorkOrder, userId, isAdmin); |
| | | } |
| | | |
| | | @Override |
| | | public int updateProductWorkOrder(ProductWorkOrderDto productWorkOrderDto) { |
| | | checkWorkOrderPermission(productWorkOrderDto.getId()); |
| | | return productWorkOrdermapper.updateById(productWorkOrderDto); |
| | | } |
| | | |
| | | @Override |
| | | public ProductWorkOrder getProductWorkOrderById(Long id) { |
| | | checkWorkOrderPermission(id); |
| | | return this.getById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void down(HttpServletResponse response, ProductWorkOrder productWorkOrder) { |
| | | checkWorkOrderPermission(productWorkOrder.getId()); |
| | | ProductWorkOrderDto productWorkOrderDto = productWorkOrdermapper.getProductWorkOrderFlowCard(productWorkOrder.getId()); |
| | | String codePath; |
| | | try { |
| | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | /*获取附件图片类型*/ |
| | | List<Map<String, Object>> images = new ArrayList<>(); |
| | | List<ProductWorkOrderFile> productWorkOrderFiles = productWorkOrderFileMapper.selectList(Wrappers.<ProductWorkOrderFile>lambdaQuery().eq(ProductWorkOrderFile::getWorkOrderId, productWorkOrder.getId())); |
| | | 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 { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode( |
| | | "流转卡", "UTF-8"); |
| | | String fileName = URLEncoder.encode("流转卡", "UTF-8"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename=" + fileName + ".docx"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |
| | | template.write(os); |
| | | os.flush(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void checkWorkOrderPermission(Long workOrderId) { |
| | | if (workOrderId == null) { |
| | | throw new RuntimeException("工单ID不能为空"); |
| | | } |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId) || SecurityUtils.hasRole(Constants.SUPER_ADMIN); |
| | | if (isAdmin) { |
| | | return; |
| | | } |
| | | Integer count = productWorkOrdermapper.checkUserCanAccess(workOrderId, userId); |
| | | if (count == null || count == 0) { |
| | | throw new RuntimeException("无权访问该工单"); |
| | | } |
| | | } |
| | | } |