hym 4 سال پیش
والد
کامیت
8f218a234a

+ 5 - 6
meter-reading-sishui/read-sqlSever/pom.xml

@@ -48,11 +48,7 @@
             <artifactId>mysql-connector-java</artifactId>
             <scope>runtime</scope>
         </dependency>
-        <dependency>
-            <groupId>com.microsoft.sqlserver</groupId>
-            <artifactId>sqljdbc4</artifactId>
-            <version>4.0</version>
-        </dependency>
+
         <!--Druid-->
         <dependency>
             <groupId>com.alibaba</groupId>
@@ -80,7 +76,10 @@
             <groupId>javax.servlet</groupId>
             <artifactId>jstl</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>com.microsoft.sqlserver</groupId>
+            <artifactId>mssql-jdbc</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 39 - 12
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/controller/DemoController.java

@@ -2,10 +2,15 @@ package com.zcxk.controller;
 
 import com.zcxk.dao.mysql.SendDao;
 import com.zcxk.dao.sqlserver.ReceiveDao;
+import com.zcxk.entity.MeterDataEntity;
+import com.zcxk.entity.TaskEntity;
+import com.zcxk.entity.UploadWaterMeterDataEntity;
+import com.zcxk.entity.WaterMeterBaseEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -16,23 +21,45 @@ public class DemoController {
     ReceiveDao receiveDao;
     @Autowired
     SendDao sendDao;
-    @GetMapping("/test")
+    @GetMapping("/getBaseInfo")
     public void countPlanDevice(){
-        sendDao.selectOne();
-        Map<String,Object>args=new HashMap<>();
-        args.put("regionId",null);
-      /*  List<Map<String, Object>> meterInfor = receiveDao.getMeterInfor(args);
-       // List<Map<String, Object>> meterChangeRecord = receiveDao.getMeterChangeRecord(args);
-        args.clear();
+        //sendDao.selectOne();
+        WaterMeterBaseEntity waterMeterBaseEntity=new WaterMeterBaseEntity();
+       List<Map<String, Object>> meterInfor = receiveDao.getMeterInfor(waterMeterBaseEntity);
+
+        System.out.println(meterInfor);
+
+    }
+    @GetMapping("/uploadData")
+    public void uploadData(){
         Map<String,Object>args2=new HashMap<>();
         List<Map<String, Object>> uploadPlan = receiveDao.getUploadPlan(args2);
         uploadPlan.forEach(map->{
-          //  args.put("planId ",map.get("PlanId"));
-            receiveDao.creatUploadTask(args);
-        });
+            TaskEntity taskEntity=new TaskEntity();
+            taskEntity.setPlanId((String) map.get("PlanId"));
+            receiveDao.creatUploadTask(taskEntity);
+            if(taskEntity.getReturnCode()==1){
 
-       // receiveDao.meterDataInsert(args);
-        System.out.println(1);*/
 
+               try {
+
+                   List<MeterDataEntity>datas=new ArrayList<>();
+                   MeterDataEntity meterDataEntity=new MeterDataEntity();
+                   meterDataEntity.setReleationId("1");
+                   meterDataEntity.setCurrentReading(12.05f);
+                   meterDataEntity.setCurrentReadDate("2020-12-29 12:15:16");
+                   datas.add(meterDataEntity);
+                   UploadWaterMeterDataEntity uploadWaterMeterDataEntity=new UploadWaterMeterDataEntity();
+                   uploadWaterMeterDataEntity.setTaskId(taskEntity.getTaskId());
+                   uploadWaterMeterDataEntity.setMeterData(datas);
+                   receiveDao.meterDataInsert(uploadWaterMeterDataEntity);
+                   System.out.println(1);
+               }catch (Exception e){
+                   e.printStackTrace();
+               }
+
+            }
+
+        });
     }
 }

+ 7 - 4
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/dao/sqlserver/ReceiveDao.java

@@ -1,5 +1,8 @@
 package com.zcxk.dao.sqlserver;
 
+import com.zcxk.entity.TaskEntity;
+import com.zcxk.entity.UploadWaterMeterDataEntity;
+import com.zcxk.entity.WaterMeterBaseEntity;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.util.List;
@@ -8,13 +11,13 @@ import java.util.Map;
 @Mapper
 public interface ReceiveDao {
 
-   List<Map<String,Object>> getMeterInfor(Map<String,Object> map);
+   List<Map<String,Object>> getMeterInfor(WaterMeterBaseEntity waterMeterBaseEntity);
    List<Map<String,Object>>  getMeterChangeRecord(Map<String,Object> map);
    List<Map<String,Object>> getUploadPlan(Map<String,Object> map);
-   void creatUploadTask(Map<String,Object> map);
-   void meterDataInsert(Map<String,Object> map);
+   void creatUploadTask(TaskEntity taskEntity);
+   void meterDataInsert(UploadWaterMeterDataEntity uploadWaterMeterDataEntity);
    void dropMeterDataTable();
    void createMeterDataTable();
-   void insertIntoMeterDataTemp(Map<String,Object>map);
+   void insertIntoMeterDataTemp(List<Map<String,Object>>map);
    void insertIntoMeterData();
 }

+ 31 - 0
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/entity/MeterDataEntity.java

@@ -0,0 +1,31 @@
+package com.zcxk.entity;
+
+public class MeterDataEntity {
+    private String releationId;
+    private float currentReading;
+    private String currentReadDate;
+
+    public String getReleationId() {
+        return releationId;
+    }
+
+    public void setReleationId(String releationId) {
+        this.releationId = releationId;
+    }
+
+    public float getCurrentReading() {
+        return currentReading;
+    }
+
+    public void setCurrentReading(float currentReading) {
+        this.currentReading = currentReading;
+    }
+
+    public String getCurrentReadDate() {
+        return currentReadDate;
+    }
+
+    public void setCurrentReadDate(String currentReadDate) {
+        this.currentReadDate = currentReadDate;
+    }
+}

+ 40 - 0
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/entity/TaskEntity.java

@@ -0,0 +1,40 @@
+package com.zcxk.entity;
+
+public class TaskEntity {
+    private String planId;
+    private String taskId;
+    private Integer returnCode;
+    private String returnMsg;
+
+    public String getPlanId() {
+        return planId;
+    }
+
+    public void setPlanId(String planId) {
+        this.planId = planId;
+    }
+
+    public String getTaskId() {
+        return taskId;
+    }
+
+    public void setTaskId(String taskId) {
+        this.taskId = taskId;
+    }
+
+    public Integer getReturnCode() {
+        return returnCode;
+    }
+
+    public void setReturnCode(Integer returnCode) {
+        this.returnCode = returnCode;
+    }
+
+    public String getReturnMsg() {
+        return returnMsg;
+    }
+
+    public void setReturnMsg(String returnMsg) {
+        this.returnMsg = returnMsg;
+    }
+}

+ 43 - 0
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/entity/UploadWaterMeterDataEntity.java

@@ -0,0 +1,43 @@
+package com.zcxk.entity;
+
+import java.util.List;
+
+public class UploadWaterMeterDataEntity {
+    private Integer returnCode;
+    private String returnMsg;
+    private String taskId;
+    private List<MeterDataEntity> meterData;
+
+    public Integer getReturnCode() {
+        return returnCode;
+    }
+
+    public void setReturnCode(Integer returnCode) {
+        this.returnCode = returnCode;
+    }
+
+    public String getReturnMsg() {
+        return returnMsg;
+    }
+
+    public void setReturnMsg(String returnMsg) {
+        this.returnMsg = returnMsg;
+    }
+
+    public String getTaskId() {
+        return taskId;
+    }
+
+    public void setTaskId(String taskId) {
+        this.taskId = taskId;
+    }
+
+
+    public List<MeterDataEntity> getMeterData() {
+        return meterData;
+    }
+
+    public void setMeterData(List<MeterDataEntity> meterData) {
+        this.meterData = meterData;
+    }
+}

+ 31 - 0
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/entity/WaterMeterBaseEntity.java

@@ -0,0 +1,31 @@
+package com.zcxk.entity;
+
+public class WaterMeterBaseEntity {
+    private Integer returnCode;
+    private String returnMsg;
+    private String regionId;
+
+    public Integer getReturnCode() {
+        return returnCode;
+    }
+
+    public void setReturnCode(Integer returnCode) {
+        this.returnCode = returnCode;
+    }
+
+    public String getReturnMsg() {
+        return returnMsg;
+    }
+
+    public void setReturnMsg(String returnMsg) {
+        this.returnMsg = returnMsg;
+    }
+
+    public String getRegionId() {
+        return regionId;
+    }
+
+    public void setRegionId(String regionId) {
+        this.regionId = regionId;
+    }
+}

+ 44 - 0
meter-reading-sishui/read-sqlSever/src/main/java/com/zcxk/handle/TableTypeHandle.java

@@ -0,0 +1,44 @@
+package com.zcxk.handle;
+
+import com.microsoft.sqlserver.jdbc.SQLServerDataTable;
+import com.zcxk.entity.MeterDataEntity;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+
+
+import java.sql.*;
+import java.util.List;
+
+public class TableTypeHandle extends BaseTypeHandler{
+
+    @Override
+    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Object paramter, JdbcType jdbcType) throws SQLException {
+        SQLServerDataTable sourceDataTable = new SQLServerDataTable();
+
+        sourceDataTable.addColumnMetadata("releationId" ,java.sql.Types.INTEGER);
+
+        sourceDataTable.addColumnMetadata("currentReading" , Types.DECIMAL);
+        sourceDataTable.addColumnMetadata("currentReadDate" , Types.VARCHAR);
+        List<MeterDataEntity>dataList= (List<MeterDataEntity>) paramter;
+       for (MeterDataEntity meterDataEntity : dataList) {
+            sourceDataTable.addRow(meterDataEntity.getReleationId(), meterDataEntity.getCurrentReading(),meterDataEntity.getCurrentReadDate());
+
+        }
+        preparedStatement.setObject(i,sourceDataTable);
+    }
+
+    @Override
+    public Object getNullableResult(ResultSet resultSet, String s) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Object getNullableResult(ResultSet resultSet, int i) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Object getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
+        return null;
+    }
+}

+ 1 - 1
meter-reading-sishui/read-sqlSever/src/main/resources/application-dev.properties

@@ -1,7 +1,7 @@
 server.port=9080
 spring.application.name=sishui-meter-reading
 logging.file.path=./logs/sishui-meter-reading
-logging.level.root=info
+logging.level.root=debug
 spring.datasource.hikari.max-lifetime=30000
 spring.datasource.mysql.jdbc-url=jdbc:mysql://114.135.61.188:33306/sms?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
 spring.datasource.mysql.username=root

+ 9 - 8
meter-reading-sishui/read-sqlSever/src/main/resources/sqlserver-mapper/ReceiveDao.xml

@@ -9,7 +9,7 @@
 
 
 
-    <select id="getMeterInfor" parameterType="map"  statementType="CALLABLE" resultType="map">
+    <select id="getMeterInfor" parameterType="com.zcxk.entity.WaterMeterBaseEntity"  statementType="CALLABLE" resultType="map">
         <![CDATA[ { call DBi_GetMeterInfor_Batch(
                 #{regionId,mode=IN,jdbcType=VARCHAR},
                 #{returnCode,mode=OUT,jdbcType=INTEGER},
@@ -37,23 +37,24 @@
             }
               ]]>
     </select>
-    <update id="creatUploadTask" parameterType="map" statementType="CALLABLE">
-        { call DBi_CreateUploadTask(
+    <update id="creatUploadTask" parameterType="com.zcxk.entity.TaskEntity" statementType="CALLABLE">
+      { call DBi_CreateUploadTask(
                 #{planId,mode=IN,jdbcType=VARCHAR},
                 #{taskId,mode=OUT,jdbcType=VARCHAR},
                 #{returnCode,mode=OUT,jdbcType=INTEGER},
                 #{returnMsg,mode=OUT,jdbcType=VARCHAR}
             )
             }
+
     </update>
-    <update id="meterDataInsert" parameterType="map" statementType="CALLABLE">
-        { call DBi_MeterDataInsert_Batch(
+    <update id="meterDataInsert" parameterType="com.zcxk.entity.UploadWaterMeterDataEntity" statementType="CALLABLE">
+        <![CDATA[  { call DBi_MeterDataInsert_Batch(
                 #{taskId,mode=IN,jdbcType=VARCHAR},
-                #{meterData,mode=IN,jdbcType=VARCHAR},
+                #{meterData,mode=IN,jdbcType=OTHER,typeHandler=com.zcxk.handle.TableTypeHandle},
                 #{returnCode,mode=OUT,jdbcType=INTEGER},
                 #{returnMsg,mode=OUT,jdbcType=VARCHAR}
             )
-            }
+            }   ]]>
     </update>
     <update id="dropMeterDataTable">
         drop table huaxu_meter_data
@@ -73,6 +74,6 @@
         </foreach >
     </insert>
     <insert id="insertIntoMeterData">
-        insert into @meterData (releationId,currentReading,currentReadDate) select *from huaxu_meter_data
+        insert into  Table_MeterDataInsertBatch (releationId,currentReading,currentReadDate) select * from huaxu_meter_data
     </insert>
 </mapper>