package com.gkhy.safePlatform.account.service.baseService.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.safePlatform.account.entity.app.AppVersionInfo; import com.gkhy.safePlatform.account.enums.AppVersionStatusEnum; import com.gkhy.safePlatform.account.model.query.db.AppVersionPageDBQuery; import com.gkhy.safePlatform.account.repository.AppVersionInfoRepository; import com.gkhy.safePlatform.account.service.baseService.AppVersionInfoService; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("appInfoService") public class AppVersionInfoServiceImpl extends ServiceImpl implements AppVersionInfoService { @Autowired private AppVersionInfoRepository appInfoRepository; @Override public long countByAppType(Byte appType) { if (appType == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return appInfoRepository.selectCount(new LambdaQueryWrapper() .eq(AppVersionInfo::getAppType,appType)); } @Override public void saveAppInfo(AppVersionInfo appEntity) { if (appEntity == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = appInfoRepository.insertAppInfo(appEntity); if (i != 1) { throw new BusinessException(ResultCodes.SERVER_ADD_ERROR); } } @Override public void updateAppInfo(AppVersionInfo appEntity) { if (appEntity == null || appEntity.getId() == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = appInfoRepository.updateAppInfo(appEntity); if (i == 0) { throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE); } if (i > 1) { throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR); } } @Override public List listAppVersionInfoByPage(Page page, AppVersionPageDBQuery dbQuery) { if (page == null || dbQuery == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return appInfoRepository.listAppVersionInfoByPage(page,dbQuery); } @Override public AppVersionInfo getAppVersionInfoByCustomVersion(String customVersion, Byte appType) { if (StringUtils.isBlank(customVersion) || appType == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List appVersionInfos = appInfoRepository.selectList(new LambdaQueryWrapper() // app 类型 .eq(AppVersionInfo::getAppType, appType) // 自定义版本 .eq(AppVersionInfo::getCustomVersion, customVersion) // 状态 .eq(AppVersionInfo::getStatus, AppVersionStatusEnum.ENABLED.code)); if (appVersionInfos.size() == 0) { return null; } if (appVersionInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return appVersionInfos.get(0); } @Override public AppVersionInfo getLastestAppRelease(Byte appType) { if (appType == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return appInfoRepository.getLastestAppRelease(appType); } }