Commit a1dfefbb by 杨涛

处理打卡旧数据

parent 97402fdb
......@@ -24,5 +24,9 @@ public interface BookClockInfoService {
@PostMapping("/sendBookClockGroupMessage")
void sendBookClockGroupMessage(@RequestBody Map<String, Object> map) throws BizException;
@ApiOperation(value = "处理关联应用的打卡的旧数据", httpMethod = "GET")
@RequestMapping(value = "/dealOldData4WeixinClock", method = RequestMethod.GET)
void dealOldData4WeixinClock();
}
......@@ -67,4 +67,8 @@ public interface BookClockBiz {
*/
void deleteBookGroupClock(Long bookClockInfoId,Long adviserId);
/**
* 处理关联应用的打卡的旧数据
*/
void dealOldData4WeixinClock();
}
......@@ -28,6 +28,8 @@ import com.pcloud.book.group.dao.WeixinQrcodeDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.weixinclock.biz.WeixinClockBiz;
import com.pcloud.book.weixinclock.dto.WeixinClockDto;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBean;
......@@ -48,6 +50,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
/**
......@@ -84,6 +88,8 @@ public class BookClockBizImpl implements BookClockBiz {
private ScheduleService scheduleService;
@Autowired
private WeixinQrcodeDao weixinQrcodeDao;
@Autowired
private WeixinClockBiz weixinClockBiz;
/**
......@@ -416,4 +422,30 @@ public class BookClockBizImpl implements BookClockBiz {
throw new BookBizException(BookBizException.ERROR,"删除定时任务失败!");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void dealOldData4WeixinClock() {
new Thread(() -> {
WeixinClockDto weixinClockDto = new WeixinClockDto();
weixinClockDto.setClockGuide("每日打卡,养成良好习惯");
weixinClockDto.setClockIntroduction("欢迎加入打卡,每天一次,养成良好习惯");
weixinClockDto.setClockKeyword("每日打卡");
List<BookClockInfoDTO> clockInfoIds = bookClockInfoDao.getAllClockInfoIds();
if(!ListUtils.isEmpty(clockInfoIds)){
for(BookClockInfoDTO bookClockInfoDTO: clockInfoIds){
List<Long> list1 = bookGroupClockDao.getClassifyIdsByBookGroupId(bookClockInfoDTO.getBookClockInfoId());
List<Long> list2 = bookGroupClockDao.getClassifyIdsByClassfyId(bookClockInfoDTO.getBookClockInfoId());
list1.addAll(list2);
List<Long> resultList = list1.stream().distinct().collect(Collectors.toList());
if(!ListUtils.isEmpty(resultList)) {
weixinClockDto.setCreateUser(bookClockInfoDTO.getCreateUser());
weixinClockDto.setLastModifiedUser(bookClockInfoDTO.getCreateUser());
weixinClockDto.setGroupClassifyIds(resultList);
weixinClockBiz.createWeixinClock(weixinClockDto);
}
}
}
}).start();
}
}
......@@ -86,4 +86,6 @@ public interface BookClockInfoDao extends BaseDao<BookClockInfo> {
* @param paramMap
*/
void deleteBookClockInfo(Map<String, Object> paramMap);
List<BookClockInfoDTO> getAllClockInfoIds();
}
......@@ -70,4 +70,8 @@ public interface BookGroupClockDao extends BaseDao<BookGroupClock> {
* @param paramMap
*/
void deleteBookGroupClock(Map<String,Object> paramMap);
List<Long> getClassifyIdsByBookGroupId(Long bookClockInfoId);
List<Long> getClassifyIdsByClassfyId(Long bookClockInfoId);
}
......@@ -135,5 +135,11 @@ public class BookClockInfoDaoImpl extends BaseDaoImpl<BookClockInfo> implements
super.sqlSessionTemplate.delete(getStatement("deleteBookClockInfo"),paramMap);
}
@Override
public List<BookClockInfoDTO> getAllClockInfoIds() {
Map<String,Object> paramMap = new HashMap<>();
return super.sqlSessionTemplate.selectList(getStatement("getAllClockInfoIds"),paramMap);
}
}
......@@ -6,6 +6,7 @@ import com.pcloud.book.clock.entity.BookGroupClock;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -100,4 +101,18 @@ public class BookGroupClockDaoImpl extends BaseDaoImpl<BookGroupClock> implement
public void deleteBookGroupClock(Map<String, Object> paramMap) {
super.sqlSessionTemplate.delete(getStatement("deleteBookGroupClock"),paramMap);
}
@Override
public List<Long> getClassifyIdsByBookGroupId(Long bookClockInfoId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookClockInfoId",bookClockInfoId);
return super.sqlSessionTemplate.selectList(getStatement("getClassifyIdsByBookGroupId"),paramMap);
}
@Override
public List<Long> getClassifyIdsByClassfyId(Long bookClockInfoId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookClockInfoId",bookClockInfoId);
return super.sqlSessionTemplate.selectList(getStatement("getClassifyIdsByClassfyId"),paramMap);
}
}
......@@ -64,4 +64,17 @@ public class BookClockInfoServiceImpl implements BookClockInfoService {
// bookClockBiz.sendBookClockGroupMessage(map);
}
/**
* @description 处理关联应用的打卡的旧数据
* @author 杨涛
* @date 2019/5/10 10:28
*/
@Override
@RequestMapping(value = "/dealOldData4WeixinClock", method = RequestMethod.GET)
public void dealOldData4WeixinClock() {
bookClockBiz.dealOldData4WeixinClock();
}
}
......@@ -9,6 +9,7 @@ import com.pcloud.book.clock.dto.PushBookClockKeywordDTO;
import com.pcloud.book.consumer.app.AppConsr;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
......@@ -122,6 +123,8 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
private WeixinClockCheck weixinClockCheck;
@Autowired
private WeixinClockPrizeRecordDao weixinClockPrizeRecordDao;
@Autowired
private AdviserConsr adviserConsr;
private static final ThreadFactory NAMED_THREAD_FACTORY = new ThreadFactoryBuilder()
.setNameFormat("weixinclock-pool-%d").build();
......@@ -384,7 +387,7 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
return content.equalsIgnoreCase(aimKeyword);
}
private String getClockRankUrl(Long clockPrizeId, String wxGroupId, String wxUserId){
private String getClockRankUrl(Long adviserId, Long clockPrizeId, String wxGroupId, String wxUserId){
StringBuffer sbu=new StringBuffer();
if(null != clockPrizeId && !clockPrizeId.equals(0L)) {
AppDto appDto = appConsr.getBaseById(clockPrizeId);
......@@ -399,8 +402,24 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
sbu.append(protocol).append(accountSettingDto.getDomain()).append("/W")
.append(accountSettingDto.getAccountSettingId()).append("/clock").append("?wxGroupId=")
.append(wxGroupId).append("&wxUserId=").append(wxUserId);
return UrlUtils.getShortUrl4Own(sbu.toString());
}
if(null != adviserId && !adviserId.equals(0L)){
Long channelId = adviserConsr.getDefaultChannel(adviserId);
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(channelId);
if (null == accountSettingDto) {
return "";
}
String protocol = accountSettingDto.getProtocol();
if (StringUtils.isEmpty(protocol)) {
protocol = ChannelConstants.HTTP;
}
sbu.append(protocol).append(accountSettingDto.getDomain()).append("/W")
.append(accountSettingDto.getAccountSettingId()).append("/clock").append("?wxGroupId=")
.append(wxGroupId).append("&wxUserId=").append(wxUserId);
return UrlUtils.getShortUrl4Own(sbu.toString());
}
return UrlUtils.getShortUrl4Own(sbu.toString());
return "";
}
private String getClockRewardUrl(Long clockPrizeId){
......@@ -452,8 +471,13 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
WeixinClockDto weixinClockDto = weixinClockGroupClassifyDao.getClockBaseInfoByClassify(classifyQrcodeInfo.getClassifyId());
WeixinClockMember clockMember = weixinClockMemberDao.getByWxUserId(wechatGroupId, userWxId);
AppDto appDto = appConsr.getBaseById(weixinClockDto.getClockPrizeId());
appDto = null == appDto ? new AppDto() :appDto;
Long wechatUserId = readerConsr.getWechatUserId(userWxId, appDto.getChannelId());
Long channelId = null;
if(null == appDto) {
channelId = adviserConsr.getDefaultChannel(weixinClockDto.getCreateUser());
}else {
channelId = appDto.getChannelId();
}
Long wechatUserId = readerConsr.getWechatUserId(userWxId, channelId);
GroupUserDTO groupUserDTO = wechatGroupConsr.getWxUserInfoByWxUserId(userWxId);
groupUserDTO = null == groupUserDTO ? new GroupUserDTO() : groupUserDTO;
Long weixinClockMemberId = clockMember == null ? null : clockMember.getWeixinClockMemberId();
......@@ -493,48 +517,53 @@ public class WeixinClockBizImpl implements WeixinClockBiz {
//发topic,增加抽奖次数
//发送抽奖的TOPIC
Long clockDays = weixinClockTopicDao.getClockCountByUser(wechatGroupId, userWxId);
if(null != wechatUserId && !wechatUserId.equals(0L)) {
EXECUTOR_SERVICE.execute(() -> {
LOGGER.info("异步校验是否满足抽奖要求,clockDays=" + clockDays);
PromotionOrderDto promotionOrderDto = new PromotionOrderDto();
List<PromotionGiftDto> promotionGiftDtoList = new ArrayList<>();
PromotionGiftDto promotionGiftDto = new PromotionGiftDto();
promotionGiftDto.setTargetClass(PromotionOrderEnum.TARGET_CLASS_APP.getCode());
promotionGiftDto.setTargetType(AppTypeEnum.DRAW.value);
promotionGiftDto.setTargetId(weixinClockDto.getClockPrizeId());
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
promotionGiftDto.setGrantNum(grantNum == null ? "0" : grantNum.toString());
promotionGiftDtoList.add(promotionGiftDto);
promotionOrderDto.setGifts(promotionGiftDtoList);
promotionOrderDto.setUserId(wechatUserId);
LOGGER.info("发送抽奖规则,参数:promotionOrderDto=" + promotionOrderDto);
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.GIVE_GIFT, promotionOrderDto);
});
} else {
WeixinClockPrizeRecord weixinClockPrizeRecord1 = weixinClockPrizeRecordDao.selectByWxUserIdAndAppId(userWxId, weixinClockDto.getClockPrizeId());
LOGGER.info("weixinClockPrizeRecord1====="+weixinClockPrizeRecord1);
if (null == weixinClockPrizeRecord1) {
WeixinClockPrizeRecord weixinClockPrizeRecord2 = new WeixinClockPrizeRecord();
weixinClockPrizeRecord2.setClockPrizeId(weixinClockDto.getClockPrizeId());
weixinClockPrizeRecord2.setWxUserId(userWxId);
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
weixinClockPrizeRecord2.setPrizeTime(grantNum == null ? 0 : grantNum);
LOGGER.info("weixinClockPrizeRecord2------"+weixinClockPrizeRecord2);
weixinClockPrizeRecordDao.insert(weixinClockPrizeRecord2);
if(null != weixinClockDto.getClockPrizeId()) {
if (null != wechatUserId && !wechatUserId.equals(0L)) {
EXECUTOR_SERVICE.execute(() -> {
LOGGER.info("异步校验是否满足抽奖要求,clockDays=" + clockDays);
PromotionOrderDto promotionOrderDto = new PromotionOrderDto();
List<PromotionGiftDto> promotionGiftDtoList = new ArrayList<>();
PromotionGiftDto promotionGiftDto = new PromotionGiftDto();
promotionGiftDto.setTargetClass(PromotionOrderEnum.TARGET_CLASS_APP.getCode());
promotionGiftDto.setTargetType(AppTypeEnum.DRAW.value);
promotionGiftDto.setTargetId(weixinClockDto.getClockPrizeId());
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
promotionGiftDto.setGrantNum(grantNum == null ? "0" : grantNum.toString());
promotionGiftDtoList.add(promotionGiftDto);
promotionOrderDto.setGifts(promotionGiftDtoList);
promotionOrderDto.setUserId(wechatUserId);
LOGGER.info("发送抽奖规则,参数:promotionOrderDto=" + promotionOrderDto);
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.GIVE_GIFT, promotionOrderDto);
});
} else {
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
grantNum = grantNum == null ? 0 : grantNum;
weixinClockPrizeRecordDao.updatePrizeTime(userWxId, weixinClockDto.getClockPrizeId(), grantNum);
WeixinClockPrizeRecord weixinClockPrizeRecord1 = weixinClockPrizeRecordDao.selectByWxUserIdAndAppId(userWxId, weixinClockDto.getClockPrizeId());
LOGGER.info("weixinClockPrizeRecord1=====" + weixinClockPrizeRecord1);
if (null == weixinClockPrizeRecord1) {
WeixinClockPrizeRecord weixinClockPrizeRecord2 = new WeixinClockPrizeRecord();
weixinClockPrizeRecord2.setClockPrizeId(weixinClockDto.getClockPrizeId());
weixinClockPrizeRecord2.setWxUserId(userWxId);
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
weixinClockPrizeRecord2.setPrizeTime(grantNum == null ? 0 : grantNum);
LOGGER.info("weixinClockPrizeRecord2------" + weixinClockPrizeRecord2);
weixinClockPrizeRecordDao.insert(weixinClockPrizeRecord2);
} else {
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
grantNum = grantNum == null ? 0 : grantNum;
weixinClockPrizeRecordDao.updatePrizeTime(userWxId, weixinClockDto.getClockPrizeId(), grantNum);
}
}
}
//获取我的新排名
Integer newOrder = weixinClockMemberDao.getMyNewOrder(wechatGroupId, userWxId);
String clockRewardUrl = getClockRewardUrl(weixinClockDto.getClockPrizeId());
String clockRankUrl = getClockRankUrl(weixinClockDto.getClockPrizeId(), wechatGroupId, userWxId);
String clockRankUrl = getClockRankUrl(weixinClockDto.getCreateUser(), weixinClockDto.getClockPrizeId(), wechatGroupId, userWxId);
Calendar today = Calendar.getInstance();
int month = today.get(Calendar.MONTH) + 1;
int dayOfMonth = today.get(Calendar.DAY_OF_MONTH);
Integer grantNum = weixinClockRewardDao.getGrantNumFromReward(weixinClockDto.getWeixinClockId(), clockDays);
if(null == weixinClockDto.getClockPrizeId()){
grantNum = 0;
}
if(null != grantNum && !grantNum.equals(0)){
sendContent = "@" + nickname + " "+ weixinClockDto.getClockIntroduction() + "\n" + month + "月" + dayOfMonth + "日打卡成功,你已累积打卡"
+ clockDays + "天,排名第" +
......
......@@ -34,8 +34,8 @@ public class WeixinClockCheckImpl implements WeixinClockCheck {
if(StringUtil.isEmpty(weixinClockDto.getClockIntroduction())){
throw new BookBizException(BookBizException.ERROR,"缺少打卡简介!");
}
if(null == weixinClockDto.getClockPrizeId()){
/*if(null == weixinClockDto.getClockPrizeId()){
throw new BookBizException(BookBizException.ERROR,"缺少打卡的奖励应用ID!");
}
}*/
}
}
......@@ -198,5 +198,10 @@
WHERE book_clock_info_id = #{bookClockInfoId}
</delete>
<select id="getAllClockInfoIds" parameterType="map" resultMap="BaseResultMapDTO">
select <include refid="Base_Column_List"/>
from book_clock_info where origin_type = 'APP'
</select>
</mapper>
\ No newline at end of file
......@@ -140,5 +140,31 @@
WHERE book_clock_info_id = #{bookClockInfoId}
</delete>
<select id="getClassifyIdsByBookGroupId" parameterType="map" resultType="Long">
SELECT DISTINCT
t2.id
FROM
book_group_clock t1
LEFT JOIN book_group_classify t2 ON t1.book_group_id = t2.book_group_id
LEFT JOIN weixin_clock_group_classify t3 ON t2.id = t3.book_group_classify_id
WHERE
t2.is_delete = 0
AND t3.weixin_clock_group_classify_id IS NULL
AND t1.book_clock_info_id = #{bookClockInfoId}
</select>
<select id="getClassifyIdsByClassfyId" parameterType="map" resultType="Long">
SELECT DISTINCT
t2.id
FROM
book_group_clock t1
LEFT JOIN book_group_classify t2 ON t1.classify_id = t2.id
LEFT JOIN weixin_clock_group_classify t3 ON t2.id = t3.book_group_classify_id
WHERE
t2.is_delete = 0
AND t3.weixin_clock_group_classify_id IS NULL
AND t1.book_clock_info_id = #{bookClockInfoId}
</select>
</mapper>
\ No newline at end of file
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