guyue
8 天以前 a9e958ce3675c4950ceddd3fd6f939cdf0d2bc5a
src/main/java/com/linghu/controller/OrderController.java
@@ -16,8 +16,10 @@
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 java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
@@ -41,6 +43,7 @@
     * 新增订单
     */
    @PostMapping
    @Transactional // 开启事务
    @ApiOperation(value = "新增订单")
    public ResponseResult<Orders> add(@RequestBody OrderDto orderDto) {
        // 将dto转entity
@@ -54,14 +57,26 @@
        // 生成订单ID:日期+当天的订单数量(如:202507060001)
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateStr = dateFormat.format(new Date());
        // 查询当天订单数量
        // 1. 查询当天最大的订单号(包含已删除的,适应硬删除场景)
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.likeRight(Orders::getOrder_id, dateStr);
        long count = orderService.count(queryWrapper);
        queryWrapper.likeRight(Orders::getOrder_id, dateStr)
                .select(Orders::getOrder_id)
                .orderByDesc(Orders::getOrder_id)
                .last("LIMIT 1"); // 只取最大的一条
        Orders maxOrder = orderService.getOne(queryWrapper);
        int sequence = 1; // 默认序号
        // 生成订单ID
        String orderId = String.format("%s%04d", dateStr, count + 1);
        if (maxOrder != null && maxOrder.getOrder_id() != null) {
            // 2. 从最大订单号中提取序号(如"202507250005"提取"0005")
            String maxId = maxOrder.getOrder_id();
            if (maxId.length() == dateStr.length() + 4) { // 校验格式
                String seqStr = maxId.substring(dateStr.length());
                sequence = Integer.parseInt(seqStr) + 1; // 序号+1
            }
        }
        // 3. 生成新订单号(补全4位,如1→0001)
        String  orderId = String.format("%s%04d", dateStr, sequence);
        order.setOrder_id(orderId);
        // 设置初始状态
@@ -131,6 +146,8 @@
            if (!saveOrderWithKeywords) {
                return ResponseResult.error("添加关键词失败");
            }
            //更新订单状态,新增关键词
            orderDto.setStatus(1);
        }
        //更新关键词数量
        LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper =  new LambdaQueryWrapper<>();
@@ -169,22 +186,46 @@
            @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);
        // 添加查询条件
        if (clientName != null && !clientName.trim().isEmpty()) {
            queryWrapper.like(Orders::getClient_name, clientName);
            queryWrapper.eq(Orders::getClient_name, clientName);
        }
        if (status != null) {
            queryWrapper.eq(Orders::getStatus, status);
        }
        if (createTime != null) {
            queryWrapper.like(Orders::getCreate_time, createTime);
        }
        // 改造时间筛选逻辑
        if (timeRange != null && !timeRange.trim().isEmpty()) {
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime startTime = null;
            switch (timeRange.trim()) {
                case "week":
                    startTime = now.minusWeeks(1);
                    break;
                case "month":
                    startTime = now.minusMonths(1);
                    break;
                case "threeMonths":
                    startTime = now.minusMonths(3);
                    break;
                case "year":
                    startTime = now.minusYears(1);
                    break;
                default:
                    // 可添加日志记录无效参数
                    break;
            }
            if (startTime != null) {
                queryWrapper.ge(Orders::getCreate_time, startTime);
            }
        }
        // 排序
        queryWrapper.orderByDesc(Orders::getCreate_time);
        // 分页查询
        if (pageNum != null && pageSize != null) {
            Page<Orders> pageInfo = new Page<>(pageNum, pageSize);
@@ -201,9 +242,27 @@
        return ResponseResult.success(page);
    }
    /**
     * 获取客户列表
     * @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) {
    public ResponseResult<List<KeywordDto>> getKeywordList(@PathVariable String orderId){
        List<KeywordDto> result = orderService.getKeywordListByOrderId(orderId);
        return ResponseResult.success(result);
    }