feat: 申请单开发

new
chenqp 1 year ago
parent 3fe5635b08
commit f0250d96d9

@ -15,8 +15,8 @@ public enum BpmProcessInstanceResultEnum {
PROCESS(1, "处理中"),
APPROVE(2, "通过"),
REJECT(3, "不通过"),
CANCEL(4, "取消"),
REJECT(3, "驳回"),
CANCEL(4, "取消"),
// ========== 流程任务独有的状态 ==========

@ -3,11 +3,15 @@ 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.bs.service.expenseapply.ExpenseApplyService;
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;
@ -33,7 +37,8 @@ public class ExpenseApplyController {
@Resource
private ExpenseApplyService expenseApplyService;
@Resource
private ExpenseApplyTripService expenseApplyTripService;
@PostMapping("/create")
@Operation(summary = "创建申请单")
@PreAuthorize("@ss.hasPermission('bs:expense-apply:create')")
@ -55,9 +60,15 @@ public class ExpenseApplyController {
@Operation(summary = "获得申请单")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bs:expense-apply:query')")
public CommonResult<ExpenseApplyRespVO> getExpenseApply(@RequestParam("id") Long id) {
public CommonResult<ExpenseApplyDO> getExpenseApply(@RequestParam("id") Long id) {
ExpenseApplyDO expenseApply = expenseApplyService.getExpenseApply(id);
return success(ExpenseApplyConvert.INSTANCE.convert(expenseApply));
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);
}
return success(expenseApply);
}
@GetMapping("/list")

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.bs.service.expenseapply;
package cn.iocoder.yudao.module.bpm.service.expenseapply;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -70,4 +70,5 @@ public interface ExpenseApplyService extends IService<ExpenseApplyDO> {
*/
List<ExpenseApplyDO> getExpenseApplyList(ExpenseApplyExportReqVO exportReqVO);
void processInstanceCallBack(long id, Integer result);
}

@ -1,15 +1,18 @@
package cn.iocoder.yudao.module.bs.service.expenseapply;
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.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.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.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;
@ -17,7 +20,7 @@ import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTr
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.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;
@ -30,10 +33,10 @@ import javax.validation.Validator;
import java.math.BigDecimal;
import java.util.Collection;
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.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_NOT_EXISTS;
/**
@ -56,7 +59,7 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
@Resource
private ExpenseApplyTripService expenseApplyTripService;
// @Resource
// private BpmProcessInstanceApi processInstanceApi;
private BpmProcessInstanceApi processInstanceApi;
@Override
public CommonResult createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
ExpenseApplyDO expenseApply = ExpenseApplyConvert.INSTANCE.convert(createReqVO);
@ -74,11 +77,14 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
}
expenseApplyTripService.saveOrUpdateBatch(trips);
}
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.UNAUDIT.getValue())) {
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
Map<String, Object> variables = BeanUtil.beanToMap(expenseApply);
//cqptodo 提交单据,创建工作流
// String processInstanceId = processInstanceApi.createProcessInstance(userId,
// new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
// .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(leave.getId())));
String processInstanceId = processInstanceApi.createProcessInstance(expenseApply.getUserId(),
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
.setVariables(variables).setBusinessKey(String.valueOf(expenseApply.getId())));
//cqptodo 待测试是否会更新其它字段 将工作流的编号,更新到单据中
updateById(new ExpenseApplyDO().setId(expenseApply.getId()).setProcessInstanceId(processInstanceId));
}
// 返回
return CommonResult.success();
@ -113,7 +119,11 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
//cqptodo 单号的规则需要重写
expenseApply.setApplyNo(RandomUtil.randomString(6));
}else {
validateExpenseApplyExists(expenseApply.getId());
ExpenseApplyDO dbApply = validateExpenseApplyExists(expenseApply.getId());
if (!dbApply.getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT)) {
//只有未提交才能更新
return CommonResult.error("只有未提交单据才能更新");
}
}
LoginUser loginUser = getLoginUser();
expenseApply.setUserId(loginUser.getId());
@ -131,10 +141,12 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
expenseApplyMapper.deleteById(id);
}
private void validateExpenseApplyExists(Long id) {
if (expenseApplyMapper.selectById(id) == null) {
private ExpenseApplyDO validateExpenseApplyExists(Long id) {
ExpenseApplyDO expenseApplyDO = expenseApplyMapper.selectById(id);
if (expenseApplyDO == null) {
throw exception(EXPENSE_APPLY_NOT_EXISTS);
}
return expenseApplyDO;
}
@Override
@ -157,4 +169,26 @@ public class ExpenseApplyServiceImpl extends ServiceImpl<ExpenseApplyMapper, Exp
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);
}
}
}

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.bs.service.expenseapplytrip;
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;

@ -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());
}
}

@ -11,9 +11,9 @@ import lombok.Getter;
public enum ExpenseApplyStatusEnum {
NOSUBMIT("0", "未提交"),
UNAUDIT("1", "待审核"),
NOPASS("2", "驳回"),
PASS("3", "通过"),
PROCESS("1", "待审核"),
APPROVE("2", "通过"),
REJECT("3", "驳回"),
CANCEL("4", "取消");

@ -1,7 +1,5 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -9,8 +7,6 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import java.util.Date;
@Schema(description = "管理后台 - 申请单创建 Request VO")
@Data
@ -19,9 +15,9 @@ import java.util.Date;
public class ExpenseApplyCreateReqVO extends ExpenseApplyBaseVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "14225")
private Long id;
@AssertTrue(message = "换班日期只能是大于今日的日期")
@AssertTrue(message = "状态只能是0或者1提交")
public boolean isStatusValid() {
//只能传未提交和待审核
return getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue()) || getStatus().equals(ExpenseApplyStatusEnum.UNAUDIT.getValue());
return getStatus().equals(ExpenseApplyStatusEnum.NOSUBMIT.getValue()) || getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue());
}
}

@ -1,11 +1,13 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
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;
@ -47,7 +49,7 @@ public class ExpenseApplyExportReqVO {
private String remark;
@Schema(description = "附件")
private String files;
private List<ImageVo> files;
@Schema(description = "创建者")
private String createBy;

@ -1,5 +1,6 @@
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;
@ -9,6 +10,7 @@ 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;
@ -52,7 +54,7 @@ public class ExpenseApplyPageReqVO extends PageParam {
private String remark;
@Schema(description = "附件")
private String files;
private List<ImageVo> files;
@Schema(description = "创建者")
private String createBy;

@ -45,11 +45,11 @@ public class ExpenseApplyTripBaseVO {
@NotNull(message = "出差天数不能为空")
private BigDecimal tripDay;
@Schema(description = "出差类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@Schema(description = "出差类型")
private String tripType;
@Schema(description = "出差同行人", requiredMode = Schema.RequiredMode.REQUIRED)
private String tripPartners;
@Schema(description = "出差同行人")
private Set<Long> tripPartners;
@Schema(description = "预计费用")
private BigDecimal amount;

@ -1,10 +1,12 @@
package cn.iocoder.yudao.module.bs.controller.admin.invoice.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* Excel VO
@ -18,7 +20,7 @@ public class InvoiceExcelVO {
private Long id;
@ExcelProperty("附件")
private String files;
private List<ImageVo> files;
@ExcelProperty("创建者")
private String createBy;

@ -1,11 +1,13 @@
package cn.iocoder.yudao.module.bs.controller.admin.invoice.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
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;
@ -14,7 +16,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class InvoiceExportReqVO {
@Schema(description = "附件")
private String files;
private List<ImageVo> files;
@Schema(description = "创建者")
private String createBy;

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bs.controller.admin.invoice.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;
@ -9,6 +10,7 @@ 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;
@ -19,7 +21,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class InvoicePageReqVO extends PageParam {
@Schema(description = "附件")
private String files;
private List<ImageVo> files;
@Schema(description = "创建者")
private String createBy;

@ -1,11 +1,13 @@
package cn.iocoder.yudao.module.bs.controller.admin.invoice.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 我的发票 Response VO")
@Data
@ -17,7 +19,7 @@ public class InvoiceRespVO extends InvoiceBaseVO {
private Long id;
@Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED)
private String files;
private List<ImageVo> files;
@Schema(description = "创建者")
private String createBy;

@ -1,11 +1,13 @@
package cn.iocoder.yudao.module.bs.controller.admin.invoice.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "管理后台 - 我的发票更新 Request VO")
@Data
@ -19,6 +21,6 @@ public class InvoiceUpdateReqVO extends InvoiceBaseVO {
@Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "附件不能为空")
private String files;
private List<ImageVo> files;
}

@ -3,6 +3,7 @@ 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;
@ -81,5 +82,13 @@ public class ExpenseApplyDO extends TenantBaseDO {
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ImageVo> files;
/**
*
*
* ProcessInstance id
*/
private String processInstanceId;
@TableField(exist = false)
private List<ExpenseApplyTripDO> expenseApplyTrips;
}

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
@ -40,7 +42,8 @@ public class ExpenseApplyTripDO extends TenantBaseDO {
/**
*
*/
private String files;
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ImageVo> files;
/**
*
*/
@ -82,8 +85,8 @@ public class ExpenseApplyTripDO extends TenantBaseDO {
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private String tripPartners;
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> tripPartners;
/**
*
*/

@ -1,19 +1,22 @@
package cn.iocoder.yudao.module.bs.dal.dataobject.invoice;
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 com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* DO
*
* @author chenqp
*/
@TableName("bs_invoice")
@TableName(value = "bs_invoice", autoResultMap = true)
@KeySequence("bs_invoice_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ -31,7 +34,8 @@ public class InvoiceDO extends TenantBaseDO {
/**
*
*/
private String files;
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ImageVo> files;
/**
*

@ -1,259 +0,0 @@
package cn.iocoder.yudao.module.bs.service.expenseapply;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
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 cn.iocoder.yudao.module.bs.dal.mysql.expenseapply.ExpenseApplyMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link ExpenseApplyServiceImpl}
*
* @author
*/
@Import(ExpenseApplyServiceImpl.class)
public class ExpenseApplyServiceImplTest extends BaseDbUnitTest {
@Resource
private ExpenseApplyServiceImpl expenseApplyService;
@Resource
private ExpenseApplyMapper expenseApplyMapper;
@Test
public void testCreateExpenseApply_success() {
// 准备参数
ExpenseApplyCreateReqVO reqVO = randomPojo(ExpenseApplyCreateReqVO.class);
// 调用
// Long expenseApplyId = expenseApplyService.createExpenseApply(reqVO);
// // 断言
// assertNotNull(expenseApplyId);
// // 校验记录的属性是否正确
// ExpenseApplyDO expenseApply = expenseApplyMapper.selectById(expenseApplyId);
// assertPojoEquals(reqVO, expenseApply);
}
@Test
public void testUpdateExpenseApply_success() {
// mock 数据
ExpenseApplyDO dbExpenseApply = randomPojo(ExpenseApplyDO.class);
expenseApplyMapper.insert(dbExpenseApply);// @Sql: 先插入出一条存在的数据
// 准备参数
ExpenseApplyUpdateReqVO reqVO = randomPojo(ExpenseApplyUpdateReqVO.class, o -> {
o.setId(dbExpenseApply.getId()); // 设置更新的 ID
});
// 调用
expenseApplyService.updateExpenseApply(reqVO);
// 校验是否更新正确
ExpenseApplyDO expenseApply = expenseApplyMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, expenseApply);
}
@Test
public void testUpdateExpenseApply_notExists() {
// 准备参数
ExpenseApplyUpdateReqVO reqVO = randomPojo(ExpenseApplyUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> expenseApplyService.updateExpenseApply(reqVO), EXPENSE_APPLY_NOT_EXISTS);
}
@Test
public void testDeleteExpenseApply_success() {
// mock 数据
ExpenseApplyDO dbExpenseApply = randomPojo(ExpenseApplyDO.class);
expenseApplyMapper.insert(dbExpenseApply);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbExpenseApply.getId();
// 调用
expenseApplyService.deleteExpenseApply(id);
// 校验数据不存在了
assertNull(expenseApplyMapper.selectById(id));
}
@Test
public void testDeleteExpenseApply_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> expenseApplyService.deleteExpenseApply(id), EXPENSE_APPLY_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetExpenseApplyPage() {
// mock 数据
ExpenseApplyDO dbExpenseApply = randomPojo(ExpenseApplyDO.class, o -> { // 等会查询到
o.setBillType(null);
o.setApplyNo(null);
o.setUserId(null);
o.setNickname(null);
o.setDeptId(null);
o.setDeptName(null);
o.setProjectName(null);
o.setReason(null);
o.setAmount(null);
o.setStatus(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateBy(null);
o.setCreateTime(null);
o.setUpdateBy(null);
});
expenseApplyMapper.insert(dbExpenseApply);
// 测试 billType 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setBillType(null)));
// 测试 applyNo 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setApplyNo(null)));
// 测试 userId 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setUserId(null)));
// 测试 nickname 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setNickname(null)));
// 测试 deptId 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setDeptId(null)));
// 测试 deptName 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setDeptName(null)));
// 测试 projectName 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setProjectName(null)));
// 测试 reason 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setReason(null)));
// 测试 amount 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setAmount(null)));
// 测试 status 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setStatus(null)));
// 测试 remark 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setRemark(null)));
// 测试 files 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setFiles(null)));
// 测试 createBy 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setCreateBy(null)));
// 测试 createTime 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setCreateTime(null)));
// 测试 updateBy 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setUpdateBy(null)));
// 准备参数
ExpenseApplyPageReqVO reqVO = new ExpenseApplyPageReqVO();
reqVO.setBillType(null);
reqVO.setApplyNo(null);
reqVO.setUserId(null);
reqVO.setNickname(null);
reqVO.setDeptId(null);
reqVO.setDeptName(null);
reqVO.setProjectName(null);
reqVO.setReason(null);
reqVO.setAmount(null);
reqVO.setStatus(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateBy(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setUpdateBy(null);
// 调用
PageResult<ExpenseApplyDO> pageResult = expenseApplyService.getExpenseApplyPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbExpenseApply, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetExpenseApplyList() {
// mock 数据
ExpenseApplyDO dbExpenseApply = randomPojo(ExpenseApplyDO.class, o -> { // 等会查询到
o.setBillType(null);
o.setApplyNo(null);
o.setUserId(null);
o.setNickname(null);
o.setDeptId(null);
o.setDeptName(null);
o.setProjectName(null);
o.setReason(null);
o.setAmount(null);
o.setStatus(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateBy(null);
o.setCreateTime(null);
o.setUpdateBy(null);
});
expenseApplyMapper.insert(dbExpenseApply);
// 测试 billType 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setBillType(null)));
// 测试 applyNo 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setApplyNo(null)));
// 测试 userId 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setUserId(null)));
// 测试 nickname 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setNickname(null)));
// 测试 deptId 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setDeptId(null)));
// 测试 deptName 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setDeptName(null)));
// 测试 projectName 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setProjectName(null)));
// 测试 reason 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setReason(null)));
// 测试 amount 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setAmount(null)));
// 测试 status 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setStatus(null)));
// 测试 remark 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setRemark(null)));
// 测试 files 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setFiles(null)));
// 测试 createBy 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setCreateBy(null)));
// 测试 createTime 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setCreateTime(null)));
// 测试 updateBy 不匹配
expenseApplyMapper.insert(cloneIgnoreId(dbExpenseApply, o -> o.setUpdateBy(null)));
// 准备参数
ExpenseApplyExportReqVO reqVO = new ExpenseApplyExportReqVO();
reqVO.setBillType(null);
reqVO.setApplyNo(null);
reqVO.setUserId(null);
reqVO.setNickname(null);
reqVO.setDeptId(null);
reqVO.setDeptName(null);
reqVO.setProjectName(null);
reqVO.setReason(null);
reqVO.setAmount(null);
reqVO.setStatus(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateBy(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setUpdateBy(null);
// 调用
List<ExpenseApplyDO> list = expenseApplyService.getExpenseApplyList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbExpenseApply, list.get(0));
}
}

@ -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));
}
}

@ -150,6 +150,7 @@ logging:
level:
# 配置自己写的 MyBatis Mapper 打印日志
cn.iocoder.yudao.module.bpm.dal.mysql: debug
cn.iocoder.yudao.module.bs.dal.mysql: debug
cn.iocoder.yudao.module.infra.dal.mysql: debug
cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper: INFO # 配置 JobLogMapper 的日志级别为 info
cn.iocoder.yudao.module.pay.dal.mysql: debug

Loading…
Cancel
Save