浏览代码

add(backend) [微信接口位置移动 1.0]

wangxiao 4 年之前
父节点
当前提交
a1d8d2950e

+ 1 - 8
operation-backend/src/main/java/com/idiot/operationbackend/controller/WeChatController.java

@@ -2,23 +2,17 @@ package com.idiot.operationbackend.controller;
 
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.idiot.operationbackend.entity.Account;
 import com.idiot.operationbackend.entity.Account;
-import com.idiot.operationbackend.entity.SubscribeScene;
 import com.idiot.operationbackend.handler.WeChatMessageFactory;
 import com.idiot.operationbackend.handler.WeChatMessageFactory;
 import com.idiot.operationbackend.service.facade.AccountService;
 import com.idiot.operationbackend.service.facade.AccountService;
-import com.idiot.operationbackend.service.facade.SubscribeSceneService;
 import com.idiot.operationbackend.service.facade.WeChatMessageService;
 import com.idiot.operationbackend.service.facade.WeChatMessageService;
 import com.idiot.operationbackend.service.facade.WeChatService;
 import com.idiot.operationbackend.service.facade.WeChatService;
-import com.idiot.operationbackend.support.AccountState;
 import com.idiot.operationbackend.support.Constants;
 import com.idiot.operationbackend.support.Constants;
-import com.idiot.operationbackend.support.JsonResult;
-import com.idiot.operationbackend.util.JwtTokenUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
@@ -26,7 +20,6 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedInputStream;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.IOException;
-import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Objects;
 
 
@@ -109,7 +102,7 @@ public class WeChatController {
             account.setBusinessInfo(authorizerInfo.getJSONObject("business_info").toJSONString());
             account.setBusinessInfo(authorizerInfo.getJSONObject("business_info").toJSONString());
             account.setAlias(authorizerInfo.getString("alias"));
             account.setAlias(authorizerInfo.getString("alias"));
             account.setQrcodeUrl(authorizerInfo.getString("qrcode_url"));
             account.setQrcodeUrl(authorizerInfo.getString("qrcode_url"));
-            account.setState(AccountState.SUCCESS);
+            account.setState(0);
             // 保存 数据和token
             // 保存 数据和token
             boolean ifResult = weChatService.saveOrUpdateWechatAcc(account);
             boolean ifResult = weChatService.saveOrUpdateWechatAcc(account);
             weChatService.cacheAuthorizerAccessToken(account.getId(),authorizerAccessToken);
             weChatService.cacheAuthorizerAccessToken(account.getId(),authorizerAccessToken);

+ 16 - 4
operation-backend/src/main/java/com/idiot/operationbackend/controller/account/AccountController.java

@@ -2,9 +2,8 @@ package com.idiot.operationbackend.controller.account;
 
 
 import com.idiot.operationbackend.entity.Account;
 import com.idiot.operationbackend.entity.Account;
 import com.idiot.operationbackend.entity.AuthUser;
 import com.idiot.operationbackend.entity.AuthUser;
-import com.idiot.operationbackend.service.facade.AccountService;
-import com.idiot.operationbackend.service.facade.AuthUserService;
-import com.idiot.operationbackend.service.facade.WeChatService;
+import com.idiot.operationbackend.service.facade.*;
+import com.idiot.operationbackend.support.Constants;
 import com.idiot.operationbackend.support.CustomException;
 import com.idiot.operationbackend.support.CustomException;
 import com.idiot.operationbackend.support.JsonResult;
 import com.idiot.operationbackend.support.JsonResult;
 import com.idiot.operationbackend.util.JwtTokenUtil;
 import com.idiot.operationbackend.util.JwtTokenUtil;
@@ -17,6 +16,7 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -43,6 +43,12 @@ public class AccountController {
     @Autowired
     @Autowired
     private WeChatService weChatService;
     private WeChatService weChatService;
 
 
+    @Autowired
+    private AccountFansService fansService;
+
+    @Autowired
+    private FansActionStatService fansActionStatService;
+
 
 
 
 
     @GetMapping
     @GetMapping
@@ -64,8 +70,14 @@ public class AccountController {
             accounts.addAll(subAccounts);
             accounts.addAll(subAccounts);
         }
         }
         if (CollectionUtils.isEmpty(accounts)){
         if (CollectionUtils.isEmpty(accounts)){
-            throw new CustomException(502,"当前帐号和子账号下没有认证的公众号,请前往公众号管理中心添加认证公众号");
+            throw new CustomException(501,"当前帐号和子账号下没有认证的公众号,请前往公众号管理中心添加认证公众号");
         }
         }
+        LocalDateTime end  = LocalDateTime.now();
+        long  start = end.plusDays(-2).toEpochSecond(Constants.DEFAULT_ZONE);
+        accounts.forEach(e->{
+            e.setFansNum(fansService.countFans(e.getId()));
+            e.setInteractFansNum(fansActionStatService.countInactiveFansNum(e.getId(),start,end.toEpochSecond(Constants.DEFAULT_ZONE)));
+        });
         return ResponseEntity.ok(JsonResult.success(accounts));
         return ResponseEntity.ok(JsonResult.success(accounts));
     }
     }
 
 

+ 3 - 4
operation-backend/src/main/java/com/idiot/operationbackend/entity/Account.java

@@ -3,7 +3,6 @@ package com.idiot.operationbackend.entity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.idiot.operationbackend.support.AccountState;
 
 
 /**
 /**
  * 公众号
  * 公众号
@@ -42,7 +41,7 @@ public class Account {
 
 
     private String qrcodeUrl;
     private String qrcodeUrl;
 
 
-    private AccountState state;
+    private Integer state;
 
 
     private String createUserId;
     private String createUserId;
 
 
@@ -162,11 +161,11 @@ public class Account {
         this.qrcodeUrl = qrcodeUrl;
         this.qrcodeUrl = qrcodeUrl;
     }
     }
 
 
-    public AccountState getState() {
+    public Integer getState() {
         return state;
         return state;
     }
     }
 
 
-    public void setState(AccountState state) {
+    public void setState(Integer state) {
         this.state = state;
         this.state = state;
     }
     }
 
 

+ 10 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/facade/AccountFansService.java

@@ -148,4 +148,14 @@ public interface AccountFansService extends IService<AccountFans> {
      * @param openId openId
      * @param openId openId
      */
      */
     void unsubscribe(String accountId,String openId);
     void unsubscribe(String accountId,String openId);
+
+
+    /**
+     *  统计粉丝数
+     * @author wangxiao
+     * @date 15:59 2020/9/25
+     * @param accountId accountId
+     * @return int 结果
+     */
+    int countFans (String accountId);
 }
 }

+ 6 - 6
operation-backend/src/main/java/com/idiot/operationbackend/service/facade/FansActionStatService.java

@@ -16,9 +16,9 @@ public interface FansActionStatService extends IService<FansActionStat> {
     /**
     /**
      * 统计区间内 粉丝活跃数量 (秒级时间戳)
      * 统计区间内 粉丝活跃数量 (秒级时间戳)
      *
      *
-     * @param accountId
-     * @param startDate
-     * @param endDate
+     * @param accountId accountId
+     * @param startDate startDate
+     * @param endDate endDate
      * @return int
      * @return int
      * @author wangxiao
      * @author wangxiao
      * @date 11:39 2020/9/16
      * @date 11:39 2020/9/16
@@ -29,9 +29,9 @@ public interface FansActionStatService extends IService<FansActionStat> {
     /**
     /**
      * 查询区间内 粉丝活跃数量 (秒级时间戳)
      * 查询区间内 粉丝活跃数量 (秒级时间戳)
      *
      *
-     * @param accountId
-     * @param startDate
-     * @param endDate
+     * @param accountId accountId
+     * @param startDate startDate
+     * @param endDate endDate
      * @return int
      * @return int
      * @author wangxiao
      * @author wangxiao
      * @date 11:39 2020/9/16
      * @date 11:39 2020/9/16

+ 7 - 1
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/AccountFansServiceImpl.java

@@ -78,7 +78,7 @@ public class AccountFansServiceImpl extends ServiceImpl<AccountFansMapper, Accou
     public Page<AccountFans> pageFans(String accountId, Integer sex, String city, String province, String tagId, String label, String startTime, String endTime, int page, int pageSize) {
     public Page<AccountFans> pageFans(String accountId, Integer sex, String city, String province, String tagId, String label, String startTime, String endTime, int page, int pageSize) {
         Page<AccountFans> queryPage = new Page<>(page,pageSize);
         Page<AccountFans> queryPage = new Page<>(page,pageSize);
         LambdaQueryWrapper<AccountFans> queryWrapper = Wrappers.lambdaQuery();
         LambdaQueryWrapper<AccountFans> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(AccountFans::getAccountId,accountId).eq(AccountFans::getState,"1");
+        queryWrapper.eq(AccountFans::getAccountId,accountId).eq(AccountFans::getState,1);
         if (Objects.nonNull(sex)) {
         if (Objects.nonNull(sex)) {
             queryWrapper.eq(AccountFans::getSex,sex);
             queryWrapper.eq(AccountFans::getSex,sex);
         }
         }
@@ -220,4 +220,10 @@ public class AccountFansServiceImpl extends ServiceImpl<AccountFansMapper, Accou
         update(Wrappers.<AccountFans>lambdaUpdate().set(AccountFans::getState,0)
         update(Wrappers.<AccountFans>lambdaUpdate().set(AccountFans::getState,0)
                 .eq(AccountFans::getAccountId,accountId).eq(AccountFans::getOpenId,openId));
                 .eq(AccountFans::getAccountId,accountId).eq(AccountFans::getOpenId,openId));
     }
     }
+
+    @Override
+    public int countFans(String accountId) {
+        return  count(Wrappers.<AccountFans>lambdaQuery().eq(AccountFans::getState,1)
+                .eq(AccountFans::getAccountId,accountId));
+    }
 }
 }

+ 0 - 39
operation-backend/src/main/java/com/idiot/operationbackend/support/AccountState.java

@@ -1,39 +0,0 @@
-package com.idiot.operationbackend.support;
-
-import com.baomidou.mybatisplus.annotation.EnumValue;
-import com.fasterxml.jackson.annotation.JsonValue;
-
-/**
- * @author wang xiao
- * @date Created in 18:08 2020/9/10
- */
-public enum AccountState {
-
-    /**
-     *  公众号认证成功
-     * @author wangxiao
-     * @date 18:10 2020/9/10
-     */
-    SUCCESS(0,"认证成功"),
-
-    /**
-     *  公众号认证成功
-     * @author wangxiao
-     * @date 18:10 2020/9/10
-     */
-    FAIL(-1,"认证失败");
-
-
-    @EnumValue
-    private final int value;
-
-    @JsonValue
-    private final String label;
-
-    AccountState(int value, String label) {
-        this.value = value;
-        this.label = label;
-    }
-
-
-}