许鹏程
2023-05-25 213cc37cbf0b2515a4de56cc1e01813211bad183
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.product.admin.service;
 
import com.product.admin.config.SystemCode;
import com.product.common.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.product.admin.config.CmnConst;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.util.BaseUtil;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * Copyright © 2020 LX-BASE
 *
 * @Title: LX-BASE-SERVER
 * @Project: lx-server-admin
 * @Date: 2020年11月17日
 * @Author: Mr.Xu
 * @Description:系统版本Service
 */
@Component
public class SystemVersionService extends AbstractBaseService {
 
    @Autowired
    private BaseDao dao;
 
    /**
     * 系统版本列表
     *
     * @return
     * @throws BaseException
     */
    public DataTableEntity listVersion(FieldSetEntity fse) throws BaseException {
 
        return dao.listTable(CmnConst.PRODUCT_SYS_VERSION, null, null, null, null,
                fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
    }
 
    /**
     * 新增版本
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public String addVersion(FieldSetEntity fse) throws BaseException {
        versionClientTypeUnique(fse);
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        fse.setValue("update_last_version", 1);//用于国际化信息修改后的最后小版本 默认值=1
        return dao.add(fse);
    }
 
    /**
     * 版本保存数据验证客户端类型是否重复
     *
     * @param fse
     * @throws BaseException
     */
    public void versionClientTypeUnique(FieldSetEntity fse) throws BaseException {
        if (fse == null || StringUtils.isEmpty(fse.getString("version_type"))) {
            return;
        }
        //根据版本code 版本类型 产品 判断是否重复
        //版本类型多选 用模糊查询两端拼接 "," 查询该类型是否被使用
        //如 fse 中字段 "uuid" 存在 则排除自己
        List<Object> params = new ArrayList<>();
        //版本code
        String version_code = fse.getString("version_code");
        //版本类型
        String[] version_type = fse.getString("version_type").split(",");
        //产品
        String system_platform = fse.getString("system_platform");
        String sql = " SELECT *  FROM product_sys_version where version_code=?  and system_platform=? ";
        params.add(version_code);
        params.add(system_platform);
        String versionTypeFilter = "  and ( ";
        for (int i = 0; i < version_type.length; i++) {
            if (0 != i) {
                versionTypeFilter += " OR ";
            }
            versionTypeFilter += " concat(',',version_type,',')  like concat(',%',?,'%,')";
            params.add(version_type[i]);
        }
        versionTypeFilter += " ) ";
        sql += versionTypeFilter;
        if (!StringUtils.isEmpty(fse.getString("uuid"))) {
            sql += " and uuid !=?";
            params.add(fse.getString("uuid"));
        }
        FieldSetEntity fs = dao.getFieldSetEntityBySQL(sql, params.toArray(), false);
        if (fs != null && !StringUtils.isEmpty(fs.getString("version_code"))) {
            //查询出数据抛出重复异常
            throw new BaseException(SystemCode.SYSTEM_VERSION_CLINET_TYPE_UNIQUE_FIAL.getValue(), SystemCode.SYSTEM_VERSION_CLINET_TYPE_UNIQUE_FIAL.getText());
        }
 
    }
 
    /**
     * 版本详情
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findVersion(String uuid) throws BaseException {
        return dao.getFieldSetEntity(CmnConst.PRODUCT_SYS_VERSION, uuid, false);
    }
 
    /**
     * 修改版本
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean updateVersion(FieldSetEntity fse) throws BaseException {
        versionClientTypeUnique(fse);
        BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(), fse);
        return dao.update(fse);
    }
 
    /**
     * 系统版本
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean deleteVersion(FieldSetEntity fse) throws BaseException {
        return dao.delete(CmnConst.PRODUCT_SYS_VERSION, new String[]{fse.getUUID()});
    }
}