赞
踩
芋道源码相信很多朋友都很了解了,今天我们试着基于FastGPT实现芋道框架的代码生成。芋道的代码生成,是基于数据库表字段实现的,那我们的思路就是看看如何使用GPT帮我们生成数据库表结构,只要数据库表字段有了,代码也就生成好了。实现这个需求我们就需要用到FastGPT的高级编排功能。编排的整体思路如下:
@PermitAll @PostMapping("busi/{busiType}") public FastCommonRespVO busi(@PathVariable("busiType") String busiType, @RequestBody Map<String, Object> reqMap) { log.info("请求参数: {}", JSONUtil.toJsonStr(reqMap)); FastCommonRespVO fastCommonRespVO = new FastCommonRespVO(); fastCommonRespVO.setResponse("\\n失败了"); FastBusiTypeEnum fastBusiTypeEnum = FastBusiTypeEnum.getByBusiCode(busiType); if (fastBusiTypeEnum != null) { FastService fastService = SpringUtil.getBean("fast".concat(fastBusiTypeEnum.getBusiCode()).concat("ServiceImpl")); try { // doBusi方法会返回一个完整的代码下载地址 fastCommonRespVO.setResponse("\\n".concat(fastService.doBusi(reqMap))); } catch (Exception e) { log.error("执行业务逻辑失败,异常原因:{}", ExceptionUtils.getStackTrace(e)); fastCommonRespVO.setResponse("\\n执行业务逻辑失败:".concat(e.getMessage())); } } else { fastCommonRespVO.setResponse("\\n非法的业务类型(busiType参数)"); } log.info("响应结果: {}", JSONUtil.toJsonStr(fastCommonRespVO)); return fastCommonRespVO; }
@PermitAll @GetMapping("/download/codegen/{codegenId}") public void downloadCodegen(@PathVariable("codegenId") String codegenId, HttpServletResponse response) throws IOException { log.info("请求参数: codegenId={}", codegenId); // 根据生成代码记录ID查询相关表记录ID Set<String> tableIds = stringRedisTemplate.opsForSet().members(codegenId); if (CollectionUtils.isEmpty(tableIds)) { throw exception(ErrorCodeConstants.AIGC_FAST_NOT_FOUND_RECORD); } // 生成代码 Map<String, String> codes = new HashMap<>(); for (String tableId : tableIds) { codes.putAll(codegenApi.generationCodes(Long.valueOf(tableId))); } // 构建 zip 包 String[] paths = codes.keySet().toArray(new String[0]); ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipUtil.zip(outputStream, paths, ins); // 输出 ServletUtils.writeAttachment(response, "codegen.zip", outputStream.toByteArray()); }
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。