Merge branch 'master' of https://gitee.com/FNumb/reimbursement-items
commit
18f04bfc3a
@ -0,0 +1,17 @@
|
||||
package cn.iocoder.yudao.framework.common.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 路由显示信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
public class ImageVo implements Serializable {
|
||||
private static final long serialVersionUID=1L;
|
||||
String name;
|
||||
String url;
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.expenseapply;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.bpm.service.expenseapplytrip.ExpenseApplyTripService;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.*;
|
||||
import cn.iocoder.yudao.module.bs.convert.expenseapply.ExpenseApplyConvert;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO;
|
||||
import cn.iocoder.yudao.module.bpm.service.expenseapply.ExpenseApplyService;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import cn.iocoder.yudao.module.bs.enums.BillTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - 申请单")
|
||||
@RestController
|
||||
@RequestMapping("/bs/expense-apply")
|
||||
@Validated
|
||||
public class ExpenseApplyController {
|
||||
|
||||
@Resource
|
||||
private ExpenseApplyService expenseApplyService;
|
||||
@Resource
|
||||
private ExpenseApplyTripService expenseApplyTripService;
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建申请单")
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:create')")
|
||||
public CommonResult createExpenseApply(@Valid @RequestBody ExpenseApplyCreateReqVO createReqVO) {
|
||||
return expenseApplyService.createExpenseApply(createReqVO);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除申请单")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:delete')")
|
||||
public CommonResult<Boolean> deleteExpenseApply(@RequestParam("id") Long id) {
|
||||
expenseApplyService.deleteExpenseApply(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得申请单")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:query')")
|
||||
public CommonResult<ExpenseApplyDO> getExpenseApply(@RequestParam("id") Long id) {
|
||||
ExpenseApplyDO expenseApply = expenseApplyService.getExpenseApply(id);
|
||||
if (expenseApply.getBillType().equals(BillTypeEnum.CLSQ.getValue())) {
|
||||
LambdaQueryWrapperX<ExpenseApplyTripDO> queryWrapper = new LambdaQueryWrapperX<>();
|
||||
queryWrapper.eq(ExpenseApplyTripDO::getApplyId, expenseApply.getId());
|
||||
List<ExpenseApplyTripDO> list = expenseApplyTripService.list(queryWrapper);
|
||||
expenseApply.setExpenseApplyTrips(list);
|
||||
//cqptodo 需要设置用户名,部门返回前端
|
||||
// expenseApplyService.setRepField(expenseApply);
|
||||
}
|
||||
return success(expenseApply);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得申请单列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:query')")
|
||||
public CommonResult<List<ExpenseApplyRespVO>> getExpenseApplyList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<ExpenseApplyDO> list = expenseApplyService.getExpenseApplyList(ids);
|
||||
return success(ExpenseApplyConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得申请单分页")
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:query')")
|
||||
public CommonResult<PageResult<ExpenseApplyRespVO>> getExpenseApplyPage(@Valid ExpenseApplyPageReqVO pageVO) {
|
||||
PageResult<ExpenseApplyDO> pageResult = expenseApplyService.getExpenseApplyPage(pageVO);
|
||||
return success(ExpenseApplyConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出申请单 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('bs:expense-apply:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportExpenseApplyExcel(@Valid ExpenseApplyExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<ExpenseApplyDO> list = expenseApplyService.getExpenseApplyList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<ExpenseApplyExcelVO> datas = ExpenseApplyConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "申请单.xls", "数据", ExpenseApplyExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.expenseapply;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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.dal.dataobject.expenseapply.ExpenseApplyDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 申请单 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ExpenseApplyService extends IService<ExpenseApplyDO> {
|
||||
|
||||
/**
|
||||
* 创建申请单
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
CommonResult createExpenseApply(@Valid ExpenseApplyCreateReqVO createReqVO);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除申请单
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteExpenseApply(Long id);
|
||||
|
||||
/**
|
||||
* 获得申请单
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 申请单
|
||||
*/
|
||||
ExpenseApplyDO getExpenseApply(Long id);
|
||||
|
||||
/**
|
||||
* 获得申请单列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 申请单列表
|
||||
*/
|
||||
List<ExpenseApplyDO> getExpenseApplyList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得申请单分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 申请单分页
|
||||
*/
|
||||
PageResult<ExpenseApplyDO> getExpenseApplyPage(ExpenseApplyPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得申请单列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 申请单列表
|
||||
*/
|
||||
List<ExpenseApplyDO> getExpenseApplyList(ExpenseApplyExportReqVO exportReqVO);
|
||||
|
||||
void processInstanceCallBack(long id, Integer result);
|
||||
|
||||
}
|
@ -0,0 +1,208 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.expenseapply;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.PageResult;
|
||||
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.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.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.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.bpm.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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 申请单 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@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 CommonResult createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
|
||||
ExpenseApplyDO expenseApply = ExpenseApplyConvert.INSTANCE.convert(createReqVO);
|
||||
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.remove(new LambdaQueryWrapperX<ExpenseApplyTripDO>().eq(ExpenseApplyTripDO::getApplyId, expenseApply.getId()));
|
||||
expenseApplyTripService.saveBatch(trips);
|
||||
}
|
||||
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
variables.put("billType", expenseApply.getBillType());
|
||||
variables.put("amount", expenseApply.getAmount());
|
||||
variables.put("deptId", expenseApply.getDeptId());
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(expenseApply.getUserId(),
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(variables).setBusinessKey(String.valueOf(expenseApply.getId())));
|
||||
updateById(new ExpenseApplyDO().setId(expenseApply.getId()).setProcessInstanceId(processInstanceId));
|
||||
}
|
||||
// 返回
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增和更新数据校验
|
||||
* @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 {
|
||||
ExpenseApplyDO dbApply = validateExpenseApplyExists(expenseApply.getId());
|
||||
if (!dbApply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue())) {
|
||||
//只有未提交才能更新
|
||||
return CommonResult.error("只有未提交单据才能更新");
|
||||
}
|
||||
}
|
||||
LoginUser loginUser = getLoginUser();
|
||||
expenseApply.setUserId(loginUser.getId());
|
||||
AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
|
||||
expenseApply.setDeptId(user.getDeptId());
|
||||
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteExpenseApply(Long id) {
|
||||
// 校验存在
|
||||
ExpenseApplyDO apply = validateExpenseApplyExists(id);
|
||||
if (!apply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue())) {
|
||||
//只有未提交才能更新
|
||||
throw exception(new ErrorCode(500, "单据状态不可操作,请刷新后重试"));
|
||||
}
|
||||
// 删除
|
||||
expenseApplyMapper.deleteById(id);
|
||||
//删除行程明细
|
||||
expenseApplyTripService.remove(new LambdaQueryWrapperX<ExpenseApplyTripDO>().eq(ExpenseApplyTripDO::getApplyId, apply.getId()));
|
||||
}
|
||||
|
||||
private ExpenseApplyDO validateExpenseApplyExists(Long id) {
|
||||
ExpenseApplyDO expenseApplyDO = expenseApplyMapper.selectById(id);
|
||||
if (expenseApplyDO == null) {
|
||||
throw exception(EXPENSE_APPLY_NOT_EXISTS);
|
||||
}
|
||||
return expenseApplyDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpenseApplyDO getExpenseApply(Long id) {
|
||||
return expenseApplyMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExpenseApplyDO> getExpenseApplyList(Collection<Long> ids) {
|
||||
return expenseApplyMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ExpenseApplyDO> getExpenseApplyPage(ExpenseApplyPageReqVO pageReqVO) {
|
||||
return expenseApplyMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExpenseApplyDO> getExpenseApplyList(ExpenseApplyExportReqVO exportReqVO) {
|
||||
return expenseApplyMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程回调
|
||||
* @param id
|
||||
* @param result
|
||||
*/
|
||||
@Override
|
||||
public void processInstanceCallBack(long id, Integer result) {
|
||||
ExpenseApplyDO apply = getById(id);
|
||||
if (BpmProcessInstanceResultEnum.APPROVE.getResult().equals(result)) {
|
||||
//审核通过
|
||||
apply.setStatus(ExpenseApplyStatusEnum.APPROVE.getValue());
|
||||
updateById(apply);
|
||||
} else if (BpmProcessInstanceResultEnum.REJECT.getResult().equals(result)) {
|
||||
//驳回
|
||||
apply.setStatus(ExpenseApplyStatusEnum.REJECT.getValue());
|
||||
updateById(apply);
|
||||
}else if (BpmProcessInstanceResultEnum.CANCEL.getResult().equals(result)) {
|
||||
//驳回
|
||||
apply.setStatus(ExpenseApplyStatusEnum.CANCEL.getValue());
|
||||
updateById(apply);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.expenseapplytrip;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapplytrip.vo.*;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 申请单行程明细 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ExpenseApplyTripService extends IService<ExpenseApplyTripDO> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.expenseapplytrip;
|
||||
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import cn.iocoder.yudao.module.bs.dal.mysql.expenseapplytrip.ExpenseApplyTripMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* 申请单行程明细 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ExpenseApplyTripServiceImpl extends ServiceImpl<ExpenseApplyTripMapper, ExpenseApplyTripDO> implements ExpenseApplyTripService {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
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 org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* OA 请假单的结果的监听器实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Component
|
||||
public class ExpenseApplyResultListener extends BpmProcessInstanceResultEventListener {
|
||||
|
||||
@Resource
|
||||
private ExpenseApplyServiceImpl expenseApplyService;
|
||||
|
||||
@Override
|
||||
protected String getProcessDefinitionKey() {
|
||||
return ExpenseApplyServiceImpl.PROCESS_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvent(BpmProcessInstanceResultEvent event) {
|
||||
expenseApplyService.processInstanceCallBack(Long.parseLong(event.getBusinessKey()), event.getResult());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.bs.enums;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 单据类型枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum BillTypeEnum {
|
||||
|
||||
CLSQ("CLSQ", "差旅申请单"),
|
||||
RCSQ("RCSQ", "日常申请单");
|
||||
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final String value;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.bs.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 申请状态枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ExpenseApplyStatusEnum {
|
||||
|
||||
NOSUBMIT("0", "未提交"),
|
||||
PROCESS("1", "待审核"),
|
||||
APPROVE("2", "通过"),
|
||||
REJECT("3", "驳回"),
|
||||
CANCEL("4", "取消");
|
||||
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final String value;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.AssertTrue;
|
||||
|
||||
@Schema(description = "管理后台 - 申请单创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpenseApplyCreateReqVO extends ExpenseApplyBaseVO {
|
||||
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14225")
|
||||
private Long id;
|
||||
@AssertTrue(message = "状态只能是0或者1提交")
|
||||
public boolean isStatusValid() {
|
||||
//只能传未提交和待审核
|
||||
return getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue()) || getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue());
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 申请单 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class ExpenseApplyExcelVO {
|
||||
|
||||
@ExcelProperty("id")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty(value = "申请类型", converter = DictConvert.class)
|
||||
@DictFormat("bs_bill_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private String billType;
|
||||
|
||||
@ExcelProperty("申请单号")
|
||||
private String applyNo;
|
||||
|
||||
@ExcelProperty("申请者ID")
|
||||
private Long userId;
|
||||
|
||||
@ExcelProperty("用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@ExcelProperty("部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@ExcelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ExcelProperty("项目名称")
|
||||
private String projectName;
|
||||
|
||||
@ExcelProperty("申请事由")
|
||||
private String reason;
|
||||
|
||||
@ExcelProperty("申请金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat("bs_expense_apply_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private String status;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 申请单分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpenseApplyPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "申请类型", example = "2")
|
||||
private String billType;
|
||||
|
||||
@Schema(description = "申请单号")
|
||||
private String applyNo;
|
||||
|
||||
@Schema(description = "申请者ID", example = "9227")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户昵称", example = "张三")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "部门ID", example = "32343")
|
||||
private Long deptId;
|
||||
|
||||
@Schema(description = "部门名称", example = "王五")
|
||||
private String deptName;
|
||||
|
||||
@Schema(description = "项目名称", example = "芋艿")
|
||||
private String projectName;
|
||||
|
||||
@Schema(description = "申请事由", example = "不香")
|
||||
private String reason;
|
||||
|
||||
@Schema(description = "申请金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "状态", example = "2")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "附件")
|
||||
private List<ImageVo> files;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private String createBy;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
private String updateBy;
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 申请单 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpenseApplyRespVO extends ExpenseApplyBaseVO {
|
||||
|
||||
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14225")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 申请单更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpenseApplyUpdateReqVO extends ExpenseApplyBaseVO {
|
||||
|
||||
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14225")
|
||||
@NotNull(message = "id不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cn.iocoder.yudao.module.bs.controller.admin.expenseapplytrip.vo;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@Schema(description = "管理后台 - 申请单行程明细创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpenseApplyTripCreateReqVO extends ExpenseApplyTripBaseVO {
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.bs.convert.expenseapply;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyExcelVO;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo.ExpenseApplyRespVO;
|
||||
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.dal.dataobject.expenseapply.ExpenseApplyDO;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 申请单 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExpenseApplyConvert {
|
||||
|
||||
ExpenseApplyConvert INSTANCE = Mappers.getMapper(ExpenseApplyConvert.class);
|
||||
|
||||
ExpenseApplyDO convert(ExpenseApplyCreateReqVO bean);
|
||||
ExpenseApplyTripDO convert(ExpenseApplyTripCreateReqVO bean);
|
||||
List<ExpenseApplyTripDO> convert(List<ExpenseApplyTripCreateReqVO> bean);
|
||||
|
||||
ExpenseApplyDO convert(ExpenseApplyUpdateReqVO bean);
|
||||
|
||||
ExpenseApplyRespVO convert(ExpenseApplyDO bean);
|
||||
|
||||
List<ExpenseApplyRespVO> convertList(List<ExpenseApplyDO> list);
|
||||
|
||||
PageResult<ExpenseApplyRespVO> convertPage(PageResult<ExpenseApplyDO> page);
|
||||
|
||||
List<ExpenseApplyExcelVO> convertList02(List<ExpenseApplyDO> list);
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 申请单 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "bs_expense_apply", autoResultMap = true)
|
||||
@KeySequence("bs_expense_apply_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ExpenseApplyDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 申请类型
|
||||
*
|
||||
* 枚举 {@link TODO bs_bill_type 对应的类}
|
||||
*/
|
||||
private String billType;
|
||||
/**
|
||||
* 申请单号
|
||||
*/
|
||||
private String applyNo;
|
||||
/**
|
||||
* 申请者ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
private String projectName;
|
||||
/**
|
||||
* 申请事由
|
||||
*/
|
||||
private String reason;
|
||||
/**
|
||||
* 申请金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link TODO bs_expense_apply_status 对应的类}
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<ImageVo> files;
|
||||
/**
|
||||
* 对应的流程编号
|
||||
*
|
||||
* 关联 ProcessInstance 的 id 属性
|
||||
*/
|
||||
private String processInstanceId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ExpenseApplyTripDO> expenseApplyTrips;
|
||||
@TableField(exist = false)
|
||||
private Boolean deleted;
|
||||
@TableField(exist = false)
|
||||
private String nickname;
|
||||
@TableField(exist = false)
|
||||
private String detpName;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package cn.iocoder.yudao.module.bs.dal.mysql.expenseapply;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
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.dal.dataobject.expenseapply.ExpenseApplyDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 申请单 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExpenseApplyMapper extends BaseMapperX<ExpenseApplyDO> {
|
||||
|
||||
default PageResult<ExpenseApplyDO> selectPage(ExpenseApplyPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ExpenseApplyDO>()
|
||||
.eqIfPresent(ExpenseApplyDO::getBillType, reqVO.getBillType())
|
||||
.eqIfPresent(ExpenseApplyDO::getApplyNo, reqVO.getApplyNo())
|
||||
.eqIfPresent(ExpenseApplyDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ExpenseApplyDO::getDeptId, reqVO.getDeptId())
|
||||
.likeIfPresent(ExpenseApplyDO::getProjectName, reqVO.getProjectName())
|
||||
.eqIfPresent(ExpenseApplyDO::getReason, reqVO.getReason())
|
||||
.eqIfPresent(ExpenseApplyDO::getAmount, reqVO.getAmount())
|
||||
.eqIfPresent(ExpenseApplyDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(ExpenseApplyDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ExpenseApplyDO::getFiles, reqVO.getFiles())
|
||||
.betweenIfPresent(ExpenseApplyDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ExpenseApplyDO::getId));
|
||||
}
|
||||
|
||||
default List<ExpenseApplyDO> selectList(ExpenseApplyExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<ExpenseApplyDO>()
|
||||
.eqIfPresent(ExpenseApplyDO::getBillType, reqVO.getBillType())
|
||||
.eqIfPresent(ExpenseApplyDO::getApplyNo, reqVO.getApplyNo())
|
||||
.eqIfPresent(ExpenseApplyDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ExpenseApplyDO::getDeptId, reqVO.getDeptId())
|
||||
.likeIfPresent(ExpenseApplyDO::getProjectName, reqVO.getProjectName())
|
||||
.eqIfPresent(ExpenseApplyDO::getReason, reqVO.getReason())
|
||||
.eqIfPresent(ExpenseApplyDO::getAmount, reqVO.getAmount())
|
||||
.eqIfPresent(ExpenseApplyDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(ExpenseApplyDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ExpenseApplyDO::getFiles, reqVO.getFiles())
|
||||
.betweenIfPresent(ExpenseApplyDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ExpenseApplyDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.bs.dal.mysql.expenseapplytrip;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.expenseapplytrip.vo.*;
|
||||
|
||||
/**
|
||||
* 申请单行程明细 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExpenseApplyTripMapper extends BaseMapperX<ExpenseApplyTripDO> {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
package cn.iocoder.yudao.module.bs.service.invoice;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.*;
|
||||
import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO;
|
||||
import cn.iocoder.yudao.module.bs.dal.mysql.invoice.InvoiceMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link InvoiceServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author chenqp
|
||||
*/
|
||||
@Import(InvoiceServiceImpl.class)
|
||||
public class InvoiceServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InvoiceServiceImpl invoiceService;
|
||||
|
||||
@Resource
|
||||
private InvoiceMapper invoiceMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateInvoice_success() {
|
||||
// 准备参数
|
||||
InvoiceCreateReqVO reqVO = randomPojo(InvoiceCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long invoiceId = invoiceService.createInvoice(reqVO);
|
||||
// 断言
|
||||
assertNotNull(invoiceId);
|
||||
// 校验记录的属性是否正确
|
||||
InvoiceDO invoice = invoiceMapper.selectById(invoiceId);
|
||||
assertPojoEquals(reqVO, invoice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInvoice_success() {
|
||||
// mock 数据
|
||||
InvoiceDO dbInvoice = randomPojo(InvoiceDO.class);
|
||||
invoiceMapper.insert(dbInvoice);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
InvoiceUpdateReqVO reqVO = randomPojo(InvoiceUpdateReqVO.class, o -> {
|
||||
o.setId(dbInvoice.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
invoiceService.updateInvoice(reqVO);
|
||||
// 校验是否更新正确
|
||||
InvoiceDO invoice = invoiceMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, invoice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInvoice_notExists() {
|
||||
// 准备参数
|
||||
InvoiceUpdateReqVO reqVO = randomPojo(InvoiceUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> invoiceService.updateInvoice(reqVO), INVOICE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInvoice_success() {
|
||||
// mock 数据
|
||||
InvoiceDO dbInvoice = randomPojo(InvoiceDO.class);
|
||||
invoiceMapper.insert(dbInvoice);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbInvoice.getId();
|
||||
|
||||
// 调用
|
||||
invoiceService.deleteInvoice(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(invoiceMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInvoice_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> invoiceService.deleteInvoice(id), INVOICE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetInvoicePage() {
|
||||
// mock 数据
|
||||
InvoiceDO dbInvoice = randomPojo(InvoiceDO.class, o -> { // 等会查询到
|
||||
o.setFiles(null);
|
||||
o.setCreateBy(null);
|
||||
o.setCreateTime(null);
|
||||
o.setUpdateBy(null);
|
||||
o.setInvoiceType(null);
|
||||
o.setInvoiceCode(null);
|
||||
o.setInvoiceNum(null);
|
||||
o.setInvoiceDate(null);
|
||||
o.setSeller(null);
|
||||
o.setTaxAmount(null);
|
||||
o.setExcludingTaxAmount(null);
|
||||
o.setTotalAmount(null);
|
||||
o.setDeptId(null);
|
||||
o.setDeptName(null);
|
||||
o.setRemark(null);
|
||||
});
|
||||
invoiceMapper.insert(dbInvoice);
|
||||
// 测试 files 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setFiles(null)));
|
||||
// 测试 createBy 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setCreateBy(null)));
|
||||
// 测试 createTime 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setCreateTime(null)));
|
||||
// 测试 updateBy 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setUpdateBy(null)));
|
||||
// 测试 invoiceType 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceType(null)));
|
||||
// 测试 invoiceCode 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceCode(null)));
|
||||
// 测试 invoiceNum 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceNum(null)));
|
||||
// 测试 invoiceDate 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceDate(null)));
|
||||
// 测试 seller 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setSeller(null)));
|
||||
// 测试 taxAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setTaxAmount(null)));
|
||||
// 测试 excludingTaxAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setExcludingTaxAmount(null)));
|
||||
// 测试 totalAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setTotalAmount(null)));
|
||||
// 测试 deptId 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setDeptId(null)));
|
||||
// 测试 deptName 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setDeptName(null)));
|
||||
// 测试 remark 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setRemark(null)));
|
||||
// 准备参数
|
||||
InvoicePageReqVO reqVO = new InvoicePageReqVO();
|
||||
reqVO.setFiles(null);
|
||||
reqVO.setCreateBy(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setUpdateBy(null);
|
||||
reqVO.setInvoiceType(null);
|
||||
reqVO.setInvoiceCode(null);
|
||||
reqVO.setInvoiceNum(null);
|
||||
reqVO.setInvoiceDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setSeller(null);
|
||||
reqVO.setTaxAmount(null);
|
||||
reqVO.setExcludingTaxAmount(null);
|
||||
reqVO.setTotalAmount(null);
|
||||
reqVO.setDeptId(null);
|
||||
reqVO.setDeptName(null);
|
||||
reqVO.setRemark(null);
|
||||
|
||||
// 调用
|
||||
PageResult<InvoiceDO> pageResult = invoiceService.getInvoicePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbInvoice, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetInvoiceList() {
|
||||
// mock 数据
|
||||
InvoiceDO dbInvoice = randomPojo(InvoiceDO.class, o -> { // 等会查询到
|
||||
o.setFiles(null);
|
||||
o.setCreateBy(null);
|
||||
o.setCreateTime(null);
|
||||
o.setUpdateBy(null);
|
||||
o.setInvoiceType(null);
|
||||
o.setInvoiceCode(null);
|
||||
o.setInvoiceNum(null);
|
||||
o.setInvoiceDate(null);
|
||||
o.setSeller(null);
|
||||
o.setTaxAmount(null);
|
||||
o.setExcludingTaxAmount(null);
|
||||
o.setTotalAmount(null);
|
||||
o.setDeptId(null);
|
||||
o.setDeptName(null);
|
||||
o.setRemark(null);
|
||||
});
|
||||
invoiceMapper.insert(dbInvoice);
|
||||
// 测试 files 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setFiles(null)));
|
||||
// 测试 createBy 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setCreateBy(null)));
|
||||
// 测试 createTime 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setCreateTime(null)));
|
||||
// 测试 updateBy 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setUpdateBy(null)));
|
||||
// 测试 invoiceType 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceType(null)));
|
||||
// 测试 invoiceCode 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceCode(null)));
|
||||
// 测试 invoiceNum 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceNum(null)));
|
||||
// 测试 invoiceDate 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setInvoiceDate(null)));
|
||||
// 测试 seller 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setSeller(null)));
|
||||
// 测试 taxAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setTaxAmount(null)));
|
||||
// 测试 excludingTaxAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setExcludingTaxAmount(null)));
|
||||
// 测试 totalAmount 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setTotalAmount(null)));
|
||||
// 测试 deptId 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setDeptId(null)));
|
||||
// 测试 deptName 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setDeptName(null)));
|
||||
// 测试 remark 不匹配
|
||||
invoiceMapper.insert(cloneIgnoreId(dbInvoice, o -> o.setRemark(null)));
|
||||
// 准备参数
|
||||
InvoiceExportReqVO reqVO = new InvoiceExportReqVO();
|
||||
reqVO.setFiles(null);
|
||||
reqVO.setCreateBy(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setUpdateBy(null);
|
||||
reqVO.setInvoiceType(null);
|
||||
reqVO.setInvoiceCode(null);
|
||||
reqVO.setInvoiceNum(null);
|
||||
reqVO.setInvoiceDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setSeller(null);
|
||||
reqVO.setTaxAmount(null);
|
||||
reqVO.setExcludingTaxAmount(null);
|
||||
reqVO.setTotalAmount(null);
|
||||
reqVO.setDeptId(null);
|
||||
reqVO.setDeptName(null);
|
||||
reqVO.setRemark(null);
|
||||
|
||||
// 调用
|
||||
List<InvoiceDO> list = invoiceService.getInvoiceList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbInvoice, list.get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue