【同步】BOOT 和 CLOUD 的功能(BPM)

pull/171/MERGE
YunaiV 2025-03-30 11:10:31 +08:00
parent 278f4838d8
commit b4c0652dfa
59 changed files with 3227 additions and 136 deletions

View File

@ -20,7 +20,7 @@ import java.util.function.Consumer;
*/
public class MPJLambdaWrapperX<T> extends MPJLambdaWrapper<T> {
public MPJLambdaWrapperX<T> likeIfPresent(SFunction<T, ?> column, String val) {
public <R> MPJLambdaWrapperX<T> likeIfPresent(SFunction<R, ?> column, String val) {
MPJWrappers.lambdaJoin().like(column, val);
if (StringUtils.hasText(val)) {
return (MPJLambdaWrapperX<T>) super.like(column, val);
@ -28,63 +28,63 @@ public class MPJLambdaWrapperX<T> extends MPJLambdaWrapper<T> {
return this;
}
public MPJLambdaWrapperX<T> inIfPresent(SFunction<T, ?> column, Collection<?> values) {
public <R> MPJLambdaWrapperX<T> inIfPresent(SFunction<R, ?> column, Collection<?> values) {
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
return (MPJLambdaWrapperX<T>) super.in(column, values);
}
return this;
}
public MPJLambdaWrapperX<T> inIfPresent(SFunction<T, ?> column, Object... values) {
public <R> MPJLambdaWrapperX<T> inIfPresent(SFunction<R, ?> column, Object... values) {
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
return (MPJLambdaWrapperX<T>) super.in(column, values);
}
return this;
}
public MPJLambdaWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> eqIfPresent(SFunction<R, ?> column, Object val) {
if (ObjectUtil.isNotEmpty(val)) {
return (MPJLambdaWrapperX<T>) super.eq(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> neIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> neIfPresent(SFunction<R, ?> column, Object val) {
if (ObjectUtil.isNotEmpty(val)) {
return (MPJLambdaWrapperX<T>) super.ne(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> gtIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> gtIfPresent(SFunction<R, ?> column, Object val) {
if (val != null) {
return (MPJLambdaWrapperX<T>) super.gt(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> geIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> geIfPresent(SFunction<R, ?> column, Object val) {
if (val != null) {
return (MPJLambdaWrapperX<T>) super.ge(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> ltIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> ltIfPresent(SFunction<R, ?> column, Object val) {
if (val != null) {
return (MPJLambdaWrapperX<T>) super.lt(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> leIfPresent(SFunction<T, ?> column, Object val) {
public <R> MPJLambdaWrapperX<T> leIfPresent(SFunction<R, ?> column, Object val) {
if (val != null) {
return (MPJLambdaWrapperX<T>) super.le(column, val);
}
return this;
}
public MPJLambdaWrapperX<T> betweenIfPresent(SFunction<T, ?> column, Object val1, Object val2) {
public <R> MPJLambdaWrapperX<T> betweenIfPresent(SFunction<R, ?> column, Object val1, Object val2) {
if (val1 != null && val2 != null) {
return (MPJLambdaWrapperX<T>) super.between(column, val1, val2);
}
@ -97,7 +97,7 @@ public class MPJLambdaWrapperX<T> extends MPJLambdaWrapper<T> {
return this;
}
public MPJLambdaWrapperX<T> betweenIfPresent(SFunction<T, ?> column, Object[] values) {
public <R> MPJLambdaWrapperX<T> betweenIfPresent(SFunction<R, ?> column, Object[] values) {
Object val1 = ArrayUtils.get(values, 0);
Object val2 = ArrayUtils.get(values, 1);
return betweenIfPresent(column, val1, val2);
@ -310,4 +310,4 @@ public class MPJLambdaWrapperX<T> extends MPJLambdaWrapper<T> {
return this;
}
}
}

View File

@ -61,4 +61,8 @@ public interface ErrorCodeConstants {
ErrorCode TOOL_NOT_EXISTS = new ErrorCode(1_040_010_000, "工具不存在");
ErrorCode TOOL_NAME_NOT_EXISTS = new ErrorCode(1_040_010_001, "工具({})找不到 Bean");
// ========== AI 工作流 1-040-011-000 ==========
ErrorCode WORKFLOW_NOT_EXISTS = new ErrorCode(1_040_011_000, "工作流不存在");
ErrorCode WORKFLOW_CODE_EXISTS = new ErrorCode(1_040_011_001, "工作流标识已存在");
}

View File

@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.ai.controller.admin.workflow;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.*;
import cn.iocoder.yudao.module.ai.dal.dataobject.workflow.AiWorkflowDO;
import cn.iocoder.yudao.module.ai.service.workflow.AiWorkflowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - AI 工作流")
@RestController
@RequestMapping("/ai/workflow")
@Slf4j
public class AiWorkflowController {
@Resource
private AiWorkflowService workflowService;
@PostMapping("/create")
@Operation(summary = "创建 AI 工作流")
@PreAuthorize("@ss.hasPermission('ai:workflow:create')")
public CommonResult<Long> createWorkflow(@Valid @RequestBody AiWorkflowSaveReqVO createReqVO) {
return success(workflowService.createWorkflow(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新 AI 工作流")
@PreAuthorize("@ss.hasPermission('ai:workflow:update')")
public CommonResult<Boolean> updateWorkflow(@Valid @RequestBody AiWorkflowSaveReqVO updateReqVO) {
workflowService.updateWorkflow(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除 AI 工作流")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('ai:workflow:delete')")
public CommonResult<Boolean> deleteWorkflow(@RequestParam("id") Long id) {
workflowService.deleteWorkflow(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得 AI 工作流")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('ai:workflow:query')")
public CommonResult<AiWorkflowRespVO> getWorkflow(@RequestParam("id") Long id) {
AiWorkflowDO workflow = workflowService.getWorkflow(id);
return success(BeanUtils.toBean(workflow, AiWorkflowRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得 AI 工作流分页")
@PreAuthorize("@ss.hasPermission('ai:workflow:query')")
public CommonResult<PageResult<AiWorkflowRespVO>> getWorkflowPage(@Valid AiWorkflowPageReqVO pageReqVO) {
PageResult<AiWorkflowDO> pageResult = workflowService.getWorkflowPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AiWorkflowRespVO.class));
}
@PostMapping("/test")
@Operation(summary = "测试 AI 工作流")
@PreAuthorize("@ss.hasPermission('ai:workflow:test')")
public CommonResult<Object> testWorkflow(@Valid @RequestBody AiWorkflowTestReqVO testReqVO) {
return success(workflowService.testWorkflow(testReqVO));
}
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.ai.controller.admin.workflow.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - AI 工作流分页 Request VO")
@Data
public class AiWorkflowPageReqVO extends PageParam {
@Schema(description = "名称", example = "工作流")
private String name;
@Schema(description = "标识", example = "FLOW")
private String code;
@Schema(description = "状态", example = "1")
@InEnum(CommonStatusEnum.class)
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.ai.controller.admin.workflow.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - AI 工作流 Response VO")
@Data
public class AiWorkflowRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "工作流标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "FLOW")
private String code;
@Schema(description = "工作流名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "工作流")
private String name;
@Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "工作流")
private String remark;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "工作流模型 JSON", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
private String graph;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.ai.controller.admin.workflow.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Schema(description = "管理后台 - AI 工作流新增/修改 Request VO")
@Data
public class AiWorkflowSaveReqVO {
@Schema(description = "编号", example = "1")
private Long id;
@Schema(description = "工作流标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "FLOW")
@NotEmpty(message = "工作流标识不能为空")
private String code;
@Schema(description = "工作流名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "工作流")
@NotEmpty(message = "工作流名称不能为空")
private String name;
@Schema(description = "备注", example = "FLOW")
private String remark;
@Schema(description = "工作流模型", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
@NotEmpty(message = "工作流模型不能为空")
private String graph;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "FLOW")
@NotNull(message = "状态不能为空")
private Integer status;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.ai.controller.admin.workflow.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.Map;
@Schema(description = "管理后台 - AI 工作流测试 Request VO")
@Data
public class AiWorkflowTestReqVO {
@Schema(description = "工作流模型", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
@NotEmpty(message = "工作流模型不能为空")
private String graph;
@Schema(description = "参数", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
private Map<String, Object> params;
}

View File

@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.ai.dal.dataobject.workflow;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* AI DO
*
* @author lesan
*/
@TableName(value = "ai_workflow", autoResultMap = true)
@KeySequence("ai_workflow") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class AiWorkflowDO extends BaseDO {
/**
*
*/
@TableId
private Long id;
/**
*
*/
private String name;
/**
*
*/
private String code;
/**
* JSON
*/
private String graph;
/**
*
*/
private String remark;
/**
*
*
* {@link CommonStatusEnum}
*/
private Integer status;
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.ai.dal.mysql.workflow;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowPageReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.workflow.AiWorkflowDO;
import org.apache.ibatis.annotations.Mapper;
/**
* AI Mapper
*
* @author lesan
*/
@Mapper
public interface AiWorkflowMapper extends BaseMapperX<AiWorkflowDO> {
default AiWorkflowDO selectByCode(String code) {
return selectOne(AiWorkflowDO::getCode, code);
}
default PageResult<AiWorkflowDO> selectPage(AiWorkflowPageReqVO pageReqVO) {
return selectPage(pageReqVO, new LambdaQueryWrapperX<AiWorkflowDO>()
.eqIfPresent(AiWorkflowDO::getStatus, pageReqVO.getStatus())
.likeIfPresent(AiWorkflowDO::getName, pageReqVO.getName())
.likeIfPresent(AiWorkflowDO::getCode, pageReqVO.getCode())
.betweenIfPresent(AiWorkflowDO::getCreateTime, pageReqVO.getCreateTime()));
}
}

View File

@ -11,6 +11,7 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpUtil;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageOptions;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO;
@ -144,7 +145,12 @@ public class AiImageServiceImpl implements AiImageService {
.withStyle(MapUtil.getStr(draw.getOptions(), "style")) // 风格
.withResponseFormat("b64_json")
.build();
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) {
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.SILICON_FLOW.getPlatform())) {
// https://docs.siliconflow.cn/cn/api-reference/images/images-generations
return SiliconFlowImageOptions.builder().model(model.getModel())
.height(draw.getHeight()).width(draw.getWidth())
.build();
} else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) {
// https://platform.stability.ai/docs/api-reference#tag/SDXL-and-SD1.6/operation/textToImage
// https://platform.stability.ai/docs/api-reference#tag/Text-to-Image/operation/textToImage
return StabilityAiImageOptions.builder().model(model.getModel())

View File

@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.ai.service.workflow;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowPageReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowSaveReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowTestReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.workflow.AiWorkflowDO;
import jakarta.validation.Valid;
/**
* AI Service
*
* @author lesan
*/
public interface AiWorkflowService {
/**
* AI
*
* @param createReqVO
* @return
*/
Long createWorkflow(@Valid AiWorkflowSaveReqVO createReqVO);
/**
* AI
*
* @param updateReqVO
*/
void updateWorkflow(@Valid AiWorkflowSaveReqVO updateReqVO);
/**
* AI
*
* @param id
*/
void deleteWorkflow(Long id);
/**
* AI
*
* @param id
* @return AI
*/
AiWorkflowDO getWorkflow(Long id);
/**
* AI
*
* @param pageReqVO
* @return AI
*/
PageResult<AiWorkflowDO> getWorkflowPage(AiWorkflowPageReqVO pageReqVO);
/**
* AI
*
* @param testReqVO
*/
Object testWorkflow(AiWorkflowTestReqVO testReqVO);
}

View File

@ -0,0 +1,150 @@
package cn.iocoder.yudao.module.ai.service.workflow;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowPageReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowSaveReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowTestReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO;
import cn.iocoder.yudao.module.ai.dal.dataobject.workflow.AiWorkflowDO;
import cn.iocoder.yudao.module.ai.dal.mysql.workflow.AiWorkflowMapper;
import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import dev.tinyflow.core.Tinyflow;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WORKFLOW_CODE_EXISTS;
import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WORKFLOW_NOT_EXISTS;
/**
* AI Service
*
* @author lesan
*/
@Service
@Slf4j
public class AiWorkflowServiceImpl implements AiWorkflowService {
@Resource
private AiWorkflowMapper workflowMapper;
@Resource
private AiApiKeyService apiKeyService;
@Override
public Long createWorkflow(AiWorkflowSaveReqVO createReqVO) {
validateWorkflowForCreateOrUpdate(null, createReqVO.getCode());
AiWorkflowDO workflow = BeanUtils.toBean(createReqVO, AiWorkflowDO.class);
workflowMapper.insert(workflow);
return workflow.getId();
}
@Override
public void updateWorkflow(AiWorkflowSaveReqVO updateReqVO) {
validateWorkflowForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getCode());
AiWorkflowDO workflow = BeanUtils.toBean(updateReqVO, AiWorkflowDO.class);
workflowMapper.updateById(workflow);
}
@Override
public void deleteWorkflow(Long id) {
validateWorkflowExists(id);
workflowMapper.deleteById(id);
}
@Override
public AiWorkflowDO getWorkflow(Long id) {
return workflowMapper.selectById(id);
}
@Override
public PageResult<AiWorkflowDO> getWorkflowPage(AiWorkflowPageReqVO pageReqVO) {
return workflowMapper.selectPage(pageReqVO);
}
@Override
public Object testWorkflow(AiWorkflowTestReqVO testReqVO) {
Map<String, Object> variables = testReqVO.getParams();
Tinyflow tinyflow = parseFlowParam(testReqVO.getGraph());
return tinyflow.toChain().executeForResult(variables);
}
private void validateWorkflowForCreateOrUpdate(Long id, String code) {
validateWorkflowExists(id);
validateCodeUnique(id, code);
}
private void validateWorkflowExists(Long id) {
if (ObjUtil.isNull(id)) {
return;
}
AiWorkflowDO workflow = workflowMapper.selectById(id);
if (ObjUtil.isNull(workflow)) {
throw exception(WORKFLOW_NOT_EXISTS);
}
}
private void validateCodeUnique(Long id, String code) {
if (StrUtil.isBlank(code)) {
return;
}
AiWorkflowDO workflow = workflowMapper.selectByCode(code);
if (ObjUtil.isNull(workflow)) {
return;
}
if (ObjUtil.isNull(id)) {
throw exception(WORKFLOW_CODE_EXISTS);
}
if (ObjUtil.notEqual(workflow.getId(), id)) {
throw exception(WORKFLOW_CODE_EXISTS);
}
}
private Tinyflow parseFlowParam(String graph) {
// TODO @lesan可以使用 jackson 哇?
JSONObject json = JSONObject.parseObject(graph);
JSONArray nodeArr = json.getJSONArray("nodes");
Tinyflow tinyflow = new Tinyflow(json.toJSONString());
for (int i = 0; i < nodeArr.size(); i++) {
JSONObject node = nodeArr.getJSONObject(i);
switch (node.getString("type")) {
case "llmNode":
JSONObject data = node.getJSONObject("data");
AiApiKeyDO apiKey = apiKeyService.getApiKey(data.getLong("llmId"));
switch (apiKey.getPlatform()) {
// TODO @lesan 需要讨论一下这里怎么弄
// TODO @lesan llmId 对应 model 的编号如何?这样的话,就是 apiModelService 提供一个获取 LLM 的方法。然后,创建的方法,也在 AiModelFactory 提供。可以先接个 deepseek 先。deepseek yyds
case "OpenAI":
break;
case "Ollama":
break;
case "YiYan":
break;
case "XingHuo":
break;
case "TongYi":
break;
case "DeepSeek":
break;
case "ZhiPu":
break;
}
break;
case "internalNode":
break;
default:
break;
}
}
return tinyflow;
}
}

View File

@ -169,15 +169,19 @@ yudao:
appKey: 75b161ed2aef4719b275d6e7f2a4d4cd
secretKey: YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz
model: generalv3.5
baichuan: # 百川智能
enable: true
api-key: sk-abc
model: Baichuan4-Turbo
midjourney:
enable: true
# base-url: https://api.holdai.top/mj-relax/mj
# base-url: https://api.holdai.top/mj-relax/mj
base-url: https://api.holdai.top/mj
api-key: sk-dZEPiVaNcT3FHhef51996bAa0bC74806BeAb620dA5Da10Bf
notify-url: http://java.nat300.top/admin-api/ai/image/midjourney/notify
suno:
enable: true
# base-url: https://suno-55ishh05u-status2xxs-projects.vercel.app
# base-url: https://suno-55ishh05u-status2xxs-projects.vercel.app
base-url: http://127.0.0.1:3001
--- #################### 芋道相关配置 ####################

View File

@ -15,6 +15,7 @@
<description>AI 大模型拓展,接入国内外大模型</description>
<properties>
<spring-ai.version>1.0.0-M6</spring-ai.version>
<tinyflow.version>1.0.0-rc.3</tinyflow.version>
</properties>
<dependencies>
@ -106,6 +107,13 @@
<version>${spring-ai.version}</version>
</dependency>
<!-- TinyFlowAI 工作流 -->
<dependency>
<groupId>dev.tinyflow</groupId>
<artifactId>tinyflow-java-core</artifactId>
<version>${tinyflow.version}</version>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -4,10 +4,12 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.ai.core.factory.AiModelFactory;
import cn.iocoder.yudao.framework.ai.core.factory.AiModelFactoryImpl;
import cn.iocoder.yudao.framework.ai.core.model.baichuan.BaiChuanChatModel;
import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
import cn.iocoder.yudao.framework.ai.core.model.hunyuan.HunYuanChatModel;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowApiConstants;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
@ -113,11 +115,11 @@ public class YudaoAiAutoConfiguration {
public SiliconFlowChatModel buildSiliconFlowChatClient(YudaoAiProperties.SiliconFlowProperties properties) {
if (StrUtil.isEmpty(properties.getModel())) {
properties.setModel(SiliconFlowChatModel.MODEL_DEFAULT);
properties.setModel(SiliconFlowApiConstants.MODEL_DEFAULT);
}
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
.openAiApi(OpenAiApi.builder()
.baseUrl(SiliconFlowChatModel.BASE_URL)
.baseUrl(SiliconFlowApiConstants.DEFAULT_BASE_URL)
.apiKey(properties.getApiKey())
.build())
.defaultOptions(OpenAiChatOptions.builder()
@ -192,6 +194,33 @@ public class YudaoAiAutoConfiguration {
return new XingHuoChatModel(openAiChatModel);
}
@Bean
@ConditionalOnProperty(value = "yudao.ai.baichuan.enable", havingValue = "true")
public BaiChuanChatModel baiChuanChatClient(YudaoAiProperties yudaoAiProperties) {
YudaoAiProperties.BaiChuanProperties properties = yudaoAiProperties.getBaichuan();
return buildBaiChuanChatClient(properties);
}
public BaiChuanChatModel buildBaiChuanChatClient(YudaoAiProperties.BaiChuanProperties properties) {
if (StrUtil.isEmpty(properties.getModel())) {
properties.setModel(BaiChuanChatModel.MODEL_DEFAULT);
}
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
.openAiApi(OpenAiApi.builder()
.baseUrl(BaiChuanChatModel.BASE_URL)
.apiKey(properties.getApiKey())
.build())
.defaultOptions(OpenAiChatOptions.builder()
.model(properties.getModel())
.temperature(properties.getTemperature())
.maxTokens(properties.getMaxTokens())
.topP(properties.getTopP())
.build())
.toolCallingManager(getToolCallingManager())
.build();
return new BaiChuanChatModel(openAiChatModel);
}
@Bean
@ConditionalOnProperty(value = "yudao.ai.midjourney.enable", havingValue = "true")
public MidjourneyApi midjourneyApi(YudaoAiProperties yudaoAiProperties) {

View File

@ -43,6 +43,12 @@ public class YudaoAiProperties {
@SuppressWarnings("SpellCheckingInspection")
private XingHuoProperties xinghuo;
/**
*
*/
@SuppressWarnings("SpellCheckingInspection")
private BaiChuanProperties baichuan;
/**
* Midjourney
*/
@ -122,6 +128,19 @@ public class YudaoAiProperties {
}
@Data
public static class BaiChuanProperties {
private String enable;
private String apiKey;
private String model;
private Double temperature;
private Integer maxTokens;
private Double topP;
}
@Data
public static class MidjourneyProperties {

View File

@ -27,6 +27,7 @@ public enum AiPlatformEnum implements ArrayValuable<String> {
SILICON_FLOW("SiliconFlow", "硅基流动"), // 硅基流动
MINI_MAX("MiniMax", "MiniMax"), // 稀宇科技
MOONSHOT("Moonshot", "月之暗灭"), // KIMI
BAI_CHUAN("BaiChuan", "百川智能"), // 百川智能
// ========== 国外平台 ==========

View File

@ -11,11 +11,15 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.ai.config.YudaoAiAutoConfiguration;
import cn.iocoder.yudao.framework.ai.config.YudaoAiProperties;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import cn.iocoder.yudao.framework.ai.core.model.baichuan.BaiChuanChatModel;
import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
import cn.iocoder.yudao.framework.ai.core.model.hunyuan.HunYuanChatModel;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowApiConstants;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageApi;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageModel;
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
@ -42,6 +46,7 @@ import org.springframework.ai.autoconfigure.moonshot.MoonshotAutoConfiguration;
import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration;
import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
import org.springframework.ai.autoconfigure.qianfan.QianFanAutoConfiguration;
import org.springframework.ai.autoconfigure.stabilityai.StabilityAiImageAutoConfiguration;
import org.springframework.ai.autoconfigure.vectorstore.milvus.MilvusServiceClientConnectionDetails;
import org.springframework.ai.autoconfigure.vectorstore.milvus.MilvusServiceClientProperties;
import org.springframework.ai.autoconfigure.vectorstore.milvus.MilvusVectorStoreAutoConfiguration;
@ -146,6 +151,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
return buildMoonshotChatModel(apiKey, url);
case XING_HUO:
return buildXingHuoChatModel(apiKey);
case BAI_CHUAN:
return buildBaiChuanChatModel(apiKey);
case OPENAI:
return buildOpenAiChatModel(apiKey, url);
case AZURE_OPENAI:
@ -182,6 +189,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
return SpringUtil.getBean(MoonshotChatModel.class);
case XING_HUO:
return SpringUtil.getBean(XingHuoChatModel.class);
case BAI_CHUAN:
return SpringUtil.getBean(AzureOpenAiChatModel.class);
case OPENAI:
return SpringUtil.getBean(OpenAiChatModel.class);
case AZURE_OPENAI:
@ -203,6 +212,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
return SpringUtil.getBean(QianFanImageModel.class);
case ZHI_PU:
return SpringUtil.getBean(ZhiPuAiImageModel.class);
case SILICON_FLOW:
return SpringUtil.getBean(SiliconFlowImageModel.class);
case OPENAI:
return SpringUtil.getBean(OpenAiImageModel.class);
case STABLE_DIFFUSION:
@ -224,6 +235,8 @@ public class AiModelFactoryImpl implements AiModelFactory {
return buildZhiPuAiImageModel(apiKey, url);
case OPENAI:
return buildOpenAiImageModel(apiKey, url);
case SILICON_FLOW:
return buildSiliconFlowImageModel(apiKey,url);
case STABLE_DIFFUSION:
return buildStabilityAiImageModel(apiKey, url);
default:
@ -433,6 +446,15 @@ public class AiModelFactoryImpl implements AiModelFactory {
return new YudaoAiAutoConfiguration().buildXingHuoChatClient(properties);
}
/**
* {@link YudaoAiAutoConfiguration#baiChuanChatClient(YudaoAiProperties)}
*/
private BaiChuanChatModel buildBaiChuanChatModel(String apiKey) {
YudaoAiProperties.BaiChuanProperties properties = new YudaoAiProperties.BaiChuanProperties()
.setApiKey(apiKey);
return new YudaoAiAutoConfiguration().buildBaiChuanChatClient(properties);
}
/**
* {@link OpenAiAutoConfiguration} openAiChatModel
*/
@ -468,6 +490,15 @@ public class AiModelFactoryImpl implements AiModelFactory {
return new OpenAiImageModel(openAiApi);
}
/**
* SiliconFlowImageModel
*/
private SiliconFlowImageModel buildSiliconFlowImageModel(String apiToken, String url) {
url = StrUtil.blankToDefault(url, SiliconFlowApiConstants.DEFAULT_BASE_URL);
SiliconFlowImageApi openAiApi = new SiliconFlowImageApi(url, apiToken);
return new SiliconFlowImageModel(openAiApi);
}
/**
* {@link OllamaAutoConfiguration} ollamaApi
*/
@ -476,6 +507,9 @@ public class AiModelFactoryImpl implements AiModelFactory {
return OllamaChatModel.builder().ollamaApi(ollamaApi).toolCallingManager(getToolCallingManager()).build();
}
/**
* {@link StabilityAiImageAutoConfiguration} stabilityAiImageModel
*/
private StabilityAiImageModel buildStabilityAiImageModel(String apiKey, String url) {
url = StrUtil.blankToDefault(url, StabilityAiApi.DEFAULT_BASE_URL);
StabilityAiApi stabilityAiApi = new StabilityAiApi(apiKey, StabilityAiApi.DEFAULT_IMAGE_MODEL, url);

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.framework.ai.core.model.baichuan;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import reactor.core.publisher.Flux;
/**
* {@link ChatModel}
*
* @author
*/
@Slf4j
@RequiredArgsConstructor
public class BaiChuanChatModel implements ChatModel {
public static final String BASE_URL = "https://api.baichuan-ai.com";
public static final String MODEL_DEFAULT = "Baichuan4-Turbo";
/**
* OpenAI
*/
private final OpenAiChatModel openAiChatModel;
@Override
public ChatResponse call(Prompt prompt) {
return openAiChatModel.call(prompt);
}
@Override
public Flux<ChatResponse> stream(Prompt prompt) {
return openAiChatModel.stream(prompt);
}
@Override
public ChatOptions getDefaultOptions() {
return openAiChatModel.getDefaultOptions();
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
/**
* SiliconFlow API
*
* @author zzt
*/
public final class SiliconFlowApiConstants {
public static final String DEFAULT_BASE_URL = "https://api.siliconflow.cn";
public static final String MODEL_DEFAULT = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B";
public static final String DEFAULT_IMAGE_MODEL = "Kwai-Kolors/Kolors";
public static final String PROVIDER_NAME = "Siiconflow";
}

View File

@ -20,10 +20,6 @@ import reactor.core.publisher.Flux;
@RequiredArgsConstructor
public class SiliconFlowChatModel implements ChatModel {
public static final String BASE_URL = "https://api.siliconflow.cn";
public static final String MODEL_DEFAULT = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B";
/**
* OpenAI
*/

View File

@ -0,0 +1,115 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.ai.model.ApiKey;
import org.springframework.ai.model.NoopApiKey;
import org.springframework.ai.model.SimpleApiKey;
import org.springframework.ai.openai.api.OpenAiImageApi;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestClient;
import java.util.Map;
/**
* Image API
*
* @see <a href= "https://docs.siliconflow.cn/cn/api-reference/images/images-generations">Images</a>
*
* @author zzt
*/
public class SiliconFlowImageApi {
private final RestClient restClient;
public SiliconFlowImageApi(String aiToken) {
this(SiliconFlowApiConstants.DEFAULT_BASE_URL, aiToken, RestClient.builder());
}
public SiliconFlowImageApi(String baseUrl, String openAiToken) {
this(baseUrl, openAiToken, RestClient.builder());
}
public SiliconFlowImageApi(String baseUrl, String openAiToken, RestClient.Builder restClientBuilder) {
this(baseUrl, openAiToken, restClientBuilder, RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER);
}
public SiliconFlowImageApi(String baseUrl, String apiKey, RestClient.Builder restClientBuilder,
ResponseErrorHandler responseErrorHandler) {
this(baseUrl, apiKey, CollectionUtils.toMultiValueMap(Map.of()), restClientBuilder, responseErrorHandler);
}
public SiliconFlowImageApi(String baseUrl, String apiKey, MultiValueMap<String, String> headers,
RestClient.Builder restClientBuilder, ResponseErrorHandler responseErrorHandler) {
this(baseUrl, new SimpleApiKey(apiKey), headers, restClientBuilder, responseErrorHandler);
}
public SiliconFlowImageApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, String> headers,
RestClient.Builder restClientBuilder, ResponseErrorHandler responseErrorHandler) {
// @formatter:off
this.restClient = restClientBuilder.baseUrl(baseUrl)
.defaultHeaders(h -> {
if(!(apiKey instanceof NoopApiKey)) {
h.setBearerAuth(apiKey.getValue());
}
h.setContentType(MediaType.APPLICATION_JSON);
h.addAll(headers);
})
.defaultStatusHandler(responseErrorHandler)
.build();
// @formatter:on
}
public ResponseEntity<OpenAiImageApi.OpenAiImageResponse> createImage(SiliconflowImageRequest siliconflowImageRequest) {
Assert.notNull(siliconflowImageRequest, "Image request cannot be null.");
Assert.hasLength(siliconflowImageRequest.prompt(), "Prompt cannot be empty.");
return this.restClient.post()
.uri("v1/images/generations")
.body(siliconflowImageRequest)
.retrieve()
.toEntity(OpenAiImageApi.OpenAiImageResponse.class);
}
// @formatter:off
@JsonInclude(JsonInclude.Include.NON_NULL)
public record SiliconflowImageRequest (
@JsonProperty("prompt") String prompt,
@JsonProperty("model") String model,
@JsonProperty("batch_size") Integer batchSize,
@JsonProperty("negative_prompt") String negativePrompt,
@JsonProperty("seed") Integer seed,
@JsonProperty("num_inference_steps") Integer numInferenceSteps,
@JsonProperty("guidance_scale") Float guidanceScale,
@JsonProperty("image") String image) {
public SiliconflowImageRequest(String prompt, String model) {
this(prompt, model, null, null, null, null, null, null);
}
}
}

View File

@ -0,0 +1,159 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
import io.micrometer.observation.ObservationRegistry;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.image.*;
import org.springframework.ai.image.observation.DefaultImageModelObservationConvention;
import org.springframework.ai.image.observation.ImageModelObservationContext;
import org.springframework.ai.image.observation.ImageModelObservationConvention;
import org.springframework.ai.image.observation.ImageModelObservationDocumentation;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.api.OpenAiImageApi;
import org.springframework.ai.openai.metadata.OpenAiImageGenerationMetadata;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
import java.util.List;
/**
* {@link ImageModel}
*
* {@link OpenAiImageModel}
*
* @author zzt
*/
public class SiliconFlowImageModel implements ImageModel {
private static final Logger logger = LoggerFactory.getLogger(SiliconFlowImageModel.class);
private static final ImageModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultImageModelObservationConvention();
private final SiliconFlowImageOptions defaultOptions;
private final RetryTemplate retryTemplate;
private final SiliconFlowImageApi siliconFlowImageApi;
private final ObservationRegistry observationRegistry;
@Setter
private ImageModelObservationConvention observationConvention = DEFAULT_OBSERVATION_CONVENTION;
public SiliconFlowImageModel(SiliconFlowImageApi siliconFlowImageApi) {
this(siliconFlowImageApi, SiliconFlowImageOptions.builder().build(), RetryUtils.DEFAULT_RETRY_TEMPLATE);
}
public SiliconFlowImageModel(SiliconFlowImageApi siliconFlowImageApi, SiliconFlowImageOptions options, RetryTemplate retryTemplate) {
this(siliconFlowImageApi, options, retryTemplate, ObservationRegistry.NOOP);
}
public SiliconFlowImageModel(SiliconFlowImageApi siliconFlowImageApi, SiliconFlowImageOptions options, RetryTemplate retryTemplate,
ObservationRegistry observationRegistry) {
Assert.notNull(siliconFlowImageApi, "OpenAiImageApi must not be null");
Assert.notNull(options, "options must not be null");
Assert.notNull(retryTemplate, "retryTemplate must not be null");
Assert.notNull(observationRegistry, "observationRegistry must not be null");
this.siliconFlowImageApi = siliconFlowImageApi;
this.defaultOptions = options;
this.retryTemplate = retryTemplate;
this.observationRegistry = observationRegistry;
}
@Override
public ImageResponse call(ImagePrompt imagePrompt) {
SiliconFlowImageOptions requestImageOptions = mergeOptions(imagePrompt.getOptions(), this.defaultOptions);
SiliconFlowImageApi.SiliconflowImageRequest imageRequest = createRequest(imagePrompt, requestImageOptions);
var observationContext = ImageModelObservationContext.builder()
.imagePrompt(imagePrompt)
.provider(SiliconFlowApiConstants.PROVIDER_NAME)
.requestOptions(imagePrompt.getOptions())
.build();
return ImageModelObservationDocumentation.IMAGE_MODEL_OPERATION
.observation(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext,
this.observationRegistry)
.observe(() -> {
ResponseEntity<OpenAiImageApi.OpenAiImageResponse> imageResponseEntity = this.retryTemplate
.execute(ctx -> this.siliconFlowImageApi.createImage(imageRequest));
ImageResponse imageResponse = convertResponse(imageResponseEntity, imageRequest);
observationContext.setResponse(imageResponse);
return imageResponse;
});
}
private SiliconFlowImageApi.SiliconflowImageRequest createRequest(ImagePrompt imagePrompt,
SiliconFlowImageOptions requestImageOptions) {
String instructions = imagePrompt.getInstructions().get(0).getText();
SiliconFlowImageApi.SiliconflowImageRequest imageRequest = new SiliconFlowImageApi.SiliconflowImageRequest(instructions,
SiliconFlowApiConstants.DEFAULT_IMAGE_MODEL);
return ModelOptionsUtils.merge(requestImageOptions, imageRequest, SiliconFlowImageApi.SiliconflowImageRequest.class);
}
private ImageResponse convertResponse(ResponseEntity<OpenAiImageApi.OpenAiImageResponse> imageResponseEntity,
SiliconFlowImageApi.SiliconflowImageRequest siliconflowImageRequest) {
OpenAiImageApi.OpenAiImageResponse imageApiResponse = imageResponseEntity.getBody();
if (imageApiResponse == null) {
logger.warn("No image response returned for request: {}", siliconflowImageRequest);
return new ImageResponse(List.of());
}
List<ImageGeneration> imageGenerationList = imageApiResponse.data()
.stream()
.map(entry -> new ImageGeneration(new Image(entry.url(), entry.b64Json()),
new OpenAiImageGenerationMetadata(entry.revisedPrompt())))
.toList();
ImageResponseMetadata openAiImageResponseMetadata = new ImageResponseMetadata(imageApiResponse.created());
return new ImageResponse(imageGenerationList, openAiImageResponseMetadata);
}
private SiliconFlowImageOptions mergeOptions(@Nullable ImageOptions runtimeOptions, SiliconFlowImageOptions defaultOptions) {
var runtimeOptionsForProvider = ModelOptionsUtils.copyToTarget(runtimeOptions, ImageOptions.class,
SiliconFlowImageOptions.class);
if (runtimeOptionsForProvider == null) {
return defaultOptions;
}
return SiliconFlowImageOptions.builder()
// Handle portable image options
.model(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel()))
.batchSize(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getN(), defaultOptions.getN()))
.width(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getWidth(), defaultOptions.getWidth()))
.height(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getHeight(), defaultOptions.getHeight()))
// Handle SiliconFlow specific image options
.negativePrompt(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getNegativePrompt(), defaultOptions.getNegativePrompt()))
.numInferenceSteps(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getNumInferenceSteps(), defaultOptions.getNumInferenceSteps()))
.guidanceScale(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getGuidanceScale(), defaultOptions.getGuidanceScale()))
.seed(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getSeed(), defaultOptions.getSeed()))
.build();
}
}

View File

@ -0,0 +1,105 @@
package cn.iocoder.yudao.framework.ai.core.model.siliconflow;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ai.image.ImageOptions;
/**
* {@link ImageOptions}
*
* @author zzt
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SiliconFlowImageOptions implements ImageOptions {
@JsonProperty("model")
private String model;
@JsonProperty("negative_prompt")
private String negativePrompt;
/**
* The number of images to generate. Must be between 1 and 4.
*/
@JsonProperty("image_size")
private String imageSize;
/**
* The number of images to generate. Must be between 1 and 4.
*/
@JsonProperty("batch_size")
private Integer batchSize = 1;
/**
* number of inference steps
*/
@JsonProperty("num_inference_steps")
private Integer numInferenceSteps = 25;
/**
* This value is used to control the degree of match between the generated image and the given prompt. The higher the value, the more the generated image will tend to strictly match the text prompt. The lower the value, the more creative and diverse the generated image will be, potentially containing more unexpected elements.
*
* Required range: 0 <= x <= 20
*/
@JsonProperty("guidance_scale")
private Float guidanceScale = 0.75F;
/**
* seed
*
*/
@JsonProperty("seed")
private Integer seed = (int)(Math.random() * 1_000_000_000);
/**
* The image that needs to be uploaded should be converted into base64 format.
*/
@JsonProperty("image")
private String image;
/**
*
*/
private Integer width;
/**
*
*/
private Integer height;
public void setHeight(Integer height) {
this.height = height;
if (this.width != null && this.height != null) {
this.imageSize = this.width + "x" + this.height;
}
}
public void setWidth(Integer width) {
this.width = width;
if (this.width != null && this.height != null) {
this.imageSize = this.width + "x" + this.height;
}
}
@Override
public Integer getN() {
return batchSize;
}
@Override
public String getResponseFormat() {
return "url";
}
@Override
public String getStyle() {
return null;
}
}

View File

@ -0,0 +1,385 @@
package cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
// TODO @新:要不改成 WenDuoDuoPptApi
/**
* API
*
* @see <a href="https://docmee.cn/open-platform/api">PPT API</a>
*
* @author xiaoxin
*/
@Slf4j
public class WddPptApi {
public static final String BASE_URL = "https://docmee.cn";
private final WebClient webClient;
private final Predicate<HttpStatusCode> STATUS_PREDICATE = status -> !status.is2xxSuccessful();
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
HttpRequest request = response.request();
log.error("[wdd-api] 调用失败!请求方式:[{}],请求地址:[{}],请求参数:[{}],响应数据: [{}]",
request.getMethod(), request.getURI(), reqParam, responseBody);
sink.error(new IllegalStateException("[wdd-api] 调用失败!"));
});
// TODO @新:是不是不用 baseUrl 哈
public WddPptApi(String baseUrl) {
this.webClient = WebClient.builder()
.baseUrl(baseUrl)
// TODO @新建议token 作为 defaultHeader
.defaultHeaders((headers) -> headers.setContentType(MediaType.APPLICATION_JSON))
.build();
}
/**
* token
*
* @param request
* @return token
*/
public String createApiToken(CreateTokenRequest request) {
return this.webClient.post()
.uri("/api/user/createApiToken")
.header("Api-Key", request.apiKey)
.body(Mono.just(request), CreateTokenRequest.class)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToMono(ApiResponse.class)
.<String>handle((response, sink) -> {
if (response.code != 0) {
sink.error(new IllegalStateException("创建 token 异常," + response.message));
return;
}
sink.next(response.data.get("token").toString());
})
.block();
}
// TODO @xin是不是给个 API 连接,这样 type、content、files 都不用写注释太细了
/**
*
*
* @param type
* 1.
* 2.
* 3.
* 4.wordppt
* 5.
* 6.
* 7.Markdown
* @param content
* type=1 1000
* type=24
* type=3
* type=5 http/https
* type=6 20000
* type=7 markdown
* @param files
* 550M
* type=1
* type=2
* type=3 xmind/mm/md
* type=4 word
* type=567
* <p>
* doc/docx/pdf/ppt/pptx/txt/md/xls/xlsx/csv/html/epub/mobi/xmind/mm
* @return ID
*/
public ApiResponse createTask(String token, Integer type, String content, List<MultipartFile> files) {
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
formData.add("type", type);
if (content != null) {
formData.add("content", content);
}
if (files != null) {
for (MultipartFile file : files) {
formData.add("file", file.getResource());
}
}
return this.webClient.post()
.uri("/api/ppt/v2/createTask")
.header("token", token)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(formData))
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(formData))
.bodyToMono(ApiResponse.class)
.block();
}
/**
*
*
* @param lang
* @return
*/
public Map<String, Object> getOptions(String lang) {
String uri = "/api/ppt/v2/options";
if (lang != null) {
uri += "?lang=" + lang;
}
return this.webClient.get()
.uri(uri)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(lang))
.bodyToMono(new ParameterizedTypeReference<ApiResponse>() {
})
.<Map<String, Object>>handle((response, sink) -> {
if (response.code != 0) {
sink.error(new IllegalStateException("获取生成选项异常," + response.message));
return;
}
sink.next(response.data);
})
.block();
}
/**
* PPT
*
* @param token
* @param request
* @return
*/
public PagePptTemplateInfo getTemplatePage(String token, TemplateQueryRequest request) {
return this.webClient.post()
.uri("/api/ppt/templates")
.header("token", token)
.bodyValue(request)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToMono(new ParameterizedTypeReference<PagePptTemplateInfo>() {
})
.block();
}
/**
*
*
* @return
*/
public Flux<Map<String, Object>> createOutline(String token, CreateOutlineRequest request) {
return this.webClient.post()
.uri("/api/ppt/v2/generateContent")
.header("token", token)
.body(Mono.just(request), CreateOutlineRequest.class)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToFlux(new ParameterizedTypeReference<>() {
});
}
/**
*
*
* @param request
* @return
*/
public Flux<Map<String, Object>> updateOutline(String token, UpdateOutlineRequest request) {
return this.webClient.post()
.uri("/api/ppt/v2/updateContent")
.header("token", token)
.body(Mono.just(request), UpdateOutlineRequest.class)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToFlux(new ParameterizedTypeReference<>() {
});
}
/**
* PPT
*
* @return PPT
*/
public PptInfo create(String token, CreatePptRequest request) {
return this.webClient.post()
.uri("/api/ppt/v2/generatePptx")
.header("token", token)
.body(Mono.just(request), CreatePptRequest.class)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToMono(ApiResponse.class)
.<PptInfo>handle((response, sink) -> {
if (response.code != 0) {
sink.error(new IllegalStateException("生成 PPT 异常," + response.message));
return;
}
sink.next(Objects.requireNonNull(JsonUtils.parseObject(JsonUtils.toJsonString(response.data.get("pptInfo")), PptInfo.class)));
})
.block();
}
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreateTokenRequest(
String apiKey,
String uid,
Integer limit
) {
public CreateTokenRequest(String apiKey) {
this(apiKey, null, null);
}
}
/**
* API
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record ApiResponse(
Integer code,
String message,
Map<String, Object> data
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreateTaskRequest(
Integer type,
String content,
List<MultipartFile> files
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreateOutlineRequest(
String id,
String length,
String scene,
String audience,
String lang,
String prompt
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record UpdateOutlineRequest(
String id,
String markdown,
String question
) { }
/**
* PPT
*/
// TODO @新:要不按照 PptCreateRequest 这样的风格
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreatePptRequest(
String id,
String templateId,
String markdown
) { }
// TODO @新:要不写下类注释
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record PptInfo(
String id,
String name,
String subject,
String coverUrl,
String fileUrl,
String templateId,
String pptxProperty,
String userId,
String userName,
int companyId,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime updateTime,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createTime,
String createUser,
String updateUser
) { }
// TODO @新:要不写下类注释
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record TemplateQueryRequest(
int page,
int size,
Filter filters
) {
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record Filter(
int type,
String category,
String style,
String themeColor
) { }
}
// TODO @新:要不写下类注释
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record PagePptTemplateInfo(
List<PptTemplateInfo> data,
String total
) {}
// TODO @新:要不写下类注释
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record PptTemplateInfo(
String id,
int type,
Integer subType,
String layout,
String category,
String style,
String themeColor,
String lang,
boolean animation,
String subject,
String coverUrl,
String fileUrl,
List<String> pageCoverUrls,
String pptxProperty,
int sort,
int num,
Integer imgNum,
int isDeleted,
String userId,
int companyId,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime updateTime,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createTime,
String createUser,
String updateUser
) { }
}

View File

@ -0,0 +1,759 @@
package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
// TODO @新:要不改成 XunFeiPptApi
/**
* PPT API
*
* @see <a href="https://www.xfyun.cn/doc/spark/PPTv2.html"> PPT API</a>
*
* @author xiaoxin
*/
@Slf4j
public class XunfeiPptApi {
public static final String BASE_URL = "https://zwapi.xfyun.cn/api/ppt/v2";
private final WebClient webClient;
private final String appId;
private final String apiSecret;
private final Predicate<HttpStatusCode> STATUS_PREDICATE = status -> !status.is2xxSuccessful();
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
log.error("[xunfei-ppt-api] 调用失败!请求参数:[{}],响应数据: [{}]", reqParam, responseBody);
sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!"));
});
// TODO @新:是不是不用 baseUrl 哈
public XunfeiPptApi(String baseUrl, String appId, String apiSecret) {
// TODO @新:建议,增加 defaultheaders例如说 appid 之类的;或者每个请求,通过 headers customer 处理。
this.webClient = WebClient.builder()
.baseUrl(baseUrl)
.build();
this.appId = appId;
this.apiSecret = apiSecret;
}
/**
*
*
* @return
*/
private SignatureInfo getSignature() {
long timestamp = System.currentTimeMillis() / 1000;
String ts = String.valueOf(timestamp);
String signature = generateSignature(appId, apiSecret, timestamp);
return new SignatureInfo(appId, ts, signature);
}
/**
*
*
* @param appId ID
* @param apiSecret
* @param timestamp
* @return
*/
private String generateSignature(String appId, String apiSecret, long timestamp) {
try {
// TODO @新:使用 hutool 简化
String auth = md5(appId + timestamp);
return hmacSHA1Encrypt(auth, apiSecret);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
log.error("[xunfei-ppt-api] 生成签名失败", e);
throw new IllegalStateException("[xunfei-ppt-api] 生成签名失败");
}
}
/**
* HMAC SHA1
*/
private String hmacSHA1Encrypt(String encryptText, String encryptKey)
throws NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec keySpec = new SecretKeySpec(
encryptKey.getBytes(StandardCharsets.UTF_8), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(keySpec);
byte[] result = mac.doFinal(encryptText.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(result);
}
/**
* MD5
*/
private String md5(String text) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(text.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
/**
* PPT
*
* @param style "商务"
* @param pageSize
* @return
*/
public TemplatePageResponse getTemplatePage(String style, Integer pageSize) {
SignatureInfo signInfo = getSignature();
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("style", style);
// TODO @新:可以使用 ObjUtil.defaultIfNull
requestBody.put("pageSize", pageSize != null ? pageSize : 10);
return this.webClient.post()
.uri("/template/list")
.header("appId", signInfo.appId)
.header("timestamp", signInfo.timestamp)
.header("signature", signInfo.signature)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(requestBody)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(requestBody))
.bodyToMono(TemplatePageResponse.class)
.block();
}
/**
*
*
* @param query
* @return
*/
public CreateResponse createOutline(String query) {
SignatureInfo signInfo = getSignature();
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
formData.add("query", query);
return this.webClient.post()
.uri("/createOutline")
.header("appId", signInfo.appId)
.header("timestamp", signInfo.timestamp)
.header("signature", signInfo.signature)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(formData))
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(formData))
.bodyToMono(CreateResponse.class)
.block();
}
/**
* PPT -
*
* @param query
* @return
*/
public CreateResponse create(String query) {
CreatePptRequest request = CreatePptRequest.builder()
.query(query)
.build();
return create(request);
}
/**
* PPT -
*
* @param file
* @param fileName
* @return
*/
public CreateResponse create(MultipartFile file, String fileName) {
CreatePptRequest request = CreatePptRequest.builder()
.file(file).fileName(fileName).build();
return create(request);
}
/**
* PPT
*
* @param request
* @return
*/
public CreateResponse create(CreatePptRequest request) {
SignatureInfo signInfo = getSignature();
MultiValueMap<String, Object> formData = buildCreateFormData(request);
return this.webClient.post()
.uri("/create")
.header("appId", signInfo.appId)
.header("timestamp", signInfo.timestamp)
.header("signature", signInfo.signature)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(formData))
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(formData))
.bodyToMono(CreateResponse.class)
.block();
}
/**
* PPT
*
* @param outline
* @param query
* @return
*/
public CreateResponse createPptByOutline(OutlineData outline, String query) {
CreatePptByOutlineRequest request = CreatePptByOutlineRequest.builder()
.outline(outline)
.query(query)
.build();
return createPptByOutline(request);
}
/**
* PPT
*
* @param request
* @return
*/
public CreateResponse createPptByOutline(CreatePptByOutlineRequest request) {
SignatureInfo signInfo = getSignature();
return this.webClient.post()
.uri("/createPptByOutline")
.header("appId", signInfo.appId)
.header("timestamp", signInfo.timestamp)
.header("signature", signInfo.signature)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(request)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
.bodyToMono(CreateResponse.class)
.block();
}
/**
* PPT
*
* @param sid ID
* @return
*/
public ProgressResponse checkProgress(String sid) {
SignatureInfo signInfo = getSignature();
return this.webClient.get()
.uri(uriBuilder -> uriBuilder
.path("/progress")
.queryParam("sid", sid)
.build())
.header("appId", signInfo.appId)
.header("timestamp", signInfo.timestamp)
.header("signature", signInfo.signature)
.retrieve()
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(sid))
.bodyToMono(ProgressResponse.class)
.block();
}
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
private record SignatureInfo(
String appId,
String timestamp,
String signature
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record TemplatePageResponse(
boolean flag,
int code,
String desc,
Integer count,
TemplatePageData data
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record TemplatePageData(
String total,
List<TemplateInfo> records,
Integer pageNum
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record TemplateInfo(
String templateIndexId,
Integer pageCount,
String type,
String color,
String industry,
String style,
String detailImage
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreateResponse(
boolean flag,
int code,
String desc,
Integer count,
CreateResponseData data
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreateResponseData(
String sid,
String coverImgSrc,
String title,
String subTitle,
OutlineData outline
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record OutlineData(
String title,
String subTitle,
List<Chapter> chapters
) {
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record Chapter(
String chapterTitle,
List<ChapterContent> chapterContents
) {
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record ChapterContent(
String chapterTitle
) { }
}
/**
* JSON
*
* @return JSON
*/
public String toJsonString() {
return JsonUtils.toJsonString(this);
}
}
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record ProgressResponse(
int code,
String desc,
ProgressResponseData data
) { }
/**
*
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record ProgressResponseData(
int process,
String pptId,
String pptUrl,
// TODO @新:字段注释,去掉
String pptStatus, // PPT构建状态building构建中done已完成build_failed生成失败
String aiImageStatus, // ai配图状态building构建中done已完成
String cardNoteStatus, // 演讲备注状态building构建中done已完成
String errMsg, // 生成PPT的失败信息
Integer totalPages, // 生成PPT的总页数
Integer donePages // 生成PPT的完成页数
) {
/**
*
*
* @return
*/
public boolean isAllDone() {
return "done".equals(pptStatus)
&& ("done".equals(aiImageStatus) || aiImageStatus == null)
&& ("done".equals(cardNoteStatus) || cardNoteStatus == null);
}
/**
*
*
* @return
*/
public boolean isFailed() {
return "build_failed".equals(pptStatus);
}
/**
*
*
* @return
*/
public int getProgressPercent() {
if (totalPages == null || totalPages == 0 || donePages == null) {
return process; // 兼容旧版返回
}
return (int) (donePages * 100.0 / totalPages);
}
}
/**
* PPT
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreatePptByOutlineRequest(
String query, // 用户生成PPT要求最多8000字
String outlineSid, // 已生成大纲后响应返回的请求大纲唯一id
OutlineData outline, // 大纲内容
String templateId, // 模板ID
String businessId, // 业务ID非必传
String author, // PPT作者名
Boolean isCardNote, // 是否生成PPT演讲备注
Boolean search, // 是否联网搜索
String language, // 语种
String fileUrl, // 文件地址
String fileName, // 文件名(带文件名后缀)
Boolean isFigure, // 是否自动配图
String aiImage // ai配图类型normal、advanced
) {
/**
*
*
* @return
*/
public static Builder builder() {
return new Builder();
}
// TODO @新:这个可以用 lombok 简化么?
/**
*
*/
public static class Builder {
private String query;
private String outlineSid;
private OutlineData outline;
private String templateId;
private String businessId;
private String author;
private Boolean isCardNote;
private Boolean search;
private String language;
private String fileUrl;
private String fileName;
private Boolean isFigure;
private String aiImage;
public Builder query(String query) {
this.query = query;
return this;
}
public Builder outlineSid(String outlineSid) {
this.outlineSid = outlineSid;
return this;
}
public Builder outline(OutlineData outline) {
this.outline = outline;
return this;
}
public Builder templateId(String templateId) {
this.templateId = templateId;
return this;
}
public Builder businessId(String businessId) {
this.businessId = businessId;
return this;
}
public Builder author(String author) {
this.author = author;
return this;
}
public Builder isCardNote(Boolean isCardNote) {
this.isCardNote = isCardNote;
return this;
}
public Builder search(Boolean search) {
this.search = search;
return this;
}
public Builder language(String language) {
this.language = language;
return this;
}
public Builder fileUrl(String fileUrl) {
this.fileUrl = fileUrl;
return this;
}
public Builder fileName(String fileName) {
this.fileName = fileName;
return this;
}
public Builder isFigure(Boolean isFigure) {
this.isFigure = isFigure;
return this;
}
public Builder aiImage(String aiImage) {
this.aiImage = aiImage;
return this;
}
public CreatePptByOutlineRequest build() {
return new CreatePptByOutlineRequest(
query, outlineSid, outline, templateId, businessId, author,
isCardNote, search, language, fileUrl, fileName, isFigure, aiImage
);
}
}
}
/**
* PPT
*
* @param request
* @return
*/
private MultiValueMap<String, Object> buildCreateFormData(CreatePptRequest request) {
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
// 添加请求参数
if (request.query() != null) {
formData.add("query", request.query());
}
if (request.file() != null) {
try {
formData.add("file", new ByteArrayResource(request.file().getBytes()) {
@Override
public String getFilename() {
return request.file().getOriginalFilename();
}
});
} catch (IOException e) {
log.error("[xunfei-ppt-api] 文件处理失败", e);
throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e);
}
}
// TODO @新:要不搞个 MapUtil.addIfPresent 方法?
if (request.fileUrl() != null) {
formData.add("fileUrl", request.fileUrl());
}
if (request.fileName() != null) {
formData.add("fileName", request.fileName());
}
if (request.templateId() != null) {
formData.add("templateId", request.templateId());
}
if (request.businessId() != null) {
formData.add("businessId", request.businessId());
}
if (request.author() != null) {
formData.add("author", request.author());
}
if (request.isCardNote() != null) {
formData.add("isCardNote", request.isCardNote().toString());
}
if (request.search() != null) {
formData.add("search", request.search().toString());
}
if (request.language() != null) {
formData.add("language", request.language());
}
if (request.isFigure() != null) {
formData.add("isFigure", request.isFigure().toString());
}
if (request.aiImage() != null) {
formData.add("aiImage", request.aiImage());
}
return formData;
}
/**
* PPT
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public record CreatePptRequest(
String query, // 用户生成PPT要求最多8000字
MultipartFile file, // 上传文件
String fileUrl, // 文件地址
String fileName, // 文件名(带文件名后缀)
String templateId, // 模板ID
String businessId, // 业务ID非必传
String author, // PPT作者名
Boolean isCardNote, // 是否生成PPT演讲备注
Boolean search, // 是否联网搜索
String language, // 语种
Boolean isFigure, // 是否自动配图
String aiImage // ai配图类型normal、advanced
) {
/**
*
*
* @return
*/
public static Builder builder() {
return new Builder();
}
/**
*
*/
public static class Builder {
private String query;
private MultipartFile file;
private String fileUrl;
private String fileName;
private String templateId;
private String businessId;
private String author;
private Boolean isCardNote;
private Boolean search;
private String language;
private Boolean isFigure;
private String aiImage;
// TODO @新:这个可以用 lombok 简化么?
public Builder query(String query) {
this.query = query;
return this;
}
public Builder file(MultipartFile file) {
this.file = file;
return this;
}
public Builder fileUrl(String fileUrl) {
this.fileUrl = fileUrl;
return this;
}
public Builder fileName(String fileName) {
this.fileName = fileName;
return this;
}
public Builder templateId(String templateId) {
this.templateId = templateId;
return this;
}
public Builder businessId(String businessId) {
this.businessId = businessId;
return this;
}
public Builder author(String author) {
this.author = author;
return this;
}
public Builder isCardNote(Boolean isCardNote) {
this.isCardNote = isCardNote;
return this;
}
public Builder search(Boolean search) {
this.search = search;
return this;
}
public Builder language(String language) {
this.language = language;
return this;
}
public Builder isFigure(Boolean isFigure) {
this.isFigure = isFigure;
return this;
}
public Builder aiImage(String aiImage) {
this.aiImage = aiImage;
return this;
}
public CreatePptRequest build() {
// 验证参数
if (query == null && file == null && fileUrl == null) {
throw new IllegalArgumentException("query、file、fileUrl必填其一");
}
if ((file != null || fileUrl != null) && fileName == null) {
throw new IllegalArgumentException("如果传file或者fileUrlfileName必填");
}
return new CreatePptRequest(
query, file, fileUrl, fileName, templateId, businessId, author,
isCardNote, search, language, isFigure, aiImage
);
}
}
}
}

View File

@ -53,6 +53,7 @@ public class AiUtils {
case HUN_YUAN: // 复用 OpenAI 客户端
case XING_HUO: // 复用 OpenAI 客户端
case SILICON_FLOW: // 复用 OpenAI 客户端
case BAI_CHUAN: // 复用 OpenAI 客户端
return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens)
.toolNames(toolNames).build();
case AZURE_OPENAI:

View File

@ -0,0 +1,68 @@
package cn.iocoder.yudao.framework.ai.chat;
import cn.iocoder.yudao.framework.ai.core.model.baichuan.BaiChuanChatModel;
import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import reactor.core.publisher.Flux;
import java.util.ArrayList;
import java.util.List;
/**
* {@link BaiChuanChatModel}
*
* @author
*/
public class BaiChuanChatModelTests {
private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
.openAiApi(OpenAiApi.builder()
.baseUrl(BaiChuanChatModel.BASE_URL)
.apiKey("sk-61b6766a94c70786ed02673f5e16af3c") // apiKey
.build())
.defaultOptions(OpenAiChatOptions.builder()
.model("Baichuan4-Turbo") // 模型https://platform.baichuan-ai.com/docs/api
.temperature(0.7)
.build())
.build();
private final DeepSeekChatModel chatModel = new DeepSeekChatModel(openAiChatModel);
@Test
@Disabled
public void testCall() {
// 准备参数
List<Message> messages = new ArrayList<>();
messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
messages.add(new UserMessage("1 + 1 = "));
// 调用
ChatResponse response = chatModel.call(new Prompt(messages));
// 打印结果
System.out.println(response);
}
@Test
@Disabled
public void testStream() {
// 准备参数
List<Message> messages = new ArrayList<>();
messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
messages.add(new UserMessage("1 + 1 = "));
// 调用
Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages));
// 打印结果
flux.doOnNext(System.out::println).then().block();
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.ai.chat;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowApiConstants;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowChatModel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -25,11 +26,11 @@ public class SiliconFlowChatModelTests {
private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
.openAiApi(OpenAiApi.builder()
.baseUrl(SiliconFlowChatModel.BASE_URL)
.baseUrl(SiliconFlowApiConstants.DEFAULT_BASE_URL)
.apiKey("sk-epsakfenqnyzoxhmbucsxlhkdqlcbnimslqoivkshalvdozz") // apiKey
.build())
.defaultOptions(OpenAiChatOptions.builder()
.model(SiliconFlowChatModel.MODEL_DEFAULT) // 模型
.model(SiliconFlowApiConstants.MODEL_DEFAULT) // 模型
// .model("deepseek-ai/DeepSeek-R1") // 模型deepseek-ai/DeepSeek-R1可用赠费
// .model("Pro/deepseek-ai/DeepSeek-R1") // 模型Pro/deepseek-ai/DeepSeek-R1需要付费
.temperature(0.7)

View File

@ -0,0 +1,35 @@
package cn.iocoder.yudao.framework.ai.image;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageApi;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageModel;
import cn.iocoder.yudao.framework.ai.core.model.siliconflow.SiliconFlowImageOptions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
/**
* {@link SiliconFlowImageModel}
*/
public class SiliconFlowImageModelTests {
private final SiliconFlowImageModel imageModel = new SiliconFlowImageModel(
new SiliconFlowImageApi("sk-epsakfenqnyzoxhmbucsxlhkdqlcbnimslqoivkshalvdozz") // 密钥
);
@Test
@Disabled
public void testCall() {
// 准备参数
SiliconFlowImageOptions imageOptions = SiliconFlowImageOptions.builder()
.model("Kwai-Kolors/Kolors")
.build();
ImagePrompt prompt = new ImagePrompt("万里长城", imageOptions);
// 方法调用
ImageResponse response = imageModel.call(prompt);
// 打印结果
System.out.println(response);
}
}

View File

@ -0,0 +1,314 @@
package cn.iocoder.yudao.framework.ai.ppt.wdd;
import cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api.WddPptApi;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import java.util.Map;
import java.util.Objects;
/**
* {@link WddPptApi}
*
* @author xiaoxin
*/
public class WddPptApiTests {
private final WddPptApi wddPptApi = new WddPptApi("https://docmee.cn");
private final String token = ""; // API Token
@Test
@Disabled
public void testCreateApiToken() {
// 准备参数
String apiKey = "";
WddPptApi.CreateTokenRequest request = new WddPptApi.CreateTokenRequest(apiKey);
// 调用方法
String token = wddPptApi.createApiToken(request);
// 打印结果
System.out.println(token);
}
/**
*
*/
@Test
@Disabled
public void testCreateTask() {
WddPptApi.ApiResponse apiResponse = wddPptApi.createTask(token, 1, "dify 介绍", null);
System.out.println(apiResponse);
}
@Test // 创建大纲
@Disabled
public void testGenerateOutlineRequest() {
WddPptApi.CreateOutlineRequest request = new WddPptApi.CreateOutlineRequest(
"1901539019628613632", "medium", null, null, null, null);
// 调用
Flux<Map<String, Object>> flux = wddPptApi.createOutline(token, request);
StringBuffer contentBuffer = new StringBuffer();
flux.doOnNext(chunk -> {
contentBuffer.append(chunk.get("text"));
if (Objects.equals(Integer.parseInt(String.valueOf(chunk.get("status"))), 4)) {
// status 为 4最终 markdown 结构树
System.out.println(JsonUtils.toJsonString(chunk.get("result")));
System.out.println(" ########################################################################");
}
}).then().block();
// 打印结果
System.out.println(contentBuffer);
}
/**
*
*/
@Test
@Disabled
public void testUpdateOutlineRequest() {
WddPptApi.UpdateOutlineRequest request = new WddPptApi.UpdateOutlineRequest(
"1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可");
// 调用
Flux<Map<String, Object>> flux = wddPptApi.updateOutline(token, request);
StringBuffer contentBuffer = new StringBuffer();
flux.doOnNext(chunk -> {
contentBuffer.append(chunk.get("text"));
if (Objects.equals(Integer.parseInt(String.valueOf(chunk.get("status"))), 4)) {
// status 为 4最终 markdown 结构树
System.out.println(JsonUtils.toJsonString(chunk.get("result")));
System.out.println(" ########################################################################");
}
}).then().block();
// 打印结果
System.out.println(contentBuffer);
}
/**
* PPT
*/
@Test
@Disabled
public void testGetPptTemplatePage() {
// 准备参数
WddPptApi.TemplateQueryRequest.Filter filter = new WddPptApi.TemplateQueryRequest.Filter(
1, null, null, null);
WddPptApi.TemplateQueryRequest request = new WddPptApi.TemplateQueryRequest(1, 10, filter);
// 调用
WddPptApi.PagePptTemplateInfo pptTemplatePage = wddPptApi.getTemplatePage(token, request);
// 打印结果
System.out.println(pptTemplatePage);
}
/**
* PPT
*/
@Test
@Disabled
public void testGeneratePptx() {
// 准备参数
WddPptApi.CreatePptRequest request = new WddPptApi.CreatePptRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT);
// 调用
WddPptApi.PptInfo pptInfo = wddPptApi.create(token, request);
// 打印结果
System.out.println(pptInfo);
}
private final String TEST_OUT_LINE_CONTENT = """
# DifyAI
## 1 Dify
### 1.1 DifyAI
#### 1.1.1
DifyAIAI
#### 1.1.2
DifyAI
#### 1.1.3
Dify
### 1.2 DifyAI
#### 1.2.1
AIDify
#### 1.2.2
AIDifyAI
#### 1.2.3
AIDify
### 1.3 Dify
#### 1.3.1
DifyNLP
#### 1.3.2
DifyAI
#### 1.3.3
Dify使DifyAI
## 2 Dify
### 2.1
#### 2.1.1
DifyNoSQL
#### 2.1.2
Dify
#### 2.1.3
Dify访
### 2.2 AI
#### 2.2.1
DifyAI使
#### 2.2.2
DifyDify
#### 2.2.3
Dify
### 2.3
#### 2.3.1
DifyAI
#### 2.3.2
Dify
#### 2.3.3
Dify
### 2.4
#### 2.4.1
DifyAI
#### 2.4.2
Dify
#### 2.4.3
Dify便
## 3 Dify
### 3.1
#### 3.1.1
DifyAI
#### 3.1.2
Dify使
#### 3.1.3
DifyAI
### 3.2
#### 3.2.1
Dify
#### 3.2.2
DifyDify
#### 3.2.3
Dify
### 3.3
#### 3.3.1
DifyAI
#### 3.3.2
DifyAI
#### 3.3.3
Dify
### 3.4
#### 3.4.1
DifyDify
#### 3.4.2
Dify使Dify
#### 3.4.3 API
DifyAPIAPIDifyDify
## 4 Dify使
### 4.1
#### 4.1.1
Dify
#### 4.1.2
Dify
#### 4.1.3
Dify
### 4.2
#### 4.2.1
Dify
#### 4.2.2
Dify
#### 4.2.3
Dify
### 4.3
#### 4.3.1
Dify
#### 4.3.2
Dify
#### 4.3.3
Dify
### 4.4
#### 4.4.1
Dify
#### 4.4.2
Dify
#### 4.4.3
Dify
## 5 Dify
### 5.1 Case 1
#### 5.1.1
#### 5.1.2
使Dify
#### 5.1.3
50%20%30%
### 5.2 Case 2
#### 5.2.1
#### 5.2.2
使Dify
#### 5.2.3
40%30%25%
### 5.3 Case 3
#### 5.3.1
#### 5.3.2
使Dify
#### 5.3.3
20%15%10%
## 6 Dify
### 6.1
#### 6.1.1
DifyAI
#### 6.1.2
Dify
#### 6.1.3
Dify
### 6.2
#### 6.2.1
DifyDify
#### 6.2.2
DifyAI
#### 6.2.3
Dify使
### 6.3
#### 6.3.1
Dify
#### 6.3.2
Dify
#### 6.3.3
Dify
## 7
### 7.1 Dify
#### 7.1.1 AI
DifyAI
#### 7.1.2 AI
DifyAI
#### 7.1.3 AI
DifyAI
### 7.2
#### 7.2.1 Dify
DifyDify
#### 7.2.2
AI
#### 7.2.3
AI""";
}

View File

@ -0,0 +1,318 @@
package cn.iocoder.yudao.framework.ai.ppt.xunfei;
import cn.hutool.core.io.FileUtil;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunfeiPptApi;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
/**
* {@link XunfeiPptApi}
*
* @author xiaoxin
*/
public class XunfeiPptApiTests {
// 讯飞 API 配置信息,实际使用时请替换为您的应用信息
private static final String APP_ID = "";
private static final String API_SECRET = "";
private final XunfeiPptApi xunfeiPptApi = new XunfeiPptApi(XunfeiPptApi.BASE_URL, APP_ID, API_SECRET);
/**
* PPT
*/
@Test
@Disabled
public void testGetTemplatePage() {
// 调用方法
XunfeiPptApi.TemplatePageResponse response = xunfeiPptApi.getTemplatePage("商务", 10);
// 打印结果
System.out.println("模板列表响应:" + JsonUtils.toJsonString(response));
if (response != null && response.data() != null && response.data().records() != null) {
System.out.println("模板总数:" + response.data().total());
System.out.println("当前页码:" + response.data().pageNum());
System.out.println("模板数量:" + response.data().records().size());
// 打印第一个模板的信息(如果存在)
if (!response.data().records().isEmpty()) {
XunfeiPptApi.TemplateInfo firstTemplate = response.data().records().get(0);
System.out.println("模板ID" + firstTemplate.templateIndexId());
System.out.println("模板风格:" + firstTemplate.style());
System.out.println("模板颜色:" + firstTemplate.color());
System.out.println("模板行业:" + firstTemplate.industry());
}
}
}
/**
*
*/
@Test
@Disabled
public void testCreateOutline() {
XunfeiPptApi.CreateResponse response = getCreateResponse();
// 打印结果
System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response));
// 保存 sid 和 outline 用于后续测试
if (response != null && response.data() != null) {
System.out.println("sid: " + response.data().sid());
if (response.data().outline() != null) {
// 使用 OutlineData 的 toJsonString 方法
System.out.println("outline: " + response.data().outline().toJsonString());
// 将 outline 对象转换为 JSON 字符串,用于后续 createPptByOutline 测试
String outlineJson = response.data().outline().toJsonString();
System.out.println("可用于 createPptByOutline 的 outline 字符串: " + outlineJson);
}
}
}
/**
*
* @return
*/
private XunfeiPptApi.CreateResponse getCreateResponse() {
String param = "智能体平台 Dify 介绍";
return xunfeiPptApi.createOutline(param);
}
/**
* PPT
*/
@Test
@Disabled
public void testCreatePptByOutlineWithFullParams() {
// 创建大纲对象
XunfeiPptApi.CreateResponse createResponse = getCreateResponse();
// 调用方法
XunfeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些不要超过6个章节");
// 打印结果
System.out.println("通过大纲创建 PPT 响应:" + JsonUtils.toJsonString(response));
// 保存sid用于后续进度查询
if (response != null && response.data() != null) {
System.out.println("sid: " + response.data().sid());
if (response.data().coverImgSrc() != null) {
System.out.println("封面图片: " + response.data().coverImgSrc());
}
}
}
/**
* PPT
*/
@Test
@Disabled
public void testCheckProgress() {
// 准备参数 - 使用之前创建 PPT 时返回的 sid
String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid
// 调用方法
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
// 打印结果
System.out.println("检查进度响应:" + JsonUtils.toJsonString(response));
// 安全地访问响应数据
if (response != null && response.data() != null) {
XunfeiPptApi.ProgressResponseData data = response.data();
// 打印PPT生成状态
System.out.println("PPT 构建状态: " + data.pptStatus());
System.out.println("AI 配图状态: " + data.aiImageStatus());
System.out.println("演讲备注状态: " + data.cardNoteStatus());
// 打印进度信息
if (data.totalPages() != null && data.donePages() != null) {
System.out.println("总页数: " + data.totalPages());
System.out.println("已完成页数: " + data.donePages());
System.out.println("完成进度: " + data.getProgressPercent() + "%");
} else {
System.out.println("进度: " + data.process() + "%");
}
// 检查是否完成
if (data.isAllDone()) {
System.out.println("PPT 生成已完成!");
System.out.println("PPT 下载链接: " + data.pptUrl());
}
// 检查是否失败
else if (data.isFailed()) {
System.out.println("PPT 生成失败!");
System.out.println("错误信息: " + data.errMsg());
}
// 正在进行中
else {
System.out.println("PPT 生成中,请稍后再查询...");
}
}
}
/**
* PPT
*/
@Test
@Disabled
public void testPollCheckProgress() throws InterruptedException {
// 准备参数 - 使用之前创建 PP T时返回的 sid
String sid = "fa36e926f2ed434987fcb4c1f0776ffb"; // 替换为实际的sid
// 最大轮询次数
int maxPolls = 20;
// 轮询间隔(毫秒)- 讯飞 API 限流为 3 秒一次
long pollInterval = 3500;
for (int i = 0; i < maxPolls; i++) {
System.out.println("第" + (i + 1) + "次查询进度...");
// 调用方法
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
// 安全地访问响应数据
if (response != null && response.data() != null) {
XunfeiPptApi.ProgressResponseData data = response.data();
// 打印进度信息
System.out.println("PPT 构建状态: " + data.pptStatus());
if (data.totalPages() != null && data.donePages() != null) {
System.out.println("完成进度: " + data.donePages() + "/" + data.totalPages()
+ " (" + data.getProgressPercent() + "%)");
}
// 检查是否完成
if (data.isAllDone()) {
System.out.println("PPT 生成已完成!");
System.out.println("PPT 下载链接: " + data.pptUrl());
break;
}
// 检查是否失败
else if (data.isFailed()) {
System.out.println("PPT 生成失败!");
System.out.println("错误信息: " + data.errMsg());
break;
}
// 正在进行中,继续轮询
else {
System.out.println("PPT 生成中,等待" + (pollInterval / 1000) + "秒后继续查询...");
Thread.sleep(pollInterval);
}
} else {
System.out.println("查询失败,等待" + (pollInterval / 1000) + "秒后重试...");
Thread.sleep(pollInterval);
}
}
}
/**
* PPT
*/
@Test
@Disabled
public void testCreatePptByText() {
// 准备参数
String query = "合肥天气趋势分析包括近5年的气温变化、降水量变化、极端天气事件以及对城市生活的影响";
// 调用方法
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(query);
// 打印结果
System.out.println("直接创建 PPT 响应:" + JsonUtils.toJsonString(response));
// 保存 sid 用于后续进度查询
if (response != null && response.data() != null) {
System.out.println("sid: " + response.data().sid());
if (response.data().coverImgSrc() != null) {
System.out.println("封面图片: " + response.data().coverImgSrc());
}
System.out.println("标题: " + response.data().title());
System.out.println("副标题: " + response.data().subTitle());
}
}
/**
* PPT
*/
@Test
@Disabled
public void testCreatePptByFile() {
// 准备参数
File file = new File("src/test/resources/test.txt"); // 请确保此文件存在
MultipartFile multipartFile = convertFileToMultipartFile(file);
// 调用方法
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(multipartFile, file.getName());
// 打印结果
System.out.println("通过文件创建PPT响应" + JsonUtils.toJsonString(response));
// 保存 sid 用于后续进度查询
if (response != null && response.data() != null) {
System.out.println("sid: " + response.data().sid());
if (response.data().coverImgSrc() != null) {
System.out.println("封面图片: " + response.data().coverImgSrc());
}
System.out.println("标题: " + response.data().title());
System.out.println("副标题: " + response.data().subTitle());
}
}
/**
* PPT
*/
@Test
@Disabled
public void testCreatePptWithFullParams() {
// 准备参数
String query = "合肥天气趋势分析,包括近 5 年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
// 创建请求对象
XunfeiPptApi.CreatePptRequest request = XunfeiPptApi.CreatePptRequest.builder()
.query(query)
.language("cn")
.isCardNote(true)
.search(true)
.isFigure(true)
.aiImage("advanced")
.author("测试用户")
.build();
// 调用方法
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(request);
// 打印结果
System.out.println("使用完整参数创建 PPT 响应:" + JsonUtils.toJsonString(response));
// 保存 sid 用于后续进度查询
if (response != null && response.data() != null) {
String sid = response.data().sid();
System.out.println("sid: " + sid);
if (response.data().coverImgSrc() != null) {
System.out.println("封面图片: " + response.data().coverImgSrc());
}
System.out.println("标题: " + response.data().title());
System.out.println("副标题: " + response.data().subTitle());
// 立即查询一次进度
System.out.println("立即查询进度...");
XunfeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid);
if (progressResponse != null && progressResponse.data() != null) {
XunfeiPptApi.ProgressResponseData progressData = progressResponse.data();
System.out.println("PPT 构建状态: " + progressData.pptStatus());
if (progressData.totalPages() != null && progressData.donePages() != null) {
System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages()
+ " (" + progressData.getProgressPercent() + "%)");
}
}
}
}
/**
* File MultipartFile
*/
private MultipartFile convertFileToMultipartFile(File file) {
return new MockMultipartFile("file", file.getName(), "text/plain", FileUtil.readBytes(file));
}
}

View File

@ -42,6 +42,7 @@ public interface ErrorCodeConstants {
ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_005, "流程取消失败,该流程不允许取消");
ErrorCode PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR = new ErrorCode(1_009_004_006, "流程 Http 触发器请求调用失败");
ErrorCode PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG = new ErrorCode(1_009_004_007, "下一个任务({})的审批人未配置");
ErrorCode PROCESS_INSTANCE_CANCEL_CHILD_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_008, "子流程取消失败,子流程不允许取消");
// ========== 流程任务 1-009-005-000 ==========
ErrorCode TASK_OPERATE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "操作失败,原因:该任务的审批人不是你");

View File

@ -18,6 +18,7 @@ public enum BpmReasonEnum {
REJECT_TASK("审批不通过任务,原因:{}"), // 场景:用户审批不通过任务。修改文案时,需要注意 isRejectReason 方法
CANCEL_PROCESS_INSTANCE_BY_START_USER("用户主动取消流程,原因:{}"), // 场景:用户主动取消流程
CANCEL_PROCESS_INSTANCE_BY_ADMIN("管理员【{}】取消流程,原因:{}"), // 场景:管理员取消流程
CANCEL_CHILD_PROCESS_INSTANCE_BY_MAIN_PROCESS("子流程自动取消,原因:主流程已取消"),
// ========== 流程任务的独有原因 ==========

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.bpm.controller.admin.base.dept;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "部门精简信息 VO")
@Data
public class DeptSimpleBaseVO {
@Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "技术部")
private String name;
}

View File

@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
@ -53,6 +55,8 @@ public class BpmModelController {
@Resource
private AdminUserApi adminUserApi;
@Resource
private DeptApi deptApi;
@GetMapping("/list")
@Operation(summary = "获得模型分页")
@ -79,14 +83,19 @@ public class BpmModelController {
List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(
deploymentMap.keySet());
Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
// 获得 User Map
// 获得 User Map、Dept Map
Set<Long> userIds = convertSetByFlatMap(list, model -> {
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
});
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
Set<Long> deptIds = convertSetByFlatMap(list, model -> {
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
return metaInfo != null && metaInfo.getStartDeptIds() != null ? metaInfo.getStartDeptIds().stream() : Stream.empty();
});
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
return success(BpmModelConvert.INSTANCE.buildModelList(list,
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap));
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap, deptMap));
}
@GetMapping("/get")

View File

@ -59,6 +59,9 @@ public class BpmModelMetaInfoVO {
@Schema(description = "可发起用户编号数组", example = "[1,2,3]")
private List<Long> startUserIds;
@Schema(description = "可发起部门编号数组", example = "[2,4,6]")
private List<Long> startDeptIds;
@Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]")
@NotEmpty(message = "可管理用户编号数组不能为空")
private List<Long> managerUserIds;
@ -88,6 +91,12 @@ public class BpmModelMetaInfoVO {
@Schema(description = "流程后置通知设置", example = "{}")
private HttpRequestSetting processAfterTriggerSetting;
@Schema(description = "任务前置通知设置", example = "{}")
private HttpRequestSetting taskBeforeTriggerSetting;
@Schema(description = "任务后置通知设置", example = "{}")
private HttpRequestSetting taskAfterTriggerSetting;
@Schema(description = "流程 ID 规则")
@Data
@Valid

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
@ -39,6 +40,9 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
@Schema(description = "可发起的用户数组")
private List<UserSimpleBaseVO> startUsers;
@Schema(description = "可发起的部门数组")
private List<DeptSimpleBaseVO> startDepts;
@Schema(description = "BPMN XML")
private String bpmnXml;

View File

@ -112,7 +112,7 @@ public class BpmSimpleModelNodeVO {
/**
*
*/
private ConditionSetting conditionSetting; // 仅用于条件节点 BpmSimpleModelNodeType.CONDITION_NODE
private ConditionSetting conditionSetting; // 仅用于条件节点 BpmSimpleModelNodeTypeEnum.CONDITION_NODE
@Schema(description = "路由分支组", example = "[]")
private List<RouterSetting> routerGroups;
@ -241,7 +241,7 @@ public class BpmSimpleModelNodeVO {
@Schema(description = "条件设置")
@Data
@Valid
// 仅用于条件节点 BpmSimpleModelNodeType.CONDITION_NODE
// 仅用于条件节点 BpmSimpleModelNodeTypeEnum.CONDITION_NODE
public static class ConditionSetting {
@Schema(description = "条件类型", example = "1")

View File

@ -148,7 +148,6 @@ public class BpmProcessInstanceController {
processDefinition, processDefinitionInfo, startUser, dept));
}
// TODO @lesan【子流程】子流程如果取消主流程应该是通过、还是不通过哈还是禁用掉子流程的取消
@DeleteMapping("/cancel-by-start-user")
@Operation(summary = "用户取消流程实例", description = "取消发起的流程")
@PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel')")

View File

@ -72,6 +72,9 @@ public class BpmApprovalDetailRespVO {
@Schema(description = "候选人用户列表")
private List<UserSimpleBaseVO> candidateUsers; // 只包含未生成 ApprovalTaskInfo 的用户列表
@Schema(description = "流程编号", example = "8761d8e0-0922-11f0-bd37-00ff1db677bf")
private String processInstanceId; // 当且仅当该节点是子流程节点时才会有值CallActivity 的 processInstanceId 字段)
}
@Schema(description = "活动节点的任务信息")

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmPro
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.engine.repository.Deployment;
@ -43,7 +45,8 @@ public interface BpmModelConvert {
Map<String, BpmCategoryDO> categoryMap,
Map<String, Deployment> deploymentMap,
Map<String, ProcessDefinition> processDefinitionMap,
Map<Long, AdminUserRespDTO> userMap) {
Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) {
List<BpmModelRespVO> result = convertList(list, model -> {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
@ -52,7 +55,8 @@ public interface BpmModelConvert {
ProcessDefinition processDefinition = model.getDeploymentId() != null ?
processDefinitionMap.get(model.getDeploymentId()) : null;
List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers);
List<DeptRespDTO> startDepts = metaInfo != null ? convertList(metaInfo.getStartDeptIds(), deptMap::get) : null;
return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers, startDepts);
});
// 排序
result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
@ -61,7 +65,7 @@ public interface BpmModelConvert {
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
}
@ -72,7 +76,7 @@ public interface BpmModelConvert {
default BpmModelRespVO buildModel0(Model model,
BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
Deployment deployment, ProcessDefinition processDefinition,
List<AdminUserRespDTO> startUsers) {
List<AdminUserRespDTO> startUsers, List<DeptRespDTO> startDepts) {
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
.setKey(model.getKey()).setCategory(model.getCategory())
.setCreateTime(DateUtils.of(model.getCreateTime()));
@ -94,8 +98,9 @@ public interface BpmModelConvert {
modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime()));
}
}
// User
modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));
// User、Dept
modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class))
.setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class));
return modelRespVO;
}

View File

@ -151,6 +151,14 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
@TableField(typeHandler = LongListTypeHandler.class) // 为了可以使用 find_in_set 进行过滤
private List<Long> startUserIds;
/**
*
*
* {@link AdminUserRespDTO#getDeptId()}
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> startDeptIds;
/**
*
*
@ -199,4 +207,16 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
@TableField(typeHandler = JacksonTypeHandler.class)
private BpmModelMetaInfoVO.HttpRequestSetting processAfterTriggerSetting;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private BpmModelMetaInfoVO.HttpRequestSetting taskBeforeTriggerSetting;
/**
*
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private BpmModelMetaInfoVO.HttpRequestSetting taskAfterTriggerSetting;
}

View File

@ -47,7 +47,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
public static final Set<FlowableEngineEventType> TASK_EVENTS = ImmutableSet.<FlowableEngineEventType>builder()
.add(FlowableEngineEventType.TASK_CREATED)
.add(FlowableEngineEventType.TASK_ASSIGNED)
// .add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,所以不需要监听了
.add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,这里仅处理任务后置通知
.add(FlowableEngineEventType.ACTIVITY_CANCELLED)
.add(FlowableEngineEventType.TIMER_FIRED) // 监听审批超时
.build();
@ -66,6 +66,11 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
taskService.processTaskAssigned((Task) event.getEntity());
}
@Override
protected void taskCompleted(FlowableEngineEntityEvent event) {
taskService.processTaskCompleted((Task) event.getEntity());
}
@Override
protected void activityCancelled(FlowableActivityCancelledEvent event) {
List<HistoricActivityInstance> activityList = taskService.getHistoricActivityListByExecutionId(event.getExecutionId());

View File

@ -187,7 +187,7 @@ public class SimpleModelUtils {
/**
* 线
*
* @param nodeId ID
* @param nodeId ID
* @param attachNodeId ID
* @param targetNodeId ID
*/
@ -662,6 +662,10 @@ public class SimpleModelUtils {
*
*/
public static String buildConditionExpression(BpmSimpleModelNodeVO.ConditionSetting conditionSetting) {
// 并行网关不需要设置条件
if (conditionSetting == null) {
return null;
}
return buildConditionExpression(conditionSetting.getConditionType(), conditionSetting.getConditionExpression(),
conditionSetting.getConditionGroups());
}
@ -813,7 +817,6 @@ public class SimpleModelUtils {
callActivity.setCalledElementType("key");
// 1. 是否异步
if (node.getChildProcessSetting().getAsync()) {
// TODO @lesan: 这里目前测试没有跳过执行call activity 后面的节点
callActivity.setAsynchronous(true);
}
@ -959,8 +962,8 @@ public class SimpleModelUtils {
if (nodeType == BpmSimpleModelNodeTypeEnum.CONDITION_BRANCH_NODE) {
// 查找满足条件的 BpmSimpleModelNodeVO 节点
BpmSimpleModelNodeVO matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(),
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
&& evalConditionExpress(variables, conditionNode.getConditionSetting()));
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
&& evalConditionExpress(variables, conditionNode.getConditionSetting()));
if (matchConditionNode == null) {
matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(),
conditionNode -> BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow()));
@ -974,8 +977,8 @@ public class SimpleModelUtils {
if (nodeType == BpmSimpleModelNodeTypeEnum.INCLUSIVE_BRANCH_NODE) {
// 查找满足条件的 BpmSimpleModelNodeVO 节点
Collection<BpmSimpleModelNodeVO> matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(),
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
&& evalConditionExpress(variables, conditionNode.getConditionSetting()));
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
&& evalConditionExpress(variables, conditionNode.getConditionSetting()));
if (CollUtil.isEmpty(matchConditionNodes)) {
matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(),
conditionNode -> BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow()));

View File

@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitio
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
@ -50,6 +52,9 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
@Resource
private BpmProcessDefinitionInfoMapper processDefinitionMapper;
@Resource
private AdminUserApi adminUserApi;
@Override
public ProcessDefinition getProcessDefinition(String id) {
return repositoryService.getProcessDefinition(id);
@ -88,12 +93,22 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
if (processDefinition == null) {
return false;
}
// 为空,则所有人都可以发起
if (CollUtil.isEmpty(processDefinition.getStartUserIds())) {
return true;
// 校验用户是否在允许发起的用户列表中
if (CollUtil.isNotEmpty(processDefinition.getStartUserIds())) {
return processDefinition.getStartUserIds().contains(userId);
}
// 不为空,则需要存在里面
return processDefinition.getStartUserIds().contains(userId);
// 校验用户是否在允许发起的部门列表中
if (CollUtil.isNotEmpty(processDefinition.getStartDeptIds())) {
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
return user != null
&& user.getDeptId() != null
&& processDefinition.getStartDeptIds().contains(user.getDeptId());
}
// 都为空,则所有人都可以发起
return true;
}
@Override

View File

@ -14,7 +14,6 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
@ -262,30 +261,31 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
processVariables.putAll(reqVO.getProcessVariables());
}
// 3 获取当前任务节点的信息
// 3.1 获取下一个将要执行的节点集合
// 3. 获取下一个将要执行的节点集合
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
return convertList(nextFlowNodes, node -> {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
// 3.2 获取节点的审批人信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds);
// 3.3 获取节点的审批人部门信息
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
// 3.4 存在一个节点多人审批的情况,组装审批人信息
List<UserSimpleBaseVO> candidateUsers = new ArrayList<>();
userMap.forEach((key, value) -> candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(key, userMap, deptMap)));
return new ActivityNode().setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setId(node.getId())
.setName(node.getName())
.setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node))
// TODO @小北:先把 candidateUserIds 设置完,然后最后拼接 candidateUsers 信息。这样,如果有多个节点,就不用重复查询啦;类似 buildApprovalDetail 思路;
// TODO 先拼接处 List ActivityNode
// TODO 接着,再起一段,处理 adminUserApi.getUserMap(candidateUserIds)、deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId))
.setCandidateUsers(candidateUsers);
});
List<ActivityNode> nextActivityNodes = convertList(nextFlowNodes, node -> new ActivityNode().setId(node.getId())
.setName(node.getName()).setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node))
.setCandidateUserIds(getTaskCandidateUserList(bpmnModel, node.getId(),
loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables)));
if (CollUtil.isNotEmpty(nextActivityNodes)) {
return nextActivityNodes;
}
// 4. 拼接基础信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSetByFlatMap(nextActivityNodes, ActivityNode::getCandidateUserIds, Collection::stream));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
nextActivityNodes.forEach(node -> node.setCandidateUsers(convertList(node.getCandidateUserIds(), userId -> {
AdminUserRespDTO user = userMap.get(userId);
if (user != null) {
return BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
}
return null;
})));
return nextActivityNodes;
}
@Override
@ -387,8 +387,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
List<HistoricActivityInstance> activities, List<HistoricTaskInstance> tasks) {
// 遍历 tasks 列表,只处理已结束的 UserTask
// 为什么不通过 activities 呢?因为,加签场景下,它只存在于 tasks没有 activities导致如果遍历 activities 的话,它无法成为一个节点
// TODO @芋艿子流程只有activity这里获取不到已结束的子流程
// TODO @lesan【子流程】基于 activities 查询出 usertask、callactivity然后拼接如果是子流程就是可以点击过去
List<HistoricTaskInstance> endTasks = filterList(tasks, task -> task.getEndTime() != null);
List<ActivityNode> approvalNodes = convertList(endTasks, task -> {
FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
@ -410,7 +408,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 遍历 activities只处理已结束的 StartEvent、EndEvent
List<HistoricActivityInstance> endActivities = filterList(activities, activity -> activity.getEndTime() != null
&& (StrUtil.equalsAny(activity.getActivityType(), ELEMENT_EVENT_START, ELEMENT_EVENT_END)));
&& (StrUtil.equalsAny(activity.getActivityType(), ELEMENT_EVENT_START, ELEMENT_CALL_ACTIVITY, ELEMENT_EVENT_END)));
endActivities.forEach(activity -> {
// StartEvent只处理 BPMN 的场景。因为SIMPLE 情况下,已经有 START_USER_NODE 节点
if (ELEMENT_EVENT_START.equals(activity.getActivityType())
@ -444,7 +442,20 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
approvalNodes.add(endNode);
}
// CallActivity
if (ELEMENT_CALL_ACTIVITY.equals(activity.getActivityType())) {
ActivityNode callActivity = new ActivityNode().setId(activity.getId())
.setName(BpmSimpleModelNodeTypeEnum.CHILD_PROCESS.getName())
.setNodeType(BpmSimpleModelNodeTypeEnum.CHILD_PROCESS.getType()).setStatus(processInstanceStatus)
.setStartTime(DateUtils.of(activity.getStartTime()))
.setEndTime(DateUtils.of(activity.getEndTime()))
.setProcessInstanceId(activity.getProcessInstanceId());
approvalNodes.add(callActivity);
}
});
// 按照时间排序
approvalNodes.sort(Comparator.comparing(ActivityNode::getStartTime));
return approvalNodes;
}
@ -464,7 +475,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
HistoricActivityInstance::getActivityId);
// 按照 activityId 分组,构建 ApprovalNodeInfo 节点
// TODO @lesan【子流程】在子流程进行审批的时候HistoricActivityInstance 里面可以拿到 runActivities.get(0).getCalledProcessInstanceId()。要不要支持跳转???
Map<String, HistoricTaskInstance> taskMap = convertMap(tasks, HistoricTaskInstance::getId);
return convertList(runningTaskMap.entrySet(), entry -> {
String activityId = entry.getKey();
@ -510,6 +520,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
approvalTaskInfo.getAssignee())); // 委派或者向前加签情况,需要先比较 owner
activityNode.setCandidateUserIds(CollUtil.sub(candidateUserIds, index + 1, candidateUserIds.size()));
}
if (BpmSimpleModelNodeTypeEnum.CHILD_PROCESS.getType().equals(activityNode.getNodeType())) {
activityNode.setProcessInstanceId(firstActivity.getProcessInstanceId());
}
return activityNode;
});
}
@ -823,6 +836,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
&& Boolean.FALSE.equals(processDefinitionInfo.getAllowCancelRunningProcess())) {
throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW);
}
// 1.4 子流程不允许取消
if (StrUtil.isNotBlank(instance.getSuperExecutionId())) {
throw exception(PROCESS_INSTANCE_CANCEL_CHILD_FAIL_NOT_ALLOW);
}
// 2. 取消流程
updateProcessInstanceCancel(cancelReqVO.getId(),
@ -849,7 +866,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
BpmProcessInstanceStatusEnum.CANCEL.getStatus());
runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, reason);
// 2. 结束流程
// 2. 取消所有子流程
List<ProcessInstance> childProcessInstances = runtimeService.createProcessInstanceQuery()
.superProcessInstanceId(id).list();
childProcessInstances.forEach(processInstance -> updateProcessInstanceCancel(
processInstance.getProcessInstanceId(), BpmReasonEnum.CANCEL_CHILD_PROCESS_INSTANCE_BY_MAIN_PROCESS.getReason()));
// 3. 结束流程
taskService.moveTaskToEnd(id, reason);
}
@ -914,10 +937,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessAfterTriggerSetting();
BpmHttpRequestUtils.executeBpmHttpRequest(instance,
setting.getUrl(),
setting.getHeader(),
setting.getBody(),
true, setting.getResponse());
setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse());
}
}
});
@ -936,10 +956,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessBeforeTriggerSetting();
BpmHttpRequestUtils.executeBpmHttpRequest(instance,
setting.getUrl(),
setting.getHeader(),
setting.getBody(),
true, setting.getResponse());
setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse());
});
}

View File

@ -278,6 +278,13 @@ public interface BpmTaskService {
*/
void processTaskAssigned(Task task);
/**
* Task
*
* @param task
*/
void processTaskCompleted(Task task);
/**
* Task
*

View File

@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
@ -23,6 +24,7 @@ import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskSignTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmHttpRequestUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
@ -597,47 +599,54 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*/
private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) {
// simple 设计器第一个节点默认为发起人节点,不校验是否存在审批人
if (Objects.equals(taskDefinitionKey, START_USER_NODE_ID)) {
return variables;
}
// 1. 获取下一个将要执行的节点集合
FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
// 2. 校验选择的下一个节点的审批人,是否合法
Map<String, List<Long>> processVariables;
for (FlowNode nextFlowNode : nextFlowNodes) {
Integer candidateStrategy = parseCandidateStrategy(nextFlowNode);
// 2.1 情况一:如果节点中的审批人策略为 发起人自选
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) {
// 特殊:如果当前节点已经存在审批人,则不允许覆盖
Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
if (startUserSelectAssignees != null && CollUtil.isNotEmpty(startUserSelectAssignees.get(nextFlowNode.getId()))) {
continue;
}
// 如果节点存在,但未配置审批人
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
if (CollUtil.isEmpty(assignees)) {
throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
}
processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
// 特殊:如果当前节点已经存在审批人,则不允许覆盖
if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) {
continue;
}
// 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES
if (processVariables == null) {
processVariables = new HashMap<>();
if (startUserSelectAssignees == null) {
startUserSelectAssignees = new HashMap<>();
}
processVariables.put(nextFlowNode.getId(), assignees);
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, processVariables);
startUserSelectAssignees.put(nextFlowNode.getId(), assignees);
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees);
continue;
}
// 2.2 情况二:如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
// 如果节点存在,但未配置审批人
Map<String, List<Long>> approveUserSelectAssignees = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
if (CollUtil.isEmpty(assignees)) {
throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
}
processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
if (processVariables == null) {
processVariables = new HashMap<>();
}
// 设置 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES
processVariables.put(nextFlowNode.getId(), assignees);
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, processVariables);
if (approveUserSelectAssignees == null) {
approveUserSelectAssignees = new HashMap<>();
}
approveUserSelectAssignees.put(nextFlowNode.getId(), assignees);
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, approveUserSelectAssignees);
}
}
return variables;
@ -1174,12 +1183,26 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
updateTaskStatus(task.getId(), BpmTaskStatusEnum.RUNNING.getStatus());
// 2. 处理自动通过的情况例如说1无审批人时是否自动通过、不通过2非【人工审核】时是否自动通过、不通过
ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
if (processInstance == null) {
log.error("[processTaskCreated][taskId({}) 没有找到流程实例]", task.getId());
return;
}
BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.
getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
if (processDefinitionInfo == null) {
log.error("[processTaskCreated][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId());
return;
}
// 2. 任务前置通知
if (ObjUtil.isNotNull(processDefinitionInfo.getTaskBeforeTriggerSetting())){
BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskBeforeTriggerSetting();
BpmHttpRequestUtils.executeBpmHttpRequest(processInstance,
setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse());
}
// 3. 处理自动通过的情况例如说1无审批人时是否自动通过、不通过2非【人工审核】时是否自动通过、不通过
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
Integer approveType = BpmnModelUtils.parseApproveType(userTaskElement);
@ -1391,6 +1414,28 @@ public class BpmTaskServiceImpl implements BpmTaskService {
});
}
@Override
public void processTaskCompleted(Task task) {
ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
if (processInstance == null) {
log.error("[processTaskCompleted][taskId({}) 没有找到流程实例]", task.getId());
return;
}
BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.
getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
if (processDefinitionInfo == null) {
log.error("[processTaskCompleted][processDefinitionId({}) 没有找到流程定义]", processInstance.getProcessDefinitionId());
return;
}
// 任务后置通知
if (ObjUtil.isNotNull(processDefinitionInfo.getTaskAfterTriggerSetting())){
BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getTaskAfterTriggerSetting();
BpmHttpRequestUtils.executeBpmHttpRequest(processInstance,
setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType) {

View File

@ -52,10 +52,7 @@ public class BpmUserTaskListener implements TaskListener {
listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskId")
.setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getId()));
BpmHttpRequestUtils.executeBpmHttpRequest(processInstance,
listenerHandler.getPath(),
listenerHandler.getHeader(),
listenerHandler.getBody(),
false, null);
listenerHandler.getPath(), listenerHandler.getHeader(), listenerHandler.getBody(), false, null);
// 3. 是否需要后续操作TODO 芋艿:待定!
}

View File

@ -45,10 +45,7 @@ public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger {
.setKey("taskDefineKey") // 重要:回调请求 taskDefineKey 需要传给被调用方,用于回调执行
.setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(setting.getCallbackTaskDefineKey()));
BpmHttpRequestUtils.executeBpmHttpRequest(processInstance,
setting.getUrl(),
setting.getHeader(),
setting.getBody(),
false, null);
setting.getUrl(), setting.getHeader(), setting.getBody(), false, null);
}
}

View File

@ -40,10 +40,7 @@ public class BpmSyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger {
// 2. 发起请求
ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId);
BpmHttpRequestUtils.executeBpmHttpRequest(processInstance,
setting.getUrl(),
setting.getHeader(),
setting.getBody(),
true, setting.getResponse());
setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse());
}
}

View File

@ -223,7 +223,7 @@ public class CrmContactServiceImpl implements CrmContactService {
}
@Override
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}",
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}}",
success = CRM_CONTACT_FOLLOW_UP_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
public void updateContactFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent) {

View File

@ -67,8 +67,8 @@ public class MenuController {
}
@GetMapping({"/list-all-simple", "simple-list"})
@Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" +
"在多租户的场景下,会只返回租户所在套餐有的菜单")
@Operation(summary = "获取菜单精简信息列表",
description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。在多租户的场景下,会只返回租户所在套餐有的菜单")
public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() {
List<MenuDO> list = menuService.getMenuListByTenant(
new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -9,7 +10,6 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSimpleRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
import io.swagger.v3.oas.annotations.Operation;
@ -27,6 +27,7 @@ import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "管理后台 - 租户")
@RestController
@ -45,13 +46,25 @@ public class TenantController {
return success(tenant != null ? tenant.getId() : null);
}
@GetMapping({ "simple-list" })
@PermitAll
@Operation(summary = "获取租户精简信息列表", description = "只包含被开启的租户,用于【首页】功能的选择租户选项")
public CommonResult<List<TenantRespVO>> getTenantSimpleList() {
List<TenantDO> list = tenantService.getTenantListByStatus(CommonStatusEnum.ENABLE.getStatus());
return success(convertList(list, tenantDO ->
new TenantRespVO().setId(tenantDO.getId()).setName(tenantDO.getName())));
}
@GetMapping("/get-by-website")
@PermitAll
@Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息")
@Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn")
public CommonResult<TenantSimpleRespVO> getTenantByWebsite(@RequestParam("website") String website) {
public CommonResult<TenantRespVO> getTenantByWebsite(@RequestParam("website") String website) {
TenantDO tenant = tenantService.getTenantByWebsite(website);
return success(BeanUtils.toBean(tenant, TenantSimpleRespVO.class));
if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) {
return success(null);
}
return success(new TenantRespVO().setId(tenant.getId()).setName(tenant.getName()));
}
@PostMapping("/create")
@ -99,8 +112,7 @@ public class TenantController {
@Operation(summary = "导出租户 Excel")
@PreAuthorize("@ss.hasPermission('system:tenant:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<TenantDO> list = tenantService.getTenantPage(exportReqVO).getList();
// 导出 Excel

View File

@ -1,16 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 租户精简 Response VO")
@Data
public class TenantSimpleRespVO {
@Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
private String name;
}

View File

@ -43,4 +43,8 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
return selectList(TenantDO::getPackageId, packageId);
}
default List<TenantDO> selectListByStatus(Integer status) {
return selectList(TenantDO::getStatus, status);
}
}

View File

@ -38,7 +38,7 @@ public interface TenantService {
*
*
* @param tenantId
* @param menuIds
* @param menuIds
*/
void updateTenantRoleMenu(Long tenantId, Set<Long> menuIds);
@ -97,6 +97,14 @@ public interface TenantService {
*/
List<TenantDO> getTenantListByPackageId(Long packageId);
/**
*
*
* @param status
* @return
*/
List<TenantDO> getTenantListByStatus(Integer status);
/**
*
* {@link TenantContextHolder}

View File

@ -265,6 +265,11 @@ public class TenantServiceImpl implements TenantService {
return tenantMapper.selectListByPackageId(packageId);
}
@Override
public List<TenantDO> getTenantListByStatus(Integer status) {
return tenantMapper.selectListByStatus(status);
}
@Override
public void handleTenantInfo(TenantInfoHandler handler) {
// 如果禁用,则不执行逻辑