XiaoRuby
2023-08-11 7b09f233bde70508f6db7e08e983e9a2c4bb3e99
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
package com.yuanchu.mom.service.impl;
 
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.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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.service.InspectionItemService;
import com.yuanchu.mom.service.ProductService;
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.List;
import java.util.Map;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-08-01
 */
@Service
public class FinishedInspectServiceImpl extends ServiceImpl<FinishedInspectMapper, FinishedInspect> implements FinishedInspectService {
 
    @Resource
    private FinishedInspectMapper finishedInspectMapper;
 
    @Autowired
    private ProductService productService;
 
    @Autowired
    private InspectionItemService inspectionItemService;
 
    @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;
    }
 
 
    @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())
                    .build();
            inspectUnacceptedMapper.insert(inspectUnaccepted);
            /*新增半成品(1)库存*/
            //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量
            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, 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) {
            //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量
            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) {
                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();
                repertoryMapper.insert(repertory);
            }
        }
        return 1;
    }
 
    @Override
    public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer inspectResult, String inspectDate, String inspectUsername) {
        return finishedInspectMapper.selectFinishedInspectPage(page, inspectResult, inspectDate, inspectUsername);
    }
}