package cn.com.countrygarden.bi.main.service.impl;

import cn.com.countrygarden.bi.main.core.AbstractService;
import cn.com.countrygarden.bi.main.dao.VersionMapper;
import cn.com.countrygarden.bi.main.model.Version;
import cn.com.countrygarden.bi.main.service.VersionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class VersionServiceImpl extends AbstractService<Version> implements VersionService {
    @Resource
    private VersionMapper versionMapper;

    public Version getLatestVersion(String platform) {
        return versionMapper.getLatestVersion(platform);
    }

    public Map<String, Object> getLatestVersion(Map<String, String> param) {
        Map<String, Object> result = new HashMap<>();
        String platform = param.getOrDefault("platform", "biappandroid");
        Version version = versionMapper.getLatestVersion(platform);
        result.put("id", version.getId());
        result.put("platform", version.getPlatform());
        result.put("version", version.getVersion());
        result.put("versionName", version.getVersionName());
        result.put("versionMemo", version.getVersionMemo());
        result.put("android", version.getAndroid());
        result.put("ios", version.getIos());
        return result;
    }
}
