admin
2019-07-11 3824cbcaec6e6c67418d5280a53e9c2fedeef6f9
fanli/src/main/java/com/yeshi/fanli/service/impl/msg/MsgOrderDetailServiceImpl.java
@@ -9,8 +9,11 @@
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 {
@@ -18,12 +21,15 @@
   @Resource
   private MsgOrderDetailMapper msgOrderDetailMapper;
   @Resource
   private UserMsgReadStateService userMsgReadStateService;
   @Override
   public void addMsgOrderDetail(MsgOrderDetail detail) throws MsgOrderDetailException {
   public void addMsgOrderDetail(MsgOrderDetail detail, boolean needNotify) 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)
      if (detail.getOrderId() == null || detail.getType() == null || detail.getState() == null
            || detail.getUser() == null)
         throw new MsgOrderDetailException(2, "消息不完整");
      MsgOrderDetail old = msgOrderDetailMapper.selectByUidAndOrderId(detail.getUser().getId(), detail.getOrderId());
      if (old == null) {
@@ -42,17 +48,55 @@
         update.setBeiZhu(detail.getBeiZhu());
         msgOrderDetailMapper.updateByPrimaryKeySelective(update);
      }
      if (needNotify)
         userMsgReadStateService.addOrderMsgUnReadCount(detail.getUser().getId(), 1);
   }
   @Override
   public List<MsgOrderDetail> listMsgOrderDetail(Long uid, int page) {
      return null;
      return msgOrderDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
   }
   @Override
   public long countMsgOrderDetail(Long uid) {
      return 0;
      return msgOrderDetailMapper.countByUid(uid);
   }
   @Override
   public void readMsgByUid(Long uid) {
      msgOrderDetailMapper.setMsgReadByUid(uid);
   }
   @Override
   public void updateMsgOrderDetail(MsgOrderDetail detail, boolean needNotify) 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());
         if (needNotify)
            userMsgReadStateService.addOrderMsgUnReadCount(detail.getUser().getId(), 1);
      }
      msgOrderDetailMapper.updateByPrimaryKeySelective(update);
   }
   @Override
   public List<MsgOrderDetail> listMsgOrderByOrderId(String orderId) {
      return msgOrderDetailMapper.listByOrderId(orderId);
   }
}