XiaoRuby
2023-08-09 ea1f48f286fa96abcd70f7063c1f5bdc94f13cc5
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
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.extension.plugins.pagination.Page;
import com.yuanchu.mom.mapper.InspectUnacceptedMapper;
import com.yuanchu.mom.pojo.FinishedInspect;
import com.yuanchu.mom.mapper.FinishedInspectMapper;
import com.yuanchu.mom.pojo.InspectUnaccepted;
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 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;
 
    @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
    public Integer inspectionConclusion(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);
        }
        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);
    }
}