郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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<AppVersionInfoRepository, AppVersionInfo> 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<AppVersionInfo>()
 
                .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<AppVersionInfo> listAppVersionInfoByPage(Page<AppVersionInfo> 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<AppVersionInfo> appVersionInfos = appInfoRepository.selectList(new LambdaQueryWrapper<AppVersionInfo>()
                // 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);
    }
}