package com.skr.mdm.api.equipment.service.impl;

import com.skr.mdm.api.equipment.annotation.UserStrategy;
import com.skr.mdm.api.equipment.service.UserStrategyService;
import com.skr.mdm.dao.DeviceEquipmentDao;
import com.skr.mdm.enums.SendCmdConfigEnum;
import com.skr.mdm.enums.UserStrategyEnum;
import com.skr.mdm.handle.IssuedUserHandler;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.entity.DeviceEquipmentDO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;

/**
 * @author nfq
 * @date 2023-02-02 16:23
 */
@UserStrategy(strategyType = UserStrategyEnum.EQUIPMENT_INFO)
public class EquipmentInfoUserStrategyServiceImpl implements UserStrategyService {

    @Autowired
    private DeviceEquipmentDao equipmentDao;
    @Autowired
    private IssuedUserHandler issuedUserHandler;

    @Override
    public ResponseResult getUserStrategy(Integer equipmentId) {
        // 下发设备信息更新指令
        DeviceEquipmentDO equipmentDO = equipmentDao.selectById(equipmentId);
        issuedUserHandler.issuedUser(Collections.singletonList(equipmentId), equipmentDO.getCompanyId(),
                SendCmdConfigEnum.UPLOAD_EQUIPMENT.getCmd(), null);
        return ResponseResult.success(equipmentDao.getEquipmentInfo(equipmentId));
    }
}
