|
|
|
|
@ -0,0 +1,259 @@
|
|
|
|
|
package com.flossom.miniProgram.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.flossom.common.core.domain.entity.SiteInfo;
|
|
|
|
|
import com.flossom.common.core.domain.entity.SiteLog;
|
|
|
|
|
import com.flossom.common.core.domain.entity.WxUserMember;
|
|
|
|
|
import com.flossom.common.core.domain.entity.WxUserTag;
|
|
|
|
|
import com.flossom.common.core.enums.SiteOpenTypeEnum;
|
|
|
|
|
import com.flossom.common.core.enums.SitePushTypeEnum;
|
|
|
|
|
import com.flossom.common.core.enums.SiteTypeEnum;
|
|
|
|
|
import com.flossom.common.core.enums.TagTypeStatus;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
|
import com.flossom.common.core.mapper.SiteInfoMapper;
|
|
|
|
|
import com.flossom.common.core.mapper.SiteLogMapper;
|
|
|
|
|
import com.flossom.common.core.mapper.WxUserTagMapper;
|
|
|
|
|
import com.flossom.common.core.utils.StringUtils;
|
|
|
|
|
import com.flossom.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.flossom.miniProgram.service.ISiteInfoService;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class SiteInfoServiceImpl implements ISiteInfoService {
|
|
|
|
|
|
|
|
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SiteInfoMapper siteInfoMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SiteLogMapper siteLogMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxUserTagMapper wxUserTagMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SiteInfo> popupList(Integer openType) {
|
|
|
|
|
SiteOpenTypeEnum openTypeEnum = SiteOpenTypeEnum.getOpenType(openType);
|
|
|
|
|
if (openTypeEnum == null) {
|
|
|
|
|
logger.error("获取弹窗失败:openType值为 {}", openType);
|
|
|
|
|
throw new ServiceException("获取弹窗失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SiteInfo siteInfo = new SiteInfo();
|
|
|
|
|
// 站点类型
|
|
|
|
|
siteInfo.setSiteType(SiteTypeEnum.POPUP_LIST.getCode());
|
|
|
|
|
// 弹窗类型
|
|
|
|
|
siteInfo.setOpenType(openTypeEnum.getCode());
|
|
|
|
|
// 开启的数据
|
|
|
|
|
siteInfo.setOperate(1);
|
|
|
|
|
List<SiteInfo> siteInfos = siteInfoMapper.selectSiteInfoList(siteInfo);
|
|
|
|
|
if (siteInfos != null && siteInfos.size() > 0) {
|
|
|
|
|
return filterSite(siteInfos);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SiteInfo> carousel() {
|
|
|
|
|
SiteInfo siteInfo = new SiteInfo();
|
|
|
|
|
// 站点类型
|
|
|
|
|
siteInfo.setSiteType(SiteTypeEnum.CAROUSEL_LIST.getCode());
|
|
|
|
|
// 开启的数据
|
|
|
|
|
siteInfo.setOperate(1);
|
|
|
|
|
List<SiteInfo> siteInfos = siteInfoMapper.selectSiteInfoList(siteInfo);
|
|
|
|
|
if (siteInfos != null && siteInfos.size() > 0) {
|
|
|
|
|
return filterSite(siteInfos);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 条件做过滤
|
|
|
|
|
*
|
|
|
|
|
* @param siteInfos
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<SiteInfo> filterSite(List<SiteInfo> siteInfos) {
|
|
|
|
|
List<SiteInfo> resultList = new ArrayList<>();
|
|
|
|
|
for (SiteInfo info : siteInfos) {
|
|
|
|
|
/* 1、开启结束时间判定 */
|
|
|
|
|
Date siteStartTime = info.getSiteStartTime();
|
|
|
|
|
Date siteEndTime = info.getSiteEndTime();
|
|
|
|
|
if (siteStartTime != null && siteEndTime != null) {
|
|
|
|
|
LocalDateTime startTime = LocalDateTime.ofInstant(siteStartTime.toInstant(), ZoneId.systemDefault());
|
|
|
|
|
LocalDateTime endTime = LocalDateTime.ofInstant(siteEndTime.toInstant(), ZoneId.systemDefault());
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
// 不在时间范围内
|
|
|
|
|
if (!(now.isAfter(startTime) && now.isBefore(endTime))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2、投放用户注册时间 */
|
|
|
|
|
Date registerStartTime = info.getUserRegisterStartTime();
|
|
|
|
|
Date registerEndTime = info.getUserRegisterEndTime();
|
|
|
|
|
if (registerStartTime != null && registerEndTime != null) {
|
|
|
|
|
LocalDateTime startTime = LocalDateTime.ofInstant(registerStartTime.toInstant(), ZoneId.systemDefault());
|
|
|
|
|
LocalDateTime endTime = LocalDateTime.ofInstant(registerEndTime.toInstant(), ZoneId.systemDefault());
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
// 不在时间范围内
|
|
|
|
|
if (!(now.isAfter(startTime) && now.isBefore(endTime))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3、可见用户类型 */
|
|
|
|
|
Integer userType = info.getUserType();
|
|
|
|
|
// 可见用户类型 0-全部 1-游客 2-会员
|
|
|
|
|
if (userType != 0) {
|
|
|
|
|
Integer loginUserType = SecurityUtils.getLoginUser().getWxUserMember().getUserType();
|
|
|
|
|
// 当用户类型为游客
|
|
|
|
|
if (loginUserType == 0) {
|
|
|
|
|
if (userType != 1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 当用户类型为会员
|
|
|
|
|
if (loginUserType == 1) {
|
|
|
|
|
if (userType != 2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 4、弹窗标签判断 */
|
|
|
|
|
// 4.1、获取用户拥有的小程序标签和企微标签
|
|
|
|
|
List<Long> userMiniTageIdList = new ArrayList<>();
|
|
|
|
|
List<Long> userWecomTageIdList = new ArrayList<>();
|
|
|
|
|
WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember();
|
|
|
|
|
WxUserTag wxUserTag = new WxUserTag();
|
|
|
|
|
wxUserTag.setUserId(wxUserMember.getId());
|
|
|
|
|
wxUserTag.setType(TagTypeStatus.MINI_PROGRAM.getCode());
|
|
|
|
|
// 用户拥有的小程序标签
|
|
|
|
|
List<WxUserTag> userMiniProgramTags = wxUserTagMapper.selectWxUserTagList(wxUserTag);
|
|
|
|
|
if (userMiniProgramTags != null && userMiniProgramTags.size() > 0) {
|
|
|
|
|
userMiniTageIdList = userMiniProgramTags.stream().map(WxUserTag::getTagId).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
wxUserTag.setType(TagTypeStatus.ENTERPRISE_WECHAT.getCode());
|
|
|
|
|
// 用户拥有的企微标签
|
|
|
|
|
List<WxUserTag> userWecomTags = wxUserTagMapper.selectWxUserTagList(wxUserTag);
|
|
|
|
|
if (userWecomTags != null && userWecomTags.size() > 0) {
|
|
|
|
|
userWecomTageIdList = userWecomTags.stream().map(WxUserTag::getTagId).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4.2、禁止小程序标签
|
|
|
|
|
String forbidWechatTagId = info.getForbidWechatTagId();
|
|
|
|
|
if (StringUtils.isNotBlank(forbidWechatTagId)) {
|
|
|
|
|
List<String> forbidWechatTagIdList = Arrays.asList(forbidWechatTagId.split(","));
|
|
|
|
|
if (forbidWechatTagIdList != null && forbidWechatTagIdList.size() > 0) {
|
|
|
|
|
if (userMiniTageIdList.size() > 0) {
|
|
|
|
|
for (Long tagid : userMiniTageIdList) {
|
|
|
|
|
if (forbidWechatTagIdList.contains(tagid)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 4.3、禁止企微标签
|
|
|
|
|
String forbidCompanyTagId = info.getForbidCompanyTagId();
|
|
|
|
|
if (StringUtils.isNotBlank(forbidCompanyTagId)) {
|
|
|
|
|
List<String> forbidCompanyTagIdList = Arrays.asList(forbidCompanyTagId.split(","));
|
|
|
|
|
if (forbidCompanyTagIdList != null && forbidCompanyTagIdList.size() > 0) {
|
|
|
|
|
if (userWecomTageIdList.size() > 0) {
|
|
|
|
|
for (Long tagid : userWecomTageIdList) {
|
|
|
|
|
if (forbidCompanyTagIdList.contains(tagid)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 4.4、可见小程序标签
|
|
|
|
|
String showWechatTagId = info.getShowWechatTagId();
|
|
|
|
|
if (StringUtils.isNotBlank(showWechatTagId)) {
|
|
|
|
|
List<String> showWechatTagIdList = Arrays.asList(showWechatTagId.split(","));
|
|
|
|
|
if (showWechatTagIdList != null && userMiniTageIdList.size() > 0) {
|
|
|
|
|
if (!userMiniTageIdList.containsAll(showWechatTagIdList)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 4.5、可见企微标签
|
|
|
|
|
String showCompanyTagId = info.getShowCompanyTagId();
|
|
|
|
|
if (StringUtils.isNotBlank(showCompanyTagId)) {
|
|
|
|
|
List<String> showCompanyTagIdList = Arrays.asList(showCompanyTagId.split(","));
|
|
|
|
|
if (userWecomTageIdList != null && userWecomTageIdList.size() > 0) {
|
|
|
|
|
if (!userWecomTageIdList.containsAll(showCompanyTagIdList)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 5、推送频次 */
|
|
|
|
|
Integer pushType = info.getPushType();
|
|
|
|
|
if (info.getPushType() != null) {
|
|
|
|
|
// 5.1、每次进入,不用做判断
|
|
|
|
|
// 5.2、一次
|
|
|
|
|
if (SitePushTypeEnum.ONE.getCode() == pushType) {
|
|
|
|
|
SiteLog siteLog = new SiteLog();
|
|
|
|
|
siteLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId());
|
|
|
|
|
siteLog.setSiteId(info.getId());
|
|
|
|
|
List<SiteLog> siteLogs = siteLogMapper.selectSiteLogList(siteLog);
|
|
|
|
|
if (siteLogs != null && siteLogs.size() > 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 自定义
|
|
|
|
|
if (SitePushTypeEnum.CUSTOM.getCode() == pushType) {
|
|
|
|
|
// 判断当前日期的星期是否在规定范围内
|
|
|
|
|
String pushTimer = info.getPushTimer();
|
|
|
|
|
if (StringUtils.isNotBlank(pushTimer)) {
|
|
|
|
|
List<String> weekList = Arrays.asList(pushTimer.split(","));
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
// 获取当前星期几(1表示周日,2表示周一,依此类推)
|
|
|
|
|
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
|
|
if (!weekList.contains(week)) {
|
|
|
|
|
// 不包含
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 在规定的星期内,判断观看次数是否达标了
|
|
|
|
|
SiteLog siteLog = new SiteLog();
|
|
|
|
|
siteLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId());
|
|
|
|
|
siteLog.setSiteId(info.getId());
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
siteLog.getParams().put("beginTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MIN));
|
|
|
|
|
siteLog.getParams().put("endTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MAX));
|
|
|
|
|
List<SiteLog> siteLogs = siteLogMapper.selectSiteLogList(siteLog);
|
|
|
|
|
if (siteLogs == null || siteLogs.size() >= info.getPushNumber()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: 打卡多少次可见
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: 关联仪器
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 最终符合条件
|
|
|
|
|
resultList.add(info);
|
|
|
|
|
}
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|