feat: 报销单

new
chenqp 1 year ago
parent c2fc20dce5
commit d70b798d1f

@ -130,8 +130,6 @@ public class ExpenseClaimController {
PageResult<ExpenseClaimDO> pageResult = expenseClaimService.getExpenseClaimPage(pageVO);
List<ExpenseClaimDO> list = pageResult.getList();
if (CollUtil.isNotEmpty(list)) {
expenseClaimService.setNickNameField(list);
taskService.handleApprovalAuthority(list);
}

@ -73,4 +73,6 @@ public interface ExpenseClaimService extends MPJBaseService<ExpenseClaimDO> {
void setNickNameField(List<ExpenseClaimDO> toList);
void setDeptNameField(List<ExpenseClaimDO> toList);
void processInstanceCallBack(long id, Integer result);
}

@ -4,16 +4,22 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.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.expenseclaimtrip.ExpenseClaimTripService;
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.dal.dataobject.expenseclaim.ExpenseClaimDO;
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.enums.BillTypeEnum;
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.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@ -26,9 +32,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
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
@Transactional(rollbackFor = Exception.class)
public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapper, ExpenseClaimDO> implements ExpenseClaimService {
public static final String PROCESS_KEY = "expense_claim";
@Resource
private ExpenseClaimMapper expenseClaimMapper;
@Resource
@ -57,6 +61,8 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
private ExpenseClaimDetailService expenseClaimDetailService;
@Resource
private DeptApi deptApi;
@Resource
private BpmProcessInstanceApi processInstanceApi;
@Override
public CommonResult createExpenseClaim(ExpenseClaimCreateReqVO createReqVO) {
@ -67,7 +73,44 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
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();
}
@ -181,4 +224,29 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
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);
}
}
}

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.bpm.service.oa.listener;
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventListener;
import cn.iocoder.yudao.module.bpm.service.expenseapply.ExpenseApplyServiceImpl;
import cn.iocoder.yudao.module.bpm.service.expenseclaim.ExpenseClaimServiceImpl;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* OA
*
* @author
*/
@Component
public class ExpenseClaimResultListener extends BpmProcessInstanceResultEventListener {
@Resource
private ExpenseClaimServiceImpl expenseClaimService;
@Override
protected String getProcessDefinitionKey() {
return ExpenseClaimServiceImpl.PROCESS_KEY;
}
@Override
protected void onEvent(BpmProcessInstanceResultEvent event) {
expenseClaimService.processInstanceCallBack(Long.parseLong(event.getBusinessKey()), event.getResult());
}
}

@ -9,6 +9,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@ -16,9 +17,8 @@ import java.util.List;
@Schema(description = "管理后台 - 报销单创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ExpenseClaimCreateReqVO extends ExpenseClaimBaseVO {
public class ExpenseClaimCreateReqVO {
@Schema(description = "id")
private Long id;
@Schema(description = "报销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ -29,9 +29,10 @@ public class ExpenseClaimCreateReqVO extends ExpenseClaimBaseVO {
private String projectName;
@Schema(description = "报销事由")
@NotNull(message = "报销事由")
@NotNull(message = "报销事由不能为空")
private String reason;
@NotNull(message = "申请事由")
@NotNull(message = "费用归属部门不能为空")
private Long costDeptId;
@NotBlank(message = "状态不能为空")
@ -43,9 +44,11 @@ public class ExpenseClaimCreateReqVO extends ExpenseClaimBaseVO {
private List<ImageVo> files;
@Schema(description = "行程明细,仅为差旅报销单的时候需要传", example = "")
@Valid
private List<ExpenseClaimTripCreateReqVO> expenseClaimTrips;
@Schema(description = "费用明细,仅为日常报销单的时候需要传", example = "")
@Valid
private List<ExpenseClaimDetailCreateReqVO> expenseClaimDetails;
@AssertTrue(message = "差旅报销单的行程明细及其报销明细不能为空")

@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@ -57,5 +58,7 @@ public class ExpenseClaimTripCreateReqVO {
private BigDecimal amount;
@Schema(description = "费用明细", example = "")
@Valid
@NotEmpty(message = "费用明细expenseClaimDetails不能为空")
private List<ExpenseClaimDetailCreateReqVO> expenseClaimDetails;
}

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.bs.convert.expenseclaim;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.ExpenseClaimCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.ExpenseClaimExcelVO;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.ExpenseClaimRespVO;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.ExpenseClaimUpdateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.expenseapplytrip.vo.ExpenseApplyTripCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.*;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimtrip.ExpenseClaimTripDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -32,5 +32,6 @@ public interface ExpenseClaimConvert {
PageResult<ExpenseClaimRespVO> convertPage(PageResult<ExpenseClaimDO> page);
List<ExpenseClaimExcelVO> convertList02(List<ExpenseClaimDO> list);
ExpenseClaimTripDO convert(ExpenseClaimTripCreateReqVO bean);
List<ExpenseClaimTripDO> convert(List<ExpenseClaimTripCreateReqVO> bean);
}

Loading…
Cancel
Save