package com.zksy.pole.factory.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zksy.pole.domain.po.DgGatewayRegistration;
import com.zksy.pole.factory.IHandleCmd;
import com.zksy.pole.mapper.DgGatewayRegistrationMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HandleDgGatewayRegistrationCmd implements IHandleCmd {
    private static final Logger log = LoggerFactory.getLogger(HandleDgGatewayRegistrationCmd.class);
    @Autowired
    private DgGatewayRegistrationMapper dgGatewayRegistrationMapper;
    @Override
    public <T> String HandleCmdMethod(T data) {

        try {
            DgGatewayRegistration d = (DgGatewayRegistration) data;
            d.setId(UUID.fastUUID().toString(true));
            dgGatewayRegistrationMapper.insert(d);
            JSONObject obj = JSONUtil.createObj();
            obj.set("cmd",1111);
            obj.set("flag",1);
            return obj.toString();
        } catch (Exception e) {
            log.error("DgGatewayRegistration数据插入失败");
            JSONObject obj = JSONUtil.createObj();
            obj.set("cmd",1111);
            obj.set("flag",0);
            return obj.toString();
        }
    }
}