From cd7dcfe32b0eddc70a3c33532bd6fdcbe52e4dc6 Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期五, 21 十月 2022 16:23:21 +0800
Subject: [PATCH] #feat 修改

---
 springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbMemberServiceImpl.java    |   65 ++++++---------
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java                       |    2 
 springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java                                             |   57 +++++++++++--
 springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbCheckUnitServiceImpl.java |   98 +++++------------------
 4 files changed, 98 insertions(+), 124 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
index 5a3d91a..7bf6658 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
@@ -5,10 +5,13 @@
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
+import cn.hutool.core.util.StrUtil;
 import com.panzhihua.common.controller.BaseController;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.user.SysAppConfigVO;
+import com.panzhihua.common.redis.RedisUtils;
 import com.panzhihua.common.service.user.UserService;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileItemFactory;
@@ -40,11 +43,15 @@
     private static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
     private static String APP_IMAGE_URL = "https://www.psciio.com//idcard/8fa82cfba258498eab2fa818220fb592.jpg";
     private static String APP_IMAGE_NAME = "5.jpg";
+    private static String WX_CALL_BACK = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=";
+    //2小时
+    private static final Long EXPIRE_TIME = 2L;
     @Resource
     private RedisTemplate redisTemplate;
     @Resource
     private StringRedisTemplate stringRedisTemplate;
-    UserService userService;
+    @Resource
+    private RedisUtils redisUtils;
 
     private static WxXCXTempSend wxXCXTempSend;
     /**
@@ -95,20 +102,48 @@
      */
     public String getAccessToken() throws Exception {
          String accessToken = "";
-         accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+this.getAppId()).get();
-        return accessToken;
-    }
-    public String getAccessToken(String appid) throws Exception {
-        String accessToken = "";
-        accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appid).get();
+        String appId = this.getAppId();
+        accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+ appId).get();
+        if (appId.equals(APP_ID)){
+            accessToken = validAccessToken(accessToken, appId,APP_SECRET);
+        }
+
         return accessToken;
     }
 
-    public String getAppAccessToken() throws Exception {
+
+    public String getAccessToken(String appId) throws Exception {
+        String accessToken = "";
+        accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appId).get();
+        if (appId.equals(APP_ID)){
+            accessToken = validAccessToken(accessToken, appId,APP_SECRET);
+        }
+        return accessToken;
+    }
+
+    private String validAccessToken(String accessToken, String appId,String appSecret) throws Exception {
+        if (StrUtil.isEmpty(accessToken)) {
+            //重新获取并设置到缓存 该方法暂时只用在花城
+            accessToken = getAppAccessToken(appId, appSecret);
+            wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS);
+        } else {
+            String accessTokenUrl = WX_CALL_BACK + accessToken;
+            String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
+            Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
+            //如果Access_token过期也重新获取
+            if (resultMap.containsKey("errcode")) {
+                accessToken = getAppAccessToken(appId, appSecret);
+                wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS);
+            }
+        }
+        return accessToken;
+    }
+
+    public String getAppAccessToken(String appId,String appSecret) throws Exception {
         String accessToken = "0";
         try {
-            log.info("获取微信token参数:appid=" + APP_ID + ",appSecret=" + APP_SECRET);
-            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + APP_ID + "&secret=" + APP_SECRET;
+            log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret);
+            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret;
             String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
             Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
             if (resultMap.containsKey("access_token")) {
@@ -281,6 +316,8 @@
         wxXCXTempSend = this;
         wxXCXTempSend.redisTemplate = this.redisTemplate;
         wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate;
+        wxXCXTempSend.redisUtils=this.redisUtils;
+
     }
 
 }
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java
index ff6ad4c..f6209a4 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java
@@ -118,7 +118,7 @@
         WxXCXTempSend wxXCXTempSend=new WxXCXTempSend();
         for(String openId:openIds){
             try {
-                WxUtil.sendLongTimeTemplate(openId,wxXCXTempSend.getXQAppAccessToken(),"疫情快讯",comActDynVO.getTitle().length()>10?comActDynVO.getTitle().substring(0,10)+"..":comActDynVO.getTitle(),"/pages/community_child/community/detail?id="+comActDynVO.getId()+"&title=疫情快讯详情");
+                WxUtil.sendLongTimeTemplate(openId,wxXCXTempSend.getAccessToken("wx118de8a734d269f0"),"疫情快讯",comActDynVO.getTitle().length()>10?comActDynVO.getTitle().substring(0,10)+"..":comActDynVO.getTitle(),"/pages/community_child/community/detail?id="+comActDynVO.getId()+"&title=疫情快讯详情");
             } catch (Exception e) {
                 e.printStackTrace();
             }
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbCheckUnitServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbCheckUnitServiceImpl.java
index 3a5477d..31a4649 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbCheckUnitServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbCheckUnitServiceImpl.java
@@ -1,30 +1,30 @@
 package com.panzhihua.service_dangjian.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
 import com.panzhihua.common.enums.ComPbCheckUnitTypeEnum;
+import com.panzhihua.common.model.dtos.common.AddComPbCheckUnitDto;
+import com.panzhihua.common.model.dtos.common.EditComPbCheckUnitDto;
+import com.panzhihua.common.model.dtos.common.PageComPbCheckUnitDto;
+import com.panzhihua.common.model.dtos.common.PagePbCheckUnitCommonDto;
+import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.common.ComPbCheckUnitVo;
 import com.panzhihua.common.model.vos.partybuilding.excel.ComPbCheckUnitErrorExcelVO;
 import com.panzhihua.common.model.vos.partybuilding.excel.ComPbCheckUnitExcelVO;
-import com.panzhihua.common.service.community.CommunityService;
 import com.panzhihua.common.utlis.StringUtils;
+import com.panzhihua.service_dangjian.dao.ComPbCheckUnitMapper;
 import com.panzhihua.service_dangjian.dao.ComPbMemberDAO;
 import com.panzhihua.service_dangjian.dao.ComPbMemberRoleDAO;
 import com.panzhihua.service_dangjian.entity.ComPbCheckUnit;
-import com.panzhihua.service_dangjian.dao.ComPbCheckUnitMapper;
 import com.panzhihua.service_dangjian.model.dos.ComPbMemberDO;
 import com.panzhihua.service_dangjian.model.dos.ComPbMemberRoleDO;
 import com.panzhihua.service_dangjian.service.ComPbCheckUnitService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.panzhihua.service_dangjian.service.ComPbMemberService;
 import org.springframework.beans.BeanUtils;
-import com.panzhihua.common.model.dtos.common.*;
-import com.panzhihua.common.model.vos.R;
 import org.springframework.stereotype.Service;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
@@ -49,10 +49,7 @@
     private ComPbMemberDAO comPbMemberDAO;
     @Resource
     private ComPbMemberRoleDAO comPbMemberRoleDAO;
-    @Resource
-    private ComPbMemberService comPbMemberService;
-    @Resource
-    private CommunityService communityService;
+
 
     /**
      * description  queryByPage  分页查询
@@ -66,15 +63,8 @@
     public R queryByPage(PageComPbCheckUnitDto comPbCheckUnit) {
 
         Long communityId = comPbCheckUnit.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -189,15 +179,8 @@
     @Override
     public R queryByList(PageComPbCheckUnitDto comPbCheckUnit) {
         Long communityId = comPbCheckUnit.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -280,15 +263,8 @@
      */
     @Override
     public R unitStatisticsTop(Long communityId, String belongTo, String choice) {
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -303,15 +279,8 @@
     @Override
     public R unitStatistics(PagePbCheckUnitCommonDto commonDto) {
         Long communityId = commonDto.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -330,15 +299,8 @@
     @Override
     public R pbStatisticsTop(Long communityId, String belongTo, String choice, Long checkUnitId) {
 
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -353,15 +315,8 @@
     @Override
     public R pbStatisticsBelong(PagePbCheckUnitCommonDto commonDto) {
         Long communityId = commonDto.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
@@ -377,15 +332,8 @@
     @Override
     public R pbStatisticsUnit(PagePbCheckUnitCommonDto commonDto) {
         Long communityId = commonDto.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbMemberServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbMemberServiceImpl.java
index c792c0f..03d2be7 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbMemberServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/ComPbMemberServiceImpl.java
@@ -1,24 +1,33 @@
 package com.panzhihua.service_dangjian.service.impl;
 
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdcardUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.panzhihua.common.constants.UserConstants;
+import com.panzhihua.common.exceptions.PartyBuildingMemberException;
 import com.panzhihua.common.model.dtos.community.PageMemberForInviteDTO;
 import com.panzhihua.common.model.dtos.partybuilding.ComDataStatisticsOrgDto;
 import com.panzhihua.common.model.dtos.partybuilding.PageComDataStatisticsMemberDto;
+import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.partybuilding.*;
 import com.panzhihua.common.model.vos.partybuilding.excel.ComDataStatisticsMemberExcelVo;
 import com.panzhihua.common.model.vos.partybuilding.excel.ComPbMemberRoleExcelVo;
-import com.panzhihua.common.service.community.CommunityService;
+import com.panzhihua.common.model.vos.user.SysUserVO;
 import com.panzhihua.common.service.user.UserService;
+import com.panzhihua.common.utlis.DateUtils;
+import com.panzhihua.common.utlis.SensitiveUtil;
+import com.panzhihua.common.utlis.StringUtils;
+import com.panzhihua.service_dangjian.dao.*;
+import com.panzhihua.service_dangjian.model.dos.ComPbDynDO;
+import com.panzhihua.service_dangjian.model.dos.ComPbDynUserDO;
+import com.panzhihua.service_dangjian.model.dos.ComPbMemberDO;
+import com.panzhihua.service_dangjian.model.dos.ComPbOrgDO;
+import com.panzhihua.service_dangjian.service.ComPbMemberService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
@@ -26,23 +35,12 @@
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.panzhihua.common.constants.UserConstants;
-import com.panzhihua.common.exceptions.PartyBuildingMemberException;
-import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.model.vos.partybuilding.*;
-import com.panzhihua.common.model.vos.user.SysUserVO;
-import com.panzhihua.common.utlis.DateUtils;
-import com.panzhihua.common.utlis.SensitiveUtil;
-import com.panzhihua.common.utlis.StringUtils;
-import com.panzhihua.service_dangjian.dao.*;
-import com.panzhihua.service_dangjian.model.dos.*;
-import com.panzhihua.service_dangjian.service.ComPbMemberService;
-
-import lombok.extern.slf4j.Slf4j;
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 import static java.util.Objects.nonNull;
 
@@ -68,8 +66,6 @@
     private ComPbDynDAO comPbDynDAO;
     @Resource
     private ComPbDynUserDAO comPbDynUserDAO;
-    @Resource
-    private CommunityService communityService;
     @Resource
     private UserService userService;
 
@@ -206,15 +202,8 @@
     public R pagePartyOrganization(PagePartyOrganizationVO pagePartyOrganizationVO) {
 
         Long communityId = pagePartyOrganizationVO.getCommunityId();
-        R r = communityService.selectCommunityIds(communityId);
-        List<Long> communityIds = null;
-        if(R.isOk(r)){
-            communityIds = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), Long.class);
-            if (CollUtil.isEmpty(communityIds)) {
-                communityIds = new ArrayList<>();
-                communityIds.add(communityId);
-            }
-        }else {
+        List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
+        if (CollUtil.isEmpty(communityIds)) {
             communityIds = new ArrayList<>();
             communityIds.add(communityId);
         }

--
Gitblit v1.7.1