package com.skr.mdm.service.impl.user;

import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.bean.vo.EquipmentInfoVO;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dao.DeviceEquipmentDao;
import com.skr.mdm.entity.DeviceEquipmentDO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author nfq
 * @date 2020/9/23 14:38
 */
@Slf4j
@CmdHandler(cmdType = CmdTypeConstants.USER_INFO)
public class UserInfoServiceImpl implements CmdHandlerService {

    @Autowired
    private DeviceEquipmentDao equipmentDao;

    @Override
    public ResponseResult cmdHandler(Integer equipmentId, String data) {
        try {
            DeviceEquipmentDO equipmentDO = equipmentDao.selectById(equipmentId);
            EquipmentInfoVO equipmentInfoVO = new EquipmentInfoVO();
            BeanUtils.copyProperties(equipmentDO, equipmentInfoVO);
            return ResponseResult.success(equipmentInfoVO);
        } catch (Exception e) {
            log.error("获取用户信息异常:" + equipmentId + data, e);
            return ResponseResult.failure();
        }
    }
}
