Преглед изворни кода

Merge remote-tracking branch 'origin/sit-three-categories' into sit-three-categories

liyafei пре 3 месеци
родитељ
комит
1ae19ac4dc

+ 20 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/AiQuestionClassificationRequestDto.java

@@ -0,0 +1,20 @@
+package shop.alien.entity.store.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 问题分类请求DTO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "QuestionClassificationRequestDto对象", description = "问题分类请求DTO")
+public class AiQuestionClassificationRequestDto {
+
+    @ApiModelProperty(value = "问题文本", required = true, example = "我想了解一下这个产品的使用方法")
+    private String question;
+}
+

+ 64 - 0
alien-store/src/main/java/shop/alien/store/controller/AiQuestionClassificationController.java

@@ -0,0 +1,64 @@
+package shop.alien.store.controller;
+
+import com.alibaba.fastjson2.JSONObject;
+import io.swagger.annotations.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.store.dto.AiQuestionClassificationRequestDto;
+import shop.alien.store.service.AiQuestionClassificationService;
+
+/**
+ * 问题分类控制器
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Api(tags = {"AI问题分类"})
+@CrossOrigin
+@RestController
+@RequestMapping("/questionClassification")
+@RequiredArgsConstructor
+@RefreshScope
+public class AiQuestionClassificationController {
+
+    private final AiQuestionClassificationService questionClassificationService;
+
+    /**
+     * 问题分类接口
+     *
+     * @param requestDto 问题分类请求DTO
+     * @return AI接口返回的原始响应
+     */
+    @ApiOperation(value = "问题分类", notes = "对用户问题进行AI分类")
+    @ApiOperationSupport(order = 1)
+    @PostMapping("/classify")
+    public ResponseEntity<String> classify(@RequestBody AiQuestionClassificationRequestDto requestDto) {
+        log.info("收到问题分类请求,问题:{}", requestDto != null ? requestDto.getQuestion() : null);
+        
+        // 参数校验
+        if (requestDto == null || !StringUtils.hasText(requestDto.getQuestion())) {
+            log.warn("问题分类请求参数为空或问题文本为空");
+            JSONObject errorResponse = new JSONObject();
+            errorResponse.put("code", 400);
+            errorResponse.put("message", "问题文本不能为空");
+            return ResponseEntity.badRequest().body(errorResponse.toJSONString());
+        }
+        
+        try {
+            String result = questionClassificationService.classify(requestDto);
+            return ResponseEntity.ok(result);
+        } catch (Exception e) {
+            log.error("问题分类失败,问题:{}", requestDto.getQuestion(), e);
+            JSONObject errorResponse = new JSONObject();
+            errorResponse.put("code", 500);
+            errorResponse.put("message", "问题分类失败:" + e.getMessage());
+            return ResponseEntity.status(500).body(errorResponse.toJSONString());
+        }
+    }
+}
+

+ 21 - 0
alien-store/src/main/java/shop/alien/store/service/AiQuestionClassificationService.java

@@ -0,0 +1,21 @@
+package shop.alien.store.service;
+
+import shop.alien.entity.store.dto.AiQuestionClassificationRequestDto;
+
+/**
+ * 问题分类服务接口
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+public interface AiQuestionClassificationService {
+
+    /**
+     * 对问题进行分类
+     *
+     * @param requestDto 问题分类请求DTO
+     * @return AI接口返回的JSON字符串
+     */
+    String classify(AiQuestionClassificationRequestDto requestDto);
+}
+

+ 88 - 0
alien-store/src/main/java/shop/alien/store/service/impl/AiQuestionClassificationServiceImpl.java

@@ -0,0 +1,88 @@
+package shop.alien.store.service.impl;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.RestTemplate;
+import shop.alien.entity.store.dto.AiQuestionClassificationRequestDto;
+import shop.alien.store.service.AiQuestionClassificationService;
+import shop.alien.store.util.ai.AiAuthTokenUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 问题分类服务实现类
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@RefreshScope
+public class AiQuestionClassificationServiceImpl implements AiQuestionClassificationService {
+
+    private final AiAuthTokenUtil aiAuthTokenUtil;
+
+    private final RestTemplate restTemplate;
+
+    @Value("${third-party-ai-question-classification.base-url}")
+    private String questionClassificationUrl;
+
+    @Override
+    public String classify(AiQuestionClassificationRequestDto requestDto) {
+        log.info("开始调用问题分类接口,问题:{}", requestDto.getQuestion());
+
+        // 获取访问令牌
+        String accessToken = aiAuthTokenUtil.getAccessToken();
+        if (!StringUtils.hasText(accessToken)) {
+            log.error("调用问题分类接口失败,获取accessToken失败");
+            throw new RuntimeException("获取访问令牌失败");
+        }
+
+        // 构建请求体
+        Map<String, Object> requestBody = new HashMap<>();
+        requestBody.put("question", requestDto.getQuestion());
+
+        // 构建请求头
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("Authorization", "Bearer " + accessToken);
+
+        HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, headers);
+
+        try {
+            log.info("调用问题分类接口,URL:{},请求参数:{}", questionClassificationUrl, requestBody);
+            ResponseEntity<String> responseEntity = restTemplate.postForEntity(
+                    questionClassificationUrl, request, String.class);
+
+            log.info("问题分类接口调用成功,响应状态:{},响应体:{}",
+                    responseEntity.getStatusCode(), responseEntity.getBody());
+
+            // 直接返回响应体
+            return responseEntity.getBody();
+
+        } catch (HttpClientErrorException e) {
+            log.error("调用问题分类接口返回客户端错误,状态码:{},响应体:{},URL:{}",
+                    e.getStatusCode(), e.getResponseBodyAsString(), questionClassificationUrl, e);
+            throw new RuntimeException("调用问题分类接口失败:" + e.getMessage(), e);
+        } catch (HttpServerErrorException e) {
+            log.error("调用问题分类接口返回服务器错误,状态码:{},响应体:{},URL:{}",
+                    e.getStatusCode(), e.getResponseBodyAsString(), questionClassificationUrl, e);
+            throw new RuntimeException("调用问题分类接口失败:" + e.getMessage(), e);
+        } catch (Exception e) {
+            log.error("调用问题分类接口异常,URL:{},异常信息:{}", questionClassificationUrl, e.getMessage(), e);
+            throw new RuntimeException("调用问题分类接口异常:" + e.getMessage(), e);
+        }
+    }
+}

+ 29 - 1
alien-store/src/main/java/shop/alien/store/service/impl/PerformanceListServiceImpl.java

@@ -146,6 +146,34 @@ public class PerformanceListServiceImpl implements PerformanceListService {
                 .eq(BarPerformance::getReviewStatus, CommonConstant.PERFORMANCE_REVIEW_STATUS_APPROVED)
                 .eq(BarPerformance::getOnlineStatus, CommonConstant.PERFORMANCE_ONLINE_STATUS_ONLINE).eq(BarPerformance::getStatus, 1);
 
+        // 过滤已过期的演出
+        Date now = new Date();
+        // 获取今天的开始时间(00:00:00)
+        java.util.Calendar cal = java.util.Calendar.getInstance();
+        cal.setTime(now);
+        cal.set(java.util.Calendar.HOUR_OF_DAY, 0);
+        cal.set(java.util.Calendar.MINUTE, 0);
+        cal.set(java.util.Calendar.SECOND, 0);
+        cal.set(java.util.Calendar.MILLISECOND, 0);
+        Date todayStart = cal.getTime();
+
+        // 使用and条件,确保至少满足以下条件之一(即未过期):
+        // 1. 单次演出:结束时间 >= 当前时间
+        // 2. 定时演出(每天定时或每周定时):结束日期 > 今天 或 (结束日期 = 今天 AND 结束时间 >= 当前时分秒)
+        queryWrapper.and(wrapper -> {
+            // 单次演出:结束时间 >= 现在
+            wrapper.or(w -> w.eq(BarPerformance::getPerformanceFrequency, "0")
+                    .ge(BarPerformance::getSingleEndDatetime, now));
+            // 定时演出:结束日期 > 今天 或 (结束日期 = 今天 AND 结束时间 >= 当前时分秒)
+            wrapper.or(w -> w.in(BarPerformance::getPerformanceFrequency, "1", "2")
+                    .and(subWrapper -> {
+                        // 结束日期 > 今天
+                        subWrapper.gt(BarPerformance::getDailyEndDate, todayStart)
+                                // 或 (结束日期 = 今天 AND 结束时间 >= 当前时分秒)
+                                .or(subSubWrapper -> subSubWrapper.apply("DATE(daily_end_date) = CURDATE() AND daily_end_time >= TIME(NOW())"));
+                    }));
+        });
+
         // 排序规则:按创建时间降序
         queryWrapper.orderByDesc(BarPerformance::getCreatedTime);
 
@@ -609,7 +637,7 @@ public class PerformanceListServiceImpl implements PerformanceListService {
         cal.set(java.util.Calendar.MILLISECOND, 0);
         Date todayStart = cal.getTime();
 
-        cal.add(java.util.Calendar.DAY_OF_MONTH, 30);
+        cal.add(java.util.Calendar.DAY_OF_MONTH, 365);
         Date futureEnd = cal.getTime();
 
         // 遍历演出,生成日期映射

+ 0 - 2
alien-store/src/main/java/shop/alien/store/util/ai/AiFeedbackAssignUtils.java

@@ -40,8 +40,6 @@ public class AiFeedbackAssignUtils {
     @Value("${ai.service.assign-staff-url}")
     private String assignStaffUrl;
 
-    private  final AlienAIFeign alienAIFeign;
-
     // 语音识别接口地址(从配置中读取,如果没有配置则使用默认值)
     @Value("${feign.alienAI.url}")
     private String aiServiceBaseUrl;

+ 1 - 0
alien-store/src/main/java/shop/alien/store/util/ai/AiImageColorExtractUtil.java

@@ -26,6 +26,7 @@ import java.util.Map;
 public class AiImageColorExtractUtil {
 
     private final RestTemplate restTemplate;
+
     private final AiAuthTokenUtil aiAuthTokenUtil;
 
     @Value("${ai.service.image-color-extract-url}")