package com.xhpc.pp.logic;

import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Lazy
@Component("BmsChargingCompletedDataLogic")
public class BmsChargingCompletedDataLogic implements ServiceLogic {

    private static final Logger log = LoggerFactory.getLogger(BmsChargingCompletedDataLogic.class);

    @Resource
    XhpcDeviceMessageMapper deviceMessageMapper;

    @Override
    public ServiceResult service(ServiceParameter sp) throws Exception {
//        log.error("====0X19======getServiceName================"+sp.getServiceName());
//        log.error("====0X19======getPileNo================"+sp.getPileNo());
//        log.error("====0X19======getParameters================"+sp.getParameters());
//        log.error("====0X19======getVersion================"+sp.getVersion());
        String remark = "充电桩与 BMS 充电结束阶段报文";
        Map<String, Object> req = sp.getParameters();

        XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
        deviceMessage.setType(StationDeviceEnum.PILE.getCode());
        deviceMessage.setSerialNumber(sp.getPileNo());
        deviceMessage.setRemark(remark);
        deviceMessage.setStatus(0);
        deviceMessage.setContent((String) req.get("hex"));
        deviceMessage.setChargeOrderNo((String) req.get("orderNo"));
        deviceMessageMapper.insertByDomain(deviceMessage);

        return new ServiceResult(false);
    }

}
