package com.bonus.canteen.core.customer.service.impl;

import com.bonus.canteen.core.common.constant.LeMqConstant;
import com.bonus.canteen.core.customer.api.CustCasualApi;
import com.bonus.canteen.core.customer.model.CustAccTemp;
import com.bonus.canteen.core.customer.mq.DelayedMessageSender;
import com.bonus.canteen.core.customer.mq.DelayedMessageTypeEnum;
import com.bonus.canteen.core.device.manage.controller.deprecated.vo.CustInfoAzVo;
import com.bonus.canteen.core.device.mq.MacMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Service
public class CustMqServiceImpl {
   private static final Logger log = LoggerFactory.getLogger(CustMqServiceImpl.class);
   @Autowired
   private CustCasualApi custCasualApi;
   @Lazy
   @Autowired
   private DelayedMessageSender delayedMessageSender;

   public void sendMsg(CustAccTemp custAccTemp) {
      CustInfoAzVo custInfoAzVo = (new CustInfoAzVo()).setCustId(custAccTemp.getCustId()).setCustName(custAccTemp.getCustName()).setCustNum(custAccTemp.getCustNum()).setCustState(custAccTemp.getCustState()).setCustPhotoUrl(custAccTemp.getCustPhotoUrl()).setAccStatus(custAccTemp.getAccStatus()).setDepartment(custAccTemp.getOrgFullName()).setCardStatus(custAccTemp.getCardStatus()).setCardType(custAccTemp.getCardType()).setSerialNum(custAccTemp.getSerialNum()).setAliopenid(this.custCasualApi.getOpenidByCustId(custAccTemp.getCustId(), 5)).setAlipayContractNum(custAccTemp.getAlipayContractNum());
      MacMessage.sendToTenant(custInfoAzVo, LeMqConstant.Topic.DEVICE_UPDATE_PERSON);
      this.delayedMessageSender.asyncDelaySendToDevice(DelayedMessageTypeEnum.PERSON);
   }
}
