mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
package com.panzhihua.service_community.service.impl;
 
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
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.panzhihua.common.model.dtos.community.social.HatchAuditProcessDTO;
import com.panzhihua.common.model.dtos.community.social.PageSocialOrgHatchAuditDTO;
import com.panzhihua.common.model.dtos.community.social.SocialOrgHatchAuditDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.social.SocialOrgHatchAuditScheduleVO;
import com.panzhihua.common.model.vos.community.social.SocialOrgHatchAuditVO;
import com.panzhihua.service_community.dao.ComActSocialOrgHatchAuditDAO;
import com.panzhihua.service_community.dao.ComActSocialOrgHatchAuditScheduleDAO;
import com.panzhihua.service_community.dao.ComActSocialOrgHatchDAO;
import com.panzhihua.service_community.dao.SysConfMapper;
import com.panzhihua.service_community.entity.ComActSocialOrgHatch;
import com.panzhihua.service_community.entity.ComActSocialOrgHatchAudit;
import com.panzhihua.service_community.entity.ComActSocialOrgHatchAuditSchedule;
import com.panzhihua.service_community.model.dos.SysConfDO;
import com.panzhihua.service_community.service.ComActSocialOrgHatchAuditService;
 
/**
 * 社会组织孵化申请表(ComActSocialOrgHatchAudit)表服务实现类
 *
 * @author makejava
 * @since 2022-04-18 14:09:53
 */
@Service("comActSocialOrgHatchAuditService")
public class ComActSocialOrgHatchAuditServiceImpl extends ServiceImpl<ComActSocialOrgHatchAuditDAO, ComActSocialOrgHatchAudit> implements ComActSocialOrgHatchAuditService {
 
    private static final String SOCIAL_ORG_HATCH_AUDIT_PROCESS_KEY = "SOCIAL_ORG_PROCESS";
    private static final String SOCIAL_ORG_HATCH_AUDIT_PROCESS_NAME = "社会组织孵化流程";
 
    @Resource
    private ComActSocialOrgHatchDAO comActSocialOrgHatchDAO;
    @Resource
    private ComActSocialOrgHatchAuditScheduleDAO comActSocialOrgHatchAuditScheduleDAO;
    @Resource
    private SysConfMapper sysConfMapper;
 
    /**
     * 分页查询孵化申请
     * @param pageHatchAuditDTO
     * @return
     */
    @Override
    public R pageHatchAudit(PageSocialOrgHatchAuditDTO pageHatchAuditDTO) {
        Page page = new Page<>();
        page.setSize(pageHatchAuditDTO.getPageSize());
        page.setCurrent(pageHatchAuditDTO.getPageNum());
        return R.ok(this.baseMapper.pageHatchAudit(page, pageHatchAuditDTO));
    }
 
    /**
     * 查看孵化申请详情
     * @param id
     * @return
     */
    @Override
    public R detailHatchAudit(Long id) {
        return R.ok(this.baseMapper.detailHatchAudit(id));
    }
 
    /**
     * 修改孵化申请
     * @param hatchAuditDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateHatchAudit(SocialOrgHatchAuditDTO hatchAuditDTO) {
        ComActSocialOrgHatchAudit hatchAudit = this.baseMapper.selectById(hatchAuditDTO.getId());
        if (isNull(hatchAudit)) {
            return R.fail("资源不存在");
        }
        Integer preStatus = hatchAudit.getStatus();
        Integer status = hatchAuditDTO.getStatus();
        BeanUtils.copyProperties(hatchAuditDTO, hatchAudit);
        int result = this.baseMapper.updateById(hatchAudit);
        if (nonNull(status) && !preStatus.equals(status) && status.equals(1)) {
            //重新提交
            if (result > 0) {
                //创建申请进度记录
                ComActSocialOrgHatchAuditSchedule hatchAuditSchedule = new ComActSocialOrgHatchAuditSchedule();
                hatchAuditSchedule.setAuditId(hatchAuditDTO.getId());
                hatchAuditSchedule.setStage(ComActSocialOrgHatchAuditSchedule.Stage.cxtj);
                comActSocialOrgHatchAuditScheduleDAO.insert(hatchAuditSchedule);
            }
        } else if (nonNull(status) && !preStatus.equals(status) && status.equals(2)) {
            //审核通过
            if (result > 0) {
                //创建孵化数据
                ComActSocialOrgHatchAudit newHatchAudit = this.baseMapper.selectById(hatchAuditDTO.getId());
                ComActSocialOrgHatch socialOrgHatch = new ComActSocialOrgHatch();
                BeanUtils.copyProperties(newHatchAudit, socialOrgHatch);
                socialOrgHatch.setCreatedAt(null);
                socialOrgHatch.setId(null);
                socialOrgHatch.setStatus(1);
                socialOrgHatch.setUpdatedAt(null);
                socialOrgHatch.setAuditId(hatchAudit.getId());
                comActSocialOrgHatchDAO.insert(socialOrgHatch);
                //创建申请进度记录
                ComActSocialOrgHatchAuditSchedule hatchAuditSchedule = new ComActSocialOrgHatchAuditSchedule();
                hatchAuditSchedule.setAuditId(hatchAuditDTO.getId());
                hatchAuditSchedule.setStage(ComActSocialOrgHatchAuditSchedule.Stage.shtg);
                comActSocialOrgHatchAuditScheduleDAO.insert(hatchAuditSchedule);
            }
        } else if (nonNull(status) && !preStatus.equals(status) && status.equals(3)) {
            //驳回申请
            if (result > 0) {
                //创建申请进度记录
                ComActSocialOrgHatchAuditSchedule hatchAuditSchedule = new ComActSocialOrgHatchAuditSchedule();
                hatchAuditSchedule.setAuditId(hatchAuditDTO.getId());
                hatchAuditSchedule.setStage(ComActSocialOrgHatchAuditSchedule.Stage.ybh);
                hatchAuditSchedule.setDetail(hatchAuditDTO.getRefuseReason());
                comActSocialOrgHatchAuditScheduleDAO.insert(hatchAuditSchedule);
            }
        }
        return result > 0 ? R.ok() : R.fail("操作失败,请重新尝试");
    }
 
    /**
     * 获取孵化流程配置
     * @return
     */
    @Override
    public R getHatchAuditProcess() {
        return R.ok(sysConfMapper.getSysConfValue(SOCIAL_ORG_HATCH_AUDIT_PROCESS_KEY, null));
    }
 
    /**
     * 修改孵化流程配置
     * @param processDTO
     * @return
     */
    @Override
    public R putHatchAuditProcess(HatchAuditProcessDTO processDTO) {
        SysConfDO sysConfDO = sysConfMapper.selectOne(new LambdaQueryWrapper<SysConfDO>().eq(SysConfDO::getCode, SOCIAL_ORG_HATCH_AUDIT_PROCESS_KEY));
        int result = 0;
        if (isNull(sysConfDO)) {
            sysConfDO=new SysConfDO();
            //创建
            sysConfDO.setName(SOCIAL_ORG_HATCH_AUDIT_PROCESS_NAME);
            sysConfDO.setCode(SOCIAL_ORG_HATCH_AUDIT_PROCESS_KEY);
            sysConfDO.setDescription(SOCIAL_ORG_HATCH_AUDIT_PROCESS_NAME);
            sysConfDO.setCreateAt(new Date());
            result = sysConfMapper.insert(sysConfDO);
        } else {
            sysConfDO.setValue(processDTO.getProcess());
            result = sysConfMapper.update(sysConfDO, new LambdaQueryWrapper<SysConfDO>().eq(SysConfDO::getCode, SOCIAL_ORG_HATCH_AUDIT_PROCESS_KEY));
        }
        return result > 0 ? R.ok() : R.fail("操作失败,请重新尝试");
    }
 
    /**
     * 新增孵化申请
     * @param hatchAuditDTO
     * @return
     */
    @Override
    public R addHatchAudit(SocialOrgHatchAuditDTO hatchAuditDTO) {
        SocialOrgHatchAuditVO orgHatchAuditVO = this.baseMapper.getHatchAuditSchedule(hatchAuditDTO.getUserId());
        if (nonNull(orgHatchAuditVO)) {
            return R.fail("请勿重复申请");
        }
        ComActSocialOrgHatchAudit orgHatchAudit = new ComActSocialOrgHatchAudit();
        BeanUtils.copyProperties(hatchAuditDTO, orgHatchAudit);
        orgHatchAudit.setStatus(1);
        int result = this.baseMapper.insert(orgHatchAudit);
        if (result > 0) {
            //创建申请进度记录
            ComActSocialOrgHatchAuditSchedule hatchAuditSchedule = new ComActSocialOrgHatchAuditSchedule();
            hatchAuditSchedule.setAuditId(orgHatchAudit.getId());
            hatchAuditSchedule.setStage(ComActSocialOrgHatchAuditSchedule.Stage.tjzl);
            comActSocialOrgHatchAuditScheduleDAO.insert(hatchAuditSchedule);
            return R.ok();
        }
        return R.fail("操作失败,请重新尝试");
    }
 
    /**
     * 查看孵化申请审核进度
     * @param userId
     * @return
     */
    @Override
    public R getHatchAuditSchedule(Long userId) {
        SocialOrgHatchAuditVO orgHatchAuditVO = this.baseMapper.getHatchAuditSchedule(userId);
        if (nonNull(orgHatchAuditVO)) {
            List<ComActSocialOrgHatchAuditSchedule> schedules = comActSocialOrgHatchAuditScheduleDAO.selectList(new LambdaQueryWrapper<ComActSocialOrgHatchAuditSchedule>()
                    .eq(ComActSocialOrgHatchAuditSchedule::getAuditId, orgHatchAuditVO.getId()).orderByAsc(ComActSocialOrgHatchAuditSchedule::getCreatedAt));
            if (!schedules.isEmpty()) {
                List<SocialOrgHatchAuditScheduleVO> scheduleVOList = new ArrayList<>();
                schedules.stream().forEach(e -> {
                    SocialOrgHatchAuditScheduleVO scheduleVO = new SocialOrgHatchAuditScheduleVO();
                    BeanUtils.copyProperties(e, scheduleVO);
                    scheduleVOList.add(scheduleVO);
                });
                orgHatchAuditVO.setScheduleVOList(scheduleVOList);
            }
        }
        return R.ok(orgHatchAuditVO);
    }
 
    /**
     * 删除孵化申请详情
     * @param id
     * @return
     */
    @Override
    public R deleteHatchAudit(Long id) {
        this.baseMapper.deleteById(id);
        comActSocialOrgHatchAuditScheduleDAO.delete(new LambdaQueryWrapper<ComActSocialOrgHatchAuditSchedule>()
                .eq(ComActSocialOrgHatchAuditSchedule::getAuditId, id));
        return R.ok();
    }
}