package shop.alien.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import shop.alien.entity.store.StoreAppVersion;
import shop.alien.mapper.StoreAppVersionMapper;
import shop.alien.store.service.StoreAppVersionService;

/**
 * App版本表 服务实现类
 *
 * @author ssk
 * @since 2025-01-07
 */
@Service
public class StoreAppVersionServiceImpl extends ServiceImpl<StoreAppVersionMapper, StoreAppVersion> implements StoreAppVersionService {

    /**
     * 获取最新版本号
     *
     * @param appType app类型: 1:用户端, 2:商家端
     * @return StoreAppVersion
     */
    @Override
    public StoreAppVersion getLatestVersion(Integer appType) {
        LambdaQueryWrapper<StoreAppVersion> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StoreAppVersion::getAppType, appType)
                .orderByDesc(StoreAppVersion::getVersionNum)
                .last("limit 1");
        return this.getOne(lambdaQueryWrapper);
    }
}
