Browse Source

伊宁项目更改相关 更新用户子关联添加条件,将手机端跳转参数username动态化

1037015548@qq.com 1 year ago
parent
commit
ba8462ef3c

+ 24 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/UserRelateController.java

@@ -1,5 +1,7 @@
 package com.ruoyi.web.controller.system;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -130,6 +132,17 @@ public class UserRelateController extends BaseController
             properties.load(inputStream);
             String urlRules = properties.getProperty("user_ralte_url_rules[" + userRelate.getDanganId() + "]");
             if(!StringUtils.isEmpty(urlRules)){
+                if(!StringUtils.isEmpty(userRelate.getDanganLoginName())) {
+                    JSONArray jsonArray = JSONArray.parseArray(urlRules);
+                    JSONObject jsonObject = jsonArray.getJSONObject(0);
+                    if("username".equals(jsonObject.getString("key"))) {
+                        jsonObject.put("value", userRelate.getDanganLoginName());
+
+                        JSONArray newJsonArray = new JSONArray();
+                        newJsonArray.add(jsonObject);
+                        urlRules = newJsonArray.toJSONString();
+                    }
+                }
                 userRelate.setUrlRules(urlRules);
             }
         }catch(Exception e){
@@ -189,6 +202,17 @@ public class UserRelateController extends BaseController
                 userRelate.setRelateTime(new Date());
                 String urlRules = properties.getProperty("user_ralte_url_rules[" + userRelate.getDanganId() + "]");
                 if(!StringUtils.isEmpty(urlRules)){
+                    if(!StringUtils.isEmpty(userRelate.getDanganLoginName())) {
+                        JSONArray jsonArray= JSONArray.parseArray(urlRules);
+                        JSONObject jsonObject = jsonArray.getJSONObject(0);
+                        if("username".equals(jsonObject.getString("key"))) {
+                            jsonObject.put("value", userRelate.getDanganLoginName());
+
+                            JSONArray newJsonArray = new JSONArray();
+                            newJsonArray.add(jsonObject);
+                            urlRules = newJsonArray.toJSONString();
+                        }
+                    }
                     userRelate.setUrlRules(urlRules);
                 }
                 userRelate.setCreateBy(ShiroUtils.getLoginName());

+ 36 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/ActionApi.java

@@ -1,5 +1,7 @@
 package com.ruoyi.web.controller.tool;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -185,6 +187,40 @@ public class ActionApi {
     //TODO 本地使用·批量插入用户
     @PostMapping("/testUtil")
     public void testUtil(){
+//        fileImport();
+        updateRelate();
+    }
+    //TODO ① 批量修改子用户关系
+    private void updateRelate(){
+        UserRelate userRelate = new UserRelate();
+        userRelate.setUrlRules("[{key:\"username\",value:\"test\"}]");
+        List<UserRelate> list = userRelateService.selectUserRelateList(userRelate);
+        System.out.println("需修改数:"+list.size());
+        int success = 0;
+        for (UserRelate item : list){
+            if(!StringUtils.isEmpty(item.getUrlRules())){
+                if(!StringUtils.isEmpty(item.getDanganLoginName())) {
+                    JSONArray jsonArray= JSONArray.parseArray(item.getUrlRules());
+                    JSONObject jsonObject = jsonArray.getJSONObject(0);
+                    if("username".equals(jsonObject.getString("key"))) {
+                        jsonObject.put("value", item.getDanganLoginName());
+
+                        JSONArray newJsonArray = new JSONArray();
+                        newJsonArray.add(jsonObject);
+                        item.setUrlRules(newJsonArray.toJSONString());
+                        int result = userRelateService.updateUserRelate(item);
+                        if(result>0){
+                            success+=1;
+                        }
+                    }
+                }
+            }
+        }
+        System.out.println("成功数:"+success);
+    }
+
+    //TODO ② 批量导入
+    private void fileImport(){
         try {
             String path = "D:\\工作文档\\武汉三环科普睿科\\会议笔记\\";
             FileInputStream fileInputStream = new FileInputStream(path + "人员信息导入.xlsx");

+ 1 - 0
ruoyi-system/src/main/resources/mapper/system/UserRelateMapper.xml

@@ -63,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                 AND ur.relate_time &lt;= to_timestamp(#{params.endTime},'YYYY-MM-DD')
             </if>
+            <if test="urlRules != null "> and ur.url_rules = #{urlRules}</if>
         </where>
         order by d.ord
     </select>