package com.bonus.canteen.core.android.service.impl;

import com.bonus.canteen.core.android.dto.AppDTO;
import com.bonus.canteen.core.android.mapper.DeviceMapper;
import com.bonus.canteen.core.android.service.DeviceService;
import com.bonus.canteen.core.android.vo.AppVersionVo;
import com.bonus.canteen.core.android.vo.DeviceInfoVo;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.constant.GlobalConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceMapper mapper;


    @Value("${face.android.appId}")
    private String appId;
    @Value("${face.android.sdkKey}")
    private String appKey;

    @Override
    public AjaxResult getDeviceInfo(AppDTO dto) {
        //判断设备是否存在
        DeviceInfoVo deviceInfoVo = mapper.getDeviceInfo(dto);
        if (deviceInfoVo == null) {
            return AjaxResult.error("设备不存在");
        }
        deviceInfoVo.setAppId(appId);
        deviceInfoVo.setAppKey(appKey);
        deviceInfoVo.setTenantId(String.valueOf(GlobalConstants.TENANT_ID));
        return AjaxResult.success(deviceInfoVo);
    }

    @Override
    public AjaxResult getAppVersion(AppDTO dto) {
        AppVersionVo appVersionVo = mapper.getAppVersion(dto);
        if (appVersionVo == null){
            return AjaxResult.success("无需更新");
        }
        return AjaxResult.success(appVersionVo);
    }
}
