Commit aa98d152 by 高鹏

Merge branch 'zhuyajie' into 'master'

广告投放-文本本链接

See merge request rays/pcloud-book!25
parents c13dde3a a841b4e6
package com.pcloud.book.advertising.biz.impl;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.pcloud.appcenter.app.dto.AppTypeDto;
import com.pcloud.appcenter.app.service.AppTypeService;
import com.pcloud.book.advertising.biz.AdvertisingSpaceBiz;
......@@ -53,6 +37,7 @@ import com.pcloud.book.book.entity.BookAdviser;
import com.pcloud.book.book.set.BookSet;
import com.pcloud.book.consumer.app.AppConsr;
import com.pcloud.book.consumer.common.ExportConsr;
import com.pcloud.book.consumer.label.LabelConsr;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.consumer.resource.ProductConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
......@@ -68,6 +53,7 @@ import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.group.dto.GroupQrcodeInfoDTO;
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.qrcode.service.QrcodeSceneService;
import com.pcloud.common.core.aspect.ParamLog;
......@@ -87,6 +73,28 @@ import com.sdk.wxgroup.SendPicMessageVO;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Description 广告位业务逻辑层接口实现类
* @author PENG
......@@ -94,6 +102,7 @@ import com.sdk.wxgroup.WxGroupSDK;
*/
@Component("advertisingSpaceBiz")
public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
private static final Logger LOGGER = LoggerFactory.getLogger(AdvertisingSpaceBizImpl.class);
@Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix;
......@@ -150,6 +159,8 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
private BookGroupDao bookGroupDao;
@Autowired
private ReaderConsr readerConsr;
@Autowired
private LabelConsr labelConsr;
/**
* 创建广告位
......@@ -201,6 +212,24 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
&& null == advertisingSpace.getPriceEachTime()) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "按点击量结算和按曝光量结算时每次价格不能为空!");
}
if (AdPositionEnum.WECHAT_GROUP_MSG.positionCode.equals(advertisingSpace.getAdPosition())) {//微信群投放
if (AdPositionModeEnum.TEXT_AND_LINK.modeCode.equals(advertisingSpace.getAdPositionMode())) {//多文字+多链接
String adTitle = advertisingSpace.getAdTitle();
List<String> linkList = getLinkList(adTitle);
int linkLength = 0;//短链接长度
if (!ListUtils.isEmpty(linkList)) {
for (String link : linkList) {
adTitle = adTitle.replace(link, "");
linkLength = linkLength + 26;
}
}
int length = linkLength + adTitle.length();
if (length > 300) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "文本长度超过300!");
}
}
}
}
/**
......@@ -426,21 +455,32 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
// 获取机器人微信号
String altId = wechatGroupConsr.getRobotIdByGroupId(groupId);
if (AdPositionModeEnum.TEXT_AND_LINK.modeCode.equals(advertisingSpace.getAdPositionMode())) {
//多文字+多链接 modifyby zhuyajie
//例如:[色]123<link>http://www.baidu.com</link>1111111[闭嘴]
String adTitle = advertisingSpace.getAdTitle();
List<String> linkList = getLinkList(adTitle);
if (!ListUtils.isEmpty(linkList)) {
for (String link : linkList) {
String adLink = "";
String adLinkOld = link.replaceAll("<link>", "").replace("</link>", "");
if (!StringUtil.isEmpty(adLinkOld)) {
if (adLinkOld.contains("?")) {
adLink = adLinkOld + "&book_group_id=" + classifyDTO.getBookGroupId() + "&classify_id=" + group.getClassifyId()
+ "&qrcode_id=" + group.getQrcodeId() + "&ad_id=" + advertisingSpace.getId();
} else {
adLink = adLinkOld + "?book_group_id=" + classifyDTO.getBookGroupId() + "&classify_id=" + group.getClassifyId()
+ "&qrcode_id=" + group.getQrcodeId() + "&ad_id=" + advertisingSpace.getId();
}
adLink = UrlUtils.getShortUrl4Own(wechatGroupLinkPrefix + "/link?url=" + URLEncoder.encode(adLink));
}
adTitle = adTitle.replace(link, adLink);
}
}
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setGroupId(groupId);
sendTextMessageVO.setAltId(altId);
String adLink = "";
if (!StringUtil.isEmpty(advertisingSpace.getAdLink())) {
if (advertisingSpace.getAdLink().contains("?")) {
adLink = advertisingSpace.getAdLink() + "&book_group_id=" + classifyDTO.getBookGroupId() + "&classify_id=" + group.getClassifyId()
+ "&qrcode_id=" + group.getQrcodeId() + "&ad_id=" + advertisingSpace.getId();
} else {
adLink = advertisingSpace.getAdLink() + "?book_group_id=" + classifyDTO.getBookGroupId() + "&classify_id=" + group.getClassifyId()
+ "&qrcode_id=" + group.getQrcodeId() + "&ad_id=" + advertisingSpace.getId();
}
adLink = UrlUtils.getShortUrl4Own(wechatGroupLinkPrefix + "/link?url=" + URLEncoder.encode(adLink));
}
sendTextMessageVO.setContent(advertisingSpace.getAdTitle() + "\n" + adLink);
sendTextMessageVO.setContent(adTitle);
LOGGER.info("发送微信消息" + sendTextMessageVO.toString());
WxGroupSDK.sendTextMessage(sendTextMessageVO);
} else if (AdPositionModeEnum.NEWS_SHARE.modeCode.equals(advertisingSpace.getAdPositionMode())) {
SendArticleMessageVO sendArticleMessageVO = new SendArticleMessageVO();
......@@ -498,6 +538,21 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
}
/**
* 提取文本中链接
* @param title
* @return
*/
private List<String> getLinkList(String title) {
List<String> list = new ArrayList<>();
Pattern pa = Pattern.compile("<link>.*?</link>");//标题正则表达式
Matcher ma = pa.matcher(title);
while (ma.find()) {
list.add(ma.group());
}
return list;
}
/**
* 获取出版社书刊权限
*/
@Override
......@@ -605,6 +660,39 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
if (pageBean == null || ListUtils.isEmpty(pageBean.getRecordList())) {
return new PageBean(0, 0, new ArrayList<>());
}
List<Object>objs = pageBean.getRecordList();
Object objectlist = (Object) objs;
List<GroupQrcodeVO> groupQrcodeVOList = ( List<GroupQrcodeVO>)objectlist;
List<Long> labelIds = new ArrayList<>();
List<Long> proLabels = groupQrcodeVOList.stream().filter(s->s.getProLabelId()!=null).map(GroupQrcodeVO::getProLabelId).distinct().collect(Collectors.toList());
List<Long> depLabels = groupQrcodeVOList.stream().filter(s->s.getDepLabelId()!=null).map(GroupQrcodeVO::getDepLabelId).distinct().collect(Collectors.toList());
List<Long> purLabels = groupQrcodeVOList.stream().filter(s->s.getPurLabelId()!=null).map(GroupQrcodeVO::getPurLabelId).distinct().collect(Collectors.toList());
if (!ListUtils.isEmpty(proLabels)){
labelIds.addAll(proLabels);
}
if (!ListUtils.isEmpty(depLabels)){
labelIds.addAll(depLabels);
}
if (!ListUtils.isEmpty(purLabels)){
labelIds.addAll(purLabels);
}
if (!ListUtils.isEmpty(labelIds)) {
Map<Long, String> labelMap = labelConsr.getLabelName(labelIds);
if (!MapUtils.isEmpty(labelMap)) {
for (Object object:objs){
GroupQrcodeVO qrcodeVO = (GroupQrcodeVO) object;
if (null != qrcodeVO.getProLabelId() && labelMap.containsKey(qrcodeVO.getProLabelId())) {
qrcodeVO.setProLabelName(labelMap.get(qrcodeVO.getProLabelId()));
}
if (null != qrcodeVO.getDepLabelId() && labelMap.containsKey(qrcodeVO.getDepLabelId())) {
qrcodeVO.setDepLabelName(labelMap.get(qrcodeVO.getDepLabelId()));
}
if (null != qrcodeVO.getPurLabelId() && labelMap.containsKey(qrcodeVO.getPurLabelId())) {
qrcodeVO.setPurLabelName(labelMap.get(qrcodeVO.getPurLabelId()));
}
}
}
}
return pageBean;
}
......
package com.pcloud.book.advertising.facade;
import org.codehaus.jackson.JsonParseException;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.pcloud.book.advertising.entity.AdvertisingAdviserPermission;
import com.pcloud.book.advertising.entity.AdvertisingAgentPermission;
import com.pcloud.book.advertising.entity.AdvertisingClickRecord;
......@@ -18,6 +10,16 @@ import com.pcloud.book.advertising.entity.AdvertisingSpace;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import org.codehaus.jackson.JsonParseException;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -254,13 +256,19 @@ public interface AdvertisingSpaceFacade {
*/
@ApiOperation(value = "平台端获取社群书微信群列表", httpMethod = "GET")
@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "token", dataType = "string", paramType = "header"),
@ApiImplicitParam(name = "name", value = "书籍名称", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "name", value = "书籍名称", dataType = "string",required = false, paramType = "query"),
@ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "numPerPage", value = "每页条数", dataType = "int", paramType = "query")
@ApiImplicitParam(name = "numPerPage", value = "每页条数", dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "proLabelId", value = "专业标签id", dataType = "long",required = false, paramType = "query"),
@ApiImplicitParam(name = "depLabelId", value = "深度标签id", dataType = "long",required = false, paramType = "query"),
@ApiImplicitParam(name = "purLabelId", value = "目的标签id", dataType = "string",required = false, paramType = "query")
})
@RequestMapping(value = "listGroupQrcode4Platform", method = RequestMethod.GET)
ResponseDto<?> listGroupQrcode4Platform(@RequestHeader("token") String token, @RequestParam(value = "name", required = false) String name,
@RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "numPerPage", required = false) Integer numPerPage)
ResponseDto<?> listGroupQrcode4Platform(
@RequestHeader("token") String token, @RequestParam(value = "name", required = false) String name,
@RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "numPerPage", required = false) Integer numPerPage,
@RequestParam(value = "proLabelId", required = false) Long proLabelId, @RequestParam(value = "depLabelId", required = false) Long depLabelId,
@RequestParam(value = "purLabelId", required = false) Long purLabelId)
throws PermissionException, BizException, JsonParseException;
/**
......
package com.pcloud.book.advertising.facade.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.JsonParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.pcloud.book.advertising.biz.AdvertisingSpaceBiz;
import com.pcloud.book.advertising.dto.AdvertisingSpaceDTO;
import com.pcloud.book.advertising.entity.AdvertisingAdviserPermission;
......@@ -31,6 +19,20 @@ import com.pcloud.common.utils.SessionUtil;
import com.pcloud.common.utils.cookie.Cookie;
import com.pcloud.common.utils.string.StringUtil;
import org.codehaus.jackson.JsonParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Description 广告位接口层接口实现类
* @author PENG
......@@ -228,8 +230,11 @@ public class AdvertisingSpaceFacadeImpl implements AdvertisingSpaceFacade {
*/
@Override
@RequestMapping(value = "listGroupQrcode4Platform", method = RequestMethod.GET)
public ResponseDto<?> listGroupQrcode4Platform(@RequestHeader("token") String token, @RequestParam(value = "name", required = false) String name,
@RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "numPerPage", required = false) Integer numPerPage)
public ResponseDto<?> listGroupQrcode4Platform(
@RequestHeader("token") String token, @RequestParam(value = "name", required = false) String name,
@RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "numPerPage", required = false) Integer numPerPage,
@RequestParam(value = "proLabelId", required = false) Long proLabelId, @RequestParam(value = "depLabelId", required = false) Long depLabelId,
@RequestParam(value = "purLabelId", required = false) Long purLabelId)
throws PermissionException, BizException, JsonParseException {
if (currentPage == null || numPerPage == null || currentPage < 0 || numPerPage < 0) {
throw BookBizException.PAGE_PARAM_DELETION;
......@@ -237,6 +242,9 @@ public class AdvertisingSpaceFacadeImpl implements AdvertisingSpaceFacade {
SessionUtil.getToken4Redis(token);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("name", StringUtil.isEmpty(name) ? null : name);
paramMap.put("proLabelId",proLabelId);
paramMap.put("depLabelId",depLabelId);
paramMap.put("purLabelId",purLabelId);
return new ResponseDto<>(advertisingSpaceBiz.listGroupQrcode4Platform(paramMap, new PageParam(currentPage, numPerPage)));
}
......
......@@ -48,6 +48,25 @@ public class GroupQrcodeVO implements Serializable {
@ApiModelProperty("是否已选")
private Boolean isSelect;
@ApiModelProperty("专业标签ID")
private Long proLabelId;
@ApiModelProperty("专业标签名称")
private String proLabelName;
@ApiModelProperty("深度标签ID")
private Long depLabelId;
@ApiModelProperty("深度标签名称")
private String depLabelName;
@ApiModelProperty("目的标签ID")
private Long purLabelId;
@ApiModelProperty("目的标签名称")
private String purLabelName;
public Long getClassifyId() {
return classifyId;
}
......@@ -136,6 +155,62 @@ public class GroupQrcodeVO implements Serializable {
this.isSelect = isSelect;
}
public Boolean getSelect() {
return isSelect;
}
public void setSelect(Boolean select) {
isSelect = select;
}
public Long getProLabelId() {
return proLabelId;
}
public void setProLabelId(Long proLabelId) {
this.proLabelId = proLabelId;
}
public String getProLabelName() {
return proLabelName;
}
public void setProLabelName(String proLabelName) {
this.proLabelName = proLabelName;
}
public Long getDepLabelId() {
return depLabelId;
}
public void setDepLabelId(Long depLabelId) {
this.depLabelId = depLabelId;
}
public String getDepLabelName() {
return depLabelName;
}
public void setDepLabelName(String depLabelName) {
this.depLabelName = depLabelName;
}
public Long getPurLabelId() {
return purLabelId;
}
public void setPurLabelId(Long purLabelId) {
this.purLabelId = purLabelId;
}
public String getPurLabelName() {
return purLabelName;
}
public void setPurLabelName(String purLabelName) {
this.purLabelName = purLabelName;
}
@Override
public String toString() {
return "GroupQrcodeVO{" +
......@@ -150,6 +225,12 @@ public class GroupQrcodeVO implements Serializable {
", channelId=" + channelId +
", adviserId=" + adviserId +
", isSelect=" + isSelect +
", proLabelId=" + proLabelId +
", proLabelName='" + proLabelName + '\'' +
", depLabelId=" + depLabelId +
", depLabelName='" + depLabelName + '\'' +
", purLabelId=" + purLabelId +
", purLabelName='" + purLabelName + '\'' +
'}';
}
}
......@@ -415,13 +415,17 @@
c.classify,
c.book_group_id bookGroupId,
g.group_name groupQrcodeName,
IF (t.id IS NOT NULL, 1, 0) isSelect
IF (t.id IS NOT NULL, 1, 0) isSelect,
bg.dep_label_id depLabelId,
bg.pro_label_id proLabelId,
bg.pur_label_id purLabelId
FROM
book_group_classify c
JOIN book_group_qrcode g ON c.id = g.classify_id
AND c.is_delete = 0
AND g.is_delete = 0
LEFT JOIN book b ON c.book_id = b.book_id
LEFT JOIN book_group bg ON c.book_group_id = bg.id
LEFT JOIN (
SELECT
db.id,
......@@ -446,8 +450,18 @@
AND (
book_name LIKE CONCAT('%', #{name},'%')
OR group_name LIKE CONCAT('%', #{name},'%')
OR classify LIKE CONCAT('%', #{name},'%')
)
</if>
<if test="depLabelId != null">
AND bg.dep_label_id = #{depLabelId}
</if>
<if test="proLabelId != null">
AND bg.pro_label_id = #{proLabelId}
</if>
<if test="purLabelId != null">
AND bg.pur_label_id = #{purLabelId}
</if>
GROUP BY
g.id
ORDER BY
......
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