Pārlūkot izejas kodu

[task-1475] 基础数据维护

Li Yuan 2 gadi atpakaļ
vecāks
revīzija
63a1b49cc2

+ 30 - 3
ibps-base-root/modules/base-quartz/src/main/java/com/lc/ibps/components/quartz/BaseJob2.java

@@ -1,8 +1,6 @@
 package com.lc.ibps.components.quartz;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import org.quartz.DisallowConcurrentExecution;
 import org.quartz.Job;
@@ -137,4 +135,33 @@ public abstract class BaseJob2 implements Job {
         return sql.toString();
     }
 
+    // 将map值全部转换为大写
+    public  Map<String, Object> transformUpperCase(Map<String, Object> orgMap) {
+        Map<String, Object> resultMap = new HashMap<>();
+        if (orgMap == null || orgMap.isEmpty()) {
+            return resultMap;
+        }
+        Set<String> keySet = orgMap.keySet();
+        for (String key : keySet) {
+            String newKey = key.toUpperCase();
+            resultMap.put(newKey, orgMap.get(key));
+        }
+        return resultMap;
+
+    }
+
+    // 将map值全部转换为小写
+    public Map<String, Object> transformLowerCase(Map<String, Object> orgMap) {
+        Map<String, Object> resultMap = new HashMap<>();
+        if (orgMap == null || orgMap.isEmpty()) {
+            return resultMap;
+        }
+        Set<String> keySet = orgMap.keySet();
+        for (String key : keySet) {
+            String newKey = key.toLowerCase();
+            resultMap.put(newKey, orgMap.get(key));
+        }
+        return resultMap;
+    }
+
 }

+ 94 - 0
ibps-provider-root/modules/provider-platform/src/main/java/com/lc/ibps/platform/plan/job/BasicDataInitializationJob.java

@@ -0,0 +1,94 @@
+package com.lc.ibps.platform.plan.job;
+
+import com.lc.ibps.base.core.util.AppUtil;
+import com.lc.ibps.base.core.util.Collections;
+import com.lc.ibps.base.framework.id.UniqueIdUtil;
+import com.lc.ibps.base.framework.table.ICommonDao;
+import com.lc.ibps.components.quartz.BaseJob2;
+import org.apache.commons.lang3.BooleanUtils;
+import org.quartz.JobExecutionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class BasicDataInitializationJob extends BaseJob2 {
+
+    private static final Logger logger = LoggerFactory.getLogger(BasicDataInitializationJob.class);
+    private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
+
+    @Override
+    public void executeJob(JobExecutionContext context) throws Exception {
+        //'Y' means just create one records.
+        String[][] tables = {
+                {"t_yjyaylpzb", "t_yjyaylpzzb", "Y", "应急预案演练配置表"},
+                {"t_gzxybmxzxqkjcjlpzb", "t_gzxybmxzxqkjcjlpzzb", "Y", "公正性与保密性检查项配置表"},
+                {"t_ryjdpzb", "t_ryjdpzzb", "N", "人员监督配置表"}};
+
+        //get admin position id.
+        String sql1 = "SELECT positions_ FROM ibps_party_employee WHERE id_=1";
+        Map<String, Object> p = commonDao.queryOne(sql1);
+        if (p == null) return;
+        String posAdmin = (String) p.get("positions_");
+
+
+        for (String[] table : tables) {
+            String sql2 = "SELECT * FROM ibps_party_entity WHERE party_type_='position' AND depth_ IN (3,4) " +
+                    "   AND path_ NOT LIKE '%%%s%%'" +
+                    "   AND id_ NOT IN (SELECT bian_zhi_bu_men_ FROM %s )" +
+                    "   ORDER BY path_";
+            sql2 = String.format(sql2, posAdmin, table[0]);
+            List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql2);
+            if (Collections.isEmpty(list)) continue;
+            for (Map<String, Object> val1 : list) {
+                Map<String, Object> val = this.transformUpperCase(val1);
+
+                String deptId = (String) val.get("ID_");
+                String deptName = (String) val.get("NAME_");
+                String didian = ((String) val.get("PATH_")).split("\\.")[1];
+                int depth = (Integer) val.get("DEPTH_");
+                //skip level 4 dept.
+                if (BooleanUtils.toBoolean(table[2]) && depth == 4) continue;
+
+                String sql3 = String.format("SELECT * FROM %s p WHERE p.bian_zhi_ren_=1 AND p.bian_zhi_bu_men_='%s'", table[0], posAdmin);
+                List<Map<String, Object>> pList = (List<Map<String, Object>>) commonDao.query(sql3);
+                if (Collections.isEmpty(pList)) continue;
+                Map<String, Object> pVal1 = pList.get(0);
+                Map<String, Object> pVal = this.transformUpperCase(pVal1);
+                //insert to parent table.
+                String pId = (String) pVal.get("ID_");
+                String newPID = UniqueIdUtil.getId();
+                pVal.put("ID_", newPID);
+                pVal.put("CREATE_TIME_", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+                if (pVal.containsKey("DI_DIAN_")) {
+                    pVal.put("DI_DIAN_", didian);
+                }
+                if (pVal.containsKey("BIAN_ZHI_BU_MEN_")) {
+                    pVal.put("BIAN_ZHI_BU_MEN_", deptId);
+                }
+                commonDao.execute(this.buildInsertSql(pVal, table[0]));
+
+                //insert to child table.
+                String sql4 = String.format("SELECT c.* FROM %s p , %s c WHERE c.parent_id_ = p.id_ AND p.bian_zhi_ren_=1 " +
+                        "AND p.bian_zhi_bu_men_='%s' AND c.parent_id_='%s'", table[0], table[1], posAdmin, pId);
+
+                List<Map<String, Object>> cList =
+                        (List<Map<String, Object>>) commonDao.query(sql4);
+
+                if (Collections.isEmpty(cList)) continue;
+
+                for (Map<String, Object> cVal1 : cList) {
+                    Map<String, Object> cVal = this.transformUpperCase(cVal1);
+                    cVal.put("ID_", UniqueIdUtil.getId());
+                    cVal.put("PARENT_ID_", newPID);
+                    commonDao.execute(this.buildInsertSql(cVal, table[1]));
+                }
+                logger.error(String.format("Done: %s: table:%s dept:%s",table[3],table[0],deptName));
+            }
+
+        }
+    }
+
+
+}