| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.mapper.InspectUnacceptedMapper; |
| | | import com.yuanchu.mom.mapper.RepertoryMapper; |
| | | import com.yuanchu.mom.pojo.FinishedInspect; |
| | | import com.yuanchu.mom.mapper.FinishedInspectMapper; |
| | | import com.yuanchu.mom.pojo.InspectUnaccepted; |
| | | import com.yuanchu.mom.pojo.Repertory; |
| | | import com.yuanchu.mom.service.FinishedInspectService; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.pojo.vo.FinishedInspectVo; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.service.InspectionItemService; |
| | | import com.yuanchu.mom.service.ProductService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class FinishedInspectServiceImpl extends ServiceImpl<FinishedInspectMapper, FinishedInspect> implements FinishedInspectService { |
| | | |
| | | @Resource |
| | | private FinishedInspectMapper finishedInspectMapper; |
| | | FinishedInspectMapper finishedInspectMapper; |
| | | |
| | | @Autowired |
| | | private ProductService productService; |
| | | @Resource |
| | | ManualTechnologyMapper manualTechnologyMapper; |
| | | |
| | | @Autowired |
| | | private InspectionItemService inspectionItemService; |
| | | @Resource |
| | | ManualProductService manualProductService; |
| | | |
| | | @Resource |
| | | InspectionItemService inspectionItemService; |
| | | |
| | | @Resource |
| | | InspectionItemMapper inspectionItemMapper; |
| | | |
| | | @Resource |
| | | InspectUnacceptedMapper inspectUnacceptedMapper; |
| | |
| | | @Resource |
| | | RepertoryMapper repertoryMapper; |
| | | |
| | | //新增检验单-->根据订单号选择产品信息 |
| | | @Override |
| | | public Integer addProcessInspectionSheet(FinishedInspect finishedInspect) { |
| | | finishedInspect.setType(0); |
| | | int insert = finishedInspectMapper.insert(finishedInspect); |
| | | if (insert == 1) { |
| | | List<Map<String, Object>> maps = productService.selectProductList(finishedInspect.getSpecificationsId()); |
| | | inspectionItemService.insertList(finishedInspect.getId(), maps); |
| | | return insert; |
| | | } |
| | | return 0; |
| | | public List<Map<String, Object>> chooseMater(String orderNumber) { |
| | | return finishedInspectMapper.chooseMater(orderNumber); |
| | | } |
| | | |
| | | //新增成品检验单 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addProcessInspectionSheet(String userId, FinishedInspectVo finishedInspectVo) { |
| | | //根据生产订单id查询编制工序的最后一道工艺 |
| | | List<ManualTechnology> manualTechnologyList = manualTechnologyMapper.selAllByMoId(finishedInspectVo.getId()); |
| | | //获取编制工艺最后一道工艺的id |
| | | Integer mtId = manualTechnologyList.get(0).getId(); |
| | | /*新增成品检验单*/ |
| | | FinishedInspect finishedInspect = new FinishedInspect(); |
| | | finishedInspect.setUserId(Integer.parseInt(userId)); |
| | | finishedInspect.setOrderNumber(finishedInspectVo.getOrderNumber()); |
| | | finishedInspect.setCustomerName(finishedInspectVo.getPrname()); |
| | | finishedInspect.setProjectName(finishedInspectVo.getSname()); |
| | | finishedInspect.setQualityTraceability(finishedInspectVo.getQualityTraceability()); |
| | | finishedInspect.setUnit(finishedInspectVo.getUnit()); |
| | | finishedInspect.setQuantity(finishedInspectVo.getQuantity()); |
| | | finishedInspect.setSpecificationsModel(finishedInspectVo.getSpecificationsModel()); |
| | | finishedInspect.setMaterial(finishedInspectVo.getMaterial()); |
| | | finishedInspect.setMaterialCode(finishedInspectVo.getMcode()); |
| | | //finishedInspect.setTechId(technologyId); |
| | | finishedInspectMapper.insert(finishedInspect); |
| | | /*批量新增成品检验项目单*/ |
| | | List<ManualProduct> manualProductList = manualProductService.selByMtid(mtId); |
| | | List<InspectionItem> inspectionItemList = manualProductList.stream().map(manualProduct -> { |
| | | InspectionItem inspectionItem = new InspectionItem(); |
| | | BeanUtils.copyProperties(manualProductList, inspectionItem); |
| | | inspectionItem.setId(null); |
| | | inspectionItem.setCreateTime(new Date()); |
| | | inspectionItem.setUpdateTime(new Date()); |
| | | inspectionItem.setInspectId(finishedInspect.getId()); |
| | | inspectionItem.setType(2);//成品 |
| | | return inspectionItem; |
| | | }).collect(Collectors.toList()); |
| | | inspectionItemService.saveBatch(inspectionItemList); |
| | | return finishedInspect.getId(); |
| | | } |
| | | |
| | | |
| | | //上报(更新检验状态) |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer inspectionConclusion(String username, Integer finishedInspectId, Integer result) { |
| | | //更新检验单里面的检验结论 |
| | | LambdaUpdateWrapper<FinishedInspect> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(FinishedInspect::getId, finishedInspectId); |
| | | updateWrapper.set(FinishedInspect::getResult, result); |
| | | finishedInspectMapper.update(new FinishedInspect(), updateWrapper); |
| | | //如果检验结论为不合格,则需要新增不合格检验单,还需要新增半成品库存 |
| | | FinishedInspect finishedInspect = finishedInspectMapper.selectById(finishedInspectId); |
| | | if (result == 0) { |
| | | /*新增不合格检验单*/ |
| | | InspectUnaccepted inspectUnaccepted = InspectUnaccepted.builder() |
| | | .reason(finishedInspect.getProjectName() + "不合格") //暂且定义为工程名称不合格 |
| | | .rawInspectId(finishedInspectId) |
| | | .type(finishedInspect.getType()) |
| | | public String updateFinishInspectsById(String username, Integer id) { |
| | | /*更新检验单里面的检验结论*/ |
| | | //先判断检验结果 |
| | | List<Integer> results = inspectionItemMapper.getResult(id, 2); |
| | | int count = 0; |
| | | for (Integer result : results) { |
| | | if (result != null && result == 1) { |
| | | count++; |
| | | } |
| | | } |
| | | FinishedInspect finishedInspect = finishedInspectMapper.selectById(id); |
| | | //如果检验项目中的结论包含不合格则检验单不合格 |
| | | if (results.contains(0)) { |
| | | finishedInspect.setResult(0);//不合格 |
| | | //更新检验单 |
| | | finishedInspectMapper.updateById(finishedInspect); |
| | | } else if (count == results.size()) { |
| | | finishedInspect.setResult(1);//合格 |
| | | finishedInspectMapper.updateById(finishedInspect); |
| | | } else return "项目未检验完!"; |
| | | /*如果检验结论为不合格,则需要新增不合格检验单*/ |
| | | if (finishedInspect.getResult() == 0) { |
| | | InspectUnaccepted finishUnaccepted = InspectUnaccepted.builder() |
| | | .reason(finishedInspect.getMaterial() + "不合格") //暂且定义为产品名称不合格 |
| | | .rawInspectId(id) |
| | | .type(1) //类型为成品检验 |
| | | .build(); |
| | | inspectUnacceptedMapper.insert(inspectUnaccepted); |
| | | /*新增半成品(1)库存*/ |
| | | inspectUnacceptedMapper.insert(finishUnaccepted); |
| | | } |
| | | /*如果检验结论为合格,则需要新增半成品库存*/ |
| | | if (finishedInspect.getResult() == 1) { |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getCode, finishedInspect.getMaterialCode()) |
| | | .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 1); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null && rep.getCheckState()==1) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条半成品库存 |
| | | Repertory repertory = Repertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .code(finishedInspect.getMaterialCode()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .type(1) |
| | | .checkState(1) |
| | | .build(); |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | //如果检验合格,需要新增成品(0)库存 |
| | | if (result == 1) { |
| | | /*新增成品(0)库存*/ |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getCode, finishedInspect.getMaterialCode()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 0); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null && rep.getCheckState()==1) { |
| | | if (rep != null) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条成品库存 |
| | | Repertory repertory = Repertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .code(finishedInspect.getMaterialCode()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .type(0) |
| | | .checkState(1) |
| | | .build(); |
| | | Repertory repertory = new Repertory(); |
| | | repertory.setOrderCode(finishedInspect.getOrderNumber()); |
| | | repertory.setQualityTraceability(finishedInspect.getQualityTraceability()); |
| | | repertory.setName(finishedInspect.getMaterial()); |
| | | repertory.setSpecifications(finishedInspect.getSpecificationsModel()); |
| | | repertory.setUnit(finishedInspect.getUnit()); |
| | | repertory.setNumber(finishedInspect.getQuantity()); |
| | | repertory.setUserName(username); |
| | | repertory.setType(1);//半成品 |
| | | repertory.setCheckResult(1);//暂定不删 |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | return 1; |
| | | return "上报成功!"; |
| | | } |
| | | |
| | | //分页查询成品检验单列表 |
| | | @Override |
| | | public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer inspectResult, String inspectDate, String inspectUsername) { |
| | | return finishedInspectMapper.selectFinishedInspectPage(page, inspectResult, inspectDate, inspectUsername); |
| | | public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer result, String material) { |
| | | return finishedInspectMapper.selectFinishedInspectPage(page, result, material); |
| | | } |
| | | |
| | | //根据检验单id查询成品检验单详情 |
| | | @Override |
| | | public List<Map<String, Object>> selectFinishInspectsListById(Integer id) { |
| | | return finishedInspectMapper.selectFinishInspectsListById(id); |
| | | } |
| | | |
| | | |
| | | } |