heheng
2 天以前 338f2f5afc7762dabf2409f296d5d023462ed4b5
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
152
153
154
155
156
157
158
159
160
161
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.constant.UserConstant;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.AnnualVerificationPlan;
import com.gkhy.exam.system.domain.SixInspection;
import com.gkhy.exam.system.domain.SixInspectionContent;
import com.gkhy.exam.system.domain.SixInspectionProblem;
import com.gkhy.exam.system.mapper.SixInspectionContentMapper;
import com.gkhy.exam.system.mapper.SixInspectionMapper;
import com.gkhy.exam.system.mapper.SixInspectionProblemMapper;
import com.gkhy.exam.system.service.SixInspectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 * 6s检查主表 服务实现类
 * </p>
 *
 * @author hh
 * @since 2025-08-25 15:01:44
 */
@Service
public class SixInspectionServiceImpl extends ServiceImpl<SixInspectionMapper, SixInspection> implements SixInspectionService {
 
    @Autowired
    private SixInspectionMapper sixInspectionMapper;
 
    @Autowired
    private SixInspectionProblemMapper sixInspectionProblemMapper;
 
    @Autowired
    private SixInspectionContentMapper sixInspectionContentMapper;
 
    @Override
    public CommonPage selectSixInspectionList(SixInspection sixInspection) {
        PageUtils.startPage();
        List<SixInspection> sixInspections = sixInspectionMapper.selectSixInspectionList(sixInspection);
        return CommonPage.restPage(sixInspections);
    }
 
    @Override
    @Transactional
    public CommonResult saveSixInspection(SixInspection sixInspection) {
        List<SixInspectionContent> sixInspectionContentList = sixInspection.getSixInspectionContentList();
        if (ObjectUtils.isEmpty(sixInspectionContentList)) {
            return CommonResult.failed("保存参数不能为空");
        }
 
        int i = 0;
        if (sixInspection.getId() == null) {
            sixInspection.setCreateBy(SecurityUtils.getUsername());
            sixInspection.setCreateTime(LocalDateTime.now());
            i = sixInspectionMapper.insert(sixInspection);
        } else {
            sixInspection.setUpdateBy(SecurityUtils.getUsername());
            sixInspection.setUpdateTime(LocalDateTime.now());
            i = sixInspectionMapper.updateById(sixInspection);
        }
        if (i > 0) {
            batchSave(sixInspection.getId(), sixInspectionContentList, sixInspection.getDelProblemIds(), sixInspection.getDelContentIds(), sixInspection.getSixInspectionProblemList());
        }
        return i > 0 ? CommonResult.success() : CommonResult.failed();
    }
 
    private void batchSave(Long id, List<SixInspectionContent> sixInspectionContentList,
                           List<Long> delProblemIds, List<Long> delContentIds, List<SixInspectionProblem> sixInspectionProblemList) {
        if (ObjectUtils.isNotEmpty(delProblemIds)) {
            int update = sixInspectionProblemMapper.update(new SixInspectionProblem(),
                    new LambdaUpdateWrapper<SixInspectionProblem>().set(SixInspectionProblem::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(SixInspectionProblem::getUpdateTime, LocalDateTime.now()).set(SixInspectionProblem::getUpdateBy, SecurityUtils.getUsername())
                            .in(SixInspectionProblem::getId, delProblemIds)
            );
        }
        if (ObjectUtils.isNotEmpty(delContentIds)) {
            int update = sixInspectionContentMapper.update(new SixInspectionContent(),
                    new LambdaUpdateWrapper<SixInspectionContent>().set(SixInspectionContent::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(SixInspectionContent::getUpdateTime, LocalDateTime.now()).set(SixInspectionContent::getUpdateBy, SecurityUtils.getUsername())
                            .in(SixInspectionContent::getId, delContentIds)
            );
        }
        if (ObjectUtils.isNotEmpty(sixInspectionContentList)) {
            sixInspectionContentList.forEach(sixInspectionContent -> {
                if (sixInspectionContent.getId() == null) {
                    sixInspectionContent.setSixInspectionId(id);
                    sixInspectionContent.setCreateTime(LocalDateTime.now());
                    sixInspectionContent.setCreateBy(SecurityUtils.getUsername());
                    sixInspectionContentMapper.insert(sixInspectionContent);
                } else {
                    sixInspectionContent.setUpdateTime(LocalDateTime.now());
                    sixInspectionContent.setUpdateBy(SecurityUtils.getUsername());
                    sixInspectionContentMapper.updateById(sixInspectionContent);
                }
            });
        }
        if (ObjectUtils.isNotEmpty(sixInspectionProblemList)) {
            sixInspectionProblemList.forEach(sixInspectionProblem -> {
                if (sixInspectionProblem.getId() == null) {
                    sixInspectionProblem.setSixInspectionId(id);
                    sixInspectionProblem.setCreateTime(LocalDateTime.now());
                    sixInspectionProblem.setCreateBy(SecurityUtils.getUsername());
                    sixInspectionProblemMapper.insert(sixInspectionProblem);
                } else {
                    sixInspectionProblem.setUpdateTime(LocalDateTime.now());
                    sixInspectionProblem.setUpdateBy(SecurityUtils.getUsername());
                    sixInspectionProblemMapper.updateById(sixInspectionProblem);
                }
            });
        }
    }
 
    @Override
    public CommonResult getSixInspection(Long id) {
        SixInspection sixInspection = sixInspectionMapper.selectById(id);
        if (sixInspection != null) {
            List<SixInspectionContent> sixInspectionContentList = sixInspectionContentMapper.selectList(new LambdaQueryWrapper<>(SixInspectionContent.class).eq(SixInspectionContent::getSixInspectionId, id)
                    .eq(SixInspectionContent::getDelFlag, UserConstant.ENABLE).orderByAsc(SixInspectionContent::getSort));
            sixInspection.setSixInspectionContentList(sixInspectionContentList);
            List<SixInspectionProblem> sixInspectionProblemList = sixInspectionProblemMapper.selectList(
                    new LambdaQueryWrapper<>(SixInspectionProblem.class).eq(SixInspectionProblem::getSixInspectionId, id)
                            .eq(SixInspectionProblem::getDelFlag, UserConstant.ENABLE).orderByAsc(SixInspectionProblem::getSort)
            );
            sixInspection.setSixInspectionProblemList(sixInspectionProblemList);
        }
        return CommonResult.success(sixInspection);
    }
 
    @Override
    @Transactional
    public CommonResult deletedSixInspection(Long id) {
        int update = sixInspectionMapper.update(new SixInspection(),
                new LambdaUpdateWrapper<SixInspection>().eq(SixInspection::getId, id)
                        .set(SixInspection::getDelFlag, UserConstant.DEPT_DISABLE).set(SixInspection::getUpdateTime, LocalDateTime.now())
                        .set(SixInspection::getUpdateBy, SecurityUtils.getUsername()));
        if (update > 0) {
            sixInspectionContentMapper.update(new SixInspectionContent(),
                    new LambdaUpdateWrapper<SixInspectionContent>().eq(SixInspectionContent::getSixInspectionId, id)
                            .set(SixInspectionContent::getDelFlag, UserConstant.DEPT_DISABLE).set(SixInspectionContent::getUpdateTime, LocalDateTime.now())
                            .set(SixInspectionContent::getUpdateBy, SecurityUtils.getUsername())
            );
            sixInspectionProblemMapper.update(new SixInspectionProblem(),
                    new LambdaUpdateWrapper<SixInspectionProblem>().eq(SixInspectionProblem::getSixInspectionId, id)
                            .set(SixInspectionProblem::getDelFlag, UserConstant.DEPT_DISABLE).set(SixInspectionProblem::getUpdateTime, LocalDateTime.now())
                            .set(SixInspectionProblem::getUpdateBy, SecurityUtils.getUsername())
            );
        }
        return update > 0 ? CommonResult.success() : CommonResult.failed();
    }
}