Commit a282d422 by 裴大威

Merge branch 'ruansiyuan' into 'master'

个人二维码替换群二维码

See merge request rays/pcloud-book!97
parents 7d29eca3 ac5674ea
......@@ -17,6 +17,11 @@ import java.util.Map;
public class BookConstant {
/**
* 微信小号每天拉人次数缓存前缀
*/
public static final String WXGROUP_ADD_USER_NUM = CacheConstant.BOOK + "WXGROUP_ADD_USER_NUM:";
/**
* 图书基础缓存前缀名称
*/
public static final String BOOK_CACHE = CacheConstant.BOOK + "BOOK:";
......
package com.pcloud.book.group.dto;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/12 14:57
**/
public class GroupCipherDTO implements Serializable {
private static final long serialVersionUID = 4254978072223600943L;
@ApiModelProperty("密码")
private String cipher;
@ApiModelProperty("分类id")
private Long classifyId;
@ApiModelProperty("创建人")
private Long wechatUserId;
@ApiModelProperty("使用人微信id")
private String wxId;
@ApiModelProperty("是否使用")
private Boolean hasUsed;
@ApiModelProperty("机器人id")
private String altId;
public String getCipher() {
return cipher;
}
public void setCipher(String cipher) {
this.cipher = cipher;
}
public Long getClassifyId() {
return classifyId;
}
public void setClassifyId(Long classifyId) {
this.classifyId = classifyId;
}
public Long getWechatUserId() {
return wechatUserId;
}
public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId;
}
public String getWxId() {
return wxId;
}
public void setWxId(String wxId) {
this.wxId = wxId;
}
public Boolean getHasUsed() {
return hasUsed;
}
public void setHasUsed(Boolean hasUsed) {
this.hasUsed = hasUsed;
}
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
@Override
public String toString() {
return "GroupCipherDTO{" +
"cipher='" + cipher + '\'' +
", classifyId=" + classifyId +
", wechatUserId=" + wechatUserId +
", wxId='" + wxId + '\'' +
", hasUsed=" + hasUsed +
", altId='" + altId + '\'' +
'}';
}
}
......@@ -54,6 +54,10 @@ public class GroupClassifyQrcodeDTO implements Serializable {
* 是否开启群学习报告
*/
private Boolean hasOpenLearningReport;
/**
* 进群方式:1群二维码,2客服机器人
*/
private Integer joinGroupType;
public Long getBookId() {
return bookId;
......@@ -135,6 +139,14 @@ public class GroupClassifyQrcodeDTO implements Serializable {
this.hasOpenLearningReport = hasOpenLearningReport;
}
public Integer getJoinGroupType() {
return joinGroupType;
}
public void setJoinGroupType(Integer joinGroupType) {
this.joinGroupType = joinGroupType;
}
@Override
public String toString() {
return "GroupClassifyQrcodeDTO{" +
......@@ -148,6 +160,7 @@ public class GroupClassifyQrcodeDTO implements Serializable {
", price=" + price +
", qrCodeUrl='" + qrCodeUrl + '\'' +
", hasOpenLearningReport=" + hasOpenLearningReport +
", joinGroupType=" + joinGroupType +
'}';
}
}
package com.pcloud.book.group.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/7 9:26
**/
@ApiModel("群使用情况模型")
public class GroupUseDTO implements Serializable {
@ApiModelProperty("已使用")
private Integer hasUsed;
@ApiModelProperty("未使用")
private Integer notUsed;
public Integer getHasUsed() {
return hasUsed;
}
public void setHasUsed(Integer hasUsed) {
this.hasUsed = hasUsed;
}
public Integer getNotUsed() {
return notUsed;
}
public void setNotUsed(Integer notUsed) {
this.notUsed = notUsed;
}
@Override
public String toString() {
return "GroupUseDTO{" +
"hasUsed=" + hasUsed +
", notUsed=" + notUsed +
'}';
}
}
package com.pcloud.book.group.dto;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/7 11:23
**/
public class LargeTempletDTO implements Serializable {
private static final long serialVersionUID = -5982946901202138966L;
@ApiModelProperty("大类")
private Integer largeTemplet;
@ApiModelProperty("名称")
private String name;
public Integer getLargeTemplet() {
return largeTemplet;
}
public void setLargeTemplet(Integer largeTemplet) {
this.largeTemplet = largeTemplet;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "LargeTempletDTO{" +
"largeTemplet=" + largeTemplet +
", name='" + name + '\'' +
'}';
}
}
......@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
......@@ -54,4 +55,8 @@ public interface BookGroupClassifyService {
@ApiOperation("过滤被删除的群分类、群二维码")
@PostMapping("filterDeleteId")
ResponseEntity<ResponseDto<List<Long>>> filterDeleteId(@RequestBody List<String >wxGroupIdList);
@ApiOperation("获取用户支付金额")
@GetMapping("getPayPrice")
ResponseEntity<ResponseDto<BigDecimal>> getPayPrice(@RequestParam("qrcodeId") Long qrcodeId, @RequestParam("wxUserId") String wxUserId);
}
......@@ -3,12 +3,11 @@ package com.pcloud.book.group.service;
import java.util.List;
import java.util.Map;
import com.pcloud.book.group.dto.GroupCipherDTO;
import com.pcloud.book.group.dto.GroupUseDTO;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
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.*;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.dto.StoreFlowInfoDto;
......@@ -52,4 +51,19 @@ public interface BookGroupService {
@RequestMapping(value = "getBaseInfoBySceneId",method = RequestMethod.GET)
ResponseEntity<ResponseDto<BookGroupDTO>> getBaseInfoBySceneId(@RequestParam("sceneId")Long sceneId) throws BizException;
@ApiOperation("获取暗号状态")
@GetMapping("/getCipherState")
ResponseEntity<ResponseDto<Integer>> getCipherState(@RequestParam("cipher")String cipher) throws BizException;
@ApiOperation("更新暗号状态为已使用")
@GetMapping("/updateCipherStateToUsed")
void updateCipherStateToUsed(@RequestParam("cipher")String cipher, @RequestParam("wxId")String wxId) throws BizException;
@ApiOperation("获取个人二维码方式群已使用和未使用数量")
@PostMapping("/getGroupUse")
ResponseEntity<ResponseDto<GroupUseDTO>> getGroupUse(@RequestBody List<String> altIds) throws BizException;
@ApiOperation("获取暗号基本信息")
@GetMapping("/getJoinGroupCipher")
ResponseEntity<ResponseDto<GroupCipherDTO>> getJoinGroupCipher(@RequestParam("cipher")String cipher) throws BizException;
}
......@@ -198,4 +198,17 @@ public class BookApplication {
public Binding wxGroupLearningReportBind() {
return RabbitMQFactory.bindingExchange(wxGroupLearningReportQueue(), MQTopicProducer.WXGROUP_LEARNING_REPORT);
}
/**
* 微信个人机器人同意加好友
*/
@Bean
public Queue wxGroupAgreeAddUserQueue() {
return RabbitMQFactory.queueBuilder(MQTopicConumer.WX_AGREE_ADD_USER);
}
@Bean
public Binding wxGroupAgreeAddUserBind() {
return RabbitMQFactory.bindingExchange(wxGroupAgreeAddUserQueue(), MQTopicProducer.WX_AGREE_ADD_USER);
}
}
......@@ -312,7 +312,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(findIp(weixinGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
LOGGER.info("发送编辑端早晚报" + sendTextMessageVO.toString());
......
......@@ -758,7 +758,7 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
}
}
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setGroupId(groupId);
sendTextMessageVO.setWxGroupId(groupId);
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setContent(adTitle);
sendTextMessageVO.setIp(findIp(groupId));
......@@ -769,7 +769,7 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
sendArticleMessageVO.setAltId(altId);
sendArticleMessageVO.setTitle(advertisingSpace.getAdTitle());
sendArticleMessageVO.setDescription(advertisingSpace.getAdSlogan());
sendArticleMessageVO.setGroupId(groupId);
sendArticleMessageVO.setWxGroupId(groupId);
String adLink = "";
if (!StringUtil.isEmpty(advertisingSpace.getAdLink())) {
if (advertisingSpace.getAdLink().contains("?")) {
......@@ -791,7 +791,7 @@ public class AdvertisingSpaceBizImpl implements AdvertisingSpaceBiz {
} else if (AdPositionModeEnum.JUST_PIC.modeCode.equals(advertisingSpace.getAdPositionMode())) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setAltId(altId);
sendPicMessageVO.setGroupId(groupId);
sendPicMessageVO.setWxGroupId(groupId);
sendPicMessageVO.setPicUrl(advertisingSpace.getAdPic());
sendPicMessageVO.setIp(findIp(groupId));
LOGGER.info("发送微信消息-纯图片" + sendPicMessageVO.toString());
......
......@@ -377,7 +377,7 @@ public class BookClockBizImpl implements BookClockBiz {
//获取机器人微信号
String altId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setContent(bookClockInfoDTO.getNoticeContent());
if(!MapUtils.isEmpty(wxQrcodeDTOMap) && wxQrcodeDTOMap.containsKey(weixinGroupId)){
......
......@@ -15,7 +15,10 @@ import com.pcloud.wechatgroup.group.service.GroupMemberService;
import com.pcloud.wechatgroup.message.dto.GroupChatCountDTO;
import com.pcloud.wechatgroup.message.service.MessageService;
import com.pcloud.wechatgroup.monitor.service.MonitorService;
import com.pcloud.wechatgroup.selfrobot.service.SelfRobotService;
import com.pcloud.wechatgroup.selfrobot.dto.SelfRobotDTO;
import com.pcloud.wechatgroup.selfrobot.service.SelfRobotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
......@@ -38,6 +41,44 @@ public class WechatGroupConsr {
private MessageService messageService;
@Autowired
private MonitorService monitorService;
@Autowired
private SelfRobotService selfRobotService;
@ParamLog("根据机器人id和用户微信id获取最新暗号")
public String getCipherByRobotAndUserWxId(String robotWxId, String userWxId) {
if (StringUtil.isBlank(robotWxId) || StringUtil.isBlank(userWxId)) {
return null;
}
try {
return ResponseHandleUtil.parseResponse(selfRobotService.getCipherByRobotAndUserWxId(robotWxId, userWxId), String.class);
} catch (BizException e) {
log.warn("根据机器人id和用户微信id获取最新暗号失败:" + e.getMessage(), e);
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
log.error("根据机器人id和用户微信id获取最新暗号.[getCipherByRobotAndUserWxId]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_RES_ERROR, "服务内部错误,请稍后重试");
} finally {
log.info("【根据机器人id和用户微信id获取最新暗号,<END>");
}
}
@ParamLog("是否群机器人")
public Boolean isGroupRobot(String robotWxId) {
if (StringUtil.isBlank(robotWxId)) {
return null;
}
try {
return ResponseHandleUtil.parseResponse(selfRobotService.isGroupRobot(robotWxId), Boolean.class);
} catch (BizException e) {
log.warn("是否群机器人失败:" + e.getMessage(), e);
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
log.error("是否群机器人.[isGroupRobot]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_RES_ERROR, "服务内部错误,请稍后重试");
} finally {
log.info("【是否群机器人,<END>");
}
}
/**
* 是否黑名单
......@@ -271,6 +312,16 @@ public class WechatGroupConsr {
return map;
}
@ParamLog(value = "获取可用机器人")
public SelfRobotDTO getAvailableRobot(Long wechatUserId, Integer largeTemplet, Long classifyId) {
SelfRobotDTO selfRobotDTO = null;
try {
selfRobotDTO = ResponseHandleUtil.parseResponse(selfRobotService.getAvailableRobot(wechatUserId, largeTemplet, classifyId), SelfRobotDTO.class);
} catch (Exception e) {
log.error("获取可用机器人.[getAvailableRobot]:" + e.getMessage(), e);
}
return selfRobotDTO;
}
@ParamLog("根据用户微信ID获取用户信息")
public GroupUserDTO getWxUserInfoByWxUserId(String wxUserId) {
GroupUserDTO dto = new GroupUserDTO();
......
package com.pcloud.book.group.biz;
import com.pcloud.book.book.dto.BookDto;
import com.pcloud.book.group.dto.*;
import com.pcloud.book.group.dto.AppStatisticsDTO;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.ClassifyKeywordDTO;
import com.pcloud.book.group.dto.GroupStoreMyPayDto;
import com.pcloud.book.group.dto.QrcodeNameAndProIdDTO;
import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.vo.*;
import com.pcloud.book.group.vo.StatisticVO;
import com.pcloud.common.dto.StoreFlowInfoDto;
......@@ -256,6 +256,42 @@ public interface BookGroupBiz {
* 获取是否显示书名
*/
Boolean getIsShowBookName(Long partyId);
/**
* 根据分类id获取个人二维码信息
*/
OwnAltQrcodeInfoDTO getOwnAltQrcodeInfoDTOByClassifyId(Long wechatUserId, Long classifyId);
/**
* 获取暗号状态
*/
Integer getCipherState(String cipher);
/**
* 更新状态为已使用
*/
void updateCipherStateToUsed(String cipher, String wxId);
/**
* 获取个人二维码方式群已使用和未使用数量
*/
GroupUseDTO getGroupUse(List<String> altIds);
/**
* 获取所有的大类分类
*/
List<LargeTempletDTO> getAllLargTemplet();
/**
* 根据微信id和机器人id获取分类集合
*/
List<JoinGroupCipherDTO> getClassifyIdsByWxIdAndAltId(String wxId,String altId);
/**
* 获取暗号基本信息
*/
GroupCipherDTO getJoinGroupCipher(String cipher);
/**
* 为信息流批量获取社群书基本信息
*/
......
package com.pcloud.book.group.biz;
import com.pcloud.book.group.dto.*;
import com.pcloud.book.group.dto.BookGroupStatisticDTO;
import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.group.dto.ClassifyLearningReportDto;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.GroupNameAndMaxSeqDTO;
import com.pcloud.book.group.dto.GroupQrcodeBaseDTO;
import com.pcloud.book.group.dto.ProAssocGroupAndUserNumberDTO;
import com.pcloud.book.group.entity.BookGroupClassify;
import com.pcloud.book.group.vo.*;
import com.pcloud.book.group.vo.AddClassifyVO;
import com.pcloud.book.group.vo.AdviserClassifyParam;
import com.pcloud.book.group.vo.AdviserClassifyVO;
import com.pcloud.book.group.vo.BookGroupClassifyVO;
import com.pcloud.book.group.vo.BookGroupQrcodeStatisticVO;
import com.pcloud.book.group.vo.ClassifyAndGroupCountVO;
import com.pcloud.book.group.vo.ClassifyAndUserCountVO;
import com.pcloud.book.group.vo.ClassifyNameVO;
import com.pcloud.book.group.vo.ClassifyVO;
import com.pcloud.book.group.vo.GroupQrcode4ClassifyVO;
import com.pcloud.book.group.vo.ListBookGroupQrcodeParamVO;
import com.pcloud.book.group.vo.ListClassify4WechatVO;
import com.pcloud.book.group.vo.ListClassifyVO;
import com.pcloud.book.group.vo.ListGroupClassifyParam;
import com.pcloud.book.group.vo.StatisticVO;
import com.pcloud.book.group.vo.UpdateClassifyVO;
import com.pcloud.book.group.vo.UpdateRankVO;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
......@@ -106,6 +129,11 @@ public interface BookGroupClassifyBiz {
List<ListClassify4WechatVO> listClassify4Wechat(Long bookGroupId, Long wechatUserId);
/**
* 批量获取分类信息
*/
List<GroupClassifyQrcodeDTO> listClassifyQrcodeInfo(List<Long> classifyIds);
/**
* @Author:lili
* @Desr:客户端根据群分类获取二维码
* @Date:2019/4/29 17:21
......@@ -113,6 +141,11 @@ public interface BookGroupClassifyBiz {
GroupQrcode4ClassifyVO getGroupQrcode4ClassifyWechat(Long classifyId, Long wechatUserId);
/**
* 用户获取具体进群id
*/
String getWxGroupIdByClassifyIdAndWechatId(Long classifyId, Long wechatUserId);
/**
* @Author:lili
* @Desr:获取编辑所有的分类
* @Date:2019/4/30 15:33
......@@ -180,6 +213,14 @@ public interface BookGroupClassifyBiz {
PageBeanNew<ClassifyLearningReportDto> listClassifyForLearningReport(Integer currentPage, Integer numPerPage, String keyword, Long partyId);
/**
* 用户支付金额
* @param qrcodeId
* @param wxId
* @return
*/
public BigDecimal getPayPrice(Long qrcodeId, String wxId);
/**
* 拖动排序
*/
void dragSortClassify(List<Long> classifyIds);
......
......@@ -20,8 +20,16 @@ import com.pcloud.book.consumer.resource.ProductConsr;
import com.pcloud.book.consumer.settlement.SettlementConsr;
import com.pcloud.book.consumer.trade.TradeConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.dao.*;
import com.pcloud.book.group.dto.*;
import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.book.group.entity.TempletRelevance;
import com.pcloud.book.group.enums.LargTempletEnum;
import com.pcloud.book.group.vo.StatisticVO;
import com.pcloud.book.group.dao.AppClickRecordDao;
import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
......@@ -53,10 +61,7 @@ import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBean;
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.QrcodeUtils;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.common.utils.*;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.common.utils.zip.CompressUtils;
import com.pcloud.facade.tradecenter.dto.GroupMoneyDto;
......@@ -77,6 +82,7 @@ import com.pcloud.settlementcenter.record.service.SettlementService;
import com.pcloud.videolesson.schedule.service.ScheduleService;
import com.pcloud.wechatgroup.group.service.GroupMemberService;
import com.pcloud.wechatgroup.selfrobot.dto.SelfRobotDTO;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -85,6 +91,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
......@@ -160,6 +167,14 @@ public class BookGroupBizImpl implements BookGroupBiz {
private TimeTableService timeTableService;
@Autowired
private AppPriceCacheService appPriceCacheService;
@Autowired
private TempletRelevanceDao templetRelevanceDao;
@Autowired
private JoinGroupCipherDao joinGroupCipherDao;
@Autowired
private WechatGroupConsr wechatGroupConsr;
@Autowired
private WeixinQrcodeDao weixinQrcodeDao;
@Override
......@@ -373,7 +388,7 @@ public class BookGroupBizImpl implements BookGroupBiz {
public void updateBookGroup(BookGroup bookGroup) throws BizException {
if (null == bookGroup.getId() || StringUtil.isEmpty(bookGroup.getGroupQrcodeName()) || null == bookGroup.getProLabelId()
|| null == bookGroup.getDepLabelId() || null == bookGroup.getPurLabelId() || StringUtil.isEmpty(bookGroup.getJoinTitle())
|| StringUtil.isEmpty(bookGroup.getJoinSlogan()) || StringUtil.isEmpty(bookGroup.getPersonalQrcodeUrl())) {
|| StringUtil.isEmpty(bookGroup.getJoinSlogan()) ) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数有误!");
}
BookGroup group = bookGroupDao.getById(bookGroup.getId());
......@@ -840,6 +855,7 @@ public class BookGroupBizImpl implements BookGroupBiz {
wechatGroupDtoP.setType("PRODUCT");
wechatGroupDtoP.setQrcodeId(qrcodeId);
Map<Long, GroupMoneyDto> productSaleMap = tradeConsr.getQrGroupSaleMoney(wechatGroupDtoP);
Map<Long, BigDecimal> productIncomeMap = settlementConsr.getAdviserIncomeByCondition(valProductIds, "PRODUCT", partyId, qrcodeId, bookGroupId);
SpeWechatGroupDto speWechatGroupDto=new SpeWechatGroupDto();
speWechatGroupDto.setBookGroupId(bookGroupId);
speWechatGroupDto.setPartyId(partyId);
......@@ -851,10 +867,11 @@ public class BookGroupBizImpl implements BookGroupBiz {
speWechatGroupDto.setProductIdMap(map);
Map<Long, GroupMoneyDto> forBuyCountMap = tradeConsr.getSpeQrGroupSaleMoney(speWechatGroupDto);
Map<Long, Double> proSaleMap = new HashMap<>();
Map<Long, Double> proIncomeMap = new HashMap<>();
if (productSaleMap.values() != null && !productSaleMap.values().isEmpty()) {
dealSale(videoProductIds, videoPProductMapIds, productSaleMap, proSaleMap);
dealSale(audioProductIds, audioPProductMapIds, productSaleMap, proSaleMap);
dealSale(liveProductIds, livePProductMapIds, productSaleMap, proSaleMap);
dealSale(videoProductIds, videoPProductMapIds, productSaleMap, proSaleMap, productIncomeMap, proIncomeMap);
dealSale(audioProductIds, audioPProductMapIds, productSaleMap, proSaleMap, productIncomeMap, proIncomeMap);
dealSale(liveProductIds, livePProductMapIds, productSaleMap, proSaleMap, productIncomeMap, proIncomeMap);
for (AppStatisticsDTO appStatisticsDTO : appStatisticsDTOS) {
Long id = appStatisticsDTO.getServeId();
String type = appStatisticsDTO.getServeType();
......@@ -864,14 +881,14 @@ public class BookGroupBizImpl implements BookGroupBiz {
if (groupMoneyDto != null && groupMoneyDto.getSaleCount() != null) {
toAddCount = groupMoneyDto.getSaleCount().intValue();
}
addProductSale(id, productDtoMap, proSaleMap, toAddCount, appStatisticsDTO);
addProductSale(id, productDtoMap, proSaleMap, proIncomeMap, toAddCount, appStatisticsDTO);
}
}
}
}
}
private void addProductSale(Long id, Map<Long, ProductDto> productDtoMap, Map<Long, Double> proSaleMap, Integer toAddCount, AppStatisticsDTO appStatisticsDTO) {
private void addProductSale(Long id, Map<Long, ProductDto> productDtoMap, Map<Long, Double> proSaleMap, Map<Long, Double> proIncomeMap, Integer toAddCount, AppStatisticsDTO appStatisticsDTO) {
ProductDto productDto = productDtoMap.get(id);
String[] videoTypes = {"VIDEO_COURSE", "VIDEO_SCHEDULE"};
String[] audioTypes = {"AUDIOAPP", "AUDIO_RESOURCE", "AUDIO_SCHEDULE", "AUDIO_COURSE"};
......@@ -884,6 +901,7 @@ public class BookGroupBizImpl implements BookGroupBiz {
|| Arrays.asList(audioTypes).contains(typeCode)
|| Arrays.asList(liveTypes).contains(typeCode))) {
Double toAdd = proSaleMap.get(id);
Double incomeToAdd = proIncomeMap.get(id);
if (toAdd != null) {
Double oldSale = appStatisticsDTO.getSaleAmount();
if (oldSale == null) {
......@@ -891,6 +909,13 @@ public class BookGroupBizImpl implements BookGroupBiz {
}
appStatisticsDTO.setSaleAmount(oldSale + toAdd);
}
if (incomeToAdd != null) {
Double oldIncome = appStatisticsDTO.getIncomeAmount();
if (oldIncome == null) {
oldIncome = 0D;
}
appStatisticsDTO.setIncomeAmount(oldIncome + incomeToAdd);
}
if (toAddCount != null) {
Integer oldBuy = appStatisticsDTO.getBuyCount();
if (oldBuy == null) {
......@@ -909,13 +934,14 @@ public class BookGroupBizImpl implements BookGroupBiz {
}
}
private void dealSale(List<Long> ids, Map<Long,List<Long>> productMapIds, Map<Long,GroupMoneyDto> productSaleMap, Map<Long,Double> saleMap) {
private void dealSale(List<Long> ids, Map<Long,List<Long>> productMapIds, Map<Long,GroupMoneyDto> productSaleMap, Map<Long,Double> saleMap, Map<Long, BigDecimal> productIncomeMap, Map<Long, Double> incomeMap) {
if (!ListUtils.isEmpty(ids)) {
for (Long id : ids) {
List<Long> productIds = productMapIds.get(id);
if (!ListUtils.isEmpty(productIds)) {
Double saleMoney = 0D;
Long saleCount = 0L;
Double incomeMoney = 0D;
for (Long productId : productIds) {
GroupMoneyDto groupMoneyDto = productSaleMap.get(productId);
if (groupMoneyDto != null) {
......@@ -926,8 +952,12 @@ public class BookGroupBizImpl implements BookGroupBiz {
saleCount = saleCount + groupMoneyDto.getSaleCount();
}
}
if (productIncomeMap != null && productIncomeMap.get(productId) != null) {
incomeMoney = incomeMoney + productIncomeMap.get(productId).doubleValue();
}
}
saleMap.put(id, saleMoney);
incomeMap.put(id, incomeMoney);
}
}
}
......@@ -1109,6 +1139,145 @@ public class BookGroupBizImpl implements BookGroupBiz {
return bookGroupDao.getIsShowBookName(partyId);
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("根据分类id获取个人二维码信息")
@Override
public OwnAltQrcodeInfoDTO getOwnAltQrcodeInfoDTOByClassifyId(Long wechatUserId, Long classifyId) {
OwnAltQrcodeInfoDTO ownAltQrcodeInfoDTO = new OwnAltQrcodeInfoDTO();
//根据分类id查询社群码信息
ClassifyDTO classifyDTO = bookGroupClassifyDao.getById(classifyId);
if (classifyDTO == null) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "没有该分类");
}
Long bookId = classifyDTO.getBookId();
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("bookId", bookId);
paramMap.put("adviserId", classifyDTO.getCreateUser());
paramMap.put("channelId", classifyDTO.getChannelId());
BookDto bookDto = bookDao.getById(paramMap);
Long templetId = bookDto.getTempletId();
//根据分类id获取大类
TempletRelevance templetRelevance = templetRelevanceDao.getByTempletId(templetId);
LOGGER.info("根据分类id获取大类templetRelevance" + templetRelevance.toString());
Integer largeTemplet = templetRelevance.getLargeTemplet();
SelfRobotDTO selfRobotDTO = wechatGroupConsr.getAvailableRobot(wechatUserId, largeTemplet, classifyId);
if (selfRobotDTO == null) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "未找到机器人!");
}
ownAltQrcodeInfoDTO.setAltHeadUrl(selfRobotDTO.getHeadPic());
ownAltQrcodeInfoDTO.setAltId(selfRobotDTO.getWxId());
ownAltQrcodeInfoDTO.setAltNickName(selfRobotDTO.getNickName());
ownAltQrcodeInfoDTO.setAltQrcodeUrl(selfRobotDTO.getQrcodeUrl());
ownAltQrcodeInfoDTO.setAltHeadUrl(selfRobotDTO.getHeadPic());
//获取之前是否有没有使用的暗号
JoinGroupCipher joinGroupCipher = joinGroupCipherDao.getByWechatUserId(wechatUserId, classifyId);
String cipher;
if (joinGroupCipher != null) {
cipher = joinGroupCipher.getCipher();
} else {
//新增暗号
cipher = UUIDUitl.generateShort();
//查重,如果有重复,再次生成
JoinGroupCipher joinGroupCipherHas = joinGroupCipherDao.getByCipher(cipher);
if (joinGroupCipherHas != null) {
cipher = UUIDUitl.generateShort();
}
cipher = "RAYS_" + cipher;
JoinGroupCipher joinGroupCipherNew = new JoinGroupCipher();
joinGroupCipherNew.setCipher(cipher);
joinGroupCipherNew.setWechatUserId(wechatUserId);
joinGroupCipherNew.setClassifyId(classifyId);
joinGroupCipherNew.setAltId(selfRobotDTO.getWxId());
joinGroupCipherDao.insert(joinGroupCipherNew);
}
ownAltQrcodeInfoDTO.setCipher(cipher);
return ownAltQrcodeInfoDTO;
}
@ParamLog("获取暗号状态")
@Override
public Integer getCipherState(String cipher) {
Integer state;
if (StringUtil.isEmpty(cipher)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数不能为空!");
}
JoinGroupCipher joinGroupCipher = joinGroupCipherDao.getByCipher(cipher);
if (joinGroupCipher == null) {
//暗号错误
state = 2;
} else if (joinGroupCipher.getHasUsed() != null && joinGroupCipher.getHasUsed()) {
//已使用
state = 1;
} else {
//未使用
state = 0;
}
return state;
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("获取暗号状态为已使用")
@Override
public void updateCipherStateToUsed(String cipher, String wxId) {
if (StringUtil.isEmpty(cipher) || StringUtil.isEmpty(wxId)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数不能为空!");
}
joinGroupCipherDao.updateCipherStateToUsed(cipher,wxId);
}
@ParamLog("获取个人二维码方式群已使用和未使用数量")
@Override
public GroupUseDTO getGroupUse(List<String> altIds) {
if (ListUtils.isEmpty(altIds)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数不能为空!");
}
GroupUseDTO groupUseDTO = new GroupUseDTO();
Integer notUsed = weixinQrcodeDao.countByState(0, altIds);
Integer hasUsed = weixinQrcodeDao.countByState(1, altIds);
Integer full = weixinQrcodeDao.countByState(2, altIds);
groupUseDTO.setHasUsed(hasUsed + full);
groupUseDTO.setNotUsed(notUsed);
return groupUseDTO;
}
@ParamLog("获取所有的大类分类")
@Override
public List<LargeTempletDTO> getAllLargTemplet() {
List<LargeTempletDTO> list = new ArrayList<>();
for (LargTempletEnum largTempletEnum : LargTempletEnum.values()) {
LargeTempletDTO largeTempletDTO = new LargeTempletDTO();
largeTempletDTO.setLargeTemplet(largTempletEnum.code);
largeTempletDTO.setName(largTempletEnum.name);
list.add(largeTempletDTO);
}
return list;
}
@ParamLog("根据微信id和机器人id获取分类集合")
@Override
public List<JoinGroupCipherDTO> getClassifyIdsByWxIdAndAltId(String wxId, String altId) {
if (StringUtil.isEmpty(wxId) || StringUtil.isEmpty(altId)) {
return new ArrayList<>();
}
List<JoinGroupCipherDTO> list = joinGroupCipherDao.getClassifyIdsByWxIdAndAltId(wxId, altId);
return CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list;
}
@ParamLog("获取暗号基本信息")
@Override
public GroupCipherDTO getJoinGroupCipher(String cipher) {
if (StringUtil.isEmpty(cipher)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数不能为空!");
}
JoinGroupCipher joinGroupCipher = joinGroupCipherDao.getByCipher(cipher);
if (joinGroupCipher != null) {
GroupCipherDTO groupCipherDTO = new GroupCipherDTO();
BeanUtils.copyProperties(joinGroupCipher, groupCipherDTO);
return groupCipherDTO;
}
return null;
}
@ParamLog("为信息流批量获取社群书基本信息")
@Override
public Map<Long, StoreFlowInfoDto> getFlowInfoByBookGroupIds(List<Long> bookGroupIds) {
......
......@@ -10,22 +10,55 @@ import com.pcloud.book.consumer.resource.ProductConsr;
import com.pcloud.book.consumer.settlement.SettlementConsr;
import com.pcloud.book.consumer.trade.TradeConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.*;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.biz.GroupAnnouncementBiz;
import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dao.BookClassifyBuyRecordDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
import com.pcloud.book.group.dao.BookQrcodeUserDao;
import com.pcloud.book.group.dao.*;
import com.pcloud.book.group.dto.*;
import com.pcloud.book.group.dao.JoinGroupCipherDao;
import com.pcloud.book.group.dao.LearningReportBrowseRecordDao;
import com.pcloud.book.group.dao.LearningReportTouchRecordDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookGroupStatisticDTO;
import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.group.dto.ClassifyLearningCountDto;
import com.pcloud.book.group.dto.ClassifyLearningReportDto;
import com.pcloud.book.group.dto.GroupAndUserNumberDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.GroupNameAndMaxSeqDTO;
import com.pcloud.book.group.dto.GroupQrcodeBaseDTO;
import com.pcloud.book.group.dto.GroupQrcodeInfoDTO;
import com.pcloud.book.group.dto.ProAssocGroupAndUserNumberDTO;
import com.pcloud.book.group.dto.QrcodeNameAndProIdDTO;
import com.pcloud.book.group.dto.WeixinQrcodeDTO;
import com.pcloud.book.group.entity.BookGroupClassify;
import com.pcloud.book.group.entity.BookQrcodeUser;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.enums.RankTypeEnum;
import com.pcloud.book.group.set.GroupSet;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.group.vo.*;
import com.pcloud.book.group.vo.AddClassifyVO;
import com.pcloud.book.group.vo.AdviserClassifyParam;
import com.pcloud.book.group.vo.AdviserClassifyVO;
import com.pcloud.book.group.vo.BookGroupClassifyVO;
import com.pcloud.book.group.vo.BookGroupQrcodeStatisticVO;
import com.pcloud.book.group.vo.ClassifyAndGroupCountVO;
import com.pcloud.book.group.vo.ClassifyAndUserCountVO;
import com.pcloud.book.group.vo.ClassifyNameVO;
import com.pcloud.book.group.vo.ClassifyVO;
import com.pcloud.book.group.vo.GroupQrcode4ClassifyVO;
import com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO;
import com.pcloud.book.group.vo.ListBookGroupQrcodeParamVO;
import com.pcloud.book.group.vo.ListClassify4WechatVO;
import com.pcloud.book.group.vo.ListClassifyVO;
import com.pcloud.book.group.vo.ListGroupClassifyParam;
import com.pcloud.book.group.vo.StatisticVO;
import com.pcloud.book.group.vo.SyncKeyworsVO;
import com.pcloud.book.group.vo.UpdateClassifyVO;
import com.pcloud.book.group.vo.UpdateRankVO;
import com.pcloud.book.keywords.dao.BookKeywordDao;
import com.pcloud.book.keywords.entity.BookKeyword;
import com.pcloud.book.util.common.ThreadPoolUtils;
......@@ -120,6 +153,8 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
private LearningReportBrowseRecordDao learningReportBrowseRecordDao;
@Autowired
private LearningReportTouchRecordDao learningReportTouchRecordDao;
@Autowired
private JoinGroupCipherDao joinGroupCipherDao;
@Override
......@@ -144,7 +179,6 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
if (qrcodeNameAndProId == null) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "请先填写社群码信息!");
}
String groupName = qrcodeNameAndProId.getGroupQrcodeName();
bookGroupClassify.setProductId(qrcodeNameAndProId.getProductId());
bookGroupClassify.setCreateUser(partyId);
Integer rank = bookGroupClassifyDao.getMaxRank(addClassifyVO.getBookGroupId());
......@@ -166,7 +200,16 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
groupQrcode.setWeixinQrcodeId(oneQrcode.getId());
groupQrcode.setUserNumber(oneQrcode.getUserNumber());
groupQrcode.setGroupSeq(1);
groupQrcode.setGroupName(groupName + addClassifyVO.getClassify() + "1群");
// 群长度超过16部分会被截取,导致群名称重复
final String s = "1群";
String groupName = qrcodeNameAndProId.getGroupQrcodeName() + addClassifyVO.getClassify() + s;
if (groupName.length() > 15) {
groupName = addClassifyVO.getClassify() + s;
if (groupName.length() > 15) {
groupName = addClassifyVO.getClassify().substring(0, 16 - s.length()) + s;
}
}
groupQrcode.setGroupName(groupName);
groupQrcode.setClassifyId(bookGroupClassify.getId());
groupQrcode.setQrcodeHeadUrl(readerConsr.getNineHeadUrl());
groupQrcodeBiz.insert(groupQrcode);
......@@ -430,6 +473,12 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
}
@Override
@ParamLog("获取分类二维码相关标识")
public List<GroupClassifyQrcodeDTO> listClassifyQrcodeInfo(List<Long> classifyIds) {
return bookGroupClassifyDao.listClassifyQrcodeInfo(classifyIds);
}
@Override
@ParamLog("客户端获取分类信息")
public List<ListClassify4WechatVO> listClassify4Wechat(Long bookGroupId, Long wechatUserId) {
//获取排序方式
......@@ -511,6 +560,19 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
return groupQrcode4ClassifyVO;
}
@Override
public String getWxGroupIdByClassifyIdAndWechatId(Long classifyId, Long wechatUserId) {
if(null == classifyId || null == wechatUserId) {
return null;
}
final GroupQrcode4ClassifyVO wechat = this.getGroupQrcode4ClassifyWechat(classifyId, wechatUserId);
if(null == wechat) {
return null;
}
final GroupQrcodeBaseInfoVO baseById = this.groupQrcodeBiz.getBaseById(wechat.getGroupQrcodeId());
return (null == baseById) ? null : baseById.getWeixinGroupId();
}
@ParamLog("获取备用二维码")
private String getSpareQr(Long bookGroupId) {
//获取备用二维码
......@@ -964,6 +1026,11 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
}
@Override
public BigDecimal getPayPrice(Long qrcodeId, String wxId) {
return joinGroupCipherDao.getPayPrice(wxId, qrcodeId);
}
@ParamLog("拖动排序")
@Transactional(rollbackFor = Exception.class)
@Override
......
......@@ -13,7 +13,9 @@ import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.biz.GroupAnnouncementBiz;
import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.constants.BookBusinessConstants;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.AutoUpdateGroupNumDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.ChangeGroupNameDTO;
import com.pcloud.book.group.dto.GroupAndUserNumberDTO;
......@@ -65,6 +67,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
......@@ -103,6 +108,72 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
private LabelConsr labelConsr;
/**
* 自动更新群人数线程是否开始执行
*/
private static final AtomicBoolean IS_START = new AtomicBoolean(false);
/**
* 处理群人数线程池
*/
private static final ExecutorService SINGLE_THREAD_EXECUTOR = Executors.newSingleThreadExecutor();
/**
* 更新群人数线程
*/
private void updateGroupNum() {
// 若已开始则无需再启动
if(IS_START.get()) {
return;
}
// 若设置时已经为true则代表已经有线程执行成功
final boolean andSet = IS_START.getAndSet(true);
if (andSet) {
return;
}
SINGLE_THREAD_EXECUTOR.execute(() -> {
while (true) {
try{
if (BookBusinessConstants.GROUP_NUM_DTO_MAP.size() < 1) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
log.error("[updateGroupNum] InterruptedException:{}", e);
}
continue;
}
log.info("[更新群人数] start GROUP_NUM_DTO_MAP:{}", BookBusinessConstants.GROUP_NUM_DTO_MAP);
for (Map.Entry<String, AutoUpdateGroupNumDTO> entry : BookBusinessConstants.GROUP_NUM_DTO_MAP.entrySet()) {
final AutoUpdateGroupNumDTO value = entry.getValue();
// 没到时间不执行(小于30s并且小于3个人不执行)
final boolean b = null == value || ((System.currentTimeMillis() + 10) < value.getStartTime().getTime() && value.getNum().get() < 3);
if(b) {
log.info("[更新群人数] null == value:{}", entry);
continue;
}
Integer peopleCounts = WxGroupSDK.getPeopleCounts(value.getWxGroupId(), value.getRobotId(), value.getIp());
if (null == peopleCounts || peopleCounts < 1) {
log.info("[更新群人数] null == peopleCounts || peopleCounts < 1 entry:{}; peopleCounts:{}", entry, peopleCounts);
continue;
}
log.info("[更新群人数] entry:{}, peopleCounts:{}", entry, peopleCounts);
groupQrcodeDao.updateUserNumber(value.getWxGroupId(), peopleCounts);
BookBusinessConstants.GROUP_NUM_DTO_MAP.remove(entry.getKey());
}
} catch (Exception e) {
log.error("[updateGroupNum] : Exception:{}", e);
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
log.error("[updateGroupNum] InterruptedException:{}", e);
}
}
});
}
@Override
@ParamLog("updateGroupQrcode")
public void updateGroupQrcode(UpdateGroupQrcodeRequestVO vo) {
......@@ -240,11 +311,23 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
}
//获取群基本信息
GroupQrcodeDTO groupQrcodeDTO = groupQrcodeDao.getGroupQrcodeInfo(weixinGroupId);
log.info("[新增一个用户] groupQrcodeDTO:{}", groupQrcodeDTO);
if (groupQrcodeDTO == null) {
return;
}
//更新用户数
groupQrcodeDao.updateUserNumber(weixinGroupId, memberCount);
//更新用户数(由于微信有延迟及时更新可能会数据对不上,所以调用方法延迟30s,统一处理)
AutoUpdateGroupNumDTO numDTO = BookBusinessConstants.GROUP_NUM_DTO_MAP.get(weixinGroupId);
if (null == numDTO){
numDTO = new AutoUpdateGroupNumDTO(weixinGroupId, robotId, ip, new Date());
} else {
numDTO.getNum().incrementAndGet();
numDTO.setStartTime(new Date());
}
BookBusinessConstants.GROUP_NUM_DTO_MAP.put(weixinGroupId, numDTO);
// 启动更新群人数线程
if (!IS_START.get()) {
this.updateGroupNum();
}
//如果人数超过限制,重新分配群
if (memberCount >= groupQrcodeDTO.getChangeNumber() && QrcodeStatusEnum.ON_USE.value.equals(groupQrcodeDTO.getQrcodeState())) {
//修改状态,重新分配一个群
......@@ -397,24 +480,28 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
/**
* 重新分配一个群
*/
@ParamLog("重新分配一个群")
@Transactional(rollbackFor = Exception.class)
public void addWechatGroup(Long classifyId, Long groupQrcodeId) {
WeixinQrcodeDTO oneQrcode = weixinQrcodeBiz.getOneQrcode();
log.info("[重新分配一个群] : oneQrcode:{}", oneQrcode);
if (oneQrcode != null) {
//将二维码改为已满群状态
Integer number = groupQrcodeDao.changeQrcodeState(groupQrcodeId, QrcodeStatusEnum.OVER_NUMBER.value);
log.info("[重新分配一个群] : groupQrcodeDao.changeQrcodeState number:{}", number);
if (number > 0){
//获取标签对应基本信息
GroupNameAndMaxSeqDTO groupNameAndMaxSeqDTO = bookGroupClassifyBiz.getGroupNameAndMaxSeq(classifyId);
log.info("[重新分配一个群] : groupNameAndMaxSeqDTO:{}", groupNameAndMaxSeqDTO);
if (groupNameAndMaxSeqDTO != null) {
Integer maxSeq = groupNameAndMaxSeqDTO.getMaxSeq() + 1;
String groupName = groupNameAndMaxSeqDTO.getGroupQrcodeName() + groupNameAndMaxSeqDTO.getClassify() + maxSeq + "群";
// 群长度超过16部分会被截取,导致群名称重复
if (groupName.length() > 16) {
if (groupName.length() > 15) {
final String s = maxSeq + "群";
groupName = groupNameAndMaxSeqDTO.getClassify() + s;
if (groupName.length() > 16) {
groupName = groupNameAndMaxSeqDTO.getClassify().substring(0, 16 - s.length()) + s;
if (groupName.length() > 15) {
groupName = groupNameAndMaxSeqDTO.getClassify().substring(0, 15 - s.length()) + s;
}
}
GroupQrcode groupQrcode = new GroupQrcode();
......
package com.pcloud.book.group.constants;
import com.pcloud.book.group.dto.AutoUpdateGroupNumDTO;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* book业务常量类
*/
public class BookBusinessConstants {
/**
* 需更新微信群信息
*/
public static final Map<String, AutoUpdateGroupNumDTO> GROUP_NUM_DTO_MAP = new ConcurrentHashMap<>(128);
}
......@@ -132,6 +132,11 @@ public interface BookGroupClassifyDao extends BaseDao<BookGroupClassify> {
GroupClassifyQrcodeDTO getClassifyQrcodeInfo(String weixinGroupId);
/**
* 批量获取分类信息
*/
List<GroupClassifyQrcodeDTO> listClassifyQrcodeInfo(List<Long> classifyIds);
/**
* @Author:lili
* @Desr:获取所有的分类
* @Date:2019/4/29 11:23
......
package com.pcloud.book.group.dao;
import com.pcloud.book.group.dto.JoinGroupCipherDTO;
import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.common.core.dao.BaseDao;
import java.math.BigDecimal;
import java.util.List;
public interface JoinGroupCipherDao extends BaseDao<JoinGroupCipher> {
JoinGroupCipher getByWechatUserId(Long wechatUserId,Long classifyId);
JoinGroupCipher getByCipher(String cipher);
JoinGroupCipherDTO getDTOByCipher(String cipher);
void updateCipherStateToUsed(String cipher, String wxId);
List<JoinGroupCipherDTO> getClassifyIdsByWxIdAndAltId(String wxId, String altId);
void updateQrcodeId(String cipher, String wxId, Long qrcodeId);
/**
* 用户支付金额
* @param wxId
* @param qrcodeId
* @return
*/
BigDecimal getPayPrice(String wxId, Long qrcodeId);
}
package com.pcloud.book.group.dao;
import com.pcloud.book.group.entity.TempletRelevance;
import com.pcloud.common.core.dao.BaseDao;
public interface TempletRelevanceDao extends BaseDao<TempletRelevance> {
TempletRelevance getByTempletId(Long templetId);
}
......@@ -155,4 +155,9 @@ public interface WeixinQrcodeDao extends BaseDao<WeixinQrcode> {
Map<String, BookWxQrcodeDTO> listByWxGroupIds(List<String> wxGroupIds);
String getVirtualIp(Integer generation);
/**
* 根据状态获取群数量
*/
Integer countByState(Integer state, List<String> altIds);
}
......@@ -110,6 +110,11 @@ public class BookGroupClassifyDaoImpl extends BaseDaoImpl<BookGroupClassify> imp
}
@Override
public List<GroupClassifyQrcodeDTO> listClassifyQrcodeInfo(List<Long> classifyIds) {
return this.getSqlSession().selectList(this.getStatement("listClassifyQrcodeInfo"), classifyIds);
}
@Override
public List<ListClassify4WechatVO> listClassify4Wechat(Long bookGroupId, Integer rankType) {
Map<String, Object> paramMap = new HashMap();
paramMap.put("bookGroupId", bookGroupId);
......
package com.pcloud.book.group.dao.impl;
import com.pcloud.book.group.dao.JoinGroupCipherDao;
import com.pcloud.book.group.dto.JoinGroupCipherDTO;
import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/5 16:18
**/
@Component("joinGroupCipherDao")
public class JoinGroupCipherDaoImpl extends BaseDaoImpl<JoinGroupCipher> implements JoinGroupCipherDao {
@Override
public JoinGroupCipher getByWechatUserId(Long wechatUserId,Long classifyId) {
Map<String,Object> map=new HashMap<>();
map.put("wechatUserId",wechatUserId);
map.put("classifyId",classifyId);
return this.getSqlSession().selectOne(this.getStatement("getByWechatUserId"), map);
}
@Override
public JoinGroupCipher getByCipher(String cipher) {
return this.getSqlSession().selectOne(this.getStatement("getByCipher"), cipher);
}
@Override
public JoinGroupCipherDTO getDTOByCipher(String cipher) {
return this.getSqlSession().selectOne(this.getStatement("getDTOByCipher"), cipher);
}
@Override
public void updateCipherStateToUsed(String cipher, String wxId) {
Map<String,Object> map=new HashMap<>();
map.put("cipher",cipher);
map.put("wxId",wxId);
this.getSqlSession().update(this.getStatement("updateCipherStateToUsed"), map);
}
@Override
public List<JoinGroupCipherDTO> getClassifyIdsByWxIdAndAltId(String wxId, String altId) {
Map<String,Object> map=new HashMap<>();
map.put("wxId",wxId);
map.put("altId",altId);
return this.getSqlSession().selectList(this.getStatement("getClassifyIdsByWxIdAndAltId"), map);
}
@Override
public void updateQrcodeId(String cipher, String wxId, Long qrcodeId) {
Map<String,Object> map=new HashMap<>();
map.put("cipher",cipher);
map.put("wxId",wxId);
map.put("qrcodeId",qrcodeId);
this.getSqlSession().update(this.getStatement("updateQrcodeId"), map);
}
@Override
public BigDecimal getPayPrice(String wxId, Long qrcodeId) {
Map<String, Object> map = new HashMap<>();
map.put("wxId", wxId);
map.put("qrcodeId", qrcodeId);
return getSessionTemplate().selectOne(getStatement("getPayPrice"), map);
}
}
package com.pcloud.book.group.dao.impl;
import com.pcloud.book.group.dao.TempletRelevanceDao;
import com.pcloud.book.group.entity.TempletRelevance;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/5 16:19
**/
@Component("templetRelevanceDao")
public class TempletRelevanceDaoImpl extends BaseDaoImpl<TempletRelevance> implements TempletRelevanceDao {
@Override
public TempletRelevance getByTempletId(Long templetId) {
return this.getSqlSession().selectOne(this.getStatement("getByTempletId"), templetId);
}
}
......@@ -154,4 +154,12 @@ public class WeixinQrcodeDaoImpl extends BaseDaoImpl<WeixinQrcode> implements We
public String getVirtualIp(Integer generation) {
return this.getSessionTemplate().selectOne("getVirtualIp", generation);
}
@Override
public Integer countByState(Integer state, List<String> altIds) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("state", state);
paramMap.put("altIds", altIds);
return this.getSessionTemplate().selectOne("countByState", paramMap);
}
}
package com.pcloud.book.group.dto;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.Data;
/**
* 自动更新群人数DTO
*/
@Data
public class AutoUpdateGroupNumDTO {
/**
* 群id
*/
private String wxGroupId;
/**
* 机器人id
*/
private String robotId;
/**
* wxGroupIp
*/
private String ip;
/**
* 当前触发次数
*/
private AtomicInteger num = new AtomicInteger(1);
/**
* 开始更新时间(犹豫微信有延迟,所以新用户进群之后30s再次更新群人数)
*/
private Date startTime;
public AutoUpdateGroupNumDTO() {
}
public AutoUpdateGroupNumDTO(String wxGroupId, String robotId, String ip, Date startTime) {
this.wxGroupId = wxGroupId;
this.robotId = robotId;
this.ip = ip;
this.num = new AtomicInteger(1);
this.startTime = startTime;
}
}
......@@ -142,6 +142,11 @@ public class BookGroupDTO extends BaseDto {
*/
private Boolean isShowBookName;
/**
* 进群方式:1群二维码,2客服机器人
*/
private Integer joinGroupType;
public String getUrl() {
return url;
}
......@@ -359,6 +364,14 @@ public class BookGroupDTO extends BaseDto {
this.isShowBookName = isShowBookName;
}
public Integer getJoinGroupType() {
return joinGroupType;
}
public void setJoinGroupType(Integer joinGroupType) {
this.joinGroupType = joinGroupType;
}
@Override
public String toString() {
return "BookGroupDTO{" +
......@@ -388,7 +401,8 @@ public class BookGroupDTO extends BaseDto {
", bookName='" + bookName + '\'' +
", url='" + url + '\'' +
", bookClockInfoId=" + bookClockInfoId +
", isShowBookName='" + isShowBookName + '\'' +
", isShowBookName=" + isShowBookName +
", joinGroupType=" + joinGroupType +
"} " + super.toString();
}
}
\ No newline at end of file
......@@ -82,6 +82,8 @@ public class ClassifyDTO implements Serializable {
private Long bookClockInfoId;
private Long createUser;
public Integer getRank() {
return rank;
}
......@@ -194,6 +196,14 @@ public class ClassifyDTO implements Serializable {
this.bookClockInfoId = bookClockInfoId;
}
public Long getCreateUser() {
return createUser;
}
public void setCreateUser(Long createUser) {
this.createUser = createUser;
}
@Override
public String toString() {
return "ClassifyDTO{" +
......@@ -211,6 +221,7 @@ public class ClassifyDTO implements Serializable {
", changeNumber=" + changeNumber +
", rank=" + rank +
", bookClockInfoId=" + bookClockInfoId +
", createUser=" + createUser +
'}';
}
}
package com.pcloud.book.group.dto;
import lombok.Data;
@Data
public class JoinGroupCipherDTO {
private String cipher;
private Long classifyId;
private Long qrcodeId;
private Long wechatUserId;
private String wxId;
private Boolean hasUsed;
private Long bookGroupId;
}
package com.pcloud.book.group.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/5 17:14
**/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OwnAltQrcodeInfoDTO implements Serializable {
@ApiModelProperty("小号id")
private String altId;
@ApiModelProperty("小号昵称")
private String altNickName;
@ApiModelProperty("小号头像")
private String altHeadUrl;
@ApiModelProperty("小号二维码地址")
private String altQrcodeUrl;
@ApiModelProperty("暗号")
private String cipher;
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
public String getAltNickName() {
return altNickName;
}
public void setAltNickName(String altNickName) {
this.altNickName = altNickName;
}
public String getAltHeadUrl() {
return altHeadUrl;
}
public void setAltHeadUrl(String altHeadUrl) {
this.altHeadUrl = altHeadUrl;
}
public String getAltQrcodeUrl() {
return altQrcodeUrl;
}
public void setAltQrcodeUrl(String altQrcodeUrl) {
this.altQrcodeUrl = altQrcodeUrl;
}
public String getCipher() {
return cipher;
}
public void setCipher(String cipher) {
this.cipher = cipher;
}
@Override
public String toString() {
return "OwnAltQrcodeInfoDTO{" +
"altId='" + altId + '\'' +
", altNickName='" + altNickName + '\'' +
", altHeadUrl='" + altHeadUrl + '\'' +
", altQrcodeUrl='" + altQrcodeUrl + '\'' +
", cipher='" + cipher + '\'' +
'}';
}
}
......@@ -102,6 +102,11 @@ public class BookGroup extends BaseEntity {
*/
private Boolean isShowBookName;
/**
* 进群方式:1群二维码,2客服机器人
*/
private Integer joinGroupType;
public Long getId() {
return id;
}
......@@ -246,6 +251,14 @@ public class BookGroup extends BaseEntity {
this.isShowBookName = isShowBookName;
}
public Integer getJoinGroupType() {
return joinGroupType;
}
public void setJoinGroupType(Integer joinGroupType) {
this.joinGroupType = joinGroupType;
}
@Override
public String toString() {
return "BookGroup{" +
......@@ -267,6 +280,7 @@ public class BookGroup extends BaseEntity {
", updateTime=" + updateTime +
", isDelete=" + isDelete +
", isShowBookName=" + isShowBookName +
", joinGroupType=" + joinGroupType +
"} " + super.toString();
}
}
\ No newline at end of file
package com.pcloud.book.group.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/8/5 15:59
**/
public class JoinGroupCipher extends BaseEntity {
private static final long serialVersionUID = -8724831387632496417L;
@ApiModelProperty("密码")
private String cipher;
@ApiModelProperty("分类id")
private Long classifyId;
@ApiModelProperty("群id")
private Long qrcodeId;
@ApiModelProperty("创建人")
private Long wechatUserId;
@ApiModelProperty("使用人微信id")
private String wxId;
@ApiModelProperty("是否使用")
private Boolean hasUsed;
@ApiModelProperty("机器人id")
private String altId;
public String getCipher() {
return cipher;
}
public void setCipher(String cipher) {
this.cipher = cipher;
}
public Long getClassifyId() {
return classifyId;
}
public void setClassifyId(Long classifyId) {
this.classifyId = classifyId;
}
public Long getQrcodeId() {
return qrcodeId;
}
public void setQrcodeId(Long qrcodeId) {
this.qrcodeId = qrcodeId;
}
public Long getWechatUserId() {
return wechatUserId;
}
public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId;
}
public String getWxId() {
return wxId;
}
public void setWxId(String wxId) {
this.wxId = wxId;
}
public Boolean getHasUsed() {
return hasUsed;
}
public void setHasUsed(Boolean hasUsed) {
this.hasUsed = hasUsed;
}
public String getAltId() {
return altId;
}
public void setAltId(String altId) {
this.altId = altId;
}
@Override
public String toString() {
return "JoinGroupCipher{" +
"cipher='" + cipher + '\'' +
", classifyId=" + classifyId +
", qrcodeId=" + qrcodeId +
", wechatUserId=" + wechatUserId +
", wxId='" + wxId + '\'' +
", hasUsed=" + hasUsed +
", altId='" + altId + '\'' +
"} " + super.toString();
}
}
package com.pcloud.book.group.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
/**
* @Description 分类关联表
* @Author ruansiyuan
* @Date 2019/8/5 15:47
**/
public class TempletRelevance extends BaseEntity {
private static final long serialVersionUID = 5014986282950538055L;
@ApiModelProperty("分类id")
private Long templetId;
@ApiModelProperty("大类id")
private Integer largeTemplet;
public Long getTempletId() {
return templetId;
}
public void setTempletId(Long templetId) {
this.templetId = templetId;
}
public Integer getLargeTemplet() {
return largeTemplet;
}
public void setLargeTemplet(Integer largeTemplet) {
this.largeTemplet = largeTemplet;
}
@Override
public String toString() {
return "TempletRelevance{" +
"templetId=" + templetId +
", largeTemplet=" + largeTemplet +
"} " + super.toString();
}
}
package com.pcloud.book.group.enums;
public enum LargTempletEnum {
/**
* K12类
*/
K12(1, "K12类"),
/**
* 少儿类
*/
CHILD(2, "少儿类"),
/**
* 高等/职教
*/
HIGH(3, "高等/职教"),
/**
* 大众类
*/
GENERAL(4, "大众类");
public final Integer code;
public final String name;
LargTempletEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
}
......@@ -3,6 +3,7 @@ package com.pcloud.book.group.facade;
import com.pcloud.book.group.entity.BookGroupClassify;
import org.codehaus.jackson.JsonParseException;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -275,4 +276,16 @@ public interface BookGroupFacade {
@RequestHeader("token") String token
) throws BizException, PermissionException, JsonParseException;
@ApiOperation("根据分类id获取个人二维码")
@GetMapping("getOwnAltQrcodeInfoDTOByClassifyId")
ResponseDto<?> getOwnAltQrcodeInfoDTOByClassifyId(
@CookieValue("userInfo") String userInfo,
@RequestParam("classifyId") Long classifyId
) throws BizException, PermissionException, JsonParseException;
@ApiOperation("获取所有的大类")
@GetMapping("getAllLargeTemplet")
ResponseDto<?> getAllLargeTemplet(
@RequestHeader("token") String token
) throws BizException, PermissionException, JsonParseException;
}
......@@ -3,6 +3,7 @@ package com.pcloud.book.group.facade.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.dto.GroupStoreMyPayDto;
import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.BookGroupClassify;
import com.pcloud.book.group.facade.BookGroupFacade;
......@@ -19,6 +20,7 @@ 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.*;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -394,4 +396,30 @@ public class BookGroupFacadeImpl implements BookGroupFacade {
Long partyId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(bookGroupBiz.getIsShowBookName(partyId));
}
@ApiOperation("根据分类id获取个人二维码")
@GetMapping("getOwnAltQrcodeInfoDTOByClassifyId")
@Override
public ResponseDto<?> getOwnAltQrcodeInfoDTOByClassifyId(
@CookieValue("userInfo") String userInfo,
@RequestParam("classifyId") Long classifyId
) throws BizException, PermissionException, JsonParseException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
if (classifyId == null) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "分类不能为空!");
}
return new ResponseDto<>(bookGroupBiz.getOwnAltQrcodeInfoDTOByClassifyId(wechatUserId, classifyId));
}
@ApiOperation("获取所有的大类")
@GetMapping("getAllLargeTemplet")
@Override
public ResponseDto<?> getAllLargeTemplet(
@RequestHeader("token") String token
) throws BizException, PermissionException, JsonParseException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(bookGroupBiz.getAllLargTemplet());
}
}
......@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
......@@ -67,7 +68,7 @@ public class BookGroupClassifyServiceImpl implements BookGroupClassifyService {
@ApiImplicitParam(name = "query", value = "书籍名称", dataType = "string",required = false, 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")
@ApiImplicitParam(name = "purLabelId", value = "目的标签id", dataType = "long",required = false, paramType = "query")
})
@GetMapping("listQrcodeIdsByLabelQuery")
public ResponseEntity<ResponseDto<List<Long>>> listQrcodeIdsByLabelQuery(
......@@ -85,4 +86,14 @@ public class BookGroupClassifyServiceImpl implements BookGroupClassifyService {
List<Long>qrcodeIds = groupQrcodeBiz.filterDeleteId(wxGroupIdList);
return ResponseHandleUtil.toResponse(qrcodeIds);
}
@Override
@GetMapping("getPayPrice")
@ApiImplicitParams({
@ApiImplicitParam(name = "qrcodeId", value = "qrcodeId", dataType = "long", required = true, paramType = "query"),
@ApiImplicitParam(name = "wxUserId", value = "wxUserId", dataType = "string", required = true, paramType = "query")
})
public ResponseEntity<ResponseDto<BigDecimal>> getPayPrice(@RequestParam("qrcodeId") Long qrcodeId, @RequestParam("wxUserId") String wxUserId) {
return ResponseHandleUtil.toResponse(bookGroupClassifyBiz.getPayPrice(qrcodeId, wxUserId));
}
}
......@@ -3,13 +3,12 @@ package com.pcloud.book.group.service.impl;
import java.util.List;
import java.util.Map;
import com.pcloud.book.group.dto.GroupCipherDTO;
import com.pcloud.book.group.dto.GroupUseDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
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 org.springframework.web.bind.annotation.*;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.service.BookGroupService;
......@@ -86,4 +85,41 @@ public class BookGroupServiceImpl implements BookGroupService {
return ResponseHandleUtil.toResponse(bookGroupBiz.getBaseInfoBySceneId(sceneId));
}
/**
* 获取暗号状态
*/
@ApiOperation("获取暗号状态")
@GetMapping("/getCipherState")
@Override
public ResponseEntity<ResponseDto<Integer>> getCipherState(String cipher) throws BizException {
return ResponseHandleUtil.toResponse(bookGroupBiz.getCipherState(cipher));
}
/**
* 更新密码状态为已使用
*/
@ApiOperation("更新暗号状态为已使用")
@GetMapping("/updateCipherStateToUsed")
@Override
public void updateCipherStateToUsed(String cipher, String wxId) throws BizException {
bookGroupBiz.updateCipherStateToUsed(cipher,wxId);
}
/**
* 获取个人二维码方式群已使用和未使用数量
*/
@ApiOperation("获取个人二维码方式群已使用和未使用数量")
@PostMapping("/getGroupUse")
@Override
public ResponseEntity<ResponseDto<GroupUseDTO>> getGroupUse(@RequestBody List<String> altIds) throws BizException {
return ResponseHandleUtil.toResponse(bookGroupBiz.getGroupUse(altIds));
}
@ApiOperation("获取暗号基本信息")
@GetMapping("/getJoinGroupCipher")
@Override
public ResponseEntity<ResponseDto<GroupCipherDTO>> getJoinGroupCipher(@RequestParam("cipher")String cipher) throws BizException {
return ResponseHandleUtil.toResponse(bookGroupBiz.getJoinGroupCipher(cipher));
}
}
......@@ -18,6 +18,7 @@ import com.pcloud.common.utils.string.StringUtil;
import com.sdk.wxgroup.ChangeNameVO;
import com.sdk.wxgroup.QrcodeVO;
import com.sdk.wxgroup.SendArticleMessageVO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import com.sdk.wxgroup.SendPicMessageVO;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
......@@ -127,8 +128,8 @@ public class SendWeixinRequestTools {
}*/
}
@ParamLog("修改微信群名称")
public static void sendGuideMessage(List<ReplyMessageVO> replyMessages, String robotId, String weixinGroupId, String ip) {
@ParamLog("发送欢迎语消息")
public static void sendGuideMessage(List<ReplyMessageVO> replyMessages, String robotId, String weixinGroupId, String ip, Integer code) {
//JedisClusterUtils.del("BOOK:WEIXINGROUP:GUIDEUSER" + weixinGroupId);
if (ListUtils.isEmpty(replyMessages)) {
return;
......@@ -148,37 +149,40 @@ public class SendWeixinRequestTools {
}
}
}
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip);
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip, code);
i++;
}
}
@ParamLog("推送消息")
private static void sendMessage(SendMessageDTO sendMessageDTO, String robotId, String weixinGroupId, String ip) {
private static void sendMessage(SendMessageDTO sendMessageDTO, String robotId, String weixinGroupId, String ip, Integer code) {
if (ReplyTypeEnum.TEXT.value.equals(sendMessageDTO.getReplyType())) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(sendMessageDTO.getContent());
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
sendTextMessageVO.setCode(code);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
} else if (ReplyTypeEnum.IMAGE.value.equals(sendMessageDTO.getReplyType())) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setGroupId(weixinGroupId);
sendPicMessageVO.setWxGroupId(weixinGroupId);
sendPicMessageVO.setAltId(robotId);
sendPicMessageVO.setPicUrl(sendMessageDTO.getPicUrl());
sendPicMessageVO.setIp(ip);
sendPicMessageVO.setCode(code);
WxGroupSDK.sendPicMessage(sendPicMessageVO);
} else if (ReplyTypeEnum.APP.value.equals(sendMessageDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(sendMessageDTO.getReplyType())) {
SendArticleMessageVO sendArticleMessageVO = new SendArticleMessageVO();
sendArticleMessageVO.setAltId(robotId);
sendArticleMessageVO.setDescription(sendMessageDTO.getDescription());
sendArticleMessageVO.setLinkUrl(sendMessageDTO.getLinkUrl());
sendArticleMessageVO.setGroupId(weixinGroupId);
sendArticleMessageVO.setWxGroupId(weixinGroupId);
sendArticleMessageVO.setPicUrl(sendMessageDTO.getPicUrl());
sendArticleMessageVO.setTitle(sendMessageDTO.getContent());
sendArticleMessageVO.setIp(ip);
sendArticleMessageVO.setCode(code);
WxGroupSDK.sendArticleMessage(sendArticleMessageVO);
}
}
......@@ -188,7 +192,7 @@ public class SendWeixinRequestTools {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(nickNameStr);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
......@@ -198,10 +202,11 @@ public class SendWeixinRequestTools {
if (StringUtil.isEmpty(url)) {
return url;
}
final String s = "qrcode_id=" + groupQrcodeId + "&classify_id=" + classifyId + (null == bookGroupId ? "" : "&book_group_id=" + bookGroupId);
if (url.contains("?")) {
url = url + "&qrcode_id=" + groupQrcodeId + "&classify_id=" + classifyId + "&book_group_id=" + bookGroupId;
url = url + "&" + s;
} else {
url = url + "?qrcode_id=" + groupQrcodeId + "&classify_id=" + classifyId + "&book_group_id=" + bookGroupId;
url = url + "?" + s;
}
return url;
}
......@@ -216,11 +221,11 @@ public class SendWeixinRequestTools {
}
sendTextMessageVO.setContent(recommendLanguage);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setGroupId(weixinGroupId);
sendPicMessageVO.setWxGroupId(weixinGroupId);
sendPicMessageVO.setAltId(robotId);
sendPicMessageVO.setPicUrl(accountSettingDto.getQrcodeUrl());
sendPicMessageVO.setIp(ip);
......@@ -228,10 +233,10 @@ public class SendWeixinRequestTools {
}
@ParamLog("推送关键词回复消息")
public static void sendKeywordMessage(ReplyKeywordDTO replyKeywordDTO, String robotId, String weixinGroupId, String ip) {
public static void sendKeywordMessage(ReplyKeywordDTO replyKeywordDTO, String robotId, String weixinGroupId, String ip, Integer code) {
SendMessageDTO sendMessageDTO = new SendMessageDTO();
BeanUtils.copyProperties(replyKeywordDTO, sendMessageDTO);
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip);
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip, code);
}
@ParamLog("补充域名")
......@@ -269,32 +274,44 @@ public class SendWeixinRequestTools {
}
@ParamLog("欢迎语中推送关键词信息")
public static void sendKeywordsInfo(List<KeywordDTO> keywords, String robotId, String weixinGroupId, String ip){
public static void sendKeywordsInfo(List<KeywordDTO> keywords, String robotId, String toWxId, String ip){
if (ListUtils.isEmpty(keywords)) {
return;
}
String content = "";
StringBuilder content = new StringBuilder();
for (int i = 0; i < keywords.size(); i++) {
KeywordDTO keywordDTO = keywords.get(i);
String keyword = "关键词【" + keywordDTO.getKeywords() + "】\n" + " "+keywordDTO.getGuide();
if (content.length() + keyword.length() > 300) {
sendTextMessage(content, robotId, weixinGroupId, ip);
content = keyword;
sendTextMessageToSelf(content.toString(), robotId, toWxId, ip);
content = new StringBuilder(keyword);
}else{
content = content + keyword;
content.append(keyword);
}
if (i != keywords.size() - 1) {
content = content + "\n";
content.append("\n");
}
}
sendTextMessage(content, robotId, weixinGroupId, ip);
// 1001282-施总需求,群不推送关键词,个人欢迎语推送关键词
// sendTextMessage(content, robotId, weixinGroupId, ip);
sendTextMessageToSelf(content.toString(), robotId, toWxId, ip);
}
private static void sendTextMessageToSelf(String content, String robotId, String toWxId, String ip){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
sendTextMessageVO.setWxGroupId(toWxId);
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
public static void sendTextMessage(String content, String robotId, String weixinGroupId, String ip){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
......@@ -303,7 +320,7 @@ public class SendWeixinRequestTools {
// SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
// sendTextMessageVO.setContent("关键词1:a" + "\n" + "换行换行换行" + "\n");
// sendTextMessageVO.setAltId("wxid_qj200bf0key022");
// sendTextMessageVO.setGroupId("14108963419@chatroom");
// sendTextMessageVO.setWxGroupId("14108963419@chatroom");
// WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
......@@ -349,7 +366,7 @@ public class SendWeixinRequestTools {
public static void sendClockKeywordsInfo(List<BookClockKeywordDTO> keywords, String robotId, String weixinGroupId, String ip) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
if (ListUtils.isEmpty(keywords)) {
return;
......
......@@ -5,11 +5,13 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author lily
* @date 2019/5/6 16:08
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GroupQrcodeBaseInfoVO implements Serializable {
......@@ -22,36 +24,7 @@ public class GroupQrcodeBaseInfoVO implements Serializable {
@ApiModelProperty("二维码地址")
private String qrcodeUrl;
public Long getGroupQrcodeId() {
return groupQrcodeId;
}
public void setGroupQrcodeId(Long groupQrcodeId) {
this.groupQrcodeId = groupQrcodeId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getQrcodeUrl() {
return qrcodeUrl;
}
public void setQrcodeUrl(String qrcodeUrl) {
this.qrcodeUrl = qrcodeUrl;
}
@Override
public String toString() {
return "GroupQrcodeBaseInfoVO{" +
"groupQrcodeId=" + groupQrcodeId +
", groupName='" + groupName + '\'' +
", qrcodeUrl='" + qrcodeUrl + '\'' +
'}';
}
@ApiModelProperty(value = "二维码地址", hidden = true)
private String weixinGroupId;
}
......@@ -5,6 +5,7 @@ import com.pcloud.book.keywords.vo.GuideVO;
import com.pcloud.book.keywords.vo.ReplyMessageVO;
import com.pcloud.book.keywords.vo.SetGuideVO;
import com.pcloud.book.keywords.vo.UpdateGuideVO;
import com.pcloud.wechatgroup.message.dto.AgreeAddUserDTO;
import java.util.List;
import java.util.Map;
......@@ -14,6 +15,11 @@ import java.util.Map;
* @date 2019/4/23 15:46
*/
public interface BookGuideBiz {
/**
* 同意加好友发送欢迎语
*/
void sendGuide(AgreeAddUserDTO agreeAddUserDTO);
/**
* @Author:lili
* @Desr:新增欢迎语
......
......@@ -6,6 +6,7 @@ import com.pcloud.book.keywords.dto.ReplyKeywordDTO;
import com.pcloud.book.keywords.dto.ServiceResourceDTO;
import com.pcloud.book.keywords.vo.*;
import com.pcloud.common.page.PageBeanNew;
import com.sdk.wxgroup.SendMessageTypeEnum;
import java.util.List;
......@@ -70,7 +71,7 @@ public interface BookKeywordBiz {
* @Desr: 回复关键词消息
* @Date:2019/5/5 16:28
*/
void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip);
void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip, Integer code);
/**
* 关键词统计
......
package com.pcloud.book.keywords.biz.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.clock.check.BookClockCheck;
import com.pcloud.book.clock.dao.BookClockKeywordDao;
import com.pcloud.book.clock.dto.BookClockKeywordDTO;
......@@ -13,9 +14,8 @@ import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.PushAddUserMessageDTO;
import com.pcloud.book.group.dao.JoinGroupCipherDao;
import com.pcloud.book.group.dto.*;
import com.pcloud.book.group.entity.AppTouchRecord;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.enums.TouchTypeEnum;
......@@ -25,10 +25,13 @@ import com.pcloud.book.keywords.biz.BookGuideBiz;
import com.pcloud.book.keywords.biz.BookKeywordBiz;
import com.pcloud.book.keywords.dao.BookGuideDao;
import com.pcloud.book.keywords.dao.BookGuideReplyDao;
import com.pcloud.book.keywords.dao.KeywordDao;
import com.pcloud.book.keywords.dto.GuideDTO;
import com.pcloud.book.keywords.dto.KeywordDTO;
import com.pcloud.book.keywords.dto.ReplyKeywordDTO;
import com.pcloud.book.keywords.entity.BookGuide;
import com.pcloud.book.keywords.entity.BookGuideReply;
import com.pcloud.book.keywords.entity.Keyword;
import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.book.keywords.vo.GuideVO;
import com.pcloud.book.keywords.vo.ReplyMessageVO;
......@@ -37,7 +40,14 @@ import com.pcloud.book.keywords.vo.UpdateGuideVO;
import com.pcloud.channelcenter.wechat.dto.AccountSettingDto;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.wechatgroup.message.dto.AgreeAddUserDTO;
import com.sdk.wxgroup.AddToGroupVO;
import com.sdk.wxgroup.SendGroupInviteVO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -87,6 +97,114 @@ public class BookGuideBizImpl implements BookGuideBiz {
private GroupQrcodeDao groupQrcodeDao;
@Autowired
private BookGroupClassifyDao bookGroupClassifyDao;
@Autowired
private JoinGroupCipherDao joinGroupCipherDao;
@Autowired
private KeywordDao keywordDao;
@ParamLog("同意加好友发送欢迎语")
@Override
public void sendGuide(AgreeAddUserDTO agreeAddUserDTO) {
if(null == agreeAddUserDTO || StringUtil.isBlank(agreeAddUserDTO.getRobotWxId()) || StringUtil.isBlank(agreeAddUserDTO.getUserWxId())) {
log.info("[同意加好友发送欢迎语] 参数为空 agreeAddUserDTO:{}", agreeAddUserDTO);
return;
}
String cipher = agreeAddUserDTO.getCipher();
if (StringUtil.isBlank(cipher)) {
cipher = wechatGroupConsr.getCipherByRobotAndUserWxId(agreeAddUserDTO.getRobotWxId(), agreeAddUserDTO.getUserWxId());
}
if (StringUtil.isBlank(cipher)) {
log.info("[同意加好友发送欢迎语] 暗号为空 agreeAddUserDTO:{}", agreeAddUserDTO);
return;
}
final JoinGroupCipherDTO dto = joinGroupCipherDao.getDTOByCipher(cipher);
//获取群
final String wxGroupId = bookGroupClassifyBiz.getWxGroupIdByClassifyIdAndWechatId(dto.getClassifyId(), dto.getWechatUserId());
if (agreeAddUserDTO.getFirst() != null && agreeAddUserDTO.getFirst()) {
// 如果是第一次就只发欢迎文案
SendTextMessageVO vo = new SendTextMessageVO();
vo.setContent("你好,我是本书智能小助手,请回复你的进群暗号,获取本书资源服务,以及入群链接如果忘了进群暗号,请重新扫描书上的二维码,点击入群即可获取");
vo.setCode(SendMessageTypeEnum.SELF.getCode());
vo.setWxId(agreeAddUserDTO.getRobotWxId());
vo.setAltId(agreeAddUserDTO.getRobotWxId());
vo.setWxGroupId(agreeAddUserDTO.getUserWxId());
vo.setIp(agreeAddUserDTO.getIp());
log.info("[同意加好友发送欢迎语] : {}", vo);
WxGroupSDK.sendTextMessage(vo);
} else {
// 如果不是第一次就发关键词
// 根据暗号获取分类id和bookGroupId推送关键词欢迎语
List<KeywordDTO> keywords = bookKeywordBiz.listFiveKeyword(dto.getClassifyId(), dto.getBookGroupId());
//发主打资源
sendMainKeyword(keywords,agreeAddUserDTO,dto,wxGroupId);
//发关键词列表
SendWeixinRequestTools.sendKeywordsInfo(keywords, agreeAddUserDTO.getRobotWxId(), agreeAddUserDTO.getUserWxId(), agreeAddUserDTO.getIp());
}
// 拉群
final Integer peopleCounts = WxGroupSDK.getPeopleCounts(wxGroupId, agreeAddUserDTO.getRobotWxId(), agreeAddUserDTO.getIp());
// 邀请好友进群有次数限制,目前测试为每天只能拉30-40人就操作频繁,所以在此加判断,超过30人或者群人数超过30人就发送邀请链接
final String num = JedisClusterUtils.get(BookConstant.WXGROUP_ADD_USER_NUM + agreeAddUserDTO.getRobotWxId());
log.info("[同意加好友发送欢迎语] 拉群 agreeAddUserDTO:{}, wxGroupId:{}, peopleCounts:{}, num:{}", agreeAddUserDTO, wxGroupId, peopleCounts, num);
if (StringUtil.isBlank(wxGroupId)) {
log.info("[同意加好友发送欢迎语] 拉群 没有找到群 bookGroupClassifyBiz.getGroupQrcode4ClassifyWechat JoinGroupCipherDTO :{}", dto);
return;
}
if ((!StringUtil.isBlank(num) && Integer.parseInt(num) >= 30) || peopleCounts >= 30) {
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(agreeAddUserDTO.getRobotWxId());
sendGroupInviteVO.setWxId(agreeAddUserDTO.getUserWxId());
sendGroupInviteVO.setWxGroupId(wxGroupId);
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO);
// 进群之后更新群qrCodeId
updateQrcodeForCipher(wxGroupId, cipher, agreeAddUserDTO.getUserWxId());
return;
}
AddToGroupVO vo1 = new AddToGroupVO();
vo1.setWxGroupId(wxGroupId);
vo1.setWxId(agreeAddUserDTO.getUserWxId());
vo1.setAltId(agreeAddUserDTO.getRobotWxId());
vo1.setIp(agreeAddUserDTO.getIp());
log.info("[同意加好友发送欢迎语 拉群] AddToGroupVO :{}", vo1);
WxGroupSDK.addToGroup(vo1);
// 进群之后更新群qrCodeId
updateQrcodeForCipher(wxGroupId, cipher, agreeAddUserDTO.getUserWxId());
// 拉一次+1
if (StringUtil.isBlank(num)) {
JedisClusterUtils.getSet(BookConstant.WXGROUP_ADD_USER_NUM + agreeAddUserDTO.getRobotWxId(), "1", 3600 * 24);
} else {
JedisClusterUtils.incr(BookConstant.WXGROUP_ADD_USER_NUM + agreeAddUserDTO.getRobotWxId());
}
}
@ParamLog("进群之后更新群qrCodeId")
private void updateQrcodeForCipher(String wxGroupId, String cipher, String userWxId){
log.info("根据群id查询群信息wxGroupId", wxGroupId);
GroupQrcodeDTO groupQrcodeInfo = groupQrcodeDao.getGroupQrcodeInfo(wxGroupId);
log.info("根据群id查询群信息groupQrcodeInfo", groupQrcodeInfo.toString());
log.info("更新暗号的群cipher=" + cipher + "wxId=" + userWxId + "qrcodeId=" + groupQrcodeInfo.getId());
joinGroupCipherDao.updateQrcodeId(cipher, userWxId, groupQrcodeInfo.getId());
}
@ParamLog("发送主打资源")
private void sendMainKeyword(List<KeywordDTO> keywords, AgreeAddUserDTO agreeAddUserDTO, JoinGroupCipherDTO dto, String wxGroupId) {
if (!ListUtils.isEmpty(keywords)) {
KeywordDTO keywordDTO = keywords.get(0);
Keyword keyword = keywordDao.getById(keywordDTO.getKeywordId());
GroupQrcodeDTO groupQrcodeInfo = groupQrcodeDao.getGroupQrcodeInfo(wxGroupId);
if (keyword != null && groupQrcodeInfo != null) {
ReplyKeywordDTO replyKeywordDTO = new ReplyKeywordDTO();
BeanUtils.copyProperties(keyword, replyKeywordDTO);
if (ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType())) {
BookGroupDTO bookGroupDTO = bookGroupDao.getDTOById(dto.getBookGroupId());
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(bookGroupDTO.getChannelId());
String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, replyKeywordDTO.getLinkUrl(), dto.getBookGroupId(), dto.getClassifyId(), groupQrcodeInfo.getId());
replyKeywordDTO.setLinkUrl(linkUrl);
}
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTO, agreeAddUserDTO.getRobotWxId(), agreeAddUserDTO.getUserWxId(), agreeAddUserDTO.getIp(), SendMessageTypeEnum.SELF.getCode());
}
}
}
@Override
@ParamLog("新增欢迎语")
......@@ -223,37 +341,12 @@ public class BookGuideBizImpl implements BookGuideBiz {
log.info("[关键词消息回复] robotId is null robotId:{},weixinGroupId:{}", robotId, weixinGroupId);
robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
}
//String robotId = "wxid_e6zsl8oohcnl22";
// 判断是否需要发送
// boolean canSend = false;
// // 查看群成员
// GroupInfoVO groupInfoVO = WxGroupSDK.getGroupInfo(weixinGroupId, robotId);
// log.info("[查看群成员] : groupInfoVO:{}",groupInfoVO);
// if (!CollectionUtils.isEmpty(groupInfoVO.getIdList())) {
// // 查看该用户weixinid
// final List<String> nickName = wechatGroupConsr.getWxUserIdsByNickName(pushAddUserMessageDTO.getNickName());
// log.info("[查看该用户weixinid] : nickName:{}",nickName);
// if(!CollectionUtils.isEmpty(nickName)) {
// final Map<String, Boolean> map = Maps.newHashMap();
// for (String s : groupInfoVO.getIdList()) {
// map.put(s, true);
// }
// for (String s : nickName) {
// if (null != map.get(s) && map.get(s)) {
// // 若在群设置true
// canSend = true;
// break;
// }
// }
// }
// }
// 判断是否黑名单
final Boolean kickUser = wechatGroupConsr.isKickUser(pushAddUserMessageDTO.getNickName(), weixinGroupId);
// log.info("[推送欢迎语消息]:pushAddUserMessageDTO:{},kickUser:{},canSend:{}", pushAddUserMessageDTO, kickUser,canSend);
log.info("[推送欢迎语消息]:pushAddUserMessageDTO:{},kickUser:{}", pushAddUserMessageDTO, kickUser);
// 在群,且非黑名单
// canSend = canSend && !kickUser;
if (kickUser) {
if (null != kickUser && kickUser) {
log.info("[推送欢迎语消息]:不推送");
return;
}
......@@ -265,25 +358,26 @@ public class BookGuideBizImpl implements BookGuideBiz {
}
//获取公众号基本信息
AccountSettingDto wechatInfo = qrcodeSceneConsr.getWechatInfo(classifyQrcodeInfo.getChannelId());
//获取关键词信息(改成10个了)
List<KeywordDTO> keywords = bookKeywordBiz.listFiveKeyword(classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId());
Boolean isHaveKeywords = !ListUtils.isEmpty(keywords);
//获取关键词信息(改成10个了) 刘娜需求 1001282 群不推送关键词
// List<KeywordDTO> keywords = bookKeywordBiz.listFiveKeyword(classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId());
// Boolean isHaveKeywords = !ListUtils.isEmpty(keywords);
if (ListUtils.isEmpty(replyMessages)) {
//获取群名称
GroupQrcodeBaseInfoVO groupInfo = groupQrcodeBiz.getBaseById(classifyQrcodeInfo.getGroupQrcodeId());
//推送消息
SendWeixinRequestTools.sendDefaultMessage(groupInfo == null ? "" : groupInfo.getGroupName(), robotId, weixinGroupId, isHaveKeywords, pushAddUserMessageDTO.getIp());
//推送消息 刘娜需求 1001282 群不推送关键词
// SendWeixinRequestTools.sendDefaultMessage(groupInfo == null ? "" : groupInfo.getGroupName(), robotId, weixinGroupId, isHaveKeywords, pushAddUserMessageDTO.getIp());
SendWeixinRequestTools.sendDefaultMessage(groupInfo == null ? "" : groupInfo.getGroupName(), robotId, weixinGroupId, false, pushAddUserMessageDTO.getIp());
} else {
//处理链接
handleUrl(replyMessages, wechatInfo, classifyQrcodeInfo);
//推送消息
SendWeixinRequestTools.sendGuideMessage(replyMessages, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
SendWeixinRequestTools.sendGuideMessage(replyMessages, robotId, weixinGroupId, pushAddUserMessageDTO.getIp(), SendMessageTypeEnum.GROUP.getCode());
//新增欢迎语应用触发记录
addGuideAppTouchRecord(replyMessages,weixinGroupId,classifyQrcodeInfo.getBookGroupId(),classifyQrcodeInfo.getClassifyId());
}
//获取关键词信息(改成10个了)
SendWeixinRequestTools.sendKeywordsInfo(keywords, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
//如果设置了群学习报告,加一个群学习报告的关键词,如果群开启了猜谜语,推送猜谜语关键词
//获取关键词信息(改成10个了)刘娜需求 1001282 群不推送关键词
// SendWeixinRequestTools.sendKeywordsInfo(keywords, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
//如果设置了群学习报告,加一个群学习报告的关键词
pushLearningReport(classifyQrcodeInfo,robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
if (bookGuide != null && bookGuide.getIsRecommend() != null && bookGuide.getIsRecommend() == 1) {
//推送公众号消息
......
......@@ -2,6 +2,7 @@ package com.pcloud.book.keywords.biz.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.pcloud.appcenter.app.dto.AppDto;
import com.pcloud.book.base.exception.BookBizException;
......@@ -10,6 +11,7 @@ import com.pcloud.book.consumer.app.AppConsr;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.consumer.resource.ProductConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
......@@ -17,11 +19,13 @@ import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.JoinGroupCipherDTO;
import com.pcloud.book.group.entity.AppTouchRecord;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.enums.TouchTypeEnum;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.group.vo.ClassifyNameVO;
import com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO;
import com.pcloud.book.keywords.biz.BookKeywordBiz;
import com.pcloud.book.keywords.dao.BookKeywordDao;
import com.pcloud.book.keywords.dao.BookKeywordRecordDao;
......@@ -53,6 +57,7 @@ import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.resourcecenter.product.dto.ProductDto;
import com.pcloud.resourcecenter.product.dto.ProductTypeDto;
import com.pcloud.wechatgroup.group.dto.RobotReplyDTO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.BeanUtils;
......@@ -66,8 +71,10 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
......@@ -110,6 +117,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private BookGroupClassifyDao bookGroupClassifyDao;
@Autowired
private QrcodeSceneService qrcodeSceneService;
@Autowired
private BookGroupBiz bookGroupBiz;
@Override
@ParamLog("新增关键词")
......@@ -411,11 +420,145 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@Override
@ParamLog("关键词消息回复")
public void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip) {
public void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip, Integer code) {
// 刘娜需求 1001282 群不推送关键词
if (SendMessageTypeEnum.GROUP.getCode().equals(code)) {
this.sendKeywordMessageToGroup(content, weixinGroupId, userWxId, robotId, ip, code);
return;
}
//个人机器人接收消息的时候,weixinGroupId就是userWxId,也就是用户的id,robotId是接收的机器人的id
//简单过滤非关键词的词
if (StringUtil.isEmpty(content) || content.length() > 20) {
return;
}
// TODO 根据小号和用户id获取所有相关的分类id,若该关键词存在多本书,则组装成文本加链接一次发送
final List<JoinGroupCipherDTO> dtos = bookGroupBiz.getClassifyIdsByWxIdAndAltId(userWxId, robotId);
if (CollectionUtils.isEmpty(dtos)) {
log.info("[关键词消息回复] classifyIds is null");
return;
}
final Set<Long> cIds = Sets.newHashSet();
final Set<Long> bIds = Sets.newHashSet();
Map<Long, Long> classifyToBookGroupMap = new HashMap<>();
Map<Long, Long> classifyToQrcodeMap = new HashMap<>();
for (JoinGroupCipherDTO dto : dtos) {
cIds.add(dto.getClassifyId());
bIds.add(dto.getBookGroupId());
classifyToBookGroupMap.put(dto.getClassifyId(),dto.getBookGroupId());
classifyToQrcodeMap.put(dto.getClassifyId(),dto.getQrcodeId());
}
final List<Long> classifyIds = Lists.newArrayList(cIds);
List<ReplyKeywordDTO> replyKeywordDTOs = new ArrayList<>();
Map<Long, Long> keywordClassifyIdMap = new HashMap<>();
List<Long> keywordIds = new ArrayList<>();
for (Long classifyId : classifyIds) {
//获取匹配关键词
ReplyKeywordDTO replyKeywordDTO = bookKeywordDao.getKeywordId(classifyId, classifyToBookGroupMap.get(classifyId), content);
if (replyKeywordDTO == null) {
continue;
}
keywordClassifyIdMap.put(replyKeywordDTO.getKeywordId(), classifyId);
//避免一本书下两个分类的关键词重复
if (!keywordIds.contains(replyKeywordDTO.getKeywordId())) {
replyKeywordDTOs.add(replyKeywordDTO);
keywordIds.add(replyKeywordDTO.getKeywordId());
}
}
final List<GroupClassifyQrcodeDTO> qrcodeDTOS = bookGroupClassifyBiz.listClassifyQrcodeInfo(classifyIds);
if (CollectionUtils.isEmpty(replyKeywordDTOs)) {
log.info("[关键词消息回复] keywordIds is null");
return;
}
if (CollectionUtils.isEmpty(qrcodeDTOS)) {
log.info("[关键词消息回复] qrcodeDTOS is null");
return;
}
final Map<Long, GroupClassifyQrcodeDTO> classifyMap = qrcodeDTOS.stream().collect(Collectors.toMap(GroupClassifyQrcodeDTO::getClassifyId, p -> p, (v1, v2) -> v2));
// 记录循环插入,消息一条发送
for (ReplyKeywordDTO replyKeywordDTO : replyKeywordDTOs) {
log.info("[关键词回复原始数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, altId:{}", replyKeywordDTO, robotId, userWxId);
// 处理链接地址
Long classifyId = keywordClassifyIdMap.get(replyKeywordDTO.getKeywordId());
final GroupClassifyQrcodeDTO dto = classifyMap.get(classifyId);
Long qrcodeId = classifyToQrcodeMap.get(dto.getClassifyId());
GroupQrcodeBaseInfoVO qrcodeInfo = groupQrcodeDao.getBaseById(qrcodeId);
if (ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType())) {
if(null == dto) {
log.info("[关键词消息回复] 分类信息为空 replyKeywordDTO:{}; classifyMap:{}", replyKeywordDTO, classifyMap);
continue;
}
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(dto.getChannelId());
String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, replyKeywordDTO.getLinkUrl(), dto.getBookGroupId(), dto.getClassifyId(), qrcodeId);
replyKeywordDTO.setLinkUrl(linkUrl);
if (!StringUtil.isEmpty(linkUrl)) {
replyKeywordDTO.setShortLinkUrl(UrlUtils.getShortUrl4Own(linkUrl));
}
}
String redisContent = JedisClusterUtils.getJson("BOOK:KEYWORD:" + userWxId + "-" + replyKeywordDTO.getKeywordId(), String.class);
// 同一群10秒内不回复同一关键词
if (insertBookKeywordRecord(qrcodeInfo.getWeixinGroupId(), userWxId, replyKeywordDTO, dto, redisContent)) {
return;
}
//获取推送消息机器人
// 20190704改为收发一体
if (StringUtil.isBlank(robotId)) {
log.info("[关键词消息回复] robotId is null content:{}, robotId:{},weixinGroupId:{}", content, robotId, qrcodeInfo.getWeixinGroupId());
robotId = wechatGroupConsr.getRobotIdByGroupId(qrcodeInfo.getWeixinGroupId());
}
log.info("[关键词回复发送数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, qrcodeInfo.getWeixinGroupId());
//新增关键词触发记录
addKeywordAppTouchRecord(replyKeywordDTO, qrcodeInfo.getWeixinGroupId(), dto.getClassifyId(), dto.getBookGroupId());
}
// 单条还是按原来的发送
if (replyKeywordDTOs.size() <= 1) {
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTOs.get(0), robotId, userWxId, ip, code);
} else {
// 多条时文字,应用,链接组装成一条发送
ReplyKeywordDTO d = new ReplyKeywordDTO();
final StringBuilder sb = new StringBuilder();
for (ReplyKeywordDTO dto : replyKeywordDTOs) {
if (ReplyTypeEnum.APP.value.equals(dto.getReplyType()) || ReplyTypeEnum.LINK.value.equals(dto.getReplyType())) {
sb.append(dto.getKeywords()).append(":").append(dto.getShortLinkUrl()).append("\n");
} else if (ReplyTypeEnum.TEXT.value.equals(dto.getReplyType())){
sb.append(dto.getKeywords()).append(":").append(dto.getContent()).append("\n");
} else if (ReplyTypeEnum.IMAGE.value.equals(dto.getReplyType())) {
SendWeixinRequestTools.sendKeywordMessage(dto, robotId, userWxId, ip, code);
continue;
}
}
d.setContent(sb.toString());
d.setReplyType(ReplyTypeEnum.TEXT.value);
SendWeixinRequestTools.sendKeywordMessage(d, robotId, userWxId, ip, code);
}
}
private boolean insertBookKeywordRecord(String weixinGroupId, String userWxId, ReplyKeywordDTO replyKeywordDTO, GroupClassifyQrcodeDTO dto, String redisContent) {
if (redisContent != null) {
insertBookKeywordRecord(dto, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, false);
log.info("[关键词消息回复] redisContent:{} insertBookKeywordRecord return", redisContent);
return true;
} else {
JedisClusterUtils.setJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), replyKeywordDTO.getKeywordId(), 10);
insertBookKeywordRecord(dto, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, true);
}
return false;
}
/**
* 原有的推送群关键词改为推送个人关键词
*/
@ParamLog("群关键词消息回复")
private void sendKeywordMessageToGroup(String content, String weixinGroupId, String userWxId, String robotId, String ip, Integer code) {
//简单过滤非关键词的词
if (StringUtil.isEmpty(content) || content.length() > 20) {
return;
}
// 若非之前的机器人则不回复普通关键词
final Boolean groupRobot = wechatGroupConsr.isGroupRobot(robotId);
log.info("[wechatGroupConsr.isGroupRobot] robotId:{} groupRobot:{}", robotId, groupRobot);
if (!groupRobot) {
return;
}
//通过群id获取对应基本信息
GroupClassifyQrcodeDTO classifyQrcodeInfo = bookGroupClassifyBiz.getClassifyQrcodeInfo(weixinGroupId);
if (classifyQrcodeInfo == null) {
......@@ -443,13 +586,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
String redisContent = JedisClusterUtils.getJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), String.class);
// 同一群10秒内不回复同一关键词
if (redisContent != null) {
insertBookKeywordRecord(classifyQrcodeInfo, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, false);
log.info("[关键词消息回复] redisContent:{} insertBookKeywordRecord return", redisContent);
if (insertBookKeywordRecord(weixinGroupId, userWxId, replyKeywordDTO, classifyQrcodeInfo, redisContent)) {
return;
} else {
JedisClusterUtils.setJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), replyKeywordDTO.getKeywordId(), 10);
insertBookKeywordRecord(classifyQrcodeInfo, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, true);
}
//获取推送消息机器人
// 20190704改为收发一体
......@@ -458,7 +596,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
}
log.info("[关键词回复发送数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, weixinGroupId);
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTO, robotId, weixinGroupId, ip);
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTO, robotId, weixinGroupId, ip, code);
//新增关键词触发记录
addKeywordAppTouchRecord(replyKeywordDTO, weixinGroupId, classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId());
//第一推送关键词消息埋点
......@@ -506,6 +644,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
bookKeywordRecord.setUserWxId(userWxId);
bookKeywordRecord.setWeixinGroupId(weixinGroupId);
bookKeywordRecord.setSend(isSend);
if (bookKeywordRecord.getGroupQrcodeId() == null) {
GroupQrcode groupQr = groupQrcodeDao.getGroupQrcodeByGroupId(weixinGroupId);
if (groupQr!=null){
bookKeywordRecord.setGroupQrcodeId(groupQr.getId());
}
}
bookKeywordRecordDao.insert(bookKeywordRecord);
}
......
......@@ -52,6 +52,11 @@ public interface BookKeywordDao extends BaseDao<BookKeyword> {
ReplyKeywordDTO getKeywordId(Long classifyId, Long bookGroupId, String content);
/**
* 根据分类ids和群ids批量获取关键词
*/
List<ReplyKeywordDTO> getKeywordIds(List<Long> classifyIds, List<Long> bookGroupIds, String content);
/**
* @Author:lili
* @Desr:校验关键词
* @Date:2019/5/6 14:47
......
package com.pcloud.book.keywords.dao.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.pcloud.book.group.vo.SyncKeyworsVO;
......@@ -12,10 +13,14 @@ import com.pcloud.book.keywords.vo.ListKeywordVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
* @author lily
......@@ -62,6 +67,18 @@ public class BookKeywordDaoImpl extends BaseDaoImpl<BookKeyword> implements Book
}
@Override
public List<ReplyKeywordDTO> getKeywordIds(List<Long> classifyIds, List<Long> bookGroupIds, String content) {
if (CollectionUtils.isEmpty(classifyIds) || CollectionUtils.isEmpty(bookGroupIds) || StringUtils.isEmpty(content)) {
return Lists.newArrayList();
}
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("classifyId", classifyIds.stream().map(Object::toString).collect(Collectors.joining(",")));
paramMap.put("bookGroupId", bookGroupIds.stream().map(Object::toString).collect(Collectors.joining(",")));
paramMap.put("content", content);
return this.getSqlSession().selectList(this.getStatement("getKeywordIds"), paramMap);
}
@Override
public Boolean checkKeyword(String keywords, Long classifyId, Long bookGroupId, Long keywordId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("classifyId", classifyId);
......
......@@ -27,6 +27,12 @@ public class ReplyKeywordDTO implements Serializable {
@ApiModelProperty("仓库关键词id")
private Long warehouseId;
@ApiModelProperty("分类id")
private Long classifyId;
@ApiModelProperty("群id")
private Long bookGroupId;
@ApiModelProperty("内容")
private String content;
......
......@@ -6,12 +6,15 @@ import com.pcloud.book.keywords.vo.GuideVO;
import com.pcloud.book.keywords.vo.ReplyMessageVO;
import com.pcloud.book.keywords.vo.SetGuideVO;
import com.pcloud.book.keywords.vo.UpdateGuideVO;
import com.pcloud.common.core.constant.MQTopicProducer;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.common.utils.SessionUtil;
import com.pcloud.wechatgroup.message.dto.AgreeAddUserDTO;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -26,16 +29,34 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
/**
* @author lily
* @date 2019/4/23 15:24
*/
@Slf4j
@RestController("bookGuideFacade")
@RequestMapping("bookGuide")
public class BookGuideFacadeImpl implements BookGuideFacade {
@Autowired
private BookGuideBiz bookGuidBiz;
@Autowired
private AmqpTemplate amqpTemplate;
@PostMapping("test")
public void test() {
final AgreeAddUserDTO agreeAddUserDTO = new AgreeAddUserDTO();
agreeAddUserDTO.setNickName("大威");
agreeAddUserDTO.setRobotWxId("wxid_arjobo1bbk2i22");
// 当消息为个人消息时,wechatGroupId为发送人id
agreeAddUserDTO.setUserWxId("p867263500");
agreeAddUserDTO.setIp("http://192.168.92.122:8081");
log.info("[processSelfMessage] start convertAndSend agreeAddUserDTO:{}", agreeAddUserDTO);
// 发送topic book处理后续欢迎语,关键词和拉群操作
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.WX_AGREE_ADD_USER, agreeAddUserDTO);
}
@Override
@PostMapping("insertGuide")
......
......@@ -70,4 +70,9 @@ public class MQTopicConumer {
*/
public static final String WXGROUP_LEARNING_REPORT = PREFIX + MQTopicProducer.WXGROUP_LEARNING_REPORT;
/**
* 微信群同意添加好友成功
*/
public static final String WX_AGREE_ADD_USER = PREFIX + MQTopicProducer.WX_AGREE_ADD_USER;
}
......@@ -51,8 +51,8 @@ public class UpdateWXGroupNameListener {
}
String groupName = groupQrcode.getGroupName();
// 如果数据库微信群名称超过16,就截断,然后重新设置数据库的名称,因为wxgroup那边设置的时候截断了
if (groupName.length() > 16) {
groupName = groupName.substring(0, 16);
if (groupName.length() > 15) {
groupName = groupName.substring(0, 15);
groupQrcodeDao.updateGroupName(groupQrcode.getId(), groupName);
}
if (!groupNameDTO.getNewGroupName().equals(groupName)) {
......@@ -67,7 +67,7 @@ public class UpdateWXGroupNameListener {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("@"+groupNameDTO.getNickName()+",为方便群友入群分享好的助学方法,请不要随意修改群名。如再修改,会将您移出群聊。谢谢配合。");
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setGroupId(wechatGroupId);
sendTextMessageVO.setWxGroupId(wechatGroupId);
LOGGER.info("发送警告文本消息"+sendTextMessageVO.toString());
sendTextMessageVO.setIp(findIp(wechatGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
......
......@@ -25,6 +25,7 @@ import com.pcloud.wechatgroup.message.dto.GroupLearningReportDTO;
import com.sdk.wxgroup.SendPicMessageVO;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
......@@ -63,8 +64,9 @@ public class WXGroupLearningReportListener {
try {
if (groupLearningReportDTO == null
|| groupLearningReportDTO.getWechatGroupId() == null
|| groupLearningReportDTO.getWechatUserId() == null)
|| groupLearningReportDTO.getWechatUserId() == null) {
return;
}
String wechatUserId = groupLearningReportDTO.getWechatUserId();
String wechatGroupId = groupLearningReportDTO.getWechatGroupId();
//新增触发记录
......@@ -102,7 +104,7 @@ public class WXGroupLearningReportListener {
return;
}
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setGroupId(wechatGroupId);
sendTextMessageVO.setWxGroupId(wechatGroupId);
sendTextMessageVO.setAltId(alt);
sendTextMessageVO.setContent("个人专属学习报告,及群成员元气排行榜。点击获取" + resultUrl);
sendTextMessageVO.setIp(findIp(wechatGroupId));
......@@ -115,7 +117,7 @@ public class WXGroupLearningReportListener {
}
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setPicUrl(imageUrl);
sendPicMessageVO.setGroupId(wechatGroupId);
sendPicMessageVO.setWxGroupId(wechatGroupId);
sendPicMessageVO.setAltId(alt);
sendPicMessageVO.setIp(findIp(wechatGroupId));
LOGGER.info("发送分享图消息开始"+sendPicMessageVO.toString());
......
package com.pcloud.book.mq.topic;
import com.pcloud.book.keywords.biz.BookGuideBiz;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.wechatgroup.message.dto.AgreeAddUserDTO;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
/**
* @author lily
* @date 2019/5/6 11:01
*/
@Slf4j
@Component
public class WxAgreeAddUserListener {
@Resource
private BookGuideBiz bookGuideBiz;
/**
* 接收微信用户进群消息
*/
@ParamLog("同意加好友发送欢迎语")
@RabbitListener(queues = MQTopicConumer.WX_AGREE_ADD_USER)
public void onMessage(AgreeAddUserDTO agreeAddUserDTO) throws BizException {
try {
bookGuideBiz.sendGuide(agreeAddUserDTO);
} catch (Exception e) {
log.error("同意加好友发送欢迎语" + e.getMessage(), e);
}
}
}
......@@ -12,6 +12,7 @@ import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.wechatgroup.message.dto.SendTextDTO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -57,11 +58,11 @@ public class WxGroupSendTextListener {
List<String> allRobotWxIds = wechatGroupConsr.listAllRobotWxId();
if (!ListUtils.isEmpty(allRobotWxIds) && !allRobotWxIds.contains(wechatUserId) && !StringUtil.isEmpty(sendTextDTO.getTextContent())) {
BookClockInfoDTO bookClockInfoDTO = bookClockCheck.checkKeywordIsClock(sendTextDTO.getTextContent().trim(), sendTextDTO.getWechatGroupId());
if(null != bookClockInfoDTO){
if(null != bookClockInfoDTO && SendMessageTypeEnum.GROUP.getCode().equals(sendTextDTO.getCode())){
bookClockKeywordBiz.sendKeywordMessage(bookClockInfoDTO, wechatUserId,sendTextDTO.getWechatGroupId(),sendTextDTO.getWxId(),sendTextDTO.getIp());
}else{
} else{
final long l = System.currentTimeMillis();
bookKeywordBiz.sendKeywordMessage(sendTextDTO.getTextContent().trim(), sendTextDTO.getWechatGroupId(), wechatUserId, sendTextDTO.getWxId(), sendTextDTO.getIp());
bookKeywordBiz.sendKeywordMessage(sendTextDTO.getTextContent().trim(), sendTextDTO.getWechatGroupId(), wechatUserId, sendTextDTO.getWxId(), sendTextDTO.getIp(), sendTextDTO.getCode());
log.info("[接收用户发送文本消息] 总耗时:{}ms ", System.currentTimeMillis() - l);
}
//猜谜语
......
......@@ -320,7 +320,7 @@ public class PushBizImpl implements PushBiz {
Integer itemType = pushItem.getItemType();
if (ItemTypeEnum.TEXT.value.equals(itemType)) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setGroupId(groupId);
sendTextMessageVO.setWxGroupId(groupId);
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setContent(pushItem.getTextContent());
sendTextMessageVO.setPushGroupRecordId(pushGroupRecordId);
......@@ -331,7 +331,7 @@ public class PushBizImpl implements PushBiz {
SendArticleMessageVO sendArticleMessageVO = new SendArticleMessageVO();
sendArticleMessageVO.setAltId(altId);
sendArticleMessageVO.setDescription(pushItem.getLinkDescription());
sendArticleMessageVO.setGroupId(groupId);
sendArticleMessageVO.setWxGroupId(groupId);
String url = pushItem.getLinkUrl();
if (url.contains("?")) {
url = url + "&" + otherUrl;
......@@ -359,7 +359,7 @@ public class PushBizImpl implements PushBiz {
SendArticleMessageVO sendArticleMessageVO = new SendArticleMessageVO();
sendArticleMessageVO.setAltId(altId);
sendArticleMessageVO.setDescription(appDto.getTypeName());
sendArticleMessageVO.setGroupId(groupId);
sendArticleMessageVO.setWxGroupId(groupId);
// 处理链接地址
String endUrl = pushItem.getAppUrl() + "&" + otherUrl;
String linkUrl = SendWeixinRequestTools.splitUrl(accountSettingDto, endUrl);
......@@ -381,7 +381,7 @@ public class PushBizImpl implements PushBiz {
if (productDto.getProductTypeDto() != null) {
sendArticleMessageVO.setDescription(productDto.getProductTypeDto().getTypeName());
}
sendArticleMessageVO.setGroupId(groupId);
sendArticleMessageVO.setWxGroupId(groupId);
// 处理链接地址
String endUrl = pushItem.getProductUrl() + "&" + otherUrl;
String linkUrl = SendWeixinRequestTools.splitUrl(accountSettingDto, endUrl);
......@@ -399,7 +399,7 @@ public class PushBizImpl implements PushBiz {
if (ItemTypeEnum.IMAGE.value.equals(itemType)) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setAltId(altId);
sendPicMessageVO.setGroupId(groupId);
sendPicMessageVO.setWxGroupId(groupId);
sendPicMessageVO.setPicUrl(pushItem.getImageUrl());
sendPicMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendPicMessageVO.setIp(findIp(groupId));
......@@ -980,7 +980,7 @@ public class PushBizImpl implements PushBiz {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setWxGroupId(weixinGroupId);
sendTextMessageVO.setIp(findIp(weixinGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
LOGGER.info("发送早晚报" + sendTextMessageVO.toString());
......
......@@ -159,7 +159,7 @@
product_id productId,
product_spec_id productSpecId,
change_number changeNumber,
create_user
create_user createUser
from
book_group_classify
where
......@@ -310,10 +310,31 @@
q.id groupQrcodeId,
c.has_open_learning_report hasOpenLearningReport,
q.weixin_qrcode_id weixinQrcodeId,
q.qrcode_url qrCodeUrl
q.qrcode_url qrCodeUrl,
g.join_group_type joinGroupType
FROM
book_group_classify c
JOIN book_group_qrcode q ON c.id = q.classify_id
JOIN book_group g ON c.book_group_id = g.id
WHERE q.weixin_group_id = #{_parameter}
LIMIT 1
</select>
<select id="listClassifyQrcodeInfo" resultType="GroupClassifyQrcodeDTO" parameterType="list">
select
c.id classifyId,
c.create_user adviserId,
c.book_id bookId,
c.channel_id channelId,
c.book_group_id bookGroupId,
c.price price,
c.has_open_learning_report hasOpenLearningReport
from
book_group_classify c join book_group_qrcode q on c.id = q.classify_id
and q.weixin_group_id = #{_parameter} limit 1
book_group_classify c
where c.id in
<foreach collection="list" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
......
......@@ -20,6 +20,7 @@
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="is_delete" property="isDelete" jdbcType="BIT"/>
<result column="is_show_book_name" property="isShowBookName" jdbcType="BOOLEAN"/>
<result column="join_group_type" property="joinGroupType" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="BookGroupDTO" type="com.pcloud.book.group.dto.BookGroupDTO">
......@@ -45,13 +46,14 @@
<result column="BOOK_NAME" property="bookName" jdbcType="VARCHAR"/>
<result column="book_clock_info_id" property="bookClockInfoId" jdbcType="BIGINT"/>
<result column="is_show_book_name" property="isShowBookName" jdbcType="BOOLEAN"/>
<result column="join_group_type" property="joinGroupType" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id, book_id, channel_id, scene_id, group_qrcode_url, group_qrcode_name, pro_label_id, dep_label_id,
pur_label_id, join_title, join_slogan, personal_qrcode_url, product_id, create_user,
create_time,
update_time, is_delete, is_show_book_name
update_time, is_delete, is_show_book_name,join_group_type
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
......@@ -86,6 +88,7 @@
and book_id = #{bookId,jdbcType=BIGINT}
and channel_id = #{channelId,jdbcType=BIGINT}
and create_user = #{adviserId,jdbcType=BIGINT}
ORDER BY create_time ASC limit 1
</select>
<select id="getBookGroupCount" resultType="Integer" parameterType="Long">
......@@ -223,6 +226,9 @@
<if test="sceneId != null and sceneId != 0">
scene_id = #{sceneId},
</if>
<if test="joinGroupType != null">
join_group_type = #{joinGroupType},
</if>
update_time = NOW(),
</set>
where id = #{id,jdbcType=BIGINT}
......
......@@ -177,7 +177,7 @@
<select id="getBaseById" parameterType="Long" resultType="GroupQrcodeBaseInfoVO">
select
id groupQrcodeId, group_name groupName,qrcode_url qrcodeUrl
id groupQrcodeId, group_name groupName,qrcode_url qrcodeUrl, weixin_group_id as weixinGroupId
from
book_group_qrcode
where
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.group.dao.impl.JoinGroupCipherDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.JoinGroupCipher">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="cipher" property="cipher" jdbcType="VARCHAR"/>
<result column="classify_id" property="classifyId" jdbcType="BIGINT"/>
<result column="qrcode_id" property="qrcodeId" jdbcType="BIGINT"/>
<result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="wx_id" property="wxId" jdbcType="VARCHAR"/>
<result column="has_used" property="hasUsed" jdbcType="BOOLEAN"/>
<result column="alt_id" property="altId" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, cipher, classify_id, qrcode_id, create_time, wechat_user_id, update_time, wx_id, has_used, alt_id
</sql>
<insert id="insert" parameterType="com.pcloud.book.group.entity.JoinGroupCipher" useGeneratedKeys="true"
keyProperty="id">
insert into join_group_cipher
<trim prefix="(" suffix=")" suffixOverrides=",">
cipher,
classify_id,
qrcode_id,
create_time,
wechat_user_id,
has_used,
alt_id
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{cipher,jdbcType=VARCHAR},
#{classifyId,jdbcType=BIGINT},
#{qrcodeId,jdbcType=BIGINT},
now(),
#{wechatUserId,jdbcType=BIGINT},
0,
#{altId,jdbcType=VARCHAR}
</trim>
</insert>
<!--获取基本信息-->
<select id="getByWechatUserId" parameterType="map" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from join_group_cipher
where wechat_user_id=#{wechatUserId} and
classify_id=#{classifyId}
</select>
<!--根据暗号获取-->
<select id="getByCipher" parameterType="String" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from join_group_cipher
where cipher=#{cipher} limit 1
</select>
<!--根据暗号获取包含bookGroupId-->
<select id="getDTOByCipher" parameterType="String" resultType="com.pcloud.book.group.dto.JoinGroupCipherDTO">
select
a.id, cipher, a.classify_id as classifyId, a.qrcode_id qrcodeId, a.wechat_user_id as wechatUserId, a.wx_id as wxId,
a.has_used as hasUsed, b.book_group_id as bookGroupId
from join_group_cipher a left join book_group_classify b on a.classify_id = b.id
where a.cipher=#{cipher} limit 1
</select>
<!--更新暗号状态为已使用-->
<update id="updateCipherStateToUsed" parameterType="map">
update join_group_cipher set
has_used=1,
wx_id=#{wxId},
update_time=now()
where cipher=#{cipher}
</update>
<!--根据微信id和机器人id获取分类集合-->
<select id="getClassifyIdsByWxIdAndAltId" parameterType="map" resultType="com.pcloud.book.group.dto.JoinGroupCipherDTO">
select a.classify_id as classifyId, a.qrcode_id qrcodeId, b.book_group_id as bookGroupId from join_group_cipher a
left join book_group_classify b on a.classify_id = b.id where
a.has_used=1
and a.alt_id=#{altId}
and a.wx_id=#{wxId}
</select>
<!--更新二维码-->
<update id="updateQrcodeId" parameterType="map">
update join_group_cipher set
qrcode_id=#{qrcodeId}
where cipher=#{cipher}
and wx_id=#{wxId}
</update>
<!--获取用户支付金额-->
<select id="getPayPrice" parameterType="map" resultType="decimal">
SELECT
price
FROM
join_group_cipher c
LEFT JOIN book_classify_buy_record r ON c.classify_id = r.classify_id
AND c.wechat_user_id = r.wechat_user_id
WHERE
c.qrcode_id = #{qrcodeId}
AND c.wx_id = #{wxId}
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.group.dao.impl.TempletRelevanceDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.TempletRelevance">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="templet_id" property="templetId" jdbcType="BIGINT"/>
<result column="large_templet" property="largeTemplet" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id, templet_id, large_templet
</sql>
<insert id="insert" parameterType="com.pcloud.book.group.entity.TempletRelevance" useGeneratedKeys="true"
keyProperty="id">
insert into templet_relevance
<trim prefix="(" suffix=")" suffixOverrides=",">
templet_id,
large_templet
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{templetId,jdbcType=BIGINT},
#{largeTemplet,jdbcType=INTEGER}
</trim>
</insert>
<!--根据模板id查询大类id-->
<select id="getByTempletId" parameterType="Long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from templet_relevance
where templet_id=#{templetId} order by id desc limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -275,4 +275,12 @@
where generation = #{_parameter}
</select>
<!--根据状态获取群数量-->
<select id="countByState" parameterType="map" resultType="Integer">
select count(1) from weixin_qrcode t where t.robot_wx_id in
<foreach collection="altIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
and use_state=#{state}
</select>
</mapper>
\ No newline at end of file
......@@ -177,6 +177,33 @@
order by set_type desc, matching_rule desc, bk.id desc limit 1
</select>
<select id="getKeywordIds" resultType="ReplyKeywordDTO" parameterType="map">
SELECT
k.id keywordId,
k.keywords,
k.reply_type replyType,
k.content,
k.description,
k.link_url linkUrl,
k.pic_url picUrl,
bk.is_warehouse as isWarehouse,
bk.warehouse_id as warehouseId,
bk.classify_id as classifyId,
bk.book_group_id as bookGroupId,
k.reply_type replyType
FROM
book_keyword bk
JOIN
keyword k ON bk.keyword_id = k.id
WHERE
bk.is_delete = 0 AND k.is_delete = 0
AND classify_id in (0, ${classifyId})
AND book_group_id in (${bookGroupId})
AND ((k.keywords = #{content} and matching_rule = 1 ) or (k.keywords like
concat('%',#{content},'%') and matching_rule = 0))
order by set_type desc, matching_rule desc, bk.id desc
</select>
<select id="checkKeyword" resultType="Boolean" parameterType="map">
SELECT
count(1)
......
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