Browse Source

通过接口 获取AI整理的个人信息

zrd 3 tháng trước cách đây
mục cha
commit
9600179555

+ 6 - 0
yudao-framework/yudao-spring-boot-starter-excel/pom.xml

@@ -75,6 +75,12 @@
             <artifactId>yudao-spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-infra-api</artifactId>
+            <version>2.4.1-RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 9 - 0
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java

@@ -1,6 +1,8 @@
 package cn.iocoder.yudao.framework.dict.config;
 
+import cn.iocoder.yudao.framework.dict.core.AiFrameworkUtils;
 import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
+import cn.iocoder.yudao.module.infra.api.ai.AiApi;
 import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
 import org.springframework.boot.autoconfigure.AutoConfiguration;
 import org.springframework.context.annotation.Bean;
@@ -14,5 +16,12 @@ public class YudaoDictAutoConfiguration {
         DictFrameworkUtils.init(dictDataApi);
         return new DictFrameworkUtils();
     }
+    
+    @Bean
+    @SuppressWarnings("InstantiationOfUtilityClass")
+    public AiFrameworkUtils aiUtils(AiApi api) {
+        AiFrameworkUtils.init(api);
+        return new AiFrameworkUtils();
+    }
 
 }

+ 33 - 0
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/AiFrameworkUtils.java

@@ -0,0 +1,33 @@
+package cn.iocoder.yudao.framework.dict.core;
+
+import cn.iocoder.yudao.module.infra.api.ai.AiApi;
+import cn.iocoder.yudao.module.infra.api.ai.dto.DifyaiReqDTO;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 字典工具类
+ *
+ * @author 芋道源码
+ */
+@Slf4j
+public class AiFrameworkUtils {
+    
+    private static AiApi api;
+    
+    
+    public static void init(AiApi api) {
+        AiFrameworkUtils.api = api;
+        log.info("[init][初始化 DictFrameworkUtils 成功]");
+    }
+    
+    @SneakyThrows
+    public static String getAi(String type, String content) {
+        DifyaiReqDTO createReqVO = new DifyaiReqDTO();
+        createReqVO.setType(type);
+        createReqVO.setContent(content);
+        return api.ai(createReqVO);
+    }
+    
+    
+}

+ 26 - 0
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserInformationController.java

@@ -57,6 +57,32 @@ public class AppUserInformationController {
         return success(BeanUtils.toBean(userInformation, UserInformationRespVO.class));
     }
     
+    @GetMapping("/getAi")
+    @Operation(summary = "获得用户信息")
+    public CommonResult<String> getAi() {
+        UserInformationDO userInformation = userInformationService.getAi();
+        StringBuffer sb = new StringBuffer();
+        if (userInformation != null) {
+            if (userInformation.getBusinessLicenseInformation() != null) {
+                sb.append("营业执照信息:");
+                sb.append(userInformation.getBusinessLicenseInformation());
+            } else {
+                sb.append("营业执照信息:");
+                sb.append("未提取到");
+            }
+            
+            if (userInformation.getCreditInformation() != null) {
+                sb.append("个人中心信息:");
+                sb.append(userInformation.getCreditInformation());
+            } else {
+                sb.append("个人中心信息:");
+                sb.append("未提取到");
+            }
+            return success(sb.toString());
+        }
+        return success("");
+    }
+    
     @GetMapping("/page")
     @Operation(summary = "获得用户信息分页")
     public CommonResult<PageResult<UserInformationRespVO>> getUserInformationPage(@Valid UserInformationPageReqVO pageReqVO) {

+ 2 - 0
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/userinformation/UserInformationService.java

@@ -43,6 +43,8 @@ public interface UserInformationService {
      */
     UserInformationDO getUserInformation(Long id);
     
+    UserInformationDO getAi();
+    
     /**
      * 获得用户信息分页
      *

+ 43 - 1
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/userinformation/UserInformationServiceImpl.java

@@ -2,11 +2,17 @@ package cn.iocoder.yudao.module.member.service.userinformation;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.dict.core.AiFrameworkUtils;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.member.controller.admin.userinformation.vo.UserInformationPageReqVO;
 import cn.iocoder.yudao.module.member.controller.admin.userinformation.vo.UserInformationSaveReqVO;
+import cn.iocoder.yudao.module.member.dal.dataobject.userbusinesslicense.UserBusinessLicenseDO;
 import cn.iocoder.yudao.module.member.dal.dataobject.userinformation.UserInformationDO;
+import cn.iocoder.yudao.module.member.dal.dataobject.userpersonalcredit.UserPersonalCreditDO;
+import cn.iocoder.yudao.module.member.dal.mysql.userbusinesslicense.UserBusinessLicenseMapper;
 import cn.iocoder.yudao.module.member.dal.mysql.userinformation.UserInformationMapper;
+import cn.iocoder.yudao.module.member.dal.mysql.userpersonalcredit.UserPersonalCreditMapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -25,7 +31,10 @@ public class UserInformationServiceImpl implements UserInformationService {
     
     @Resource
     private UserInformationMapper userInformationMapper;
-    
+    @Resource
+    private UserPersonalCreditMapper userPersonalCreditMapper;
+    @Resource
+    private UserBusinessLicenseMapper userBusinessLicenseMapper;
     @Override
     public Long createUserInformation(UserInformationSaveReqVO createReqVO) {
         // 插入
@@ -64,6 +73,39 @@ public class UserInformationServiceImpl implements UserInformationService {
         return userInformationMapper.selectById(id);
     }
     
+    @Override
+    public UserInformationDO getAi() {
+        Long userId = SecurityFrameworkUtils.getLoginUserId();
+        UserInformationDO userInformation = userInformationMapper.selectOne(UserInformationDO::getUserId,
+                SecurityFrameworkUtils.getLoginUserId());
+        
+        if (userInformation != null) {
+            return userInformation;
+        } else {
+            userInformation = new UserInformationDO();
+            UserPersonalCreditDO userPersonalCreditDO =
+                    userPersonalCreditMapper.selectOne(new QueryWrapper<UserPersonalCreditDO>()
+                            .eq("user_id", userId)
+                            .orderByDesc("create_time")
+                            .last("limit 1"));
+            if (userPersonalCreditDO != null) {
+                userInformation.setCreditInformation(AiFrameworkUtils.getAi("个人征信MD", userPersonalCreditDO.toString()));
+            }
+            UserBusinessLicenseDO userBusinessLicenseDO =
+                    userBusinessLicenseMapper.selectOne(new QueryWrapper<UserBusinessLicenseDO>()
+                            .eq("creator", userId)
+                            .orderByDesc("create_time")
+                            .last("limit 1"));
+            if (userBusinessLicenseDO != null) {
+                userInformation.setBusinessLicenseInformation(AiFrameworkUtils.getAi("营业执照MD",
+                        userBusinessLicenseDO.toString()));
+            }
+            userInformation.setUserId(SecurityFrameworkUtils.getLoginUserId());
+            userInformationMapper.insert(userInformation);
+        }
+        return userInformation;
+    }
+    
     @Override
     public PageResult<UserInformationDO> getUserInformationPage(UserInformationPageReqVO pageReqVO) {
         return userInformationMapper.selectPage(pageReqVO);