Browse Source

数据集管理模块,静态,动态数据集bug修改

Rgx 8 months ago
parent
commit
08d4dfc295

+ 19 - 5
src/main/java/io/renren/modules/dataSet/service/impl/DynamicSystemServiceImpl.java

@@ -326,7 +326,14 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
 
     @Override
     public Map<String, List<String>> getEqumentOneColumnTimeLimit(String hbaseTableName, String[] needFileds, Integer limit,Long start,Long end) {
-        String[] fileds = needFileds;
+        String[] fileds = new String[needFileds.length];
+        for(int i = 0; i < fileds.length; i++){
+            if(!needFileds[i].equals("time") ){
+                fileds[i] = needFileds[i] + "_after";
+            }else{
+                fileds[i] = needFileds[i];
+            }
+        }
         final List<Map> equmentAll = getContentTimeLimit(hbaseTableName, limit,start,end);
         Map<String, List<String>> needColumnMap = new HashMap<>();
         if (equmentAll.size() == 0) return needColumnMap;
@@ -452,11 +459,17 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
     }
 
     public String runSave_coal(Map map) {
+        List choosedataZh = (List<String>)map.get("chosedataZh");
         StringBuilder s = new StringBuilder();
         String hbaseTableName = (String) map.get("hbaseTableName");
         if (hbaseTableName.length()==0|| "".equals(hbaseTableName)) return "数据源为空!!!";
         List choosedatas = (List<String>) map.get("chosedata");
         if(choosedatas.size() ==0) return "请选择字段!!!";
+        if(choosedataZh.size() == 0){
+            for(int i = 0; i < choosedatas.size(); i++){
+                choosedataZh.add(choosedatas.get(i));
+            }
+        }
         String newFileName = (String) map.get("newFileName");
         String oldFileName = (String) map.get("oldFileName");
 //        System.out.println(oldFileName+"--->"+newFileName);
@@ -468,6 +481,7 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
             FileUtil.mkdir(path);
         }
         String filed = new String();
+        String filedZh = new String();
         List<String> fileds = new ArrayList<>();
 
         String[] chooseDates = (String[]) choosedatas.toArray(new String[choosedatas.size()]);
@@ -476,12 +490,13 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
         final Map<String, List<String>> equmentOneColumn = getEqumentOneColumnTimeLimit(hbaseTableName, chooseDates, 1000,start,end);
         if (equmentOneColumn.isEmpty()) return "数据为空,请检查数据源中是否有数据!!";
         for (int i = 0; i < choosedatas.size(); i++) {
-            filed = (String) choosedatas.get(i);
+            filed = choosedatas.get(i).equals("time")?(String) choosedatas.get(i):(String) choosedatas.get(i)+"_after";
+            filedZh = (String) choosedataZh.get(i);
             // 添加表头
             if (i == 0) {
-                fileds.add(filed);
+                fileds.add(filedZh);
             } else {
-                fileds.set(0, fileds.get(0) + "," + filed);
+                fileds.set(0, fileds.get(0) + "," + filedZh);
             }
             final List<String> columns = equmentOneColumn.get(filed);
 //            List<Subeqpdemo> subeqpdemos = subeqpdemoMapper.getSelectFiled(hbaseTableName, filed);
@@ -529,7 +544,6 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
         }
         return "done";
     }
-
     // 首次创建csv文件
     public String creatCSV(File creatFileName, List<String> fileds) throws IOException {
         BufferedWriter bw = null;

+ 1 - 0
src/main/java/io/renren/modules/job/task/demo1.java

@@ -91,6 +91,7 @@ public class demo1 implements ITask{
                     }
                     map.put("chosedata",chosedata);
                     map.put("userID",dataSetDy.getUid().toString());
+                    map.put("chosedataZh", new ArrayList<String>());
                     System.out.println(map);
                     dynamicSystemService.runSave(map);
                 }

+ 1 - 28
src/main/java/io/renren/modules/levelManage/controller/UniversalTableController.java

@@ -778,34 +778,7 @@ public class UniversalTableController extends AbstractController {
      */
     @RequestMapping(value = {"/getNotLeafItemByParent","/getOtherLeafItem"})    //第一个url是bug,但是已经使用了,就不修改了
     public R getOtherLeafItem(@RequestParam Long tableId,@RequestParam Long id){
-        //1.获取选中的item的相关子item
-        List<LevelRelationEntity> levelRelationEntities= levelRelationService.selectByParent(tableId,id);
-        //2.获取子表名
-        LevelEntity sonLevel=levelService.getEnabledSon(tableId);
-        String sonTableName=sonLevel.getTableName();
-        //3.在表中获取对应的叶子节点信息
-        List<String> tableCols = levelTableService.listColsByLevelId(sonLevel.getId());
-        List<Map<String,Object>> candidateItem=universalTableService.listLeafItem(sonTableName,tableCols);
-        //4.通过检查levelRelationEntities和candidateItem中的重合部分,获取目标item,为了加速,用了HashMap
-        List<Map<String,Object>> data=new ArrayList<>();
-        //用一个map装所有的item,之后遍历关系,将其中的item信息取出,发给前端
-        HashMap<Object,Object> cItemId_lRelationSonId=new HashMap<>();
-        for(int i=0;i<candidateItem.size();i++){
-            cItemId_lRelationSonId.put(candidateItem.get(i).get("id"),i);
-        }
-        for(LevelRelationEntity levelRelation:levelRelationEntities){
-            if(cItemId_lRelationSonId.get(levelRelation.getSonRowId())!=null) {
-                int itemId = (int) cItemId_lRelationSonId.get(levelRelation.getSonRowId());
-                data.add(candidateItem.get(itemId));
-            }
-        }
-        //data是<列名,具体值>的list
-        //对bool值需要修改为是/否,否则前端不显示
-        List<String> boolCols=levelTableService.listBoolColsById(sonLevel.getId());
-        modifyBool(data,boolCols);
-        //去除名字前面的随机数
-        SubString.subStringList(data);
-        return R.ok().put("data",data).put("levelId",sonLevel.getId());
+        return R.ok(universalTableService.getOtherLeafItem(tableId,id));
     }
 
     /**

+ 2 - 0
src/main/java/io/renren/modules/levelManage/service/UniversalTableService.java

@@ -59,5 +59,7 @@ public interface UniversalTableService extends IService<UniversalTableEntity> {
     List<Map<String,Object>>  listAllItemInfo(String tableName, List<String> tableCols);
 
     List<Map<String, Object>> listBySonIdsNotLimit(String tableName, List<String> tableCols, List<Long> sonIds);
+
+    Map<String, Object> getOtherLeafItem(Long tableId, Long id);
 }
 

+ 75 - 0
src/main/java/io/renren/modules/levelManage/service/impl/UniversalTableServiceImpl.java

@@ -5,13 +5,22 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import io.renren.common.utils.PageUtils;
 import io.renren.common.utils.Query;
+import io.renren.common.utils.SubString;
 import io.renren.datasource.annotation.DataSource;
+import io.renren.modules.dataSet.DataSetUtils.ToEnglish;
 import io.renren.modules.levelManage.dao.UniversalTableDao;
+import io.renren.modules.levelManage.entity.LevelEntity;
+import io.renren.modules.levelManage.entity.LevelRelationEntity;
 import io.renren.modules.levelManage.entity.UniversalTableEntity;
+import io.renren.modules.levelManage.service.LevelRelationService;
+import io.renren.modules.levelManage.service.LevelService;
+import io.renren.modules.levelManage.service.LevelTableService;
 import io.renren.modules.levelManage.service.UniversalTableService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -23,6 +32,13 @@ public class UniversalTableServiceImpl extends ServiceImpl<UniversalTableDao, Un
     @Autowired
     UniversalTableDao universalTableDao;
 
+    @Autowired
+    LevelRelationService levelRelationService;
+    @Autowired
+    LevelService levelService;
+    @Autowired
+    LevelTableService levelTableService;
+
     @Override
     public PageUtils queryPage(Map<String, Object> params) {
         IPage<UniversalTableEntity> page = this.page(
@@ -141,4 +157,63 @@ public class UniversalTableServiceImpl extends ServiceImpl<UniversalTableDao, Un
         return universalTableDao.listBySonIdsNotLimit(tableName,tableCols,sonIds);
     }
 
+    @Override
+    public Map<String, Object> getOtherLeafItem(Long tableId, Long id) {
+        //1.获取选中的item的相关子item
+        List<LevelRelationEntity> levelRelationEntities = levelRelationService.selectByParent(tableId, id);
+        //2.获取子表名
+        LevelEntity sonLevel = levelService.getEnabledSon(tableId);
+        if(sonLevel==null)
+            return null;
+        String sonTableName = sonLevel.getTableName();
+        //3.在表中获取对应的叶子节点信息
+        List<String> tableCols = levelTableService.listColsByLevelId(sonLevel.getId());
+        List<Map<String, Object>> candidateItem = listLeafItem(sonTableName, tableCols);
+        //4.通过检查levelRelationEntities和candidateItem中的重合部分,获取目标item,为了加速,用了HashMap
+        List<Map<String, Object>> data = new ArrayList<>();
+        //用一个map装所有的item,之后遍历关系,将其中的item信息取出,发给前端
+        HashMap<Object, Object> cItemId_lRelationSonId = new HashMap<>();
+        for (int i = 0; i < candidateItem.size(); i++) {
+            cItemId_lRelationSonId.put(candidateItem.get(i).get("id"), i);
+        }
+        for (LevelRelationEntity levelRelation : levelRelationEntities) {
+            if (cItemId_lRelationSonId.get(levelRelation.getSonRowId()) != null) {
+                int itemId = (int) cItemId_lRelationSonId.get(levelRelation.getSonRowId());
+                data.add(candidateItem.get(itemId));
+            }
+        }
+        //data是<列名,具体值>的list
+        //对bool值需要修改为是/否,否则前端不显示
+        List<String> boolCols = levelTableService.listBoolColsById(sonLevel.getId());
+        modifyBool(data, boolCols);
+        //去除名字前面的随机数
+        SubString.subStringList(data);
+        //将测点名称转拼音返回前端
+        List<String> pinyin = new ArrayList<>();
+        for (Map<String, Object> datum : data) {
+            pinyin.add(ToEnglish.getPinYin((String) datum.get("name")));
+        }
+        HashMap<String,Object> result=new HashMap<>();
+        result.put("data",data);
+        result.put("levelId", sonLevel.getId());
+        result.put("pinyin", pinyin);
+        return result;
+
+    }
+    private void modifyBool(List<Map<String,Object>> data,List<String> boolCols){
+        for(Map<String,Object> map :data)
+        {
+            for(String col: boolCols)
+            {
+                Byte a =1;
+                if(map.get(col)==a)
+                {
+                    map.put(col,"是");
+                }
+                else
+                    map.put(col,"否");
+            }
+        }
+    }
+
 }