Przeglądaj źródła

归集数据分析

wangzhe 2 lat temu
rodzic
commit
6a41c2ed78

+ 2 - 1
mybusiness/src/main/java/com/business/controller/GetProvinceController.java

@@ -38,7 +38,8 @@ public class GetProvinceController {
                 "  \"enterpriseName\": \"北京阿里巴巴信息技术有限公司\"\n" +
                 "}";
         try{
-            return HttpUtil2.doPost(url + "/api/cegnir/getEnterpriseUniscId", JSONObject.toJSONString(parem), headerparam);
+//            return HttpUtil2.doPost(url + "/api/cegnir/getEnterpriseUniscId", JSONObject.toJSONString(parem), headerparam);
+            return HttpUtil2.doPost("http://19.133.2.202:6689/api/cegnir/getEnterpriseUniscId", JSONObject.toJSONString(parem), headerparam);
         }catch (Exception e){
             e.printStackTrace();
             return "interfaceErrorMsg:" + e.toString();

+ 2 - 1
mybusiness/src/main/java/com/business/controller/VisualizationController.java

@@ -131,7 +131,8 @@ public class VisualizationController extends BaseController {
     @ResponseBody
     public JSONObject imputationData(){
         JSONObject jsonObject = new JSONObject();
-        interfaceinfoService.imputationData();
+//        interfaceinfoService.imputationData();
+        interfaceinfoService.imputationDataByMonth();
         jsonObject.put("data", "well done");
         return jsonObject;
     }

+ 6 - 0
mybusiness/src/main/java/com/business/domain/ImputationData.java

@@ -17,6 +17,12 @@ public class ImputationData extends BaseEntity
     /** 年份 */
     private String year;
 
+    /** 月份 */
+    private String month;
+
+    /** 当月数量 */
+    private String count;
+
     /** 表名 */
     private String tableName;
 

+ 8 - 0
mybusiness/src/main/java/com/business/mapper/ImputationDataMapper.java

@@ -43,6 +43,14 @@ public interface ImputationDataMapper {
     public int insertImputationInterface(ImputationData imputationData);
 
     /**
+     * 修改接口归集数据
+     *
+     * @param imputationData 根据月份接口归集数据
+     * @return 结果
+     */
+    public int updateImputationInterfaceByYearMonthTableName(ImputationData imputationData);
+
+    /**
      * 修改日志归集数据
      *
      * @param imputationData 日志归集数据

+ 9 - 1
mybusiness/src/main/java/com/sooka/system/mapper/TUInterfaceinfoMapper.java

@@ -82,7 +82,7 @@ public interface TUInterfaceinfoMapper
     public int updateInterfaceCallsuccnum(TUInterfaceinfo tUInterfaceinfo);
 
     /**
-     * 修改【归集数据分析】
+     * 安装年份查询【归集数据分析】
      *
      * @param imputationData 【归集数据分析】
      * @return 结果
@@ -90,6 +90,14 @@ public interface TUInterfaceinfoMapper
     public ImputationData imputationData(Map imputationData);
 
     /**
+     * 按照月份查询【归集数据分析】
+     *
+     * @param imputationData 【归集数据分析】
+     * @return 结果
+     */
+    public ImputationData imputationDataByMonth(Map imputationData);
+
+    /**
      * 修改【接口数据条数】
      *
      * @param tUInterfaceinfo 【接口数据条数】

+ 5 - 0
mybusiness/src/main/java/com/sooka/system/service/ITUInterfaceinfoService.java

@@ -81,6 +81,11 @@ public interface ITUInterfaceinfoService
     public void imputationData();
 
     /**
+     * 按月刷新归集数据分析
+     */
+    public void imputationDataByMonth();
+
+    /**
      * 查询接口数量
      * @return 结果
      */

+ 47 - 0
mybusiness/src/main/java/com/sooka/system/service/impl/TUInterfaceinfoServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sooka.system.service.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -280,6 +281,52 @@ public class TUInterfaceinfoServiceImpl implements ITUInterfaceinfoService
     }
 
     /**
+     * 按月刷新归集数据分析
+     */
+    @Override
+    public void imputationDataByMonth(){
+        String year = new SimpleDateFormat("yyyy").format(new Date());//String year = "2022";
+        String month = new SimpleDateFormat("M").format(new Date());
+        TUInterfaceinfo param = new TUInterfaceinfo();
+        param.setShareType("share_type_2");//市归集
+//        param.setNeedRefresh("1");
+        //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 237962 ms
+        //(164-70) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 352968 ms
+        List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
+        for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
+            TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
+            String tableName = tuInterfaceinfo.getTableName();
+            if (tableName == null || tableName.equals("") || tableName.equals("t_u_interfaceinfo_emptytable")) {
+                System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
+                continue;
+            }
+            ImputationData imputationDataParam = new ImputationData();
+            imputationDataParam.setYear(year);
+            imputationDataParam.setTableName(tableName);
+            boolean isExist = !(imputationDataMapper.selectImputationInterface(imputationDataParam).size() == 0);
+            if(!isExist){
+                continue;
+            }
+            Map map = new HashMap();
+            map.put("year", year);
+            map.put("month", month);
+            map.put("tableName", tableName);
+            System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
+            Date dateBegin = new Date();
+            ImputationData imputationData = tUInterfaceinfoMapper.imputationDataByMonth(map);
+            Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
+            ImputationData imputationDataInsert = new ImputationData();
+            imputationDataInsert.setYear(year);
+            imputationDataInsert.setMonth(month);
+            imputationDataInsert.setTableName(tableName);
+//            imputationDataInsert.setInterfaceName(tuInterfaceinfo.getInterfaceName());//接口名称可能会变
+            imputationDataInsert.setCount(imputationData.getCount());
+            imputationDataMapper.updateImputationInterfaceByYearMonthTableName(imputationDataInsert);
+            System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
+        }
+    }
+
+    /**
      * 查询接口数量
      * @return 结果
      */

+ 114 - 4
mybusiness/src/main/java/com/util/StaticScheduleTask.java

@@ -1,23 +1,24 @@
 package com.util;
 
 import com.business.domain.ImputationData;
+import com.business.mapper.ImputationDataMapper;
 import com.business.service.ImputationDataService;
 import com.sooka.common.utils.DateUtils;
 import com.sooka.common.utils.StringUtils;
+import com.sooka.system.domain.TUInterfaceinfo;
+import com.sooka.system.mapper.TUInterfaceinfoMapper;
 import com.sooka.system.service.ITULogService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
+import javax.annotation.Resource;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author limeng
@@ -35,6 +36,115 @@ public class StaticScheduleTask {
     @Autowired
     private ImputationDataService imputationDataService;
 
+    @Resource
+    private TUInterfaceinfoMapper tUInterfaceinfoMapper;
+    @Resource
+    private ImputationDataMapper imputationDataMapper;
+
+    /**添加定时任务 每天凌晨1点**/
+    /**
+     * 刷新归集数据分析 更新当月数据
+     */
+    @Scheduled(cron = "0 0 1 * * ?")
+    private void imputationData() {
+        System.out.println("按照年份每年新增一批新数据");
+        imputationDataByYear();//按照年份每年新增一批新数据
+        System.out.println("按照月份每日更新当月数据");
+        imputationDataByMonth();//按照月份每日更新当月数据
+    }
+
+    private void imputationDataByMonth() {
+        String year = new SimpleDateFormat("yyyy").format(new Date());//String year = "2022";
+        String month = new SimpleDateFormat("M").format(new Date());
+        TUInterfaceinfo param = new TUInterfaceinfo();
+        param.setShareType("share_type_2");//市归集
+//        param.setNeedRefresh("1");
+        //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 237962 ms
+        //(164-70) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 352968 ms
+        List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
+        for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
+            TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
+            String tableName = tuInterfaceinfo.getTableName();
+            if (tableName == null || tableName.equals("") || tableName.equals("t_u_interfaceinfo_emptytable")) {
+                System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
+                continue;
+            }
+            ImputationData imputationDataParam = new ImputationData();
+            imputationDataParam.setYear(year);
+            imputationDataParam.setTableName(tableName);
+            boolean isExist = !(imputationDataMapper.selectImputationInterface(imputationDataParam).size() == 0);
+            if(!isExist){
+                continue;
+            }
+            Map map = new HashMap();
+            map.put("year", year);
+            map.put("month", month);
+            map.put("tableName", tableName);
+            System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
+            Date dateBegin = new Date();
+            ImputationData imputationData = tUInterfaceinfoMapper.imputationDataByMonth(map);
+            Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
+            ImputationData imputationDataInsert = new ImputationData();
+            imputationDataInsert.setYear(year);
+            imputationDataInsert.setMonth(month);
+            imputationDataInsert.setTableName(tableName);
+//            imputationDataInsert.setInterfaceName(tuInterfaceinfo.getInterfaceName());//接口名称可能会变
+            imputationDataInsert.setCount(imputationData.getCount());
+            imputationDataMapper.updateImputationInterfaceByYearMonthTableName(imputationDataInsert);
+            System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
+        }
+    }
+
+    private void imputationDataByYear() {
+        String year = new SimpleDateFormat("yyyy").format(new Date());//String year = "2022";
+        TUInterfaceinfo param = new TUInterfaceinfo();
+        param.setShareType("share_type_2");//市归集
+//        param.setNeedRefresh("1");
+        //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 237962 ms
+        //(164-70) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 352968 ms
+        List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
+        for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
+            TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
+            String tableName = tuInterfaceinfo.getTableName();
+            if (tableName == null || tableName.equals("") || tableName.equals("t_u_interfaceinfo_emptytable")) {
+                System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
+                continue;
+            }
+            ImputationData imputationDataParam = new ImputationData();
+            imputationDataParam.setYear(year);
+            imputationDataParam.setTableName(tableName);
+            boolean isExist = !(imputationDataMapper.selectImputationInterface(imputationDataParam).size() == 0);
+            if(isExist){
+                continue;
+            }
+            Map map = new HashMap();
+            map.put("year", year);
+            map.put("tableName", tableName);
+            System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
+            Date dateBegin = new Date();
+            ImputationData imputationData = tUInterfaceinfoMapper.imputationData(map);
+            Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
+            ImputationData imputationDataInsert = new ImputationData();
+            imputationDataInsert.setYear(year);
+            imputationDataInsert.setTableName(tableName);
+            imputationDataInsert.setInterfaceName(tuInterfaceinfo.getInterfaceName());
+            imputationDataInsert.setJan(imputationData.getJan());
+            imputationDataInsert.setFeb(imputationData.getFeb());
+            imputationDataInsert.setMar(imputationData.getMar());
+            imputationDataInsert.setApr(imputationData.getApr());
+            imputationDataInsert.setMay(imputationData.getMay());
+            imputationDataInsert.setJun(imputationData.getJun());
+            imputationDataInsert.setJul(imputationData.getJul());
+            imputationDataInsert.setAug(imputationData.getAug());
+            imputationDataInsert.setSep(imputationData.getSep());
+            imputationDataInsert.setOct(imputationData.getOct());
+            imputationDataInsert.setNov(imputationData.getNov());
+            imputationDataInsert.setDecb(imputationData.getDecb());
+            imputationDataMapper.insertImputationInterface(imputationDataInsert);
+            System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
+        }
+    }
+
     /**添加定时任务 每天凌晨1点**/
     //@Scheduled(cron = "0 0 1 * * ?")
     private void configureTasks() {

+ 19 - 0
mybusiness/src/main/resources/mapper/imputationData/ImputationDataMapper.xml

@@ -78,6 +78,25 @@
             </trim>
     </insert>
 
+    <update id="updateImputationInterfaceByYearMonthTableName" parameterType="ImputationData">
+        update t_u_imputation_interface
+            <trim prefix="SET" suffixOverrides=",">
+                <if test="month == '1'">jan = #{count},</if>
+                <if test="month == '2'">feb = #{count},</if>
+                <if test="month == '3'">mar = #{count},</if>
+                <if test="month == '4'">apr = #{count},</if>
+                <if test="month == '5'">may = #{count},</if>
+                <if test="month == '6'">jun = #{count},</if>
+                <if test="month == '7'">jul = #{count},</if>
+                <if test="month == '8'">aug = #{count},</if>
+                <if test="month == '9'">sep = #{count},</if>
+                <if test="month == '10'">oct = #{count},</if>
+                <if test="month == '11'">nov = #{count},</if>
+                <if test="month == '12'">decb = #{count},</if>
+            </trim>
+        where year = #{year} and table_name = #{tableName}
+    </update>
+
     <insert id="insertImputationData" parameterType="ImputationData">
         insert into t_u_imputation_data
             <trim prefix="(" suffix=")" suffixOverrides=",">

+ 4 - 0
mybusiness/src/main/resources/mapper/system/TUInterfaceinfoMapper.xml

@@ -234,6 +234,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         )
     </select>
 
+    <select id="imputationDataByMonth" parameterType="java.util.Map" resultType="ImputationData">
+        select count(id) count from ${tableName} where year(create_time) = #{year} and month(create_time) = #{month}
+    </select>
+
     <update id="updateDataNum" parameterType="TUInterfaceinfo">
         update t_u_interfaceinfo_datanum set update_time = #{updateTime}, datanum = (select count(id) from ${tableName}) where id = #{id}
     </update>