| | |
| | | package com.yeshi.fanli.service.impl.user.invite;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.msg.MsgInviteDetailMapper;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgInviteDetail;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.exception.msg.MsgInviteDetailException;
|
| | | import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
|
| | | @Service
|
| | | public class MsgInviteDetailServiceImpl implements MsgInviteDetailService {
|
| | |
|
| | | @Resource
|
| | | private MsgInviteDetailMapper msgInviteDetailMapper;
|
| | |
|
| | | @Resource
|
| | | private UserMsgReadStateService userMsgReadStateService;
|
| | |
|
| | | @Override
|
| | | public void addMsgInviteDetail(MsgInviteDetail detail) throws MsgInviteDetailException {
|
| | | if (detail == null)
|
| | | throw new MsgInviteDetailException(1, "消息为空");
|
| | |
|
| | | if (detail.getInviteUser() == null || detail.getMsgType() == null || detail.getUser() == null
|
| | | || detail.getDesc() == null)
|
| | | throw new MsgInviteDetailException(2, "消息内容不完整");
|
| | |
|
| | | // 查询是否已存在该邀请ID
|
| | | MsgInviteDetail oldDetail = msgInviteDetailMapper.selectByThreeSaleId(detail.getInviteUser().getId());
|
| | | if (oldDetail == null) {
|
| | | detail.setCreateTime(new Date());
|
| | | detail.setUpdateTime(new Date());
|
| | | detail.setRead(false);
|
| | | msgInviteDetailMapper.insertSelective(detail);
|
| | | } else {
|
| | | MsgInviteDetail update = new MsgInviteDetail();
|
| | | update.setId(oldDetail.getId());
|
| | | if (!detail.getInviteUser().getState()) {
|
| | | if (detail.getInviteUser().getExpire() == ThreeSale.EXPIRE_NORMAL) {
|
| | | update.setDesc("恭喜你,有新粉丝加入你的队列,若对方60天内未激活将会与你脱离邀请关系");
|
| | | } else {
|
| | | update.setDesc("抱歉,该粉丝因60天内未激活,已脱离了你的队列,可以试着重新邀请");
|
| | | }
|
| | | } else {
|
| | | update.setDesc("恭喜你,成功邀请一个粉丝");
|
| | | }
|
| | | update.setUpdateTime(new Date());
|
| | | update.setRead(false);
|
| | | msgInviteDetailMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | userMsgReadStateService.addInviteMsgUnReadCount(detail.getUser().getId(), 1);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<MsgInviteDetail> listMsgInviteDetail(Long uid, int page) {
|
| | | return msgInviteDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countMsgInviteDetail(Long uid) {
|
| | | return msgInviteDetailMapper.countByUid(uid);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void readMsgByUid(Long uid) {
|
| | | msgInviteDetailMapper.setMsgReadByUid(uid);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteByThreeSale(ThreeSale sale) {
|
| | | if (sale == null)
|
| | | return;
|
| | | msgInviteDetailMapper.deleteByThreeSaleId(sale.getId());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void insertSelective(MsgInviteDetail detail) {
|
| | | msgInviteDetailMapper.insertSelective(detail);
|
| | | userMsgReadStateService.addInviteMsgUnReadCount(detail.getUser().getId(), 1);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user.invite; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.msg.MsgInviteDetailMapper; |
| | | import com.yeshi.fanli.entity.bus.msg.MsgExtra; |
| | | import com.yeshi.fanli.entity.bus.msg.MsgInviteDetail; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.exception.msg.MsgInviteDetailException; |
| | | import com.yeshi.fanli.service.inter.msg.MsgExtraService; |
| | | import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService; |
| | | import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Service |
| | | public class MsgInviteDetailServiceImpl implements MsgInviteDetailService { |
| | | |
| | | @Resource |
| | | private MsgInviteDetailMapper msgInviteDetailMapper; |
| | | |
| | | @Resource |
| | | private UserMsgReadStateService userMsgReadStateService; |
| | | |
| | | @Resource |
| | | private MsgExtraService msgExtraService; |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addMsgInviteDetail(MsgInviteDetail detail) throws MsgInviteDetailException { |
| | | if (detail == null) |
| | | throw new MsgInviteDetailException(1, "消息为空"); |
| | | |
| | | if (detail.getMsgType() == null || detail.getUser() == null || StringUtil.isNullOrEmpty(detail.getExtraInfo())) |
| | | throw new MsgInviteDetailException(2, "消息内容不完整"); |
| | | |
| | | detail.setCreateTime(new Date()); |
| | | detail.setUpdateTime(new Date()); |
| | | detail.setRead(false); |
| | | msgInviteDetailMapper.insertSelective(detail); |
| | | msgExtraService.addMsgExtra(detail.getId(), detail.getExtraInfo(), MsgExtra.MSG_TYPE_INVITE); |
| | | userMsgReadStateService.addInviteMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | |
| | | @Override |
| | | public List<MsgInviteDetail> listMsgInviteDetail(Long uid, int page) { |
| | | return msgInviteDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | public List<MsgInviteDetail> listDetail(List<Long> ids) { |
| | | return msgInviteDetailMapper.listByPrimaryKeys(ids); |
| | | } |
| | | |
| | | @Override |
| | | public long countMsgInviteDetail(Long uid) { |
| | | return msgInviteDetailMapper.countByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public void readMsgByUid(Long uid) { |
| | | msgInviteDetailMapper.setMsgReadByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByThreeSale(ThreeSale sale) { |
| | | if (sale == null) |
| | | return; |
| | | msgInviteDetailMapper.deleteByThreeSaleId(sale.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public void insertSelective(MsgInviteDetail detail) { |
| | | msgInviteDetailMapper.insertSelective(detail); |
| | | userMsgReadStateService.addInviteMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | |
| | | @Override |
| | | public MsgInviteDetail selectByPrimaryKey(Long id) { |
| | | return msgInviteDetailMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByPrimaryKey(Long id) { |
| | | msgInviteDetailMapper.deleteByPrimaryKey(id); |
| | | msgExtraService.deleteByPidAndType(id, MsgExtra.MSG_TYPE_INVITE); |
| | | } |
| | | |
| | | } |