zss
2023-09-25 d1ea726be5628c46fb6be700a0197002d55d39f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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.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;
 
    //产品检验
    @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查询原材料检验信息
                RawInspectVo map = inspectUnacceptedMapper.editDisposalOpinionConfirmation(rawUnacceptedId);
                RawInspect rawInspect = new RawInspect();
                BeanUtils.copyProperties(map, rawInspect);
                // 保存父级
                rawInspectService.save(rawInspect);
                // 批量保存子级
                rawInsProductService.batchAddInsProduct(rawInspect.getId(), map.getRawInsProducts());
            }
            // 等于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);
    }
}