Commit ece9c568 by 郑勇

feat: [1006639] 活动报名慢sql

parent c2bbd899
......@@ -88,6 +88,7 @@ import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.vo.GroupQrcodeVO;
import com.pcloud.book.util.common.CommonUtils;
import com.pcloud.channelcenter.base.constants.ChannelConstants;
import com.pcloud.channelcenter.qrcode.service.QrcodeSceneService;
import com.pcloud.common.constant.UrlConstant;
import com.pcloud.common.core.aspect.ParamLog;
......@@ -142,6 +143,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import static com.pcloud.book.util.common.ThreadPoolUtils.SEND_MESSAGE_THREAD_POOL;
/**
......@@ -2151,17 +2155,27 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
public List<AdvertisingSpaceDTO> get4Wechat(Long sceneId, Long adviserId, Long channelId, String adPositionDetail, Long bookGroupId) throws BizException {
Long agentId;
Long bookId;
Long aId;
if (null != bookGroupId) {
BookGroupDTO bookGroupDTO = bookGroupDao.getDTOById(bookGroupId);
if (null == bookGroupDTO || null == bookGroupDTO.getBookId()) {
return new ArrayList<>();
}
bookId = bookGroupDTO.getBookId();
agentId = adviserConsr.getAgentIdByAdviser(bookGroupDTO.getCreateUser());
aId=bookGroupDTO.getCreateUser();
} else {
agentId = adviserConsr.getAgentIdByAdviser(adviserId);
aId=adviserId;
bookId = ResponseHandleUtil.parseResponse(qrcodeSceneService.getBookId4SceneId(sceneId), Long.class);
}
String adviserAgentKey= ChannelConstants.ADVISER_AGENT+aId;
if(null==JedisClusterUtils.get(adviserAgentKey)){
agentId = adviserConsr.getAgentIdByAdviser(aId);
if(null!=agentId) {
JedisClusterUtils.setJson(adviserAgentKey, agentId.toString(), 3600);
}
}else{
agentId=JedisClusterUtils.getJson(adviserAgentKey,Long.class);
}
if (null == agentId || null == bookId) {
return new ArrayList<>();
}
......@@ -2180,13 +2194,22 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
return new ArrayList<>();
}
if (!ListUtils.isEmpty(list)) {
list.forEach(spaceDTO -> spaceDTO.setBookId(bookId));
List<Long> masterIds = list.stream().map(a -> a.getMasterId()).distinct().collect(Collectors.toList());
List<Long> adIds = list.stream().map(a -> a.getId()).distinct().collect(Collectors.toList());
List<AdvertisingSettlementMethodDTO> listDto =advertisingSettlementMethodDao.getByMasterIdsAndAdIds(masterIds,adIds);
Map<String, String> methodMap = CollUtil.isEmpty(listDto) ? new HashMap<>() :
listDto.stream().collect(Collectors.toMap(a -> a.getMasterId() + "-" + a.getAdId(), a -> a.getSettlementMethod(), (v1, v2) -> v2));
for (AdvertisingSpaceDTO spaceDTO : list) {
spaceDTO.setBookId(bookId);
//填充结算方式
AdvertisingSettlementMethodDTO methodDTO = advertisingSettlementMethodDao.getByMasterIdAndAdId(spaceDTO.getMasterId(), spaceDTO.getId());
String key = spaceDTO.getMasterId() + "-"+spaceDTO.getId();
if(CollUtil.isNotEmpty(methodMap) && methodMap.containsKey(key)){
spaceDTO.setSettlementMethod(methodMap.get(key));
}
/* AdvertisingSettlementMethodDTO methodDTO = advertisingSettlementMethodDao.getByMasterIdAndAdId(spaceDTO.getMasterId(), spaceDTO.getId());
if (null != methodDTO) {
spaceDTO.setSettlementMethod(methodDTO.getSettlementMethod());
}
}*/
}
}
return list;
......
......@@ -32,4 +32,6 @@ public interface AdvertisingSettlementMethodDao extends BaseDao<AdvertisingSettl
* @return
*/
AdvertisingSettlementMethodDTO getByMasterIdAndAdId(Long masterId, Long adId);
List<AdvertisingSettlementMethodDTO> getByMasterIdsAndAdIds(List<Long> masterIds, List<Long> adIds);
}
......@@ -42,4 +42,12 @@ public class AdvertisingSettlementMethodDaoImpl extends BaseDaoImpl<AdvertisingS
paramMap.put("adId", adId);
return super.getSqlSession().selectOne(getStatement("getByMasterIdAndAdId"), paramMap);
}
@Override
public List<AdvertisingSettlementMethodDTO> getByMasterIdsAndAdIds(List<Long> masterIds, List<Long> adIds) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("masterIds", masterIds);
paramMap.put("adIds", adIds);
return super.getSqlSession().selectList(getStatement("getByMasterIdsAndAdIds"), paramMap);
}
}
......@@ -37,6 +37,8 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
/**
* @描述:商品中间件
* @作者:songx
......@@ -462,4 +464,20 @@ public class ProductConsr {
LOGGER.error("【资源中心(消)】调用失败[setOffShelvesProductOnShelves]:" + e.getMessage(), e);
}
}
public Map<String, String> getProTypeCodeByIds(List<Long> productIds) {
Map<String, String> result = new HashMap<>();
if(CollUtil.isEmpty(productIds)){
return result;
}
try {
result=ResponseHandleUtil.parseMap(productService.getProTypeCodeByIds(productIds), String.class, String.class);
} catch (BizException e) {
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
LOGGER.error("获取商品id集合对应商品类型失败[productService.getProTypeCodeByIds]:" + e.getMessage(), e);
throw new ChannelBizException(ChannelBizException.INVOKE_RES_ERROR, "获取商品类型失败~!");
}
return result;
}
}
......@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* @author lily
......@@ -97,11 +98,11 @@ public class BookAuthServeBizImpl implements BookAuthServeBiz {
}
// TAPD:1005196 目前只支持视频、题库等作品
List<String> openAuthPayProductTypeCodeList = CollUtil.toList("VIDEO", "PRETEST");
Map<Long, ProductDto> productMap = productConsr.getProBasesByIds(productIds);
Map<String, String> productMap = productConsr.getProTypeCodeByIds(productIds);
if(CollUtil.isNotEmpty(productMap)){
for (ProductDto productDto : productMap.values()) {
if(productDto.getProductTypeDto() != null && openAuthPayProductTypeCodeList.contains(productDto.getProductTypeDto().getTypeCode())){
isSetServesMap.put("PRODUCT" + productDto.getProductId(), true);
for (Entry<String, String> entry : productMap.entrySet()) {
if(openAuthPayProductTypeCodeList.contains(entry.getValue())){
isSetServesMap.put("PRODUCT" + entry.getKey(), true);
}
}
}
......
......@@ -30,9 +30,12 @@ import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.cookie.Cookie;
import com.pcloud.readercenter.wechat.entity.WechatUser;
import com.pcloud.resourcecenter.base.constants.ResourceRedisCons;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
......@@ -188,12 +191,19 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
@Override
public Boolean checkIsHaveAuthWithServer(String userInfo, Long serverId, String serverType) {
// 如果包含超级作者资源, 则直接返回
long t1 = System.currentTimeMillis();
if(checkIsSuperProduct(serverId)){
long t2 = System.currentTimeMillis();
System.out.println("第0阶段耗时=" + (t2 - t1));
return false;
}
long t2 = System.currentTimeMillis();
System.out.println("第1阶段耗时=" + (t2 - t1));
// 否则查询授权关系
Long bookId = qrcodeSceneConsr.getBookId4SceneId(Cookie.getId(userInfo,Cookie._SCENE_ID));
long t3 = System.currentTimeMillis();
System.out.println("第2阶段耗时=" + (t3 - t2));
Long channelId = Cookie.getId(userInfo, Cookie._CHANNEL_ID);
Long adviserId = Cookie.getId(userInfo,Cookie._ADVISER_ID);
Long wecharUserId = Cookie.getId(userInfo,Cookie._WECHAT_USER_ID);
......@@ -210,8 +220,12 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
}
}
else{
return checkIsHaveAuthWithServer(bookId,channelId,adviserId,wecharUserId,serverId);
Boolean aBoolean = checkIsHaveAuthWithServer(bookId, channelId, adviserId, wecharUserId, serverId);
long t4 = System.currentTimeMillis();
System.out.println("第3阶段耗时=" + (t4 - t3));
return aBoolean;
}
}
private Boolean checkIsHaveAuthWithServer(Long bookId, Long channelId, Long adviserId, Long wecharUserId, Long serverId) {
......@@ -240,11 +254,20 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
// 判断是否为超级作者的商品
private Boolean checkIsSuperProduct(Long serverId) {
String isSuper = null;
try {
isSuper = JedisClusterUtils.hget(ResourceRedisCons.IS_SUPER_MERCHANT_PRODUCT, serverId.toString());
} catch (Exception e) {
LOGGER.warn("从redis获取是否为超级作者的商品失败");
}
if(null==isSuper) {
Map<Long, Boolean> map = productConsr.getIsSuperByProductIdList(Lists.newArrayList(serverId));
if (map != null && map.containsKey(serverId)) {
return map.get(serverId);
}
}else{
return Boolean.valueOf(isSuper);
}
return false;
}
......
......@@ -122,4 +122,28 @@
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<select id="getByMasterIdsAndAdIds" parameterType="map" resultMap="AdvertisingSettlementMethodDTO">
select master_id, ad_id, settlement_method
from
(select
master_id, ad_id, settlement_method
from advertising_settlement_method
where
1=1
<if test="masterIds != null and masterIds.size()>0">
and master_id in
<foreach collection="masterIds" open="(" close=")" separator="," index="index" item="item">
#{item}
</foreach>
</if>
<if test="adIds != null and adIds.size()>0">
and ad_id in
<foreach collection="adIds" open="(" close=")" separator="," index="index" item="item">
#{item}
</foreach>
</if>
order by create_time desc
)t GROUP BY master_id,ad_id
</select>
</mapper>
\ No newline at end of file
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