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()});
|
}
|
}
|