springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
@@ -1,23 +1,16 @@ package com.panzhihua.common.utlis; import java.io.*; import java.net.HttpURLConnection; 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.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.constants.SecurityConstants; 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 lombok.extern.slf4j.Slf4j; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.http.entity.ContentType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -25,14 +18,18 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.constants.SecurityConstants; import lombok.extern.slf4j.Slf4j; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import java.util.concurrent.TimeUnit; @Slf4j @Component @@ -54,6 +51,7 @@ private RedisUtils redisUtils; private static WxXCXTempSend wxXCXTempSend; /** * url转变为 MultipartFile对象 * @@ -65,7 +63,7 @@ private static MultipartFile createFileItem(String url, String fileName) throws Exception { FileItem item = null; try { HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection(); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setReadTimeout(30000); conn.setConnectTimeout(30000); // 设置应用程序要从网络连接读取数据 @@ -77,7 +75,7 @@ FileItemFactory factory = new DiskFileItemFactory(16, null); String textFieldName = "uploadfile"; item = factory.createItem(textFieldName, ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); factory.createItem(textFieldName, ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); OutputStream os = item.getOutputStream(); int bytesRead = 0; @@ -101,31 +99,27 @@ * @return */ public String getAccessToken() throws Exception { String accessToken = ""; String accessToken = ""; 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); } accessToken = wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:" + appId).get(); return accessToken; } 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); 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 { 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); 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); @@ -133,13 +127,13 @@ //如果Access_token过期也重新获取 if (resultMap.containsKey("errcode")) { accessToken = getAppAccessToken(appId, appSecret); wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS); 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 { public String getAppAccessToken(String appId, String appSecret) throws Exception { String accessToken = "0"; try { log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret); @@ -148,7 +142,17 @@ Map<String, Object> resultMap = JSON.parseObject(result, Map.class); if (resultMap.containsKey("access_token")) { accessToken = resultMap.get("access_token").toString(); wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken); } HttpServletRequest request = ServletUtils.getRequest(); String requestURI = request.getRequestURI(); //加上时间戳 String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date()); //这里是 Redis key的前缀,如: sys:tabieId:表名 如果不需要去掉表名也可以 String key = MessageFormat.format("{0}:{1}:{2}", "request_incr",datetime,requestURI); //查询 key 是否存在, 不存在返回 1 ,存在的话则自增加1 wxXCXTempSend.stringRedisTemplate.opsForValue().increment(key, 1); } catch (IOException ioe) { log.error("小程序http请求异常"); ioe.printStackTrace(); @@ -158,11 +162,12 @@ /** * 发布消息时重新设置access_token 防止过期 * * @param appId * @param appSecret * @throws Exception */ public void setAppAccessTokenToCache(String appId,String appSecret) throws Exception{ public void setAppAccessTokenToCache(String appId, String appSecret) throws Exception { String accessToken = "0"; try { log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret); @@ -171,7 +176,7 @@ Map<String, Object> resultMap = JSON.parseObject(result, Map.class); if (resultMap.containsKey("access_token")) { accessToken = resultMap.get("access_token").toString(); wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS); wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME, TimeUnit.HOURS); } } catch (IOException ioe) { log.error("小程序http请求异常"); @@ -179,19 +184,20 @@ } } public String getAccessTokenValid(String appId,Integer index) throws Exception { if (index % 100 == 0){ public String getAccessTokenValid(String appId, Integer index) throws Exception { if (index % 1000 == 0) { return getAccessToken(appId); }else { return wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appId).get(); } else { return wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:" + appId).get(); } } public String getWsAccessToken() throws Exception { String accessToken = "0"; try { // log.info("获取微信token参数:appid=" + APP_ID + ",appSecret=" + APP_SECRET); String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=wx98d62711dfbd8425"+ "&secret=97a2a10b990c2774ed279724337b5337"; String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=wx98d62711dfbd8425" + "&secret=97a2a10b990c2774ed279724337b5337"; String result = HttpClientUtil.httpGet(accessTokenUrl, null, null); Map<String, Object> resultMap = JSON.parseObject(result, Map.class); if (resultMap.containsKey("access_token")) { @@ -203,9 +209,11 @@ } return accessToken; } /** * 获取西区社区通微信token * @return 西区社区通微信token * * @return 西区社区通微信token * @throws Exception 异常 */ public String getXQAppAccessToken() throws Exception { @@ -238,7 +246,7 @@ mediaId = getAppMediaId(accessToken); valueOperations.set(SecurityConstants.APPLETS_ACCESS_MEDIA_ID, mediaId); valueOperations.set(SecurityConstants.APPLETS_ACCESS_MEDIA_ID_TIME, System.currentTimeMillis() + 259000000 + ""); System.currentTimeMillis() + 259000000 + ""); } else { mediaId = valueOperations.get(SecurityConstants.APPLETS_ACCESS_MEDIA_ID); } @@ -246,7 +254,7 @@ mediaId = getAppMediaId(accessToken); valueOperations.set(SecurityConstants.APPLETS_ACCESS_MEDIA_ID, mediaId); valueOperations.set(SecurityConstants.APPLETS_ACCESS_MEDIA_ID_TIME, System.currentTimeMillis() + 259000000 + ""); System.currentTimeMillis() + 259000000 + ""); } return mediaId; } @@ -267,15 +275,15 @@ * * @param file * @return * @author yixiu * @throws Exception * @author yixiu */ public String uploadFile(MultipartFile file, String access_token) throws Exception { String url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + access_token + "&type=image"; String result = null; String fileName = file.getOriginalFilename(); URL urlObj = new URL(url); HttpURLConnection con = (HttpURLConnection)urlObj.openConnection(); HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); @@ -347,8 +355,8 @@ public void init() { wxXCXTempSend = this; wxXCXTempSend.redisTemplate = this.redisTemplate; wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate; wxXCXTempSend.redisUtils=this.redisUtils; wxXCXTempSend.stringRedisTemplate = this.stringRedisTemplate; wxXCXTempSend.redisUtils = this.redisUtils; } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActActivityDAO.java
@@ -183,8 +183,8 @@ @Select("SELECT " + " count( caa.id ) as totalNum, " + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and volunteer_min = 0 and community_id = ${communityId}) as commonNum, " + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and volunteer_min > 0 and community_id = ${communityId}) as volunteerNum, " + " (select count(caas.user_id) from (select * from com_act_act_sign where `status` = 1) as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and is_volunteer = 0 and caa.community_id = ${communityId}) as commonPeopleNum, " + " (select count(caas.user_id) from (select * from com_act_act_sign where `status` = 1) as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and is_volunteer = 1 and caa.community_id = ${communityId}) as volunteerPeopleNum, " + " (select count(caas.user_id) from (select * from com_act_act_sign where `status` = 1) as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and caas.sign_identity != 3 and caa.community_id = ${communityId}) as commonPeopleNum, " + " (select count(caas.user_id) from (select * from com_act_act_sign where `status` = 1) as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and caas.sign_identity = 3 and caa.community_id = ${communityId}) as volunteerPeopleNum, " + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and community_id = ${communityId} and create_at between date_sub(curdate() - day(curdate()) +1,interval 1 month) and now()) as currentNum " + "FROM " + " com_act_activity AS caa " + "WHERE " + " caa.`status` IN (1,2,3,4,5) and community_id = ${communityId}") springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActNeighborCircleDAO.java
@@ -87,7 +87,7 @@ + "UNION ALL " + "SELECT COUNT(id) as num,'一起议' as name FROM com_act_discuss WHERE community_id = ${communityId} " + "UNION ALL " + "SELECT COUNT(id) as num,'邻里圈' as name FROM com_act_neighbor_circle WHERE community_id = ${communityId} AND STATUS = 2 and belong_type = 1" + "SELECT COUNT(id) as num,'邻里圈' as name FROM com_act_neighbor_circle WHERE community_id = ${communityId} AND STATUS = 2 and belong_type = 1 " + "UNION ALL " + "SELECT COUNT( e.id ) AS num,'网格事件' AS name FROM `event` as e left join event_grid_data as egd on egd.id = e.grid_id WHERE egd.grid_community_id = ${communityId} AND e.event_process_status = 2 " + "UNION ALL " @@ -100,7 +100,7 @@ + "UNION ALL " + "SELECT COUNT(id) as num,'一起议' as name FROM com_act_discuss WHERE community_id = ${communityId} " + "UNION ALL " + "SELECT COUNT(id) as num,'邻里圈' as name FROM com_act_neighbor_circle WHERE community_id = ${communityId} AND STATUS = 1 and belong_type = 1" + "SELECT COUNT(id) as num,'邻里圈' as name FROM com_act_neighbor_circle WHERE community_id = ${communityId} AND STATUS = 1 and belong_type = 1 " + "UNION ALL " + "SELECT COUNT( e.id ) AS num,'网格事件' AS NAME FROM `event` as e left join event_grid_data as egd on egd.id = e.grid_id WHERE egd.grid_community_id = ${communityId} AND e.event_status = 2 and e.event_deal_status in (1,2,3) " + "UNION ALL " springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/AcidMessage.java
@@ -117,18 +117,13 @@ try{ List<String> openIds=sysUserDao.selectOpenId(); String appId = "wx118de8a734d269f0"; String appSecret = "0264342daefde5cd70a6adada09ee5b1"; WxXCXTempSend wxXCXTempSend=new WxXCXTempSend(); // wxXCXTempSend.setAppAccessTokenToCache(appId,appSecret); for (int i = 0; i < openIds.size(); i++) { try { WxUtil.sendLongTimeTemplate(openIds.get(i),wxXCXTempSend.getAccessTokenValid(appId,i),"疫情快讯",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(); } } for(String openId:openIds){ } }catch (Exception e){ e.printStackTrace(); springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/dao/UserDao.java
@@ -201,32 +201,37 @@ /** * 根据手机号查询社区团队表中用户数量 * * @param phone 手机号 * @return 用户数量 * @return 用户数量 */ Integer getCommunityTeamCount(@Param("phone") String phone); /** * 查询西区所有街道列表以及统计人数 * @return 西区所有街道列表以及统计人数 * * @return 西区所有街道列表以及统计人数 */ List<IndexUserStreetVo> getUserStreetList(@Param("areaCode") String areaCode); /** * 查询街道下社区列表以及统计人数 * @param streetId 街道id * @return 社区列表以及统计人数 * * @param streetId 街道id * @return 社区列表以及统计人数 */ List<IndexUserCommunityVo> getUserCommunityList(@Param("streetId") Long streetId); /** * 查询街道下社区注册人数统计数据导出 * @return 社区注册人数统计数据导出 * * @return 社区注册人数统计数据导出 */ List<IndexUserStreetExcelExportVo> getUserCommunityExcelExport(String areaCode); /** * 查看是否是社区物业人员 * * @param userId * @param userCommunityId * @return @@ -235,6 +240,7 @@ /** * 查看是否社工 * * @param phone * @param communityId * @return @@ -243,6 +249,7 @@ /** * 查看是否社会组织 * * @param userId * @return */ @@ -251,6 +258,7 @@ /** * 查看是否是微团队成员 * * @param phone * @param userCommunityId * @return @@ -259,6 +267,7 @@ /** * 查询街道信息 * * @param streetId * @return */ @@ -266,6 +275,7 @@ /** * 查询是否是社会组织成员 * * @param userId * @return */ @@ -273,6 +283,7 @@ /** * 查询是否社会组织联系人 * * @param phone * @return */ @@ -280,13 +291,16 @@ /** * 查询是否人大代表 * * @param phone * @param userCommunityId * @return */ int selectCountDpc(@Param("phone") String phone, @Param("userCommunityId") Long userCommunityId); /** * 查看是否网格员 * * @param phone * @param userCommunityId * @return @@ -295,6 +309,7 @@ /** * 查询防疫工作人员信息 * * @param phone * @return */ @@ -302,6 +317,7 @@ /** * 查询单位管理员 * * @param phone * @return */ @@ -309,6 +325,7 @@ /** * 查询报道单位id * * @param phone * @return */ @@ -316,6 +333,7 @@ /** * 根据社区名称查询区县社区联动关系 * * @param relationName * @return */ @@ -323,6 +341,7 @@ /** * 根据街道id查询区域名称 * * @param streetId * @return */ @@ -330,28 +349,28 @@ /** * 看板用户统计:用户占比统计 * */ List<UserProportion> userAnalysis(@Param("type") Integer type,@Param("range") String range,@Param("streetId") Long streetId,@Param("areaCode")Long areaCode,@Param("appId")String appId); */ List<UserProportion> userAnalysis(@Param("type") Integer type, @Param("range") String range, @Param("streetId") Long streetId, @Param("areaCode") Long areaCode, @Param("appId") String appId); /** * 统计区域实名用户数 * */ List<RealUser> realUserCount(@Param("type") Integer type,@Param("range") String range,@Param("streetId") Long streetId,@Param("areaCode")Long areaCode,@Param("appId")String appId); */ List<RealUser> realUserCount(@Param("type") Integer type, @Param("range") String range, @Param("streetId") Long streetId, @Param("areaCode") Long areaCode, @Param("appId") String appId); /** * 统计该街道内的所有用户数 * */ Integer streetUserCount(@Param("id") Long id,@Param("areaCode")Long areaCode); */ Integer streetUserCount(@Param("id") Long id, @Param("areaCode") Long areaCode); /** * 街道用户统计 * */ IndexDataKanbanVO dataKanBanStreet(@Param("streetId") Long streetId,@Param("areaCode") Long areaCode,@Param("range") String range); */ IndexDataKanbanVO dataKanBanStreet(@Param("streetId") Long streetId, @Param("areaCode") Long areaCode, @Param("range") String range); /** * 获取当天的新增和日活 * */ Map<String,Long> getDailyAddAndActive(@Param("date") Date date, @Param("id") Long streetId, @Param("areaCode") Long areaCode, @Param("appId") String appId); */ Map<String, Long> getDailyAddAndActive(@Param("date") Date date, @Param("id") Long streetId, @Param("areaCode") Long areaCode, @Param("appId") String appId); List<UsersStatisticsDTO> getDailyAdd(@Param("createAt") String createAt, @Param("id") Long streetId, @Param("areaCode") Long areaCode, @Param("appId") String appId); @@ -370,17 +389,17 @@ /** * 获取本月的 * */ Integer getMonthUsers(@Param("streetId") Long streetId,@Param("areaCode") Long areaCode,@Param("range") String range,@Param("appId")String appId); */ Integer getMonthUsers(@Param("streetId") Long streetId, @Param("areaCode") Long areaCode, @Param("range") String range, @Param("appId") String appId); /** * 获取街道下属村/社区 * */ List<CommunityVO> selectCommunityByStreetId(@Param("id") Long streetId,@Param("type") Integer type); */ List<CommunityVO> selectCommunityByStreetId(@Param("id") Long streetId, @Param("type") Integer type); /** * 获取账户id * */ */ List<Integer> selectIdsByAccount(@Param("array") String[] streetList); List<CommunityVO> selectCommunityByStreetName(String name); @@ -389,21 +408,28 @@ /** * 是否为专家 * */ */ ComSanshuoExpertVO isExpert(String phone); /** * 当前账号是否为专家后台账号 * */ */ int isIndustryCenterAccount(String account); /** * 当前账号是否为专家后台账号 * */ */ int isExpertAccount(String account); /** * 是否为党员 * */ int isDpcMember(@Param("phone") String phone,@Param("name")String name); /** * 查询两个appid的用户做更新 * @param userId * @return */ List<SysUserDO> selectByUserId(@Param("userId") Long userId); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -3300,16 +3300,19 @@ @Override public R updateUserPartyStatus(Long userId) { SysUserDO sysUserDO = userDao.selectById(userId); if (sysUserDO != null) { sysUserDO.setIsPartymember(1); int updated = userDao.updateById(sysUserDO); if (updated > 0) { // 删除用户信息缓存 String userKey = UserConstants.LOGIN_USER_INFO + sysUserDO.getUserId(); stringRedisTemplate.delete(userKey); List<SysUserDO> sysUserDOs = userDao.selectByUserId(userId); for (SysUserDO sysUserDO : sysUserDOs) { if (sysUserDO != null) { sysUserDO.setIsPartymember(1); int updated = userDao.updateById(sysUserDO); if (updated > 0) { // 删除用户信息缓存 String userKey = UserConstants.LOGIN_USER_INFO + sysUserDO.getUserId(); stringRedisTemplate.delete(userKey); } } } return R.ok(); } @@ -3630,7 +3633,7 @@ String accessToken = ""; WxXCXTempSend util = new WxXCXTempSend(); try { accessToken = util.getAccessToken(); accessToken = util.getAccessToken("wx118de8a734d269f0"); } catch (Exception e) { e.printStackTrace(); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/resources/mapper/SysUserDOMapper.xml
@@ -105,5 +105,8 @@ ORDER BY u.user_id DESC </select> <select id="selectByUserId" resultMap="BaseResultMap"> SELECT u1.* FROM sys_user u1 WHERE u1.phone = (SELECT phone FROM sys_user u2 WHERE u2.user_id=#{userId}) AND u1.app_id in ('wx118de8a734d269f0','wx0cef797390444b75') </select> </mapper>