
package com.lideeyunji.core.framework.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lideeyunji.core.framework.config.validate.DbFormCopyValidate;
import com.lideeyunji.core.framework.config.validate.TableNameValidate;
import com.lideeyunji.core.framework.entity.FormEntity;
import com.lideeyunji.core.framework.entity.FormFieldWebEntity;
import com.lideeyunji.core.framework.params.DbFormAddOrUpdateParam;
import com.lideeyunji.core.framework.params.DictLabelParam;
import com.lideeyunji.core.framework.params.PageDbFormParam;
import com.lideeyunji.core.framework.params.TreeParentParam;
import com.lideeyunji.core.framework.params.model.AllTableModel;
import com.lideeyunji.core.framework.params.model.ExplainDatasourceSqlModel;
import com.lideeyunji.core.framework.params.model.ExplainFieldParam;
import com.lideeyunji.core.framework.params.model.ExplainSqlFieldModel;
import com.lideeyunji.core.framework.params.vo.*;
import com.lideeyunji.core.framework.params.vo.copy.CopyJsonVo;
import com.lideeyunji.core.framework.params.vo.role.DbFormRoleButtonVo;
import com.lideeyunji.core.framework.params.vo.role.DbFormRoleFieldVo;
import com.lideeyunji.core.framework.params.vo.webconfig.WebConfigRoleFieldVo;
import com.lideeyunji.core.framework.params.vo.webconfig.WebConfigVo;
import com.lideeyunji.core.framework.service.IDbFormRoleService;
import com.lideeyunji.core.framework.service.IFormService;
import com.lideeyunji.core.framework.service.IFrameService;
import com.lideeyunji.core.framework.service.IFrameSqlService;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.core.framework.utils.FuncWeb;
import com.lideeyunji.tool.framework.ai.chat.ChatBaseRequest;
import com.lideeyunji.tool.framework.ai.chat.ChatBaseResponse;
import com.lideeyunji.tool.framework.ai.chat.tool.ChatMessage;
import com.lideeyunji.tool.framework.ai.chat.tool.Choice;
import com.lideeyunji.tool.framework.ai.service.IChatService;
import com.lideeyunji.tool.framework.ai.service.PlatformType;
import com.lideeyunji.tool.framework.ai.service.factor.AiService;
import com.lideeyunji.tool.framework.ai.template.CreateTableTemplate;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import com.lideeyunji.tool.framework.constants.FrameErrorCodeConstants;
import com.lideeyunji.tool.framework.exception.lideeYunJiException;
import com.lideeyunji.tool.framework.exception.lideeYunJiMoreException;
import com.lideeyunji.tool.framework.yunji.adapter.IlideeYunjiAdapter;
import com.lideeyunji.tool.framework.yunji.annotation.lideeYunjiValidate;
import com.lideeyunji.tool.framework.yunji.component.properties.lideeYunjiProperties;
import com.lideeyunji.tool.framework.yunji.enums.DbFormTypeEnum;
import com.lideeyunji.tool.framework.yunji.enums.ParamEnum;
import com.lideeyunji.tool.framework.yunji.enums.YNEnum;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
import com.lideeyunji.tool.framework.yunji.model.global.BaseWebResult;
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
import com.lideeyunji.tool.framework.yunji.utils.lideeYunJiUtils;
import com.lideeyunji.tool.framework.sql.SqlHelper;
import com.lideeyunji.tool.framework.sql.build.buildmodel.wrapper.SqlInfoQueryWrapper;
import com.lideeyunji.tool.framework.tenant.core.aop.TenantIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;

@Tag(name = "低代码框架-框架接口")
@RestController
@AllArgsConstructor
@RequestMapping(lideeYunJiBaseConstant.REQUEST_URL_START + "/dbform")
public class DbFormController extends BaseController {

    private final IFrameService frameService;

    private final IFormService dbFormService;

    private final IlideeYunjiAdapter lideeYunJiAdapter;

    private final IFrameSqlService sqlService;

    private final IDbFormRoleService dbFormRoleService;

    private final AiService aiService;

    @lideeYunjiValidate(title = "自定义校验-表名是否正确", validateClass = TableNameValidate.class)
    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @Operation(tags = "表单开发",summary = "表单开发 - 保存")
    public BaseWebResult saveDbFormConfig(@RequestBody DbFormAddOrUpdateParam param, HttpServletRequest req) {
        //基本信息校验完成
        dbFormService.saveDbFormConfig(param);
        return BaseWebResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:update')")
    @PutMapping("/update")
    @ApiOperationSupport(order = 2)
    @Operation(tags = "表单开发",summary = "表单开发 - 修改")
    public BaseWebResult updateDbFormConfig(@RequestBody DbFormAddOrUpdateParam param) {
        dbFormService.updateDbFormConfig(param);
        return BaseWebResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:delete')")
    @DeleteMapping("/delete")
    @ApiOperationSupport(order = 3)
    @Operation(tags = "表单开发",summary = "表单开发 - 删除")
    public BaseWebResult deleteDbFormConfig(@RequestBody List<Long> dbFormIdList) {
        dbFormService.deleteDbFormConfig(dbFormIdList, true);
        return BaseWebResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:query')")
    @PostMapping("/detail")
    @ApiOperationSupport(order = 4)
    @Operation(tags = "表单开发",summary = "表单开发 - 获取详情")
    public BaseWebResult getDetailDbFormConfig(Long dbFormId, @RequestBody List<String> typeList) {
        List<DbFormTypeEnum> enumList = typeList.stream()
                .map(type -> DbFormTypeEnum.getByType(type))
                .collect(Collectors.toList());
        DbFormConfigVo vo = dbFormService.getDetailDbFormConfig(dbFormId, enumList);
        return BaseWebResult.success(vo);
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:query')")
    @PostMapping("/page")
    @ApiOperationSupport(order = 5)
    @Operation(tags = "表单开发",summary = "表单开发 - 获取分页数据")
    public BaseWebResult getPageDbFormConfig(@RequestBody PageDbFormParam param, PageVo pageVo) {
        Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
        IPage<FormEntity> pages = dbFormService.getPageDbFormConfig(param, page);
        IPage<FormEntityPageVo> vopages = toVoBean(pages, FormEntityPageVo.class);
        List<FormEntityPageVo> records = vopages.getRecords();
        super.formatFormEntityPageVo(records,dbFormService);
        return BaseWebResult.success(vopages);
    }


    @lideeYunjiValidate(title = "判断表名是否合法", validateClass = DbFormCopyValidate.class)
    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @GetMapping({"/copy/{dbformId}"})
    @ApiOperationSupport(order = 6)
    @Operation(tags = "表单开发",summary = "复制表")
    public BaseWebResult copy(@PathVariable("dbformId") Long dbformId, String tableName) {
        dbFormService.copyDbFormConfig(dbformId, tableName);
        return BaseWebResult.success("复制成功");
    }


    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @GetMapping({"/copyJson/{dbformId}"})
    @ApiOperationSupport(order = 6)
    @Operation(tags = "表单开发",summary = "复制Json配置")
    public BaseWebResult copyJson(@PathVariable("dbformId") Long dbformId) {
        CopyJsonVo vo = dbFormService.copyDbFormJsonConfig(dbformId);
        return BaseWebResult.success(vo);
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @PostMapping({"/importJson"})
    @ApiOperationSupport(order = 6)
    @Operation(tags = "表单开发",summary = "导入Json配置")
    public BaseWebResult importJson(String tableName,@RequestBody CopyJsonVo vo) {
        if (FuncBase.isEmpty(tableName)) {
            throw new lideeYunJiException("表名不允许为空");
        }
        if (!Func.checkTableName(tableName)) {
            StringJoiner joiner = new StringJoiner(",");
            lideeYunjiProperties.getExcludeTableNames().forEach(joiner::add);
            String errorMsg = joiner.toString();
            throw new lideeYunJiException(String.format("表名称不允许以【%s】开头", errorMsg));
        }
        //校验表名是否重复
        if (frameService.checkTable(tableName)) {
            String errorStr = String.format("数据库表【%s】已存在", tableName);
            throw new lideeYunJiException(errorStr);
        }

        dbFormService.importDbFormJsonConfig(tableName,vo);
        return BaseWebResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:sync')")
    @TenantIgnore
    @PostMapping({"/sync-db/{dbformId}"})
    @ApiOperationSupport(order = 7)
    @Operation(tags = "表单开发",summary = "同步数据库")
    public BaseWebResult syncDb(@PathVariable("dbformId") Long dbformId, String syncModel) {
        try {
            frameService.syncDb(dbformId, syncModel);
        } catch (Exception e) {
            throw new lideeYunJiMoreException("同步失败", e.getMessage());
        }
        return BaseWebResult.success("同步完成");
    }

    @GetMapping("/check/table")
    @TenantIgnore
    @ApiOperationSupport(order = 8)
    @Operation(tags = "表单开发",summary = "校验表明是否存在")
    public BaseWebResult checkTable(String tableName) {
        boolean flag = frameService.checkTable(tableName);
        return BaseWebResult.success(flag);
    }


    @GetMapping("/get/web-config")
    @ApiOperationSupport(order = 9)
    @Operation(tags = "表单开发",summary = "获取页面信息配置")
    public BaseWebResult getWebConfig(@RequestParam("dbformId")Long dbformId) {
        WebConfigVo webConfig = dbFormService.getWebConfig(dbformId);
        //判断是否有租户字段权限
        Long tenantId = lideeYunJiAdapter.getTenantId();
        if(Func.isNotEmpty(tenantId) && Func.notEquals(tenantId,"-1")){
            //字段权限->部分租户只能看到部分字段
            List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbformId,false);
            if(Func.isNotEmpty(roleFieldVoList)){
                List<WebConfigRoleFieldVo> webConfigRoleFieldVoList = BeanUtil.copyToList(roleFieldVoList, WebConfigRoleFieldVo.class);
                webConfig.setWebConfigRoleFieldVoList(webConfigRoleFieldVoList);
            }
            //按钮权限->部分租户只能看到部分按钮
            List<DbFormRoleButtonVo> roleButtonVoList = dbFormRoleService.listRoleButton(tenantId, dbformId, false);
            if(Func.isNotEmpty(roleButtonVoList)){
                List<String> webConfigRoleButtonVoList = roleButtonVoList.stream()
                        .map(DbFormRoleButtonVo::getButtonCode) // 提取 buttonCode
                        .collect(Collectors.toList()); // 收集到新的列表中
                webConfig.setWebConfigRoleButtonVoList(webConfigRoleButtonVoList);
            }

        }
        return BaseWebResult.success(webConfig);
    }




    @PostMapping("/get/dict-table-web-config/{dbformId}")
    @ApiOperationSupport(order = 10)
    @Operation(tags = "表单开发",summary = "获取字典表页面信息配置")
    public BaseWebResult getDictTableWebConfig(@PathVariable("dbformId") Long dbformId, HttpServletRequest req) {
        Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);

        List<String> fieldList = lideeYunJiUtils.getMap2List(bodyParams, ParamEnum.DICT_TABLE_FIELD.getCode());//自定义列 id,name,age,sex
        if (FuncBase.isEmpty(fieldList)) {//查字典数据
            return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
        }
        //获取指定列配置
        WebConfigVo webConfig = dbFormService.getWebConfig(dbformId, fieldList);
        webConfig.setButtonList(null);

        return BaseWebResult.success(webConfig);
    }

    @PostMapping("/get/table-label")
    @ApiOperationSupport(order = 11)
    @Operation(tags = "表单开发",summary = "表字段回显")
    public BaseWebResult getTableLabel(HttpServletRequest req) {
        Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);
        List<DictLabelParam> labelParamList = (List<DictLabelParam>) bodyParams.get(ParamEnum.DICT_LABEL.getCode());

        if (FuncBase.isEmpty(labelParamList)) {
            return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
        }

        for(DictLabelParam dictLabelParam:labelParamList){
            Long dbformId = dictLabelParam.getDbformId();
            String label = dictLabelParam.getLabel();
            List<String> fieldList = dictLabelParam.getFieldList();
            if(FuncBase.isNotEmpty(fieldList)){
                int ind = fieldList.indexOf(label);

                FormFieldWebEntity formFieldWebEntity = dbFormService.getFieldWebEntity(dbformId, label);
                if(FuncBase.isNotEmpty(formFieldWebEntity)){
                    String controlType = formFieldWebEntity.getControlType();
                    switch (controlType){
                        case "userSelect":
                            String userFormatSql="(select username from system_users where id ="+label+") as "+label;
                            fieldList.set(ind,userFormatSql);//子查询
                            break;
                        case "deptSelect":
                            String deptormatSql="(select name from system_dept where id ="+label+") as "+label;
                            fieldList.set(ind,deptormatSql);//子查询
                            break;
                    }
                }
            }

            
        }


        Map<String, List<Map<String, Object>>> resultMap = new ConcurrentHashMap<>();

        ForkJoinPool pool = null;
        try {
            pool = FuncBase.lideeyunjiForkJoinPool();
            pool.submit(() -> labelParamList.parallelStream().forEach(labelParam ->{
                Long dbformId = labelParam.getDbformId();
                List<String> fieldList = labelParam.getFieldList();
                String code = labelParam.getCode();
                String label = labelParam.getLabel();
                List<String> dataList = labelParam.getDataList();
                List<Long> userIdList = labelParam.getUserIdList();//用户id
                List<Long> deptIdList = labelParam.getDeptIdList();//部门id

                if (Func.isNotEmpty(dbformId)) { //自定义表
                    String mapKey = dbformId + "&" + label;
                    if (FuncBase.isEmpty(dataList)) {
                        List<Map<String, Object>> resultList = new ArrayList<>();
                        resultMap.put(FuncBase.toStr(dbformId), resultList);
                        return;
                    }

                    List<Map<String, Object>> resultList =new ArrayList<>();
                    for(String dataId:dataList){
                        Map<String, Object> params =new HashMap<>();
                        params.put(ParamEnum.DICT_TABLE_FIELD.getCode(),fieldList);
                        params.put(code,dataId);//id=1
                        params.put(ParamEnum.PAGE_NO.getCode(),1);
                        params.put(ParamEnum.PAGE_SIZE.getCode(),1000);
                        params.put(ParamEnum.ALL_QUERY_FIELD.getCode(),"Y");
                        ResultDataModel model = frameService.getDataList(dbformId, params);
                        List<Map<String, Object>> tmpList = model.getRecords();
                        if(Func.isEmpty(tmpList)){
                            continue;
                        }
                        resultList.addAll(tmpList);
                    }

                    resultMap.put(mapKey, resultList);
                }
                if (Func.isNotEmpty(userIdList)) {//用户表回显
                    List<Map<String, Object>> userViewList = lideeYunJiAdapter.getUserViewList(userIdList);
                    resultMap.put("userList", userViewList);
                }
                if (Func.isNotEmpty(deptIdList)) {//部门表回显
                    List<Map<String, Object>> deptViewList = lideeYunJiAdapter.getDeptViewList(deptIdList);
                    resultMap.put("deptList", deptViewList);
                }
            })).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e.getMessage());
        } finally {
            if (pool != null) {
                pool.shutdown();
            }
        }

        return BaseWebResult.success(resultMap);
    }


    @GetMapping("/get/all-table")
    @ApiOperationSupport(order = 13)
    @Operation(tags = "表单开发",summary = "获取所有表名")
    public BaseWebResult getAllTable(String systemFlag,String onlyTableName,String dataSourcesCode) {
        if(Func.isNotEmpty(dataSourcesCode)){
            List<AllTableModel> list = dbFormService.getDataSourceTable(dataSourcesCode);
            return BaseWebResult.success(list);
        }
        List<AllTableModel> list = dbFormService.getAllTable(systemFlag,onlyTableName);

        //只查表名
        boolean onlyTableNameFlag = Func.isNotEmpty(onlyTableName) && Func.equals(onlyTableName, YNEnum.Y.getCode());
        if (onlyTableNameFlag && list != null && !list.isEmpty()) {
            list.forEach(tableModel -> tableModel.setFieldModelList(null));
        }
        return BaseWebResult.success(list);
    }



    @GetMapping("/clear-cache")
    @ApiOperationSupport(order = 14)
    @Operation(tags = "表单开发",summary = "清除缓存")
    public BaseWebResult clearCache() {
        dbFormService.cleanCache();
        return BaseWebResult.success("成功");
    }

    @PostMapping("/get/tree-parent")
    @ApiOperationSupport(order = 10)
    @Operation(tags = "表单开发",summary = "获取字典表页面信息配置")
    public BaseWebResult getTreeParentList( HttpServletRequest req) {
        Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);
        if(!bodyParams.containsKey(ParamEnum.TREE_PARENT.getCode())){
            return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
        }


        List<TreeParentParam> paramList = (List<TreeParentParam>) bodyParams.get(ParamEnum.TREE_PARENT.getCode());

        Map<String,List<Map<String, Object>>> resultMap=new HashMap<>();
        paramList.stream().forEach(param ->{
            Long dbformId = param.getDbformId();
            List<Map<String, Object>> resultDataMapList = dbFormService.getTreeParentList(dbformId, param);
            resultMap.put(dbformId.toString(),resultDataMapList);
        });
        return BaseWebResult.success(resultMap);
    }



    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @PostMapping("/explain/datasource-sql")
    @ApiOperationSupport(order = 11)
    @Operation(tags = "表单开发",summary = "解释数据源SQL的运行结果")
    public BaseWebResult explainDatasourceSql(@RequestBody ExplainDatasourceSqlModel model) {
        Page page = FuncWeb.getPage(1, 10);
        Map<String, Object> params=new HashMap<>();
        SqlInfoQueryWrapper.Wrapper queryWrapper = SqlHelper.getQueryWrapper();
        //处理占位符参数
        Func.replaceParam(model.getExplainSql(), params, null, lideeYunJiAdapter);
        queryWrapper.setTableSql(model.getExplainSql());//sql
        if(Func.isNotEmpty(model.getDataSourcesCode())){
            queryWrapper.setDataSourceType(model.getDataSourcesCode());
            queryWrapper.setTenantIgnore(true);//外部数据源 直接忽略多租户
        }

        try{
            IPage<Map<String, Object>> pages = sqlService.getDataIPageByPlus(page, queryWrapper,params);
            return BaseWebResult.success(pages);
        }catch (Exception  e){
            throw new lideeYunJiMoreException("SQL执行错误",e.getMessage());
        }

    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @PostMapping("/explain/sqlfield")
    @ApiOperationSupport(order = 11)
    @Operation(tags = "表单开发",summary = "解释数据源SQL字段类型")
    public BaseWebResult explainSqlField(@RequestBody ExplainFieldParam param) {
        Map<String, Object> resultMap =new HashMap<>();
        List<ExplainSqlFieldModel> modelList = param.getModelList();
        if(Func.isNotEmpty(modelList)){//拖拉形式
            resultMap = dbFormService.explainSqlField(modelList);
            return BaseWebResult.success(resultMap);
        }
        //自定义sql，从运行结果来解析,保证能运行出结果
        Page page = FuncWeb.getPage(1, 10);
        Map<String, Object> params=new HashMap<>();
        SqlInfoQueryWrapper.Wrapper queryWrapper = SqlHelper.getQueryWrapper();
        //处理占位符参数
        Func.replaceParam(param.getExplainSql(), params, null, lideeYunJiAdapter);
        queryWrapper.setTableSql(param.getExplainSql());//sql
        if(Func.isNotEmpty(param.getDataSourcesCode())){
            queryWrapper.setDataSourceType(param.getDataSourcesCode());
            queryWrapper.setTenantIgnore(true);//外部数据源 直接忽略多租户
        }
        try{
            IPage<Map<String, Object>> pages = sqlService.getDataIPageByPlus(page, queryWrapper,params);
            List<Map<String, Object>> records = pages.getRecords();
            resultMap = super.formatExplainSqlField(records);
            return BaseWebResult.success(resultMap);
        }catch (Exception  e){
        }
        return BaseWebResult.success(resultMap);
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @GetMapping("/get/not-in-dbform-tables")
    @ApiOperationSupport(order = 11)
    @Operation(tags = "表单开发",summary = "获取未在表单开发里面的表")
    public BaseWebResult getNotInDbformTables() {
        List<NotInDbformTablesVo> voList = dbFormService.getNotInDbformTables();
        return BaseWebResult.success(voList);
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @GetMapping("/get/tables-field")
    @ApiOperationSupport(order = 11)
    @Operation(tags = "表单开发",summary = "获取表字段")
    public BaseWebResult getTableField(String tableName) {
        List<TableFieldModelVo> voList = dbFormService.getTableFieldComment(tableName);
        return BaseWebResult.success(voList);
    }

    @PreAuthorize("@ss.hasPermission('lideeyunji:dbform:create')")
    @GetMapping("/ai/create-table")
    @ApiOperationSupport(order = 12)
    @Operation(tags = "表单开发",summary = "AI自动生成表")
    public BaseWebResult aiCreateTable(String prompt) {

            IChatService chatService = aiService.getChatService(PlatformType.KIMI);

            //有时候生成失败，重试3次
            for (int i = 0; i < 3; i++) {
               try{
                   ChatBaseRequest chatBaseRequest = ChatBaseRequest.builder()
                           .messages(CreateTableTemplate.getMessageTemplateList())
                           .message(ChatMessage.withUser(prompt))
                           .build();
                   ChatBaseResponse chatBaseResponse = chatService.chatCompletion(chatBaseRequest);
                   List<Choice> choices = chatBaseResponse.getChoices();
                   if(FuncBase.isEmpty(choices)){
                       continue;
                   }
                   Choice choice = choices.get(0);
                   ChatMessage message = choice.getMessage();
                   if(FuncBase.isEmpty(message)){
                       continue;
                   }
                   String content = message.getContent();
                   CreateTableTemplate.RspModel rspModel = FuncBase.json2Bean(content, CreateTableTemplate.RspModel.class);
                   return BaseWebResult.success(rspModel);
               }catch (Exception e){
                   e.printStackTrace();
               }
            }

        return BaseWebResult.error(FrameErrorCodeConstants.FRAM_SELF_ERROR.getCode(),"生成失败");
    }
}
