Commit a4091391 by zhuyajie

个人号群发

parent f7af4ffd
......@@ -40,6 +40,8 @@ public class AdviserBookInfoDTO extends BaseDto {
*/
private String agentName;
private Long bookGroupId;
public Long getBookId() {
return bookId;
}
......@@ -128,6 +130,14 @@ public class AdviserBookInfoDTO extends BaseDto {
this.agentName = agentName;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
@Override
public String toString() {
return "AdviserBookInfoDTO{" +
......@@ -142,6 +152,7 @@ public class AdviserBookInfoDTO extends BaseDto {
", adviserName='" + adviserName + '\'' +
", agentId=" + agentId +
", agentName='" + agentName + '\'' +
", bookGroupId=" + bookGroupId +
'}';
}
}
......@@ -10,7 +10,6 @@ import lombok.Data;
* @创建时间:15:31 2020/1/2
* @版本:1.0
*/
@Data
public class SelfRobotBookGroupDTO extends BaseDto {
/**
......@@ -39,4 +38,52 @@ public class SelfRobotBookGroupDTO extends BaseDto {
* 编辑id
*/
private Long adviserId;
public String getWxId() {
return wxId;
}
public void setWxId(String wxId) {
this.wxId = wxId;
}
public String getWxNickName() {
return wxNickName;
}
public void setWxNickName(String wxNickName) {
this.wxNickName = wxNickName;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
public String getGroupQrcodeName() {
return groupQrcodeName;
}
public void setGroupQrcodeName(String groupQrcodeName) {
this.groupQrcodeName = groupQrcodeName;
}
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
public Long getAdviserId() {
return adviserId;
}
public void setAdviserId(Long adviserId) {
this.adviserId = adviserId;
}
}
......@@ -15,4 +15,8 @@ public class PushConstant {
* 个人号定时群发-定时器方法名
*/
public static final String JOB_NAME_SELF_PUSH = "judgeSelfPushTime";
public static final Long[] pro_demo_book_group_id = {23722L, 23721L, 23720L, 23718L};
public static final Long[] uat_demo_book_group_id = {441L, 442L};
}
package com.pcloud.book.push.biz.impl;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.dao.BookGroupCipherUserDao;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.WeixinQrcodeGenerationDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.SelfRobotBookGroupDTO;
import com.pcloud.book.group.entity.WeixinQrcodeGeneration;
import com.pcloud.book.group.set.GroupSet;
import com.pcloud.book.group.tools.SendSelfMsgTools;
......@@ -19,10 +23,12 @@ import com.pcloud.book.push.entity.SelfPushUser;
import com.pcloud.book.push.enums.ItemTypeEnum;
import com.pcloud.book.push.enums.PushStatusEnum;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.core.constant.SystemCode;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.facade.quartz.entity.CallBackParam;
import com.pcloud.facade.quartz.entity.ScheduleJob;
import com.pcloud.facade.quartz.service.ScheduleService;
......@@ -35,7 +41,9 @@ import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
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 java.util.ArrayList;
......@@ -71,6 +79,12 @@ public class SelfPushBizImpl implements SelfPushBiz {
private WeixinQrcodeGenerationDao weixinQrcodeGenerationDao;
@Autowired
private ScheduleService scheduleService;
@Autowired
private BookGroupCipherUserDao bookGroupCipherUserDao;
@Value("${system.env}")
private String envStr;
@Autowired
private BookGroupDao bookGroupDao;
@Override
public void createSelfPush(Long partyId, SelfPushAddParamDTO addParamDTO) {
......@@ -79,7 +93,12 @@ public class SelfPushBizImpl implements SelfPushBiz {
SelfPush selfPush = new SelfPush();
selfPush.setCreateUser(partyId);
selfPush.setUpdateUser(partyId);
selfPush.setAltId(addParamDTO.getAltId());
if (SystemCode.adviser.code.equalsIgnoreCase(addParamDTO.getSystemCode())){
selfPush.setBookGroupId(addParamDTO.getBookGroupId());
}
if (SystemCode.pcloud.code.equalsIgnoreCase(addParamDTO.getSystemCode())){
selfPush.setAltId(addParamDTO.getAltId());
}
selfPush.setSendNow(sendNow);
if (sendNow) {
selfPush.setSendTime(new Date());
......@@ -96,7 +115,7 @@ public class SelfPushBizImpl implements SelfPushBiz {
setSelfPushUser(userIdList, partyId, pushId);
if (sendNow) {
//微信立即发送
msgPush(userIdList, itemList, selfPush.getAltId(), pushId);
msgPush(userIdList, itemList, pushId);
} else {
//定时任务
addSendQuartzJob(pushId, addParamDTO.getSendTime());
......@@ -137,15 +156,43 @@ public class SelfPushBizImpl implements SelfPushBiz {
/**
* 微信群消息推送
*/
private void msgPush(List<String> userIdList, List<SelfPushItem> itemList, String altId, Long pushId) {
ThreadPoolUtils.SEND_MESSAGE_THREAD_POOL.execute(() -> {
for (String userId : userIdList) {
for (SelfPushItem pushItem : itemList) {
sendSelfMsg(userId, altId, pushItem);
private void msgPush(List<String> userIdList, List<SelfPushItem> itemList, Long pushId) {
SelfPush selfPush = selfPushDao.getById(pushId);
if (!StringUtil.isEmpty(selfPush.getAltId())){//平台端群发
String altId = selfPush.getAltId();
List<String> sendUserIds = new ArrayList<>();
sendUserIds.addAll(userIdList);
ThreadPoolUtils.SEND_MESSAGE_THREAD_POOL.execute(() -> {
for (String userId : sendUserIds) {
for (SelfPushItem pushItem : itemList) {
sendSelfMsg(userId, altId, pushItem);
}
}
selfPushItemDao.updatePushStatusByPushId(PushStatusEnum.SUCCESS.value, pushId);
});
}else if ( null != selfPush.getBookGroupId()){//编辑端群发
Long bookGroupId = selfPush.getBookGroupId();
if ("pro".equals(envStr) && ArrayUtils.contains(PushConstant.pro_demo_book_group_id,bookGroupId)) {
//生产环境特定社群书,发给所有好友
userIdList = bookGroupCipherUserDao.getFriendIdsByBookGroupId(bookGroupId);
} else if ("uat".equalsIgnoreCase(envStr) && ArrayUtils.contains(PushConstant.uat_demo_book_group_id, bookGroupId)){
userIdList = bookGroupCipherUserDao.getFriendIdsByBookGroupId(bookGroupId);
}
selfPushItemDao.updatePushStatusByPushId(PushStatusEnum.SUCCESS.value, pushId);
});
List<String> sendUserIds = new ArrayList<>();
sendUserIds.addAll(userIdList);
ThreadPoolUtils.SEND_MESSAGE_THREAD_POOL.execute(() -> {
for (String userId : sendUserIds) {
//查好友对应的小号
SelfRobotBookGroupDTO bookGroupDTO = bookGroupCipherUserDao.getSelfRobotBookGroupInfoByUser(userId, bookGroupId);
String altId = bookGroupDTO.getWxId();
for (SelfPushItem pushItem : itemList) {
sendSelfMsg(userId, altId, pushItem);
}
}
selfPushItemDao.updatePushStatusByPushId(PushStatusEnum.SUCCESS.value, pushId);
});
}
}
/**
......@@ -191,6 +238,9 @@ public class SelfPushBizImpl implements SelfPushBiz {
* @param selfPushItem
*/
public void sendSelfMsg(String userWxId, String altId, SelfPushItem selfPushItem) {
if (StringUtil.isEmpty(userWxId) || StringUtil.isEmpty(altId)){
return;
}
Integer code = SendMessageTypeEnum.SELF.getCode();
Integer itemType = selfPushItem.getItemType();
if (ItemTypeEnum.TEXT.value.equals(itemType)) {
......@@ -274,14 +324,21 @@ public class SelfPushBizImpl implements SelfPushBiz {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
}
List<String> wxIds = pageBeanNew.getRecordList().stream().filter(s -> s != null).map(SelfPushRecordDTO::getAltId).distinct().collect(Collectors.toList());
Map<String, GroupUserDTO> robotMap = wechatGroupConsr.mapRobotInfoByIdList(wxIds);
Map<String, GroupUserDTO> robotMap = new HashMap<>();
if (!ListUtils.isEmpty(wxIds)){
robotMap = wechatGroupConsr.mapRobotInfoByIdList(wxIds);
}
for (SelfPushRecordDTO dto : pageBeanNew.getRecordList()) {
Integer userCount = selfPushUserDao.getCountByPushId(dto.getPushId());
dto.setUserCount(userCount);
if (!MapUtils.isEmpty(robotMap) && robotMap.containsKey(dto.getAltId())) {
if (!MapUtils.isEmpty(robotMap) && !StringUtil.isEmpty(dto.getAltId()) && robotMap.containsKey(dto.getAltId())) {
GroupUserDTO userDTO = robotMap.get(dto.getAltId());
dto.setRobotName(userDTO.getNickName());
}
if (null != dto.getBookGroupId()){
BookGroupDTO bookGroupDTO = bookGroupDao.getBookBaseInfoById(dto.getBookGroupId());
dto.setBookName(bookGroupDTO.getBookName());
}
}
return pageBeanNew;
}
......@@ -298,6 +355,6 @@ public class SelfPushBizImpl implements SelfPushBiz {
return;
}
selfPushItemDao.updatePushStatusByPushId(PushStatusEnum.PUSHING.value, pushId);
msgPush(userIdList, itemList, selfPush.getAltId(), pushId);
msgPush(userIdList, itemList, pushId);
}
}
......@@ -10,6 +10,7 @@ import com.pcloud.book.push.entity.SelfPushItem;
import com.pcloud.book.push.enums.ItemTypeEnum;
import com.pcloud.book.push.enums.PushTypeEnum;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.constant.SystemCode;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
......@@ -289,6 +290,12 @@ public class PushCheck {
if (null == addParamDTO) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数为空");
}
if (SystemCode.adviser.code.equalsIgnoreCase(addParamDTO.getSystemCode()) && null == addParamDTO.getBookGroupId()){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "缺少bookGroupId");
}
if (SystemCode.pcloud.code.equalsIgnoreCase(addParamDTO.getSystemCode()) && StringUtil.isEmpty(addParamDTO.getAltId())){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "缺少个人号id");
}
if (null == addParamDTO.getSendNow()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "缺少立即发送字段");
}
......
......@@ -13,23 +13,22 @@ import lombok.Data;
* @创建时间:9:49 2019/11/27
* @版本:1.0
*/
@Data
public class SelfPushAddParamDTO {
/**
* 推送小号id
*/
public String altId;
private String altId;
/**
* 推送用户id
*/
public List<String> userIdList;
private List<String> userIdList;
/**
* 推送信息
*/
public List<SelfPushItem> pushItemList;
private List<SelfPushItem> pushItemList;
/**
* 立即发送
*/
......@@ -38,4 +37,64 @@ public class SelfPushAddParamDTO {
* 发送时间
*/
private String sendTime;
private String systemCode;
private Long bookGroupId;
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
public List<String> getUserIdList() {
return userIdList;
}
public void setUserIdList(List<String> userIdList) {
this.userIdList = userIdList;
}
public List<SelfPushItem> getPushItemList() {
return pushItemList;
}
public void setPushItemList(List<SelfPushItem> pushItemList) {
this.pushItemList = pushItemList;
}
public Boolean getSendNow() {
return sendNow;
}
public void setSendNow(Boolean sendNow) {
this.sendNow = sendNow;
}
public String getSendTime() {
return sendTime;
}
public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}
public String getSystemCode() {
return systemCode;
}
public void setSystemCode(String systemCode) {
this.systemCode = systemCode;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
}
......@@ -14,7 +14,6 @@ import lombok.Data;
* @创建时间:16:50 2019/11/27
* @版本:1.0
*/
@Data
public class SelfPushRecordDTO extends BaseDto{
@ApiModelProperty("群发小号id")
......@@ -76,4 +75,177 @@ public class SelfPushRecordDTO extends BaseDto{
@ApiModelProperty("发送时间")
private Date sendTime;
@ApiModelProperty("bookGroupId")
private Long bookGroupId;
@ApiModelProperty("bookName")
private String bookName;
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
public String getRobotName() {
return robotName;
}
public void setRobotName(String robotName) {
this.robotName = robotName;
}
public Long getPushId() {
return pushId;
}
public void setPushId(Long pushId) {
this.pushId = pushId;
}
public Long getPushItemId() {
return pushItemId;
}
public void setPushItemId(Long pushItemId) {
this.pushItemId = pushItemId;
}
public Integer getItemType() {
return itemType;
}
public void setItemType(Integer itemType) {
this.itemType = itemType;
}
public String getTextContent() {
return textContent;
}
public void setTextContent(String textContent) {
this.textContent = textContent;
}
public String getLinkUrl() {
return linkUrl;
}
public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl;
}
public String getLinkTitle() {
return linkTitle;
}
public void setLinkTitle(String linkTitle) {
this.linkTitle = linkTitle;
}
public String getLinkDescription() {
return linkDescription;
}
public void setLinkDescription(String linkDescription) {
this.linkDescription = linkDescription;
}
public String getLinkImageUrl() {
return linkImageUrl;
}
public void setLinkImageUrl(String linkImageUrl) {
this.linkImageUrl = linkImageUrl;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public Long getAppId() {
return appId;
}
public void setAppId(Long appId) {
this.appId = appId;
}
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public String getAppUrl() {
return appUrl;
}
public void setAppUrl(String appUrl) {
this.appUrl = appUrl;
}
public String getProductUrl() {
return productUrl;
}
public void setProductUrl(String productUrl) {
this.productUrl = productUrl;
}
public Integer getPushStatus() {
return pushStatus;
}
public void setPushStatus(Integer pushStatus) {
this.pushStatus = pushStatus;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getUserCount() {
return userCount;
}
public void setUserCount(Integer userCount) {
this.userCount = userCount;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
}
......@@ -10,7 +10,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("个人号群发")
@Data
public class SelfPush extends BaseEntity{
@ApiModelProperty("群发小号id")
......@@ -36,4 +35,75 @@ public class SelfPush extends BaseEntity{
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("发送时间")
private Date sendTime;
@ApiModelProperty("bookGroupId")
private Long bookGroupId;
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
public Long getCreateUser() {
return createUser;
}
public void setCreateUser(Long createUser) {
this.createUser = createUser;
}
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Long getUpdateUser() {
return updateUser;
}
public void setUpdateUser(Long updateUser) {
this.updateUser = updateUser;
}
@Override
public Date getUpdateTime() {
return updateTime;
}
@Override
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Boolean getSendNow() {
return sendNow;
}
public void setSendNow(Boolean sendNow) {
this.sendNow = sendNow;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("个人号群发项")
@Data
public class SelfPushItem extends BaseEntity{
@ApiModelProperty("推送id")
......@@ -69,4 +68,152 @@ public class SelfPushItem extends BaseEntity{
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("发送时间")
private Date sendTime;
public Long getPushId() {
return pushId;
}
public void setPushId(Long pushId) {
this.pushId = pushId;
}
public Integer getItemType() {
return itemType;
}
public void setItemType(Integer itemType) {
this.itemType = itemType;
}
public String getTextContent() {
return textContent;
}
public void setTextContent(String textContent) {
this.textContent = textContent;
}
public String getLinkUrl() {
return linkUrl;
}
public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl;
}
public String getLinkTitle() {
return linkTitle;
}
public void setLinkTitle(String linkTitle) {
this.linkTitle = linkTitle;
}
public String getLinkDescription() {
return linkDescription;
}
public void setLinkDescription(String linkDescription) {
this.linkDescription = linkDescription;
}
public String getLinkImageUrl() {
return linkImageUrl;
}
public void setLinkImageUrl(String linkImageUrl) {
this.linkImageUrl = linkImageUrl;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public Long getAppId() {
return appId;
}
public void setAppId(Long appId) {
this.appId = appId;
}
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public String getAppUrl() {
return appUrl;
}
public void setAppUrl(String appUrl) {
this.appUrl = appUrl;
}
public String getProductUrl() {
return productUrl;
}
public void setProductUrl(String productUrl) {
this.productUrl = productUrl;
}
public Integer getPushStatus() {
return pushStatus;
}
public void setPushStatus(Integer pushStatus) {
this.pushStatus = pushStatus;
}
public Long getCreateUser() {
return createUser;
}
public void setCreateUser(Long createUser) {
this.createUser = createUser;
}
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Long getUpdateUser() {
return updateUser;
}
public void setUpdateUser(Long updateUser) {
this.updateUser = updateUser;
}
@Override
public Date getUpdateTime() {
return updateTime;
}
@Override
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
}
\ No newline at end of file
......@@ -45,9 +45,11 @@ public class SelfPushFacade {
@ApiOperation("创建个人号群发")
@PostMapping("createSelfPush")
public ResponseDto<?> createSelfPush(@RequestHeader("token") String token, @RequestBody @ApiParam SelfPushAddParamDTO addParamDTO) throws PermissionException {
pushCheck.selfPushParamCheck(addParamDTO);
Map<String, Object> map = SessionUtil.getToken4Redis(token);
Long partyId = (Long) map.get(SessionUtil.PARTY_ID);
String systemCode = (String) map.get(SessionUtil.SYSTEM_CODE);
addParamDTO.setSystemCode(systemCode);
pushCheck.selfPushParamCheck(addParamDTO);
if (partyId == 0){
String isSystem = (String) map.get(SessionUtil.IS_SYSTEM);
if ("0".equals(isSystem)) {
......
......@@ -1824,7 +1824,8 @@
b.ISBN isbn,
b.BOOK_NAME bookName,
a.ADVISER_ID adviserId,
g.agent_id agentId
g.agent_id agentId,
g.id bookGroupId
FROM
book_group g
LEFT JOIN book_adviser a ON g.book_id = a.BOOK_ID
......
......@@ -96,6 +96,7 @@
<select id="listSelfPushRecord" parameterType="map" resultType="com.pcloud.book.push.dto.SelfPushRecordDTO">
SELECT
p.alt_id altId,
p.book_group_id bookGroupId,
p.id pushId,
i.id pushItemId,
i.item_type itemType,
......
......@@ -10,19 +10,21 @@
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="send_now" property="sendNow" jdbcType="BIT" />
<result column="send_time" property="sendTime" jdbcType="TIMESTAMP" />
<result column="book_group_id" property="bookGroupId" jdbcType="BIGINT" />
</resultMap>
<sql id="Base_Column_List" >
id, alt_id, create_user, create_time, update_user, update_time, send_now, send_time
id, alt_id, create_user, create_time, update_user, update_time, send_now, send_time, book_group_id
</sql>
<insert id="insert" parameterType="com.pcloud.book.push.entity.SelfPush" useGeneratedKeys="true" keyProperty="id">
insert into self_push (id, alt_id, create_user,
create_time, update_user, update_time, send_now, send_time
create_time, update_user, update_time, send_now, send_time, book_group_id
)
values (#{id,jdbcType=BIGINT}, #{altId,jdbcType=VARCHAR}, #{createUser,jdbcType=BIGINT},
now(), #{updateUser,jdbcType=BIGINT}, now(), #{sendNow}, #{sendTime}
now(), #{updateUser,jdbcType=BIGINT}, now(), #{sendNow}, #{sendTime}, #{bookGroupId}
)
</insert>
......
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