Kaynağa Gözat

Merge remote-tracking branch 'origin/main' into main

# Conflicts:
#	ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java
侯茂昌 1 yıl önce
ebeveyn
işleme
e09c7e25cb

+ 129 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonBtnController.java

@@ -0,0 +1,129 @@
+package com.ruoyi.web.controller.dragForm;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.ruoyi.common.constant.ButtonTypeConstants;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.form.FromUtils;
+import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.DragForm;
+import com.ruoyi.system.entity.DragTableBtn;
+import com.ruoyi.system.service.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author hanzihang
+ * @date 2023/11/16 5:49 PM
+ */
+@RestController
+@RequestMapping("/dragform/commonbtn")
+public class CommonBtnController extends BaseController {
+    @Resource   // 共通crud
+    private ICommonService commonService;
+
+    @Resource  // 动态表单
+    private IDragFormService dragFormService;
+
+    @Resource  // 表格按钮
+    private IDragTableBtnService iDragTableBtnService;
+
+    @Resource
+    private FromUtils fromUtils;
+
+    /**
+     * 处理按钮通用接口(新增、修改、删除)
+     */
+    @PostMapping("/commonBtnHandle")
+    public AjaxResult commonBtnHandle(@RequestBody CommonEntity commonEntity) throws JsonProcessingException {
+
+        //按钮类型
+        Long btnType = Long.valueOf(commonEntity.getBasicMap().get("btnType").toString());
+        String type = "";
+        if (btnType == ButtonTypeConstants.INSERT) {
+            type = "INSERT";
+        } else if (btnType == ButtonTypeConstants.UPDATE) {
+            type = "UPDATE";
+        } else if (btnType == ButtonTypeConstants.DELETE) {
+            type = "DELETE";
+        }
+        /*
+         * 判断什么类型走什么接口:
+         * btnType  10:新增、8:修改、9:删除、5:脚本
+         * visible  false代表弹窗未开启时走回显表单模板及数据信息接口;true代表弹窗开启时走保存数据接口
+         * */
+        //是否提交表单操作 true是 false回显表单数据 commonEntity.getBasicMap().get("visible").toString()
+        switch (type) {
+            case "INSERT":
+                return insertBtn(commonEntity);
+            case "UPDATE":
+                return updateBtn(commonEntity);
+            case "DELETE":
+                return deleteBtn(commonEntity);
+            default:
+                return warn("暂不支持该操作!");
+        }
+    }
+
+
+    // 新增类型按钮
+    public AjaxResult insertBtn(CommonEntity commonEntity) throws JsonProcessingException {
+        if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
+            return AjaxResult.btnMessage(commonService.batchInsert(commonEntity));
+        } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
+            String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
+            return success(dragFormService.selectDragFormBySqlKey(sqlKey));
+        } else {
+            return warn("暂不支持该操作!");
+        }
+    }
+
+
+    // 修改类型按钮
+    public AjaxResult updateBtn(CommonEntity commonEntity) throws JsonProcessingException {
+        //是否开启弹窗
+        if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
+            if (commonEntity.getBasicMap().containsKey("btnKey")) {  // 按钮提交时会触发别的操作
+                // 根据按钮别名查询按钮详细信息
+                DragTableBtn dragTableBtn = iDragTableBtnService.selectDragTableBtnByBtnKey(commonEntity.getBasicMap().get("btnKey").toString());
+                // 根据流程的key判断当前按钮是否执行触发流程
+                if (!dragTableBtn.getBtnProcessKey().isEmpty()) {
+                    // 调用发起流程接口
+                    fromUtils.runBpmProductionScheduling(commonEntity);
+
+//                    if (dragTableBtn.getBtnFormKey().isEmpty()) {  // 校验当前按钮是否是直接触发流程 或者脚本 (新增按钮类型)
+//                        fromUtils.runBpmProductionScheduling(commonEntity);
+//                    }
+
+                } else if (!dragTableBtn.getBtnScriptKey().isEmpty()) {
+                    // 调用执行脚本接口
+                    fromUtils.triggerScript(commonEntity);
+                }
+            }
+            return toAjax(commonService.edit(commonEntity));
+        } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
+            Map<String, Object> map = new HashMap<>();
+            //获取模板信息
+            String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
+            DragForm dragForm = dragFormService.selectDragFormBySqlKey(sqlKey);
+            map.put("template", dragForm);
+            //返回结果
+            map.put("result", commonService.getInfoById(commonEntity));
+            return success(map);
+        } else {
+            return warn("暂不支持该操作!");
+        }
+    }
+
+    // 删除类型按钮
+    public AjaxResult deleteBtn(CommonEntity commonEntity) {
+        return toAjax(commonService.batchDelete(commonEntity));
+    }
+
+}

+ 8 - 7
ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -5,6 +5,8 @@ import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.utils.form.ThisTokenVal;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -18,22 +20,21 @@ import com.ruoyi.framework.web.service.TokenService;
 
 /**
  * token过滤器 验证token有效性
- * 
+ *
  * @author ruoyi
  */
 @Component
-public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
-{
+public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
     @Autowired
     private TokenService tokenService;
 
     @Override
     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
-            throws ServletException, IOException
-    {
+            throws ServletException, IOException {
+        ThisTokenVal.clearMap();
         LoginUser loginUser = tokenService.getLoginUser(request);
-        if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
-        {
+        ThisTokenVal.set(loginUser.getToken(), request.getHeader("Authorization"));
+        if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {
             tokenService.verifyToken(loginUser);
             UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
             authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));

+ 15 - 8
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -140,13 +140,13 @@ public class CommonServiceImpl implements ICommonService {
            }
            Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
 
-           //正常的查询
-           String queryCriteriaValue =
-                        conditions.containsKey("queryCriteriaValue") == true
-                                ? conditions.get("queryCriteriaValue").toString() : "";
-           String endSQL = replaceSql.get().replace("#{val}", queryCriteriaValue);
-           String sqlString=tableSql.getTableSql() + " where " + endSQL;
-           return commonMapper.queryTableList(sqlString);
+        //正常的查询
+        String queryCriteriaValue =
+                conditions.containsKey("queryCriteriaValue") == true
+                        ? conditions.get("queryCriteriaValue").toString() : "";
+        String endSQL = replaceSql.get().replace("#{val}", queryCriteriaValue);
+        String sqlString = tableSql.getTableSql() + " where " + endSQL;
+        return commonMapper.queryTableList(sqlString);
     }
 
 
@@ -289,7 +289,14 @@ public class CommonServiceImpl implements ICommonService {
     public CommonEntity getInfoById(CommonEntity commonEntity) {
         String tableName = (String) commonEntity.getBasicMap().get("tableName");
         Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
-        return commonMapper.getInfoById(tableName,conditions);
+        CommonEntity common = new CommonEntity();
+        Map<String, Object> retMap = commonMapper.getInfoById(tableName, conditions).getResultMap();
+        Map<String, Object> retMap1 = new HashMap<>();
+        retMap.keySet().forEach(item -> {
+            retMap1.put(toUnderScoreCase(item), retMap.get(item));
+        });
+        common.setResultMap(retMap1);
+        return common;
     }
 
     public static String extractSubstring(String input, String identifier) {

+ 49 - 0
ruoyi-system/src/main/java/com/ruoyi/system/test/code/DynamicCodeExecution.java

@@ -0,0 +1,49 @@
+package com.ruoyi.system.test.code;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+
+public class DynamicCodeExecution {
+    public static void main(String[] args) {
+        String codeToExecute = "System.out.println(\"Hello, World12312!\");";
+
+        try {
+            String className = "test";
+            String packageName = DynamicCodeExecution.class.getPackage().getName(); // 获取当前类的包名
+            String sourceCode = "package " + packageName + ";\n" +
+                    "public class " + className + " { public void execute() { " + codeToExecute + " } }";
+
+            // 获取当前包的路径
+            Path packagePath = Paths.get("ruoyi-system/src/main/java", packageName.replace(".", "/"));
+            // 将源代码写入一个.java文件,保存到当前包下
+            Path sourcePath = packagePath.resolve(className + ".java");
+            Files.createDirectories(packagePath);
+            Files.write(sourcePath, sourceCode.getBytes(), StandardOpenOption.CREATE);
+
+            // 使用Java编译器编译.java文件为.class文件
+            Process compileProcess = Runtime.getRuntime().exec("javac " + sourcePath, null, packagePath.toFile());
+            compileProcess.waitFor();
+
+            // 创建一个新的ClassLoader以加载编译后的类
+            DynamicClassLoader classLoader = new DynamicClassLoader();
+            Class<?> dynamicClass = classLoader.loadClass(packageName + "." + className);
+
+            // 在动态生成的类上查找名为"execute"的方法
+            dynamicClass.getMethod("execute").invoke(dynamicClass.newInstance());
+
+            // 删除生成的.java和.class文件
+            Files.deleteIfExists(sourcePath);
+            Files.deleteIfExists(packagePath.resolve(className + ".class"));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
+
+class DynamicClassLoader extends ClassLoader {
+    public Class<?> loadClass(String className) throws ClassNotFoundException {
+        return super.findSystemClass(className);
+    }
+}

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/test/code/test.java

@@ -0,0 +1,2 @@
+package com.ruoyi.system.test.code;
+public class test { public void execute() { System.out.println("Hello, World12312!"); } }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 41 - 11
ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor