| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.ruoyi.common.enums.StockRecordTypeEnum; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.procurementrecord.dto.Details; |
| | | import com.ruoyi.procurementrecord.dto.ProcurementAddDto; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.procurementrecord.service.ProcurementRecordService; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.mapper.ProductOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductionProductMainMapper; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | import com.ruoyi.production.pojo.ProductionProductMain; |
| | | import com.ruoyi.quality.dto.QualityInspectDto; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardMapper; |
| | |
| | | import com.ruoyi.quality.service.IQualityInspectParamService; |
| | | import com.ruoyi.quality.service.IQualityInspectService; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.io.OutputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | private ProcurementRecordService procurementRecordService; |
| | | |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | |
| | | private ProductOrderMapper productOrderMapper; |
| | | |
| | | |
| | | @Override |
| | | public int add(QualityInspectDto qualityInspectDto) { |
| | |
| | | @Override |
| | | public int submit(QualityInspect inspect) { |
| | | QualityInspect qualityInspect = qualityInspectMapper.selectById(inspect.getId()); |
| | | ProductionProductMain productionProductMain = productionProductMainMapper.selectById(qualityInspect.getProductMainId()); |
| | | |
| | | String batchNo; |
| | | String customer; |
| | | if (productionProductMain != null) { |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId()); |
| | | ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId()); |
| | | batchNo = productOrder.getBatchNo(); |
| | | customer = "长治市轴承制造有限公司"; |
| | | } else { |
| | | batchNo = qualityInspect.getBatchNo(); |
| | | customer = qualityInspect.getSupplier(); |
| | | } |
| | | |
| | | //提交前必须判断是否合格 |
| | | if (ObjectUtils.isNull(qualityInspect.getCheckResult())) { |
| | | throw new RuntimeException("请先判断是否合格"); |
| | | } |
| | | /*判断不合格*/ |
| | | if (ObjectUtils.isNotNull(qualityInspect.getCheckResult()) && qualityInspect.getCheckResult().equals("不合格")) { |
| | | if (qualityInspect.getCheckResult().equals("不合格")) { |
| | | QualityUnqualified qualityUnqualified = new QualityUnqualified(); |
| | | BeanUtils.copyProperties(qualityInspect, qualityUnqualified); |
| | | qualityUnqualified.setInspectState(0);//待处理 |
| | |
| | | qualityUnqualifiedMapper.insert(qualityUnqualified); |
| | | } else { |
| | | //合格直接入库 |
| | | stockUtils.addStock(inspect.getProductModelId(), inspect.getQuantity(), StockRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode(), inspect.getId()); |
| | | stockUtils.addStock(qualityInspect.getProductModelId(), qualityInspect.getQuantity(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode(), |
| | | qualityInspect.getId(), batchNo, customer |
| | | ); |
| | | } |
| | | qualityInspect.setInspectState(1);//已提交 |
| | | return qualityInspectMapper.updateById(qualityInspect); |
| | |
| | | |
| | | @Override |
| | | public IPage<QualityInspect> qualityInspectListPage(Page page, QualityInspect qualityInspect) { |
| | | IPage<QualityInspect> qualityInspectIPage = qualityInspectMapper.qualityInspectListPage(page, qualityInspect); |
| | | List<QualityInspect> records = qualityInspectIPage.getRecords(); |
| | | for (int i = 0; i < records.size(); i++) { |
| | | QualityInspect item = records.get(i); |
| | | ProductModel productModel = productModelMapper.selectById(item.getProductModelId()); |
| | | if (productModel == null) { |
| | | continue; |
| | | } |
| | | item.setUidNo(productModel.getUidNo()); |
| | | } |
| | | |
| | | return qualityInspectMapper.qualityInspectListPage(page, qualityInspect); |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void downOutReport(HttpServletResponse response, QualityInspect qualityInspect) { |
| | | QualityInspect inspect = qualityInspectMapper.selectOneData(qualityInspect.getId()); |
| | | |
| | | // 格式化日期字段 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | inspect.setCheckTimeStr(inspect.getCheckTime() != null ? sdf.format(inspect.getCheckTime()) : ""); |
| | | inspect.setProductionDateStr(inspect.getProductionDate() != null ? inspect.getProductionDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : ""); |
| | | inspect.setValidityDateStr(inspect.getValidityDate() != null ? inspect.getValidityDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : ""); |
| | | |
| | | // 获取检验参数列表 |
| | | List<QualityInspectParam> paramList = qualityInspectParamService.list( |
| | | Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, inspect.getId())); |
| | | int index = 1; |
| | | for (QualityInspectParam detail : paramList) { |
| | | detail.setIndex(index); |
| | | index++; |
| | | } |
| | | |
| | | // 获取产品型号信息(包含有效期) |
| | | ProductModel productModel = null; |
| | | BigDecimal validityPeriod = null; |
| | | if (inspect.getProductModelId() != null) { |
| | | productModel = productModelMapper.selectById(inspect.getProductModelId()); |
| | | if (productModel != null) { |
| | | validityPeriod = productModel.getValidityPeriod(); |
| | | } |
| | | } |
| | | /*String calculatedValidityDate = ""; |
| | | if (inspect.getProductionDate() != null && validityPeriod != null) { |
| | | LocalDate productionDate = inspect.getProductionDate(); |
| | | int years = validityPeriod.intValue(); |
| | | int months = validityPeriod |
| | | .subtract(new BigDecimal(years)) |
| | | .multiply(new BigDecimal(12)) |
| | | .setScale(0, RoundingMode.HALF_UP) |
| | | .intValue(); |
| | | LocalDate calculatedDate = productionDate |
| | | .plusYears(years) |
| | | .plusMonths(months); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | calculatedValidityDate = calculatedDate.format(formatter); |
| | | }*/ |
| | | |
| | | // 检验依据:产品名称 + 出厂检验操作流程 |
| | | String checkBasis = (inspect.getProductName() != null ? inspect.getProductName() : "") + "出厂检验操作流程"; |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/out-report-template.docx"); |
| | | Configure configure = Configure.builder() |
| | | .bind("paramList", new HackLoopTableRenderPolicy()) |
| | | .build(); |
| | | // final String finalCalculatedValidityDate = calculatedValidityDate; |
| | | final String finalCheckBasis = checkBasis; |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("inspect", inspect); |
| | | put("checkBasis", finalCheckBasis); |
| | | // put("calculatedValidityDate", finalCalculatedValidityDate); |
| | | put("paramList", paramList); |
| | | }}); |
| | | |
| | | try { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode("出库检验报告", "UTF-8"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |
| | | template.write(os); |
| | | os.flush(); |
| | | os.close(); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | |
| | | } |