|
|
@ -3,9 +3,12 @@ package cn.iocoder.yudao.module.bpm.service.expenseapply;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
|
|
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
|
|
@ -32,6 +35,7 @@ import javax.annotation.Resource;
|
|
|
|
import javax.validation.Validator;
|
|
|
|
import javax.validation.Validator;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
@ -58,7 +62,7 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ExpenseApplyTripService expenseApplyTripService;
|
|
|
|
private ExpenseApplyTripService expenseApplyTripService;
|
|
|
|
// @Resource
|
|
|
|
@Resource
|
|
|
|
private BpmProcessInstanceApi processInstanceApi;
|
|
|
|
private BpmProcessInstanceApi processInstanceApi;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public CommonResult createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
|
|
|
|
public CommonResult createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
|
|
|
@ -75,15 +79,19 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
|
|
|
|
for (ExpenseApplyTripDO trip : trips) {
|
|
|
|
for (ExpenseApplyTripDO trip : trips) {
|
|
|
|
trip.setApplyId(expenseApply.getId());
|
|
|
|
trip.setApplyId(expenseApply.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expenseApplyTripService.saveOrUpdateBatch(trips);
|
|
|
|
//采用先删后增的方式来
|
|
|
|
|
|
|
|
//删除行程明细
|
|
|
|
|
|
|
|
expenseApplyTripService.remove(new LambdaQueryWrapperX<ExpenseApplyTripDO>().eq(ExpenseApplyTripDO::getApplyId, expenseApply.getId()));
|
|
|
|
|
|
|
|
expenseApplyTripService.saveBatch(trips);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
|
|
|
|
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
|
|
|
|
Map<String, Object> variables = BeanUtil.beanToMap(expenseApply);
|
|
|
|
Map<String, Object> variables = new HashMap<>();
|
|
|
|
//cqptodo 提交单据,创建工作流
|
|
|
|
variables.put("billType", expenseApply.getBillType());
|
|
|
|
|
|
|
|
variables.put("amount", expenseApply.getAmount());
|
|
|
|
|
|
|
|
variables.put("deptId", expenseApply.getDeptId());
|
|
|
|
String processInstanceId = processInstanceApi.createProcessInstance(expenseApply.getUserId(),
|
|
|
|
String processInstanceId = processInstanceApi.createProcessInstance(expenseApply.getUserId(),
|
|
|
|
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
|
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
|
.setVariables(variables).setBusinessKey(String.valueOf(expenseApply.getId())));
|
|
|
|
.setVariables(variables).setBusinessKey(String.valueOf(expenseApply.getId())));
|
|
|
|
//cqptodo 待测试是否会更新其它字段 将工作流的编号,更新到单据中
|
|
|
|
|
|
|
|
updateById(new ExpenseApplyDO().setId(expenseApply.getId()).setProcessInstanceId(processInstanceId));
|
|
|
|
updateById(new ExpenseApplyDO().setId(expenseApply.getId()).setProcessInstanceId(processInstanceId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 返回
|
|
|
|
// 返回
|
|
|
@ -120,7 +128,7 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
|
|
|
|
expenseApply.setApplyNo(RandomUtil.randomString(6));
|
|
|
|
expenseApply.setApplyNo(RandomUtil.randomString(6));
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
ExpenseApplyDO dbApply = validateExpenseApplyExists(expenseApply.getId());
|
|
|
|
ExpenseApplyDO dbApply = validateExpenseApplyExists(expenseApply.getId());
|
|
|
|
if (!dbApply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT)) {
|
|
|
|
if (!dbApply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue())) {
|
|
|
|
//只有未提交才能更新
|
|
|
|
//只有未提交才能更新
|
|
|
|
return CommonResult.error("只有未提交单据才能更新");
|
|
|
|
return CommonResult.error("只有未提交单据才能更新");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -136,9 +144,15 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteExpenseApply(Long id) {
|
|
|
|
public void deleteExpenseApply(Long id) {
|
|
|
|
// 校验存在
|
|
|
|
// 校验存在
|
|
|
|
validateExpenseApplyExists(id);
|
|
|
|
ExpenseApplyDO apply = validateExpenseApplyExists(id);
|
|
|
|
|
|
|
|
if (!apply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue())) {
|
|
|
|
|
|
|
|
//只有未提交才能更新
|
|
|
|
|
|
|
|
throw exception(new ErrorCode(500, "单据状态不可操作,请刷新后重试"));
|
|
|
|
|
|
|
|
}
|
|
|
|
// 删除
|
|
|
|
// 删除
|
|
|
|
expenseApplyMapper.deleteById(id);
|
|
|
|
expenseApplyMapper.deleteById(id);
|
|
|
|
|
|
|
|
//删除行程明细
|
|
|
|
|
|
|
|
expenseApplyTripService.remove(new LambdaQueryWrapperX<ExpenseApplyTripDO>().eq(ExpenseApplyTripDO::getApplyId, apply.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ExpenseApplyDO validateExpenseApplyExists(Long id) {
|
|
|
|
private ExpenseApplyDO validateExpenseApplyExists(Long id) {
|
|
|
|