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

import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dao.AppConfigDao;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 应用配置列表
 *
 * @author nfq
 * @date 2023-02-09 11:28
 */
@Slf4j
@CmdHandler(cmdType = CmdTypeConstants.APP_CONFIG)
public class AppConfigServiceImpl implements CmdHandlerService {

    @Autowired
    private AppConfigDao appConfigDao;

    @Override
    public ResponseResult cmdHandler(Integer equipmentId, String data) {
        try {
            LoginUserDTO loginUserDTO = (LoginUserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return ResponseResult.success(appConfigDao.listAppConfigVO(loginUserDTO.getCompanyId(), null, null));
        } catch (Exception e) {
            log.error("客户端应用配置异常:" + equipmentId + data, e);
            return ResponseResult.failure();
        }
    }
}
