|
@@ -17,9 +17,11 @@ import org.springblade.control.vo.*;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
@@ -27,10 +29,10 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -39,6 +41,7 @@ public class TaskProcessServiceImpl extends BaseServiceImpl<TaskProcessMapper, T
|
|
|
|
|
|
private final IUserClient iUserClient;
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
+ private final BladeRedis bladeRedis;
|
|
|
|
|
|
@Override
|
|
|
public IPage<TaskProcessInfoVO> taskPage(IPage<TaskProcessInfo> page, TaskProcessInfoDTO dto) {
|
|
@@ -77,12 +80,19 @@ public class TaskProcessServiceImpl extends BaseServiceImpl<TaskProcessMapper, T
|
|
|
return pages.convert((obj -> {
|
|
|
TaskProcessInfoVO vo = new TaskProcessInfoVO();
|
|
|
BeanUtils.copyProperties(obj, vo);
|
|
|
+
|
|
|
vo.setReportUserName(userMap.get(vo.getReportUserId()));
|
|
|
+
|
|
|
List<String> auditUserNames = Arrays.stream(vo.getAuditUserIds().split(","))
|
|
|
.map(Long::parseLong).map(userMap::get)
|
|
|
.collect(Collectors.toList());
|
|
|
vo.setAuditUserNames(StringUtils.join(auditUserNames, "、"));
|
|
|
|
|
|
+ List<String> auditUserCompleteNames = Arrays.stream(vo.getAuditUserIdsComplete().split(","))
|
|
|
+ .map(Long::parseLong).map(userMap::get)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ vo.setAuditUserCompleteNames(StringUtils.join(auditUserCompleteNames, "、"));
|
|
|
+
|
|
|
vo.setStatusName(vo.getStatus().equals(1) ? "待审批" : (vo.getStatus().equals(2) ? "已审批" : "已驳回"));
|
|
|
|
|
|
for (DictInfo dictInfo : dictInfoList) {
|
|
@@ -135,7 +145,7 @@ public class TaskProcessServiceImpl extends BaseServiceImpl<TaskProcessMapper, T
|
|
|
data = jdbcTemplate.query("select * from c_expense_financial_reimbursement_info where id = " + record.getExpenseInfoId(), new BeanPropertyRowMapper<>(EMFinancialReimbursementInfo.class)).stream().findAny().orElse(null);
|
|
|
|
|
|
EMFinancialReimbursementInfoVO voCW = BeanUtil.copyProperties(data, EMFinancialReimbursementInfoVO.class);
|
|
|
- if (voCW != null){
|
|
|
+ if (voCW != null) {
|
|
|
for (DictInfo dictInfo : dictInfoList2) {
|
|
|
if (dictInfo.getDictValue().equals(voCW.getFrType() + "")) {
|
|
|
voCW.setFrTypeName(dictInfo.getDictName());
|
|
@@ -197,53 +207,176 @@ public class TaskProcessServiceImpl extends BaseServiceImpl<TaskProcessMapper, T
|
|
|
|
|
|
@Override
|
|
|
public boolean taskReject(TaskProcessInfoDTO dto) {
|
|
|
- //修改业务数据状态为已驳回
|
|
|
- List<ExpenseTaskRecord> records = jdbcTemplate.query("select * from task_id = " + dto.getId(), new BeanPropertyRowMapper<>(ExpenseTaskRecord.class));
|
|
|
- for (ExpenseTaskRecord record : records) {
|
|
|
- if (ObjectUtil.isNotEmpty(record.getExpenseInfoType())) {
|
|
|
- Integer type = record.getExpenseInfoType();
|
|
|
- switch (type) {
|
|
|
- case 1: //计划任务
|
|
|
- //TODO 修改计划任务状态
|
|
|
- break;
|
|
|
-
|
|
|
- case 2: //财务
|
|
|
- jdbcTemplate.execute("update c_expense_financial_reimbursement_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 3: //支付
|
|
|
- jdbcTemplate.execute("update c_expense_pay_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 4: //借款
|
|
|
- jdbcTemplate.execute("update c_expense_loan_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 5: //采购
|
|
|
- jdbcTemplate.execute("update c_expense_purchase_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 6: //用车
|
|
|
- jdbcTemplate.execute("update c_expense_use_car_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 7: //发票
|
|
|
- jdbcTemplate.execute("update c_expense_invoice_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 8: //外包
|
|
|
- jdbcTemplate.execute("update c_expense_outsourcing_pay_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
- case 9: //出差
|
|
|
- jdbcTemplate.execute("update c_attendance_trip_info set status = 3 where id = " + record.getExpenseInfoId());
|
|
|
- break;
|
|
|
+ if (ObjectUtil.isEmpty(dto.getId())) {
|
|
|
+ throw new ServiceException("未获取到当前任务信息,请联系管理员");
|
|
|
+ }
|
|
|
+ List<ExpenseTaskRecord> records = jdbcTemplate.query("select * from c_expense_task_record where task_id = " + dto.getId(), new BeanPropertyRowMapper<>(ExpenseTaskRecord.class));
|
|
|
+ if (records.size() == 0) {
|
|
|
+ throw new ServiceException("未获取当前任务的关联业务信息,请联系管理员");
|
|
|
+ }
|
|
|
+ //修改审批任务状态 =3 已驳回
|
|
|
+ if (this.update(Wrappers.<TaskProcessInfo>lambdaUpdate()
|
|
|
+ .set(TaskProcessInfo::getStatus, 3)
|
|
|
+ .set(TaskProcessInfo::getRejectDesc, StringUtils.isNotEmpty(dto.getRejectDesc()) ? dto.getRejectDesc() : null)
|
|
|
+ .eq(TaskProcessInfo::getId, dto.getId()))) {
|
|
|
+ //修改业务数据状态 =3 已驳回
|
|
|
+ for (ExpenseTaskRecord record : records) {
|
|
|
+ if (ObjectUtil.isNotEmpty(record.getExpenseInfoType())) {
|
|
|
+ Integer businessDataType = record.getExpenseInfoType();
|
|
|
+ if (businessDataType.equals(dto.getTaskType())) {
|
|
|
+ this.updateTaskStatus(businessDataType, 3, record.getExpenseInfoId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("当前任务审批失败,请联系管理员");
|
|
|
}
|
|
|
- //修改审批任务状态为已驳回
|
|
|
- this.update(Wrappers.<TaskProcessInfo>lambdaUpdate().set(TaskProcessInfo::getStatus, 3).set(TaskProcessInfo::getRejectDesc, dto.getRejectDesc()).eq(TaskProcessInfo::getId, dto.getId()));
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean taskSubmit(String id) {
|
|
|
- //TODO
|
|
|
- return true;
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUser())) {
|
|
|
+ throw new ServiceException("未获取到当前用户信息,请联系管理员");
|
|
|
+ }
|
|
|
+ TaskProcessInfo taskProcessInfo = baseMapper.selectById(id);
|
|
|
+ if (ObjectUtil.isEmpty(taskProcessInfo)) {
|
|
|
+ throw new ServiceException("未获取当前任务信息,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExpenseTaskRecord> records = jdbcTemplate.query("select * from c_expense_task_record where task_id = " + id, new BeanPropertyRowMapper<>(ExpenseTaskRecord.class));
|
|
|
+ if (records.size() == 0) {
|
|
|
+ throw new ServiceException("未获取当前任务的关联业务信息,请联系管理员");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(taskProcessInfo.getAuditUserIds()) && taskProcessInfo.getAuditUserIds().contains(SecureUtil.getUserId() + "")) {
|
|
|
+ //加锁
|
|
|
+ String redisLock = bladeRedis.get("user:id=" + SecureUtil.getUserId());
|
|
|
+ if (StringUtils.isNotEmpty(redisLock) && redisLock.equals("task:id=" + id)) {
|
|
|
+ throw new ServiceException("当前用户已提交该任务的审批,请勿重复操作!");
|
|
|
+ } else {
|
|
|
+ bladeRedis.setEx("user:id=" + SecureUtil.getUserId(), "task:id=" + id, Duration.ofMinutes(10));//10分钟过期
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> auditUserIdList = Func.toStrList(taskProcessInfo.getAuditUserIds());
|
|
|
+ Set<String> auditUserIdCompleteList = new HashSet<>(Func.toStrList(taskProcessInfo.getAuditUserIdsComplete()));
|
|
|
+
|
|
|
+ //剔除待审批中当前用户信息
|
|
|
+ if (auditUserIdList.removeIf(next -> next != null && next.equals(SecureUtil.getUserId() + ""))) {
|
|
|
+ //剔除后视为已完成审批
|
|
|
+ auditUserIdCompleteList.add(SecureUtil.getUserId() + "");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改待审批人ids、完成审批人ids
|
|
|
+ this.update(Wrappers.<TaskProcessInfo>lambdaUpdate()
|
|
|
+ .set(TaskProcessInfo::getAuditUserIds, ObjectUtil.isNotEmpty(auditUserIdList) ? StringUtils.join(auditUserIdList, ",") : null)
|
|
|
+ .set(TaskProcessInfo::getAuditUserIdsComplete, ObjectUtil.isNotEmpty(auditUserIdCompleteList) ? StringUtils.join(auditUserIdCompleteList, ",") : null)
|
|
|
+ .eq(TaskProcessInfo::getId, id));
|
|
|
+
|
|
|
+ //如果待审批人已全部审批完毕,那么修改任务状态
|
|
|
+ if (auditUserIdList.size() == 0) {
|
|
|
+
|
|
|
+ //审批任务状态 =2 已审批
|
|
|
+ if (this.update(Wrappers.<TaskProcessInfo>lambdaUpdate().set(TaskProcessInfo::getStatus, 2).eq(TaskProcessInfo::getId, id))) {
|
|
|
+ //业务状态 =2 已审批
|
|
|
+ for (ExpenseTaskRecord record : records) {
|
|
|
+ if (ObjectUtil.isNotEmpty(record.getExpenseInfoType())) {
|
|
|
+ Integer businessDataType = record.getExpenseInfoType();
|
|
|
+ if (businessDataType.equals(taskProcessInfo.getTaskType())) {
|
|
|
+ //修改业务审批状态
|
|
|
+ this.updateTaskStatus(businessDataType, 2, record.getExpenseInfoId());
|
|
|
+
|
|
|
+ //处理审批闭环后的业务数据
|
|
|
+ this.processTheServiceDataAfterTheApprovalClosedLoop(businessDataType, record.getExpenseInfoId());
|
|
|
+
|
|
|
+ //解锁
|
|
|
+ bladeRedis.del("user:id=" + SecureUtil.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未获取到当前任务的审批人员信息,请联系管理员");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改业务审批状态
|
|
|
+ *
|
|
|
+ * @param businessDataType 业务类型
|
|
|
+ * @param taskStatus 任务状态
|
|
|
+ * @param dataId 业务id
|
|
|
+ */
|
|
|
+ private void updateTaskStatus(Integer businessDataType, Integer taskStatus, Long dataId) {
|
|
|
+ switch (businessDataType) {
|
|
|
+ case 1: //计划任务
|
|
|
+ //TODO 修改计划任务状态
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2: //财务
|
|
|
+ jdbcTemplate.execute("update c_expense_financial_reimbursement_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 3: //支付
|
|
|
+ jdbcTemplate.execute("update c_expense_pay_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 4: //借款
|
|
|
+ jdbcTemplate.execute("update c_expense_loan_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 5: //采购
|
|
|
+ jdbcTemplate.execute("update c_expense_purchase_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 6: //用车
|
|
|
+ jdbcTemplate.execute("update c_expense_use_car_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 7: //发票
|
|
|
+ jdbcTemplate.execute("update c_expense_invoice_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 8: //外包
|
|
|
+ jdbcTemplate.execute("update c_expense_outsourcing_pay_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ case 9: //出差
|
|
|
+ jdbcTemplate.execute("update c_attendance_trip_info set status = " + taskStatus + " where id = " + dataId);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理审批闭环后的业务数据
|
|
|
+ *
|
|
|
+ * @param businessDataType 业务类型
|
|
|
+ * @param dataId 业务id
|
|
|
+ */
|
|
|
+ private void processTheServiceDataAfterTheApprovalClosedLoop(Integer businessDataType, Long dataId) {
|
|
|
+ switch (businessDataType) {
|
|
|
+ case 1: //计划任务
|
|
|
+ //TODO 处理计划任务List
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 2: //财务 TODO 财务与预算计划关联
|
|
|
+ EMFinancialReimbursementInfo emFinancialReimbursementInfo = jdbcTemplate.query("select * from c_expense_financial_reimbursement_info where id = " + dataId, new BeanPropertyRowMapper<>(EMFinancialReimbursementInfo.class)).stream().findAny().orElse(null);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 3: //支付 TODO 请款金额与项目关联
|
|
|
+ EMPayInfo emPayInfo = jdbcTemplate.query("select * from c_expense_pay_info where id = " + dataId, new BeanPropertyRowMapper<>(EMPayInfo.class)).stream().findAny().orElse(null);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 4: //借款 TODO 借款与财务报销的抵消关联
|
|
|
+ EMLoanInfo emLoanInfo = jdbcTemplate.query("select * from c_expense_loan_info where id = " + dataId, new BeanPropertyRowMapper<>(EMLoanInfo.class)).stream().findAny().orElse(null);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 5: //采购 TODO 采购与经营预算关联
|
|
|
+ EMPurchaseInfo emPurchaseInfo = jdbcTemplate.query("select * from c_expense_purchase_info where id = " + dataId, new BeanPropertyRowMapper<>(EMPurchaseInfo.class)).stream().findAny().orElse(null);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 8: //外包 TODO 外包支付与项目关联
|
|
|
+ EMOutsourcingPayInfo emOutsourcingPayInfo = jdbcTemplate.query("select * from c_expense_outsourcing_pay_info where id = " + dataId, new BeanPropertyRowMapper<>(EMOutsourcingPayInfo.class)).stream().findAny().orElse(null);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|