xiaoyong931011
2021-07-07 6c5a9e94f11c5ce05336303129a21886383967a6
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.utils.BusinessUtil;
import com.xzx.gc.entity.VersionInfo;
import com.xzx.gc.user.mapper.VersionInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletRequest;
 
@Service
@Transactional
@Slf4j
public class VersionService {
 
    @Autowired
    private VersionInfoMapper versionInfoMapper;
 
    @Autowired
    private HttpServletRequest request;
    
    @Autowired
    private BusinessUtil businessUtil;
 
    public VersionInfo find(){
        String version = request.getHeader("anroidVersion");
        if(StrUtil.isNotBlank(version)){
            Double currentVersion = businessUtil.getVersion(version);
            VersionInfo versionInfo=new VersionInfo();
            versionInfo.setDelFlag(Convert.toShort(Constants.DEL_NOT_FLAG));
            VersionInfo versionInfo1 = versionInfoMapper.selectOne(versionInfo);
            Double newVersion = versionInfo1.getNewVersion();
            Double minVersion = versionInfo1.getMinVersion();
 
            if(NumberUtil.compare(currentVersion,newVersion)<0){
                versionInfo1.setUpdateFlag(Convert.toShort(Constants.RESULT_SUCCESS));
            }
            if(NumberUtil.compare(currentVersion,minVersion)<0) {
                versionInfo1.setForceUpdateFlag(Convert.toShort(Constants.RESULT_SUCCESS));
            }
            return  versionInfo1;
        }else {
            return null;
        }
    }
}