zss
2023-09-19 3625accd261feb99a6927013d7551a08d68c756e
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
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);
    }
}