郑永安
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
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.commons.utils.StringUtils;
import com.gkhy.safePlatform.specialWork.entity.WorkApplyCountDO;
import com.gkhy.safePlatform.specialWork.entity.WorkApplyInfo;
import com.gkhy.safePlatform.specialWork.entity.WorkApplyReportableDO;
import com.gkhy.safePlatform.specialWork.enums.WorkApplyStatusEnum;
import com.gkhy.safePlatform.specialWork.model.bo.WorkApplyPendingInfoBO;
import com.gkhy.safePlatform.specialWork.model.query.db.AllWorkApplyPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkApplyApplyingPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkApplyPendingPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkProcessWorkApplyDBQuery;
import com.gkhy.safePlatform.specialWork.repository.WorkApplyInfoRepository;
import com.gkhy.safePlatform.specialWork.service.baseService.WorkApplyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service("workApplyInfoService")
public class WorkApplyInfoServiceImpl extends ServiceImpl<WorkApplyInfoRepository, WorkApplyInfo> implements WorkApplyInfoService {
 
    @Autowired
    private WorkApplyInfoRepository workApplyInfoRepository;
 
 
    @Override
    public void saveWorkApplyInfo(WorkApplyInfo applyEntity) {
        if (applyEntity == null || applyEntity.getId() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = workApplyInfoRepository.insertWorkApplyInfo(applyEntity);
        if (i != 1) {
            throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
        }
    }
 
    @Override
    public void updateStatusById(Long workApplyId, WorkApplyStatusEnum statusEnum) {
        if (workApplyId == null || statusEnum == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = workApplyInfoRepository.updateStatusById(workApplyId, statusEnum.getStatus());
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
 
    @Override
    public List<WorkApplyInfo> listWorkApplyInfoByPage(Page<WorkApplyInfo> page, WorkApplyApplyingPageDBQuery dbQuery) {
        if (page == null || dbQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return workApplyInfoRepository.listWorkApplyInfoByPage(page,dbQuery);
    }
 
    @Override
    public List<WorkApplyPendingInfoBO> listPendingWorkApplyInfo(Page<WorkApplyPendingInfoBO> page, WorkApplyPendingPageDBQuery dbQuery) {
        if (page == null || dbQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return workApplyInfoRepository.listPendingWorkApplyInfo(page,dbQuery);
    }
 
    @Override
    public WorkApplyInfo getWorkApprovalByApprovalUid(Long workApplyId, Long approvalUid) {
        if (workApplyId == null || approvalUid == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return workApplyInfoRepository.getWorkApprovalByApprovalUid(workApplyId,approvalUid);
    }
 
    @Override
    public int countWorkApplyInfo() {
        return workApplyInfoRepository.countWorkApplyInfo();
    }
 
    @Override
    public void updateApprovalStepIdById(Long workApplyId, Long nextStepId) {
        if (workApplyId == null || nextStepId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = workApplyInfoRepository.updateApprovalStepIdById(workApplyId, nextStepId);
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
 
    @Override
    public WorkApplyInfo getApplyInfoByWorkPermitNo(String workPermitNo) {
        if (StringUtils.isBlank(workPermitNo)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        List<WorkApplyInfo> workApplyInfos = workApplyInfoRepository.selectList(new LambdaQueryWrapper<WorkApplyInfo>()
                // 编号
                .eq(WorkApplyInfo::getWorkPermitNo, workPermitNo));
 
        if (workApplyInfos.size() == 0) {
            return null;
        }
        if (workApplyInfos.size() > 1) {
            throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
        }
 
        return workApplyInfos.get(0);
    }
 
    @Override
    public List<WorkApplyReportableDO> listReportableWorkApply(WorkProcessWorkApplyDBQuery dbQuery) {
        if (dbQuery == null || dbQuery.getNow() == null || dbQuery.getStatus() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return workApplyInfoRepository.listReportableWorkApply(dbQuery);
    }
 
    @Override
    public List<WorkApplyInfo> listAllWorkApplyByPage(Page<WorkApplyInfo> page, AllWorkApplyPageDBQuery dbQuery) {
        if (page == null || dbQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return workApplyInfoRepository.listAllWorkApplyByPage(page,dbQuery);
    }
 
    @Override
    public List<WorkApplyCountDO> getWorkApplyCountByDep() {
        return workApplyInfoRepository.getWorkApplyCountByDep();
    }
 
    @Override
    public void finishStepById(Long workApplyId) {
        if (workApplyId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = workApplyInfoRepository.updateApprovalStepIdToNull(workApplyId);
        if (i != 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
}