| | |
| | | import com.ks.app.util.AlipayAppUtil; |
| | | import com.ks.daylucky.exception.UserMsgException; |
| | | import com.ks.daylucky.pojo.DO.UserInfo; |
| | | import com.ks.daylucky.pojo.DTO.UserMsgSettings; |
| | | import com.ks.daylucky.service.UserInfoExtraService; |
| | | import com.ks.daylucky.service.UserInfoService; |
| | | import com.ks.daylucky.service.UserMsgService; |
| | | import com.ks.daylucky.service.impl.AlipayTemplateMsgManager; |
| | | import com.ks.daylucky.service.impl.AppManager; |
| | | import com.ks.daylucky.util.activity.ActivityUtil; |
| | | import com.ks.daylucky.util.factory.LuckyMsgContentFactory; |
| | | import com.ks.daylucky.util.factory.UserMsgFactory; |
| | | import com.ks.lucky.pojo.DO.LuckyActivity; |
| | | import com.ks.lucky.pojo.DO.LuckyActivityAwardResult; |
| | | import com.ks.lucky.pojo.DO.LuckyActivityAwards; |
| | | import com.ks.lucky.pojo.DO.LuckyActivityJoinRecord; |
| | | import com.ks.lucky.pojo.DTO.ActivitySimpleUser; |
| | | import com.ks.lucky.remote.service.LuckyActivityAwardResultService; |
| | | import com.ks.lucky.remote.service.LuckyActivityAwardService; |
| | | import com.ks.lucky.remote.service.LuckyActivityJoinService; |
| | | import com.ks.lucky.remote.service.LuckyActivityService; |
| | | import org.apache.dubbo.config.annotation.Reference; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.yeshi.utils.alipay.AlipayXcxUtil; |
| | | import org.yeshi.utils.exception.AlipayXcxException; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @SpringBootTest |
| | | public class MsgTest { |
| | |
| | | |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityService luckyActivityService; |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityJoinService luckyActivityJoinService; |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityAwardResultService luckyActivityAwardResultService; |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityAwardService luckyActivityAwardService; |
| | | |
| | | @Resource |
| | | private AlipayTemplateMsgManager alipayTemplateMsgManager; |
| | | |
| | | |
| | | Logger logger = LoggerFactory.getLogger(MsgTest.class); |
| | | |
| | | @Test |
| | | public void addMsg() { |
| | |
| | | } |
| | | } |
| | | |
| | | private List<ActivitySimpleUser> getValidJoinerList(Long activityId) { |
| | | List<ActivitySimpleUser> list = new ArrayList<>(); |
| | | //查询所有参与者 |
| | | long count = luckyActivityJoinService.countJoiner(activityId, LuckyActivityJoinRecord.USER_TYPE_REAL); |
| | | int pageSize = 500; |
| | | int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | for (int i = 0; i < page; i++) { |
| | | List<ActivitySimpleUser> userList = luckyActivityJoinService.getJoinerList(activityId, LuckyActivityJoinRecord.USER_TYPE_REAL, i + 1, pageSize); |
| | | list.addAll(userList); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private UserMsgSettings getUserMsgSetting(Long uid) { |
| | | return userInfoExtraService.getUserMsgSettings(uid); |
| | | } |
| | | |
| | | @Test |
| | | public void consumeMsg() { |
| | | |
| | | Long activityId = 10052L; |
| | | List<ActivitySimpleUser> userList = getValidJoinerList(activityId); |
| | | for (ActivitySimpleUser user : userList) { |
| | | //判断是否中奖 |
| | | UserMsgSettings settings = getUserMsgSetting(Long.parseLong(user.getUid())); |
| | | LuckyActivity activity = luckyActivityService.getActivity(activityId); |
| | | |
| | | LuckyActivityAwardResult result = luckyActivityAwardResultService.getResult(user.getAppId(), user.getUid(), activityId); |
| | | if (result != null) { |
| | | if (settings.getDrawnMsg() != null && settings.getDrawnMsg()) { |
| | | LuckyActivityAwards awards = luckyActivityAwardService.getAwardDetail(result.getAwardId()); |
| | | |
| | | try { |
| | | userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(result.getUid()), LuckyMsgContentFactory.createDrawn(activityId, activity.getCreateTime(), awards.getAwardName()))); |
| | | } catch (UserMsgException e) { |
| | | logger.error("添加中奖消息出错 awardResultId-{}", result.getId(), e); |
| | | } |
| | | |
| | | //发送中奖模板消息 |
| | | alipayTemplateMsgManager.sendDrawnMsg(activity, Long.parseLong(result.getUid())); |
| | | } |
| | | } else { |
| | | if (settings.getNotDrawnMsg() != null && settings.getNotDrawnMsg()) { |
| | | try { |
| | | userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(user.getUid()), LuckyMsgContentFactory.createNotDrawn(activityId, activity.getCreateTime()))); |
| | | } catch (UserMsgException e) { |
| | | logger.error("添加未中奖消息出错 activityId-{} uid-{} ",activityId, user.getUid(), e); |
| | | } |
| | | //发送未中奖模板消息 |
| | | alipayTemplateMsgManager.sendUnDrawnMsg(activity, Long.parseLong(result.getUid())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |