Ver Fonte

定时任务增加全局开关

leon há 5 anos atrás
pai
commit
180692bf26

+ 0 - 1
src/main/java/com/mokamrp/privates/PrivateServerStart.java

@@ -13,7 +13,6 @@ import org.springframework.web.client.RestTemplate;
 import java.util.Arrays;
 
 @EnableAsync
-@EnableScheduling
 @MapperScan("com.mokamrp.privates.mapper")
 @SpringBootApplication
 public class PrivateServerStart {

+ 18 - 0
src/main/java/com/mokamrp/privates/config/ScheduledCondition.java

@@ -0,0 +1,18 @@
+package com.mokamrp.privates.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.stereotype.Component;
+
+@Component
+@Configuration
+public class ScheduledCondition implements Condition {
+    @Override
+    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+        String power = context.getEnvironment().getProperty("cronjob.power");
+        return Boolean.valueOf(power);
+    }
+}

+ 12 - 0
src/main/java/com/mokamrp/privates/config/TaskConfig.java

@@ -1,12 +1,18 @@
 package com.mokamrp.privates.config;
 
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.TaskScheduler;
+import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.stereotype.Component;
 
 @Configuration
+@Component
 public class TaskConfig {
+
     @Bean
     public TaskScheduler taskScheduler() {
         ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
@@ -14,4 +20,10 @@ public class TaskConfig {
         scheduler.setPoolSize(1);
         return scheduler;
     }
+
+    @Conditional(ScheduledCondition.class)
+    @Bean
+    public ScheduledAnnotationBeanPostProcessor processor() {
+        return new ScheduledAnnotationBeanPostProcessor();
+    }
 }

+ 2 - 0
src/main/java/com/mokamrp/privates/constant/RedisKey.java

@@ -31,6 +31,8 @@ public class RedisKey {
     public static final String PanWxFosterMobileInfo = "pan_wxfoster_mobile_info:";
     //.盘古 微信养号账号修改异步操作
     public static final String PanWxFosterMobileSync = "pan_wxfoster_mobile_sync";
+    //.盘古 微信养号站点修改异步操作
+    public static final String PanWxFosterStationSync = "pan_wxfoster_station_sync";
     //.盘古 微信养号小程序异步编辑任务
     public static final String PanWxFosterTaskSync = "pan_wxfoster_task_sync";
     //.盘古 微信养号站点列表

+ 2 - 1
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxMobileController.java

@@ -9,6 +9,7 @@ import com.mokamrp.privates.controller.BaseController;
 import com.mokamrp.privates.entity.AddHandle;
 import com.mokamrp.privates.entity.DelHandle;
 import com.mokamrp.privates.entity.EditHandle;
+import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.GetForsterwxMobileHandle;
 import com.mokamrp.privates.help.AjaxResult;
 import com.mokamrp.privates.help.Analysis;
@@ -68,7 +69,7 @@ public class FosterwxMobileController extends BaseController<FosterwxMobile> {
         if (bindingResult.hasErrors()) {
             return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
         }
-        Map<String, Object> res = fosterwxMobileService.getList(getForsterwxMobileHandle);
+        ResHandle<List<FosterwxMobile>> res = fosterwxMobileService.getList(getForsterwxMobileHandle);
         return AjaxResult.success(res);
     }
 

+ 4 - 0
src/main/java/com/mokamrp/privates/entity/pangu/GetForsterwxMobileHandle.java

@@ -2,6 +2,8 @@ package com.mokamrp.privates.entity.pangu;
 
 import lombok.Data;
 
+import java.time.LocalDateTime;
+
 @Data
 public class GetForsterwxMobileHandle {
     private Integer page;
@@ -17,6 +19,8 @@ public class GetForsterwxMobileHandle {
     private Integer status;
     private String year;
     private String month;
+    private String createDate;
+    private String updateDate;
 
     public Integer getPage() {
         return page;

+ 2 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxMobileMapper.xml

@@ -50,6 +50,8 @@
             <if test="param.wxStatus != null">and wx_status = #{param.wxStatus}</if>
             <if test="param.status != null">and status = #{param.status}</if>
             <if test="param.stationId != null">and station_id = #{param.stationId}</if>
+            <if test="param.createDate != null">and left(create_at,10) = #{param.createDate}</if>
+            <if test="param.updateDate != null">and left(update_at,10) = #{param.updateDate}</if>
         </where>
         order by id desc
     </select>

+ 8 - 9
src/main/java/com/mokamrp/privates/mapper/pangu/pojo/FosterwxStation.java

@@ -37,12 +37,19 @@ public class FosterwxStation extends Model<FosterwxStation> {
      */
     private String stationName;
 
+    private Integer vip;
+
     /**
      * 站点负责人id(private.user.id)
      */
     private Integer stationUid;
 
     /**
+     * 站点负责人名称
+     */
+    private Integer stationAdminName;
+
+    /**
      * 小程序分享链接
      */
     private String boxShareUrl;
@@ -70,7 +77,7 @@ public class FosterwxStation extends Model<FosterwxStation> {
     /**
      * 更新时间
      */
-    private LocalDateTime uploadAt;
+    private LocalDateTime updateAt;
 
 
     public Integer getId() {
@@ -121,13 +128,6 @@ public class FosterwxStation extends Model<FosterwxStation> {
         this.createAt = createAt;
     }
 
-    public LocalDateTime getUploadAt() {
-        return uploadAt;
-    }
-
-    public void setUploadAt(LocalDateTime uploadAt) {
-        this.uploadAt = uploadAt;
-    }
 
     @Override
     protected Serializable pkVal() {
@@ -143,7 +143,6 @@ public class FosterwxStation extends Model<FosterwxStation> {
                 ", boxShareUrl=" + boxShareUrl +
                 ", uploadUid=" + uploadUid +
                 ", createAt=" + createAt +
-                ", uploadAt=" + uploadAt +
                 "}";
     }
 }

+ 2 - 1
src/main/java/com/mokamrp/privates/service/pangu/FosterwxMobileService.java

@@ -1,5 +1,6 @@
 package com.mokamrp.privates.service.pangu;
 
+import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.GetForsterwxMobileHandle;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -18,7 +19,7 @@ import java.util.Map;
  */
 public interface FosterwxMobileService extends IService<FosterwxMobile> {
     //.@leon 获取数据列表
-    public Map<String, Object> getList(GetForsterwxMobileHandle handle);
+    public ResHandle<List<FosterwxMobile>> getList(GetForsterwxMobileHandle handle);
     //.@leon 获取指定站点下账号列表
     public Map<String, Object> getListByStationId(GetForsterwxMobileHandle getForsterwxMobileHandle, Integer stationId);
 

+ 7 - 5
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxMobileServiceImpl.java

@@ -1,6 +1,8 @@
 package com.mokamrp.privates.service.pangu.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.api.R;
+import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.GetForsterwxMobileHandle;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
 import com.mokamrp.privates.mapper.pangu.FosterwxMobileMapper;
@@ -42,15 +44,15 @@ public class FosterwxMobileServiceImpl extends ServiceImpl<FosterwxMobileMapper,
      * @param handle
      * @return
      */
-    public Map<String, Object> getList(GetForsterwxMobileHandle handle) {
+    public ResHandle<List<FosterwxMobile>> getList(GetForsterwxMobileHandle handle) {
         Integer pagesize = handle.getPagesize();
         Integer page = handle.getPage();
         Page<FosterwxMobile> pageObj = new Page<FosterwxMobile>(page, pagesize);
         List<FosterwxMobile> list = fosterwxMobileMapper.getList(pageObj,handle);
-        Map<String, Object> resMap = new HashMap<String, Object>();
-        resMap.put("list", list);
-        resMap.put("total", pageObj.getTotal());
-        return resMap;
+        ResHandle<List<FosterwxMobile>> resHandle = new ResHandle<>();
+        resHandle.setList(list);
+        resHandle.setTotal(pageObj.getTotal());
+        return resHandle;
     }
 
     /**

+ 1 - 0
src/main/java/com/mokamrp/privates/tast/Datahub/DatahubCorpData.java

@@ -46,6 +46,7 @@ public class DatahubCorpData {
     @Scheduled(fixedDelay = 300000)
     public void execute() {
         System.out.println("执行概览数据推送datahub任务,当前时间"+new Date());
+
         job(project,topic,3);
     }
 

+ 75 - 0
src/main/java/com/mokamrp/privates/tast/pangu/StationMobileNotice.java

@@ -0,0 +1,75 @@
+package com.mokamrp.privates.tast.pangu;
+
+import com.mokamrp.privates.entity.ResHandle;
+import com.mokamrp.privates.entity.pangu.GetForsterwxMobileHandle;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxStation;
+import com.mokamrp.privates.service.pangu.FosterwxMobileService;
+import com.mokamrp.privates.service.pangu.FosterwxStationService;
+import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
+import com.mokamrp.privates.utils.Cmd;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+@Component
+public class StationMobileNotice {
+
+    @Autowired
+    public FosterwxTaskScheduleService fosterwxTaskScheduleService;
+
+    @Autowired
+    public FosterwxStationService fosterwxStationService;
+
+    @Autowired
+    public FosterwxMobileService fosterwxMobileService;
+
+    @Autowired
+    public StringRedisTemplate stringRedisTemplate;
+
+    private String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/60fa2762-e0a0-4eb8-97ce-8dc0938057de";
+
+    @Scheduled(cron = "0 0 9 * * ?")
+    public void execute() {
+        System.out.println("[cronjob]:每日站点账号新增统计通知");
+        GetForsterwxMobileHandle getForsterwxMobileHandle = new GetForsterwxMobileHandle();
+        String lastDay = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        getForsterwxMobileHandle.setCreateDate(lastDay);
+        getForsterwxMobileHandle.setPage(1);
+        getForsterwxMobileHandle.setPagesize(9999);
+        ResHandle<List<FosterwxMobile>> res = fosterwxMobileService.getList(getForsterwxMobileHandle);
+        List<FosterwxMobile> list = res.getList();
+        Map<String,String> sendMap = new HashMap<>();
+        List<FosterwxStation> fosterwxStationList = fosterwxStationService.list();
+        for (FosterwxMobile fosterwxMobile : list){
+            FosterwxStation fosterwxStationInfo = this.getStationInfo(fosterwxMobile.getStationId(),fosterwxStationList);
+            String stationNm = fosterwxStationInfo.getStationName();
+            if (sendMap.get(stationNm) == null || sendMap.get(stationNm).isEmpty()){
+                sendMap.put(stationNm,fosterwxMobile.getMobileCode().toString());
+            }else{
+                sendMap.put(stationNm,sendMap.get(stationNm)+"、"+fosterwxMobile.getMobileCode().toString());
+            }
+        }
+        String sendMsg = "[站点账号新增 "+lastDay+"]\r\n";
+        for (String key : sendMap.keySet()){
+            sendMsg += "站点编号:"+key+"   ";
+            sendMsg += "手机编号:"+sendMap.get(key)+"\r\n";
+        }
+        Cmd.sendFeishuMsg(feishu, sendMsg);
+    }
+
+    public FosterwxStation getStationInfo(Integer stationId,List<FosterwxStation> rows){
+        for (FosterwxStation fosterwxStation : rows){
+            if (fosterwxStation.getId().equals(stationId)){
+                return fosterwxStation;
+            }
+        }
+        return null;
+    }
+}

+ 72 - 0
src/main/java/com/mokamrp/privates/tast/pangu/SyncFosterwxStationEdit.java

@@ -0,0 +1,72 @@
+package com.mokamrp.privates.tast.pangu;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mokamrp.privates.constant.RedisKey;
+import com.mokamrp.privates.entity.pangu.AddFosterwxMobileHandle;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobileWxfriend;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxStation;
+import com.mokamrp.privates.service.pangu.FosterwxMobileService;
+import com.mokamrp.privates.service.pangu.FosterwxMobileWxfriendService;
+import com.mokamrp.privates.service.pangu.FosterwxStationService;
+import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class SyncFosterwxStationEdit {
+
+    @Autowired
+    public FosterwxTaskScheduleService fosterwxTaskScheduleService;
+
+    @Autowired
+    public FosterwxStationService fosterwxStationService;
+
+    @Autowired
+    public FosterwxMobileService fosterwxMobileService;
+
+    @Autowired
+    public FosterwxMobileWxfriendService fosterwxMobileWxfriendService;
+
+    @Autowired
+    public StringRedisTemplate stringRedisTemplate;
+
+    @Scheduled(cron = "*/1 * * * * ?")
+    public void execute() {
+        System.out.println("[cronjob]:异步执行微信养号站点信息修改/新增操作");
+        Integer cnt = 1;
+        while (true) {
+            cnt++;
+            if (cnt > 20) {
+                break;
+            }
+            try {
+                Thread.sleep(100);
+                String info = stringRedisTemplate.opsForList().rightPop(RedisKey.PanWxFosterStationSync);
+                if (info == null || info.isEmpty()) {
+                    continue;
+                }
+                FosterwxStation fosterwxStation = JSONObject.parseObject(info, FosterwxStation.class);
+                if (fosterwxStation.getId().equals(0)) {
+                    continue;
+                }
+                //.更新
+                fosterwxStation.setUpdateAt(LocalDateTime.now());
+                fosterwxStationService.update(fosterwxStation, new QueryWrapper<FosterwxStation>().eq("id", fosterwxStation.getId()));
+                //.立刻更新账号REDIS
+                FosterwxStation stationInfo = fosterwxStationService.getOne(new QueryWrapper<FosterwxStation>().eq("id", fosterwxStation.getId()));
+                stringRedisTemplate.opsForHash().put(RedisKey.PanWxFosterStationInfo,fosterwxStation.getId().toString(),JSONObject.toJSONString(stationInfo));
+            } catch (InterruptedException ie) {
+                Thread.currentThread().interrupt();
+            }
+        }
+    }
+}

+ 3 - 0
src/main/resources/application-local.properties

@@ -62,3 +62,6 @@ datahub.accesssecret=p9tVmeDeeEENKhfsBsSeYc0F0ggH5b
 datahub.topic=s_hera_api_external_user
 datahub.corpTopic=ods_hera_msv_corp_data
 datahub.project=hera
+
+#定时任务全局开关,本地环境无需开启
+cronjob.power=false

+ 2 - 0
src/main/resources/application-prod.properties

@@ -68,3 +68,5 @@ datahub.topic=s_hera_api_external_user
 datahub.corpTopic=ods_hera_msv_corp_data
 datahub.project=hera
 
+#定时任务全局开关,线上环境需要开启
+cronjob.power=true 

+ 2 - 1
src/main/resources/application-test.properties

@@ -72,7 +72,8 @@ datahub.topic=s_hera_api_external_user_test
 datahub.corpTopic=ods_hera_msv_corp_data
 datahub.project=hera
 
-
+#定时任务全局开关,线上环境需要开启
+cronjob.power=true 
 
 
 

+ 2 - 1
src/main/resources/template/controller.java.vm

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import com.mokamrp.privates.controller.BaseController;
 import javax.validation.Valid;
 import java.util.Map;
+import java.util.List;
 
 #if(${restControllerStyle})
 import org.springframework.web.bind.annotation.RestController;
@@ -62,7 +63,7 @@ public class ${table.controllerName} {
         if (bindingResult.hasErrors()) {
             return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
         }
-        Map<String,Object> res = ${table.entityPath}Service.getList(postBasePageHandle);
+        ResHandle<List<${table.entityPath}>> res = ${table.entityPath}Service.getList(postBasePageHandle);
         return AjaxResult.success(res);
     }
 

+ 1 - 1
src/main/resources/template/service.java.vm

@@ -17,6 +17,6 @@ interface ${table.serviceName} : ${superServiceClass}<${entity}>
 #else
 public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
     //.@leon 获取数据列表
-    public Map<String, Object> getList(PostBasePageHandle handle);
+    public ResHandle<List<${table.entityPath}>> getList(PostBasePageHandle handle);
 }
 #end

+ 4 - 3
src/main/resources/template/serviceImpl.java.vm

@@ -9,6 +9,7 @@ import com.mokamrp.privates.entity.PostBasePageHandle;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import com.mokamrp.privates.entity.ResHandle;
 import java.util.*;
 
 /**
@@ -39,9 +40,9 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
         Integer page = handle.getPage();
         Page<${entity}> pageObj = new Page<${entity}>(page, pagesize);
         List<${entity}> list = ${table.entityPath}Mapper.getList(pageObj);
-        Map<String, Object> resMap = new HashMap<String, Object>();
-        resMap.put("list", list);
-        resMap.put("total", pageObj.getTotal());
+        ResHandle<List<FosterwxMobile>> resHandle = new ResHandle<>();
+        resHandle.setList(list);
+        resHandle.setTotal(pageObj.getTotal());
         return resMap;
     }
 }