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
162
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.DocumentChangesInvalidated;
import com.gkhy.exam.system.domain.DocumentChangesInvalidatedEvaluate;
import com.gkhy.exam.system.domain.DocumentChangesInvalidatedIssue;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedEvaluateMapper;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedIssueMapper;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedMapper;
import com.gkhy.exam.system.service.DocumentChangesInvalidatedService;
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>
 * 文件更改作废申请主表     服务实现类
 * </p>
 *
 * @author hh
 * @since 2025-08-25 15:01:44
 */
@Service
public class DocumentChangesInvalidatedServiceImpl extends ServiceImpl<DocumentChangesInvalidatedMapper, DocumentChangesInvalidated> implements DocumentChangesInvalidatedService {
 
    @Autowired
    private DocumentChangesInvalidatedMapper documentChangesInvalidatedMapper;
 
    @Autowired
    private DocumentChangesInvalidatedIssueMapper documentChangesInvalidatedIssueMapper;
 
    @Autowired
    private DocumentChangesInvalidatedEvaluateMapper documentChangesInvalidatedEvaluateMapper;
 
    @Override
    public CommonPage selectDocumentChangesInvalidatedList(DocumentChangesInvalidated documentChangesInvalidated) {
        PageUtils.startPage();
        List<DocumentChangesInvalidated> documentChangesInvalidated1 = documentChangesInvalidatedMapper.getDocumentChangesInvalidated(documentChangesInvalidated);
        return CommonPage.restPage(documentChangesInvalidated1);
    }
 
    @Override
    @Transactional
    public CommonResult saveDocumentChangesInvalidated(DocumentChangesInvalidated documentChangesInvalidated) {
        int i = 0;
        if (documentChangesInvalidated.getId() == null){
            documentChangesInvalidated.setCreateBy(SecurityUtils.getUsername());
            documentChangesInvalidated.setCreateTime(LocalDateTime.now());
            i = documentChangesInvalidatedMapper.insert(documentChangesInvalidated);
        }else {
            documentChangesInvalidated.setUpdateTime(LocalDateTime.now());
            documentChangesInvalidated.setUpdateBy(SecurityUtils.getUsername());
            i = documentChangesInvalidatedMapper.updateById(documentChangesInvalidated);
        }
        if (i > 0){
            batchSave(documentChangesInvalidated.getId(), documentChangesInvalidated.getDocumentChangesInvalidatedEvaluateList()
                    , documentChangesInvalidated.getDocumentChangesInvalidatedIssueList(),documentChangesInvalidated.getDelEvaluateIds(),documentChangesInvalidated.getDelInvalidatedIssueIds());
        }
        return i > 0 ? CommonResult.success() : CommonResult.failed();
    }
 
    private void batchSave(Long id, List<DocumentChangesInvalidatedEvaluate> documentChangesInvalidatedEvaluates,
                           List<DocumentChangesInvalidatedIssue> documentChangesInvalidatedIssues,
                           List<Long> delEvaluateIds, List<Long> delInvalidatedIssueIds) {
        if (ObjectUtils.isNotEmpty(delEvaluateIds)){
 
            int update = documentChangesInvalidatedEvaluateMapper.update(new DocumentChangesInvalidatedEvaluate(),
                    new LambdaUpdateWrapper<DocumentChangesInvalidatedEvaluate>().set(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(DocumentChangesInvalidatedEvaluate::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedEvaluate::getUpdateBy, SecurityUtils.getUsername())
                            .in(DocumentChangesInvalidatedEvaluate::getId, delEvaluateIds)
            );
        }
        if (ObjectUtils.isNotEmpty(delInvalidatedIssueIds)){
 
            int update = documentChangesInvalidatedIssueMapper.update(new DocumentChangesInvalidatedIssue(),
                    new LambdaUpdateWrapper<DocumentChangesInvalidatedIssue>().set(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(DocumentChangesInvalidatedIssue::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedIssue:: getUpdateBy, SecurityUtils.getUsername())
                    .in(DocumentChangesInvalidatedIssue::getId, delInvalidatedIssueIds)
            );
        }
        if (ObjectUtils.isNotEmpty(documentChangesInvalidatedIssues)){
            documentChangesInvalidatedIssues.forEach(documentChangesInvalidatedIssue -> {
                if (documentChangesInvalidatedIssue.getId() == null){
                    documentChangesInvalidatedIssue.setDocumentChangesId(id);
                    documentChangesInvalidatedIssue.setCreateTime(LocalDateTime.now());
                    documentChangesInvalidatedIssue.setCreateBy(SecurityUtils.getUsername());
                    documentChangesInvalidatedIssueMapper.insert(documentChangesInvalidatedIssue);
                }else {
                    documentChangesInvalidatedIssue.setUpdateTime(LocalDateTime.now());
                    documentChangesInvalidatedIssue.setUpdateBy(SecurityUtils.getUsername());
                    documentChangesInvalidatedIssueMapper.updateById(documentChangesInvalidatedIssue);
                }
            });
        }
        if (ObjectUtils.isNotEmpty(documentChangesInvalidatedEvaluates)){
            documentChangesInvalidatedEvaluates.forEach(documentChangesInvalidatedEvaluate -> {
 
                if (documentChangesInvalidatedEvaluate.getId() == null){
                    documentChangesInvalidatedEvaluate.setDocumentChangesId(id);
                    documentChangesInvalidatedEvaluate.setCreateTime(LocalDateTime.now());
                    documentChangesInvalidatedEvaluate.setCreateBy(SecurityUtils.getUsername());
                    documentChangesInvalidatedEvaluateMapper.insert(documentChangesInvalidatedEvaluate);
                }else {
                    documentChangesInvalidatedEvaluate.setUpdateTime(LocalDateTime.now());
                    documentChangesInvalidatedEvaluate.setUpdateBy(SecurityUtils.getUsername());
                    documentChangesInvalidatedEvaluateMapper.updateById(documentChangesInvalidatedEvaluate);
                }
            });
        }
 
    }
 
    @Override
    public CommonResult getDocumentChangesInvalidated(Long id) {
        DocumentChangesInvalidated documentChangesInvalidated = documentChangesInvalidatedMapper.selectById(id);
        if (documentChangesInvalidated != null){
 
            List<DocumentChangesInvalidatedIssue> documentChangesInvalidatedIssues = documentChangesInvalidatedIssueMapper.selectList(new LambdaQueryWrapper<>(DocumentChangesInvalidatedIssue.class)
                    .eq(DocumentChangesInvalidatedIssue::getDocumentChangesId, id)
                    .eq(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.ENABLE).orderByAsc(DocumentChangesInvalidatedIssue::getSort));
            documentChangesInvalidated.setDocumentChangesInvalidatedIssueList(documentChangesInvalidatedIssues);
            documentChangesInvalidated.setDocumentChangesInvalidatedEvaluateList(documentChangesInvalidatedEvaluateMapper.selectList(new LambdaQueryWrapper<>(DocumentChangesInvalidatedEvaluate.class).eq(DocumentChangesInvalidatedEvaluate::getDocumentChangesId, id)
                    .eq(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.ENABLE).orderByAsc(DocumentChangesInvalidatedEvaluate::getSort)));
        }
        return CommonResult.success(documentChangesInvalidated);
    }
 
    @Override
    @Transactional
    public CommonResult deletedDocumentChangesInvalidated(Long id) {
        int i = documentChangesInvalidatedMapper.update(new DocumentChangesInvalidated(),
                new LambdaUpdateWrapper<DocumentChangesInvalidated>().set(DocumentChangesInvalidated::getDelFlag, UserConstant.DEPT_DISABLE)
                        .set(DocumentChangesInvalidated::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidated::getUpdateBy, SecurityUtils.getUsername())
                        .eq(DocumentChangesInvalidated::getId, id)
        );
        if (i > 0){
            documentChangesInvalidatedIssueMapper.update(new DocumentChangesInvalidatedIssue(),
                    new LambdaUpdateWrapper<DocumentChangesInvalidatedIssue>().set(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(DocumentChangesInvalidatedIssue::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedIssue::getUpdateBy, SecurityUtils.getUsername())
                            .eq(DocumentChangesInvalidatedIssue::getDocumentChangesId, id)
            );
            documentChangesInvalidatedEvaluateMapper.update(new DocumentChangesInvalidatedEvaluate(),
                    new LambdaUpdateWrapper<DocumentChangesInvalidatedEvaluate>().set(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.DEPT_DISABLE)
                            .set(DocumentChangesInvalidatedEvaluate::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedEvaluate::getUpdateBy, SecurityUtils.getUsername())
                            .eq(DocumentChangesInvalidatedEvaluate::getDocumentChangesId, id)
            );
        }
        return CommonResult.success();
    }
}