package com.java110.user.dao.impl;

import com.java110.core.base.dao.BaseServiceDao;
import com.java110.user.dao.property.IAppVersionV1ServiceDao;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("appVersionV1ServiceDaoImpl")
public class AppVersionV1ServiceDaoImpl extends BaseServiceDao implements IAppVersionV1ServiceDao {

    @Override
    public Map queryLatestVersion(Map params) {
        List<Map> list = sqlSessionTemplate.selectList("appVersionV1ServiceDaoImpl.queryLatestVersion", params);
        return (list != null && !list.isEmpty()) ? list.get(0) : null;
    }

    @Override
    public List<Map> queryAppVersions(Map params) {
        return sqlSessionTemplate.selectList("appVersionV1ServiceDaoImpl.queryAppVersions", params);
    }

    @Override
    public int queryAppVersionsCount(Map params) {
        List<Map> list = sqlSessionTemplate.selectList("appVersionV1ServiceDaoImpl.queryAppVersionsCount", params);
        if (list != null && !list.isEmpty()) {
            Object count = list.get(0).get("count");
            return count instanceof Number ? ((Number) count).intValue() : Integer.parseInt(count.toString());
        }
        return 0;
    }

    @Override
    public int saveAppVersion(Map params) {
        return sqlSessionTemplate.insert("appVersionV1ServiceDaoImpl.saveAppVersion", params);
    }

    @Override
    public int updateAppVersion(Map params) {
        return sqlSessionTemplate.update("appVersionV1ServiceDaoImpl.updateAppVersion", params);
    }

    @Override
    public int deleteAppVersion(Map params) {
        return sqlSessionTemplate.update("appVersionV1ServiceDaoImpl.deleteAppVersion", params);
    }
}
