|
@@ -0,0 +1,263 @@
|
|
|
+package com.zkqy.web.controller.system;
|
|
|
+
|
|
|
+import com.zkqy.common.annotation.Log;
|
|
|
+import com.zkqy.common.core.controller.BaseController;
|
|
|
+import com.zkqy.common.core.domain.AjaxResult;
|
|
|
+import com.zkqy.common.core.page.TableDataInfo;
|
|
|
+import com.zkqy.common.enums.BusinessType;
|
|
|
+import com.zkqy.common.utils.PlaceholderReplacer;
|
|
|
+import com.zkqy.common.utils.poi.ExcelUtil;
|
|
|
+import com.zkqy.system.domain.SysBusinessFlowScript;
|
|
|
+import com.zkqy.system.service.ISysBusinessFlowScriptService;
|
|
|
+import com.zkqy.web.controller.utils.DefaultPackageCompiler;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 业务脚本Controller
|
|
|
+ *
|
|
|
+ * @author zkqy
|
|
|
+ * @date 2025-05-19
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/system/SysBusinessFlowScript")
|
|
|
+@Api(value = "/system/SysBusinessFlowScript", description = "业务脚本-接口")
|
|
|
+@Slf4j
|
|
|
+public class SysBusinessFlowScriptController extends BaseController
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private ISysBusinessFlowScriptService sysBusinessFlowScriptService;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${template.urlBusiness.javaDownload}")
|
|
|
+ private String urlJavaTemplateDownload;
|
|
|
+
|
|
|
+ @Value("${template.urluPload}")
|
|
|
+ private String urluPload;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询业务脚本列表
|
|
|
+ */
|
|
|
+ //@PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:list')")
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperation(value = "查询业务脚本列表")
|
|
|
+ public TableDataInfo list(SysBusinessFlowScript sysBusinessFlowScript)
|
|
|
+ {
|
|
|
+ startPage();
|
|
|
+ List<SysBusinessFlowScript> list = sysBusinessFlowScriptService.selectSysBusinessFlowScriptList(sysBusinessFlowScript);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+// @GetMapping("/list/all")
|
|
|
+// @ApiOperation(value = "查询业务脚本列表")
|
|
|
+// public TableDataInfo listAll(SysBusinessFlowScript sysBusinessFlowScript)
|
|
|
+// {
|
|
|
+// List<SysBusinessFlowScript> list = sysBusinessFlowScriptService.selectSysBusinessFlowScriptList(sysBusinessFlowScript);
|
|
|
+// return getDataTable(list);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出业务脚本列表
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:export')")
|
|
|
+ @Log(title = "业务脚本", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/export")
|
|
|
+ @ApiOperation(value = "导出业务脚本列表")
|
|
|
+ public void export(HttpServletResponse response, SysBusinessFlowScript sysBusinessFlowScript)
|
|
|
+ {
|
|
|
+ List<SysBusinessFlowScript> list = sysBusinessFlowScriptService.selectSysBusinessFlowScriptList(sysBusinessFlowScript);
|
|
|
+ ExcelUtil<SysBusinessFlowScript> util = new ExcelUtil<SysBusinessFlowScript>(SysBusinessFlowScript.class);
|
|
|
+ util.exportExcel(response, list, "业务脚本数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取业务脚本详细信息
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:query')")
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ @ApiOperation(value = "获取业务脚本详细信息")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
+ {
|
|
|
+ return success(sysBusinessFlowScriptService.selectSysBusinessFlowScriptById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增业务脚本
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:add')")
|
|
|
+ @Log(title = "业务脚本", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ @ApiOperation(value = "新增业务脚本")
|
|
|
+ public AjaxResult add(@RequestBody SysBusinessFlowScript sysBusinessFlowScript)
|
|
|
+ {
|
|
|
+ return toAjax(sysBusinessFlowScriptService.insertSysBusinessFlowScript(sysBusinessFlowScript));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改业务脚本
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:edit')")
|
|
|
+ @Log(title = "业务脚本", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ @ApiOperation(value = "修改业务脚本")
|
|
|
+ public AjaxResult edit(@RequestBody SysBusinessFlowScript sysBusinessFlowScript)
|
|
|
+ {
|
|
|
+ return toAjax(sysBusinessFlowScriptService.updateSysBusinessFlowScript(sysBusinessFlowScript));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除业务脚本
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:SysBusinessFlowScript:remove')")
|
|
|
+ @Log(title = "业务脚本", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ @ApiOperation(value = "删除业务脚本")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
+ {
|
|
|
+ return toAjax(sysBusinessFlowScriptService.deleteSysBusinessFlowScriptByIds(ids));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 脚本节点上传
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("businessKey") String businessKey) {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return AjaxResult.error("请选择一个文件上传");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 1、上传文件的文件名称就是businessKey
|
|
|
+
|
|
|
+ // 2、确保保存文件的目录存在
|
|
|
+ Path uploadPath = Paths.get(urluPload);
|
|
|
+ if (!Files.exists(uploadPath)) {
|
|
|
+ Files.createDirectories(uploadPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3、删除对应的java源文件
|
|
|
+ StringBuffer stringBuffer=new StringBuffer();
|
|
|
+ stringBuffer.append(urluPload).append(businessKey);
|
|
|
+ File newFile = new File(stringBuffer.toString());
|
|
|
+ // 如果存在编译文件就把编译文件删除掉从新编译
|
|
|
+ if (newFile.exists()) {
|
|
|
+ newFile.delete();
|
|
|
+ log.info("java源文件删除成功!!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4、删除对应的编译文件
|
|
|
+ String methodName = file.getOriginalFilename().replace(".java", "");//替换内容
|
|
|
+ // 判断有没有生成对应的编译文件如果有就把编译文件删除掉
|
|
|
+ StringBuffer stringBufferClass=new StringBuffer();
|
|
|
+ stringBufferClass.append(urluPload).append(businessKey).append(".class");
|
|
|
+ File newFileClass = new File(stringBufferClass.toString());
|
|
|
+ // 如果存在编译文件就把编译文件删除掉从新编译
|
|
|
+ if (newFileClass.exists()) {
|
|
|
+ newFileClass.delete();
|
|
|
+ log.info("编译文件删除成功!!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5、将文件保存到指定路径
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ String pathString = urluPload + businessKey + ".java";
|
|
|
+ Path path = Paths.get(pathString);
|
|
|
+ Files.write(path, bytes);
|
|
|
+
|
|
|
+ PlaceholderReplacer placeholderReplacer = new PlaceholderReplacer();
|
|
|
+ //查询脚本信息
|
|
|
+// SysBpmNodeScript sysBpmNodeScript1 = sysBpmNodeScriptService.selectSysBpmNodeScriptByScriptKey(replace);
|
|
|
+ //COMPONENT_ID PLACEHOLDERDesc
|
|
|
+ placeholderReplacer.setCOMPONENT_ID(businessKey); //脚本id
|
|
|
+ placeholderReplacer.setPLACEHOLDERDesc(file.getOriginalFilename());// 脚本描述----脚本名称
|
|
|
+ // 更改文件内容
|
|
|
+ // 第一步:将注解中的内容替换为占位符
|
|
|
+ String filledContent = placeholderReplacer.replaceWithPlaceholder(pathString);
|
|
|
+ // 第二步:将填充好的内容写入新文件
|
|
|
+ placeholderReplacer.createNewFile(pathString, filledContent);
|
|
|
+
|
|
|
+ // 6、开始把java文件编译成.class文件
|
|
|
+ DefaultPackageCompiler defaultPackageCompiler=new DefaultPackageCompiler();
|
|
|
+ String s = defaultPackageCompiler.compileJavaFile(pathString);
|
|
|
+ if(s.equals("编译成功")){
|
|
|
+ return AjaxResult.success("文件上传+编译成功", methodName);
|
|
|
+ }else {
|
|
|
+ // java 源文件
|
|
|
+ if (newFile.exists()) {
|
|
|
+ newFile.delete();
|
|
|
+ log.info("java源文件删除成功!!!");
|
|
|
+ }
|
|
|
+ // class 文件
|
|
|
+ if (newFileClass.exists()) {
|
|
|
+ newFileClass.delete();
|
|
|
+ log.info("class编译文件删除成功!!!");
|
|
|
+ }
|
|
|
+ return AjaxResult.error("编译失败,上传文件失败");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error("读取文件失败: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载java模板
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/download")
|
|
|
+ public ResponseEntity<Resource> downloadJavaTemplate() throws IOException {
|
|
|
+ // 加载模板文件
|
|
|
+ Resource resource = new FileSystemResource(urlJavaTemplateDownload);
|
|
|
+ // 设置响应头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=template.java");
|
|
|
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE);
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .contentLength(resource.contentLength())
|
|
|
+ .body(resource);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 下载对应行的java代码
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/download/code")
|
|
|
+ public ResponseEntity<Resource> downloadJavaCode(String businessKey) throws IOException {
|
|
|
+ String fileName = businessKey + ".java";
|
|
|
+ // 加载模板文件
|
|
|
+ Resource resource = new FileSystemResource(urluPload + fileName);
|
|
|
+ // 设置响应头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);
|
|
|
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE);
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .contentLength(resource.contentLength())
|
|
|
+ .body(resource);
|
|
|
+ }
|
|
|
+}
|