Просмотр исходного кода

新增个微池 历史总金粉人数 当日进粉人数 统计

lqc 4 лет назад
Родитель
Сommit
9f5f91e8ff

+ 29 - 0
src/main/java/com/mokamrp/privates/controller/pangu/PanJobController.java

@@ -0,0 +1,29 @@
+package com.mokamrp.privates.controller.pangu;
+
+import com.mokamrp.privates.help.AjaxResult;
+import com.mokamrp.privates.task.pangu.SyncMobilePoolFans;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/job")
+@RestController
+@Slf4j
+public class PanJobController {
+    @Autowired
+    private SyncMobilePoolFans syncMobilePoolFans;
+
+    @GetMapping("/test")
+    public Object test() {
+        return AjaxResult.success("测试通路成功!");
+    }
+
+    @GetMapping("/sync")
+    public Object sync() {
+        syncMobilePoolFans.syncTotalFans();
+        syncMobilePoolFans.syncDayFans();
+        return AjaxResult.success("数据同步成功");
+    }
+}

+ 3 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxFlowListMapper.java

@@ -3,6 +3,7 @@ package com.mokamrp.privates.mapper.pangu;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxFlowList;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -18,4 +19,6 @@ import java.util.List;
 @Component
 public interface FosterwxFlowListMapper extends BaseMapper<FosterwxFlowList> {
     public List<FosterwxFlowList> getList(Page<FosterwxFlowList> pageObj);
+
+    Integer getTotalFans(@Param("poolIndex") String poolIndex);
 }

+ 7 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxFlowListMapper.xml

@@ -26,4 +26,11 @@
         SELECT *
         FROM pan_fosterwx_flow_list
     </select>
+    <select id="getTotalFans" resultType="java.lang.Integer">
+        SELECT SUM(TOTAL_FANS.total_fans)
+        FROM (SELECT MAX(bus_fans) AS total_fans
+              FROM pan_fosterwx_flow_list
+              WHERE pool_id = #{poolIndex}
+              GROUP BY DATE(time_line)) TOTAL_FANS
+    </select>
 </mapper>

+ 3 - 1
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxMobilePoolMapper.xml

@@ -19,6 +19,8 @@
         <result column="income_fans_type" property="incomeFansType"/>
         <result column="bus_mobile_no" property="busMobileNo"/>
         <result column="flow_position" property="flowPosition"/>
+        <result column="total_fans" property="totalFans" />
+        <result column="day_fans" property="dayFans" />
         <result column="create_uid" property="createUid"/>
         <result column="update_uid" property="updateUid"/>
         <result column="create_at" property="createAt"/>
@@ -28,7 +30,7 @@
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
         id
-        , pool_index, station_id, station_name, mobile_code, mobile_no, code_url, status, is_auto, status_update_time, wx_appid, max_fans, income_fans_type, bus_mobile_no, flow_position, create_uid, update_uid, create_at, update_at
+        , pool_index, station_id, station_name, mobile_code, mobile_no, code_url, status, is_auto, status_update_time, wx_appid, max_fans, income_fans_type, bus_mobile_no, flow_position, total_fans, day_fans, create_uid, update_uid, create_at, update_at
     </sql>
     <select id="getList" resultType="com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobilePool">
         SELECT *

+ 10 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/pojo/FosterwxMobilePool.java

@@ -107,6 +107,16 @@ public class FosterwxMobilePool extends Model<FosterwxMobilePool> {
     private String flowPosition;
 
     /**
+     * 历史总进粉人数
+     */
+    private Integer totalFans;
+
+    /**
+     * 当天进粉数
+     */
+    private Integer dayFans;
+
+    /**
      * 创建人
      */
     private Integer createUid;

+ 7 - 0
src/main/java/com/mokamrp/privates/service/pangu/FosterwxFlowListService.java

@@ -17,4 +17,11 @@ import java.util.Map;
 public interface FosterwxFlowListService extends IService<FosterwxFlowList> {
     //.@leon 获取数据列表
     public Map<String, Object> getList(FosterwxFlowListHandle handle);
+
+    /**
+     * 根据个微唯一码获取历史总进粉数
+     * @param poolIndex
+     * @return
+     */
+    Integer getTotalFans(String poolIndex);
 }

+ 11 - 0
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxFlowListServiceImpl.java

@@ -55,4 +55,15 @@ public class FosterwxFlowListServiceImpl extends ServiceImpl<FosterwxFlowListMap
         resMap.put("total", pageObj.getTotal());
         return resMap;
     }
+
+    /**
+     * 根据个微唯一码获取历史总进粉数
+     * @param poolIndex
+     * @return
+     */
+    @Override
+    public Integer getTotalFans(String poolIndex) {
+        Integer totalFans = fosterwxFlowListMapper.getTotalFans(poolIndex);
+        return totalFans;
+    }
 }

+ 0 - 49
src/main/java/com/mokamrp/privates/task/pangu/CheckPoolStatus.java

@@ -1,49 +0,0 @@
-// package com.mokamrp.privates.task.pangu;
-//
-// import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-// import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobilePool;
-// import com.mokamrp.privates.service.pangu.FosterwxMobilePoolService;
-// import lombok.extern.slf4j.Slf4j;
-// import org.springframework.beans.factory.annotation.Autowired;
-// import org.springframework.http.HttpEntity;
-// import org.springframework.http.HttpMethod;
-// import org.springframework.http.ResponseEntity;
-// import org.springframework.scheduling.annotation.Scheduled;
-// import org.springframework.stereotype.Component;
-// import org.springframework.web.client.RestTemplate;
-//
-// import java.util.HashMap;
-// import java.util.Map;
-//
-// /**检查个微池二维码是否有能用的
-//  * @author luqiucheng
-//  */
-// @Component
-// @Slf4j
-// public class CheckPoolStatus {
-//     @Autowired
-//     private FosterwxMobilePoolService fosterwxMobilePoolService;
-//
-//     @Autowired
-//     private RestTemplate restTemplate;
-//
-//     @Scheduled(cron = "0 */1 * * * ?")
-//     public void execute() {
-//         LambdaQueryWrapper<FosterwxMobilePool> fosterwxMobilePoolLambdaQueryWrapper = new LambdaQueryWrapper<>();
-//         // 查询有分组的 类型为游戏导粉的
-//         fosterwxMobilePoolLambdaQueryWrapper.ne(FosterwxMobilePool::getFlowPosition, "").eq(FosterwxMobilePool::getIncomeFansType, 2).groupBy(FosterwxMobilePool::getFlowPosition);
-//         fosterwxMobilePoolService.list(fosterwxMobilePoolLambdaQueryWrapper).forEach(fosterwxMobilePool -> {
-//             // 判断分组下未停用账号是否存在
-//             if (fosterwxMobilePoolService.count(new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getFlowPosition, fosterwxMobilePool.getFlowPosition()).ne(FosterwxMobilePool::getStatus, 0)) == 0) {
-//                 Map<String, Object> jsonObject = new HashMap<>();
-//                 jsonObject.put("msg_type", "text");
-//                 Map<String, String> contentObj = new HashMap<>();
-//                 String info = "流量位置:" + fosterwxMobilePool.getFlowPosition() + "已没有可以使用的二维码了!";
-//                 contentObj.put("text", info);
-//                 jsonObject.put("content", contentObj);
-//                 HttpEntity<Map<String, Object>> entity = new HttpEntity<>(jsonObject, null);
-//                 ResponseEntity<String> str = restTemplate.exchange("https://open.feishu.cn/open-apis/bot/v2/hook/782210e2-b016-4dd7-885b-e0ea5e58be94", HttpMethod.POST, entity, String.class);
-//             }
-//         });
-//     }
-// }

+ 104 - 0
src/main/java/com/mokamrp/privates/task/pangu/SyncMobilePoolFans.java

@@ -0,0 +1,104 @@
+package com.mokamrp.privates.task.pangu;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxFlowList;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobilePool;
+import com.mokamrp.privates.service.pangu.FosterwxFlowListService;
+import com.mokamrp.privates.service.pangu.FosterwxMobilePoolService;
+import lombok.extern.slf4j.Slf4j;
+import net.javacrumbs.shedlock.core.SchedulerLock;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/**统计今日进粉数 及 历史进粉数
+ * @author luqiucheng
+ */
+@Component
+@Slf4j
+public class SyncMobilePoolFans {
+    @Autowired
+    private FosterwxMobilePoolService fosterwxMobilePoolService;
+
+    @Autowired
+    private FosterwxFlowListService fosterwxFlowListService;
+
+
+    @Scheduled(cron = "0 0 0 * * ?")
+    @SchedulerLock(name = "pangu:syncTotalFans", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
+    public void syncTotalFans() {
+        fosterwxMobilePoolService.list().forEach(fosterwxMobilePool -> {
+            Integer totalFans = fosterwxFlowListService.getTotalFans(fosterwxMobilePool.getPoolIndex());
+            log.info("{}:{}", fosterwxMobilePool.getPoolIndex(), totalFans);
+            if (null != totalFans) {
+                fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+                    setTotalFans(totalFans);
+                }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getPoolIndex, fosterwxMobilePool.getPoolIndex()));
+            }
+        });
+
+        // // 获取游戏导粉类型的活码
+        // promoteCodeService.list(new LambdaQueryWrapper<PromoteCode>().eq(PromoteCode::getPromoteType, 2)).forEach(promoteCode -> {
+        //     // 根据活码id获取各位id 并取得redis缓存
+        //     promoteQrcodePoolService.list(new LambdaQueryWrapper<PromoteQrcodePool>().eq(PromoteQrcodePool::getPromoteId, promoteCode.getId())).forEach(promoteQrcodePool -> {
+        //         // 获取redis缓存
+        //         Double score = stringRedisTemplate.opsForZSet().score(RedisKey.PanCustServiceIdDayView + promoteCode.getId(), Integer.toString(promoteQrcodePool.getCustserviceId()));
+        //         log.info("{}:{}:{}", promoteCode.getId(), promoteQrcodePool.getCustserviceId(), score == null ? null : score.intValue());
+        //         // 活码使用了
+        //         if (null != score) {
+        //             // 判断长按识别数是否大于阈值
+        //             if (score.compareTo((double) 0) > 0) {
+        //                 if (score.compareTo(Double.valueOf(promoteQrcodePool.getDayUvMax())) >= 0) {
+        //                     // 没有超量
+        //                     fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+        //                         setStatus(2);
+        //                         setMaxFans(String.valueOf(promoteQrcodePool.getDayUvMax()));
+        //                         setUpdateAt(LocalDateTime.now());
+        //                     }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getId, promoteQrcodePool.getCustserviceId()).ne(FosterwxMobilePool::getStatus, 1));
+        //                 } else {
+        //
+        //                 }
+        //             } else {
+        //                 // 活码未使用
+        //                 fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+        //                     setStatus(1);
+        //                     set
+        //                     setMaxFans(String.valueOf(promoteQrcodePool.getDayUvMax()));
+        //                     setUpdateAt(LocalDateTime.now());
+        //                 }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getId, promoteQrcodePool.getCustserviceId()).ne(FosterwxMobilePool::getStatus, 1));
+        //             }
+        //         } else {
+        //             // 活码未使用
+        //             fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+        //                 setStatus(1);
+        //                 setMaxFans(String.valueOf(promoteQrcodePool.getDayUvMax()));
+        //                 setUpdateAt(LocalDateTime.now());
+        //             }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getId, promoteQrcodePool.getCustserviceId()).ne(FosterwxMobilePool::getStatus, 1));
+        //         }
+        //     });
+        // });
+    }
+
+    @Scheduled(cron = "1 */10 * * * ?")
+    @SchedulerLock(name = "pangu:syncDayFans", lockAtLeastForString = "PT5S", lockAtMostForString = "PT1M")
+    public void syncDayFans() {
+        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
+        fosterwxMobilePoolService.list().forEach(fosterwxMobilePool -> {
+            FosterwxFlowList fosterwxFlowList = fosterwxFlowListService.getOne(new LambdaQueryWrapper<FosterwxFlowList>().eq(FosterwxFlowList::getPoolId, fosterwxMobilePool.getPoolIndex()).ge(FosterwxFlowList::getTimeLine, localDateTime).orderByDesc(FosterwxFlowList::getId).last("limit 1"));
+            log.info("当天最新的进粉数据{}", fosterwxFlowList);
+            if (null != fosterwxFlowList) {
+                fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+                    setDayFans(fosterwxFlowList.getBusFans());
+                }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getPoolIndex, fosterwxMobilePool.getPoolIndex()));
+            } else {
+                fosterwxMobilePoolService.update(new FosterwxMobilePool() {{
+                    setDayFans(0);
+                }}, new LambdaQueryWrapper<FosterwxMobilePool>().eq(FosterwxMobilePool::getPoolIndex, fosterwxMobilePool.getPoolIndex()));
+            }
+        });
+    }
+}

+ 4 - 3
src/test/java/com/mokamrp/WebTest.java

@@ -10,8 +10,8 @@ import com.mokamrp.privates.service.pangu.FosterwxMobilePoolService;
 import com.mokamrp.privates.service.pangu.FosterwxMobileService;
 import com.mokamrp.privates.service.pangu.FosterwxMobileTaskTimeListService;
 import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
-import com.mokamrp.privates.task.pangu.CheckPoolStatus;
 import com.mokamrp.privates.task.pangu.SyncFosterwxMobilePool;
+import com.mokamrp.privates.task.pangu.SyncMobilePoolFans;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -44,7 +44,7 @@ public class WebTest {
     private FosterwxTaskScheduleService fosterwxTaskScheduleService;
 
     @Autowired
-    private CheckPoolStatus checkPoolStatus;
+    private SyncMobilePoolFans syncMobilePoolFans;
 
     @Test
     public void test1() {
@@ -72,7 +72,8 @@ public class WebTest {
     @Test
     public void test2() {
         // syncFosterwxMobilePool.execute();
-        checkPoolStatus.execute();
+        syncMobilePoolFans.syncTotalFans();
+        syncMobilePoolFans.syncDayFans();
     }
 
     /**