| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.service.inter.msg.MsgOverViewsService; |
| | | import com.yeshi.fanli.util.factory.msg.MsgOverViewsFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Service |
| | | public class MsgAccountDetailServiceImpl implements MsgAccountDetailService { |
| | | |
| | | @Resource |
| | | private MsgAccountDetailMapper msgAccountDetailMapper; |
| | | @Resource |
| | | private MsgAccountDetailMapper msgAccountDetailMapper; |
| | | |
| | | @Resource |
| | | private UserMsgReadStateService userMsgReadStateService; |
| | | |
| | | @Resource |
| | | private MsgExtraService msgExtraService; |
| | | @Resource |
| | | private UserMsgReadStateService userMsgReadStateService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException { |
| | | if (detail == null || detail.getUser() == null || detail.getType() == null |
| | | || StringUtil.isNullOrEmpty(detail.getExtraInfo())) |
| | | throw new MsgAccountDetailException(1, "消息信息不全"); |
| | | // 持久化到数据库 |
| | | detail.setCreateTime(new Date()); |
| | | detail.setUpdateTime(new Date()); |
| | | detail.setRead(false); |
| | | msgAccountDetailMapper.insertSelective(detail); |
| | | // 消息内容 |
| | | msgExtraService.addMsgExtra(detail.getId(), detail.getExtraInfo(), MsgExtra.MSG_TYPE_ACCOUNT); |
| | | // 红点 |
| | | userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | @Resource |
| | | private MsgExtraService msgExtraService; |
| | | |
| | | @Override |
| | | public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) { |
| | | return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); |
| | | } |
| | | @Resource |
| | | private MsgOverViewsService msgOverViewsService; |
| | | |
| | | @Override |
| | | public long countMsgAccountDetail(Long uid) { |
| | | return msgAccountDetailMapper.countByUid(uid); |
| | | } |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException { |
| | | if (detail == null || detail.getUser() == null || detail.getType() == null |
| | | || StringUtil.isNullOrEmpty(detail.getExtraInfo())) |
| | | throw new MsgAccountDetailException(1, "消息信息不全"); |
| | | // 持久化到数据库 |
| | | detail.setCreateTime(new Date()); |
| | | detail.setUpdateTime(new Date()); |
| | | detail.setRead(false); |
| | | msgAccountDetailMapper.insertSelective(detail); |
| | | |
| | | @Override |
| | | public void readMsgByUid(Long uid) { |
| | | msgAccountDetailMapper.setMsgReadByUid(uid); |
| | | } |
| | | //加入消息索引 |
| | | msgOverViewsService.save(MsgOverViewsFactory.create(detail)); |
| | | // 消息内容 |
| | | msgExtraService.addMsgExtra(detail.getId(), detail.getExtraInfo(), MsgExtra.MSG_TYPE_ACCOUNT); |
| | | // 红点 |
| | | userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void addMsgVIP(Long uid, String title, String beiZhu, MsgAccountVipDTO dto) { |
| | | MsgAccountDetail detail = new MsgAccountDetail(); |
| | | detail.setTitle(title); |
| | | detail.setBeiZhu(beiZhu); |
| | | detail.setCreateTime(new Date()); |
| | | detail.setUpdateTime(new Date()); |
| | | detail.setRead(false); |
| | | detail.setUser(new UserInfo(uid)); |
| | | detail.setContent(new Gson().toJson(dto)); |
| | | detail.setType(MsgTypeAccountTypeEnum.vipPgrade); |
| | | msgAccountDetailMapper.insertSelective(detail); |
| | | |
| | | userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MsgAccountDetail selectByPrimaryKey(Long id) { |
| | | return msgAccountDetailMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByPrimaryKey(Long id) { |
| | | msgAccountDetailMapper.deleteByPrimaryKey(id); |
| | | msgExtraService.deleteByPidAndType(id, MsgExtra.MSG_TYPE_ACCOUNT); |
| | | } |
| | | |
| | | @Override |
| | | public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) { |
| | | return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | public List<MsgAccountDetail> listDetail(List<Long> ids) { |
| | | return msgAccountDetailMapper.listByPrimaryKeys(ids); |
| | | } |
| | | |
| | | @Override |
| | | public long countMsgAccountDetail(Long uid) { |
| | | return msgAccountDetailMapper.countByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public void readMsgByUid(Long uid) { |
| | | msgAccountDetailMapper.setMsgReadByUid(uid); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void addMsgVIP(Long uid, String title, String beiZhu, MsgAccountVipDTO dto) { |
| | | MsgAccountDetail detail = new MsgAccountDetail(); |
| | | detail.setTitle(title); |
| | | detail.setBeiZhu(beiZhu); |
| | | detail.setCreateTime(new Date()); |
| | | detail.setUpdateTime(new Date()); |
| | | detail.setRead(false); |
| | | detail.setUser(new UserInfo(uid)); |
| | | detail.setContent(new Gson().toJson(dto)); |
| | | detail.setType(MsgTypeAccountTypeEnum.vipPgrade); |
| | | msgAccountDetailMapper.insertSelective(detail); |
| | | |
| | | userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MsgAccountDetail selectByPrimaryKey(Long id) { |
| | | return msgAccountDetailMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByPrimaryKey(Long id) { |
| | | msgAccountDetailMapper.deleteByPrimaryKey(id); |
| | | msgExtraService.deleteByPidAndType(id, MsgExtra.MSG_TYPE_ACCOUNT); |
| | | } |
| | | |
| | | } |