feat: 预算,费控初始化

new
chenqp 1 year ago
parent 518cf7d728
commit b2fd04d427

@ -11,4 +11,6 @@ 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, "申请单不存在"); ErrorCode EXPENSE_APPLY_NOT_EXISTS = new ErrorCode(200200, "申请单不存在");
ErrorCode BUDGET_NOT_EXISTS = new ErrorCode(200400, "预算管理不存在");
ErrorCode FEE_MANAGE_NOT_EXISTS = new ErrorCode(200500, "费用控制不存在");
} }

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget;
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.budget.vo.*;
import cn.iocoder.yudao.module.bs.convert.budget.BudgetConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import cn.iocoder.yudao.module.bs.service.budget.BudgetService;
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/budget")
@Validated
public class BudgetController {
@Resource
private BudgetService budgetService;
@PostMapping("/create")
@Operation(summary = "创建预算管理")
@PreAuthorize("@ss.hasPermission('bs:budget:create')")
public CommonResult<Long> createBudget(@Valid @RequestBody BudgetCreateReqVO createReqVO) {
return success(budgetService.createBudget(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新预算管理")
@PreAuthorize("@ss.hasPermission('bs:budget:update')")
public CommonResult<Boolean> updateBudget(@Valid @RequestBody BudgetUpdateReqVO updateReqVO) {
budgetService.updateBudget(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除预算管理")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('bs:budget:delete')")
public CommonResult<Boolean> deleteBudget(@RequestParam("id") Long id) {
budgetService.deleteBudget(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得预算管理")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bs:budget:query')")
public CommonResult<BudgetDO> getBudget(@RequestParam("id") Long id) {
BudgetDO budget = budgetService.getBudget(id);
return success(budget);
}
@GetMapping("/list")
@Operation(summary = "获得预算管理列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('bs:budget:query')")
public CommonResult<List<BudgetRespVO>> getBudgetList(@RequestParam("ids") Collection<Long> ids) {
List<BudgetDO> list = budgetService.getBudgetList(ids);
return success(BudgetConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得预算管理分页")
@PreAuthorize("@ss.hasPermission('bs:budget:query')")
public CommonResult<PageResult<BudgetDO>> getBudgetPage(@Valid BudgetPageReqVO pageVO) {
PageResult<BudgetDO> pageResult = budgetService.getBudgetPage(pageVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@Operation(summary = "导出预算管理 Excel")
@PreAuthorize("@ss.hasPermission('bs:budget:export')")
@OperateLog(type = EXPORT)
public void exportBudgetExcel(@Valid BudgetExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<BudgetDO> list = budgetService.getBudgetList(exportReqVO);
// 导出 Excel
List<BudgetExcelVO> datas = BudgetConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "预算管理.xls", "数据", BudgetExcelVO.class, datas);
}
}

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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 javax.validation.constraints.NotNull;
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;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class BudgetBaseVO {
@Schema(description = "预算年度", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "预算年度不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime budgetYear;
@Schema(description = "预算金额", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "预算金额不能为空")
private BigDecimal amount;
@Schema(description = "部门ID", example = "30450")
@NotNull(message = "部门ID不能为空")
private Long deptId;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED)
private List<ImageVo> files;
}

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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 BudgetCreateReqVO extends BudgetBaseVO {
}

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* Excel VO
*
* @author chenqp
*/
@Data
public class BudgetExcelVO {
@ExcelProperty("id")
private Long id;
@ExcelProperty("预算年度")
private LocalDateTime budgetYear;
@ExcelProperty("预算金额")
private BigDecimal amount;
@ExcelProperty("已使用金额")
private BigDecimal usedAmount;
@ExcelProperty("占用金额")
private BigDecimal occupyAmount;
@ExcelProperty("剩余金额")
private BigDecimal remainAmount;
@ExcelProperty("部门ID")
private Long deptId;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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参数和 BudgetPageReqVO 是一致的")
@Data
public class BudgetExportReqVO {
@Schema(description = "预算年度")
private LocalDateTime budgetYear;
@Schema(description = "预算金额")
private BigDecimal amount;
@Schema(description = "已使用金额")
private BigDecimal usedAmount;
@Schema(description = "占用金额")
private BigDecimal occupyAmount;
@Schema(description = "剩余金额")
private BigDecimal remainAmount;
@Schema(description = "部门ID", example = "30450")
private Long deptId;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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 BudgetPageReqVO extends PageParam {
@Schema(description = "预算年度")
private LocalDateTime budgetYear;
@Schema(description = "预算金额")
private BigDecimal amount;
@Schema(description = "已使用金额")
private BigDecimal usedAmount;
@Schema(description = "占用金额")
private BigDecimal occupyAmount;
@Schema(description = "剩余金额")
private BigDecimal remainAmount;
@Schema(description = "部门ID", example = "30450")
private Long deptId;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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 BudgetRespVO extends BudgetBaseVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29841")
private Long id;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.bs.controller.admin.budget.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 BudgetUpdateReqVO extends BudgetBaseVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29841")
@NotNull(message = "id不能为空")
private Long id;
}

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage;
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.feemanage.vo.*;
import cn.iocoder.yudao.module.bs.convert.feemanage.FeeManageConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import cn.iocoder.yudao.module.bs.service.feemanage.FeeManageService;
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/fee-manage")
@Validated
public class FeeManageController {
@Resource
private FeeManageService feeManageService;
@PostMapping("/create")
@Operation(summary = "创建费用控制")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:create')")
public CommonResult<Long> createFeeManage(@Valid @RequestBody FeeManageCreateReqVO createReqVO) {
return success(feeManageService.createFeeManage(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新费用控制")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:update')")
public CommonResult<Boolean> updateFeeManage(@Valid @RequestBody FeeManageUpdateReqVO updateReqVO) {
feeManageService.updateFeeManage(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除费用控制")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('bs:fee-manage:delete')")
public CommonResult<Boolean> deleteFeeManage(@RequestParam("id") Long id) {
feeManageService.deleteFeeManage(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得费用控制")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:query')")
public CommonResult<FeeManageDO> getFeeManage(@RequestParam("id") Long id) {
FeeManageDO feeManage = feeManageService.getFeeManage(id);
return success(feeManage);
}
@GetMapping("/list")
@Operation(summary = "获得费用控制列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:query')")
public CommonResult<List<FeeManageRespVO>> getFeeManageList(@RequestParam("ids") Collection<Long> ids) {
List<FeeManageDO> list = feeManageService.getFeeManageList(ids);
return success(FeeManageConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得费用控制分页")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:query')")
public CommonResult<PageResult<FeeManageDO>> getFeeManagePage(@Valid FeeManagePageReqVO pageVO) {
PageResult<FeeManageDO> pageResult = feeManageService.getFeeManagePage(pageVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@Operation(summary = "导出费用控制 Excel")
@PreAuthorize("@ss.hasPermission('bs:fee-manage:export')")
@OperateLog(type = EXPORT)
public void exportFeeManageExcel(@Valid FeeManageExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<FeeManageDO> list = feeManageService.getFeeManageList(exportReqVO);
// 导出 Excel
List<FeeManageExcelVO> datas = FeeManageConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "费用控制.xls", "数据", FeeManageExcelVO.class, datas);
}
}

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class FeeManageBaseVO {
@Schema(description = "部门ID", example = "29962")
private Long deptId;
@Schema(description = "角色", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "角色不能为空")
private Set<Long> roleIds;
@Schema(description = "限定金额", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "限定金额不能为空")
private BigDecimal amount;
@Schema(description = "出差区域", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "出差区域不能为空")
private List<String> area;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED)
private List<ImageVo> files;
}

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.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 FeeManageCreateReqVO extends FeeManageBaseVO {
}

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
/**
* Excel VO
*
* @author chenqp
*/
@Data
public class FeeManageExcelVO {
@ExcelProperty("id")
private Long id;
@ExcelProperty("部门ID")
private Long deptId;
@ExcelProperty("角色")
private Set<Long> roleIds;
@ExcelProperty("限定金额")
private BigDecimal amount;
@ExcelProperty("出差区域")
private List<String> area;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.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 java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 费用控制 Excel 导出 Request VO参数和 FeeManagePageReqVO 是一致的")
@Data
public class FeeManageExportReqVO {
@Schema(description = "部门ID", example = "29962")
private Long deptId;
@Schema(description = "角色")
private Set<Long> roleIds;
@Schema(description = "限定金额")
private BigDecimal amount;
@Schema(description = "出差区域")
private List<String> area;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.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 java.util.List;
import java.util.Set;
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 FeeManagePageReqVO extends PageParam {
@Schema(description = "部门ID", example = "29962")
private Long deptId;
@Schema(description = "角色")
private Set<Long> roleIds;
@Schema(description = "限定金额")
private BigDecimal amount;
@Schema(description = "出差区域")
private List<String> area;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.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 FeeManageRespVO extends FeeManageBaseVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1002")
private Long id;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.bs.controller.admin.feemanage.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 FeeManageUpdateReqVO extends FeeManageBaseVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1002")
@NotNull(message = "id不能为空")
private Long id;
}

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.bs.convert.budget;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExcelVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetRespVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Convert
*
* @author chenqp
*/
@Mapper
public interface BudgetConvert {
BudgetConvert INSTANCE = Mappers.getMapper(BudgetConvert.class);
BudgetDO convert(BudgetCreateReqVO bean);
BudgetDO convert(BudgetUpdateReqVO bean);
BudgetRespVO convert(BudgetDO bean);
List<BudgetRespVO> convertList(List<BudgetDO> list);
PageResult<BudgetRespVO> convertPage(PageResult<BudgetDO> page);
List<BudgetExcelVO> convertList02(List<BudgetDO> list);
}

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.bs.convert.feemanage;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageExcelVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageRespVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Convert
*
* @author chenqp
*/
@Mapper
public interface FeeManageConvert {
FeeManageConvert INSTANCE = Mappers.getMapper(FeeManageConvert.class);
FeeManageDO convert(FeeManageCreateReqVO bean);
FeeManageDO convert(FeeManageUpdateReqVO bean);
FeeManageRespVO convert(FeeManageDO bean);
List<FeeManageRespVO> convertList(List<FeeManageDO> list);
PageResult<FeeManageRespVO> convertPage(PageResult<FeeManageDO> page);
List<FeeManageExcelVO> convertList02(List<FeeManageDO> list);
}

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.bs.dal.dataobject.budget;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
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.time.LocalDateTime;
import java.util.List;
/**
* DO
*
* @author chenqp
*/
@TableName(value = "bs_budget", autoResultMap = true)
@KeySequence("bs_budget_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BudgetDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
*
*/
private LocalDateTime budgetYear;
/**
*
*/
private BigDecimal amount;
/**
* 使
*/
private BigDecimal usedAmount;
/**
*
*/
private BigDecimal occupyAmount;
/**
*
*/
private BigDecimal remainAmount;
/**
* ID
*/
private Long deptId;
/**
*
*/
private String remark;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ImageVo> files;
}

@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.bs.dal.dataobject.feemanage;
import cn.iocoder.yudao.framework.common.pojo.ImageVo;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
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;
import java.util.Set;
/**
* DO
*
* @author chenqp
*/
@TableName(value = "bs_fee_manage", autoResultMap = true)
@KeySequence("bs_fee_manage_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FeeManageDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* ID
*/
private Long deptId;
/**
*
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> roleIds;
/**
*
*/
private BigDecimal amount;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> area;
/**
*
*/
private String remark;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<ImageVo> files;
}

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.bs.dal.mysql.budget;
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.budget.vo.BudgetExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
*
* @author chenqp
*/
@Mapper
public interface BudgetMapper extends BaseMapperX<BudgetDO> {
default PageResult<BudgetDO> selectPage(BudgetPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BudgetDO>()
.eqIfPresent(BudgetDO::getBudgetYear, reqVO.getBudgetYear())
.eqIfPresent(BudgetDO::getAmount, reqVO.getAmount())
.eqIfPresent(BudgetDO::getUsedAmount, reqVO.getUsedAmount())
.eqIfPresent(BudgetDO::getOccupyAmount, reqVO.getOccupyAmount())
.eqIfPresent(BudgetDO::getRemainAmount, reqVO.getRemainAmount())
.eqIfPresent(BudgetDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(BudgetDO::getRemark, reqVO.getRemark())
.betweenIfPresent(BudgetDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(BudgetDO::getId));
}
default List<BudgetDO> selectList(BudgetExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<BudgetDO>()
.eqIfPresent(BudgetDO::getBudgetYear, reqVO.getBudgetYear())
.eqIfPresent(BudgetDO::getAmount, reqVO.getAmount())
.eqIfPresent(BudgetDO::getUsedAmount, reqVO.getUsedAmount())
.eqIfPresent(BudgetDO::getOccupyAmount, reqVO.getOccupyAmount())
.eqIfPresent(BudgetDO::getRemainAmount, reqVO.getRemainAmount())
.eqIfPresent(BudgetDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(BudgetDO::getRemark, reqVO.getRemark())
.betweenIfPresent(BudgetDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(BudgetDO::getId));
}
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.bs.dal.mysql.feemanage;
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.feemanage.vo.FeeManageExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManagePageReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
*
* @author chenqp
*/
@Mapper
public interface FeeManageMapper extends BaseMapperX<FeeManageDO> {
default PageResult<FeeManageDO> selectPage(FeeManagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<FeeManageDO>()
.eqIfPresent(FeeManageDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(FeeManageDO::getRoleIds, reqVO.getRoleIds())
.eqIfPresent(FeeManageDO::getAmount, reqVO.getAmount())
.eqIfPresent(FeeManageDO::getArea, reqVO.getArea())
.eqIfPresent(FeeManageDO::getRemark, reqVO.getRemark())
.betweenIfPresent(FeeManageDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(FeeManageDO::getId));
}
default List<FeeManageDO> selectList(FeeManageExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<FeeManageDO>()
.eqIfPresent(FeeManageDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(FeeManageDO::getRoleIds, reqVO.getRoleIds())
.eqIfPresent(FeeManageDO::getAmount, reqVO.getAmount())
.eqIfPresent(FeeManageDO::getArea, reqVO.getArea())
.eqIfPresent(FeeManageDO::getRemark, reqVO.getRemark())
.betweenIfPresent(FeeManageDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(FeeManageDO::getId));
}
}

@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.bs.service.budget;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import com.github.yulichang.base.MPJBaseService;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
*
* @author chenqp
*/
public interface BudgetService extends MPJBaseService<BudgetDO> {
/**
*
*
* @param createReqVO
* @return
*/
Long createBudget(@Valid BudgetCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateBudget(@Valid BudgetUpdateReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteBudget(Long id);
/**
*
*
* @param id
* @return
*/
BudgetDO getBudget(Long id);
/**
*
*
* @param ids
* @return
*/
List<BudgetDO> getBudgetList(Collection<Long> ids);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<BudgetDO> getBudgetPage(BudgetPageReqVO pageReqVO);
/**
* , Excel
*
* @param exportReqVO
* @return
*/
List<BudgetDO> getBudgetList(BudgetExportReqVO exportReqVO);
}

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.bs.service.budget;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
import cn.iocoder.yudao.module.bs.convert.budget.BudgetConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import cn.iocoder.yudao.module.bs.dal.mysql.budget.BudgetMapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.BUDGET_NOT_EXISTS;
/**
* Service
*
* @author chenqp
*/
@Service
@Validated
public class BudgetServiceImpl extends MPJBaseServiceImpl<BudgetMapper, BudgetDO> implements BudgetService {
@Resource
private BudgetMapper budgetMapper;
@Override
public Long createBudget(BudgetCreateReqVO createReqVO) {
// 插入
BudgetDO budget = BudgetConvert.INSTANCE.convert(createReqVO);
setBaseField(budget);
budgetMapper.insert(budget);
// 返回
return budget.getId();
}
@Override
public void updateBudget(BudgetUpdateReqVO updateReqVO) {
// 校验存在
validateBudgetExists(updateReqVO.getId());
// 更新
BudgetDO budget = BudgetConvert.INSTANCE.convert(updateReqVO);
setBaseField(budget);
budgetMapper.updateById(budget);
}
private void setBaseField(BudgetDO budget) {
budget.setOccupyAmount(BigDecimal.ZERO);
budget.setUsedAmount(BigDecimal.ZERO);
budget.setRemainAmount(BigDecimal.ZERO);
}
@Override
public void deleteBudget(Long id) {
// 校验存在
validateBudgetExists(id);
// 删除
budgetMapper.deleteById(id);
}
private void validateBudgetExists(Long id) {
if (budgetMapper.selectById(id) == null) {
throw exception(BUDGET_NOT_EXISTS);
}
}
@Override
public BudgetDO getBudget(Long id) {
return budgetMapper.selectById(id);
}
@Override
public List<BudgetDO> getBudgetList(Collection<Long> ids) {
return budgetMapper.selectBatchIds(ids);
}
@Override
public PageResult<BudgetDO> getBudgetPage(BudgetPageReqVO pageReqVO) {
return budgetMapper.selectPage(pageReqVO);
}
@Override
public List<BudgetDO> getBudgetList(BudgetExportReqVO exportReqVO) {
return budgetMapper.selectList(exportReqVO);
}
}

@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.bs.service.feemanage;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManagePageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import com.github.yulichang.base.MPJBaseService;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
*
* @author chenqp
*/
public interface FeeManageService extends MPJBaseService<FeeManageDO> {
/**
*
*
* @param createReqVO
* @return
*/
Long createFeeManage(@Valid FeeManageCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateFeeManage(@Valid FeeManageUpdateReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteFeeManage(Long id);
/**
*
*
* @param id
* @return
*/
FeeManageDO getFeeManage(Long id);
/**
*
*
* @param ids
* @return
*/
List<FeeManageDO> getFeeManageList(Collection<Long> ids);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<FeeManageDO> getFeeManagePage(FeeManagePageReqVO pageReqVO);
/**
* , Excel
*
* @param exportReqVO
* @return
*/
List<FeeManageDO> getFeeManageList(FeeManageExportReqVO exportReqVO);
}

@ -0,0 +1,86 @@
package cn.iocoder.yudao.module.bs.service.feemanage;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManagePageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateReqVO;
import cn.iocoder.yudao.module.bs.convert.feemanage.FeeManageConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import cn.iocoder.yudao.module.bs.dal.mysql.feemanage.FeeManageMapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
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.FEE_MANAGE_NOT_EXISTS;
/**
* Service
*
* @author chenqp
*/
@Service
@Validated
public class FeeManageServiceImpl extends MPJBaseServiceImpl<FeeManageMapper, FeeManageDO> implements FeeManageService {
@Resource
private FeeManageMapper feeManageMapper;
@Override
public Long createFeeManage(FeeManageCreateReqVO createReqVO) {
// 插入
FeeManageDO feeManage = FeeManageConvert.INSTANCE.convert(createReqVO);
feeManageMapper.insert(feeManage);
// 返回
return feeManage.getId();
}
@Override
public void updateFeeManage(FeeManageUpdateReqVO updateReqVO) {
// 校验存在
validateFeeManageExists(updateReqVO.getId());
// 更新
FeeManageDO updateObj = FeeManageConvert.INSTANCE.convert(updateReqVO);
feeManageMapper.updateById(updateObj);
}
@Override
public void deleteFeeManage(Long id) {
// 校验存在
validateFeeManageExists(id);
// 删除
feeManageMapper.deleteById(id);
}
private void validateFeeManageExists(Long id) {
if (feeManageMapper.selectById(id) == null) {
throw exception(FEE_MANAGE_NOT_EXISTS);
}
}
@Override
public FeeManageDO getFeeManage(Long id) {
return feeManageMapper.selectById(id);
}
@Override
public List<FeeManageDO> getFeeManageList(Collection<Long> ids) {
return feeManageMapper.selectBatchIds(ids);
}
@Override
public PageResult<FeeManageDO> getFeeManagePage(FeeManagePageReqVO pageReqVO) {
return feeManageMapper.selectPage(pageReqVO);
}
@Override
public List<FeeManageDO> getFeeManageList(FeeManageExportReqVO exportReqVO) {
return feeManageMapper.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.budget.BudgetMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -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.feemanage.FeeManageMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,211 @@
package cn.iocoder.yudao.module.bs.service.budget;
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.budget.vo.BudgetCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
import cn.iocoder.yudao.module.bs.dal.mysql.budget.BudgetMapper;
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.BUDGET_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link BudgetServiceImpl}
*
* @author chenqp
*/
@Import(BudgetServiceImpl.class)
public class BudgetServiceImplTest extends BaseDbUnitTest {
@Resource
private BudgetServiceImpl budgetService;
@Resource
private BudgetMapper budgetMapper;
@Test
public void testCreateBudget_success() {
// 准备参数
BudgetCreateReqVO reqVO = randomPojo(BudgetCreateReqVO.class);
// 调用
Long budgetId = budgetService.createBudget(reqVO);
// 断言
assertNotNull(budgetId);
// 校验记录的属性是否正确
BudgetDO budget = budgetMapper.selectById(budgetId);
assertPojoEquals(reqVO, budget);
}
@Test
public void testUpdateBudget_success() {
// mock 数据
BudgetDO dbBudget = randomPojo(BudgetDO.class);
budgetMapper.insert(dbBudget);// @Sql: 先插入出一条存在的数据
// 准备参数
BudgetUpdateReqVO reqVO = randomPojo(BudgetUpdateReqVO.class, o -> {
o.setId(dbBudget.getId()); // 设置更新的 ID
});
// 调用
budgetService.updateBudget(reqVO);
// 校验是否更新正确
BudgetDO budget = budgetMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, budget);
}
@Test
public void testUpdateBudget_notExists() {
// 准备参数
BudgetUpdateReqVO reqVO = randomPojo(BudgetUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> budgetService.updateBudget(reqVO), BUDGET_NOT_EXISTS);
}
@Test
public void testDeleteBudget_success() {
// mock 数据
BudgetDO dbBudget = randomPojo(BudgetDO.class);
budgetMapper.insert(dbBudget);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbBudget.getId();
// 调用
budgetService.deleteBudget(id);
// 校验数据不存在了
assertNull(budgetMapper.selectById(id));
}
@Test
public void testDeleteBudget_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> budgetService.deleteBudget(id), BUDGET_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetBudgetPage() {
// mock 数据
BudgetDO dbBudget = randomPojo(BudgetDO.class, o -> { // 等会查询到
o.setBudgetYear(null);
o.setAmount(null);
o.setUsedAmount(null);
o.setOccupyAmount(null);
o.setRemainAmount(null);
o.setDeptId(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateTime(null);
});
budgetMapper.insert(dbBudget);
// 测试 budgetYear 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setBudgetYear(null)));
// 测试 amount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setAmount(null)));
// 测试 usedAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setUsedAmount(null)));
// 测试 occupyAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setOccupyAmount(null)));
// 测试 remainAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemainAmount(null)));
// 测试 deptId 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setDeptId(null)));
// 测试 remark 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemark(null)));
// 测试 files 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setFiles(null)));
// 测试 createTime 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setCreateTime(null)));
// 准备参数
BudgetPageReqVO reqVO = new BudgetPageReqVO();
reqVO.setBudgetYear(null);
reqVO.setAmount(null);
reqVO.setUsedAmount(null);
reqVO.setOccupyAmount(null);
reqVO.setRemainAmount(null);
reqVO.setDeptId(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<BudgetDO> pageResult = budgetService.getBudgetPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbBudget, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetBudgetList() {
// mock 数据
BudgetDO dbBudget = randomPojo(BudgetDO.class, o -> { // 等会查询到
o.setBudgetYear(null);
o.setAmount(null);
o.setUsedAmount(null);
o.setOccupyAmount(null);
o.setRemainAmount(null);
o.setDeptId(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateTime(null);
});
budgetMapper.insert(dbBudget);
// 测试 budgetYear 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setBudgetYear(null)));
// 测试 amount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setAmount(null)));
// 测试 usedAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setUsedAmount(null)));
// 测试 occupyAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setOccupyAmount(null)));
// 测试 remainAmount 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemainAmount(null)));
// 测试 deptId 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setDeptId(null)));
// 测试 remark 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemark(null)));
// 测试 files 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setFiles(null)));
// 测试 createTime 不匹配
budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setCreateTime(null)));
// 准备参数
BudgetExportReqVO reqVO = new BudgetExportReqVO();
reqVO.setBudgetYear(null);
reqVO.setAmount(null);
reqVO.setUsedAmount(null);
reqVO.setOccupyAmount(null);
reqVO.setRemainAmount(null);
reqVO.setDeptId(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<BudgetDO> list = budgetService.getBudgetList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbBudget, list.get(0));
}
}

@ -0,0 +1,195 @@
package cn.iocoder.yudao.module.bs.service.feemanage;
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.feemanage.vo.FeeManageCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManagePageReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateReqVO;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import cn.iocoder.yudao.module.bs.dal.mysql.feemanage.FeeManageMapper;
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.FEE_MANAGE_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link FeeManageServiceImpl}
*
* @author chenqp
*/
@Import(FeeManageServiceImpl.class)
public class FeeManageServiceImplTest extends BaseDbUnitTest {
@Resource
private FeeManageServiceImpl feeManageService;
@Resource
private FeeManageMapper feeManageMapper;
@Test
public void testCreateFeeManage_success() {
// 准备参数
FeeManageCreateReqVO reqVO = randomPojo(FeeManageCreateReqVO.class);
// 调用
Long feeManageId = feeManageService.createFeeManage(reqVO);
// 断言
assertNotNull(feeManageId);
// 校验记录的属性是否正确
FeeManageDO feeManage = feeManageMapper.selectById(feeManageId);
assertPojoEquals(reqVO, feeManage);
}
@Test
public void testUpdateFeeManage_success() {
// mock 数据
FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class);
feeManageMapper.insert(dbFeeManage);// @Sql: 先插入出一条存在的数据
// 准备参数
FeeManageUpdateReqVO reqVO = randomPojo(FeeManageUpdateReqVO.class, o -> {
o.setId(dbFeeManage.getId()); // 设置更新的 ID
});
// 调用
feeManageService.updateFeeManage(reqVO);
// 校验是否更新正确
FeeManageDO feeManage = feeManageMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, feeManage);
}
@Test
public void testUpdateFeeManage_notExists() {
// 准备参数
FeeManageUpdateReqVO reqVO = randomPojo(FeeManageUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> feeManageService.updateFeeManage(reqVO), FEE_MANAGE_NOT_EXISTS);
}
@Test
public void testDeleteFeeManage_success() {
// mock 数据
FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class);
feeManageMapper.insert(dbFeeManage);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbFeeManage.getId();
// 调用
feeManageService.deleteFeeManage(id);
// 校验数据不存在了
assertNull(feeManageMapper.selectById(id));
}
@Test
public void testDeleteFeeManage_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> feeManageService.deleteFeeManage(id), FEE_MANAGE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetFeeManagePage() {
// mock 数据
FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class, o -> { // 等会查询到
o.setDeptId(null);
o.setRoleIds(null);
o.setAmount(null);
o.setArea(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateTime(null);
});
feeManageMapper.insert(dbFeeManage);
// 测试 deptId 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setDeptId(null)));
// 测试 roleIds 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRoleIds(null)));
// 测试 amount 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setAmount(null)));
// 测试 area 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setArea(null)));
// 测试 remark 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRemark(null)));
// 测试 files 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setFiles(null)));
// 测试 createTime 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setCreateTime(null)));
// 准备参数
FeeManagePageReqVO reqVO = new FeeManagePageReqVO();
reqVO.setDeptId(null);
reqVO.setRoleIds(null);
reqVO.setAmount(null);
reqVO.setArea(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<FeeManageDO> pageResult = feeManageService.getFeeManagePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbFeeManage, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetFeeManageList() {
// mock 数据
FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class, o -> { // 等会查询到
o.setDeptId(null);
o.setRoleIds(null);
o.setAmount(null);
o.setArea(null);
o.setRemark(null);
o.setFiles(null);
o.setCreateTime(null);
});
feeManageMapper.insert(dbFeeManage);
// 测试 deptId 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setDeptId(null)));
// 测试 roleIds 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRoleIds(null)));
// 测试 amount 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setAmount(null)));
// 测试 area 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setArea(null)));
// 测试 remark 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRemark(null)));
// 测试 files 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setFiles(null)));
// 测试 createTime 不匹配
feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setCreateTime(null)));
// 准备参数
FeeManageExportReqVO reqVO = new FeeManageExportReqVO();
reqVO.setDeptId(null);
reqVO.setRoleIds(null);
reqVO.setAmount(null);
reqVO.setArea(null);
reqVO.setRemark(null);
reqVO.setFiles(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<FeeManageDO> list = feeManageService.getFeeManageList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbFeeManage, list.get(0));
}
}
Loading…
Cancel
Save