package com.yeshi.fanli.service.impl.msg; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.yeshi.fanli.dao.mybatis.msg.MsgOrderDetailMapper; import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail; import com.yeshi.fanli.entity.order.CommonOrder; import com.yeshi.fanli.exception.msg.MsgOrderDetailException; import com.yeshi.fanli.service.inter.msg.MsgOrderDetailService; import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService; import com.yeshi.fanli.util.Constant; @Service public class MsgOrderDetailServiceImpl implements MsgOrderDetailService { @Resource private MsgOrderDetailMapper msgOrderDetailMapper; @Resource private UserMsgReadStateService userMsgReadStateService; @Override public void addMsgOrderDetail(MsgOrderDetail detail) throws MsgOrderDetailException { if (detail == null) throw new MsgOrderDetailException(1, "消息为空"); if (detail.getOrderId() == null || detail.getGoodsCount() == null || detail.getType() == null || detail.getState() == null || detail.getPayMoney() == null || detail.getUser() == null) throw new MsgOrderDetailException(2, "消息不完整"); MsgOrderDetail old = msgOrderDetailMapper.selectByUidAndOrderId(detail.getUser().getId(), detail.getOrderId()); if (old == null) { detail.setCreateTime(new Date()); detail.setUpdateTime(new Date()); detail.setRead(false); msgOrderDetailMapper.insertSelective(detail); } else { MsgOrderDetail update = new MsgOrderDetail(); update.setId(old.getId()); update.setUpdateTime(new Date()); update.setState(detail.getState()); update.setPayMoney(detail.getPayMoney()); update.setHongBaoMoney(detail.getHongBaoMoney()); update.setRead(false); update.setBeiZhu(detail.getBeiZhu()); msgOrderDetailMapper.updateByPrimaryKeySelective(update); } userMsgReadStateService.addOrderMsgUnReadCount(detail.getUser().getId(), 1); } @Override public List listMsgOrderDetail(Long uid, int page) { return msgOrderDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); } @Override public long countMsgOrderDetail(Long uid) { return msgOrderDetailMapper.countByUid(uid); } @Override public void readMsgByUid(Long uid) { msgOrderDetailMapper.setMsgReadByUid(uid); } @Override public void updateMsgOrderDetail(MsgOrderDetail detail) throws MsgOrderDetailException { if (detail == null) throw new MsgOrderDetailException(1, "消息为空"); if (detail.getOrderId() == null || detail.getState() == null || detail.getUser() == null) throw new MsgOrderDetailException(2, "消息不完整"); MsgOrderDetail msg = msgOrderDetailMapper.selectByUidAndOrderId(detail.getUser().getId(), detail.getOrderId()); if (msg == null) return; if (msg.getState() == CommonOrder.STATE_WQ) return; MsgOrderDetail update = new MsgOrderDetail(); update.setId(msg.getId()); update.setHongBaoMoney(detail.getHongBaoMoney()); update.setPayMoney(detail.getPayMoney()); if (detail.getState().intValue() != msg.getState()) { update.setState(detail.getState()); update.setUpdateTime(new Date()); userMsgReadStateService.addOrderMsgUnReadCount(detail.getUser().getId(), 1); } msgOrderDetailMapper.updateByPrimaryKeySelective(update); } @Override public List listMsgOrderByOrderId(String orderId) { return msgOrderDetailMapper.listByOrderId(orderId); } }