Forráskód Böngészése

智能客服问题答案

jyc 2 hónapja
szülő
commit
aa1e528d95

+ 6 - 6
alien-entity/src/main/java/shop/alien/entity/store/AiIntelligentAssistant.java

@@ -29,17 +29,17 @@ public class AiIntelligentAssistant {
     @TableField("context")
     private String context;
 
-    @ApiModelProperty(value = "类型")
+    @ApiModelProperty(value = "类型(0空数据/1输入的问题/2ai回答/3固定问题)")
     @TableField("type")
     private Integer type;
 
     @ApiModelProperty(value = "回复id")
     @TableField("reply_id")
-    private String replyId;
+    private Integer replyId;
 
     @ApiModelProperty(value = "回复时间")
     @TableField("reply_date")
-    private String replyDate;
+    private Date replyDate;
 
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     @TableField("delete_flag")
@@ -64,8 +64,8 @@ public class AiIntelligentAssistant {
     @TableField("updated_user_id")
     private Integer updatedUserId;
 
-    @ApiModelProperty(value = "业务ID")
-    @TableField("business_id")
-    private Integer businessId;
+    @ApiModelProperty(value = "用户ID")
+    @TableField("user_id")
+    private Integer userId;
 
 }

+ 19 - 0
alien-entity/src/main/java/shop/alien/mapper/AiIntelligentAssistantMapper.java

@@ -0,0 +1,19 @@
+package shop.alien.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import shop.alien.entity.store.AiIntelligentAssistant;
+
+import java.util.List;
+
+
+@Mapper
+public interface AiIntelligentAssistantMapper extends BaseMapper<AiIntelligentAssistant> {
+
+
+    void insertList(List<AiIntelligentAssistant> list);
+}
+
+
+
+

+ 2 - 1
alien-entity/src/main/java/shop/alien/mapper/LifeDiscountCouponStoreFriendMapper.java

@@ -35,7 +35,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
             "${ew.customSqlSegment}")
     IPage<LifeDiscountCouponVo> selectPage(IPage<LifeDiscountCouponStoreFriendVo> iPage, @Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponStoreFriendVo> friendLifeDiscountCouponQueryWrapper);
 
-    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,su.head_img imgUrl,\n" +
+    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
             "si.store_name storeName,\n" +
             "ldc.name couponName,\n" +
             "ldcsf.single_qty couponNum\n" +
@@ -45,6 +45,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
             "left join store_info si\n" +
             "on si.id = ldc.store_id and si.delete_flag = 0\n" +
             "left join store_user su on si.id = su.store_id\n" +
+            "left join store_img img on si.id = img.store_id and img.img_type = 1 and img.delete_flag = 0\n" +
             "${ew.customSqlSegment}")
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);
 }

+ 36 - 0
alien-entity/src/main/resources/mapper/AiIntelligentAssistantMapper.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="shop.alien.mapper.AiIntelligentAssistantMapper">
+
+    <insert id="insertList">
+        INSERT INTO ai_intelligent_assistant (
+        context,
+        type,
+        reply_id,
+        reply_date,
+        delete_flag,
+        created_time,
+        created_user_id,
+        updated_time,
+        updated_user_id,
+        user_id
+        ) VALUES
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.context},
+            #{item.type},
+            #{item.replyId},
+            #{item.replyDate},
+            #{item.deleteFlag},
+            #{item.createdTime},
+            #{item.createdUserId},
+            #{item.updatedTime},
+            #{item.updatedUserId},
+            #{item.userId}
+            )
+        </foreach>
+    </insert>
+
+</mapper>

+ 20 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreCustomerServiceController.java

@@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.AiIntelligentAssistant;
 import shop.alien.entity.store.StoreCustomerService;
 import shop.alien.store.service.StoreCustomerServiceService;
 
@@ -97,4 +98,23 @@ public class StoreCustomerServiceController {
         StoreCustomerService saved = storeCustomerServiceService.getById(id);
         return R.data(saved);
     }
+
+    @ApiOperation("保存聊天")
+    @ApiOperationSupport(order = 5)
+    @PostMapping("/saveAiIntelligentAssistant")
+    public R<List<AiIntelligentAssistant>> saveAiIntelligentAssistant(@RequestBody List<AiIntelligentAssistant> aiIntelligentAssistants) {
+        log.info("StoreCustomerServiceController.saveAiIntelligentAssistant?aiIntelligentAssistants={}", aiIntelligentAssistants.toString());
+        List<AiIntelligentAssistant> saved = storeCustomerServiceService.saveAiIntelligentAssistant(aiIntelligentAssistants);
+        return R.data(saved);
+    }
+
+    @ApiOperation("查询聊天记录")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id)", dataType = "String", paramType = "query", required = true)
+            , @ApiImplicitParam(name = "time", value = "时间", dataType = "String", paramType = "query", required = true)})
+    @GetMapping("/selectAiIntelligentAssistant")
+    public R<List<AiIntelligentAssistant>> selectAiIntelligentAssistant(@RequestParam String userId, @RequestParam String time) {
+        List<AiIntelligentAssistant> result = storeCustomerServiceService.selectAiIntelligentAssistant(userId,time);
+        return R.data(result);
+    }
 }

+ 5 - 0
alien-store/src/main/java/shop/alien/store/service/StoreCustomerServiceService.java

@@ -2,6 +2,7 @@ package shop.alien.store.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.store.AiIntelligentAssistant;
 import shop.alien.entity.store.StoreCustomerService;
 
 import java.util.List;
@@ -27,4 +28,8 @@ public interface StoreCustomerServiceService extends IService<StoreCustomerServi
     StoreCustomerService getById(String id);
 
     List<StoreCustomerService> getRandList(String type,Integer limit);
+
+    List<AiIntelligentAssistant> saveAiIntelligentAssistant(List<AiIntelligentAssistant> aiIntelligentAssistants);
+
+    List<AiIntelligentAssistant> selectAiIntelligentAssistant(String userId,String time);
 }

+ 34 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreCustomerServiceServiceImpl.java

@@ -6,12 +6,15 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
+import shop.alien.entity.store.AiIntelligentAssistant;
 import shop.alien.entity.store.StoreCustomerService;
+import shop.alien.mapper.AiIntelligentAssistantMapper;
 import shop.alien.mapper.StoreCustomerServiceMapper;
 import shop.alien.store.service.StoreCustomerServiceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -29,6 +32,8 @@ public class StoreCustomerServiceServiceImpl extends ServiceImpl<StoreCustomerSe
 
     private final StoreCustomerServiceMapper storeCustomerServiceMapper;
 
+    private final AiIntelligentAssistantMapper aiIntelligentAssistantMapper;
+
     @Override
     public StoreCustomerService getByQuestion(String question) {
         LambdaQueryWrapper<StoreCustomerService> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -78,4 +83,33 @@ public class StoreCustomerServiceServiceImpl extends ServiceImpl<StoreCustomerSe
                 .last("order by rand() LIMIT " + limit);
         return storeCustomerServiceMapper.selectList(lambdaQueryWrapper);
     }
+
+    @Override
+    public List<AiIntelligentAssistant> saveAiIntelligentAssistant(List<AiIntelligentAssistant> aiIntelligentAssistants) {
+        for (AiIntelligentAssistant aiIntelligentAssistant : aiIntelligentAssistants) {
+            aiIntelligentAssistant.setCreatedTime(new Date());
+            aiIntelligentAssistant.setUpdatedTime(new Date());
+        }
+        aiIntelligentAssistantMapper.insertList(aiIntelligentAssistants);
+        return aiIntelligentAssistants;
+    }
+
+    @Override
+    public List<AiIntelligentAssistant> selectAiIntelligentAssistant(String userId,String time) {
+        LambdaQueryWrapper<AiIntelligentAssistant> last = new LambdaQueryWrapper<AiIntelligentAssistant>()
+                .lt(AiIntelligentAssistant::getCreatedTime, time)
+                .eq(AiIntelligentAssistant::getDeleteFlag, 0)
+                .eq(AiIntelligentAssistant::getType, 0).eq(AiIntelligentAssistant::getUserId, userId).orderByDesc(AiIntelligentAssistant::getCreatedTime).last("limit 1");
+        AiIntelligentAssistant aiIntelligentAssistant = aiIntelligentAssistantMapper.selectOne(last);
+        if (ObjectUtils.isNotEmpty(aiIntelligentAssistant)) {
+            LambdaQueryWrapper<AiIntelligentAssistant> queryWrapper = new LambdaQueryWrapper<AiIntelligentAssistant>()
+                    .ge(AiIntelligentAssistant::getCreatedTime, aiIntelligentAssistant.getCreatedTime())
+                    .lt(AiIntelligentAssistant::getCreatedTime, time)
+                    .eq(AiIntelligentAssistant::getDeleteFlag, 0)
+                    .eq(AiIntelligentAssistant::getUserId, userId)
+                    .orderByAsc(AiIntelligentAssistant::getCreatedTime);
+            return aiIntelligentAssistantMapper.selectList(queryWrapper);
+        }
+        return new ArrayList<>();
+    }
 }