| | |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | QualityInspect qualityInspect = new QualityInspect(); |
| | | BeanUtils.copyProperties(qualityInspectDto,qualityInspect); |
| | | qualityInspect.setInspectState(0);//默认未提交 |
| | | qualityInspectMapper.insert(qualityInspect); |
| | | int inserted = qualityInspectMapper.insert(qualityInspect); |
| | | if (inserted <= 0 || qualityInspect.getId() == null) { |
| | | throw new ServiceException("新增检验记录失败"); |
| | | } |
| | | for (QualityInspectParam qualityInspectParam : qualityInspectDto.getQualityInspectParams()) { |
| | | qualityInspectParam.setInspectId(qualityInspect.getId()); |
| | | } |
| | | qualityInspectParamService.saveBatch(qualityInspectDto.getQualityInspectParams()); |
| | | return 0; |
| | | if (!qualityInspectParamService.saveBatch(qualityInspectDto.getQualityInspectParams())) { |
| | | throw new ServiceException("保存检验项目失败"); |
| | | } |
| | | return inserted; |
| | | } |
| | | |
| | | @Override |
| | | public QualityInspectDto getDetailById(Integer id) { |
| | | QualityInspect qualityInspect = qualityInspectMapper.selectById(id); |
| | | if (qualityInspect == null) { |
| | | throw new ServiceException("检验记录不存在"); |
| | | } |
| | | List<QualityInspectParam> qualityInspectParams = qualityInspectParamService.list(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, id)); |
| | | QualityInspectDto qualityInspectDto = new QualityInspectDto(); |
| | | BeanUtils.copyProperties(qualityInspect,qualityInspectDto); |
| | |
| | | //提交 |
| | | @Override |
| | | public int submit(QualityInspect inspect) { |
| | | if (inspect == null || inspect.getId() == null) { |
| | | throw new ServiceException("检验记录ID不能为空"); |
| | | } |
| | | QualityInspect qualityInspect = qualityInspectMapper.selectById(inspect.getId()); |
| | | if (qualityInspect == null) { |
| | | throw new ServiceException("检验记录不存在"); |
| | | } |
| | | if (Integer.valueOf(1).equals(qualityInspect.getInspectState())) { |
| | | throw new ServiceException("检验记录已提交,请勿重复操作"); |
| | | } |
| | | if (!"合格".equals(qualityInspect.getCheckResult()) |
| | | && !"不合格".equals(qualityInspect.getCheckResult())) { |
| | | throw new ServiceException("请先完成检验结果判定"); |
| | | } |
| | | List<QualityInspectParam> inspectParams = qualityInspectParamService.list( |
| | | Wrappers.<QualityInspectParam>lambdaQuery() |
| | | .eq(QualityInspectParam::getInspectId, inspect.getId())); |
| | | if (inspectParams.isEmpty()) { |
| | | throw new ServiceException("检验项目为空,不能提交"); |
| | | } |
| | | for (QualityInspectParam parameter : inspectParams) { |
| | | if (StringUtils.isBlank(parameter.getTestValue())) { |
| | | throw new ServiceException("检验项目“" + parameter.getParameterItem() + "”尚未填写检验值"); |
| | | } |
| | | } |
| | | /*判断不合格*/ |
| | | if (ObjectUtils.isNotNull(qualityInspect.getCheckResult()) && qualityInspect.getCheckResult().equals("不合格")){ |
| | | QualityUnqualified qualityUnqualified = new QualityUnqualified(); |
| | | BeanUtils.copyProperties(qualityInspect,qualityUnqualified); |
| | | qualityUnqualified.setInspectState(0);//待处理 |
| | | List<QualityInspectParam> inspectParams = qualityInspectParamService.list(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, inspect.getId())); |
| | | String text = inspectParams.stream().map(QualityInspectParam::getParameterItem).collect(Collectors.joining(",")); |
| | | qualityUnqualified.setDefectivePhenomena(text+"这些指标中存在不合格");//不合格现象 |
| | | qualityUnqualifiedMapper.insert(qualityUnqualified); |
| | |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if (qualityInspect.getInspectType() == 0) { |
| | | if ("合格".equals(qualityInspect.getCheckResult())) { |
| | | // 合格且关联了采购单/产品信息时才自动入库,信息不全时跳过入库但正常提交 |
| | | if ("合格".equals(qualityInspect.getCheckResult()) |
| | | && qualityInspect.getPurchaseLedgerId() != null) { |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(qualityInspect.getProductId()); |
| | | if (salesLedgerProduct != null) { |
| | | ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto(); |
| | | procurementRecordOutAdd.setType(1); |
| | | procurementRecordOutAdd.setTypeName("采购原材料检验合格入库"); |
| | | procurementRecordOutAdd.setNickName(loginUser.getNickName()); |
| | | procurementRecordOutAdd.setPurchaseLedgerId(Math.toIntExact(qualityInspect.getPurchaseLedgerId())); |
| | | if (qualityInspect.getPurchaseLedgerId() == null) { |
| | | throw new BaseException("请选择采购单"); |
| | | } |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(qualityInspect.getProductId()); |
| | | |
| | | ArrayList<Details> detailss = new ArrayList<>(); |
| | | Details details = new Details(); |
| | |
| | | procurementRecordOutAdd.setQualityInspectId(qualityInspect.getId()); |
| | | procurementRecordService.add(procurementRecordOutAdd); |
| | | } |
| | | } |
| | | }else if (qualityInspect.getInspectType() == 1) { |
| | | //查询UnitPrice/TotalPrice |
| | | // 过程检验仅合格时入库,不合格品由上面的不合格管理流程处理 |
| | | if ("合格".equals(qualityInspect.getCheckResult())) { |
| | | ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto(); |
| | | procurementRecordOutAdd.setType(2); |
| | | procurementRecordOutAdd.setTypeName("生产过程检验合格入库"); |
| | |
| | | .productModelId(details1.getProductModelId()) |
| | | .qualityInspectId(qualityInspect.getId()); |
| | | procurementRecordService.save(procurementRecordBuilder.build()); |
| | | |
| | | |
| | | |
| | | } |
| | | }else if (qualityInspect.getInspectType() == 2) { |
| | | //查询UnitPrice/TotalPrice |
| | | // 出厂检验仅合格时入库,缺少产品信息时跳过入库但正常提交 |
| | | if ("合格".equals(qualityInspect.getCheckResult())) { |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectSalesLedgerProductByMainId(qualityInspect.getProductMainId()); |
| | | if (salesLedgerProduct != null) { |
| | | ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto(); |
| | | procurementRecordOutAdd.setType(2); |
| | | procurementRecordOutAdd.setTypeName("生产出厂检验合格入库"); |
| | |
| | | procurementRecordOutAdd.setQualityInspectId(qualityInspect.getId()); |
| | | procurementRecordService.add(procurementRecordOutAdd); |
| | | } |
| | | } |
| | | } |
| | | qualityInspect.setInspectState(1);//已提交 |
| | | return qualityInspectMapper.updateById(qualityInspect); |
| | | } |