| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.*; |
| | | import cc.mrbird.febs.ai.mapper.AiProductQuestionJobMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiProductQuestionMapper; |
| | | import cc.mrbird.febs.ai.req.AiProductQuestionAiDto; |
| | | import cc.mrbird.febs.ai.service.AiProductQuestionItemService; |
| | |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.mall.entity.MallMember; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | |
| | | public class AiProductQuestionServiceImpl extends ServiceImpl<AiProductQuestionMapper, AiProductQuestion> implements AiProductQuestionService { |
| | | |
| | | private final AiProductQuestionMapper aiProductQuestionMapper; |
| | | private final AiProductQuestionJobMapper aiProductQuestionJobMapper; |
| | | private final AiProductQuestionItemService aiProductQuestionItemService; |
| | | private final AiService aiService; |
| | | |
| | |
| | | if (StrUtil.isNotEmpty(dto.getCompanyId())){ |
| | | query.eq(AiProductQuestion::getCompanyId, dto.getCompanyId()); |
| | | } |
| | | if (StrUtil.isNotEmpty(dto.getProductCategoryId())){ |
| | | query.eq(AiProductQuestion::getProductCategoryId, dto.getProductCategoryId()); |
| | | } |
| | | query.ne(AiProductQuestion::getState, 2); |
| | | query.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | Page<AiProductQuestion> pages = aiProductQuestionMapper.selectPage(page, query); |
| | | return pages; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AiProductQuestionJob> listJobInPage(AiProductQuestionJob dto, QueryRequest request) { |
| | | Page<AiProductQuestionJob> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | LambdaQueryWrapper<AiProductQuestionJob> query = Wrappers.lambdaQuery(AiProductQuestionJob.class); |
| | | if (StrUtil.isNotEmpty(dto.getCompanyId())){ |
| | | query.eq(AiProductQuestionJob::getCompanyId, dto.getCompanyId()); |
| | | } |
| | | if (StrUtil.isNotEmpty(dto.getProductCategoryId())){ |
| | | query.eq(AiProductQuestionJob::getProductCategoryId, dto.getProductCategoryId()); |
| | | } |
| | | query.orderByDesc(AiProductQuestionJob::getCreatedTime); |
| | | Page<AiProductQuestionJob> pages = aiProductQuestionJobMapper.selectPage(page, query); |
| | | return pages; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse stateUpdate(String ids, Integer type) { |
| | | if (StrUtil.isEmpty(ids)) { |
| | | throw new FebsException("参数错误"); |
| | | } |
| | | List<String> idList = StrUtil.split(ids, ','); |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductQuestion.class) |
| | | .set(AiProductQuestion::getState, type) |
| | | .set(AiProductQuestion::getUpdatedTime, new Date()) |
| | | .in(AiProductQuestion::getId, idList)); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse delete(String id) { |
| | | AiProductQuestion entity = this.getById(id); |
| | | if(ObjectUtil.isNotNull( entity)){ |
| | |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse aiAddV2(AiProductQuestionAiDto dto) { |
| | | String companyId = dto.getCompanyId(); |
| | | String productCategoryId = dto.getProductCategoryId(); |
| | | Integer questionCnt = dto.getQuestionCnt(); |
| | | String query = dto.getQuery(); |
| | | Integer difficulty = dto.getDifficulty(); |
| | | Date createdTime = new Date(); |
| | | AiProductQuestionJob aiProductQuestionJob = new AiProductQuestionJob(); |
| | | aiProductQuestionJob.setId(UUID.getSimpleUUIDString()); |
| | | aiProductQuestionJob.setCompanyId(companyId); |
| | | aiProductQuestionJob.setProductCategoryId(productCategoryId); |
| | | aiProductQuestionJob.setTitle(query); |
| | | aiProductQuestionJob.setQuestionCnt(questionCnt); |
| | | aiProductQuestionJob.setDifficulty(difficulty); |
| | | aiProductQuestionJob.setCreatedTime(createdTime); |
| | | aiProductQuestionJobMapper.insert(aiProductQuestionJob); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 解析AI返回的包含问题和答案的JSON字符串 |
| | | * @param aiResponse AI返回的原始响应字符串 |