feat:增加账单搜索接口
This commit is contained in:
@@ -9,6 +9,7 @@ import com.cxx.home.dto.bill.BillRecordDto;
|
||||
import com.cxx.home.dto.bill.BillSummaryDto;
|
||||
import com.cxx.home.service.BillRecordService;
|
||||
import com.cxx.home.vo.BillQueryVo;
|
||||
import com.cxx.home.vo.BillSearchVo;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -55,6 +56,12 @@ public class BillController {
|
||||
return billRecordService.queryBillSummary(billQueryVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "搜索账单概要")
|
||||
@GetMapping("/search")
|
||||
public @JsonView(ReadView.class) List<BillSummaryDto> searchBillSummary(BillSearchVo billSearchVo) {
|
||||
return billRecordService.searchBillSummary(billSearchVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询账单统计")
|
||||
@GetMapping("/stats/{type}")
|
||||
public List<StatsChartDto> queryBillStats(@PathVariable("type") String type, BillQueryVo billQueryVo) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.cxx.home.dto.bill.BillItemDto;
|
||||
import com.cxx.home.dto.bill.BillRecordDto;
|
||||
import com.cxx.home.dto.bill.BillSummaryDto;
|
||||
import com.cxx.home.vo.BillQueryVo;
|
||||
import com.cxx.home.vo.BillSearchVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -17,6 +18,8 @@ public interface BillDao {
|
||||
|
||||
List<BillSummaryDto> queryBillSummary(@Param("query") BillQueryVo query);
|
||||
|
||||
List<BillSummaryDto> searchBillSummary(@Param("query") BillSearchVo search);
|
||||
|
||||
void insertBillImage(@Param("billId") Long billId,
|
||||
@Param("list") List<String> imageFiles);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.cxx.home.dto.bill.BillItemDto;
|
||||
import com.cxx.home.dto.bill.BillRecordDto;
|
||||
import com.cxx.home.dto.bill.BillSummaryDto;
|
||||
import com.cxx.home.vo.BillQueryVo;
|
||||
import com.cxx.home.vo.BillSearchVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,6 +19,8 @@ public interface BillRecordService {
|
||||
|
||||
List<BillSummaryDto> queryBillSummary(BillQueryVo billQueryVo);
|
||||
|
||||
List<BillSummaryDto> searchBillSummary(BillSearchVo searchVo);
|
||||
|
||||
List<StatsChartDto> queryBillStats(String type, BillQueryVo billQueryVo);
|
||||
|
||||
List<BillItemDto> queryBillPay();
|
||||
|
||||
@@ -13,10 +13,13 @@ import com.cxx.framework.web.CustomException;
|
||||
import com.cxx.home.dao.BillDao;
|
||||
import com.cxx.home.service.BillRecordService;
|
||||
import com.cxx.home.vo.BillQueryVo;
|
||||
import com.cxx.home.vo.BillSearchVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -131,6 +134,16 @@ public class BillRecordServiceImpl implements BillRecordService {
|
||||
return billDao.queryBillSummary(billQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BillSummaryDto> searchBillSummary(BillSearchVo billSearch) {
|
||||
if (billSearch.getContent().isEmpty()
|
||||
&& billSearch.getCategory().isEmpty()
|
||||
&& billSearch.getLocation().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return billDao.searchBillSummary(billSearch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatsChartDto> queryBillStats(String type, BillQueryVo billQuery) {
|
||||
return billDao.queryBillStats(type, billQuery);
|
||||
|
||||
18
home-service/src/main/java/com/cxx/home/vo/BillSearchVo.java
Normal file
18
home-service/src/main/java/com/cxx/home/vo/BillSearchVo.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BillSearchVo {
|
||||
@Schema(description = "名称")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "类别")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "地址")
|
||||
private String location;
|
||||
}
|
||||
@@ -56,16 +56,16 @@
|
||||
|
||||
<select id="queryBillSummary" resultMap="billSummaryResultMap">
|
||||
SELECT
|
||||
a.id AS id,
|
||||
c.name AS bookName,
|
||||
a.type AS type,
|
||||
d.name AS category,
|
||||
a.location AS location,
|
||||
b.name AS payAccount,
|
||||
a.amount AS amount,
|
||||
a.content AS content,
|
||||
a.remark AS remark,
|
||||
a.date AS date
|
||||
a.id AS id,
|
||||
c.name AS bookName,
|
||||
a.type AS type,
|
||||
d.name AS category,
|
||||
a.location AS location,
|
||||
b.name AS payAccount,
|
||||
a.amount AS amount,
|
||||
a.content AS content,
|
||||
a.remark AS remark,
|
||||
a.date AS date
|
||||
FROM bill_record a
|
||||
LEFT JOIN bill_pay b ON a.pay_id = b.id
|
||||
LEFT JOIN bill_book c ON a.book_id = c.id
|
||||
@@ -83,6 +83,36 @@
|
||||
ORDER BY a.date DESC
|
||||
</select>
|
||||
|
||||
<select id="searchBillSummary" resultMap="billSummaryResultMap">
|
||||
SELECT
|
||||
a.id AS id,
|
||||
c.name AS bookName,
|
||||
a.type AS type,
|
||||
d.name AS category,
|
||||
a.location AS location,
|
||||
b.name AS payAccount,
|
||||
a.amount AS amount,
|
||||
a.content AS content,
|
||||
a.remark AS remark,
|
||||
a.date AS date
|
||||
FROM bill_record a
|
||||
LEFT JOIN bill_pay b ON a.pay_id = b.id
|
||||
LEFT JOIN bill_book c ON a.book_id = c.id
|
||||
LEFT JOIN bill_category d ON a.category_id = d.id
|
||||
<where>
|
||||
<if test="query.content != null and query.content != ''">
|
||||
a.content LIKE CONCAT('%', #{query.content}, '%')
|
||||
</if>
|
||||
<if test="query.category != null and query.category != ''">
|
||||
AND d.name LIKE CONCAT('%', #{query.category}, '%')
|
||||
</if>
|
||||
<if test="query.location != null and query.location != ''">
|
||||
AND a.location LIKE CONCAT('%', #{query.location}, '%')
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY a.date DESC
|
||||
</select>
|
||||
|
||||
<insert id="insertBillImage">
|
||||
INSERT INTO bill_image (bill_id, image_url) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
@@ -131,6 +161,7 @@
|
||||
</if>
|
||||
<if test="type eq 'category'">
|
||||
GROUP BY c.name
|
||||
ORDER BY value DESC
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user