Commit 87e609e6 by 杨涛

fix 必要参数校验

parent d5f2c25d
......@@ -60,7 +60,8 @@ public class BookClockInfoServiceImpl implements BookClockInfoService {
@RequestMapping(value = "sendBookClockGroupMessage", method = RequestMethod.POST)
public void sendBookClockGroupMessage(@RequestBody Map<String, Object> map) throws BizException {
LOGGER.info("内部接口群发消息被调用"+map.toString());
bookClockBiz.sendBookClockGroupMessage(map);
return;
// bookClockBiz.sendBookClockGroupMessage(map);
}
}
......@@ -39,7 +39,6 @@ import com.pcloud.book.keywords.vo.SetGuideVO;
import com.pcloud.book.keywords.vo.UpdateGuideVO;
import com.pcloud.book.weixinclock.dao.WeixinClockGroupClassifyDao;
import com.pcloud.book.weixinclock.dto.WeixinClockDto;
import com.pcloud.book.weixinclock.entity.WeixinClockGroupClassify;
import com.pcloud.channelcenter.wechat.dto.AccountSettingDto;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.utils.ListUtils;
......@@ -391,7 +390,7 @@ public class BookGuideBizImpl implements BookGuideBiz {
SendWeixinRequestTools.sendAccountMessage(weixinGroupId, bookGuide.getRecommendLanguage(), robotId, wechatInfo, pushAddUserMessageDTO.getIp());
}
//校验该群是否与微信群打卡有关
List<Long> bookClockInfoIdList = bookClockCheck.checkGroupIsClock(classifyQrcodeInfo);
/*List<Long> bookClockInfoIdList = bookClockCheck.checkGroupIsClock(classifyQrcodeInfo);
if(!ListUtils.isEmpty(bookClockInfoIdList)){
Map<String,Object> paramMap = new HashMap<>();
int i = 0;
......@@ -414,7 +413,7 @@ public class BookGuideBizImpl implements BookGuideBiz {
}
}
}
}*/
}
@ParamLog("推关学习报告/猜谜语关键词消息")
......
......@@ -63,15 +63,10 @@ public class WxGroupSendTextListener {
if(flag && SendMessageTypeEnum.GROUP.getCode().equals(sendTextDTO.getCode())){
weixinClockBiz.sendKeywordMessage(sendTextDTO.getTextContent().trim(), wechatUserId, sendTextDTO.getWechatGroupId(), sendTextDTO.getWxId(), sendTextDTO.getIp());
} else {
BookClockInfoDTO bookClockInfoDTO = bookClockCheck.checkKeywordIsClock(sendTextDTO.getTextContent().trim(), sendTextDTO.getWechatGroupId());
if (null != bookClockInfoDTO && SendMessageTypeEnum.GROUP.getCode().equals(sendTextDTO.getCode())) {
bookClockKeywordBiz.sendKeywordMessage(bookClockInfoDTO, wechatUserId, sendTextDTO.getWechatGroupId(), sendTextDTO.getWxId(), sendTextDTO.getIp());
} else {
final long l = System.currentTimeMillis();
bookKeywordBiz.sendKeywordMessage(sendTextDTO.getTextContent().trim(), sendTextDTO.getWechatGroupId(), wechatUserId, sendTextDTO.getWxId(), sendTextDTO.getIp(), sendTextDTO.getCode());
log.info("[接收用户发送文本消息] 总耗时:{}ms ", System.currentTimeMillis() - l);
}
}
//猜谜语
riddleRecordBiz.riddleProcess(sendTextDTO);
}
......
package com.pcloud.book.weixinclock.biz.impl;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.pcloud.appcenter.app.dto.AppDto;
import com.pcloud.book.base.exception.BookBizException;
......@@ -15,6 +16,7 @@ import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.vo.BookGroupClassifyVO;
import com.pcloud.book.group.vo.ListGroupClassifyParam;
import com.pcloud.book.weixinclock.biz.WeixinClockBiz;
import com.pcloud.book.weixinclock.check.WeixinClockCheck;
import com.pcloud.book.weixinclock.dao.WeixinClockDao;
import com.pcloud.book.weixinclock.dao.WeixinClockGroupClassifyDao;
import com.pcloud.book.weixinclock.dao.WeixinClockMemberDao;
......@@ -70,6 +72,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -108,6 +115,14 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
private AmqpTemplate amqpTemplate;
@Autowired
private ReaderConsr readerConsr;
@Autowired
private WeixinClockCheck weixinClockCheck;
private static final ThreadFactory NAMED_THREAD_FACTORY = new ThreadFactoryBuilder()
.setNameFormat("weixinclock-pool-%d").build();
private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(5, 10, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), NAMED_THREAD_FACTORY, new ThreadPoolExecutor.CallerRunsPolicy());
@Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix;
......@@ -124,6 +139,7 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
if(null == weixinClockDto) {
throw new BookBizException(BookBizException.ERROR,"缺少必要参数!");
}
weixinClockCheck.checkParam4CreateWeixinClock(weixinClockDto);
WeixinClock weixinClock = new WeixinClock();
BeanUtils.copyProperties(weixinClockDto, weixinClock);
weixinClockDao.insert(weixinClock);
......@@ -219,6 +235,9 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
@ParamLog("删除微信群签到打卡")
@Transactional(rollbackFor = Exception.class)
public void deleteWeixinClock(Long weixinClockId, Long adviserId) throws BizException {
if(null == weixinClockId){
throw new BookBizException(BookBizException.ERROR,"缺少删除的必要参数");
}
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("weixinClockId",weixinClockId);
//删除对应的群分类
......@@ -238,6 +257,13 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
@ParamLog("修改微信群签到打卡")
@Transactional(rollbackFor = Exception.class)
public void updateWeixinClock(WeixinClockDto weixinClockDto) throws BizException {
if(null == weixinClockDto) {
throw new BookBizException(BookBizException.ERROR,"缺少必要参数!");
}
if(null == weixinClockDto.getWeixinClockId()){
throw new BookBizException(BookBizException.ERROR,"缺少修改的必要参数");
}
weixinClockCheck.checkParam4CreateWeixinClock(weixinClockDto);
Long weixinClockId = weixinClockDto.getWeixinClockId();
WeixinClock weixinClock = new WeixinClock();
BeanUtils.copyProperties(weixinClockDto, weixinClock);
......@@ -306,6 +332,9 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
@Override
@ParamLog("获取某个微信群签到打卡的所有群分类详情")
public PageBeanNew<BookGroupClassifyVO> listGroupClassifyDetail4Clock(Long weixinClockId, Integer currentPage, Integer numPerPage) throws BizException {
if(null == weixinClockId) {
throw new BookBizException(BookBizException.ERROR,"缺少微信打卡标识的必要参数!");
}
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("weixinClockId", weixinClockId);
PageParam pageParam = new PageParam(currentPage, numPerPage);
......@@ -438,6 +467,8 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
//发topic,增加抽奖次数
//发送抽奖的TOPIC
Long clockDays = weixinClockTopicDao.getClockCountByUser(wechatGroupId, userWxId);
EXECUTOR_SERVICE.execute(() -> {
LOGGER.info("异步校验是否满足抽奖要求,clockDays=" + clockDays);
PromotionOrderDto promotionOrderDto = new PromotionOrderDto();
List<PromotionGiftDto> promotionGiftDtoList = new ArrayList<>();
PromotionGiftDto promotionGiftDto = new PromotionGiftDto();
......@@ -445,13 +476,14 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
promotionGiftDto.setTargetType(AppTypeEnum.DRAW.value);
promotionGiftDto.setTargetId(weixinClockDto.getClockPrizeId());
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
promotionGiftDto.setGrantNum(grantNum == null ? "0" :grantNum.toString());
promotionGiftDto.setGrantNum(grantNum == null ? "0" : grantNum.toString());
promotionGiftDtoList.add(promotionGiftDto);
promotionOrderDto.setGifts(promotionGiftDtoList);
AppDto appDto = appConsr.getBaseById(weixinClockDto.getClockPrizeId());
promotionOrderDto.setUserId(readerConsr.getWechatUserId(userWxId, appDto.getChannelId()));
LOGGER.info("发送抽奖规则,参数:promotionOrderDto="+promotionOrderDto);
LOGGER.info("发送抽奖规则,参数:promotionOrderDto=" + promotionOrderDto);
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.GIVE_GIFT, promotionOrderDto);
});
//获取我的新排名
Integer newOrder = weixinClockMemberDao.getMyNewOrder(wechatGroupId, userWxId);
String clockRewardUrl = getClockRewardUrl(weixinClockDto.getClockPrizeId());
......
package com.pcloud.book.weixinclock.check;
import com.pcloud.book.weixinclock.dto.WeixinClockDto;
/**
* @author 杨涛
* @description 检查
* @date 2019/8/20 10:03
*/
public interface WeixinClockCheck {
void checkParam4CreateWeixinClock(WeixinClockDto weixinClockDto);
}
package com.pcloud.book.weixinclock.check.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.clock.entity.BookClockInfo;
import com.pcloud.book.weixinclock.check.WeixinClockCheck;
import com.pcloud.book.weixinclock.dto.WeixinClockDto;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author 杨涛
* @description 检查
* @date 2019/8/20 10:19
*/
@Component("weixinClockCheck")
public class WeixinClockCheckImpl implements WeixinClockCheck {
/**
* 创建微信签到打卡时的参数校验
* @param weixinClockDto
*/
@Override
public void checkParam4CreateWeixinClock(WeixinClockDto weixinClockDto) {
if(StringUtil.isEmpty(weixinClockDto.getClockKeyword())){
throw new BookBizException(BookBizException.ERROR,"缺少打卡关键词!");
}
if(StringUtil.isEmpty(weixinClockDto.getClockGuide())){
throw new BookBizException(BookBizException.ERROR,"缺少打卡引导语!");
}
if(StringUtil.isEmpty(weixinClockDto.getClockIntroduction())){
throw new BookBizException(BookBizException.ERROR,"缺少打卡简介!");
}
if(null == weixinClockDto.getClockPrizeId()){
throw new BookBizException(BookBizException.ERROR,"缺少打卡的奖励应用ID!");
}
}
}
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