package com.yuanchu.mom.service.impl;
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.mom.mapper.InspectUnacceptedMapper;
|
import com.yuanchu.mom.mapper.InspectionItemMapper;
|
import com.yuanchu.mom.mapper.RawInsProductMapper;
|
import com.yuanchu.mom.pojo.*;
|
import com.yuanchu.mom.pojo.dto.InspectionItemDto;
|
import com.yuanchu.mom.pojo.vo.RawInspectVo;
|
import com.yuanchu.mom.service.*;
|
import com.yuanchu.mom.utils.MyUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.xml.crypto.Data;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 不合格品检验表(InspectUnaccepted)表服务实现类
|
*
|
* @author zss
|
* @since 2023-08-07 10:04:01
|
*/
|
@Service
|
public class InspectUnacceptedServiceImpl extends ServiceImpl<InspectUnacceptedMapper, InspectUnaccepted> implements InspectUnacceptedService {
|
|
@Resource
|
InspectUnacceptedMapper inspectUnacceptedMapper;
|
|
// 原材料检验
|
@Autowired
|
private RawInspectService rawInspectService;
|
|
//原材料检验子数据
|
@Autowired
|
private RawInsProductService rawInsProductService;
|
|
@Resource
|
RawInsProductMapper rawInsProductMapper;
|
|
//产品检验
|
@Autowired
|
private FinishedInspectService finishedInspectService;
|
|
//过程检验
|
@Autowired
|
private ProcessInspectService processInspectService;
|
|
@Resource
|
InspectionItemMapper inspectionItemMapper;
|
|
@Resource
|
InspectionItemService inspectionItemService;
|
|
//不合格处置列表
|
@Override
|
public IPage<Map<String, Object>> selectDisposal(Page<Object> page, String specificationModel, String productName, Integer productCategories, Integer state) {
|
return inspectUnacceptedMapper.selectDisposal(page, specificationModel, productName, productCategories, state);
|
}
|
|
//现象描述失焦保存
|
@Override
|
public Integer descriptionUpdate(Integer rawUnacceptedId, String tell) {
|
LambdaUpdateWrapper<InspectUnaccepted> updateWrapper = Wrappers.<InspectUnaccepted>lambdaUpdate()
|
.eq(InspectUnaccepted::getId, rawUnacceptedId)
|
.set(InspectUnaccepted::getTell, tell);
|
return inspectUnacceptedMapper.update(new InspectUnaccepted(), updateWrapper);
|
}
|
|
//编辑处置意见确定按钮
|
@Override
|
public Integer editDisposalOpinionConfirmation(Integer rawUnacceptedId, String opinionTell, Integer way, Integer type) {
|
//根据不合格品id查询不合格品信息
|
InspectUnaccepted inspectUnaccepted = inspectUnacceptedMapper.selectById(rawUnacceptedId);
|
LambdaUpdateWrapper<InspectUnaccepted> updateWrapper = Wrappers.<InspectUnaccepted>lambdaUpdate()
|
.eq(InspectUnaccepted::getId, rawUnacceptedId)
|
.set(InspectUnaccepted::getWay, way)
|
.set(InspectUnaccepted::getDealState, 1)
|
.set(InspectUnaccepted::getDealTime, new Date())
|
.set(InspectUnaccepted::getOpinionTell, opinionTell);
|
if (way == 1) {
|
// 等于0:原材料
|
if (type == 0) {
|
// 根据Id查询原材料检验信息
|
RawInspect rawInspect = rawInspectService.getById(inspectUnaccepted.getRawInspectId());
|
List<RawInsProduct> rawInsProductList = rawInsProductMapper.selectList(Wrappers.<RawInsProduct>query()
|
.eq("raw_inspect_id", rawInspect.getId()));
|
// 保存父级
|
rawInspect.setId(null);
|
rawInspect.setInsState(0);
|
rawInspect.setJudgeState(null);
|
rawInspect.setInsTime(null);
|
rawInspectService.save(rawInspect);
|
// 批量保存子级
|
List<RawInsProduct> rawInsProducts = rawInsProductList.stream().map(rawInsProduct -> {
|
rawInsProduct.setId(null);
|
rawInsProduct.setTestValue(null);
|
rawInsProduct.setTestState(null);
|
rawInsProduct.setDeviceId(null);
|
rawInsProduct.setRawInspectId(rawInspect.getId());
|
rawInsProduct.setUserId(null);
|
return rawInsProduct;
|
}).collect(Collectors.toList());
|
rawInsProductService.saveBatch(rawInsProducts);
|
}
|
// 等于1:产品检验(半成品)
|
else if (type == 1) {
|
//根据id查询产品检验信息
|
FinishedInspect finishedInspect = finishedInspectService.getById(inspectUnaccepted.getRawInspectId());
|
//根据产品检验单id查询检验项目
|
List<InspectionItem> inspectionItems = inspectionItemMapper.selectList(Wrappers.<InspectionItem>query()
|
.eq("inspect_id", finishedInspect.getId())
|
.eq("type", 2));
|
//保存产品单
|
finishedInspect.setId(null);
|
finishedInspect.setResult(null);
|
finishedInspectService.save(finishedInspect);
|
//保存产品项目
|
List<InspectionItem> inspectionItemList = inspectionItems.stream().map(inspectionItem -> {
|
inspectionItem.setId(null);
|
inspectionItem.setInspectionValue(null);
|
inspectionItem.setDeviceId(null);
|
inspectionItem.setResult(null);
|
inspectionItem.setInspectId(finishedInspect.getId());
|
inspectionItem.setUsername(null);
|
return inspectionItem;
|
}).collect(Collectors.toList());
|
inspectionItemService.saveBatch(inspectionItemList);
|
}
|
// 等于2:过程检验(在制品)
|
else if (type == 2) {
|
//根据id查询产品检验信息
|
ProcessInspect processInspect = processInspectService.getById(inspectUnaccepted.getRawInspectId());
|
//根据产品检验单id查询检验项目
|
List<InspectionItem> inspectionItems = inspectionItemMapper.selectList(Wrappers.<InspectionItem>query()
|
.eq("inspect_id", processInspect.getId())
|
.eq("type", 1));
|
//保存产品单
|
processInspect.setId(null);
|
processInspect.setResult(null);
|
processInspectService.save(processInspect);
|
//保存产品项目
|
List<InspectionItem> inspectionItemList = inspectionItems.stream().map(inspectionItem -> {
|
inspectionItem.setId(null);
|
inspectionItem.setInspectionValue(null);
|
inspectionItem.setDeviceId(null);
|
inspectionItem.setResult(null);
|
inspectionItem.setInspectId(processInspect.getId());
|
inspectionItem.setUsername(null);
|
return inspectionItem;
|
}).collect(Collectors.toList());
|
inspectionItemService.saveBatch(inspectionItemList);
|
}
|
} else if (way == 2 || way == 3 || way == 4) {
|
updateWrapper.set(InspectUnaccepted::getFaultyMaterials, 1);
|
}
|
return inspectUnacceptedMapper.update(new InspectUnaccepted(), updateWrapper);
|
}
|
}
|