|
|
|
@ -1,21 +1,39 @@
|
|
|
|
|
package cn.iocoder.yudao.module.bs.service.expenseapply;
|
|
|
|
|
|
|
|
|
|
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.common.util.validation.ValidationUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyCreateReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyExportReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyUpdateReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.expenseapplytrip.vo.ExpenseApplyTripCreateReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.convert.expenseapply.ExpenseApplyConvert;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.mysql.expenseapply.ExpenseApplyMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.BillTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.bs.service.expenseapplytrip.ExpenseApplyTripService;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.Validator;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_NOT_EXISTS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -25,27 +43,84 @@ import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Validated
|
|
|
|
|
public class ExpenseApplyServiceImpl implements ExpenseApplyService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, ExpenseApplyDO> implements ExpenseApplyService {
|
|
|
|
|
|
|
|
|
|
public static final String PROCESS_KEY = "expense_apply";
|
|
|
|
|
@Resource
|
|
|
|
|
private Validator validator;
|
|
|
|
|
@Resource
|
|
|
|
|
private ExpenseApplyMapper expenseApplyMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private ExpenseApplyTripService expenseApplyTripService;
|
|
|
|
|
// @Resource
|
|
|
|
|
// private BpmProcessInstanceApi processInstanceApi;
|
|
|
|
|
@Override
|
|
|
|
|
public Long createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
|
|
|
|
|
// 插入
|
|
|
|
|
public CommonResult createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
|
|
|
|
|
ExpenseApplyDO expenseApply = ExpenseApplyConvert.INSTANCE.convert(createReqVO);
|
|
|
|
|
expenseApplyMapper.insert(expenseApply);
|
|
|
|
|
CommonResult<Object> result = dataValidAndSetFileName(createReqVO, expenseApply);
|
|
|
|
|
if (result.isError()) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveOrUpdate(expenseApply);
|
|
|
|
|
if (expenseApply.getBillType().equals(BillTypeEnum.CLSQ.getValue())) {
|
|
|
|
|
//插入或者更新差旅明细
|
|
|
|
|
List<ExpenseApplyTripDO> trips = ExpenseApplyConvert.INSTANCE.convert(createReqVO.getExpenseApplyTrips());
|
|
|
|
|
for (ExpenseApplyTripDO trip : trips) {
|
|
|
|
|
trip.setApplyId(expenseApply.getId());
|
|
|
|
|
}
|
|
|
|
|
expenseApplyTripService.saveOrUpdateBatch(trips);
|
|
|
|
|
}
|
|
|
|
|
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.UNAUDIT.getValue())) {
|
|
|
|
|
//cqptodo 提交单据,创建工作流
|
|
|
|
|
// String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
|
|
|
|
// new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
|
|
// .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(leave.getId())));
|
|
|
|
|
}
|
|
|
|
|
// 返回
|
|
|
|
|
return expenseApply.getId();
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateExpenseApply(ExpenseApplyUpdateReqVO updateReqVO) {
|
|
|
|
|
// 校验存在
|
|
|
|
|
validateExpenseApplyExists(updateReqVO.getId());
|
|
|
|
|
// 更新
|
|
|
|
|
ExpenseApplyDO updateObj = ExpenseApplyConvert.INSTANCE.convert(updateReqVO);
|
|
|
|
|
expenseApplyMapper.updateById(updateObj);
|
|
|
|
|
/**
|
|
|
|
|
* 新增和更新数据校验
|
|
|
|
|
* @param createReqVO
|
|
|
|
|
* @param expenseApply
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private CommonResult<Object> dataValidAndSetFileName(ExpenseApplyCreateReqVO createReqVO, ExpenseApplyDO expenseApply) {
|
|
|
|
|
boolean isAdd = createReqVO.getId() == null;
|
|
|
|
|
|
|
|
|
|
if (expenseApply.getBillType().equals(BillTypeEnum.CLSQ.getValue())) {
|
|
|
|
|
List<ExpenseApplyTripCreateReqVO> expenseApplyTrips = createReqVO.getExpenseApplyTrips();
|
|
|
|
|
if (CollUtil.isEmpty(expenseApplyTrips)) {
|
|
|
|
|
return CommonResult.error("差旅明细不能为空");
|
|
|
|
|
}
|
|
|
|
|
// 参数校验
|
|
|
|
|
ValidationUtils.validate(validator, expenseApplyTrips);
|
|
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
|
|
for (ExpenseApplyTripCreateReqVO trip : expenseApplyTrips) {
|
|
|
|
|
if (trip.getAmount()!=null) {
|
|
|
|
|
amount = amount.add(trip.getAmount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
expenseApply.setAmount(amount);
|
|
|
|
|
}
|
|
|
|
|
if (isAdd) {
|
|
|
|
|
//新增
|
|
|
|
|
//cqptodo 单号的规则需要重写
|
|
|
|
|
expenseApply.setApplyNo(RandomUtil.randomString(6));
|
|
|
|
|
}else {
|
|
|
|
|
validateExpenseApplyExists(expenseApply.getId());
|
|
|
|
|
}
|
|
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
|
|
expenseApply.setUserId(loginUser.getId());
|
|
|
|
|
AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
|
|
|
|
|
expenseApply.setDeptId(user.getDeptId());
|
|
|
|
|
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|