|
|
@ -4,16 +4,22 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
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.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
|
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.dto.BpmProcessInstanceCreateReqDTO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
|
|
|
import cn.iocoder.yudao.module.bpm.service.expenseclaimdetail.ExpenseClaimDetailService;
|
|
|
|
import cn.iocoder.yudao.module.bpm.service.expenseclaimdetail.ExpenseClaimDetailService;
|
|
|
|
import cn.iocoder.yudao.module.bpm.service.expenseclaimtrip.ExpenseClaimTripService;
|
|
|
|
import cn.iocoder.yudao.module.bpm.service.expenseclaimtrip.ExpenseClaimTripService;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.*;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.*;
|
|
|
|
import cn.iocoder.yudao.module.bs.convert.expenseclaim.ExpenseClaimConvert;
|
|
|
|
import cn.iocoder.yudao.module.bs.convert.expenseclaim.ExpenseClaimConvert;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimdetail.ExpenseClaimDetailDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimdetail.ExpenseClaimDetailDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimtrip.ExpenseClaimTripDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.mysql.expenseclaim.ExpenseClaimMapper;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.mysql.expenseclaim.ExpenseClaimMapper;
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.BillTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.BillTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.ExpenseClaimSettleStatusEnum;
|
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
@ -26,9 +32,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
@ -44,7 +48,7 @@ import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_CLAIM_
|
|
|
|
@Validated
|
|
|
|
@Validated
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapper, ExpenseClaimDO> implements ExpenseClaimService {
|
|
|
|
public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapper, ExpenseClaimDO> implements ExpenseClaimService {
|
|
|
|
|
|
|
|
public static final String PROCESS_KEY = "expense_claim";
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ExpenseClaimMapper expenseClaimMapper;
|
|
|
|
private ExpenseClaimMapper expenseClaimMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
@ -57,6 +61,8 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
|
|
|
|
private ExpenseClaimDetailService expenseClaimDetailService;
|
|
|
|
private ExpenseClaimDetailService expenseClaimDetailService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private DeptApi deptApi;
|
|
|
|
private DeptApi deptApi;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private BpmProcessInstanceApi processInstanceApi;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public CommonResult createExpenseClaim(ExpenseClaimCreateReqVO createReqVO) {
|
|
|
|
public CommonResult createExpenseClaim(ExpenseClaimCreateReqVO createReqVO) {
|
|
|
@ -67,7 +73,44 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expenseClaimMapper.insert(expenseClaim);
|
|
|
|
saveOrUpdate(expenseClaim);
|
|
|
|
|
|
|
|
if (expenseClaim.getBillType().equals(BillTypeEnum.CLBX.getValue())) {
|
|
|
|
|
|
|
|
List<ExpenseClaimTripDO> trips = ExpenseClaimConvert.INSTANCE.convert(createReqVO.getExpenseClaimTrips());
|
|
|
|
|
|
|
|
for (ExpenseClaimTripDO trip : trips) {
|
|
|
|
|
|
|
|
trip.setClaimId(expenseClaim.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
expenseClaimTripService.remove(new LambdaQueryWrapperX<ExpenseClaimTripDO>().eq(ExpenseClaimTripDO::getClaimId, expenseClaim.getId()));
|
|
|
|
|
|
|
|
expenseClaimTripService.saveBatch(trips);
|
|
|
|
|
|
|
|
expenseClaimDetailService.remove(new LambdaQueryWrapperX<ExpenseClaimDetailDO>().eq(ExpenseClaimDetailDO::getClaimId, expenseClaim.getId()));
|
|
|
|
|
|
|
|
List<ExpenseClaimDetailDO> allDetais = new ArrayList<>();
|
|
|
|
|
|
|
|
for (ExpenseClaimTripDO trip : trips) {
|
|
|
|
|
|
|
|
List<ExpenseClaimDetailDO> details = trip.getExpenseClaimDetails();
|
|
|
|
|
|
|
|
for (ExpenseClaimDetailDO detail : details) {
|
|
|
|
|
|
|
|
detail.setClaimId(expenseClaim.getId());
|
|
|
|
|
|
|
|
detail.setTripId(trip.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
allDetais.addAll(details);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
expenseClaimDetailService.saveBatch(allDetais);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
expenseClaimDetailService.remove(new LambdaQueryWrapperX<ExpenseClaimDetailDO>().eq(ExpenseClaimDetailDO::getClaimId, expenseClaim.getId()));
|
|
|
|
|
|
|
|
List<ExpenseClaimDetailDO> details = expenseClaim.getExpenseClaimDetails();
|
|
|
|
|
|
|
|
for (ExpenseClaimDetailDO detail : details) {
|
|
|
|
|
|
|
|
detail.setClaimId(expenseClaim.getId());
|
|
|
|
|
|
|
|
detail.setTripId(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
expenseClaimDetailService.saveBatch(details);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expenseClaim.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
|
|
|
|
|
|
|
|
Map<String, Object> variables = new HashMap<>();
|
|
|
|
|
|
|
|
variables.put("billType", expenseClaim.getBillType());
|
|
|
|
|
|
|
|
variables.put("amount", expenseClaim.getAmount());
|
|
|
|
|
|
|
|
variables.put("deptId", expenseClaim.getDeptId());
|
|
|
|
|
|
|
|
String processInstanceId = processInstanceApi.createProcessInstance(expenseClaim.getUserId(),
|
|
|
|
|
|
|
|
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
|
|
|
|
|
.setVariables(variables).setBusinessKey(String.valueOf(expenseClaim.getId())));
|
|
|
|
|
|
|
|
updateById(new ExpenseClaimDO().setId(expenseClaim.getId()).setProcessInstanceId(processInstanceId));
|
|
|
|
|
|
|
|
}
|
|
|
|
// 返回
|
|
|
|
// 返回
|
|
|
|
return CommonResult.success();
|
|
|
|
return CommonResult.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -181,4 +224,29 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
|
|
|
|
expenseApply.setCostDeptName(deptMap.get(expenseApply.getDeptId()));
|
|
|
|
expenseApply.setCostDeptName(deptMap.get(expenseApply.getDeptId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 流程回调
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @param result
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void processInstanceCallBack(long id, Integer result) {
|
|
|
|
|
|
|
|
ExpenseClaimDO claim = getById(id);
|
|
|
|
|
|
|
|
if (BpmProcessInstanceResultEnum.APPROVE.getResult().equals(result)) {
|
|
|
|
|
|
|
|
//审核通过
|
|
|
|
|
|
|
|
claim.setStatus(ExpenseApplyStatusEnum.APPROVE.getValue());
|
|
|
|
|
|
|
|
claim.setSettleStatus(ExpenseClaimSettleStatusEnum.WAITSETTLE.getValue());
|
|
|
|
|
|
|
|
updateById(claim);
|
|
|
|
|
|
|
|
} else if (BpmProcessInstanceResultEnum.REJECT.getResult().equals(result)) {
|
|
|
|
|
|
|
|
//驳回
|
|
|
|
|
|
|
|
claim.setStatus(ExpenseApplyStatusEnum.REJECT.getValue());
|
|
|
|
|
|
|
|
updateById(claim);
|
|
|
|
|
|
|
|
}else if (BpmProcessInstanceResultEnum.CANCEL.getResult().equals(result)) {
|
|
|
|
|
|
|
|
//驳回
|
|
|
|
|
|
|
|
claim.setStatus(ExpenseApplyStatusEnum.CANCEL.getValue());
|
|
|
|
|
|
|
|
updateById(claim);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|