增加全局配置

This commit is contained in:
none 2023-03-09 13:58:51 +08:00
parent 82f0783cb8
commit 908b35f3de
10 changed files with 155 additions and 63 deletions

View File

@ -5,7 +5,6 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import xyz.playedu.api.constant.BPermissionConstant;
import xyz.playedu.api.constant.BackendConstant;
import xyz.playedu.api.domain.AdminPermission;
import xyz.playedu.api.service.AdminPermissionService;
@ -18,9 +17,6 @@ import java.util.*;
@Component
public class AdminPermissionCheck implements ApplicationRunner {
@Autowired
private AdminPermissionService permissionService;
private final Map<String, Map<String, AdminPermission[]>> permissions = new HashMap<>() {{
put(BPermissionConstant.TYPE_ACTION, new HashMap<>() {{
put("管理员", new AdminPermission[]{
@ -114,8 +110,11 @@ public class AdminPermissionCheck implements ApplicationRunner {
}});
}};
@Autowired
private AdminPermissionService permissionService;
@Override
public void run(ApplicationArguments args) {
public void run(ApplicationArguments args) throws Exception {
HashMap<String, Boolean> slugs = permissionService.allSlugs();
List<AdminPermission> list = new ArrayList<>();
Date now = new Date();

View File

@ -20,7 +20,7 @@ public class AdminRoleCheck implements ApplicationRunner {
@Autowired
private AdminRoleService adminRoleService;
private final AdminRole superRole = new AdminRole() {{
private static final AdminRole superRole = new AdminRole() {{
setName("超级管理员");
setSlug(BackendConstant.SUPER_ADMIN_ROLE);
setCreatedAt(new Date());

View File

@ -0,0 +1,88 @@
package xyz.playedu.api.checks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import xyz.playedu.api.constant.BackendConstant;
import xyz.playedu.api.domain.AppConfig;
import xyz.playedu.api.service.AppConfigService;
import java.util.*;
/**
* @Author 杭州白书科技有限公司
* @create 2023/3/9 13:29
*/
@Component
public class AppConfigCheck implements ApplicationRunner {
private static final HashMap<String, AppConfig[]> configs = new HashMap<>() {{
put("系统", new AppConfig[]{
new AppConfig() {{
setName("网站名");
setSort(10);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_INPUT);
setKeyName("system.name");
setKeyValue("");
}},
new AppConfig() {{
setName("Logo");
setSort(20);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_IMAGE);
setKeyName("system.key");
setKeyValue("");
}},
new AppConfig() {{
setName("API访问地址");
setSort(30);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_INPUT);
setKeyName("system.api_url");
setKeyValue("");
}},
new AppConfig() {{
setName("PC端口访问地址");
setSort(40);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_INPUT);
setKeyName("system.pc_url");
setKeyValue("");
}},
new AppConfig() {{
setName("H5端口访问地址");
setSort(50);
setFieldType(BackendConstant.APP_CONFIG_FIELD_TYPE_INPUT);
setKeyName("system.h5_url");
setKeyValue("");
}},
});
}};
@Autowired
private AppConfigService configService;
@Override
public void run(ApplicationArguments args) throws Exception {
Map<String, Long> keys = configService.allKeys();
List<AppConfig> list = new ArrayList<>();
Date now = new Date();
configs.forEach((groupNameValue, items) -> {
for (int i = 0; i < items.length; i++) {
AppConfig configItem = items[i];
if (keys.get(configItem.getKeyName()) != null) {
continue;
}
configItem.setGroupName(groupNameValue);
configItem.setCreatedAt(now);
list.add(configItem);
}
});
if (list.size() > 0) {
configService.saveBatch(list);
}
}
}

View File

@ -47,8 +47,6 @@ public class BackendConstant {
public final static String STORAGE_DRIVER_MINIO = "minio";
public final static String[] RESOURCE_DISK_WHITELIST = {STORAGE_DRIVER_MINIO};
public final static String[] COURSE_HOUR_TYPE_WHITELIST = {"VIDEO"};
public final static String[] COURSE_HOUR_TYPE_WHITELIST_TEXT = {"视频"};
@ -63,4 +61,9 @@ public class BackendConstant {
public final static String PRIVACY_FIELD_TYPE_NAME = "name";
public final static String PRIVACY_FIELD_TYPE_ID_CARD = "IDCard";
public final static String APP_CONFIG_FIELD_TYPE_IMAGE = "image";
public final static String APP_CONFIG_FIELD_TYPE_INPUT = "input";
public final static String APP_CONFIG_FIELD_TYPE_TEXT = "text";
public final static String APP_CONFIG_FIELD_TYPE_SELECT = "select";
}

View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@ -27,7 +28,8 @@ public class AppConfig implements Serializable {
/**
* 分组
*/
private String group;
@JsonProperty("group_name")
private String groupName;
/**
* 名称
@ -48,18 +50,14 @@ public class AppConfig implements Serializable {
/**
*
*/
private String key;
@JsonProperty("key_name")
private String keyName;
/**
*
*/
private String value;
/**
* 默认值
*/
@JsonProperty("default_value")
private String defaultValue;
@JsonProperty("key_value")
private String keyValue;
/**
* 可选值
@ -88,7 +86,12 @@ public class AppConfig implements Serializable {
* 1显示,0否
*/
@JsonIgnore
private Integer isShow;
private Integer isHidden;
@JsonGetter("key_value")
public String transformKeyValue() {
return isHidden == 1 ? "******" : keyValue;
}
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@ -106,18 +109,17 @@ public class AppConfig implements Serializable {
}
AppConfig other = (AppConfig) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getGroup() == null ? other.getGroup() == null : this.getGroup().equals(other.getGroup()))
&& (this.getGroupName() == null ? other.getGroupName() == null : this.getGroupName().equals(other.getGroupName()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getSort() == null ? other.getSort() == null : this.getSort().equals(other.getSort()))
&& (this.getFieldType() == null ? other.getFieldType() == null : this.getFieldType().equals(other.getFieldType()))
&& (this.getKey() == null ? other.getKey() == null : this.getKey().equals(other.getKey()))
&& (this.getValue() == null ? other.getValue() == null : this.getValue().equals(other.getValue()))
&& (this.getDefaultValue() == null ? other.getDefaultValue() == null : this.getDefaultValue().equals(other.getDefaultValue()))
&& (this.getKeyName() == null ? other.getKeyName() == null : this.getKeyName().equals(other.getKeyName()))
&& (this.getKeyValue() == null ? other.getKeyValue() == null : this.getKeyValue().equals(other.getKeyValue()))
&& (this.getOptionValue() == null ? other.getOptionValue() == null : this.getOptionValue().equals(other.getOptionValue()))
&& (this.getIsPrivate() == null ? other.getIsPrivate() == null : this.getIsPrivate().equals(other.getIsPrivate()))
&& (this.getHelp() == null ? other.getHelp() == null : this.getHelp().equals(other.getHelp()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getIsShow() == null ? other.getIsShow() == null : this.getIsShow().equals(other.getIsShow()));
&& (this.getIsHidden() == null ? other.getIsHidden() == null : this.getIsHidden().equals(other.getIsHidden()));
}
@Override
@ -125,18 +127,17 @@ public class AppConfig implements Serializable {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getGroup() == null) ? 0 : getGroup().hashCode());
result = prime * result + ((getGroupName() == null) ? 0 : getGroupName().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getSort() == null) ? 0 : getSort().hashCode());
result = prime * result + ((getFieldType() == null) ? 0 : getFieldType().hashCode());
result = prime * result + ((getKey() == null) ? 0 : getKey().hashCode());
result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode());
result = prime * result + ((getDefaultValue() == null) ? 0 : getDefaultValue().hashCode());
result = prime * result + ((getKeyName() == null) ? 0 : getKeyName().hashCode());
result = prime * result + ((getKeyValue() == null) ? 0 : getKeyValue().hashCode());
result = prime * result + ((getOptionValue() == null) ? 0 : getOptionValue().hashCode());
result = prime * result + ((getIsPrivate() == null) ? 0 : getIsPrivate().hashCode());
result = prime * result + ((getHelp() == null) ? 0 : getHelp().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getIsShow() == null) ? 0 : getIsShow().hashCode());
result = prime * result + ((getIsHidden() == null) ? 0 : getIsHidden().hashCode());
return result;
}
@ -147,18 +148,17 @@ public class AppConfig implements Serializable {
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", group=").append(group);
sb.append(", groupName=").append(groupName);
sb.append(", name=").append(name);
sb.append(", sort=").append(sort);
sb.append(", fieldType=").append(fieldType);
sb.append(", key=").append(key);
sb.append(", value=").append(value);
sb.append(", defaultValue=").append(defaultValue);
sb.append(", keyName=").append(keyName);
sb.append(", keyValue=").append(keyValue);
sb.append(", optionValue=").append(optionValue);
sb.append(", isPrivate=").append(isPrivate);
sb.append(", help=").append(help);
sb.append(", createdAt=").append(createdAt);
sb.append(", isShow=").append(isShow);
sb.append(", isHidden=").append(isHidden);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();

View File

@ -5,11 +5,11 @@ import xyz.playedu.api.domain.AppConfig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author tengteng
* @description 针对表app_config的数据库操作Mapper
* @createDate 2023-03-09 11:13:33
* @Entity xyz.playedu.api.domain.AppConfig
*/
* @author tengteng
* @description 针对表app_config的数据库操作Mapper
* @createDate 2023-03-09 13:55:39
* @Entity xyz.playedu.api.domain.AppConfig
*/
@Mapper
public interface AppConfigMapper extends BaseMapper<AppConfig> {

View File

@ -3,6 +3,8 @@ package xyz.playedu.api.service;
import xyz.playedu.api.domain.AppConfig;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Map;
/**
* @author tengteng
* @description 针对表app_config的数据库操作Service
@ -10,4 +12,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface AppConfigService extends IService<AppConfig> {
Map<String, Long> allKeys();
}

View File

@ -6,15 +6,22 @@ import xyz.playedu.api.service.AppConfigService;
import xyz.playedu.api.mapper.AppConfigMapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author tengteng
* @description 针对表app_config的数据库操作Service实现
* @createDate 2023-03-09 11:13:33
*/
* @author tengteng
* @description 针对表app_config的数据库操作Service实现
* @createDate 2023-03-09 11:13:33
*/
@Service
public class AppConfigServiceImpl extends ServiceImpl<AppConfigMapper, AppConfig>
implements AppConfigService{
implements AppConfigService {
@Override
public Map<String, Long> allKeys() {
return list().stream().collect(Collectors.toMap(AppConfig::getKeyName, AppConfig::getId));
}
}

View File

@ -152,16 +152,9 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
public void updateWithCategoryIdsAndDepIds(Course course, String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds) {
Course newCourse = new Course();
newCourse.setId(course.getId());
if (!course.getTitle().equals(title)) {
newCourse.setTitle(title);
}
if (!course.getThumb().equals(thumb)) {
newCourse.setThumb(thumb);
}
if (!course.getIsShow().equals(isShow)) {
newCourse.setIsShow(isShow);
}
newCourse.setTitle(title);
newCourse.setThumb(thumb);
newCourse.setIsShow(isShow);
updateById(newCourse);

View File

@ -6,25 +6,23 @@
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AppConfig">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="group" column="group" jdbcType="VARCHAR"/>
<result property="groupName" column="group_name" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="sort" column="sort" jdbcType="INTEGER"/>
<result property="fieldType" column="field_type" jdbcType="VARCHAR"/>
<result property="key" column="key" jdbcType="VARCHAR"/>
<result property="value" column="value" jdbcType="VARCHAR"/>
<result property="defaultValue" column="default_value" jdbcType="VARCHAR"/>
<result property="keyName" column="key_name" jdbcType="VARCHAR"/>
<result property="keyValue" column="key_value" jdbcType="VARCHAR"/>
<result property="optionValue" column="option_value" jdbcType="VARCHAR"/>
<result property="isPrivate" column="is_private" jdbcType="TINYINT"/>
<result property="help" column="help" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
<result property="isHidden" column="is_hidden" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
id,group,name,
sort,field_type,key,
value,default_value,option_value,
is_private,help,created_at,
is_show
id,group_name,name,
sort,field_type,key_name,
key_value,option_value,is_private,
help,created_at,is_hidden
</sql>
</mapper>