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();
|
}
|
}
|