dev-chenjiajian #1

Merged
ChenJiaJian merged 8 commits from dev-chenjiajian into master 2026-01-17 16:31:39 +08:00
13 changed files with 246 additions and 11 deletions
Showing only changes of commit 7aad37af87 - Show all commits

View File

@ -19,7 +19,7 @@ import java.util.List;
* @since 2025-12-30
*/
@Data
@TableName("mp_activity_info_collection")
@TableName(value = "mp_activity_info_collection", autoResultMap = true)
@Schema(name = "MpActivityInfoCollectionEntity对象", description = "活动信息收集表")
public class MpActivityInfoCollectionEntity extends BaseEntity {

View File

@ -0,0 +1,63 @@
package com.seer.teach.mp.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.seer.teach.common.entity.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDate;
/**
* <p>
*
* </p>
*
* @author 嘉多宝宝
* @since 2026-01-17
*/
@Getter
@Setter
@TableName("mp_test_child_character")
@Schema(name = "MpTestChildCharacterEntity对象", description = "测试孩子性格")
public class MpTestChildCharacterEntity extends BaseEntity {
@TableField("parent_id")
@Schema(description = "家长ID")
private Integer parentId;
@TableField("grade")
@Schema(description = "年级")
private String grade;
@TableField("constellation")
@Schema(description = "星座")
private String constellation;
@TableField("child_birth_date")
@Schema(description = "出生年月")
private LocalDate childBirthDate;
@TableField("child_gender")
@Schema(description = "孩子性别(男,女)")
private String childGender;
@TableField("character_analysis")
@Schema(description = "性格分析结果")
private String characterAnalysis;
@TableField("character_traits")
@Schema(description = "性格特征")
private String characterTraits;
@TableField("suggestions")
@Schema(description = "建议")
private String suggestions;
@TableField("character_type")
@Schema(description = "性格类型")
private String characterType;
}

View File

@ -0,0 +1,16 @@
package com.seer.teach.mp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.seer.teach.mp.entity.MpTestChildCharacterEntity;
/**
* <p>
* Mapper 接口
* </p>
*
* @author 嘉多宝宝
* @since 2026-01-17
*/
public interface MpTestChildCharacterMapper extends BaseMapper<MpTestChildCharacterEntity> {
}

View File

@ -0,0 +1,5 @@
<?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="com.seer.teach.mp.mapper.MpTestChildCharacterMapper">
</mapper>

View File

@ -0,0 +1,24 @@
--
DROP TABLE IF EXISTS `mp_test_child_character`;
CREATE TABLE `mp_test_child_character`(
`id` int NOT NULL AUTO_INCREMENT,
`parent_id` int NULL DEFAULT NULL COMMENT '家长Id',
`grade` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '年级',
`constellation` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '星座',
`child_birth_date` date NULL DEFAULT NULL COMMENT '出生年月',
`child_gender` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '孩子性别(男,女)',
`character_analysis` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格分析结果',
`character_traits` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格特征',
`suggestions` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '建议',
`character_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格类型',
`deleted` int NOT NULL COMMENT '逻辑删除(0-正常1-已删除)',
`create_time` datetime NOT NULL COMMENT '创建时间',
`create_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '创建人',
`update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
`update_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '修改人',
`tenant_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '租户Id',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
SET
FOREIGN_KEY_CHECKS = 1;

View File

@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.mp.app.controller.req.AppMpSignUpActivityReq;
import com.seer.teach.mp.app.controller.req.TestChildCharacterReq;
import com.seer.teach.mp.app.controller.resp.AppChildCharacterResp;
import com.seer.teach.mp.app.controller.resp.AppMpSignUpActivityResp;
import com.seer.teach.mp.app.controller.resp.TestChildCharacterResp;
import com.seer.teach.mp.app.service.AppParentAgentActivityService;
@ -13,13 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 家长参与代理商活动控制器 - 应用端
@ -66,9 +61,17 @@ public class AppParentAgentActivityController {
@PostMapping("/test-child-character")
@SaCheckLogin
@Operation(summary = "测试孩子性格")
@Operation(summary = "AI测试孩子性格")
public ResultBean<TestChildCharacterResp> testChildCharacter(@RequestBody @Valid TestChildCharacterReq request) {
Integer parentId = StpUtil.getLoginIdAsInt();
return ResultBean.success(appParentAgentActivityService.testChildCharacter(request, parentId));
}
@GetMapping("/get-child-character")
@SaCheckLogin
@Operation(summary = "获取AI测试性格报告")
public ResultBean<AppChildCharacterResp> getChildCharacter() {
Integer parentId = StpUtil.getLoginIdAsInt();
return ResultBean.success(appParentAgentActivityService.getChildCharacter(parentId));
}
}

View File

@ -1,9 +1,9 @@
package com.seer.teach.mp.app.controller.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
@Schema(description = "测试孩子性格请求对象")

View File

@ -0,0 +1,35 @@
package com.seer.teach.mp.app.controller.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
@Schema(description = "孩子性格响应对象")
@Data
public class AppChildCharacterResp {
@Schema(description = "性格分析结果")
private String characterAnalysis;
@Schema(description = "性格特征")
private String characterTraits;
@Schema(description = "建议")
private String suggestions;
@Schema(description = "性格类型")
private String characterType;
@Schema(description = "年级")
private String grade;
@Schema(description = "星座")
private String constellation;
@Schema(description = "出生年月")
private LocalDate childBirthDate;
@Schema(description = "孩子性别(男,女)")
private String childGender;
}

View File

@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
import java.util.List;
@Schema(name = "AppMpSignUpActivityResp", description = "家长报名参加代理商活动信息Resp")
@Data
@ -54,6 +55,12 @@ public class AppMpSignUpActivityResp {
@Schema(description = "薄弱科目")
private String weakSubject;
@Schema(description = "薄弱科目")
private List<Integer> weakSubjectIds;
@Schema(description = "优势科目")
private List<Integer> strongSubjectIds;
@Schema(description = "代理商拨打电话联系家长的次数")
private Integer contactCallCount;
}

View File

@ -1,8 +1,10 @@
package com.seer.teach.mp.app.convert;
import com.seer.teach.mp.app.controller.req.AppMpSignUpActivityReq;
import com.seer.teach.mp.app.controller.resp.AppChildCharacterResp;
import com.seer.teach.mp.app.controller.resp.AppMpSignUpActivityResp;
import com.seer.teach.mp.entity.MpActivityInfoCollectionEntity;
import com.seer.teach.mp.entity.MpTestChildCharacterEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@ -19,6 +21,8 @@ public interface AppMpActivityInfoCollectionConvert {
*/
@Mapping(source = "mobile", target = "mobile")
@Mapping(source = "contactCallCount", target = "contactCallCount")
@Mapping(source = "weakSubjectIds", target = "weakSubjectIds")
@Mapping(source = "strongSubjectIds", target = "strongSubjectIds")
AppMpSignUpActivityResp convert2Resp(MpActivityInfoCollectionEntity entity);
@ -28,4 +32,7 @@ public interface AppMpActivityInfoCollectionConvert {
* @return 实体
*/
MpActivityInfoCollectionEntity convertOne2Entity(AppMpSignUpActivityReq request);
AppChildCharacterResp convert2ChildCharacterResp(MpTestChildCharacterEntity entity);
}

View File

@ -5,6 +5,7 @@ import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.mp.app.controller.req.AppMpSignUpActivityReq;
import com.seer.teach.mp.app.controller.req.TestChildCharacterReq;
import com.seer.teach.mp.app.controller.resp.AppChildCharacterResp;
import com.seer.teach.mp.app.controller.resp.AppMpSignUpActivityResp;
import com.seer.teach.mp.app.controller.resp.TestChildCharacterResp;
import com.seer.teach.mp.app.convert.AppMpActivityInfoCollectionConvert;
@ -37,6 +38,8 @@ public class AppParentAgentActivityService implements IAppParentAgentActivitySer
private final AiModelCallService aiModelCallService;
private final IMpTestChildCharacterService mpTestChildCharacterService;
/**
* 报名活动
*
@ -181,6 +184,13 @@ public class AppParentAgentActivityService implements IAppParentAgentActivitySer
// 获取AI返回的内容
String content = response.getChoices().get(0).getMessage().getContent();
result = parseAiResponse(content);
// 如果AI调用成功则将测试结果保存到数据库中
MpTestChildCharacterEntity entity = getCharacterEntity(request, parentId, result);
boolean save = mpTestChildCharacterService.save(entity);
if (save) {
log.info("保存性格测试结果成功");
}
} else {
// 如果AI调用失败返回默认响应
result.setCharacterAnalysis("暂时无法分析孩子的性格,请稍后重试。");
@ -193,6 +203,20 @@ public class AppParentAgentActivityService implements IAppParentAgentActivitySer
return result;
}
private MpTestChildCharacterEntity getCharacterEntity(TestChildCharacterReq request, Integer parentId, TestChildCharacterResp result) {
MpTestChildCharacterEntity entity = new MpTestChildCharacterEntity();
entity.setParentId(parentId);
entity.setConstellation(request.getConstellation());
entity.setGrade(request.getGrade());
entity.setChildBirthDate(request.getChildBirthDate());
entity.setChildGender(request.getChildGender());
entity.setCharacterType(result.getCharacterType());
entity.setCharacterAnalysis(result.getCharacterAnalysis());
entity.setCharacterTraits(result.getCharacterTraits());
entity.setSuggestions(result.getSuggestions());
return entity;
}
/**
* 构建性格测试的提示词
*
@ -281,5 +305,20 @@ public class AppParentAgentActivityService implements IAppParentAgentActivitySer
}
/**
* 获取孩子性格返回结果
* @param parentId 家长ID
* @return 孩子性格返回结果
*/
public AppChildCharacterResp getChildCharacter(Integer parentId) {
MpTestChildCharacterEntity one = mpTestChildCharacterService.lambdaQuery()
.eq(MpTestChildCharacterEntity::getParentId, parentId)
.orderByDesc(MpTestChildCharacterEntity::getCreateTime)
.last("limit 1") // 获取最新的一条数据
.one();
if (one == null) {
return new AppChildCharacterResp();
}
return AppMpActivityInfoCollectionConvert.INSTANCE.convert2ChildCharacterResp(one);
}
}

View File

@ -0,0 +1,16 @@
package com.seer.teach.mp.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.seer.teach.mp.entity.MpTestChildCharacterEntity;
/**
* <p>
* 服务类
* </p>
*
* @author 嘉多宝宝
* @since 2026-01-17
*/
public interface IMpTestChildCharacterService extends IService<MpTestChildCharacterEntity> {
}

View File

@ -0,0 +1,20 @@
package com.seer.teach.mp.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.mp.entity.MpTestChildCharacterEntity;
import com.seer.teach.mp.mapper.MpTestChildCharacterMapper;
import com.seer.teach.mp.service.IMpTestChildCharacterService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author 嘉多宝宝
* @since 2026-01-17
*/
@Service
public class MpTestChildCharacterServiceImpl extends ServiceImpl<MpTestChildCharacterMapper, MpTestChildCharacterEntity> implements IMpTestChildCharacterService {
}