吉安感知网项目-后端
linwei
2026-02-28 465580e3b8c4e26b4dd8f35524c0cd2fc87d9652
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.sxkj.gd.airesults.service.impl;
 
import org.springblade.core.tool.utils.StringUtil;
import org.sxkj.gd.airesults.entity.GdAiResultsEntity;
import org.sxkj.gd.airesults.param.GdAiResultsPageParam;
import org.sxkj.gd.airesults.vo.GdAiResultsVO;
import org.sxkj.gd.airesults.excel.GdAiResultsExcel;
import org.sxkj.gd.airesults.mapper.GdAiResultsMapper;
import org.sxkj.gd.airesults.service.IGdAiResultsService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
 
import java.util.List;
 
/**
 * AI成果表 服务实现类
 *
 * @author lw
 * @since 2026-02-28
 */
@Service
public class GdAiResultsServiceImpl extends BaseServiceImpl<GdAiResultsMapper, GdAiResultsEntity> implements IGdAiResultsService {
 
    /**
     * 自定义分页查询
     *
     * @param page 分页对象
     * @param gdAiResults 查询参数
     * @return AI成果分页结果
     */
    @Override
    public IPage<GdAiResultsVO> selectGdAiResultsPage(IPage<GdAiResultsVO> page, GdAiResultsPageParam gdAiResults) {
        return page.setRecords(baseMapper.selectGdAiResultsPage(page, gdAiResults));
    }
 
    /**
     * 导出数据
     *
     * @param queryWrapper 查询条件
     * @return AI成果Excel列表
     */
    @Override
    public List<GdAiResultsExcel> exportGdAiResults(Wrapper<GdAiResultsEntity> queryWrapper) {
        List<GdAiResultsExcel> gdAiResultsList = baseMapper.exportGdAiResults(queryWrapper);
        return gdAiResultsList;
    }
 
    /**
     * 新增或修改AI成果
     *
     * @param entity AI成果实体对象
     * @return 保存或更新成功返回true,失败返回false
     */
    @Override
    public boolean saveOrUpdateAiResults(GdAiResultsEntity entity) {
        // 步骤1:校验AI流请求key是否为空
        if (StringUtil.isNotBlank(entity.getAiReqKey())) {
            // 步骤2:查询数据库中是否存在相同AI流请求key的记录
            Long count = baseMapper.selectCount(
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<GdAiResultsEntity>()
                    .eq(GdAiResultsEntity::getAiReqKey, entity.getAiReqKey())
                    .ne(entity.getId() != null, GdAiResultsEntity::getId, entity.getId())
            );
            // 步骤3:如果存在重复的AI流请求key,抛出异常
            if (count > 0) {
                throw new RuntimeException("AI流请求key已存在,请使用其他key");
            }
        }
        // 步骤4:执行保存或更新操作
        return saveOrUpdate(entity);
    }
}