Commit f0bce7f4 by xiongjiangtao

Merge remote-tracking branch 'origin/feature-chat-activity' into feature-chat-activity

parents 25b522e2 6fd5a0c7
package com.gic.haoban.manage.api.qdto.combined;
import java.io.Serializable;
public class CombinedQDTO implements Serializable {
private static final long serialVersionUID = -28454620622119889L;
/**
* 主图url
*/
private String imageUrl;
/**
* 小程序码url
*/
private String qrCodeUrl;
/**
* 展示样式
*/
private Integer showStyle;
/**
* 第一行文字
*/
private String lineOne;
/**
* 第二行文字
*/
private String lineTwo;
/**
* 1群发 2朋友圈
*/
private Integer mediaType;
/**
* 导购id(作标识)
*/
private String clerkId;
/**
* 业务id(作标识)
*/
private String businessId;
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getQrCodeUrl() {
return qrCodeUrl;
}
public void setQrCodeUrl(String qrCodeUrl) {
this.qrCodeUrl = qrCodeUrl;
}
public Integer getShowStyle() {
return showStyle;
}
public void setShowStyle(Integer showStyle) {
this.showStyle = showStyle;
}
public String getLineOne() {
return lineOne;
}
public void setLineOne(String lineOne) {
this.lineOne = lineOne;
}
public String getLineTwo() {
return lineTwo;
}
public void setLineTwo(String lineTwo) {
this.lineTwo = lineTwo;
}
public Integer getMediaType() {
return mediaType;
}
public void setMediaType(Integer mediaType) {
this.mediaType = mediaType;
}
public String getUnionString() {
return this.getImageUrl() + this.getQrCodeUrl() + this.getShowStyle() + this.getLineOne() + this.getLineTwo() + this.getMediaType();
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getBusinessId() {
return businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
}
...@@ -7,6 +7,7 @@ import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO; ...@@ -7,6 +7,7 @@ import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO; import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import java.util.List; import java.util.List;
...@@ -85,4 +86,6 @@ public interface MaterialApiService { ...@@ -85,4 +86,6 @@ public interface MaterialApiService {
com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByUrl(String wxEnterpriseId, ContentMaterialDTO dto) ; com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByUrl(String wxEnterpriseId, ContentMaterialDTO dto) ;
com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO);
} }
...@@ -229,6 +229,18 @@ ...@@ -229,6 +229,18 @@
<artifactId>gic-member-ext-api</artifactId> <artifactId>gic-member-ext-api</artifactId>
<version>${gic-member-ext-api}</version> <version>${gic-member-ext-api}</version>
</dependency> </dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -189,6 +189,9 @@ public class JoinRuleManager { ...@@ -189,6 +189,9 @@ public class JoinRuleManager {
FunctionWithException<GroupChatActivityHmQDTO, List<GroupChatHmBO>> handler = ruleHandlers.get(ruleEnum); FunctionWithException<GroupChatActivityHmQDTO, List<GroupChatHmBO>> handler = ruleHandlers.get(ruleEnum);
if (handler != null) { if (handler != null) {
List<GroupChatHmBO> apply = handler.apply(activityHmQDTO); List<GroupChatHmBO> apply = handler.apply(activityHmQDTO);
if (apply == null) {
apply = new ArrayList<>();
}
logger.info("规则:{},获取活码数:{}", ruleEnum.desc, apply.size()); logger.info("规则:{},获取活码数:{}", ruleEnum.desc, apply.size());
return apply; return apply;
} }
......
package com.gic.haoban.manage.service.pojo.bo.chat; package com.gic.haoban.manage.service.pojo.bo.chat;
import com.gic.haoban.manage.api.dto.chat.GroupChatActivityDTO; import java.util.Date;
import com.gic.haoban.manage.service.entity.chat.TabGroupChatUser;
/** /**
* Created by wangzubo on 2024/10/9. * Created by wangzubo on 2024/10/9.
...@@ -33,6 +32,11 @@ public class GroupChatActivityBaseContext { ...@@ -33,6 +32,11 @@ public class GroupChatActivityBaseContext {
*/ */
private String uniqueId; private String uniqueId;
/**
* 最后一次访问邀请页时间
*/
private Date lastShareTime;
public Long getChatUserId() { public Long getChatUserId() {
return chatUserId; return chatUserId;
} }
...@@ -72,4 +76,12 @@ public class GroupChatActivityBaseContext { ...@@ -72,4 +76,12 @@ public class GroupChatActivityBaseContext {
public void setUniqueId(String uniqueId) { public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId; this.uniqueId = uniqueId;
} }
public Date getLastShareTime() {
return lastShareTime;
}
public void setLastShareTime(Date lastShareTime) {
this.lastShareTime = lastShareTime;
}
} }
...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service; ...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service;
import com.gic.api.base.commons.JSONResponse; import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO; import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import java.util.List; import java.util.List;
...@@ -59,4 +60,7 @@ public interface MaterialService { ...@@ -59,4 +60,7 @@ public interface MaterialService {
public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) ; public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) ;
List<MaterialDTO> listContentMaterialByIds(List<String> materialIds,Integer mediaType); List<MaterialDTO> listContentMaterialByIds(List<String> materialIds,Integer mediaType);
JSONResponse getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO);
} }
...@@ -110,7 +110,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -110,7 +110,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
return; return;
} }
List<String> unionIdList = chatUserList.stream().map(TabGroupChatUser::getUnionid).collect(Collectors.toList()); List<String> unionIdList = chatUserList.stream().map(TabGroupChatUser::getUnionid).collect(Collectors.toList());
List<List<String>> partition = Lists.partition(unionIdList, 1000); List<List<String>> partition = Lists.partition(unionIdList, 100);
for (List<String> unionIds : partition) { for (List<String> unionIds : partition) {
List<TabGroupChatActivityShareBind> shareBindList = groupChatActivityShareBindService.query24Record(unionIds); List<TabGroupChatActivityShareBind> shareBindList = groupChatActivityShareBindService.query24Record(unionIds);
if (CollectionUtils.isEmpty(shareBindList)) { if (CollectionUtils.isEmpty(shareBindList)) {
...@@ -120,6 +120,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -120,6 +120,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
Map<String, List<TabGroupChatActivityShareBind>> map = shareBindList.stream().collect(Collectors.groupingBy(TabGroupChatActivityShareBind::getInviteeUnionId)); Map<String, List<TabGroupChatActivityShareBind>> map = shareBindList.stream().collect(Collectors.groupingBy(TabGroupChatActivityShareBind::getInviteeUnionId));
for (TabGroupChatUser groupChatUser : chatUserList) { for (TabGroupChatUser groupChatUser : chatUserList) {
Long chatUserId = groupChatUser.getChatUserId(); Long chatUserId = groupChatUser.getChatUserId();
Date joinTime = groupChatUser.getJoinTime();
String unionid = groupChatUser.getUnionid(); String unionid = groupChatUser.getUnionid();
List<TabGroupChatActivityShareBind> list = map.get(unionid); List<TabGroupChatActivityShareBind> list = map.get(unionid);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
...@@ -128,6 +129,10 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -128,6 +129,10 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
Set<Long> chatActivityIdSet = new HashSet<>(); Set<Long> chatActivityIdSet = new HashSet<>();
//同个活动取最近一条绑定信息 //同个活动取最近一条绑定信息
for (TabGroupChatActivityShareBind shareBind : list) { for (TabGroupChatActivityShareBind shareBind : list) {
if (DateUtil.compare(shareBind.getCreateTime(),joinTime) >= 0) {
logger.info("分享绑定时间大于入群时间 过滤");
continue;
}
Long chatActivityId = shareBind.getChatActivityId(); Long chatActivityId = shareBind.getChatActivityId();
if (chatActivityIdSet.add(chatActivityId)) { if (chatActivityIdSet.add(chatActivityId)) {
GroupChatActivityBaseContext chatActivityContext = new GroupChatActivityBaseContext(); GroupChatActivityBaseContext chatActivityContext = new GroupChatActivityBaseContext();
...@@ -136,7 +141,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -136,7 +141,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
chatActivityContext.setInviterMemberId(shareBind.getInviterMemberId()); chatActivityContext.setInviterMemberId(shareBind.getInviterMemberId());
chatActivityContext.setEnterpriseId(shareBind.getEnterpriseId()); chatActivityContext.setEnterpriseId(shareBind.getEnterpriseId());
chatActivityContext.setUniqueId(shareBind.getInviteeUnionId()); chatActivityContext.setUniqueId(shareBind.getInviteeUnionId());
// todo 社群邀请-mq异步 chatActivityContext.setLastShareTime(shareBind.getCreateTime());
// groupChatInvite(chatActivityContext); // groupChatInvite(chatActivityContext);
try { try {
GICMQClientUtil.getClientInstance().sendMessage("shareGroupChatInviteMQ",JSON.toJSONString(chatActivityContext)); GICMQClientUtil.getClientInstance().sendMessage("shareGroupChatInviteMQ",JSON.toJSONString(chatActivityContext));
...@@ -179,7 +184,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -179,7 +184,7 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
Integer inviteType = Constant.FLAG_FALSE; Integer inviteType = Constant.FLAG_FALSE;
int batchNumber = -1; int batchNumber = -1;
Integer invalidInviteType = getActivityEffective(context); Integer invalidInviteType = getActivityEffective(context);
logger.info("获取本次入群有效状态:{}", invalidInviteType); logger.info("获取本次入群有效状态:{},{}", invalidInviteType,ChatActivityInvalidInviteTypeEnum.getDescByValue(invalidInviteType));
if (invalidInviteType == null) { if (invalidInviteType == null) {
inviteType = Constant.FLAG_TRUE; inviteType = Constant.FLAG_TRUE;
//获取奖励批次 //获取奖励批次
...@@ -249,6 +254,11 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -249,6 +254,11 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
return false; return false;
} }
} }
String memberId = chatUser.getMemberId();
if (Objects.equals(memberId, context.getInviterMemberId())) {
logger.info("无法邀请自己");
return false;
}
TabGroupChatActivityInviteLog inviteLog = new TabGroupChatActivityInviteLog(); TabGroupChatActivityInviteLog inviteLog = new TabGroupChatActivityInviteLog();
inviteLog.setChatActivityId(context.getChatActivityId()); inviteLog.setChatActivityId(context.getChatActivityId());
inviteLog.setInviteeUserId(chatUser.getUserId()); inviteLog.setInviteeUserId(chatUser.getUserId());
...@@ -271,8 +281,10 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -271,8 +281,10 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
private Integer getActivityEffective(GroupChatActivityContext context) { private Integer getActivityEffective(GroupChatActivityContext context) {
GroupChatActivityDTO activity = context.getChatActivityDTO(); GroupChatActivityDTO activity = context.getChatActivityDTO();
String enterpriseId = activity.getEnterpriseId(); String enterpriseId = activity.getEnterpriseId();
String userId = context.getChatUser().getUserId(); TabGroupChatUser chatUser = context.getChatUser();
String userId = chatUser.getUserId();
Long chatActivityId = context.getChatActivityId(); Long chatActivityId = context.getChatActivityId();
Date lastShareTime = context.getLastShareTime();
Integer inviteType = activity.getInviteType(); Integer inviteType = activity.getInviteType();
TabGroupChatActivityInviteLog inviteLog = new TabGroupChatActivityInviteLog(); TabGroupChatActivityInviteLog inviteLog = new TabGroupChatActivityInviteLog();
inviteLog.setChatActivityId(chatActivityId); inviteLog.setChatActivityId(chatActivityId);
...@@ -285,11 +297,17 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI ...@@ -285,11 +297,17 @@ public class GroupChatActivityInviteLogServiceImpl implements GroupChatActivityI
if (Objects.equals(ChatActivityInviteTypeEnum.NONE_GROUP_CHAT.value, inviteType)) { if (Objects.equals(ChatActivityInviteTypeEnum.NONE_GROUP_CHAT.value, inviteType)) {
List<TabGroupChatUser> chatUserList = groupChatUserMapper.listByUserId(enterpriseId, userId, 1); List<TabGroupChatUser> chatUserList = groupChatUserMapper.listByUserId(enterpriseId, userId, 1);
if (CollectionUtils.isNotEmpty(chatUserList)) { if (CollectionUtils.isNotEmpty(chatUserList)) {
return ChatActivityInvalidInviteTypeEnum.TWO.value; // 入群时间在访问分享页之前的才算无效入群
chatUserList = chatUserList.stream().filter(u -> DateUtil.compare(lastShareTime, u.getJoinTime()) >= 0).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(chatUserList)) {
return ChatActivityInvalidInviteTypeEnum.TWO.value;
}
} }
} }
if (Objects.equals(ChatActivityInviteTypeEnum.FIRST_GROUP_CHAT.value, inviteType)) { if (Objects.equals(ChatActivityInviteTypeEnum.FIRST_GROUP_CHAT.value, inviteType)) {
List<TabGroupChatUser> chatUserList2 = groupChatUserMapper.listByUserId(enterpriseId, userId, null); List<TabGroupChatUser> chatUserList2 = groupChatUserMapper.listByUserId(enterpriseId, userId, null);
// 入群时间在访问分享页之前的才算无效入群
chatUserList2 = chatUserList2.stream().filter(u -> DateUtil.compare(lastShareTime, u.getJoinTime()) >= 0).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(chatUserList2)) { if (CollectionUtils.isNotEmpty(chatUserList2)) {
return ChatActivityInvalidInviteTypeEnum.THREE.value; return ChatActivityInvalidInviteTypeEnum.THREE.value;
} }
......
...@@ -6,9 +6,10 @@ import java.util.*; ...@@ -6,9 +6,10 @@ import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.HttpClient; import com.gic.commons.util.HttpClient;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.redis.data.util.RedisUtil; import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
...@@ -345,4 +346,38 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -345,4 +346,38 @@ public class MaterialServiceImpl implements MaterialService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return materialDTOS; return materialDTOS;
} }
@Override
public JSONResponse getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO) {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
JSONResponse jsonResponse = new JSONResponse();
jsonResponse.setErrorCode(9999);
jsonResponse.setErrorMessage("获取媒体id失败");
try {
String[] arr = null ;
String imageUrl = combinedQDTO.getImageUrl();
//合成图片
byte[] combinedImageData = ImageCombined.getCombinedImage(combinedQDTO);
if (combinedImageData == null) {
logger.info("合成图片的数据为空");
return jsonResponse;
}
if(imageUrl.contains("?")) {
arr = imageUrl.split("\\?")[0].split("/") ;
}else {
arr = imageUrl.split("/");
}
JSONResponse json = null;
Integer mediaType = combinedQDTO.getMediaType();
if (Objects.equals(1,mediaType)) {
json = qywxSuiteApiService.uploadMedia(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), combinedImageData, arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode(), qwDTO.isSelf(), qwDTO.getUrlHost());
}else if (Objects.equals(2,mediaType)) {
json = qywxSuiteApiService.uploadAttachment(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), combinedImageData, arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode(), qwDTO.isSelf(), qwDTO.getUrlHost());
}
return json;
} catch (Exception e) {
logger.info("合成图片获取媒体id异常",e);
return jsonResponse;
}
}
} }
package com.gic.haoban.manage.service.service.out.impl; package com.gic.haoban.manage.service.service.out.impl;
import java.util.ArrayList; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.*;
import java.util.Collections; import java.util.concurrent.Callable;
import java.util.Date; import java.util.concurrent.Future;
import java.util.List; import java.util.concurrent.TimeUnit;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.collection.ListUtil; import com.gic.commons.util.TraceIdUtil;
import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.redis.data.util.RedisUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.bouncycastle.crypto.MacDerivationFunction;
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;
...@@ -41,7 +45,6 @@ import com.gic.haoban.manage.service.service.MaterialCategoryService; ...@@ -41,7 +45,6 @@ import com.gic.haoban.manage.service.service.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService; import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.MiniprogramSettingService; import com.gic.haoban.manage.service.service.MiniprogramSettingService;
import com.gic.haoban.manage.service.service.WxEnterpriseService; import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.util.CommonUtil;
import com.gic.wechat.api.enums.QywxMediaTypeEnum; import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService; import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
...@@ -516,4 +519,46 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -516,4 +519,46 @@ public class MaterialApiServiceImpl implements MaterialApiService {
String materialId = materialIdList.get(0) ; String materialId = materialIdList.get(0) ;
return com.gic.api.base.commons.ServiceResponse.success(materialId) ; return com.gic.api.base.commons.ServiceResponse.success(materialId) ;
} }
@Override
public com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO) {
if (StringUtils.isAnyBlank(combinedQDTO.getImageUrl(), combinedQDTO.getQrCodeUrl())) {
return com.gic.api.base.commons.ServiceResponse.failure("9999","参数异常") ;
}
logger.info("请求合成图片并上传企微:{}",JSON.toJSONString(combinedQDTO));
String unionString = combinedQDTO.getUnionString();
String key = ImageCombined.IMAGE_REDIS_KEY + wxEnterpriseId + ":" + UUID.nameUUIDFromBytes(unionString.getBytes(StandardCharsets.UTF_8));
String cache = (String)RedisUtil.getCache(key);
if (StringUtils.isNotBlank(cache)) {
return com.gic.api.base.commons.ServiceResponse.success(cache);
}
ProviderLocalTag localTag = ProviderLocalTag.tag.get();
String traceId = localTag.traceId;
Future<JSONResponse> future = null;
JSONResponse json = null;
try {
future = ImageCombined.EXECUTOR.submit(() -> {
TraceIdUtil.traceBegin(TraceIdUtil.EntranceType.THREAD_POOL);
logger.info("线程池合成图片clerkId:{},businessId:{},traceId:{}", combinedQDTO.getClerkId(), combinedQDTO.getBusinessId(), traceId);
JSONResponse jr = materialService.getMaterialIdByCombined(wxEnterpriseId, combinedQDTO);
TraceIdUtil.traceEnd();
return jr;
});
json = future.get();
if (json == null) {
return com.gic.api.base.commons.ServiceResponse.failure("9999", "获取图片失败,请稍后再试");
}
if (json.getErrorCode() == 0) {
String mediaId= json.getResult().toString() ;
logger.info("设置缓存key:{},value:{}", key, mediaId);
RedisUtil.setCache(key, mediaId, 1L, TimeUnit.DAYS);
return com.gic.api.base.commons.ServiceResponse.success(mediaId) ;
}else {
return com.gic.api.base.commons.ServiceResponse.failure("9999",json.getErrorMessage()) ;
}
} catch (Exception e) {
logger.info("获取素材id失败", e);
return com.gic.api.base.commons.ServiceResponse.failure("9999", "获取图片失败,请稍后再试");
}
}
} }
...@@ -56,9 +56,6 @@ public class GroupChatActivityShareApiServiceImpl implements GroupChatActivitySh ...@@ -56,9 +56,6 @@ public class GroupChatActivityShareApiServiceImpl implements GroupChatActivitySh
activityHmQDTO.getInviterMemberId()) || activityHmQDTO.getChatActivityId() == null) { activityHmQDTO.getInviterMemberId()) || activityHmQDTO.getChatActivityId() == null) {
return ServiceResponse.failure("500", "参数异常"); return ServiceResponse.failure("500", "参数异常");
} }
if (Objects.equals(activityHmQDTO.getInviterMemberId(), activityHmQDTO.getInviteeMemberId())) {
return ServiceResponse.failure("500", "无法邀请自己");
}
try { try {
List<GroupChatHmBO> hmBOList = groupChatActivityService.listGroupChatHm(activityHmQDTO); List<GroupChatHmBO> hmBOList = groupChatActivityService.listGroupChatHm(activityHmQDTO);
return ServiceResponse.success(EntityUtil.changeEntityListNew(GroupChatHmDTO.class,hmBOList)); return ServiceResponse.success(EntityUtil.changeEntityListNew(GroupChatHmDTO.class,hmBOList));
......
...@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.util; ...@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.util;
import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService; import com.ctrip.framework.apollo.ConfigService;
import java.util.Map;
public class ApolloUtils { public class ApolloUtils {
/** /**
...@@ -14,4 +16,24 @@ public class ApolloUtils { ...@@ -14,4 +16,24 @@ public class ApolloUtils {
String messageCenterSwitch = config.getProperty("messageCenterSwitch", "0"); String messageCenterSwitch = config.getProperty("messageCenterSwitch", "0");
return "1".equals(messageCenterSwitch); return "1".equals(messageCenterSwitch);
} }
/**
* 线程池核心线程数
* @return
*/
public static Integer combinedCorePoolSize() {
Config config = ConfigService.getAppConfig();
String corePoolSize = config.getProperty("combinedCorePoolSize", "20");
return Integer.parseInt(corePoolSize);
}
/**
* 线程池最大线程数
* @return
*/
public static Integer combinedMaximumPoolSize() {
Config config = ConfigService.getAppConfig();
String maximumPoolSize = config.getProperty("combinedMaximumPoolSize", "40");
return Integer.parseInt(maximumPoolSize);
}
} }
...@@ -216,6 +216,7 @@ ...@@ -216,6 +216,7 @@
and status_flag = #{statusFlag} and status_flag = #{statusFlag}
</if> </if>
and delete_flag = 0 and delete_flag = 0
order by join_time asc,chat_user_id asc
</select> </select>
<select id="listByExternalUseridForMatch" resultMap="result-map-tabHaobanGroupChatUser"> <select id="listByExternalUseridForMatch" resultMap="result-map-tabHaobanGroupChatUser">
......
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class QWmediaTest {
private static Logger logger = LoggerFactory.getLogger(QWmediaTest.class);
@Autowired
private QywxSuiteApiService qywxSuiteApiService ;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private MaterialService materialService;
private static final String LARGE_IMAGE_URL = "https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4582434f589b494aa4f27df6e3aa3770.png?imageView2/2/w/1080/h/10800/format/jpg";
private static final String QR_CODE_URL = "https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png";
private static final String STORE_NAME = "门店CCA";
private static final String GUIDE_NAME = "宇智222";
@Test
public void test() throws Exception{
CombinedQDTO combinedQDTO = new CombinedQDTO();
combinedQDTO.setImageUrl(LARGE_IMAGE_URL);
combinedQDTO.setQrCodeUrl(QR_CODE_URL);
combinedQDTO.setShowStyle(1);
combinedQDTO.setLineOne(STORE_NAME);
combinedQDTO.setLineTwo(GUIDE_NAME);
JSONResponse json = materialService.getMaterialIdByCombined("b18ffdc9d0644912865a248859914d80", combinedQDTO);
System.out.println(JSON.toJSONString(json));
}
public static void main(String[] args) {
int TOTAL_REQUESTS = 1800; // 总请求数
List<String> list = FileUtil.readLines("/Users/wang/Downloads/image.txt", "UTF-8");
List<String> qrList = FileUtil.readLines("/Users/wang/Downloads/qrcode.txt", "UTF-8");
ExecutorService executorService = Executors.newFixedThreadPool(30); // 创建线程池
Semaphore semaphore = new Semaphore(30); // 限制并发请求数为30
// 用于统计请求耗时
AtomicLong totalTime = new AtomicLong(0);
AtomicLong maxTime = new AtomicLong(0);
AtomicLong minTime = new AtomicLong(Long.MAX_VALUE);
for (int i = 0; i < TOTAL_REQUESTS; i++) {
final int imageId = i % 9;
final int qrId = i / 9;
executorService.submit(() -> {
long startTime = System.currentTimeMillis();
try {
semaphore.acquire(); // 获取许可,控制并发请求
JSONObject jo = new JSONObject();
jo.put("wxEnterpriseId", "b18ffdc9d0644912865a248859914d80");
jo.put("qrCodeUrl", "https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png");
jo.put("showStyle", "0");
jo.put("lineOne", "门店CCA");
jo.put("lineTwo", "宇智222为您推荐");
jo.put("mediaType", 1);
jo.put("imageUrl", list.get(imageId));
jo.put("qrCodeUrl", qrList.get(qrId));
HttpResponse execute = HttpRequest.post("https://www.gicdev.com/haoban-manage3-wx/combined-qw-materialid.json").timeout(-1).body(jo.toJSONString()).execute();
String body = execute.body();
String headerValue = execute.header("x-request-id");
// String post = HttpUtil.post("https://www.gicdev.com/haoban-manage3-wx/combined-qw-materialid.json", jo.toJSONString());
System.out.println(body);
System.out.println(headerValue);
} catch (Exception e) {
System.out.println("异常: " + e.getMessage());
} finally {
long duration = System.currentTimeMillis() - startTime;
System.out.println(duration);
totalTime.addAndGet(duration);
maxTime.updateAndGet(x -> Math.max(x, duration));
minTime.updateAndGet(x -> Math.min(x, duration));
semaphore.release(); // 释放许可
}
});
}
executorService.shutdown(); // 关闭线程池
// 打印统计信息
try {
if (!executorService.awaitTermination(1, TimeUnit.MINUTES)) {
executorService.shutdownNow(); // 强制关闭
}
} catch (InterruptedException e) {
executorService.shutdownNow();
}
long averageTime = totalTime.get() / TOTAL_REQUESTS;
System.out.println("完成所有请求");
System.out.println("平均耗时: " + averageTime + " ms");
System.out.println("最大耗时: " + maxTime.get() + " ms");
System.out.println("最小耗时: " + (minTime.get() == Long.MAX_VALUE ? 0 : minTime.get()) + " ms");
}
}
...@@ -5,6 +5,7 @@ import com.gic.commons.util.EntityUtil; ...@@ -5,6 +5,7 @@ import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse; import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.content.api.dto.setting.ContentSettingDTO; import com.gic.content.api.dto.setting.ContentSettingDTO;
import com.gic.content.api.service.ContentSettingApiService; import com.gic.content.api.service.ContentSettingApiService;
import com.gic.haoban.manage.web.utils.ApolloUtils;
import com.gic.haoban.manage.web.vo.content.ContentSettingVO; import com.gic.haoban.manage.web.vo.content.ContentSettingVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -39,6 +40,7 @@ public class ContentSettingController { ...@@ -39,6 +40,7 @@ public class ContentSettingController {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage()); return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
} }
ContentSettingVO contentSettingVO = EntityUtil.changeEntityByJSON(ContentSettingVO.class, serviceResponse.getResult()); ContentSettingVO contentSettingVO = EntityUtil.changeEntityByJSON(ContentSettingVO.class, serviceResponse.getResult());
contentSettingVO.setCombinedType(ApolloUtils.combinedType(enterpriseId));
return RestResponse.successResult(contentSettingVO); return RestResponse.successResult(contentSettingVO);
} }
} }
...@@ -3,11 +3,15 @@ package com.gic.haoban.manage.web.controller.content; ...@@ -3,11 +3,15 @@ package com.gic.haoban.manage.web.controller.content;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.web.qo.combined.CombinedQO;
import com.gic.haoban.manage.web.qo.combined.CombinedsQO;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -171,4 +175,16 @@ public class QwMessageController extends WebBaseController { ...@@ -171,4 +175,16 @@ public class QwMessageController extends WebBaseController {
} }
return RestResponse.failure("-1", resp.getMessage()) ; return RestResponse.failure("-1", resp.getMessage()) ;
} }
@RequestMapping("combined-qw-materialid")
public RestResponse<Object> combinedMaterialId(@RequestBody CombinedQO combinedQO) {
String wxEnterpriseId = combinedQO.getWxEnterpriseId();
CombinedQDTO combinedQDTO = com.gic.commons.util.EntityUtil.changeEntityNew(CombinedQDTO.class, combinedQO);
ServiceResponse<String> resp = this.materialApiService.getMaterialIdByCombined(wxEnterpriseId, combinedQDTO) ;
if(resp.isSuccess()) {
return RestResponse.successResult(resp.getResult()) ;
}
return RestResponse.failure("-1", resp.getMessage()) ;
}
} }
package com.gic.haoban.manage.web.qo.combined;
import java.io.Serializable;
public class CombinedQO implements Serializable {
private static final long serialVersionUID = -28454620622119889L;
private String wxEnterpriseId;
/**
* 主图url
*/
private String imageUrl;
/**
* 小程序码url
*/
private String qrCodeUrl;
/**
* 展示样式
*/
private Integer showStyle;
/**
* 第一行文字
*/
private String lineOne;
/**
* 第二行文字
*/
private String lineTwo;
/**
* 1群发 2朋友圈
*/
private Integer mediaType ;
/**
* 导购id(作标识)
*/
private String clerkId;
/**
* 业务id(作标识)
*/
private String businessId;
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getQrCodeUrl() {
return qrCodeUrl;
}
public void setQrCodeUrl(String qrCodeUrl) {
this.qrCodeUrl = qrCodeUrl;
}
public Integer getShowStyle() {
return showStyle;
}
public void setShowStyle(Integer showStyle) {
this.showStyle = showStyle;
}
public String getLineOne() {
return lineOne;
}
public void setLineOne(String lineOne) {
this.lineOne = lineOne;
}
public String getLineTwo() {
return lineTwo;
}
public void setLineTwo(String lineTwo) {
this.lineTwo = lineTwo;
}
public Integer getMediaType() {
return mediaType;
}
public void setMediaType(Integer mediaType) {
this.mediaType = mediaType;
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getBusinessId() {
return businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
}
package com.gic.haoban.manage.web.qo.combined;
import java.io.Serializable;
import java.util.List;
public class CombinedsQO implements Serializable {
private static final long serialVersionUID = -28454620622119889L;
private String wxEnterpriseId;
/**
* 主图url
*/
private List<String> imageUrlList;
/**
* 小程序码url
*/
private String qrCodeUrl;
/**
* 展示样式
*/
private Integer showStyle;
/**
* 第一行文字
*/
private String lineOne;
/**
* 第二行文字
*/
private String lineTwo;
/**
* 1群发 2朋友圈
*/
private Integer mediaType ;
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public List<String> getImageUrlList() {
return imageUrlList;
}
public void setImageUrlList(List<String> imageUrlList) {
this.imageUrlList = imageUrlList;
}
public String getQrCodeUrl() {
return qrCodeUrl;
}
public void setQrCodeUrl(String qrCodeUrl) {
this.qrCodeUrl = qrCodeUrl;
}
public Integer getShowStyle() {
return showStyle;
}
public void setShowStyle(Integer showStyle) {
this.showStyle = showStyle;
}
public String getLineOne() {
return lineOne;
}
public void setLineOne(String lineOne) {
this.lineOne = lineOne;
}
public String getLineTwo() {
return lineTwo;
}
public void setLineTwo(String lineTwo) {
this.lineTwo = lineTwo;
}
public Integer getMediaType() {
return mediaType;
}
public void setMediaType(Integer mediaType) {
this.mediaType = mediaType;
}
}
package com.gic.haoban.manage.web.utils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.gic.api.base.commons.Constant;
import org.apache.commons.lang3.StringUtils;
public class ApolloUtils {
/**
* 内容分享企微素材使用老的前端合成还是新的后端合成 0老1新
* @return
*/
public static Integer combinedType(String eid) {
Config config = ConfigService.getAppConfig();
String combinedEid = config.getProperty("combinedEid", "");
if (StringUtils.isBlank(combinedEid)) {
return Constant.FLAG_TRUE;
}
return combinedEid.contains(eid) ? Constant.FLAG_TRUE : Constant.FLAG_FALSE;
}
}
...@@ -75,6 +75,11 @@ public class ContentSettingVO implements Serializable { ...@@ -75,6 +75,11 @@ public class ContentSettingVO implements Serializable {
*/ */
private Integer showStyle; private Integer showStyle;
/**
* 0老模式1新模式
*/
private Integer combinedType;
public Long getContentSettingId() { public Long getContentSettingId() {
return contentSettingId; return contentSettingId;
} }
...@@ -170,4 +175,12 @@ public class ContentSettingVO implements Serializable { ...@@ -170,4 +175,12 @@ public class ContentSettingVO implements Serializable {
public void setShowStyle(Integer showStyle) { public void setShowStyle(Integer showStyle) {
this.showStyle = showStyle; this.showStyle = showStyle;
} }
public Integer getCombinedType() {
return combinedType;
}
public void setCombinedType(Integer combinedType) {
this.combinedType = combinedType;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment