Commit a0c692fe authored by shiyu's avatar shiyu

专场商品列表查询新是否订阅专场

parent 529e7684
......@@ -319,4 +319,9 @@ public class SupplierItemVo implements Entity {
*/
private String shareTip;
/**
* 商品在专场中是否被关注
*/
private Boolean isFollowed;
}
......@@ -612,7 +612,7 @@ public class SendMsgServiceImpl implements SendMsgService {
* @param auctionOfferNoticeMsg
* @return
*/
public boolean sendSpecialPerformanceStartMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
public Result sendSpecialPerformanceStartMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
String openId = auctionOfferNoticeMsg.getOpenId();
String token = officialAccountApi.getAccessToken();
String url = SEND_SUBSCRIBE_MSG_URL + "?access_token=" + token;
......@@ -643,10 +643,10 @@ public class SendMsgServiceImpl implements SendMsgService {
String errmsg = JsonUtils.getValueByPath(responseStr, "errmsg");
if (!"0".equals(errorCode)) {
logger.error("openid : {}, 发送专场即将开始订阅消息, errorCode : {}, errmsg : {} ", openId, errorCode, errmsg);
return false;
return Result.failed(responseStr);
}
logger.info("============= 发送专场即将开始订阅消息成功 ===========");
return true;
return Result.success();
}
......@@ -655,7 +655,7 @@ public class SendMsgServiceImpl implements SendMsgService {
* @param auctionOfferNoticeMsg
* @return
*/
public boolean sendSpecialPerformanceEndMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
public Result sendSpecialPerformanceEndMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
String openId = auctionOfferNoticeMsg.getOpenId();
String token = officialAccountApi.getAccessToken();
String url = SEND_SUBSCRIBE_MSG_URL + "?access_token=" + token;
......@@ -691,10 +691,10 @@ public class SendMsgServiceImpl implements SendMsgService {
String errmsg = JsonUtils.getValueByPath(responseStr, "errmsg");
if (!"0".equals(errorCode)) {
logger.error("openid : {}, 发送专场即将结束订阅消息, errorCode : {}, errmsg : {} ", openId, errorCode, errmsg);
return false;
return Result.failed(responseStr);
}
logger.info("============= 发送专场即将结束订阅消息成功 ===========");
return true;
return Result.success();
}
......
......@@ -81,4 +81,11 @@ public interface SendMsgService {
String getOpenIdByUserId(long userId);
Result sendSpecialPerformanceStartMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg);
Result sendSpecialPerformanceEndMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg);
}
......@@ -11,6 +11,8 @@ public interface DisposableSubscribeRecordDao {
boolean update(DisposableSubscribeRecord disposableSubscribeRecord);
boolean updateInvalid(String openid, long targetId, String templateId);
/**
* 是否存在
* @param openid
......@@ -27,5 +29,11 @@ public interface DisposableSubscribeRecordDao {
*/
boolean isSubscribed(String openid, long targetId, String templateId);
boolean isSubscribed(long userId, long targetId, int type);
List<DisposableSubscribeRecord> findList(DisposableSubscribeRecordRequestDto dto);
List<DisposableSubscribeRecord> findValid(long userId);
}
......@@ -10,6 +10,8 @@ import java.util.List;
@Data
public class SpecialPerformanceRequestDto extends BaseRequestDto implements Entity {
private Long userId;
private Integer id;
/**
......
......@@ -37,6 +37,20 @@ public class DisposableSubscribeRecordDaoImpl implements DisposableSubscribeReco
return disposableSubscribeRecordMapper.updateByExampleSelective(disposableSubscribeRecord, example) > 0;
}
@Override
public boolean updateInvalid(String openid, long targetId, String templateId) {
DisposableSubscribeRecordExample example = new DisposableSubscribeRecordExample();
DisposableSubscribeRecordExample.Criteria criteria = example.createCriteria();
criteria.andOpenidEqualTo(openid);
criteria.andTargetIdEqualTo(targetId);
criteria.andTemplateIdEqualTo(templateId);
DisposableSubscribeRecord disposableSubscribeRecord = new DisposableSubscribeRecord();
disposableSubscribeRecord.setIsValid(false);
disposableSubscribeRecord.setUpdateTime(new Date());
return disposableSubscribeRecordMapper.updateByExampleSelective(disposableSubscribeRecord, example) > 0;
}
@Override
public boolean isExisted(String openid, long targetId, String templateId) {
DisposableSubscribeRecordExample example = new DisposableSubscribeRecordExample();
......@@ -58,6 +72,17 @@ public class DisposableSubscribeRecordDaoImpl implements DisposableSubscribeReco
return disposableSubscribeRecordMapper.countByExample(example) > 0;
}
@Override
public boolean isSubscribed(long userId, long targetId, int type) {
DisposableSubscribeRecordExample example = new DisposableSubscribeRecordExample();
DisposableSubscribeRecordExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andTargetIdEqualTo(targetId);
criteria.andTypeEqualTo(type);
criteria.andIsValidEqualTo(true);
return disposableSubscribeRecordMapper.countByExample(example) > 0;
}
@Override
public List<DisposableSubscribeRecord> findList(DisposableSubscribeRecordRequestDto dto) {
DisposableSubscribeRecordExample example = new DisposableSubscribeRecordExample();
......@@ -71,4 +96,14 @@ public class DisposableSubscribeRecordDaoImpl implements DisposableSubscribeReco
PageHelper.startPage(dto.getPage(), dto.getLimit());
return disposableSubscribeRecordMapper.selectByExample(example);
}
@Override
public List<DisposableSubscribeRecord> findValid(long userId) {
DisposableSubscribeRecordExample example = new DisposableSubscribeRecordExample();
DisposableSubscribeRecordExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andIsValidEqualTo(true);
return disposableSubscribeRecordMapper.selectByExample(example);
}
}
package com.wwdz.ch.db.mapper.distribution;
import com.wwdz.ch.db.domain.distribution.SpecialPerformanceItemFollow;
import com.wwdz.ch.db.domain.distribution.SpecialPerformanceItemFollowExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface SpecialPerformanceItemFollowMapper {
long countByExample(SpecialPerformanceItemFollowExample example);
int deleteByExample(SpecialPerformanceItemFollowExample example);
int deleteByPrimaryKey(Long id);
int insert(SpecialPerformanceItemFollow record);
int insertSelective(SpecialPerformanceItemFollow record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table special_performance_item_follow
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
SpecialPerformanceItemFollow selectOneByExample(SpecialPerformanceItemFollowExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table special_performance_item_follow
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
SpecialPerformanceItemFollow selectOneByExampleSelective(@Param("example") SpecialPerformanceItemFollowExample example, @Param("selective") SpecialPerformanceItemFollow.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table special_performance_item_follow
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<SpecialPerformanceItemFollow> selectByExampleSelective(@Param("example") SpecialPerformanceItemFollowExample example, @Param("selective") SpecialPerformanceItemFollow.Column ... selective);
List<SpecialPerformanceItemFollow> selectByExample(SpecialPerformanceItemFollowExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table special_performance_item_follow
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
SpecialPerformanceItemFollow selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") SpecialPerformanceItemFollow.Column ... selective);
SpecialPerformanceItemFollow selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") SpecialPerformanceItemFollow record, @Param("example") SpecialPerformanceItemFollowExample example);
int updateByExample(@Param("record") SpecialPerformanceItemFollow record, @Param("example") SpecialPerformanceItemFollowExample example);
int updateByPrimaryKeySelective(SpecialPerformanceItemFollow record);
int updateByPrimaryKey(SpecialPerformanceItemFollow record);
}
\ No newline at end of file
......@@ -72,7 +72,7 @@
<javaClientGenerator type="XMLMAPPER" targetPackage="com.wwdz.ch.db.mapper.distribution"
targetProject="ch-dao/src/main/java"/>
<table tableName="disposable_subscribe_record" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<table tableName="special_performance_item_follow" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
......
......@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.impl.distribution;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.AuctionEnum;
import com.wwdz.ch.core.consts.DisposableSubscribeRecordEnum;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.SpecialPerformanceEnum;
import com.wwdz.ch.core.entity.SupplierItemVo;
......@@ -12,6 +13,7 @@ import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.MediaUtil;
import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.dao.DisposableSubscribeRecordDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.User;
......@@ -70,6 +72,9 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
@Autowired
RedisUtils redisUtils;
@Autowired
DisposableSubscribeRecordDao disposableSubscribeRecordDao;
private final static String SPECIAL_PERFORMANCE_URL = "/pages/saleSpecialList/index";
private final static String SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY = "SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY:";
......@@ -389,6 +394,11 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
resultMap.put("endTime", specialPerformance.getEndTime());
resultMap.put("title", specialPerformance.getTitle());
resultMap.put("specialPerformanceId", specialPerformance.getId());
//判断用户是否订阅过消息
resultMap.put("subscribeStart", disposableSubscribeRecordDao.isSubscribed(dto.getUserId(), specialPerformance.getId(), DisposableSubscribeRecordEnum.TypeEnum.PRE_START.getType()));
resultMap.put("subscribeEnd", disposableSubscribeRecordDao.isSubscribed(dto.getUserId(), specialPerformance.getId(), DisposableSubscribeRecordEnum.TypeEnum.PRE_END.getType()));
//当前时间大于专场结束时间则修改专场的状态
if (now.after(specialPerformance.getEndTime())) {
SpecialPerformance updateDto = new SpecialPerformance();
......
......@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.job;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.AuctionEnum;
import com.wwdz.ch.core.consts.DisposableSubscribeRecordEnum;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.SpecialPerformanceEnum;
import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg;
......@@ -12,6 +13,7 @@ import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.core.util.StringUtil;
import com.wwdz.ch.db.dao.DisposableSubscribeRecordDao;
import com.wwdz.ch.db.dao.FollowFansRecordDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.distribution.*;
......@@ -20,10 +22,12 @@ import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.dto.request.FollowFansRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.db.dto.request.distribution.DisposableSubscribeRecordRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceConfigRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto;
import com.wwdz.ch.wx.service.distribution.DistributionOrderService;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.JsonUtils;
import com.xxdxxs.utils.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
......@@ -85,6 +89,10 @@ public class SpecialPerformanceNoticeJob {
@Autowired
FollowFansRecordDao followFansRecordDao;
@Autowired
DisposableSubscribeRecordDao disposableSubscribeRecordDao;
@Value("${spring.profiles.active}")
private String env;
......@@ -124,64 +132,51 @@ public class SpecialPerformanceNoticeJob {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行专场即将开始通知任务<<<<<<<<<<<<<<<<<<<<<");
return;
}
//正式环境测试, 不发送消息
/* if (true) {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> 正式环境测试, 不执行专场即将开始通知任务<<<<<<<<<<<<<<<<<<<<<");
return;
}*/
logger.info("当前即将开始的专场id:{}, 名称为 {} ", specialPerformance.getId(), specialPerformance.getTitle());
//查询专场的商品所属藏家
Long creatorId = null;
SpecialPerformanceConfigRequestDto specialPerformanceConfigRequestDto = new SpecialPerformanceConfigRequestDto();
specialPerformanceConfigRequestDto.setSpecialPerformanceId(specialPerformance.getId());
List<SpecialPerformanceConfig> specialPerformanceConfigList = specialPerformanceConfigDao.findList(specialPerformanceConfigRequestDto);
if (!CollectionUtils.isEmpty(specialPerformanceConfigList)) {
SpecialPerformanceConfig specialPerformanceConfig = specialPerformanceConfigList.get(0);
long itemId = specialPerformanceConfig.getItemId();
AuctionConfig auctionConfig = auctionConfigDao.findByItemId(itemId);
if (auctionConfig == null) {
return;
}
creatorId = auctionConfig.getCreatorId();
//查询该用户的粉丝列表
}
if (creatorId == null) {
logger.error("================ 专场商品所属藏家id为空,不发送通知 ================ ");
return;
}
//发送短信通知
String url = wxAppletApi.getUrlLink(SPECIAL_PERFORMANCE_URL,"specialId=" + specialPerformance.getId());
String msg = specialPerformance.getTitle() + "将在" + DateUtils.toString(specialPerformance.getStartTime()) + "开始,请前往"+ url + "查看";
//发送专场开始订阅通知
DisposableSubscribeRecordRequestDto disposableSubscribeRecordRequestDto = new DisposableSubscribeRecordRequestDto();
disposableSubscribeRecordRequestDto.setTargetId(Long.valueOf(specialPerformance.getId()));
disposableSubscribeRecordRequestDto.setType(DisposableSubscribeRecordEnum.TypeEnum.PRE_START.getType());
boolean hasNextPage = true;
int page = 1;
FollowFansRecordRequestDto followFansRecordRequestDto = new FollowFansRecordRequestDto();
followFansRecordRequestDto.setFollowerId(creatorId);
String url = wxAppletApi.getUrlLink(SPECIAL_PERFORMANCE_URL,"specialId=" + specialPerformance.getId());
String msg = specialPerformance.getTitle() + "将在" + DateUtils.toString(specialPerformance.getStartTime()) + "开始,请前往"+ url + "查看";
while (hasNextPage) {
List<FollowFansRecord > followFansRecordList = followFansRecordDao.findList(followFansRecordRequestDto);
PageInfo pageInfo = new PageInfo(followFansRecordList);
for (FollowFansRecord followFansRecord : followFansRecordList) {
long userId = followFansRecord.getFansId();
List<DisposableSubscribeRecord> disposableSubscribeRecordList = disposableSubscribeRecordDao.findList(disposableSubscribeRecordRequestDto);
PageInfo pageInfo = new PageInfo(disposableSubscribeRecordList);
for (DisposableSubscribeRecord disposableSubscribeRecord : disposableSubscribeRecordList) {
AuctionOfferNoticeMsg auctionOfferNoticeMsg = new AuctionOfferNoticeMsg();
auctionOfferNoticeMsg.setSpecialPerformanceTitle(specialPerformance.getTitle());
auctionOfferNoticeMsg.setSpecialPerformanceStartTime(DateUtils.toString(specialPerformance.getStartTime()));
auctionOfferNoticeMsg.setOpenId(disposableSubscribeRecord.getOpenid());
Result result = sendMsgService.sendSpecialPerformanceStartMsg(auctionOfferNoticeMsg);
if (!result.getSuccess()) {
String errorCode = JsonUtils.getValueByPath(result.getData().toString(), "errcode");
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if (!"43101".equals(errorCode) && !"43108".equals(errorCode)) {
//发订阅消息送失败发短信
long userId = disposableSubscribeRecord.getUserId();
aliSmsSender.sendSms(userId, msg);
}
} else {
//发送成功后订阅状态改为无效
disposableSubscribeRecordDao.updateInvalid(disposableSubscribeRecord.getOpenid(), disposableSubscribeRecord.getTargetId(), disposableSubscribeRecord.getTemplateId());
}
}
if (pageInfo.isHasNextPage()) {
page = page + 1;
followFansRecordRequestDto.setPage(page);
logger.info("要发送短信通知的用户数据总页数为 : {}, 当前为 : {}", pageInfo.getPages(), page);
disposableSubscribeRecordRequestDto.setPage(page);
logger.info("要发送专场开始订阅消息的用户数据总页数为 : {}, 当前为 : {}", pageInfo.getPages(), page);
} else {
hasNextPage = false;
logger.info("============= 发送专场开始短信循环结束 =============");
}
if (page > 500) {
hasNextPage = false;
logger.info("============= 发送专场开始短信超出上限,停止发送 =============");
logger.info("============= 发送专场开始订阅消息循环结束 =============");
break;
}
}
logger.info("================专场id: {}, 即将开始通知任务,提醒短信发送成功 ==============", specialPerformance.getId());
logger.info("================专场id: {}, 即将开始通知消息全部发送成功 ==============", specialPerformance.getId());
redisUtils.set(abortStartKey, specialPerformance.getId(), 3600 * 24);
} else {
logger.info("================专场id: {}, 通知任务已经完成,无需重复发送 ==============", specialPerformance.getId());
logger.info("================专场id: {}, 即将开始通知任务已经完成,无需重复发送 ==============", specialPerformance.getId());
}
} catch (Exception e) {
logger.error("专场即将开始通知任务 error {}", e);
......
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