fix: 导入账单无法下载模板;查询账单添加多个类别查询

This commit is contained in:
Bunny 2024-12-27 15:57:04 +08:00
parent a09399b12d
commit cd35da82a0
10 changed files with 61 additions and 29 deletions

View File

@ -9,6 +9,7 @@ import lombok.NoArgsConstructor;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -23,6 +24,9 @@ public class BillDto {
@Schema(name = "amount", title = "金额") @Schema(name = "amount", title = "金额")
private BigDecimal amount; private BigDecimal amount;
@Schema(name = "categoryIds", title = "类别分类")
private List<Long> categoryIds;
@Schema(name = "username", title = "类型1 - 收入,-1 - 支出") @Schema(name = "username", title = "类型1 - 收入,-1 - 支出")
private Byte type; private Byte type;

View File

@ -32,4 +32,5 @@ public class IncomeExpenseQueryDto {
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd") @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
@NotNull(message = "日期不能为空") @NotNull(message = "日期不能为空")
private LocalDate endDate; private LocalDate endDate;
} }

View File

@ -37,6 +37,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- admin 依赖 --> <!-- admin 依赖 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -1,6 +1,5 @@
package cn.bunny.services.factory; package cn.bunny.services.factory;
import cn.bunny.common.service.exception.AuthCustomerException;
import cn.bunny.dao.dto.financial.bill.BillDto; import cn.bunny.dao.dto.financial.bill.BillDto;
import cn.bunny.dao.dto.financial.bill.IncomeExpenseQueryDto; import cn.bunny.dao.dto.financial.bill.IncomeExpenseQueryDto;
import cn.bunny.dao.dto.financial.bill.excel.BillExportDto; import cn.bunny.dao.dto.financial.bill.excel.BillExportDto;
@ -9,7 +8,6 @@ import cn.bunny.dao.entity.system.EmailTemplate;
import cn.bunny.dao.excel.BillExportExcelByUser; import cn.bunny.dao.excel.BillExportExcelByUser;
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant; import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
import cn.bunny.dao.pojo.enums.EmailTemplateEnums; import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.financial.admin.BillVo; import cn.bunny.dao.vo.financial.admin.BillVo;
import cn.bunny.dao.vo.financial.user.expendAndIncome.ExpendWithIncome; import cn.bunny.dao.vo.financial.user.expendAndIncome.ExpendWithIncome;
import cn.bunny.services.mapper.email.EmailTemplateMapper; import cn.bunny.services.mapper.email.EmailTemplateMapper;
@ -22,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -34,7 +33,6 @@ import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -93,10 +91,10 @@ public class BillFactory {
}).toList(); }).toList();
// 查找模板文件 // 查找模板文件
String filenameTemplate = Objects.requireNonNull(getClass().getResource("/static/bill-template.xlsx")).getFile(); // InputStream filenameTemplate = getClass().getClassLoader().getResourceAsStream("static/bill-template.xlsx");
if (filenameTemplate == null) throw new AuthCustomerException(ResultCodeEnum.MISSING_TEMPLATE_FILES); ClassPathResource classPathResource = new ClassPathResource("static/bill-template.xlsx");
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(filenameTemplate).build()) { try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(classPathResource.getInputStream()).build()) {
// 填充数据 // 填充数据
WriteSheet writeSheet = EasyExcel.writerSheet().build(); WriteSheet writeSheet = EasyExcel.writerSheet().build();
excelWriter.fill(excelList, writeSheet); excelWriter.fill(excelList, writeSheet);

View File

@ -76,8 +76,10 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
@Autowired @Autowired
private MessageReceivedMapper messageReceivedMapper; private MessageReceivedMapper messageReceivedMapper;
@Autowired @Autowired
private UserMapper userMapper; private UserMapper userMapper;
@Autowired @Autowired
private EmailTemplateMapper emailTemplateMapper; private EmailTemplateMapper emailTemplateMapper;

View File

@ -33,6 +33,7 @@ import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -45,7 +46,6 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
/** /**
@ -303,6 +303,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
/** /**
* 获取添加账单模板文件 * 获取添加账单模板文件
*/ */
@SneakyThrows
@Override @Override
public void getAddBillTemplate(HttpServletResponse response) { public void getAddBillTemplate(HttpServletResponse response) {
// 设置数据库查询时间 // 设置数据库查询时间
@ -312,10 +313,11 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
LambdaQueryWrapper<Category> queryWrapper = Wrappers.<Category>lambdaQuery().eq(Category::getUserId, userId).or().eq(Category::getIsBuiltin, true); LambdaQueryWrapper<Category> queryWrapper = Wrappers.<Category>lambdaQuery().eq(Category::getUserId, userId).or().eq(Category::getIsBuiltin, true);
List<Category> categoryList = categoryMapper.selectList(queryWrapper); List<Category> categoryList = categoryMapper.selectList(queryWrapper);
String filenameTemplate = Objects.requireNonNull(getClass().getResource("/static/bill-add-template.xlsx")).getFile(); // 从本地文件找到添加模板
if (filenameTemplate == null) throw new AuthCustomerException(ResultCodeEnum.MISSING_TEMPLATE_FILES); // InputStream filenameTemplate = getClass().getClassLoader().getResourceAsStream("static/bill-add-template.xlsx");
ClassPathResource classPathResource = new ClassPathResource("static/bill-add-template.xlsx");
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(filenameTemplate).build()) { try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(classPathResource.getInputStream()).build()) {
// 填充数据类型数据要填充的在第二个sheet // 填充数据类型数据要填充的在第二个sheet
WriteSheet writeSheet = EasyExcel.writerSheet(1).build(); WriteSheet writeSheet = EasyExcel.writerSheet(1).build();
excelWriter.fill(categoryList, writeSheet); excelWriter.fill(categoryList, writeSheet);

View File

@ -16,20 +16,29 @@ logging:
bunny: bunny:
master: master:
host: 192.168.3.129 host: 192.168.3.130
port: 3304 port: 3306
database: family_financial database: family_financial
username: root username: root
password: "02120212" password: "123456"
mongodb:
database: financial
host: 192.168.3.130
port: 27017
username: admin
password: "123456"
authentication-database: admin
additional-hosts: 192.168.3.130
redis: redis:
host: 192.168.3.129 host: 192.168.3.130
port: 6379 port: 6379
database: 6 database: 0
password: "123456" password: "123456"
minio: minio:
endpointUrl: "http://192.168.3.129:9000" endpointUrl: "http://192.168.3.130:9000"
accessKey: bunny accessKey: bunny
secretKey: "02120212" secretKey: "02120212"
bucket-name: financial bucket-name: financial

View File

@ -29,6 +29,15 @@ bunny:
username: family_financial_prod username: family_financial_prod
password: 0212family_financial password: 0212family_financial
mongodb:
database: financial
host: 111.229.137.235
port: 27017
username: admin
password: "02120212"
authentication-database: admin
additional-hosts: 111.229.137.235
redis: redis:
host: 47.120.65.66 host: 47.120.65.66
port: 6379 port: 6379

View File

@ -16,21 +16,17 @@ spring:
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: ${bunny.master.username} username: ${bunny.master.username}
password: ${bunny.master.password} password: ${bunny.master.password}
# dynamic:
# primary: master #设置默认的数据源或者数据源组,默认值即为master
# strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
# grace-destroy: false #是否优雅关闭数据源默认为false设置为true时关闭数据源时如果数据源中还存在活跃连接至多等待10s后强制关闭
# datasource:
# master:
# type: com.zaxxer.hikari.HikariDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
# username: ${bunny.master.username}
# password: ${bunny.master.password}
# aop:
# enabled: true
data: data:
mongodb:
database: ${bunny.mongodb.database}
host: ${bunny.mongodb.host}
port: ${bunny.mongodb.port}
username: ${bunny.mongodb.username}
password: ${bunny.mongodb.password}
authentication-database: ${bunny.mongodb.authentication-database}
additional-hosts: ${bunny.mongodb.additional-hosts}
redis: redis:
host: ${bunny.redis.host} host: ${bunny.redis.host}
port: ${bunny.redis.port} port: ${bunny.redis.port}

View File

@ -41,6 +41,12 @@
<if test="dto.userId != null and dto.userId != ''"> <if test="dto.userId != null and dto.userId != ''">
and base.user_id = #{dto.userId} and base.user_id = #{dto.userId}
</if> </if>
<if test="dto.categoryIds != null">
and base.category_id in
<foreach collection="dto.categoryIds" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
<if test="dto.type != null and dto.type != ''"> <if test="dto.type != null and dto.type != ''">
and base.type = #{dto.type} and base.type = #{dto.type}
</if> </if>