Pārlūkot izejas kodu

init: 初始化项目

Jaluson 3 dienas atpakaļ
vecāks
revīzija
9bf0ac9adf

+ 0 - 6
src/main/java/com/sinoqixin/bgdrocketmq/config/MqConsumerBeanConfig.java

@@ -6,10 +6,8 @@ import org.apache.rocketmq.remoting.protocol.heartbeat.MessageModel;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
 
 @Configuration
-@PropertySource(value = {"classpath:rocketMQ.properties"})
 public class MqConsumerBeanConfig {
 
     @Value("${consumer.namesrvAddr}")
@@ -18,9 +16,6 @@ public class MqConsumerBeanConfig {
     @Value("${consumer.groupName}")
     private String groupName;
 
-    @Value("${test-switch}")
-    private Boolean testSwitch;
-
     @Bean(name = "rocketMqClient")
     public DefaultMQPushConsumer initRocketMqClient() {
         DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(groupName);
@@ -36,7 +31,6 @@ public class MqConsumerBeanConfig {
         // CONSUME_FROM_FIRST_OFFSET:从第一个偏移量开始消费,即从头开始消费队列中的所有消息
         // CONSUME_FROM_LAST_OFFSET:从最后一个偏移量开始消费,即只消费新到达的消息。这对于只关注最新消息的消费者很有用
         // CONSUME_FROM_TIMESTAMP:从指定的时间戳开始消费。你需要提供一个时间戳,消费者将从该时间戳之后的第一条消息开始消费
-//        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
         consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
 
         return consumer;

+ 26 - 43
src/main/java/com/sinoqixin/bgdrocketmq/service/GetProducePlanDetailApiService.java

@@ -9,7 +9,6 @@ import com.sinoqixin.bgdrocketmq.vo.AjaxResult;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.PropertySource;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -17,28 +16,22 @@ import java.util.Map;
 
 @Service
 @Slf4j
-@PropertySource(value = {"classpath:rocketMQ.properties"})
 public class GetProducePlanDetailApiService {
-
-    /*@Value("${queryPlanInfoForPowerSupplyUrl_simulation}")
-    private String queryPlanInfoForPowerSupplyUrl;
-    @Value("${queryPlanBusinessInfoUrl_simulation}")
-    private String queryPlanBusinessInfoUrl;*/
-
     //分省标识
     private final static String TOP_PROVINCE_FLAG = "7F079D562F9A8360BE8CA1292A27AF28";
     private final static String BUSINESS_TYPES = "Source_164";
-    @Value("${queryPlanInfoForPowerSupplyUrl_formal}")
+
+    @Value("${consumer.queryPlanInfoForPowerSupplyUrl_formal}")
     private String queryPlanInfoForPowerSupplyUrl;
-    @Value("${queryPlanBusinessInfoUrl_formal}")
+    @Value("${consumer.queryPlanBusinessInfoUrl_formal}")
     private String queryPlanBusinessInfoUrl;
-    @Value("${getToken_url}")
+    @Value("${consumer.getToken_url}")
     private String getTokenUrl;
-    @Value("${getToken_account}")
+    @Value("${consumer.getToken_account}")
     private String getTokenAccount;
-    @Value("${getToken_password}")
+    @Value("${consumer.getToken_password}")
     private String getTokenPassword;
-    @Value("${getToken_authCode}")
+    @Value("${consumer.getToken_authCode}")
     private String getTokenAuthCode;
 
     public AjaxResult getPlanBusinessInfoByApi(String planIds, String bureauCode, int timeout) {
@@ -65,12 +58,11 @@ public class GetProducePlanDetailApiService {
         headerMap.put("topProvinceFlag", TOP_PROVINCE_FLAG);
 
         log.info("【queryPlanBusinessInfo】开始请求,地址:{},请求头:{},请求体:{}", queryPlanBusinessInfoUrl, headerMap, bodyMap);
-        try {
-            HttpResponse httpResponse = HttpRequest.post(queryPlanBusinessInfoUrl)
-                    .headerMap(headerMap, false)
-                    .timeout(timeout)
-                    .body(JSONObject.toJSONString(bodyMap))
-                    .execute();
+        try(HttpResponse httpResponse = HttpRequest.post(queryPlanBusinessInfoUrl)
+                .headerMap(headerMap, false)
+                .timeout(timeout)
+                .body(JSONObject.toJSONString(bodyMap))
+                .execute()) {
             if (httpResponse == null) {
                 return AjaxResult.error("【queryPlanBusinessInfoUrl】请求返回结果 httpResponse 为空");
             }
@@ -88,7 +80,7 @@ public class GetProducePlanDetailApiService {
             }
             return AjaxResult.error(httpResponse.body());
         } catch (HttpException e) {
-            e.printStackTrace();
+            log.error("", e);
             log.info("【queryPlanBusinessInfoUrl】请求异常,请求地址:{},请求头部:{},请求参数:{},异常信息:{}", queryPlanBusinessInfoUrl, headerMap, bodyMap, e.getMessage());
             return AjaxResult.error(e.getMessage());
         }
@@ -129,12 +121,11 @@ public class GetProducePlanDetailApiService {
         headerMap.put("access-token", token);
         headerMap.put("topProvinceFlag", TOP_PROVINCE_FLAG);
         log.info("【queryPlanInfoForPowerSupply】开始请求,地址:{},请求头:{},请求体:{}", queryPlanInfoForPowerSupplyUrl, headerMap, bodyMap);
-        try {
-            HttpResponse httpResponse = HttpRequest.post(queryPlanInfoForPowerSupplyUrl)
-                    .headerMap(headerMap, false)
-                    .timeout(timeout)
-                    .body(JSONObject.toJSONString(bodyMap))
-                    .execute();
+        try (HttpResponse httpResponse = HttpRequest.post(queryPlanInfoForPowerSupplyUrl)
+                .headerMap(headerMap, false)
+                .timeout(timeout)
+                .body(JSONObject.toJSONString(bodyMap))
+                .execute()) {
             if (httpResponse == null) {
                 return AjaxResult.error("【queryPlanInfoForPowerSupply】请求返回结果 httpResponse 为空");
             }
@@ -142,21 +133,13 @@ public class GetProducePlanDetailApiService {
             log.info("【queryPlanInfoForPowerSupply】本次请求status:{},地址:{},返回结果是:{}", code, queryPlanInfoForPowerSupplyUrl, httpResponse.body());
             if (httpResponse.isOk()) {
                 String jsonStr = httpResponse.body();
-//                JSONObject jsonObject = JSONObject.parseObject(jsonStr);
-
                 return AjaxResult.success("queryPlanInfoForPowerSupply获取成功", jsonStr);
-
-                /*if (jsonObject.getInteger("code") == 200) {
-                    return AjaxResult.success(jsonStr);
-                } else {
-                    log.info("【queryPlanInfoForPowerSupply】请求返回结果异常,请求地址:{},请求头部:{},请求参数:{},返回结果是:{}", queryPlanInfoForPowerSupplyUrl, headerMap, bodyMap, httpResponse.body());
-                }*/
             } else {
                 log.info("【queryPlanInfoForPowerSupply】请求数据失败,请求地址:{},请求头部:{},请求参数:{},返回结果是:{}", queryPlanInfoForPowerSupplyUrl, headerMap, bodyMap, httpResponse.body());
             }
             return AjaxResult.error(httpResponse.body());
         } catch (HttpException e) {
-            e.printStackTrace();
+            log.error("", e);
             log.info("【queryPlanInfoForPowerSupply】请求异常,请求地址:{},请求头部:{},请求参数:{},异常信息:{}", queryPlanInfoForPowerSupplyUrl, headerMap, bodyMap, e.getMessage());
             return AjaxResult.error(e.getMessage());
         }
@@ -174,12 +157,12 @@ public class GetProducePlanDetailApiService {
         bodyMap.put("password", getTokenPassword);
         bodyMap.put("authCode", getTokenAuthCode);
         log.info("【queryPlanInfoForPowerSupply】开始请求,地址:{},请求体:{}", queryPlanInfoForPowerSupplyUrl, bodyMap);
-        try {
-            HttpResponse httpResponse = HttpRequest.post(getTokenUrl)
-                    .timeout(timeout)
-                    .header("Content-Type", "application/json")
-                    .body(JSONObject.toJSONString(bodyMap))
-                    .execute();
+        try (HttpResponse httpResponse = HttpRequest.post(getTokenUrl)
+                .timeout(timeout)
+                .header("Content-Type", "application/json")
+                .body(JSONObject.toJSONString(bodyMap))
+                .execute()) {
+
             if (httpResponse == null) {
                 return AjaxResult.error("【getToken】请求返回结果 httpResponse 为空");
             }
@@ -199,7 +182,7 @@ public class GetProducePlanDetailApiService {
                 return AjaxResult.error(httpResponse.body());
             }
         } catch (HttpException e) {
-            e.printStackTrace();
+            log.error("", e);
             log.info("【getToken】请求异常,请求地址:{},请求参数:{},异常信息:{}", getTokenUrl, bodyMap, e.getMessage());
             return AjaxResult.error(e.getMessage());
         }

+ 6 - 29
src/main/java/com/sinoqixin/bgdrocketmq/service/ProducePlanService.java

@@ -11,7 +11,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.PropertySource;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -20,7 +19,6 @@ import java.util.Map;
 
 @Service
 @Slf4j
-@PropertySource(value = {"classpath:common.properties", "classpath:rocketMQ.properties"})
 public class ProducePlanService implements MqDataHandle {
 
     //生成计划通知(生产工单推送)
@@ -29,6 +27,7 @@ public class ProducePlanService implements MqDataHandle {
     //计划来源,164-广州智慧保供电,通过这个字段判断是否是保供电生成的计划
     private final static String PLAN_SOURCE_TYPE = "164";
     private final static int TIME_OUT = 30 * 1000; // 30s请求超时
+
     @Autowired
     private ProducePlanDao producePlanDao;
     @Value("${err.file.path}")
@@ -53,7 +52,7 @@ public class ProducePlanService implements MqDataHandle {
                     producePlanDao.insertDwglProducePlanWorkOrderFullRecord(fullArgs);
                 } catch (Exception e) {
                     recordErrDataToFile(fullArgs, "DWGL_ERR");
-                    e.printStackTrace();
+                    log.error("", e);
                     log.info("更新 电网管理平台生产计划工单表【接口返回字段】,异常信息:{}", e.getMessage());
                 }
             }
@@ -65,7 +64,7 @@ public class ProducePlanService implements MqDataHandle {
                     producePlanDao.insertDwglProducePlanWorkOrderRecord(args);
                 } catch (Exception e) {
                     recordErrDataToFile(args, "DWGL_ERR");
-                    e.printStackTrace();
+                    log.error("", e);
                     log.info("更新 电网管理平台生产计划工单表【rocketMq返回字段】,异常信息:{}", e.getMessage());
                 }
             }
@@ -76,12 +75,12 @@ public class ProducePlanService implements MqDataHandle {
                     producePlanDao.updateBgdTaskInfo(bgdArgs);
                 } catch (Exception e) {
                     recordErrDataToFile(bgdArgs, "BGD_ERR");
-                    e.printStackTrace();
+                    log.error("", e);
                     log.info("更新 保供电任务信息表,异常信息:{}", e.getMessage());
                 }
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("", e);
             log.info("生成计划通知(计划创建推送)数据解析出错,出错数据:{},异常信息:{}", msg, e.getMessage());
         }
     }
@@ -215,11 +214,8 @@ public class ProducePlanService implements MqDataHandle {
             Object[] arg = {prodPlanId, planCode, planState, speciality, bureauCode, powerGridFlag, workType, planBeginTime, planEndTime,
                     id, businessType, patrolClassify};
 
-//            Object[] fullArg = null;
-
             List<Object[]> fullList = new ArrayList<>();
 
-//            if ("CREATE".equals(businessType)) {
             AjaxResult planBusinessInfoByApi = getProducePlanDetailApiService.getPlanBusinessInfoByApi(prodPlanId, bureauCode, TIME_OUT);
 
             if (planBusinessInfoByApi.isSuccess()) {
@@ -244,27 +240,10 @@ public class ProducePlanService implements MqDataHandle {
                         }
                     }
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    log.error("", e);
                     log.info("【queryPlanBusinessInfo】请求返回结果成功,但解析失败,生产计划id:{},返回结果:{},失败原因:{}", prodPlanId, jkResult, e.getMessage());
                 }
             }
-                /*AjaxResult producePlanDetailByApi = getProducePlanDetailApiService.getProducePlanDetailByApi(prodPlanId, bureauCode, TIME_OUT);
-                if (producePlanDetailByApi.isSuccess()) {
-                    try {
-                        jkResult = Utils.getString(producePlanDetailByApi.get(AjaxResult.DATA_TAG));
-                        JSONObject jkResultObj = JSONObject.parseObject(jkResult);
-                        String planInfoListStr = jkResultObj.getString("planInfoList");
-                        List<Map<String, Object>> planInfoList = JSONObject.parseObject(planInfoListStr, new TypeReference<List<Map<String, Object>>>() {});
-                        if (!planInfoList.isEmpty()) {
-                            Map<String, Object> jkItemObjectMap = planInfoList.get(0);
-                            fullArg = getQueryPlanInfoForPowerSupplyProp(jkItemObjectMap, arg);
-                        }
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                        log.info("【queryPlanInfoForPowerSupply】请求返回结果成功,但解析失败,生产计划id:{},返回结果:{},失败原因:{}", prodPlanId, jkResult, e.getMessage());
-                    }
-                }*/
-//            }
 
             if (!fullList.isEmpty()) {
                 fullArgs.addAll(fullList);
@@ -274,8 +253,6 @@ public class ProducePlanService implements MqDataHandle {
                 System.arraycopy(arg, 0, arg2, arg.length, arg.length);
                 args.add(arg2);
             }
-            /*Object[] bgdArg = {prodPlanId, planCode, getPlanState(planState), id};
-            bgdArgs.add(bgdArg);*/
         }
     }
 

+ 2 - 2
src/main/java/com/sinoqixin/bgdrocketmq/service/handle/MqDataHandleFactory.java

@@ -74,7 +74,7 @@ public class MqDataHandleFactory implements Runnable {
             log.info("rocketMq 注册监听成功");
             consumer.start();
         } catch (MQClientException e) {
-            e.printStackTrace();
+            log.error("", e);
             log.error("rocketMq 监听失败,失败原因:{}", e.getErrorMessage());
         }
     }
@@ -101,7 +101,7 @@ public class MqDataHandleFactory implements Runnable {
                 log.info("rocket获取数据主题 ===>:{},tab:{},queueId:{},offset:{}, 数据:{}", topic, tags, queueId, queueOffset, msg);
                 mqDataHandle.handleData(msg);
             } catch (Exception e) {
-                e.printStackTrace();
+                log.error("", e);
                 log.info("rocketMq 处理数据异常:{},poll数据为:{}", e.getMessage(), msg);
             }
         }

+ 0 - 11
src/main/java/com/sinoqixin/bgdrocketmq/utils/Utils.java

@@ -138,17 +138,6 @@ public class Utils {
      * @return
      */
     public static boolean getTableIsExist(JdbcTemplate jdbcTemplate, String patternName, String tableName) {
-        /*String sql = "select COUNT(1) RESULT from dba_segments where dba_segments.OWNER = ? and SEGMENT_NAME= ? ";
-        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, patternName, tableName);
-        boolean result = false;
-        if (mapList.isEmpty()) return false;
-        String rowVal = Utils.getString(mapList.get(0).get("RESULT"));
-        if ("1".equals(rowVal)) {
-            result = true;
-        }
-        return result;*/
-
-//        String sql = "SELECT COUNT(*) COUNT FROM DBA_TABLES  WHERE OWNER = ? AND TABLE_NAME = ? ";
         String sql = "SELECT COUNT(*) COUNT FROM USER_TABLES  WHERE TABLE_NAME = ? ";
         List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, tableName);
         if (!mapList.isEmpty()) {

+ 3 - 3
src/main/resources/application-dev.yaml

@@ -1,9 +1,9 @@
 spring:
   datasource:
     driver-class-name: dm.jdbc.driver.DmDriver
-    url: jdbc:dm://localhost:5236
-    username: NWYJ_SERVICE
-    password: NWYJ123456
+    url: jdbc:dm://127.0.0.1:5237/ITGBGD?rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
+    username: ITGBGD
+    password: rw_YJ#YZT_2024
     hikari:
       maximum-pool-size: 50
       minimum-idle: 5

+ 3 - 0
src/main/resources/application.yaml

@@ -7,3 +7,6 @@ spring:
     name: bgd-rocketmq
   profiles:
     active: dev
+err:
+  file:
+    path: /nwyj/dataCenterProject/err/

+ 68 - 0
src/main/resources/log4j2-dev.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+    <Properties> <!-- 配置日志文件输出目录,此配置将日志输出到工程目录下的logOut文件夹 -->
+        <Property name="APP_NAME">dataCenterProject</Property>
+        <Property name="LOG_HOME">/nwyj/dataCenterProject/logs</Property>
+    </Properties>
+
+    <Appenders>
+        <Console name="console_out_appender" target="SYSTEM_OUT">
+            <PatternLayout charset="UTF-8" pattern="test %d{HH:mm:ss} %t [%p] %c (%F:%L)  %msg%n"/>
+        </Console>
+
+        <RollingFile name="info_appender" immediateFlush="false"
+                     fileName="${LOG_HOME}/${APP_NAME}_info.log"
+                     filePattern="${LOG_HOME}/${APP_NAME}_info.%d{yyyy-MM-dd}.log">
+            <PatternLayout charset="UTF-8">
+                <pattern>%d{yyyy-MM-dd HH:mm:ss} %t [%p] %c %msg%n</pattern>
+            </PatternLayout>
+            <Policies>
+                <TimeBasedTriggeringPolicy modulate="true" interval="1"/>
+            </Policies>
+            <Filters>
+                <ThresholdFilter level="info" onMatch="ACCEPT"
+                                 onMismatch="DENY"/>
+            </Filters>
+            <DefaultRolloverStrategy>
+                <Delete basePath="${LOG_HOME}" maxDepth="1">
+                    <IfFileName glob="${APP_NAME}_*.log"/>
+                    <IfLastModified age="180d"/>
+                </Delete>
+            </DefaultRolloverStrategy>
+        </RollingFile>
+
+        <RollingFile name="error_appender" immediateFlush="true"
+                     fileName="${LOG_HOME}/${APP_NAME}_error.log"
+                     filePattern="${LOG_HOME}/${APP_NAME}_error.%d{yyyy-MM-dd}.log">
+            <PatternLayout charset="UTF-8">
+                <pattern>%d{yyyy-MM-dd HH:mm:ss} %t [%p] %c %msg%n</pattern>
+            </PatternLayout>
+            <Policies>
+                <SizeBasedTriggeringPolicy size="50MB"/>
+                <TimeBasedTriggeringPolicy modulate="true" interval="1"/>
+            </Policies>
+            <Filters>
+                <ThresholdFilter level="warn" onMatch="ACCEPT"
+                                 onMismatch="DENY"/>
+            </Filters>
+        </RollingFile>
+    </Appenders>
+    <Loggers>
+        <asyncRoot level="DEBUG" includeLocation="false">
+            <appender-ref ref="info_appender"/>
+            <appender-ref ref="error_appender"/>
+            <appender-ref ref="console_out_appender"/>
+        </asyncRoot>
+        <!-- 第三方日志系统 -->
+        <!--        <logger name="com.jcraft.jsch" level="warn"/>-->
+        <logger name="org.springframework.core" level="warn"/>
+        <logger name="org.springframework.beans" level="warn"/>
+        <logger name="org.springframework.context" level="warn"/>
+        <logger name="org.springframework.web" level="warn"/>
+        <logger name="org.apache.http" level="warn"/>
+
+        <Logger name="org.springframework.jdbc.core.JdbcTemplate" level="DEBUG" />
+        <Logger name="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" level="DEBUG" />
+
+    </Loggers>
+</Configuration>

+ 5 - 1
src/main/resources/log4j2.xml

@@ -48,7 +48,7 @@
         </RollingFile>
     </Appenders>
     <Loggers>
-        <asyncRoot level="info" includeLocation="false">
+        <asyncRoot level="INFO" includeLocation="false">
             <appender-ref ref="info_appender"/>
             <appender-ref ref="error_appender"/>
             <appender-ref ref="console_out_appender"/>
@@ -60,5 +60,9 @@
         <logger name="org.springframework.context" level="warn"/>
         <logger name="org.springframework.web" level="warn"/>
         <logger name="org.apache.http" level="warn"/>
+
+        <Logger name="org.springframework.jdbc.core.JdbcTemplate" level="INFO" />
+        <Logger name="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" level="INFO" />
+
     </Loggers>
 </Configuration>

+ 2 - 2
src/main/resources/rocketmq-dev.yaml

@@ -1,9 +1,9 @@
 consumer:
   groupName: test-consumer
   namesrvAddr: 127.0.0.1:9876
-  queryPlanInfoForPowerSupplyUrl_simulation: http://10.92.190.36/gmp/sp/operationmaintenaceservice//prodplan/planQueryForExtService/queryPlanInfoForPowerSupply
+  queryPlanInfoForPowerSupplyUrl_formal: http://10.10.21.28/gmp/sp/operationmaintenaceservice//prodplan/planQueryForExtService/queryPlanInfoForPowerSupply
   queryPlanBusinessInfoUrl_formal: http://10.10.21.28/gmp/sp/operationmaintenaceservice/prodplan/planInfoForQuery/queryPlanBusinessInfo
   getToken_url: http://10.10.21.28/api/jadp/auth/session/thirdSystem
   getToken_account: gz_power_supply
   getToken_password: 3C364DEF4A3ADAEEEB9A69184C378109
-  getToken_authCode: 55DB587E73464C18BCB350C65BCF13EC
+  getToken_authCode: 55DB587E73464C18BCB350C65BCF13EC