郑永安
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
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.enums.RuleStatusEnum;
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleListDbQuery;
import com.gkhy.safePlatform.specialWork.repository.ApprovalRuleRepository;
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.List;
 
@Service("ApprovalRuleService")
public class ApprovalRuleServiceImpl extends ServiceImpl<ApprovalRuleRepository, ApprovalRule> implements ApprovalRuleService {
 
    @Autowired
    private ApprovalRuleRepository approvalRuleRepository;
 
    /**
     * 规则新增
     * @param rule
     * @return
     */
    @Override
    public int saveOneRule(ApprovalRule rule) {
        rule.setStatus(RuleStatusEnum.VALID.getCode());
        rule.setGmtCreate(LocalDateTime.now());
        return baseMapper.insert(rule);
    }
    /**
     * 更新
     * @param rule
     * @return
     */
    @Override
    public int updateRule(ApprovalRule rule) {
        rule.setGmtModified(LocalDateTime.now());
        return baseMapper.updateById(rule);
    }
    /**
     * 逻辑删除 批量删除
     */
    @Override
    public int updateStutsByRuleIds(List<Long> ruleIds) {
 
        return baseMapper.updateStutsByRuleIds(ruleIds,RuleStatusEnum.ABANDONED.getCode());
    }
 
    /**
     * 删除-单条
     */
    @Override
    public int updateStutsByRuleId(Long ruleId) {
 
        return baseMapper.updateStutsByRuleId(ruleId,RuleStatusEnum.ABANDONED.getCode());
    }
    /**
     * 条件查询
     * @param query
     * @return
     */
    @Override
    public List<ApprovalRule> listRule(ApprovalRuleListDbQuery query) {
        query.setStatus(RuleStatusEnum.VALID.getCode());
        List<ApprovalRule> approvalRuleList = baseMapper.listByConditions(query);
        return approvalRuleList;
    }
 
    @Override
    public List<ApprovalRule> listRuleByPage(Page<ApprovalRule> page, ApprovalRuleListDbQuery query) {
        query.setStatus(RuleStatusEnum.VALID.getCode());
        List<ApprovalRule> approvalRuleList = baseMapper.listByConditions(page,query);
        return approvalRuleList;
    }
 
    @Override
    public ApprovalRule getApprovalRuleInfo(Long depId, Byte workType, Byte workLevel) {
        if (depId == null || workLevel == null || workType == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return approvalRuleRepository.selectOne(new LambdaQueryWrapper<ApprovalRule>()
                // 部门id
                .eq(ApprovalRule::getDepId,depId)
                // 作业等级
                .eq(ApprovalRule::getWorkLevel,workLevel)
                // 作业类型
                .eq(ApprovalRule::getWorkType,workType)
                // 状态
                .eq(ApprovalRule::getStatus,RuleStatusEnum.VALID.getCode()));
    }
 
 
 
}