diff --git a/backend/src/main/java/io/dataease/base/domain/License.java b/backend/src/main/java/io/dataease/base/domain/License.java new file mode 100644 index 0000000000..00c4c1dab4 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/License.java @@ -0,0 +1,125 @@ +package io.dataease.base.domain; + +import java.io.Serializable; +import java.util.Date; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +public class License implements Serializable { + @ApiModelProperty("") + private String id; + + @ApiModelProperty("更新时间") + private Date updateTime; + + @ApiModelProperty("license") + private String license; + + @ApiModelProperty("F2C License") + private String f2cLicense; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table license + * + * @mbg.generated + */ + private static final long serialVersionUID = 1L; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column license.id + * + * @return the value of license.id + * + * @mbg.generated + */ + public String getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column license.id + * + * @param id the value for license.id + * + * @mbg.generated + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column license.update_time + * + * @return the value of license.update_time + * + * @mbg.generated + */ + public Date getUpdateTime() { + return updateTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column license.update_time + * + * @param updateTime the value for license.update_time + * + * @mbg.generated + */ + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column license.license + * + * @return the value of license.license + * + * @mbg.generated + */ + public String getLicense() { + return license; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column license.license + * + * @param license the value for license.license + * + * @mbg.generated + */ + public void setLicense(String license) { + this.license = license == null ? null : license.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column license.f2c_license + * + * @return the value of license.f2c_license + * + * @mbg.generated + */ + public String getF2cLicense() { + return f2cLicense; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column license.f2c_license + * + * @param f2cLicense the value for license.f2c_license + * + * @mbg.generated + */ + public void setF2cLicense(String f2cLicense) { + this.f2cLicense = f2cLicense == null ? null : f2cLicense.trim(); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/domain/LicenseExample.java b/backend/src/main/java/io/dataease/base/domain/LicenseExample.java new file mode 100644 index 0000000000..5dd276f76f --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/LicenseExample.java @@ -0,0 +1,578 @@ +package io.dataease.base.domain; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class LicenseExample { + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table license + * + * @mbg.generated + */ + protected String orderByClause; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table license + * + * @mbg.generated + */ + protected boolean distinct; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table license + * + * @mbg.generated + */ + protected List oredCriteria; + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public LicenseExample() { + oredCriteria = new ArrayList(); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public String getOrderByClause() { + return orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public boolean isDistinct() { + return distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public List getOredCriteria() { + return oredCriteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table license + * + * @mbg.generated + */ + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(String value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(String value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(String value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(String value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(String value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(String value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLike(String value) { + addCriterion("id like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotLike(String value) { + addCriterion("id not like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(String value1, String value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(String value1, String value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Date value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Date value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Date value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Date value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Date value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Date value1, Date value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Date value1, Date value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andLicenseIsNull() { + addCriterion("license is null"); + return (Criteria) this; + } + + public Criteria andLicenseIsNotNull() { + addCriterion("license is not null"); + return (Criteria) this; + } + + public Criteria andLicenseEqualTo(String value) { + addCriterion("license =", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseNotEqualTo(String value) { + addCriterion("license <>", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseGreaterThan(String value) { + addCriterion("license >", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseGreaterThanOrEqualTo(String value) { + addCriterion("license >=", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseLessThan(String value) { + addCriterion("license <", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseLessThanOrEqualTo(String value) { + addCriterion("license <=", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseLike(String value) { + addCriterion("license like", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseNotLike(String value) { + addCriterion("license not like", value, "license"); + return (Criteria) this; + } + + public Criteria andLicenseIn(List values) { + addCriterion("license in", values, "license"); + return (Criteria) this; + } + + public Criteria andLicenseNotIn(List values) { + addCriterion("license not in", values, "license"); + return (Criteria) this; + } + + public Criteria andLicenseBetween(String value1, String value2) { + addCriterion("license between", value1, value2, "license"); + return (Criteria) this; + } + + public Criteria andLicenseNotBetween(String value1, String value2) { + addCriterion("license not between", value1, value2, "license"); + return (Criteria) this; + } + + public Criteria andF2cLicenseIsNull() { + addCriterion("f2c_license is null"); + return (Criteria) this; + } + + public Criteria andF2cLicenseIsNotNull() { + addCriterion("f2c_license is not null"); + return (Criteria) this; + } + + public Criteria andF2cLicenseEqualTo(String value) { + addCriterion("f2c_license =", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseNotEqualTo(String value) { + addCriterion("f2c_license <>", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseGreaterThan(String value) { + addCriterion("f2c_license >", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseGreaterThanOrEqualTo(String value) { + addCriterion("f2c_license >=", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseLessThan(String value) { + addCriterion("f2c_license <", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseLessThanOrEqualTo(String value) { + addCriterion("f2c_license <=", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseLike(String value) { + addCriterion("f2c_license like", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseNotLike(String value) { + addCriterion("f2c_license not like", value, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseIn(List values) { + addCriterion("f2c_license in", values, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseNotIn(List values) { + addCriterion("f2c_license not in", values, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseBetween(String value1, String value2) { + addCriterion("f2c_license between", value1, value2, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andF2cLicenseNotBetween(String value1, String value2) { + addCriterion("f2c_license not between", value1, value2, "f2cLicense"); + return (Criteria) this; + } + + public Criteria andSqlCriterion(String value) { + addCriterion("(" + value + ")"); + return (Criteria) this; + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table license + * + * @mbg.generated do_not_delete_during_merge + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table license + * + * @mbg.generated + */ + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} diff --git a/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.java b/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.java new file mode 100644 index 0000000000..4fcada9294 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.java @@ -0,0 +1,96 @@ +package io.dataease.base.mapper; + +import io.dataease.base.domain.License; +import io.dataease.base.domain.LicenseExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface LicenseMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + long countByExample(LicenseExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int deleteByExample(LicenseExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int deleteByPrimaryKey(String id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int insert(License record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int insertSelective(License record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + List selectByExample(LicenseExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + License selectByPrimaryKey(String id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int updateByExampleSelective(@Param("record") License record, @Param("example") LicenseExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int updateByExample(@Param("record") License record, @Param("example") LicenseExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int updateByPrimaryKeySelective(License record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table license + * + * @mbg.generated + */ + int updateByPrimaryKey(License record); +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.xml b/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.xml new file mode 100644 index 0000000000..0ce7f6ee51 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/LicenseMapper.xml @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + id, update_time, license, f2c_license + + + + + + delete from license + where id = #{id,jdbcType=VARCHAR} + + + + delete from license + + + + + + + insert into license (id, update_time, license, + f2c_license) + values (#{id,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{license,jdbcType=VARCHAR}, + #{f2cLicense,jdbcType=VARCHAR}) + + + + insert into license + + + id, + + + update_time, + + + license, + + + f2c_license, + + + + + #{id,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{license,jdbcType=VARCHAR}, + + + #{f2cLicense,jdbcType=VARCHAR}, + + + + + + + update license + + + id = #{record.id,jdbcType=VARCHAR}, + + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + + license = #{record.license,jdbcType=VARCHAR}, + + + f2c_license = #{record.f2cLicense,jdbcType=VARCHAR}, + + + + + + + + + update license + set id = #{record.id,jdbcType=VARCHAR}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + license = #{record.license,jdbcType=VARCHAR}, + f2c_license = #{record.f2cLicense,jdbcType=VARCHAR} + + + + + + + update license + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + license = #{license,jdbcType=VARCHAR}, + + + f2c_license = #{f2cLicense,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + + update license + set update_time = #{updateTime,jdbcType=TIMESTAMP}, + license = #{license,jdbcType=VARCHAR}, + f2c_license = #{f2cLicense,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java b/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java new file mode 100644 index 0000000000..b0e074fece --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java @@ -0,0 +1,130 @@ +package io.dataease.commons.license; + +import com.google.gson.Gson; +import io.dataease.base.domain.License; +import io.dataease.commons.exception.DEException; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +@Service +public class DefaultLicenseService { + @Resource + private InnerLicenseService innerLicenseService; + @Value("${spring.application.name:null}") + private String moduleId; + + private static final String LICENSE_ID = "fit2cloud_license"; + private static final String validatorUtil = "/usr/bin/validator"; + private static final String product = "cmp"; + private static final String[] NO_PLU_LIMIT_MODULES = new String[]{"dashboard", "gateway"}; + + public F2CLicenseResponse validateLicense(String product, String licenseKey){ + List command = new ArrayList(); + StringBuilder result = new StringBuilder(); + command.add(validatorUtil); + command.add(licenseKey); + try{ + execCommand(result, command); + F2CLicenseResponse f2CLicenseResponse = new Gson().fromJson(result.toString(), F2CLicenseResponse.class); + if(f2CLicenseResponse.getStatus() != F2CLicenseResponse.Status.valid){ + return f2CLicenseResponse; + } + if(!StringUtils.equals(f2CLicenseResponse.getLicense().getProduct(), product)){ + f2CLicenseResponse.setStatus(F2CLicenseResponse.Status.invalid); + f2CLicenseResponse.setLicense(null); + f2CLicenseResponse.setMessage("The license is unavailable for this product."); + return f2CLicenseResponse; + } + +// 检查每个模块的PLU限制 +// if(!Arrays.asList(NO_PLU_LIMIT_MODULES).contains(moduleId)){ +// AuthorizationUnit authorizationUnit= CommonBeanFactory.getBean(AuthorizationUnit.class); +// try{ +// authorizationUnit.calculateAssets(f2CLicenseResponse.getLicense().getCount()); +// return f2CLicenseResponse; +// }catch (Exception e){ +// f2CLicenseResponse.setStatus(F2CLicenseResponse.Status.invalid); +// f2CLicenseResponse.setMessage(e.getMessage()); +// } +// } + return f2CLicenseResponse; + }catch (Exception e){ + return F2CLicenseResponse.invalid(e.getMessage()); + } + } + + + private static int execCommand(StringBuilder result, List command) throws Exception{ + ProcessBuilder builder = new ProcessBuilder(); + builder.command(command); + Process process = builder.start(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line = null; + while ((line=bufferedReader.readLine()) != null){ + result.append(line).append("\n"); + } + int exitCode = process.waitFor(); + command.clear(); + return exitCode; + } + + public F2CLicenseResponse validateLicense() { + try { + License license = readLicense(); + return validateLicense(product, license.getLicense()); + } catch (Exception e) { + return F2CLicenseResponse.invalid(e.getMessage()); + } + } + + public void validateF2cLicense(){ + License license = readLicense(); + F2CLicenseResponse f2CLicenseResponse = validateLicense(product, license.getLicense()); + writeLicense(license.getLicense(), f2CLicenseResponse); + } + + public F2CLicenseResponse updateLicense(String product, String licenseKey) { + // 验证license + F2CLicenseResponse response = validateLicense(product, licenseKey); + if (response.getStatus() != F2CLicenseResponse.Status.valid) { + return response; + } + // 覆盖原license + writeLicense(licenseKey, response); + return response; + } + + // 从数据库读取License + public License readLicense() { + License license = innerLicenseService.getLicense(LICENSE_ID); + if (license == null) { + /*DEException.throwException(Translator.get("i18n_no_license_record"));*/ + DEException.throwException("i18n_no_license_record"); + } + if (StringUtils.isBlank(license.getLicense())) { + DEException.throwException("i18n_license_is_empty"); + //F2CException.throwException(Translator.get("i18n_license_is_empty")); + } + return license; + } + + // 创建或更新License + private void writeLicense(String licenseKey, F2CLicenseResponse response) { + if (StringUtils.isBlank(licenseKey)) { + + DEException.throwException("i18n_license_is_empty"); + + } + License license = new License(); + license.setId(LICENSE_ID); + license.setLicense(licenseKey); + license.setF2cLicense(new Gson().toJson(response)); + innerLicenseService.saveLicense(license); + } +} diff --git a/backend/src/main/java/io/dataease/commons/license/F2CLicense.java b/backend/src/main/java/io/dataease/commons/license/F2CLicense.java new file mode 100644 index 0000000000..c2d7b5cb39 --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/license/F2CLicense.java @@ -0,0 +1,70 @@ +package io.dataease.commons.license; + +public class F2CLicense { + + private String corporation; + private String expired; + private String licenseVersion; + private String product; + private Long generateTime; + private String edition; + private Long count; + + public String getCorporation() { + return corporation; + } + + public void setCorporation(String corporation) { + this.corporation = corporation; + } + + public String getExpired() { + return expired; + } + + public void setExpired(String expired) { + this.expired = expired; + } + + public String getLicenseVersion() { + return licenseVersion; + } + + public void setLicenseVersion(String licenseVersion) { + this.licenseVersion = licenseVersion; + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + public Long getGenerateTime() { + return generateTime; + } + + public void setGenerateTime(Long generateTime) { + this.generateTime = generateTime; + } + + public String getEdition() { + return edition; + } + + public void setEdition(String edition) { + this.edition = edition; + } + + public Long getCount() { + return count; + } + + public void setCount(Long count) { + this.count = count; + } + + +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/commons/license/F2CLicenseResponse.java b/backend/src/main/java/io/dataease/commons/license/F2CLicenseResponse.java new file mode 100644 index 0000000000..529c97d609 --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/license/F2CLicenseResponse.java @@ -0,0 +1,46 @@ +package io.dataease.commons.license; + +public class F2CLicenseResponse { + + private Status status; + private F2CLicense license; + private String message; + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public F2CLicense getLicense() { + return license; + } + + public void setLicense(F2CLicense license) { + this.license = license; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public static enum Status { + valid, + invalid, + expired; + } + + public static F2CLicenseResponse invalid(String a) { + F2CLicenseResponse f2CLicenseResponse = new F2CLicenseResponse(); + f2CLicenseResponse.setStatus(Status.invalid); + f2CLicenseResponse.setLicense(null); + f2CLicenseResponse.setMessage(a); + return f2CLicenseResponse; + } +} diff --git a/backend/src/main/java/io/dataease/commons/license/InnerLicenseService.java b/backend/src/main/java/io/dataease/commons/license/InnerLicenseService.java new file mode 100644 index 0000000000..a72a223f7d --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/license/InnerLicenseService.java @@ -0,0 +1,39 @@ +package io.dataease.commons.license; + +import io.dataease.base.domain.License; +import io.dataease.base.mapper.LicenseMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; + +@Service +@Transactional(rollbackFor = Exception.class) +class InnerLicenseService { + + @Resource + private LicenseMapper licenseMapper; + + boolean existLicense(String key) { + License license = licenseMapper.selectByPrimaryKey(key); + return license != null; + } + + License getLicense(String key) { + License license = licenseMapper.selectByPrimaryKey(key); + if (license == null) return null; + return license; + } + + void saveLicense(License license) { + license.setUpdateTime(new Date()); + if (existLicense(license.getId())) { + licenseMapper.updateByPrimaryKey(license); + } else { + licenseMapper.insert(license); + } + } + + +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/controller/LicenseController.java b/backend/src/main/java/io/dataease/controller/LicenseController.java new file mode 100644 index 0000000000..f56e19d51c --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/LicenseController.java @@ -0,0 +1,46 @@ +package io.dataease.controller; + + + +import io.dataease.commons.license.DefaultLicenseService; +import io.dataease.commons.license.F2CLicenseResponse; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; + +@RestController +@RequestMapping(headers = "Accept=application/json") +public class LicenseController { + + @Value("${dataease.need_validate_lic:true}") + private Boolean need_validate_lic; + + @Resource + private DefaultLicenseService defaultLicenseService; + + @GetMapping(value = "anonymous/license/validate") + public ResultHolder validateLicense() throws Exception { + if (!need_validate_lic) { + return ResultHolder.success(null); + } + /* License license = defaultLicenseService.readLicense(); + if(StringUtils.isEmpty(license.getF2cLicense())){ + throw new Exception("Invalid License."); + } + F2CLicenseResponse f2CLicenseResponse = new Gson().fromJson(license.getF2cLicense(), F2CLicenseResponse.class);*/ + F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.validateLicense(); + switch (f2CLicenseResponse.getStatus()) { + case valid: + return ResultHolder.success(null); + case expired: + String expired = f2CLicenseResponse.getLicense().getExpired(); + throw new Exception("License has expired since " + expired + ", please update license."); + case invalid: + throw new Exception(f2CLicenseResponse.getMessage()); + default: + throw new Exception("Invalid License."); + } + } +} diff --git a/backend/src/main/java/io/dataease/controller/SystemParameterController.java b/backend/src/main/java/io/dataease/controller/SystemParameterController.java index 7aacf70966..8bb20f7223 100644 --- a/backend/src/main/java/io/dataease/controller/SystemParameterController.java +++ b/backend/src/main/java/io/dataease/controller/SystemParameterController.java @@ -6,8 +6,13 @@ import io.dataease.commons.constants.RoleConstants; import io.dataease.dto.BaseSystemConfigDTO; import io.dataease.dto.SystemParameterDTO; import io.dataease.notice.domain.MailInfo; +import io.dataease.service.FileService; import io.dataease.service.system.SystemParameterService; import org.apache.shiro.authz.annotation.RequiresRoles; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -23,6 +28,9 @@ public class SystemParameterController { @Resource private SystemParameterService systemParameterService; + @Resource + private FileService fileService; + @PostMapping("/edit/email") public void editMail(@RequestBody List systemParameter) { systemParameterService.editMail(systemParameter); @@ -54,8 +62,16 @@ public class SystemParameterController { return systemParameterService.getSystemParameterInfo(ParamConstants.Classify.UI.getValue()); } + @GetMapping(value="/ui/image/{imageId}", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE}) + public ResponseEntity image(@PathVariable("imageId") String imageId) { + byte[] bytes = fileService.loadFileAsBytes(imageId); + final HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.IMAGE_PNG); + return new ResponseEntity<>(bytes, headers, HttpStatus.OK); + } + @PostMapping(value="/save/ui", consumes = {"multipart/form-data"}) - public void saveUIInfo (@RequestPart("request") Map> systemParameterMap,@RequestPart(value = "files") List bodyFiles) throws IOException { + public void saveUIInfo (@RequestPart("request") Map> systemParameterMap,@RequestPart(value = "files", required = false) List bodyFiles) throws IOException { systemParameterService.saveUIInfo(systemParameterMap,bodyFiles); } diff --git a/backend/src/main/java/io/dataease/service/system/SystemParameterService.java b/backend/src/main/java/io/dataease/service/system/SystemParameterService.java index 4da94a29da..6b26bf6f54 100644 --- a/backend/src/main/java/io/dataease/service/system/SystemParameterService.java +++ b/backend/src/main/java/io/dataease/service/system/SystemParameterService.java @@ -220,6 +220,7 @@ public class SystemParameterService { public void saveUIInfo(Map> request, List bodyFiles) throws IOException { List parameters = request.get("systemParams"); + if (null != bodyFiles) for (MultipartFile multipartFile : bodyFiles) { if (!multipartFile.isEmpty()) { //防止添加非图片文件 diff --git a/backend/src/main/resources/db/migration/V8__system.sql b/backend/src/main/resources/db/migration/V8__system.sql index f7c72f8cff..b2ca5d69a9 100644 --- a/backend/src/main/resources/db/migration/V8__system.sql +++ b/backend/src/main/resources/db/migration/V8__system.sql @@ -271,3 +271,20 @@ BEGIN; COMMIT; SET FOREIGN_KEY_CHECKS = 1; + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for license +-- ---------------------------- +DROP TABLE IF EXISTS `license`; +CREATE TABLE `license` ( + `id` varchar(50) NOT NULL, + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + `license` longtext COMMENT 'license', + `f2c_license` longtext COMMENT 'F2C License', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/frontend/src/api/system/lic.js b/frontend/src/api/system/lic.js new file mode 100644 index 0000000000..fbf634dda2 --- /dev/null +++ b/frontend/src/api/system/lic.js @@ -0,0 +1,8 @@ +import request from '@/utils/request' + +export function validateLic() { + return request({ + url: '/anonymous/license/validate', + method: 'get' + }) +} diff --git a/frontend/src/api/user.js b/frontend/src/api/user.js index fbe62b88a2..2f82672213 100644 --- a/frontend/src/api/user.js +++ b/frontend/src/api/user.js @@ -29,3 +29,17 @@ export function validateUserName(data) { data }) } + +export function getUIinfo() { + return request({ + url: '/system/ui/info', + method: 'get' + }) +} + +export function uiImage(imageId) { + return request({ + url: '/display/file/' + imageId, + method: 'get' + }) +} diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 1644fe74cb..45b89ac3b4 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -74,7 +74,7 @@ export default { }, login: { title: 'Login Form', - welcome: 'welcome To DataEase', + welcome: 'welcome To ', logIn: 'Login', username: 'Username', password: 'Password', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index cfd220c381..8e78d2f927 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -74,7 +74,7 @@ export default { }, login: { title: '系统登录', - welcome: '歡迎使用DATAEASE', + welcome: '歡迎使用', logIn: '登錄', username: '账号', password: '密码', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 23897aa5a3..36af4a74d1 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -74,7 +74,7 @@ export default { }, login: { title: '系统登录', - welcome: '欢迎使用DataEase', + welcome: '欢迎使用', logIn: '登录', username: '账号', password: '密码', @@ -905,5 +905,12 @@ export default { un_install: '卸载', uninstall_confirm: '确定卸载该插件', uninstall_cancel: '取消卸载插件' + }, + display: { + logo: '头部系统logo', + loginLogo: '登录页面头部logo', + loginImage: '登录页面右侧图片', + loginTitle: '登录页面标题', + title: '系统名称' } } diff --git a/frontend/src/layout/components/Licbar.vue b/frontend/src/layout/components/Licbar.vue new file mode 100644 index 0000000000..1d8446cf53 --- /dev/null +++ b/frontend/src/layout/components/Licbar.vue @@ -0,0 +1,56 @@ + + + + diff --git a/frontend/src/layout/components/Topbar.vue b/frontend/src/layout/components/Topbar.vue index e827dbefcf..edd91a3092 100644 --- a/frontend/src/layout/components/Topbar.vue +++ b/frontend/src/layout/components/Topbar.vue @@ -1,7 +1,8 @@