admin
2019-01-19 23f7b250c00597ad89282075460a4c27dffe1ada
fanli/src/main/java/com/yeshi/fanli/service/impl/msg/MsgOrderDetailServiceImpl.java
New file
@@ -0,0 +1,94 @@
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.util.Constant;
@Service
public class MsgOrderDetailServiceImpl implements MsgOrderDetailService {
   @Resource
   private MsgOrderDetailMapper msgOrderDetailMapper;
   @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);
      }
   }
   @Override
   public List<MsgOrderDetail> 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(detail.getId());
      update.setHongBaoMoney(detail.getHongBaoMoney());
      update.setPayMoney(detail.getPayMoney());
      if (detail.getState().intValue() != msg.getState()) {
         update.setState(detail.getState());
         update.setUpdateTime(new Date());
      }
      msgOrderDetailMapper.updateByPrimaryKeySelective(update);
   }
   @Override
   public List<MsgOrderDetail> listMsgOrderByOrderId(String orderId) {
      return msgOrderDetailMapper.listByOrderId(orderId);
   }
}