From dd028e18a12ad9ae7c43ed09b15ddd6bde1a43e9 Mon Sep 17 00:00:00 2001
From: guyue <1721849008@qq.com>
Date: 星期三, 03 九月 2025 11:27:50 +0800
Subject: [PATCH] 采集中状态修改提前,统计数据合并

---
 src/main/java/com/linghu/controller/OrderController.java |  141 +++++++++++++++-------------------------------
 1 files changed, 47 insertions(+), 94 deletions(-)

diff --git a/src/main/java/com/linghu/controller/OrderController.java b/src/main/java/com/linghu/controller/OrderController.java
index 8ce2d69..49afe6a 100644
--- a/src/main/java/com/linghu/controller/OrderController.java
+++ b/src/main/java/com/linghu/controller/OrderController.java
@@ -4,16 +4,23 @@
 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;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.Date;
@@ -30,48 +37,15 @@
     @Autowired
     private OrderService orderService;
 
+
     /**
      * 新增订单
      */
     @PostMapping
+    @Transactional // 开启事务
     @ApiOperation(value = "新增订单")
-    public ResponseResult<Orders> add(@RequestBody OrderDto orderDto) {
-        // 将dto转entity
-        Orders order = new Orders();
-        BeanUtils.copyProperties(orderDto, order);
-
-        if (order.getClient_name() == null || order.getClient_name().trim().isEmpty()) {
-            return ResponseResult.error("客户名称不能为空");
-        }
-
-        // 生成订单ID:日期+当天的订单数量(如:202507060001)
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
-        String dateStr = dateFormat.format(new Date());
-
-        // 查询当天订单数量
-        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.likeRight(Orders::getOrder_id, dateStr);
-        long count = orderService.count(queryWrapper);
-
-        // 生成订单ID
-        String orderId = String.format("%s%04d", dateStr, count + 1);
-        order.setOrder_id(orderId);
-
-        // 设置初始状态
-        order.setStatus(1); // 待处理
-        order.setDel_flag(0); // 未删除
-        order.setCreate_time(LocalDateTime.now());
-        boolean save = orderService.save(order);
-        // 保存关键词
-        boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto,order.getOrder_id());
-        if (!saveOrderWithKeywords) {
-            return ResponseResult.error("添加关键词失败");
-        }
-
-        if (save) {
-            return ResponseResult.success(order);
-        }
-        return ResponseResult.error("添加订单失败");
+    public ResponseResult<Orders> add(@Valid @RequestBody OrderDto orderDto) {
+        return orderService.getOrdersResponseResult(orderDto);
     }
 
     /**
@@ -80,43 +54,20 @@
     @DeleteMapping("/{orderId}")
     @ApiOperation(value = "删除订单")
     public ResponseResult<Void> delete(@PathVariable String orderId) {
-        Orders order = orderService.getById(orderId);
-        if (order == null) {
-            return ResponseResult.error("订单不存在");
-        }
-
-        order.setDel_flag(1);
-        order.setUpdate_time(LocalDateTime.now());
-        boolean success = orderService.updateById(order);
-
-        return success ? ResponseResult.success() : ResponseResult.error("删除订单失败");
+        return orderService.getVoidResponseResult(orderId);
     }
+
+
 
     /**
      * 更新订单
      */
     @PutMapping
     @ApiOperation(value = "更新订单")
-    public ResponseResult<Void> update(@RequestBody Orders order) {
-        if (order.getOrder_id() == null) {
-            return ResponseResult.error("订单ID不能为空");
-        }
-        if (order.getClient_name() == null || order.getClient_name().trim().isEmpty()) {
-            return ResponseResult.error("客户名称不能为空");
-        }
-
-        Orders existingOrder = orderService.getById(order.getOrder_id());
-        if (existingOrder == null) {
-            return ResponseResult.error("订单不存在");
-        }
-
-        order.setUpdate_time(LocalDateTime.now());
-
-        if (orderService.updateById(order)) {
-            return ResponseResult.success();
-        }
-        return ResponseResult.error("更新订单失败");
+    public ResponseResult<Void> update(@Valid @RequestBody OrderDto orderDto) {
+        return orderService.updateOrder(orderDto);
     }
+
 
     /**
      * 根据ID查询订单
@@ -124,48 +75,50 @@
     @GetMapping("/{orderId}")
     @ApiOperation("根据ID查询订单")
     public ResponseResult<Orders> getById(@PathVariable String orderId) {
-        Orders order = orderService.getById(orderId);
-        if (order == null || order.getDel_flag() == 1) {
-            return ResponseResult.error("订单不存在");
-        }
-        return ResponseResult.success(order);
+        return orderService.getOrderById(orderId);
     }
+
+
 
     /**
      * 查询订单列表
      */
     @GetMapping
     @ApiOperation("查询订单列表")
-    public ResponseResult<List<Orders>> list(
+    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) {
+            @RequestParam(required = false) String timeRange) {
 
-        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(Orders::getDel_flag, 0); // 只查询未删除的订单
+        return orderService.getCustomPageResponseResult(pageNum, pageSize, clientName, status, timeRange);
+    }
 
-        // 添加查询条件
-        if (clientName != null && !clientName.trim().isEmpty()) {
-            queryWrapper.like(Orders::getClient_name, clientName);
-        }
-        if (status != null) {
-            queryWrapper.eq(Orders::getStatus, status);
-        }
-        if (createTime != null) {
-            queryWrapper.like(Orders::getCreate_time, createTime);
-        }
 
-        // 分页查询
-        if (pageNum != null && pageSize != null) {
-            Page<Orders> pageInfo = new Page<>(pageNum, pageSize);
-            Page<Orders> result = orderService.page(pageInfo, queryWrapper);
-            return ResponseResult.success(result.getRecords());
-        }
 
-        // 不分页
-        List<Orders> list = orderService.list(queryWrapper);
-        return ResponseResult.success(list);
+    /**
+     * 获取客户列表
+     * @param
+     * @return
+     */
+    @GetMapping("/clientList")
+    @ApiOperation("获取客户列表")
+    public ResponseResult<CustomPage<String>> getClientList(@RequestParam(required = false) String clientName,
+                                                      @RequestParam(required = false,defaultValue = "1") Integer pageNum,
+                                                      @RequestParam(required = false, defaultValue = "100") Integer pageSize) {
+
+        Page<String> result = orderService.getClientList(clientName,pageNum, pageSize);
+
+
+        return ResponseResult.success(new CustomPage<>( result));
+    }
+
+
+    @GetMapping("/{orderId}/keywordList")
+    @ApiOperation("获取订单关联的关键词及提问词")
+    public ResponseResult<List<KeywordDto>> getKeywordList(@PathVariable String orderId){
+        List<KeywordDto> result = orderService.getKeywordListByOrderId(orderId);
+        return ResponseResult.success(result);
     }
 }
\ No newline at end of file

--
Gitblit v1.7.1