feat: 申请单主单代码临时提交

new
chenqp 1 year ago
parent 4dfc6e5f07
commit 1580d21d83

@ -10,5 +10,5 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
public interface ErrorCodeConstants { public interface ErrorCodeConstants {
ErrorCode INVOICE_NOT_EXISTS = new ErrorCode(200100, "我的发票不存在"); ErrorCode INVOICE_NOT_EXISTS = new ErrorCode(200100, "我的发票不存在");
ErrorCode EXPENSE_APPLY_NOT_EXISTS = new ErrorCode(200200, "申请单不存在");
} }

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.bs.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.operatelog.core.annotations.OperateLog;
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 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;
@PostMapping("/create")
@Operation(summary = "创建申请单")
@PreAuthorize("@ss.hasPermission('bs:expense-apply:create')")
public CommonResult<Long> createExpenseApply(@Valid @RequestBody ExpenseApplyCreateReqVO createReqVO) {
return success(expenseApplyService.createExpenseApply(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新申请单")
@PreAuthorize("@ss.hasPermission('bs:expense-apply:update')")
public CommonResult<Boolean> updateExpenseApply(@Valid @RequestBody ExpenseApplyUpdateReqVO updateReqVO) {
expenseApplyService.updateExpenseApply(updateReqVO);
return success(true);
}
@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<ExpenseApplyRespVO> getExpenseApply(@RequestParam("id") Long id) {
ExpenseApplyDO expenseApply = expenseApplyService.getExpenseApply(id);
return success(ExpenseApplyConvert.INSTANCE.convert(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,49 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class ExpenseApplyBaseVO {
@Schema(description = "申请类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "申请类型不能为空")
private String billType;
@Schema(description = "申请者ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9227")
@NotNull(message = "申请者ID不能为空")
private Long userId;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@NotNull(message = "用户昵称不能为空")
private String nickname;
@Schema(description = "部门ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "32343")
@NotNull(message = "部门ID不能为空")
private Long deptId;
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@NotNull(message = "部门名称不能为空")
private String deptName;
@Schema(description = "项目名称", example = "芋艿")
private String projectName;
@Schema(description = "申请事由", example = "不香")
private String reason;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "附件不能为空")
private String files;
}

@ -0,0 +1,14 @@
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;
@Schema(description = "管理后台 - 申请单创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ExpenseApplyCreateReqVO extends ExpenseApplyBaseVO {
}

@ -0,0 +1,70 @@
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 String files;
@ExcelProperty("创建者")
private String createBy;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@ExcelProperty("更新者")
private String updateBy;
}

@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
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 static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 申请单 Excel 导出 Request VO参数和 ExpenseApplyPageReqVO 是一致的")
@Data
public class ExpenseApplyExportReqVO {
@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 String 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,67 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseapply.vo;
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 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 String 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,36 @@
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.dal.dataobject.expenseapply.ExpenseApplyDO;
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);
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,84 @@
package cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
/**
* 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 BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
*
*
* {@link TODO bs_bill_type }
*/
private String billType;
/**
*
*/
private String applyNo;
/**
* ID
*/
private Long userId;
/**
*
*/
private String nickname;
/**
* ID
*/
private Long deptId;
/**
*
*/
private String deptName;
/**
*
*/
private String projectName;
/**
*
*/
private String reason;
/**
*
*/
private BigDecimal amount;
/**
*
*
* {@link TODO bs_expense_apply_status }
*/
private String status;
/**
*
*/
private String remark;
/**
*
*/
private String files;
}

@ -31,14 +31,7 @@ public class InvoiceDO extends BaseDO {
* *
*/ */
private String files; private String files;
/**
*
*/
private String createBy;
/**
*
*/
private String updateBy;
/** /**
* *
*/ */

@ -0,0 +1,57 @@
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())
.likeIfPresent(ExpenseApplyDO::getNickname, reqVO.getNickname())
.eqIfPresent(ExpenseApplyDO::getDeptId, reqVO.getDeptId())
.likeIfPresent(ExpenseApplyDO::getDeptName, reqVO.getDeptName())
.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())
.likeIfPresent(ExpenseApplyDO::getNickname, reqVO.getNickname())
.eqIfPresent(ExpenseApplyDO::getDeptId, reqVO.getDeptId())
.likeIfPresent(ExpenseApplyDO::getDeptName, reqVO.getDeptName())
.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));
}
}

@ -21,9 +21,7 @@ public interface InvoiceMapper extends BaseMapperX<InvoiceDO> {
default PageResult<InvoiceDO> selectPage(InvoicePageReqVO reqVO) { default PageResult<InvoiceDO> selectPage(InvoicePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<InvoiceDO>() return selectPage(reqVO, new LambdaQueryWrapperX<InvoiceDO>()
.eqIfPresent(InvoiceDO::getFiles, reqVO.getFiles()) .eqIfPresent(InvoiceDO::getFiles, reqVO.getFiles())
.eqIfPresent(InvoiceDO::getCreateBy, reqVO.getCreateBy())
.betweenIfPresent(InvoiceDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(InvoiceDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(InvoiceDO::getUpdateBy, reqVO.getUpdateBy())
.eqIfPresent(InvoiceDO::getInvoiceType, reqVO.getInvoiceType()) .eqIfPresent(InvoiceDO::getInvoiceType, reqVO.getInvoiceType())
.eqIfPresent(InvoiceDO::getInvoiceCode, reqVO.getInvoiceCode()) .eqIfPresent(InvoiceDO::getInvoiceCode, reqVO.getInvoiceCode())
.eqIfPresent(InvoiceDO::getInvoiceNum, reqVO.getInvoiceNum()) .eqIfPresent(InvoiceDO::getInvoiceNum, reqVO.getInvoiceNum())
@ -41,9 +39,7 @@ public interface InvoiceMapper extends BaseMapperX<InvoiceDO> {
default List<InvoiceDO> selectList(InvoiceExportReqVO reqVO) { default List<InvoiceDO> selectList(InvoiceExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<InvoiceDO>() return selectList(new LambdaQueryWrapperX<InvoiceDO>()
.eqIfPresent(InvoiceDO::getFiles, reqVO.getFiles()) .eqIfPresent(InvoiceDO::getFiles, reqVO.getFiles())
.eqIfPresent(InvoiceDO::getCreateBy, reqVO.getCreateBy())
.betweenIfPresent(InvoiceDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(InvoiceDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(InvoiceDO::getUpdateBy, reqVO.getUpdateBy())
.eqIfPresent(InvoiceDO::getInvoiceType, reqVO.getInvoiceType()) .eqIfPresent(InvoiceDO::getInvoiceType, reqVO.getInvoiceType())
.eqIfPresent(InvoiceDO::getInvoiceCode, reqVO.getInvoiceCode()) .eqIfPresent(InvoiceDO::getInvoiceCode, reqVO.getInvoiceCode())
.eqIfPresent(InvoiceDO::getInvoiceNum, reqVO.getInvoiceNum()) .eqIfPresent(InvoiceDO::getInvoiceNum, reqVO.getInvoiceNum())

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.bs.service.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.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 javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
*
* @author
*/
public interface ExpenseApplyService {
/**
*
*
* @param createReqVO
* @return
*/
Long createExpenseApply(@Valid ExpenseApplyCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateExpenseApply(@Valid ExpenseApplyUpdateReqVO updateReqVO);
/**
*
*
* @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);
}

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.bs.service.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.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.convert.expenseapply.ExpenseApplyConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO;
import cn.iocoder.yudao.module.bs.dal.mysql.expenseapply.ExpenseApplyMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.EXPENSE_APPLY_NOT_EXISTS;
/**
* Service
*
* @author
*/
@Service
@Validated
public class ExpenseApplyServiceImpl implements ExpenseApplyService {
@Resource
private ExpenseApplyMapper expenseApplyMapper;
@Override
public Long createExpenseApply(ExpenseApplyCreateReqVO createReqVO) {
// 插入
ExpenseApplyDO expenseApply = ExpenseApplyConvert.INSTANCE.convert(createReqVO);
expenseApplyMapper.insert(expenseApply);
// 返回
return expenseApply.getId();
}
@Override
public void updateExpenseApply(ExpenseApplyUpdateReqVO updateReqVO) {
// 校验存在
validateExpenseApplyExists(updateReqVO.getId());
// 更新
ExpenseApplyDO updateObj = ExpenseApplyConvert.INSTANCE.convert(updateReqVO);
expenseApplyMapper.updateById(updateObj);
}
@Override
public void deleteExpenseApply(Long id) {
// 校验存在
validateExpenseApplyExists(id);
// 删除
expenseApplyMapper.deleteById(id);
}
private void validateExpenseApplyExists(Long id) {
if (expenseApplyMapper.selectById(id) == null) {
throw exception(EXPENSE_APPLY_NOT_EXISTS);
}
}
@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);
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.bs.dal.mysql.expenseapply.ExpenseApplyMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,259 @@
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));
}
}
Loading…
Cancel
Save