From 1cb09e4cde9fb97b8369478a9fc16418ac4e29a4 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期三, 09 七月 2025 17:31:07 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/main/resources/mapper/OrderMapper.xml | 3 + src/main/java/com/linghu/model/entity/Orders.java | 5 ++ src/main/java/com/linghu/model/page/CustomPage.java | 19 +++++++++ src/main/java/com/linghu/controller/OrderController.java | 59 ++++++++++++++++++++++++----- src/main/java/com/linghu/service/impl/OrderServiceImpl.java | 1 src/main/java/com/linghu/config/MyBatisPlusConfig.java | 18 +++++++++ 6 files changed, 93 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/linghu/config/MyBatisPlusConfig.java b/src/main/java/com/linghu/config/MyBatisPlusConfig.java new file mode 100644 index 0000000..bb1be96 --- /dev/null +++ b/src/main/java/com/linghu/config/MyBatisPlusConfig.java @@ -0,0 +1,18 @@ +package com.linghu.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MyBatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 添加分页插件,这里可指定数据库类型(如 MySQL),也可默认 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; + } +} \ No newline at end of file diff --git a/src/main/java/com/linghu/controller/OrderController.java b/src/main/java/com/linghu/controller/OrderController.java index 7c9995e..3b7fb30 100644 --- a/src/main/java/com/linghu/controller/OrderController.java +++ b/src/main/java/com/linghu/controller/OrderController.java @@ -4,9 +4,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.databind.util.BeanUtil; import com.linghu.model.common.ResponseResult; +import com.linghu.model.entity.Keyword; import com.linghu.model.entity.Orders; import com.linghu.model.dto.KeywordDto; import com.linghu.model.dto.OrderDto; +import com.linghu.model.page.CustomPage; +import com.linghu.service.KeywordService; import com.linghu.service.OrderService; import io.swagger.annotations.Api; @@ -30,6 +33,9 @@ @Autowired private OrderService orderService; + + @Autowired + private KeywordService keywordService; /** * 新增订单 @@ -68,6 +74,13 @@ if (!saveOrderWithKeywords) { return ResponseResult.error("添加关键词失败"); } + //更新关键词数量 + LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper = new LambdaQueryWrapper<>(); + queryKeywordsQueryWrapper.eq(Keyword::getOrder_id, order.getOrder_id()); + int count1 = keywordService.count(queryKeywordsQueryWrapper); + order.setKeyword_num(count1); + order.setUpdate_time(LocalDateTime.now()); + orderService.updateById(order); if (save) { return ResponseResult.success(order); @@ -98,22 +111,36 @@ */ @PutMapping @ApiOperation(value = "更新订单") - public ResponseResult<Void> update(@RequestBody Orders order) { - if (order.getOrder_id() == null) { + public ResponseResult<Void> update(@RequestBody OrderDto orderDto) { + if (orderDto.getOrder_id() == null) { return ResponseResult.error("订单ID不能为空"); } - if (order.getClient_name() == null || order.getClient_name().trim().isEmpty()) { + if (orderDto.getClient_name() == null || orderDto.getClient_name().trim().isEmpty()) { return ResponseResult.error("客户名称不能为空"); } - Orders existingOrder = orderService.getById(order.getOrder_id()); + Orders existingOrder = orderService.getById(orderDto.getOrder_id()); if (existingOrder == null) { return ResponseResult.error("订单不存在"); } - order.setUpdate_time(LocalDateTime.now()); + orderDto.setUpdate_time(LocalDateTime.now()); + if (orderDto.getKeywords()!= null&&orderDto.getKeywords().trim().length() > 0){ + // 保存关键词 + boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto, orderDto.getOrder_id()); + if (!saveOrderWithKeywords) { + return ResponseResult.error("添加关键词失败"); + } + } + //更新关键词数量 + LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper = new LambdaQueryWrapper<>(); + queryKeywordsQueryWrapper.eq(Keyword::getOrder_id, orderDto.getOrder_id()); + int count1 = keywordService.count(queryKeywordsQueryWrapper); + orderDto.setKeyword_num(count1); - if (orderService.updateById(order)) { + + + if (orderService.updateById(orderDto)) { return ResponseResult.success(); } return ResponseResult.error("更新订单失败"); @@ -137,15 +164,15 @@ */ @GetMapping @ApiOperation("查询订单列表") - public ResponseResult<Page<Orders>> list( - @RequestParam(required = false,defaultValue = "1") Integer pageNum , - @RequestParam(required = false,defaultValue = "10") Integer pageSize , + public ResponseResult<CustomPage<Orders>> list( + @RequestParam(required = false) Integer pageNum, + @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) String clientName, @RequestParam(required = false) Integer status, @RequestParam(required = false) String createTime) { LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Orders::getDel_flag, 0); // 只查询未删除的订单 + queryWrapper.eq(Orders::getDel_flag, 0); // 添加查询条件 if (clientName != null && !clientName.trim().isEmpty()) { @@ -159,9 +186,19 @@ } // 分页查询 + if (pageNum != null && pageSize != null) { Page<Orders> pageInfo = new Page<>(pageNum, pageSize); Page<Orders> result = orderService.page(pageInfo, queryWrapper); - return ResponseResult.success(result); + return ResponseResult.success(new CustomPage<>(result)); + } + + // 不分页查询:手动创建 CustomPage + List<Orders> list = orderService.list(queryWrapper); + CustomPage<Orders> page = new CustomPage<>(new Page<>()); + page.setRecords(list); + page.setTotal(list.size()); + + return ResponseResult.success(page); } @GetMapping("/{orderId}/keywordList") diff --git a/src/main/java/com/linghu/model/entity/Orders.java b/src/main/java/com/linghu/model/entity/Orders.java index ef156ad..63b4170 100644 --- a/src/main/java/com/linghu/model/entity/Orders.java +++ b/src/main/java/com/linghu/model/entity/Orders.java @@ -39,6 +39,11 @@ private Integer del_flag; /** + * 关键词数量 + */ + private Integer keyword_num; + + /** * 提交人 */ private String create_by; diff --git a/src/main/java/com/linghu/model/page/CustomPage.java b/src/main/java/com/linghu/model/page/CustomPage.java new file mode 100644 index 0000000..3fa276d --- /dev/null +++ b/src/main/java/com/linghu/model/page/CustomPage.java @@ -0,0 +1,19 @@ +package com.linghu.model.page; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.Data; +import java.util.List; + +/** + * 自定义分页结果 + */ +@Data +public class CustomPage<T> { + private List<T> records; // 数据列表 + private long total; // 总记录数 + + public CustomPage(Page<T> page) { + this.records = page.getRecords(); + this.total = page.getTotal(); + } +} \ No newline at end of file diff --git a/src/main/java/com/linghu/service/impl/OrderServiceImpl.java b/src/main/java/com/linghu/service/impl/OrderServiceImpl.java index 92e7030..6609a5f 100644 --- a/src/main/java/com/linghu/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/linghu/service/impl/OrderServiceImpl.java @@ -51,6 +51,7 @@ keywordService.save(keyword); } } + } return true; diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderMapper.xml index a4c8056..67e8594 100644 --- a/src/main/resources/mapper/OrderMapper.xml +++ b/src/main/resources/mapper/OrderMapper.xml @@ -9,6 +9,7 @@ <result property="client_name" column="client_name" jdbcType="VARCHAR"/> <result property="status" column="status" jdbcType="INTEGER"/> <result property="del_flag" column="del_flag" jdbcType="INTEGER"/> + <result property="keyword_num" column="keyword_num" jdbcType="INTEGER"/> <result property="create_by" column="create_by" jdbcType="VARCHAR"/> <result property="create_time" column="create_time" jdbcType="TIMESTAMP"/> <result property="update_by" column="update_by" jdbcType="VARCHAR"/> @@ -17,7 +18,7 @@ <sql id="Base_Column_List"> order_id,client_name,status, - del_flag,create_by,create_time, + del_flag,keyword_num,create_by,create_time, update_by,update_time </sql> </mapper> -- Gitblit v1.7.1