郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package com.gkhy.safePlatform.specialWork.service.baseService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.specialWork.entity.ApprovalRule;
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleUnitItem;
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleUnitItemDO;
import com.gkhy.safePlatform.specialWork.enums.RuleItemStatusEnum;
import com.gkhy.safePlatform.specialWork.enums.RuleStatusEnum;
import com.gkhy.safePlatform.specialWork.model.update.EntityStatusBatchUO;
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleItemDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleItemPageDBQuery;
import com.gkhy.safePlatform.specialWork.repository.ApprovalRuleUnitItemRepository;
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleUnitItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.List;
 
@Service("ApprovalRuleUnitItemService")
public class ApprovalRuleUnitItemServiceImpl extends ServiceImpl<ApprovalRuleUnitItemRepository, ApprovalRuleUnitItem> implements ApprovalRuleUnitItemService {
 
    @Autowired
    private ApprovalRuleUnitItemRepository approvalRuleUnitItemRepository;
 
    /**
     * 新增
     * @param item
     * @return
     */
    @Override
    public int saveOneItem(ApprovalRuleUnitItem item) {
        item.setStatus(RuleItemStatusEnum.VALID.getCode());
        item.setGmtCreate(LocalDateTime.now());
        return baseMapper.insert(item);
    }
 
    @Override
    public int batchSaveItemList(List<ApprovalRuleUnitItem> itemList) {
        return baseMapper.batchInsert(itemList);
    }
 
 
    @Override
    public List<ApprovalRuleUnitItem> listActiveByRuleStepId(Long stepId) {
        return baseMapper.listActiveByRuleStepId(stepId,RuleItemStatusEnum.VALID.getCode());
    }
 
    @Override
    public List<ApprovalRuleUnitItem> listByRuleId(Long ruleId) {
        return baseMapper.listActiveByRuleId(ruleId,RuleItemStatusEnum.VALID.getCode());
    }
    /**
     * 根据审批项删除
     * @param itemId
     * @return
     */
    @Override
    public int updateStatusById(Long itemId) {
        return baseMapper.updateStatusById(itemId,RuleItemStatusEnum.ABANDONED.getCode());
    }
 
    /**
     * 审批项删除
     * @param itemIds
     * @return
     */
    @Override
    public int updateStatusByIds(List<Long> itemIds) {
        return baseMapper.updateStatusByIds(itemIds,RuleItemStatusEnum.ABANDONED.getCode());
    }
 
    /**
     * 根据标准id获取数据
     * @param standIdList
     * @return
     */
    @Override
    public List<ApprovalRuleUnitItem> listActiveByRuleStandIds(List<Long> standIdList) {
        List<ApprovalRuleUnitItem> approvalRuleUnitItems = baseMapper.listActiveByRuleStandId(standIdList,RuleItemStatusEnum.VALID.getCode());
        return approvalRuleUnitItems;
    }
 
    /**
     * 根据ruleIds 批量删除
     * @param ruleIds
     * @return
     */
    @Override
    public int updateStatusByRuleIds(List<Long> ruleIds) {
        return baseMapper.updateStatusByRuleIds(ruleIds,RuleItemStatusEnum.ABANDONED.getCode());
    }
    /**
     * 根据规则删除
     * @param ruleId
     * @return
     */
    @Override
    public int updateStatusByRuleId(Long ruleId) {
        return baseMapper.updateStatusByRuleId(ruleId,RuleItemStatusEnum.ABANDONED.getCode());
    }
    /**
     * 根据层级删除 stepId
     */
    @Override
    public int updateStatusByStepId(Long stepId) {
        return baseMapper.updateStatusByStepId(stepId,RuleItemStatusEnum.ABANDONED.getCode());
    }
    /**
     * 根据层级删除 stepIds
     */
    @Override
    public int updateStatusByStepIds(List<Long> stepIds) {
        return baseMapper.updateStatusByStepIds(stepIds,RuleItemStatusEnum.ABANDONED.getCode());
    }
 
 
    @Override
    public void saveRuleItem(ApprovalRuleUnitItem itemEntity) {
        if (itemEntity == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = approvalRuleUnitItemRepository.insertRuleItem(itemEntity);
        if (i != 1) {
            throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
        }
    }
 
    @Override
    public void updateRuleItem(ApprovalRuleUnitItem itemEntity) {
        if (itemEntity == null || itemEntity.getId() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = approvalRuleUnitItemRepository.updateRuleItem(itemEntity);
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
 
    @Override
    public ApprovalRuleUnitItemDO getApprovalRuleUnitItemDOById(Long ruleItemId) {
        if (ruleItemId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return approvalRuleUnitItemRepository.getApprovalRuleUnitItemDOById(ruleItemId);
    }
 
    @Override
    public void deleteBatch(EntityStatusBatchUO entityBatchDeleteObject) {
        if (entityBatchDeleteObject == null ||
                entityBatchDeleteObject.getIds() == null ||
                entityBatchDeleteObject.getIds().size() == 0 ||
                entityBatchDeleteObject.getStatus() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = approvalRuleUnitItemRepository.updateStatusBatch(entityBatchDeleteObject);
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i != entityBatchDeleteObject.getIds().size()) {
            throw new BusinessException(ResultCodes.SERVER_BATCH_UPDATE_ERROR);
        }
 
    }
 
    @Override
    public List<ApprovalRuleUnitItem> listRuleItemByPage(Page<ApprovalRuleUnitItem> page, ApprovalRuleItemPageDBQuery dbQuery) {
        if (dbQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return approvalRuleUnitItemRepository.listRuleItemByPage(page,dbQuery);
    }
 
    @Override
    public List<ApprovalRuleUnitItemDO> listRuleItem(ApprovalRuleItemDBQuery dbQuery) {
        if (dbQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        dbQuery.setStatus(RuleItemStatusEnum.VALID.getCode());
        return approvalRuleUnitItemRepository.listRuleItemDO(dbQuery);
    }
 
    @Override
    public long countByRuleStandId(Long ruleStandId) {
        if (ruleStandId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return approvalRuleUnitItemRepository.selectCount(new LambdaQueryWrapper<ApprovalRuleUnitItem>()
                // 审批项标准id
                .eq(ApprovalRuleUnitItem::getStandId, ruleStandId)
                // 状态
                .eq(ApprovalRuleUnitItem::getStatus,RuleItemStatusEnum.VALID.getCode()));
    }
 
    /**
     * 根据措施ids统计数据
     * @param measureIds
     * @return
     */
    @Override
    public int countByMeasureIds(List<Long> measureIds) {
        return baseMapper.countByMeasureIds(measureIds,RuleItemStatusEnum.VALID.getCode());
    }
 
    @Override
    public int updateBatchItem(List<ApprovalRuleUnitItem> itemList) {
        return baseMapper.updateItemBatch(itemList);
    }
 
    @Override
    public List<ApprovalRuleUnitItem> listByNoConditions() {
        return baseMapper.selectList(new LambdaQueryWrapper<ApprovalRuleUnitItem>()
                .eq(ApprovalRuleUnitItem::getStatus,RuleItemStatusEnum.VALID.getCode()));
    }
 
    @Override
    public List<ApprovalRuleUnitItem> listApprovalRuleUnitItemByRuleId(Long ruleId) {
        if (ruleId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
 
        return approvalRuleUnitItemRepository.selectList(new LambdaQueryWrapper<ApprovalRuleUnitItem>()
                // 规则id
                .eq(ApprovalRuleUnitItem::getRuleId,ruleId)
                // 状态
                .eq(ApprovalRuleUnitItem::getStatus,RuleItemStatusEnum.VALID.getCode())
        );
    }
 
 
}