|
|
@@ -3,6 +3,7 @@ package org.dromara.main.service.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -10,14 +11,17 @@ import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.main.domain.MainAudit;
|
|
|
import org.dromara.main.domain.MainBackCandidate;
|
|
|
import org.dromara.main.domain.MainPostApply;
|
|
|
import org.dromara.main.domain.bo.MainPostApplyBo;
|
|
|
import org.dromara.main.domain.vo.MainPostApplyVo;
|
|
|
+import org.dromara.main.mapper.MainAuditMapper;
|
|
|
import org.dromara.main.mapper.MainBackCandidateMapper;
|
|
|
import org.dromara.main.mapper.MainPostApplyMapper;
|
|
|
import org.dromara.main.service.IMainPostApplyService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Collection;
|
|
|
@@ -34,6 +38,7 @@ import java.util.stream.Collectors;
|
|
|
public class MainPostApplyServiceImpl implements IMainPostApplyService {
|
|
|
|
|
|
private final MainPostApplyMapper baseMapper;
|
|
|
+ private final MainAuditMapper mainAuditMapper;
|
|
|
private final MainBackCandidateMapper mainBackCandidateMapper;
|
|
|
|
|
|
@Override
|
|
|
@@ -58,21 +63,51 @@ public class MainPostApplyServiceImpl implements IMainPostApplyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean insertByBo(MainPostApplyBo bo) {
|
|
|
MainPostApply add = MapstructUtils.convert(bo, MainPostApply.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
+ MainAudit audit = buildPendingAudit(add.getId(), add.getTenantId());
|
|
|
+ mainAuditMapper.insert(audit);
|
|
|
+ add.setAuditId(audit.getId());
|
|
|
+ add.setApplyStatus(0);
|
|
|
+ baseMapper.updateById(add);
|
|
|
bo.setId(add.getId());
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateByBo(MainPostApplyBo bo) {
|
|
|
MainPostApply update = MapstructUtils.convert(bo, MainPostApply.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
+ update.setApplyStatus(0);
|
|
|
+ update.setRejectReason(null);
|
|
|
+ boolean updated = baseMapper.updateById(update) > 0;
|
|
|
+ if (!updated) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (update.getAuditId() != null) {
|
|
|
+ LambdaUpdateWrapper<MainAudit> updateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ updateWrapper.eq(MainAudit::getId, update.getAuditId())
|
|
|
+ .set(MainAudit::getAuditResult, 0)
|
|
|
+ .set(MainAudit::getAuditRemark, null)
|
|
|
+ .set(MainAudit::getAuditTime, null)
|
|
|
+ .set(MainAudit::getAuditBy, null);
|
|
|
+ mainAuditMapper.update(null, updateWrapper);
|
|
|
+ } else {
|
|
|
+ MainAudit audit = buildPendingAudit(update.getId(), update.getTenantId());
|
|
|
+ mainAuditMapper.insert(audit);
|
|
|
+ MainPostApply apply = new MainPostApply();
|
|
|
+ apply.setId(update.getId());
|
|
|
+ apply.setAuditId(audit.getId());
|
|
|
+ baseMapper.updateById(apply);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -171,4 +206,13 @@ public class MainPostApplyServiceImpl implements IMainPostApplyService {
|
|
|
|
|
|
postList.forEach(item -> item.setApplyCount(countMap.getOrDefault(item.getPostId(), 0L)));
|
|
|
}
|
|
|
+
|
|
|
+ private MainAudit buildPendingAudit(Long targetId, String tenantId) {
|
|
|
+ MainAudit audit = new MainAudit();
|
|
|
+ audit.setAuditType(2);
|
|
|
+ audit.setTargetId(targetId);
|
|
|
+ audit.setAuditResult(0);
|
|
|
+ audit.setTenantId(tenantId);
|
|
|
+ return audit;
|
|
|
+ }
|
|
|
}
|