2 Incheckningar ccb4180d69 ... 5470e625c6

Upphovsman SHA1 Meddelande Datum
  maxiaoxia 5470e625c6 Merge branch 'master' of http://49.4.49.126:3000/GYEE_R.D/Gyee_Frame_NX 4 år sedan
  maxiaoxia e0fa4cfc11 标准点表 4 år sedan

+ 92 - 0
src/main/java/com/gyee/frame/controller/StandardPointTable/StandardPointTableController.java

@@ -0,0 +1,92 @@
+package com.gyee.frame.controller.StandardPointTable;
+
+
+import com.gyee.frame.service.StandardPointTable.StandardPointTableService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 标准点表
+ * @author 马晓霞
+ * @email maxiaoxia@gyee-china.com
+ * @date 2021-1-9 17:00:04
+ */
+
+@RestController
+@RequestMapping("/UnionTable")
+public class StandardPointTableController {
+
+    List<Map<String,Object>> unionData= new ArrayList<>();
+
+    @Autowired
+    private StandardPointTableService standardPointTableService;
+
+    /**
+     * 数据库表名
+     *
+     * @param
+     * @return 返回数据库表名
+     */
+    @GetMapping("/tableNames")
+    public List<String> getTableName() {
+        return standardPointTableService.getTableName();
+    }
+
+    /**
+     * 查询列名
+     * @param tableName 表名
+     * @return
+     */
+    @CrossOrigin(origins  = "*",maxAge = 3600)
+    @PostMapping("/columns")
+    @ResponseBody
+    public  List<String> getAllColumns(@RequestBody String tableName){
+
+        return standardPointTableService.getAllColumns(tableName.substring(0,tableName.length()-1 ));
+    }
+
+    /**
+     * 联合表
+     * @param map 表名,列名,excel数据
+     * @return 联合表
+     */
+    @CrossOrigin(origins  = "*",maxAge = 3600)
+    @ResponseBody
+    @PostMapping("/tableData")
+    public List<Map<String, Object>> getDataByColumns(  @RequestBody Map<String, Object> map) {
+
+        String tableName = (String) map.get("tableName");
+        List columnsName  = (List)map.get("columnsName");
+        List<Map<String, Object>> excelData  = (List) map.get("excelData");
+
+        String stringColumnsName="";
+        for (int i=0; i<columnsName.size();i++) {
+            stringColumnsName +=columnsName.get(i)+(i==columnsName.size()-1 ? "":",");
+        }
+        unionData = standardPointTableService.getDataByColumns(tableName,stringColumnsName,excelData);
+        return unionData;
+    }
+
+    /**
+     * 将上面展示出来的数据保存到数据库
+     *
+     * @param tableName 数据库表名
+     */
+    @PostMapping("/saveData")
+    @ResponseBody
+    @CrossOrigin(origins  = "*",maxAge = 3600)
+    public String saveTableData(@RequestBody String tableName) {
+
+        standardPointTableService.saveData(unionData,tableName.substring(0,tableName.length()-1 ));
+
+        return "保存成功";
+    }
+
+}
+
+

+ 35 - 0
src/main/java/com/gyee/frame/mapper/StandardPointTableMapper/StandardPointTableMapper.java

@@ -0,0 +1,35 @@
+package com.gyee.frame.mapper.StandardPointTableMapper;
+
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+@Repository
+public interface StandardPointTableMapper {
+
+    //所有表名
+    @Select("select table_name from user_tables")
+    List<String> getTableName();
+
+    //指定表字段
+    @Select( "SELECT column_name FROM user_tab_columns where table_name = upper('${tableName}') ")
+    List<String> getAllColumns(@Param("tableName") String tableName);
+
+    //根据指定列查询出数据
+    @Select( "SELECT ${columnsName} FROM ${tableName}")
+    List<Map<String, Object>> getDataByColumns(@Param("tableName") String tableName, @Param("columnsName") String columnsName);
+
+    //存到数据库
+//    @Select("insert into ${tableName}\n" +
+//            "    <foreach item=\"value\" collection=\"unionData\" index=\"key\" open=\"(\"   separator=\",\" close=\")\">\n" +
+//            "      ${key}\n" +
+//            "    </foreach>\n" +
+//            "    values\n" +
+//            "    <foreach item=\"value\" collection=\"unionData\" index=\"key\"  open=\"(\"   separator=\",\" close=\")\">\n" +
+//            "      #{value}\n" +
+//            "    </foreach>")
+    void saveData(@Param("unionData") Map<String, Object> unionData,@Param("tableName") String tableName);
+}

+ 57 - 0
src/main/java/com/gyee/frame/service/StandardPointTable/StandardPointTableService.java

@@ -0,0 +1,57 @@
+package com.gyee.frame.service.StandardPointTable;
+
+import com.gyee.frame.mapper.StandardPointTableMapper.StandardPointTableMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+@Service
+public class StandardPointTableService {
+    @Resource
+    private StandardPointTableMapper standardPointTableMapper;
+
+    //获得数据表名
+    public List getTableName(){ return standardPointTableMapper.getTableName(); }
+
+    //获取表的所有列名
+    public List<String> getAllColumns(String tableName)
+    {
+        return standardPointTableMapper.getAllColumns(tableName);
+    }
+
+    //联合表
+    public List<Map<String, Object>> getDataByColumns(@Param("tableName") String tableName, @Param("columnsName") String columnsName, @Param("excelData")List<Map<String, Object>> excelData) {
+
+        List<Map<String, Object>> dataByColumnsName = standardPointTableMapper.getDataByColumns(tableName,columnsName);//数据库数据
+
+        ArrayList<Map<String,Object>> uniformTable=new ArrayList<>() ;
+        Iterator<Map<String,Object>> tableRowIterator=dataByColumnsName.iterator();//数据库表的行
+        while (tableRowIterator.hasNext())//根据数据库表的风机导航
+        {
+            Map<String,Object> tabRow=tableRowIterator.next();
+            Iterator<Map<String,Object>> excelRowIterator=excelData.iterator();//excel的行
+            while (excelRowIterator.hasNext()) // Excel表的行
+            {
+                Map<String,Object> newRow=new HashMap<>() ;
+                newRow.putAll(excelRowIterator.next()); //
+                newRow.putAll(tabRow); // 加上数据库表的行,
+                uniformTable.add(newRow);//联合表加上合成后的行
+            }
+
+        }
+        return uniformTable;
+    }
+
+    //将数据存到数据库
+    public void saveData(@Param("unionData")List<Map<String, Object>> unionData,@Param("tableName") String tableName){
+        Iterator<Map<String,Object>> Data=unionData.iterator();
+        while (Data.hasNext()) {
+            standardPointTableMapper.saveData(Data.next(), tableName);
+
+        }
+
+    }
+
+}

+ 17 - 0
src/main/resources/mybatis/standardPointTableMybatis/StandardPointTableMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gyee.frame.mapper.StandardPointTableMapper.StandardPointTableMapper">
+    <!--collection中的unionData是dao层传入的map参数,item中的value表示unionData中的值,index中的key表示map中键-->
+    <!--foreach进行循环unionData取出里面的key和value-->
+    <insert id="saveData"  >
+        insert into ${tableName}
+        <foreach item="value" collection="unionData" index="key" open="("   separator="," close=")">
+            ${key}
+        </foreach>
+        values
+        <foreach item="value" collection="unionData" index="key"  open="("   separator="," close=")">
+            #{value}
+        </foreach>
+    </insert>
+</mapper>
+