package com.yihu.jw.gateway.service;


import com.yihu.jw.entity.iot.gateway.GcClientDetails;
import com.yihu.jw.gateway.dao.GcClientDetailsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

import static com.sun.xml.internal.ws.util.JAXWSUtils.getUUID;

/**
 * Created by chenweida on 2017/8/17.
 */
@Service
public class GcClientDetailsService{
    @Autowired
    private GcClientDetailsDao gtClientDetailsDao;

    public GcClientDetails findByAppId(String appid) {
        return gtClientDetailsDao.findByAppid(appid);
    }

    @Transactional
    public GcClientDetails createClientDetails(String appUri,String createUserName,String creatieUser,String remark) throws Exception{
        GcClientDetails gcClientDetails = new GcClientDetails();
        gcClientDetails.setAppId(getUUID());
        gcClientDetails.setAppSecret(getUUID());
        gcClientDetails.setAppUri(appUri);
        gcClientDetails.setCreateUserName(createUserName);
        gcClientDetails.setCreatieUser(creatieUser);
        gcClientDetails.setCreatieTime(new Date());
        gcClientDetails.setDel(1);
        gcClientDetails.setRemark(remark);
        return gtClientDetailsDao.save(gcClientDetails);
    }
}
