Parcourir la source

Merge branch 'master' of http://120.78.165.83:8123/git/nazw

李雪梅 il y a 2 ans
Parent
commit
a010d78cae

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/GetData/GetAllData.java

@@ -13,6 +13,7 @@ import com.example.nngkxxdp.util.Blank;
 import com.example.nngkxxdp.util.ConstStr;
 import com.example.nngkxxdp.util.SendUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -127,6 +128,7 @@ public class GetAllData {
     @RequestMapping("/article2")
     //自动获取前14天0 42 16 * * ?
 //    @Scheduled(cron = "0 0 1 * * ?")//定时每天凌晨1点钟执行
+//    @Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
     public String article2() throws Exception {
 //        getarticletotal   抓取所有的公众号的前面的数据,放在数据库中, 用字符按连接起来
         String appid = GetIdAndSecret.getId();

+ 40 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/configer/SchedulingTaskConfig.java

@@ -0,0 +1,40 @@
+package com.example.nngkxxdp.configer;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * 定时器配置类
+ * @author zhoupeng
+ * @date 2022/6/30
+ */
+@Configuration
+@EnableAsync
+public class SchedulingTaskConfig {
+    private static final int corePoolSize = 10;               // 默认线程数
+    private static final int maxPoolSize = 100;                // 最大线程数
+    private static final int keepAliveTime = 10;            // 允许线程空闲时间(单位:默认为秒),十秒后就把线程关闭
+    private static final int queueCapacity = 200;            // 缓冲队列数
+    private static final String threadNamePrefix = "thread-"; // 线程池名前缀
+
+    @Bean("threadPoolTaskExecutor") // bean的名称,默认为首字母小写的方法名
+    public ThreadPoolTaskExecutor getDemoThread(){
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(keepAliveTime);
+        executor.setKeepAliveSeconds(queueCapacity);
+        executor.setThreadNamePrefix(threadNamePrefix);
+
+        //线程池拒绝任务的处理策略
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        //初始化
+        executor.initialize();
+
+        return executor;
+    }
+}

+ 2 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/YxnnController.java

@@ -70,10 +70,10 @@ public class YxnnController {
     @GetMapping("/getDocumentPageFront")
     public Map<String, Object> getDocumentPageFront(int page, int limit, String pictureType, String examineState) {
         try {
-            if (Blank.isNotEmpty(page) && Blank.isNotEmpty(limit) && page > 0 && limit > 0) {
+            if (Blank.isNotEmpty(page) && Blank.isNotEmpty(limit) && page > 0 && limit > 0&&Blank.isNotEmpty(pictureType)&&Blank.isNotEmpty(examineState)) {
                 return SendUtil.send(true, null, yxnnService.getDocumentPageFront(page, limit, pictureType, examineState));
             }
-            return SendUtil.send(true, null, "page和limit不能为空,且要大于0");
+            return SendUtil.send(true, null, "page和limit不能为空,且要大于0.pictureType和examineState不能为空");
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 4 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/YxnnDao.java

@@ -25,4 +25,8 @@ public interface YxnnDao {
     int deleteDocumentById(Integer id);
 
     int updateDocumentById(ImpressionNanan impressionNanan);
+
+    List<Map<String, Object>> getDocumentPageFront(@Param("startRows") int startRows, @Param("rows")int rows, @Param("pictureType")String pictureType,@Param("examineState") String examineState);
+
+    int getDocumentCountFront(@Param("pictureType")String pictureType,@Param("examineState") String examineState);
 }

+ 2 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/YxnnServiceImpl.java

@@ -42,9 +42,9 @@ public class YxnnServiceImpl implements YxnnService {
     @Override
     public Map<String, Object> getDocumentPageFront(int page, int limit, String pictureType, String examineState) {
         int startRows = (page - 1) * limit;
-        int count = yxnnDao.getDocumentCount();
+        int count = yxnnDao.getDocumentCountFront(pictureType,examineState);
         if (count > 0) {
-            List<Map<String, Object>> mapList = yxnnDao.getDocumentPage(startRows, limit, pictureType, examineState);
+            List<Map<String, Object>> mapList = yxnnDao.getDocumentPageFront(startRows, limit, pictureType, examineState);
             for (Map<String, Object> map : mapList) {
                 if ((int) map.get("isPublic") == ConstantUtil.IS_NOT_PUBLIC) {
                     String uploaderPhone = map.get("uploaderPhone").toString();

+ 3 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/task/HlwTask.java

@@ -34,6 +34,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSourceType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -87,6 +88,7 @@ public class HlwTask {
     }
 
     //    @Scheduled(cron = "0 10 0 * * ?")
+//    @Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 //    @GetMapping("/getTodayData")
     public void saveAndUpdateColumnRelationData() throws Exception {
         JSONArray articleList = HlwHttpUtil.getArticleList("-1");
@@ -132,6 +134,7 @@ public class HlwTask {
      * 全量采集华龙网接口数据
      */
     @Scheduled(cron = "0 30 01 * * ?")
+    @Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 //    @GetMapping("/test/saveHlwData")
     public void task() {
         System.setProperty("sun.net.client.defaultConnectTimeout", "30000");

+ 3 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/util/ArticleSmsUtil.java

@@ -8,6 +8,7 @@ import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
@@ -42,7 +43,8 @@ public class ArticleSmsUtil {
 	private SmsMessageDao smsMessageDao;
 
 	@Scheduled(cron = "0 0 9 * * ?")
-	private void task() {
+	@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
+	public void task() {
 		Map<String, Object> queryMap = new HashMap<>();
 		queryMap.put("day", 0);
 		List<Map<String, Object>> zyldList = smsMessageDao.getArticleFrequencyList(queryMap);

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/DeptTaskUtil.java

@@ -8,6 +8,7 @@ import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
@@ -34,6 +35,7 @@ public class DeptTaskUtil {
 	private TjDao tjDao;
 
 //	@Scheduled(cron = "0 30 0 1 * ?")
+//@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 	private void task() {
 		String[] columns = new String[] {"重大建设项目","公共资源交易","义务教育","户籍管理","社会救助","养老服务","公共法律服务","财政预决算",
 				"促进就业","社会保险","国土空间规划","征地补偿","生态环保","国有土地上房屋征收","保障性住房","农村危房改造","城市综合执法","市政服务",

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/NewDeptTaskUtil.java

@@ -8,6 +8,7 @@ import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
@@ -55,6 +56,7 @@ public class NewDeptTaskUtil {
 	public static int[] partitionThreeMonth = new int[] {37};
 	
 //	@Scheduled(cron = "0 30 0 1 * ?")
+//@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 	private void task() {
 		// 初始化部门分值
 		List<Map<String, Object>> deptList = initDeptScore();

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/NewDeptTaskUtil3.java

@@ -12,6 +12,7 @@ import com.example.nngkxxdp.dao.HlwInterfaceDao;
 import com.example.nngkxxdp.dao.TjDao;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Controller;
@@ -38,6 +39,7 @@ public class NewDeptTaskUtil3 {
 	private WzkpRecordUtil wzkpRecordUtil;
 	
 	@Scheduled(cron = "0 30 0 1 * ?")
+	@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 	public void task() {
 		wzkpRecordUtil.generateRecord(null);
 	}

+ 3 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/util/OfaSmsUtil.java

@@ -9,6 +9,7 @@ import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
@@ -39,7 +40,8 @@ public class OfaSmsUtil {
 	private SmsMessageDao smsMessageDao;
 
 	@Scheduled(cron = "0 30 23 * * ?")
-	private void task() {
+	@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
+	public void task() {
 		List<Map<String, Object>> list = smsMessageDao.getAllOfa();
 		if (!Blank.notBlank(list)) {
 			return;

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/WebsiteSmsUtil.java

@@ -11,6 +11,7 @@ import com.example.nngkxxdp.service.WebsiteSmsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
@@ -52,6 +53,7 @@ public class WebsiteSmsUtil {
 	* @throws
 	 */
 //	@Scheduled(cron = "0 0 08 10 * ?")
+//	@Async("threadPoolTaskExecutor")//多个定时器需要用到的线程池
 	public void task() {
 		StaticLog.info("==============================================================");
 		StaticLog.info("开始执行每月网站考评短信发送任务");

+ 9 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/util/WzkpRecordUtil.java

@@ -10,6 +10,8 @@ import com.example.nngkxxdp.dao.ColumnDao;
 import com.example.nngkxxdp.dao.HlwInterfaceDao;
 import com.example.nngkxxdp.dao.TjDao;
 import com.example.nngkxxdp.enums.UtilEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -21,6 +23,8 @@ import java.util.*;
 @Component
 public class WzkpRecordUtil {
 
+    private static final Logger logger = LoggerFactory.getLogger(WzkpRecordUtil.class);
+
     @Autowired
     private TjDao tjDao;
 
@@ -38,7 +42,7 @@ public class WzkpRecordUtil {
     public void generateRecord(String dateString) {
         try {
             //基础处理
-            if (dateString.isEmpty()) {
+            if (Blank.isEmpty(dateString)) {
                 dateString = DateUtil.format(new Date(), "yyyy-MM-dd");
             }
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -78,6 +82,7 @@ public class WzkpRecordUtil {
             cl4.setTime(date);
             cl4.add(Calendar.MONTH, -1);
             String thisMonth = DateUtil.format(cl4.getTime(), "yyyy-MM");
+            logger.info("开始生成" + thisMonth + "网站考评的数据");
             // 查询是否已初始化
             Integer count = tjDao.getCountWebsiteRating(null, thisMonth);
             // 部门基础分值配置
@@ -85,6 +90,7 @@ public class WzkpRecordUtil {
             if (count == 0) {
                 // 初始化当月分值
                 tjDao.saveDeptRecord(deptList, thisMonth);
+                logger.info("生成部门基础分值成功");
             }
             //----------------------------------------
 
@@ -297,6 +303,8 @@ public class WzkpRecordUtil {
                 }
             }
             tjDao.saveNewRecord(tRecordList);
+            logger.info("生成加扣分详情成功!");
+            logger.info(thisMonth+"网站考评分数生成成功!");
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 4 - 1
nngkxxdp/src/main/resources/mapper/HlwInterfaceDao.xml

@@ -239,7 +239,10 @@
     </delete>
 
     <select id="getHlwData" resultType="map">
-        SELECT * from save_hlw_interface_data where DOCRELTIME BETWEEN #{firstDay} and #{lastDay} and CHANNELNAME =
+        SELECT id,CHNLID,CHANNELNAME,DOCPUBURL,DOCRELTIME,DOCTITLE
+        from save_hlw_interface_data
+        where DOCRELTIME BETWEEN
+        #{firstDay} and #{lastDay} and CHANNELNAME =
         #{gzqk}
         and CHNLID in
         <foreach item="item" collection="chnilds" open="(" separator="," close=" )">

+ 41 - 0
nngkxxdp/src/main/resources/mapper/YxnnDao.xml

@@ -6,6 +6,19 @@
         from impression_nanan
     </select>
 
+    <select id="getDocumentCountFront" resultType="Integer">
+        select count(*)
+        from impression_nanan
+        <where>
+            <if test="pictureType != null">
+                AND picture_type LIKE CONCAT('%', #{pictureType}, '%')
+            </if>
+            <if test="examineState != null">
+                AND examine_state LIKE CONCAT('%', #{examineState}, '%')
+            </if>
+        </where>
+    </select>
+
     <select id="getDocumentPage" resultType="java.util.Map">
         SELECT id,
         uploader_phone,
@@ -34,6 +47,34 @@
         limit #{startRows},#{rows}
     </select>
 
+    <select id="getDocumentPageFront" resultType="java.util.Map">
+        SELECT id,
+        uploader_phone,
+        upload_time,
+        update_time,
+        url_address,
+        picture_type,
+        examine_state,
+        picture_description,
+        picture_title,
+        picture_author,
+        vesting_date,
+        is_public,
+        is_anonymous
+        FROM impression_nanan
+        <where>
+            <if test="pictureType != null">
+                AND picture_type LIKE CONCAT('%', #{pictureType}, '%')
+            </if>
+            <if test="examineState != null">
+                AND examine_state LIKE CONCAT('%', #{examineState}, '%')
+            </if>
+        </where>
+        order by vesting_date DESC,upload_time DESC,
+        update_time DESC
+        limit #{startRows},#{rows}
+    </select>
+
     <insert id="saveDocumetIn" parameterType="com.example.nngkxxdp.entity.ImpressionNanan">
         INSERT INTO impression_nanan (uploader_phone, upload_time, update_time, url_address, picture_type,
                                       examine_state,picture_description,picture_title,picture_author,vesting_date,is_public,is_anonymous)