package com.yuanchu.mom.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.yuanchu.mom.mapper.*;
|
import com.yuanchu.mom.pojo.*;
|
import com.yuanchu.mom.pojo.dto.UpdateInspectUnacceptedDto;
|
import com.yuanchu.mom.service.OpinionService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.mom.utils.JackSonUtil;
|
import com.yuanchu.mom.vo.Result;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicReference;
|
|
/**
|
* <p>
|
* 不合格处理意见表 服务实现类
|
* </p>
|
*
|
* @author 江苏鵷雏网络科技有限公司
|
* @since 2023-08-07 01:54:28
|
*/
|
@Service
|
public class OpinionServiceImpl extends ServiceImpl<OpinionMapper, Opinion> implements OpinionService {
|
|
@Resource
|
private OpinionMapper opinionMapper;
|
|
@Resource
|
InspectUnacceptedMapper inspectUnacceptedMapper;
|
|
@Resource
|
RawInspectMapper rawInspectMapper;
|
|
@Resource
|
ProcessInspectMapper processInspectMapper;
|
|
@Resource
|
FinishedInspectMapper finishedInspectMapper;
|
|
@Resource
|
InspectionItemMapper inspectionItemMapper;
|
|
@Resource
|
RawInsProductMapper rawInsProductMapper;
|
|
|
@Override
|
public List<UpdateInspectUnacceptedDto> clickEditingTriggerQuery(Integer rawUnacceptedId) {
|
List<UpdateInspectUnacceptedDto> mapList = opinionMapper.clickEditingTriggerQuery(rawUnacceptedId);
|
if (mapList.size() == 0) {
|
List<Opinion> list = new ArrayList<>();
|
for (int i = 0; i <= 3; i++) {
|
Opinion opinion = new Opinion()
|
.setType(i)
|
.setRawUnacceptedId(rawUnacceptedId);
|
list.add(opinion);
|
}
|
opinionMapper.insertBatchSomeColumn(list);
|
mapList = opinionMapper.clickEditingTriggerQuery(rawUnacceptedId);
|
}
|
return mapList;
|
}
|
|
//编辑意见
|
@Override
|
public Integer updateOpinion(String id, List<?> opinion) {
|
List<Opinion> list = new ArrayList<>();
|
AtomicInteger a= new AtomicInteger();
|
AtomicInteger unId= new AtomicInteger();
|
opinion.forEach(i -> {
|
try {
|
Opinion unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(i), Opinion.class);
|
unmarshal.setUserId(Integer.valueOf(id));
|
unmarshal.setFillDate(new Date());
|
list.add(unmarshal);
|
//记录处理的方式为返修的次数
|
if (unmarshal.getWay()==1){
|
a.getAndIncrement();
|
}
|
//记录这个处理意见关联的不合格订单id
|
unId.set(opinionMapper.selectById(unmarshal.getId()).getRawUnacceptedId());
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
});
|
//编辑意见之后姜处理状态修改为1已处理
|
InspectUnaccepted inspectUnaccepted = inspectUnacceptedMapper.selectById(unId.get());
|
inspectUnaccepted.setDealState(1);
|
inspectUnacceptedMapper.updateById(inspectUnaccepted);
|
//如果全部都是返修则返回检验,将检验状态清空
|
if (a.get()==opinion.size()){
|
switch (inspectUnaccepted.getType()){
|
case 1:
|
//成品检验单
|
finishedInspectMapper.updById(inspectUnaccepted.getRawInspectId());
|
//成品检验项目
|
List<InspectionItem> inspectionItemList = inspectionItemMapper.selectList(Wrappers.<InspectionItem>query()
|
.eq("type", 2)
|
.eq("inspect_id", inspectUnaccepted.getRawInspectId()));
|
inspectionItemMapper.updateBatch(inspectionItemList);
|
break;
|
case 2:
|
//过程检验单
|
processInspectMapper.updById(inspectUnaccepted.getRawInspectId());
|
//过程检验项目
|
List<InspectionItem> inspectionItems = inspectionItemMapper.selectList(Wrappers.<InspectionItem>query()
|
.eq("type", 1)
|
.eq("inspect_id", inspectUnaccepted.getRawInspectId()));
|
inspectionItemMapper.updateBatch(inspectionItems);
|
break;
|
case 0:
|
//原材料检验单
|
rawInspectMapper.updById(inspectUnaccepted.getRawInspectId());
|
//原材料检验项目
|
List<RawInsProduct> rawInsProductList = rawInsProductMapper.selectList(Wrappers.<RawInsProduct>query()
|
.eq("raw_inspect_id", inspectUnaccepted.getRawInspectId()));
|
rawInsProductMapper.updateBatch(rawInsProductList);
|
break;
|
default:
|
break;
|
}
|
}
|
//更新意见
|
return opinionMapper.updateOpinion(list);
|
}
|
|
@Override
|
public List<Map<String, Object>> viewEditorialComments(Integer rawUnacceptedId) {
|
return opinionMapper.viewEditorialComments(rawUnacceptedId);
|
}
|
}
|