feat: 预算分类完成

This commit is contained in:
Bunny 2024-11-14 12:01:22 +08:00
parent 25c1f5095d
commit f7677c8bc1
16 changed files with 421 additions and 44 deletions

View File

@ -3,11 +3,11 @@ package cn.bunny.common.generator.generator;
import cn.bunny.common.generator.entity.BaseField; import cn.bunny.common.generator.entity.BaseField;
import cn.bunny.common.generator.entity.BaseResultMap; import cn.bunny.common.generator.entity.BaseResultMap;
import cn.bunny.common.generator.utils.GeneratorCodeUtils; import cn.bunny.common.generator.utils.GeneratorCodeUtils;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalAddDto; import cn.bunny.dao.dto.financial.bill.admin.BillAddDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalDto; import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalUpdateDto; import cn.bunny.dao.dto.financial.bill.admin.BillUpdateDto;
import cn.bunny.dao.entity.financial.SavingGoal; import cn.bunny.dao.entity.financial.Bill;
import cn.bunny.dao.vo.financial.admin.SavingGoalVo; import cn.bunny.dao.vo.financial.admin.BillVo;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -36,8 +36,7 @@ import java.util.stream.Stream;
@Service @Service
public class WebGeneratorCode { public class WebGeneratorCode {
// 公共路径 // 公共路径
// public static String commonPath = "D:\\Project\\web\\PC\\financial\\financial-web\\src"; public static String commonPath = "D:\\Project\\web\\PC\\finance\\financial-admin\\src";
public static String commonPath = "D:\\MyFolder\\auth\\financial-web\\src";
// 生成API请求路径 // 生成API请求路径
public static String apiPath = commonPath + "\\api\\v1\\financial\\"; public static String apiPath = commonPath + "\\api\\v1\\financial\\";
// 生成vue路径 // 生成vue路径
@ -45,18 +44,18 @@ public class WebGeneratorCode {
// 生成仓库路径 // 生成仓库路径
public static String storePath = commonPath + "\\store\\financial\\"; public static String storePath = commonPath + "\\store\\financial\\";
// 后端controller // 后端controller
public static String controllerPath = "D:\\MyFolder\\auth\\financial-web-server\\service\\src\\main\\java\\cn\\bunny\\services\\controller\\financial\\"; public static String controllerPath = "D:\\Project\\web\\PC\\finance\\financia-admin-server\\service\\src\\main\\java\\cn\\bunny\\services\\controller\\financial\\";
public static String servicePath = "D:\\MyFolder\\auth\\financial-web-server\\service\\src\\main\\java\\cn\\bunny\\services\\service\\financial\\"; public static String servicePath = "D:\\Project\\web\\PC\\finance\\financia-admin-server\\service\\src\\main\\java\\cn\\bunny\\services\\service\\financial\\";
public static String serviceImplPath = "D:\\MyFolder\\auth\\financial-web-server\\service\\src\\main\\java\\cn\\bunny\\services\\service\\financial\\impl\\"; public static String serviceImplPath = "D:\\Project\\web\\PC\\finance\\financia-admin-server\\service\\src\\main\\java\\cn\\bunny\\services\\service\\financial\\impl\\";
public static String mapperPath = "D:\\MyFolder\\auth\\financial-web-server\\service\\src\\main\\java\\cn\\bunny\\services\\mapper\\financial\\"; public static String mapperPath = "D:\\Project\\web\\PC\\finance\\financia-admin-server\\service\\src\\main\\java\\cn\\bunny\\services\\mapper\\financial\\";
public static String resourceMapperPath = "D:\\MyFolder\\auth\\financial-web-server\\service\\src\\main\\resources\\mapper\\financial\\"; public static String resourceMapperPath = "D:\\Project\\web\\PC\\finance\\financia-admin-server\\service\\src\\main\\resources\\mapper\\financial\\";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Class<?> originalClass = SavingGoal.class; Class<?> originalClass = Bill.class;
Class<?> dtoClass = SavingGoalDto.class; Class<?> dtoClass = BillDto.class;
Class<?> addDtoClass = SavingGoalAddDto.class; Class<?> addDtoClass = BillAddDto.class;
Class<?> updateDtoClass = SavingGoalUpdateDto.class; Class<?> updateDtoClass = BillUpdateDto.class;
Class<?> voClass = SavingGoalVo.class; Class<?> voClass = BillVo.class;
// 设置velocity资源加载器 // 设置velocity资源加载器
Properties prop = new Properties(); Properties prop = new Properties();

View File

@ -0,0 +1,50 @@
package cn.bunny.dao.dto.financial.bill.admin;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "BillAddDto对象", title = "账单信息添加内容", description = "账单信息添加内容")
public class BillAddDto {
@Schema(name = "userId", title = "绑定的用户id")
@NotNull(message = "债绑定的用户不能为空")
private Long userId;
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
@NotNull(message = "类型不能为空")
@Min(value = -1, message = "类型格式不正确")
@Max(value = 1, message = "类型格式不正确")
private Byte type;
@Schema(name = "amount", title = "金额")
@NotNull(message = "金额不能为空")
@Min(value = 0, message = "金额格式不正确")
private BigDecimal amount;
@Schema(name = "description", title = "描述")
private String description;
@Schema(name = "transactionDate", title = "交易日期")
@NotNull(message = "交易日期不能为空")
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime transactionDate;
@Schema(name = "categoryId", title = "类别id")
@NotNull(message = "类别id不能为空")
private Long categoryId;
}

View File

@ -0,0 +1,36 @@
package cn.bunny.dao.dto.financial.bill.admin;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "BillDto对象", title = "账单信息查询内容", description = "账单信息查询内容")
public class BillDto {
@Schema(name = "userId", title = "绑定的用户id")
private Long userId;
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
private Byte type;
@Schema(name = "description", title = "描述")
private String description;
@Schema(name = "startDate", title = "开始交易日期")
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
private LocalDate startDate;
@Schema(name = "endDate", title = "结束交易日期")
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
private LocalDate endDate;
}

View File

@ -0,0 +1,45 @@
package cn.bunny.dao.dto.financial.bill.admin;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "BillUpdateDto对象", title = "账单信息更新内容", description = "账单信息更新内容")
public class BillUpdateDto {
@Schema(name = "id", title = "主键")
@NotNull(message = "id不能为空")
private Long id;
@Schema(name = "userId", title = "绑定的用户id")
@NotNull(message = "债绑定的用户不能为空")
private Long userId;
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
private Byte type;
@Schema(name = "amount", title = "金额")
private BigDecimal amount;
@Schema(name = "description", title = "描述")
private String description;
@Schema(name = "transactionDate", title = "交易日期")
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime transactionDate;
@Schema(name = "categoryId", title = "类别id")
private Long categoryId;
}

View File

@ -17,7 +17,7 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder @Builder
@Schema(name = "BillAddDto对象", title = "账单信息添加内容", description = "账单信息添加内容") @Schema(name = "BillUserAddDto对象", title = "用户账单信息添加内容", description = "用户账单信息添加内容")
public class BillUserAddDto { public class BillUserAddDto {
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出") @Schema(name = "username", title = "类型1 - 收入,-1 - 支出")

View File

@ -13,7 +13,7 @@ import java.time.LocalDate;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder @Builder
@Schema(name = "BillDto对象", title = "账单信息查询内容", description = "账单信息查询内容") @Schema(name = "BillUserDto对象", title = "用户账单信息查询内容", description = "用户账单信息查询内容")
public class BillUserDto { public class BillUserDto {
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出") @Schema(name = "username", title = "类型1 - 收入,-1 - 支出")

View File

@ -15,7 +15,7 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder @Builder
@Schema(name = "BillUpdateDto对象", title = "账单信息更新内容", description = "账单信息更新内容") @Schema(name = "BillUserUpdateDto对象", title = "用户账单信息更新内容", description = "用户账单信息更新内容")
public class BillUserUpdateDto { public class BillUserUpdateDto {
@Schema(name = "id", title = "主键") @Schema(name = "id", title = "主键")

View File

@ -28,6 +28,9 @@ public class Bill extends BaseEntity {
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出") @Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
private Byte type; private Byte type;
@Schema(name = "userId", title = "绑定的用户id")
private Long userId;
@Schema(name = "amount", title = "金额") @Schema(name = "amount", title = "金额")
private BigDecimal amount; private BigDecimal amount;

View File

@ -0,0 +1,56 @@
package cn.bunny.dao.vo.financial.admin;
import cn.bunny.dao.common.vo.BaseUserVo;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "BillVo对象", title = "账单信息返回内容", description = "账单信息返回内容")
public class BillVo extends BaseUserVo {
@Schema(name = "userId", title = "绑定的用户id")
@JsonFormat(shape = JsonFormat.Shape.STRING)
@JSONField(serializeUsing = ToStringSerializer.class)
private Long userId;
@Schema(name = "username", title = "用户名")
private String username;
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
private Byte type;
@Schema(name = "amount", title = "金额")
private BigDecimal amount;
@Schema(name = "description", title = "描述")
private String description;
@Schema(name = "transactionDate", title = "交易日期")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime transactionDate;
@Schema(name = "categoryId", title = "分类Id")
@JsonFormat(shape = JsonFormat.Shape.STRING)
@JSONField(serializeUsing = ToStringSerializer.class)
private String categoryId;
@Schema(name = "categoryName", title = "类别分类")
private String categoryName;
}

View File

@ -19,7 +19,7 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder @Builder
@Schema(name = "BillVo对象", title = "账单信息返回内容", description = "账单信息返回内容") @Schema(name = "BillUserVo对象", title = "用户账单信息返回内容", description = "用户账单信息返回内容")
public class BillUserVo extends BaseVo { public class BillUserVo extends BaseVo {
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出") @Schema(name = "username", title = "类型1 - 收入,-1 - 支出")

View File

@ -1,5 +1,8 @@
package cn.bunny.services.controller.financial; package cn.bunny.services.controller.financial;
import cn.bunny.dao.dto.financial.bill.admin.BillAddDto;
import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.bill.admin.BillUpdateDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto; import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserDto; import cn.bunny.dao.dto.financial.bill.user.BillUserDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto; import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto;
@ -7,6 +10,7 @@ import cn.bunny.dao.entity.financial.Bill;
import cn.bunny.dao.pojo.result.PageResult; import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.Result; import cn.bunny.dao.pojo.result.Result;
import cn.bunny.dao.pojo.result.ResultCodeEnum; import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.financial.admin.BillVo;
import cn.bunny.dao.vo.financial.user.BillUserVo; import cn.bunny.dao.vo.financial.user.BillUserVo;
import cn.bunny.services.service.financial.BillService; import cn.bunny.services.service.financial.BillService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -36,35 +40,69 @@ public class BillController {
@Autowired @Autowired
private BillService billService; private BillService billService;
@Operation(summary = "分页查询账单信息", description = "分页查询账单信息") @Operation(summary = "用户分页查询账单信息", description = "用户分页查询账单信息")
@GetMapping("noManage/getUserBillList/{page}/{limit}") @GetMapping("noManage/getUserBillList/{page}/{limit}")
public Mono<Result<PageResult<BillUserVo>>> getBillList( public Mono<Result<PageResult<BillUserVo>>> getUserBillList(
@Parameter(name = "page", description = "当前页", required = true) @Parameter(name = "page", description = "当前页", required = true)
@PathVariable("page") Integer page, @PathVariable("page") Integer page,
@Parameter(name = "limit", description = "每页记录数", required = true) @Parameter(name = "limit", description = "每页记录数", required = true)
@PathVariable("limit") Integer limit, @PathVariable("limit") Integer limit,
BillUserDto dto) { BillUserDto dto) {
Page<Bill> pageParams = new Page<>(page, limit); Page<Bill> pageParams = new Page<>(page, limit);
PageResult<BillUserVo> pageResult = billService.getBillList(pageParams, dto); PageResult<BillUserVo> pageResult = billService.getUserBillList(pageParams, dto);
return Mono.just(Result.success(pageResult));
}
@Operation(summary = "用户添加账单信息", description = "用户添加账单信息")
@PostMapping("noManage/addUserBill")
public Mono<Result<String>> addUserBill(@Valid @RequestBody BillUserAddDto dto) {
billService.addUserBill(dto);
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
}
@Operation(summary = "用户更新账单信息", description = "用户更新账单信息")
@PutMapping("noManage/updateUserBill")
public Mono<Result<String>> updateUserBill(@Valid @RequestBody BillUserUpdateDto dto) {
billService.updateUserBill(dto);
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
}
@Operation(summary = "用户删除账单信息", description = "用户删除账单信息")
@DeleteMapping("noManage/deleteUserBill")
public Mono<Result<String>> deleteUserBill(@RequestBody List<Long> ids) {
billService.deleteUserBill(ids);
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
}
@Operation(summary = "分页查询账单信息", description = "分页查询账单信息")
@GetMapping("getBillList/{page}/{limit}")
public Mono<Result<PageResult<BillVo>>> getBillList(
@Parameter(name = "page", description = "当前页", required = true)
@PathVariable("page") Integer page,
@Parameter(name = "limit", description = "每页记录数", required = true)
@PathVariable("limit") Integer limit,
BillDto dto) {
Page<Bill> pageParams = new Page<>(page, limit);
PageResult<BillVo> pageResult = billService.getBillList(pageParams, dto);
return Mono.just(Result.success(pageResult)); return Mono.just(Result.success(pageResult));
} }
@Operation(summary = "添加账单信息", description = "添加账单信息") @Operation(summary = "添加账单信息", description = "添加账单信息")
@PostMapping("noManage/addUserBill") @PostMapping("addBill")
public Mono<Result<String>> addBill(@Valid @RequestBody BillUserAddDto dto) { public Mono<Result<String>> addBill(@Valid @RequestBody BillAddDto dto) {
billService.addBill(dto); billService.addBill(dto);
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS)); return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
} }
@Operation(summary = "更新账单信息", description = "更新账单信息") @Operation(summary = "更新账单信息", description = "更新账单信息")
@PutMapping("noManage/updateUserBill") @PutMapping("updateBill")
public Mono<Result<String>> updateBill(@Valid @RequestBody BillUserUpdateDto dto) { public Mono<Result<String>> updateBill(@Valid @RequestBody BillUpdateDto dto) {
billService.updateBill(dto); billService.updateBill(dto);
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS)); return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
} }
@Operation(summary = "删除账单信息", description = "删除账单信息") @Operation(summary = "删除账单信息", description = "删除账单信息")
@DeleteMapping("noManage/deleteUserBill") @DeleteMapping("deleteBill")
public Mono<Result<String>> deleteBill(@RequestBody List<Long> ids) { public Mono<Result<String>> deleteBill(@RequestBody List<Long> ids) {
billService.deleteBill(ids); billService.deleteBill(ids);
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS)); return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));

View File

@ -1,4 +1,4 @@
package cn.bunny.services.controller; package cn.bunny.services.controller.financial;
import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanAddDto; import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanAddDto;
import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanDto; import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanDto;

View File

@ -1,7 +1,9 @@
package cn.bunny.services.mapper.financial; package cn.bunny.services.mapper.financial;
import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserDto; import cn.bunny.dao.dto.financial.bill.user.BillUserDto;
import cn.bunny.dao.entity.financial.Bill; import cn.bunny.dao.entity.financial.Bill;
import cn.bunny.dao.vo.financial.admin.BillVo;
import cn.bunny.dao.vo.financial.user.BillUserVo; import cn.bunny.dao.vo.financial.user.BillUserVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -23,13 +25,13 @@ import java.util.List;
public interface BillMapper extends BaseMapper<Bill> { public interface BillMapper extends BaseMapper<Bill> {
/** /**
* * 分页查询账单信息内容 * * 分页查询用户账单信息内容
* *
* @param pageParams 账单信息分页参数 * @param pageParams 账单信息分页参数
* @param dto 账单信息查询表单 * @param dto 账单信息查询表单
* @return 账单信息分页结果 * @return 账单信息分页结果
*/ */
IPage<BillUserVo> selectListByPage(@Param("page") Page<Bill> pageParams, @Param("dto") BillUserDto dto, @Param("userId") Long userId); IPage<BillUserVo> selectUserListByPage(@Param("page") Page<Bill> pageParams, @Param("dto") BillUserDto dto, @Param("userId") Long userId);
/** /**
* 物理删除账单信息 * 物理删除账单信息
@ -37,4 +39,13 @@ public interface BillMapper extends BaseMapper<Bill> {
* @param ids 删除 id 列表 * @param ids 删除 id 列表
*/ */
void deleteBatchIdsWithPhysics(List<Long> ids); void deleteBatchIdsWithPhysics(List<Long> ids);
/**
* * 分页查询账单信息内容
*
* @param pageParams 账单信息分页参数
* @param dto 账单信息查询表单
* @return 账单信息分页结果
*/
IPage<BillVo> selectListByPage(@Param("page") Page<Bill> pageParams, @Param("dto") BillDto dto);
} }

View File

@ -1,10 +1,14 @@
package cn.bunny.services.service.financial; package cn.bunny.services.service.financial;
import cn.bunny.dao.dto.financial.bill.admin.BillAddDto;
import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.bill.admin.BillUpdateDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto; import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserDto; import cn.bunny.dao.dto.financial.bill.user.BillUserDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto; import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto;
import cn.bunny.dao.entity.financial.Bill; import cn.bunny.dao.entity.financial.Bill;
import cn.bunny.dao.pojo.result.PageResult; import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.financial.admin.BillVo;
import cn.bunny.dao.vo.financial.user.BillUserVo; import cn.bunny.dao.vo.financial.user.BillUserVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
@ -27,26 +31,54 @@ public interface BillService extends IService<Bill> {
* *
* @return 账单信息返回列表 * @return 账单信息返回列表
*/ */
PageResult<BillUserVo> getBillList(Page<Bill> pageParams, BillUserDto dto); PageResult<BillUserVo> getUserBillList(Page<Bill> pageParams, BillUserDto dto);
/** /**
* * 添加账单信息 * * 添加账单信息
* *
* @param dto 添加表单 * @param dto 添加表单
*/ */
void addBill(@Valid BillUserAddDto dto); void addUserBill(@Valid BillUserAddDto dto);
/** /**
* * 更新账单信息 * * 更新账单信息
* *
* @param dto 更新表单 * @param dto 更新表单
*/ */
void updateBill(@Valid BillUserUpdateDto dto); void updateUserBill(@Valid BillUserUpdateDto dto);
/** /**
* * 删除|批量删除账单信息类型 * * 删除|批量删除账单信息类型
* *
* @param ids 删除id列表 * @param ids 删除id列表
*/ */
void deleteUserBill(List<Long> ids);
/**
* 分页查询账单信息
*
* @return 账单信息返回列表
*/
PageResult<BillVo> getBillList(Page<Bill> pageParams, BillDto dto);
/**
* 添加账单信息
*
* @param dto 添加表单
*/
void addBill(BillAddDto dto);
/**
* 更新账单信息
*
* @param dto 更新表单
*/
void updateBill(BillUpdateDto dto);
/**
* 删除账单信息
*
* @param ids 删除的ids
*/
void deleteBill(List<Long> ids); void deleteBill(List<Long> ids);
} }

View File

@ -1,15 +1,22 @@
package cn.bunny.services.service.financial.impl; package cn.bunny.services.service.financial.impl;
import cn.bunny.common.service.context.BaseContext; import cn.bunny.common.service.context.BaseContext;
import cn.bunny.common.service.exception.BunnyException;
import cn.bunny.dao.dto.financial.bill.admin.BillAddDto;
import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.bill.admin.BillUpdateDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto; import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserDto; import cn.bunny.dao.dto.financial.bill.user.BillUserDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto; import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto;
import cn.bunny.dao.entity.financial.Bill; import cn.bunny.dao.entity.financial.Bill;
import cn.bunny.dao.pojo.result.PageResult; import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.financial.admin.BillVo;
import cn.bunny.dao.vo.financial.user.BillUserVo; import cn.bunny.dao.vo.financial.user.BillUserVo;
import cn.bunny.services.mapper.financial.BillMapper; import cn.bunny.services.mapper.financial.BillMapper;
import cn.bunny.services.service.financial.BillService; import cn.bunny.services.service.financial.BillService;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -37,12 +44,12 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
* @return 查询分页账单信息返回对象 * @return 查询分页账单信息返回对象
*/ */
@Override @Override
public PageResult<BillUserVo> getBillList(Page<Bill> pageParams, BillUserDto dto) { public PageResult<BillUserVo> getUserBillList(Page<Bill> pageParams, BillUserDto dto) {
// 需要根据当前用户去查询 // 需要根据当前用户去查询
Long userId = BaseContext.getUserId(); Long userId = BaseContext.getUserId();
// 判断创建用户的Id是否和当前请求的用户id是否相同 // 判断创建用户的Id是否和当前请求的用户id是否相同
IPage<BillUserVo> page = baseMapper.selectListByPage(pageParams, dto, userId); IPage<BillUserVo> page = baseMapper.selectUserListByPage(pageParams, dto, userId);
return PageResult.<BillUserVo>builder() return PageResult.<BillUserVo>builder()
.list(page.getRecords()) .list(page.getRecords())
@ -58,10 +65,13 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
* @param dto 账单信息添加 * @param dto 账单信息添加
*/ */
@Override @Override
public void addBill(@Valid BillUserAddDto dto) { public void addUserBill(@Valid BillUserAddDto dto) {
// 保存数据 // 保存数据
Bill bill = new Bill(); Bill bill = new Bill();
BeanUtils.copyProperties(dto, bill); BeanUtils.copyProperties(dto, bill);
// 设置当前的用户Id
bill.setUserId(BaseContext.getUserId());
save(bill); save(bill);
} }
@ -71,9 +81,15 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
* @param dto 账单信息更新 * @param dto 账单信息更新
*/ */
@Override @Override
public void updateBill(@Valid BillUserUpdateDto dto) { public void updateUserBill(@Valid BillUserUpdateDto dto) {
// 判断当前用户修改的内容是否是自己的内容
Bill bill = getOne(Wrappers.<Bill>lambdaQuery().eq(Bill::getId, dto.getId()));
if (!bill.getUserId().equals(BaseContext.getUserId())) {
throw new BunnyException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
}
// 更新内容 // 更新内容
Bill bill = new Bill(); bill = new Bill();
BeanUtils.copyProperties(dto, bill); BeanUtils.copyProperties(dto, bill);
updateById(bill); updateById(bill);
} }
@ -84,6 +100,66 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
* @param ids 删除id列表 * @param ids 删除id列表
*/ */
@Override @Override
public void deleteUserBill(List<Long> ids) {
// 判断删除的是否是自己的账单
List<Bill> billList = list(Wrappers.<Bill>lambdaQuery().in(Bill::getId, ids))
.stream().filter(bill -> !bill.getUserId().equals(BaseContext.getUserId())).toList();
if (!billList.isEmpty()) {
throw new BunnyException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
}
baseMapper.deleteBatchIdsWithPhysics(ids);
}
/**
* 分页查询账单信息
*
* @return 账单信息返回列表
*/
@Override
public PageResult<BillVo> getBillList(Page<Bill> pageParams, BillDto dto) {
// 判断创建用户的Id是否和当前请求的用户id是否相同
IPage<BillVo> page = baseMapper.selectListByPage(pageParams, dto);
return PageResult.<BillVo>builder()
.list(page.getRecords())
.pageNo(page.getCurrent())
.pageSize(page.getSize())
.total(page.getTotal())
.build();
}
/**
* 添加账单信息
*
* @param dto 添加表单
*/
@Override
public void addBill(BillAddDto dto) {
// 保存数据
Bill bill = new Bill();
BeanUtils.copyProperties(dto, bill);
save(bill);
}
/**
* 更新账单信息
*
* @param dto 更新表单
*/
@Override
public void updateBill(BillUpdateDto dto) {
// 更新内容
Bill bill = new Bill();
BeanUtils.copyProperties(dto, bill);
updateById(bill);
}
/**
* 删除账单信息
*
* @param ids 删除的ids
*/
@Override
public void deleteBill(List<Long> ids) { public void deleteBill(List<Long> ids) {
baseMapper.deleteBatchIdsWithPhysics(ids); baseMapper.deleteBatchIdsWithPhysics(ids);
} }

View File

@ -22,8 +22,8 @@
id, create_time, update_time, create_user, update_user, is_deleted, type, amount, description, transaction_date, category_id id, create_time, update_time, create_user, update_user, is_deleted, type, amount, description, transaction_date, category_id
</sql> </sql>
<!-- 分页查询账单信息内容 --> <!-- 分页查询用户账单信息内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.vo.financial.user.BillUserVo"> <select id="selectUserListByPage" resultType="cn.bunny.dao.vo.financial.user.BillUserVo">
select select
base.*, base.*,
category.category_name, category.category_name,
@ -35,9 +35,40 @@
left join sys_user create_user on create_user.id = base.create_user left join sys_user create_user on create_user.id = base.create_user
left join sys_user update_user on update_user.id = base.update_user left join sys_user update_user on update_user.id = base.update_user
<where> <where>
base.is_deleted = 0 and base.create_user = #{userId} base.is_deleted = 0 and base.user_id = #{userId}
<if test="dto.type != null and dto.type != ''"> <if test="dto.type != null and dto.type != ''">
and base.type like CONCAT('%',#{dto.type},'%') and base.type = #{dto.type}
</if>
<if test="dto.description != null and dto.description != ''">
and base.description like CONCAT('%',#{dto.description},'%')
</if>
<if test="dto.startDate != null and dto.endDate != null">
and base.transaction_date between #{dto.startDate} and #{dto.endDate}
</if>
</where>
</select>
<!-- 分页查询账单信息内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.vo.financial.admin.BillVo">
select
base.*,
category.category_name,
category.id as category_id,
baseuser.username as username,
create_user.username as create_username,
update_user.username as update_username
from t_bill base
left join t_category category on category.id = base.category_id
left join sys_user baseuser on baseuser.id = base.user_id
left join sys_user create_user on create_user.id = base.create_user
left join sys_user update_user on update_user.id = base.update_user
<where>
base.is_deleted = 0
<if test="dto.userId != null and dto.userId != ''">
and base.user_id = #{dto.userId}
</if>
<if test="dto.type != null and dto.type != ''">
and base.type = #{dto.type}
</if> </if>
<if test="dto.description != null and dto.description != ''"> <if test="dto.description != null and dto.description != ''">
and base.description like CONCAT('%',#{dto.description},'%') and base.description like CONCAT('%',#{dto.description},'%')