diff --git a/src/main/java/xyz/playedu/api/checks/AdminPermissionCheck.java b/src/main/java/xyz/playedu/api/checks/AdminPermissionCheck.java index c9efd2e..1ec289f 100644 --- a/src/main/java/xyz/playedu/api/checks/AdminPermissionCheck.java +++ b/src/main/java/xyz/playedu/api/checks/AdminPermissionCheck.java @@ -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> 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 slugs = permissionService.allSlugs(); List list = new ArrayList<>(); Date now = new Date(); diff --git a/src/main/java/xyz/playedu/api/checks/AdminRoleCheck.java b/src/main/java/xyz/playedu/api/checks/AdminRoleCheck.java index 9c35934..73a239a 100644 --- a/src/main/java/xyz/playedu/api/checks/AdminRoleCheck.java +++ b/src/main/java/xyz/playedu/api/checks/AdminRoleCheck.java @@ -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()); diff --git a/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java new file mode 100644 index 0000000..1f7a360 --- /dev/null +++ b/src/main/java/xyz/playedu/api/checks/AppConfigCheck.java @@ -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 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 keys = configService.allKeys(); + List 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); + } + } + +} diff --git a/src/main/java/xyz/playedu/api/constant/BackendConstant.java b/src/main/java/xyz/playedu/api/constant/BackendConstant.java index 467e67d..04251f2 100644 --- a/src/main/java/xyz/playedu/api/constant/BackendConstant.java +++ b/src/main/java/xyz/playedu/api/constant/BackendConstant.java @@ -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"; + } diff --git a/src/main/java/xyz/playedu/api/domain/AppConfig.java b/src/main/java/xyz/playedu/api/domain/AppConfig.java index e18a26a..b8486fe 100644 --- a/src/main/java/xyz/playedu/api/domain/AppConfig.java +++ b/src/main/java/xyz/playedu/api/domain/AppConfig.java @@ -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(); diff --git a/src/main/java/xyz/playedu/api/mapper/AppConfigMapper.java b/src/main/java/xyz/playedu/api/mapper/AppConfigMapper.java index 76e7ce4..0df1ebd 100644 --- a/src/main/java/xyz/playedu/api/mapper/AppConfigMapper.java +++ b/src/main/java/xyz/playedu/api/mapper/AppConfigMapper.java @@ -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 { diff --git a/src/main/java/xyz/playedu/api/service/AppConfigService.java b/src/main/java/xyz/playedu/api/service/AppConfigService.java index 16b3b40..71e9f95 100644 --- a/src/main/java/xyz/playedu/api/service/AppConfigService.java +++ b/src/main/java/xyz/playedu/api/service/AppConfigService.java @@ -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 { + Map allKeys(); + } diff --git a/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java index 99f90e8..93a18d0 100644 --- a/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/AppConfigServiceImpl.java @@ -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 - implements AppConfigService{ + implements AppConfigService { + @Override + public Map allKeys() { + return list().stream().collect(Collectors.toMap(AppConfig::getKeyName, AppConfig::getId)); + } } diff --git a/src/main/java/xyz/playedu/api/service/impl/CourseServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/CourseServiceImpl.java index 13966a3..340e351 100644 --- a/src/main/java/xyz/playedu/api/service/impl/CourseServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/CourseServiceImpl.java @@ -152,16 +152,9 @@ public class CourseServiceImpl extends ServiceImpl 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); diff --git a/src/main/resources/mapper/AppConfigMapper.xml b/src/main/resources/mapper/AppConfigMapper.xml index 84fd50f..212a3e4 100644 --- a/src/main/resources/mapper/AppConfigMapper.xml +++ b/src/main/resources/mapper/AppConfigMapper.xml @@ -6,25 +6,23 @@ - + - - - + + - + - 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