From 2c26613456bea2e399326f605ff9f346912d3255 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:50:24 +0800 Subject: [PATCH 1/5] chore(deps): bump org.springframework.boot:spring-boot-starter-parent (#212) Bumps [org.springframework.boot:spring-boot-starter-parent](https://github.com/spring-projects/spring-boot) from 3.2.2 to 3.2.3. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.2.2...v3.2.3) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-parent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6713f1c..6e90fbf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.2 + 3.2.3 From a293983bebc086de98d226d99b64a47ed95c78c5 Mon Sep 17 00:00:00 2001 From: BingChunMoLi <44092516+BingChunMoLi@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:28:15 +0800 Subject: [PATCH 2/5] fix(v3.15.1): vue deploy base admin IpInterceptor count > 40 --- pom.xml | 22 ------------------- .../api/config/UserController.java | 11 +++------- .../api/config/UserServiceImpl.java | 2 +- .../api/interceptor/IpInterceptor.java | 13 +---------- .../api/weather/bean/WeatherSubscribeParam.kt | 1 + src/main/vue/admin/.env.production | 3 ++- src/main/vue/admin/src/views/InitView.vue | 2 +- src/main/vue/admin/src/views/LoginView.vue | 2 +- src/main/vue/admin/src/views/MainView.vue | 13 +++++++---- src/main/vue/admin/vite.config.ts | 1 + 10 files changed, 20 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index 6e90fbf..705acd2 100644 --- a/pom.xml +++ b/pom.xml @@ -17,8 +17,6 @@ 17 - 3.5.15 - 3.0.3 3.5.5 1.4.13 5.8.26 @@ -61,26 +59,6 @@ com.baomidou mybatis-plus-spring-boot3-starter ${mybatis-plus.version} - - - org.mybatis - mybatis - - - org.mybatis - mybatis-spring - - - - - org.mybatis - mybatis - ${mybatis.version} - - - org.mybatis - mybatis-spring - ${mybatis-spring.version} org.springframework.boot diff --git a/src/main/java/com/bingchunmoli/api/config/UserController.java b/src/main/java/com/bingchunmoli/api/config/UserController.java index f7ce514..a0b11c5 100644 --- a/src/main/java/com/bingchunmoli/api/config/UserController.java +++ b/src/main/java/com/bingchunmoli/api/config/UserController.java @@ -7,16 +7,11 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @Slf4j @RestController -@RequestMapping +@RequestMapping("/user") @RequiredArgsConstructor public class UserController { private final UserService userService; @@ -36,7 +31,7 @@ public ResultVO isInit() { return ResultVO.ok(userService.count() == 0L); } - @PutMapping + @PutMapping("/register") public ResultVO register(@Valid @RequestBody User user) { if (userService.register(user)) { request.getSession().setAttribute("user", user.getId()); diff --git a/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java b/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java index def0757..85c068f 100644 --- a/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java +++ b/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java @@ -33,7 +33,7 @@ public Boolean login(User user) { @Override public synchronized boolean register(User user) { - if (count() > 1) { + if (count() > 0) { throw new ApiSystemException("错误的初始化用户"); } user.setPassword(passwordEncoder.encode(user.getPassword())); diff --git a/src/main/java/com/bingchunmoli/api/interceptor/IpInterceptor.java b/src/main/java/com/bingchunmoli/api/interceptor/IpInterceptor.java index 259ae38..10752d9 100644 --- a/src/main/java/com/bingchunmoli/api/interceptor/IpInterceptor.java +++ b/src/main/java/com/bingchunmoli/api/interceptor/IpInterceptor.java @@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -31,7 +30,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl String clientIP = JakartaServletUtil.getClientIP(request); String key = "filter:" + requestURI + ":" + clientIP + ":" + request.getRequestedSessionId(); Integer value = redisUtil.getObject(key); - if (value != null && value > 10) { + if (value != null && value > 40) { response.setStatus(429); return false; } @@ -50,14 +49,4 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl redisUtil.setObject(key, count.get(), 60, TimeUnit.SECONDS); return true; } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - - } } diff --git a/src/main/java/com/bingchunmoli/api/weather/bean/WeatherSubscribeParam.kt b/src/main/java/com/bingchunmoli/api/weather/bean/WeatherSubscribeParam.kt index 7c63e39..979df1f 100644 --- a/src/main/java/com/bingchunmoli/api/weather/bean/WeatherSubscribeParam.kt +++ b/src/main/java/com/bingchunmoli/api/weather/bean/WeatherSubscribeParam.kt @@ -3,3 +3,4 @@ package com.bingchunmoli.api.weather.bean import jakarta.validation.constraints.Email data class WeatherSubscribeParam (@Email val email: String, val location: String) + diff --git a/src/main/vue/admin/.env.production b/src/main/vue/admin/.env.production index baeb84c..eb67286 100644 --- a/src/main/vue/admin/.env.production +++ b/src/main/vue/admin/.env.production @@ -1 +1,2 @@ -VITE_API_BASE_URL=https://api.bingchunmoli.com/ \ No newline at end of file +VITE_API_BASE_URL=https://api.bingchunmoli.com/ +BASE_URL=/admin/ diff --git a/src/main/vue/admin/src/views/InitView.vue b/src/main/vue/admin/src/views/InitView.vue index 4a48738..b13e037 100644 --- a/src/main/vue/admin/src/views/InitView.vue +++ b/src/main/vue/admin/src/views/InitView.vue @@ -53,7 +53,7 @@ const submitForm = async (formEl: FormInstance | undefined) => { if (!formEl) return await formEl.validate((valid, fields) => { if (valid) { - fetch(import.meta.env.VITE_API_BASE_URL, { + fetch(import.meta.env.VITE_API_BASE_URL + 'user/register', { method: 'put', headers: { 'Content-Type': 'application/json' diff --git a/src/main/vue/admin/src/views/LoginView.vue b/src/main/vue/admin/src/views/LoginView.vue index 08aa175..2ed1b78 100644 --- a/src/main/vue/admin/src/views/LoginView.vue +++ b/src/main/vue/admin/src/views/LoginView.vue @@ -52,7 +52,7 @@ const submitForm = async (formEl: FormInstance | undefined) => { if (!formEl) return await formEl.validate((valid, fields) => { if (valid) { - fetch(import.meta.env.VITE_API_BASE_URL + 'login', { + fetch(import.meta.env.VITE_API_BASE_URL + 'user/login', { method: 'post', headers: { 'Content-Type': 'application/json' diff --git a/src/main/vue/admin/src/views/MainView.vue b/src/main/vue/admin/src/views/MainView.vue index 9c5dfa7..539e347 100644 --- a/src/main/vue/admin/src/views/MainView.vue +++ b/src/main/vue/admin/src/views/MainView.vue @@ -4,7 +4,8 @@ import type {ResultVO} from '@/type/ResultVO' import type {FormInstance} from 'element-plus' import {reactive, ref} from 'vue' -fetch(import.meta.env.VITE_API_BASE_URL + 'init', { +let flag = false; +fetch(import.meta.env.VITE_API_BASE_URL + 'user/init', { method: 'get', headers: { 'Content-Type': 'application/json' @@ -14,6 +15,7 @@ fetch(import.meta.env.VITE_API_BASE_URL + 'init', { .then((res) => { if (res && res.code === '00000' && res.data === true) { ElMessage('前往初始化注册用户') + flag = true; router.push({path: '/init'}) } }) @@ -34,9 +36,10 @@ function getSystemConfig() { return r.json() as Promise> } else { if (r.status === 401) { - router.push({path: '/login'}) + if (!flag) { + router.push({path: '/login'}); + } } - throw new Error() } }) .then((res) => { @@ -49,7 +52,9 @@ function getSystemConfig() { }) } -getSystemConfig() +if (!flag) { + getSystemConfig() +} interface ApiConfig { weatherKey: string diff --git a/src/main/vue/admin/vite.config.ts b/src/main/vue/admin/vite.config.ts index ed57561..e094410 100644 --- a/src/main/vue/admin/vite.config.ts +++ b/src/main/vue/admin/vite.config.ts @@ -9,6 +9,7 @@ import {ElementPlusResolver} from 'unplugin-vue-components/resolvers' // https://vitejs.dev/config/ export default defineConfig({ + base: '/admin/', plugins: [ vue(), vueJsx(), From cf9dd935cfb8e5c33c851866491bfb4104db1ea7 Mon Sep 17 00:00:00 2001 From: BingChunMoLi <44092516+BingChunMoLi@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:50:10 +0800 Subject: [PATCH 3/5] feat: config update --- .../bingchunmoli/api/config/ApiConfig.java | 4 +- .../api/config/SystemController.java | 12 +- .../api/config/UserController.java | 1 + .../bingchunmoli/api/config/bean/Config.java | 44 ++++++ .../api/config/mapper/ConfigMapper.java | 15 ++ .../api/config/service/ConfigService.java | 13 ++ .../api/config/{ => service}/UserService.java | 2 +- .../service/impl/ConfigServiceImpl.java | 62 +++++++++ .../{ => service/impl}/UserServiceImpl.java | 9 +- .../SystemAuthenticationInterceptor.java | 6 +- .../api/netease/MusicService.java | 130 +++++++++--------- src/main/resources/META-INF/spring.components | 2 +- src/main/resources/init/db/init.sql | 14 +- src/main/resources/mapper/ConfigMapper.xml | 19 +++ src/main/vue/admin/src/views/MainView.vue | 31 ++++- 15 files changed, 278 insertions(+), 86 deletions(-) create mode 100644 src/main/java/com/bingchunmoli/api/config/bean/Config.java create mode 100644 src/main/java/com/bingchunmoli/api/config/mapper/ConfigMapper.java create mode 100644 src/main/java/com/bingchunmoli/api/config/service/ConfigService.java rename src/main/java/com/bingchunmoli/api/config/{ => service}/UserService.java (84%) create mode 100644 src/main/java/com/bingchunmoli/api/config/service/impl/ConfigServiceImpl.java rename src/main/java/com/bingchunmoli/api/config/{ => service/impl}/UserServiceImpl.java (83%) create mode 100644 src/main/resources/mapper/ConfigMapper.xml diff --git a/src/main/java/com/bingchunmoli/api/config/ApiConfig.java b/src/main/java/com/bingchunmoli/api/config/ApiConfig.java index 3189b38..2e5f98d 100644 --- a/src/main/java/com/bingchunmoli/api/config/ApiConfig.java +++ b/src/main/java/com/bingchunmoli/api/config/ApiConfig.java @@ -4,8 +4,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; -import java.util.List; - /** * ApiConfig * @author bingchunmoli @@ -69,7 +67,7 @@ public class ApiConfig { /** * 定时任务歌单id */ - private List playListId; + private String playListId; /** * 歌单用的cookies, diff --git a/src/main/java/com/bingchunmoli/api/config/SystemController.java b/src/main/java/com/bingchunmoli/api/config/SystemController.java index be12c9c..e8f41db 100644 --- a/src/main/java/com/bingchunmoli/api/config/SystemController.java +++ b/src/main/java/com/bingchunmoli/api/config/SystemController.java @@ -1,13 +1,10 @@ package com.bingchunmoli.api.config; import com.bingchunmoli.api.bean.ResultVO; +import com.bingchunmoli.api.config.service.ConfigService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @Slf4j @RestController @@ -15,7 +12,7 @@ @RequestMapping("/system") public class SystemController { private final ApiConfig apiConfig; - + private final ConfigService configService; /** * 查询当前的配置项 * @@ -34,6 +31,7 @@ public ResultVO systemConfig() { */ @PostMapping public ResultVO updateSystemConfig(@RequestBody ApiConfig apiConfig) { - return ResultVO.ok(null); + configService.updateApiConfig(apiConfig); + return ResultVO.ok(true); } } diff --git a/src/main/java/com/bingchunmoli/api/config/UserController.java b/src/main/java/com/bingchunmoli/api/config/UserController.java index a0b11c5..c5b4504 100644 --- a/src/main/java/com/bingchunmoli/api/config/UserController.java +++ b/src/main/java/com/bingchunmoli/api/config/UserController.java @@ -2,6 +2,7 @@ import com.bingchunmoli.api.bean.ResultVO; import com.bingchunmoli.api.config.bean.User; +import com.bingchunmoli.api.config.service.UserService; import com.bingchunmoli.api.exception.system.ApiSystemException; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; diff --git a/src/main/java/com/bingchunmoli/api/config/bean/Config.java b/src/main/java/com/bingchunmoli/api/config/bean/Config.java new file mode 100644 index 0000000..31fbc16 --- /dev/null +++ b/src/main/java/com/bingchunmoli/api/config/bean/Config.java @@ -0,0 +1,44 @@ +package com.bingchunmoli.api.config.bean; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * + */ +@Data +@Builder +@TableName(value = "`config`") +public class Config implements Serializable { + @TableField(exist = false) + private static final long serialVersionUID = 1L; + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 配置的key + */ + @TableField(value = "`key`") + private String key; + /** + * 配置的值 + */ + @TableField(value = "`value`") + private String value; + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; +} diff --git a/src/main/java/com/bingchunmoli/api/config/mapper/ConfigMapper.java b/src/main/java/com/bingchunmoli/api/config/mapper/ConfigMapper.java new file mode 100644 index 0000000..92f2085 --- /dev/null +++ b/src/main/java/com/bingchunmoli/api/config/mapper/ConfigMapper.java @@ -0,0 +1,15 @@ +package com.bingchunmoli.api.config.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bingchunmoli.api.config.bean.Config; + +/** + * @author MoLi + */ +public interface ConfigMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/bingchunmoli/api/config/service/ConfigService.java b/src/main/java/com/bingchunmoli/api/config/service/ConfigService.java new file mode 100644 index 0000000..17ff062 --- /dev/null +++ b/src/main/java/com/bingchunmoli/api/config/service/ConfigService.java @@ -0,0 +1,13 @@ +package com.bingchunmoli.api.config.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.bingchunmoli.api.config.ApiConfig; +import com.bingchunmoli.api.config.bean.Config; + +/** + * @author MoLi + */ +public interface ConfigService extends IService { + + void updateApiConfig(ApiConfig apiConfig); +} diff --git a/src/main/java/com/bingchunmoli/api/config/UserService.java b/src/main/java/com/bingchunmoli/api/config/service/UserService.java similarity index 84% rename from src/main/java/com/bingchunmoli/api/config/UserService.java rename to src/main/java/com/bingchunmoli/api/config/service/UserService.java index b0b96ba..0189d10 100644 --- a/src/main/java/com/bingchunmoli/api/config/UserService.java +++ b/src/main/java/com/bingchunmoli/api/config/service/UserService.java @@ -1,4 +1,4 @@ -package com.bingchunmoli.api.config; +package com.bingchunmoli.api.config.service; import com.baomidou.mybatisplus.extension.service.IService; import com.bingchunmoli.api.config.bean.User; diff --git a/src/main/java/com/bingchunmoli/api/config/service/impl/ConfigServiceImpl.java b/src/main/java/com/bingchunmoli/api/config/service/impl/ConfigServiceImpl.java new file mode 100644 index 0000000..896cf79 --- /dev/null +++ b/src/main/java/com/bingchunmoli/api/config/service/impl/ConfigServiceImpl.java @@ -0,0 +1,62 @@ +package com.bingchunmoli.api.config.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bingchunmoli.api.config.ApiConfig; +import com.bingchunmoli.api.config.bean.Config; +import com.bingchunmoli.api.config.mapper.ConfigMapper; +import com.bingchunmoli.api.config.service.ConfigService; +import com.bingchunmoli.api.exception.ApiException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.time.LocalDateTime; +import java.util.Locale; +import java.util.Objects; + +/** + * @author MoLi + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class ConfigServiceImpl extends ServiceImpl implements ConfigService { + private final ApiConfig apiConfig; + + @Override + public void updateApiConfig(ApiConfig apiConfig) { + Class apiConfigClass = apiConfig.getClass(); + for (Field field : apiConfigClass.getDeclaredFields()) { +// field.setAccessible(true); + String fieldName = field.getName(); + String upperCaseFieldName = fieldName.substring(0, 1).toUpperCase(Locale.ROOT) + fieldName.substring(1); + try { + Method getMethod = apiConfigClass.getMethod("get" + upperCaseFieldName); + Object paramValue = getMethod.invoke(apiConfig); + Object systemValue = getMethod.invoke(this.apiConfig); + if (!Objects.equals(paramValue, systemValue)) { + Method setMethod = apiConfigClass.getMethod("set" + upperCaseFieldName, String.class); + setMethod.invoke(this.apiConfig, paramValue); + Config config = getOneOpt(new LambdaQueryWrapper().eq(Config::getKey, fieldName)) + .orElse(Config.builder() + .key(fieldName) + .value((String) paramValue) + .updateTime(LocalDateTime.now()) + .build()); + saveOrUpdate(config); + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new ApiException(e); + } + + } + } +} + + + + diff --git a/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java b/src/main/java/com/bingchunmoli/api/config/service/impl/UserServiceImpl.java similarity index 83% rename from src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java rename to src/main/java/com/bingchunmoli/api/config/service/impl/UserServiceImpl.java index 85c068f..b06d343 100644 --- a/src/main/java/com/bingchunmoli/api/config/UserServiceImpl.java +++ b/src/main/java/com/bingchunmoli/api/config/service/impl/UserServiceImpl.java @@ -1,9 +1,10 @@ -package com.bingchunmoli.api.config; +package com.bingchunmoli.api.config.service.impl; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.bingchunmoli.api.config.bean.User; import com.bingchunmoli.api.config.mapper.UserMapper; +import com.bingchunmoli.api.config.service.UserService; import com.bingchunmoli.api.exception.system.ApiSystemException; import com.bingchunmoli.api.exception.system.ApiUserNonFoundException; import lombok.RequiredArgsConstructor; @@ -28,7 +29,11 @@ public Boolean login(User user) { Optional optional = getOneOpt(Wrappers.lambdaQuery(new User()).eq(User::getName, user.getName())); optional.orElseThrow(() -> new ApiUserNonFoundException("non user")); String password = optional.map(User::getPassword).orElseThrow(() -> new ApiSystemException("non password")); - return passwordEncoder.matches(user.getPassword(), password); + boolean matche = passwordEncoder.matches(user.getPassword(), password); + if (matche) { + user.setId(optional.map(User::getId).orElseThrow()); + } + return matche; } @Override diff --git a/src/main/java/com/bingchunmoli/api/interceptor/SystemAuthenticationInterceptor.java b/src/main/java/com/bingchunmoli/api/interceptor/SystemAuthenticationInterceptor.java index 7577e32..026b4b0 100644 --- a/src/main/java/com/bingchunmoli/api/interceptor/SystemAuthenticationInterceptor.java +++ b/src/main/java/com/bingchunmoli/api/interceptor/SystemAuthenticationInterceptor.java @@ -2,12 +2,13 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; +import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import org.springframework.web.servlet.AsyncHandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor; +@Slf4j @Component public class SystemAuthenticationInterceptor implements HandlerInterceptor { @@ -37,8 +38,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl if (!request.getRequestURI().startsWith("/system")) { return true; } - HttpSession session = request.getSession(); - Integer userId = (Integer) session.getAttribute("user"); + Integer userId = (Integer) request.getSession().getAttribute("user"); if (userId == null || userId < 1) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return false; diff --git a/src/main/java/com/bingchunmoli/api/netease/MusicService.java b/src/main/java/com/bingchunmoli/api/netease/MusicService.java index 338503e..8159097 100644 --- a/src/main/java/com/bingchunmoli/api/netease/MusicService.java +++ b/src/main/java/com/bingchunmoli/api/netease/MusicService.java @@ -76,76 +76,72 @@ public void savePlayList() { log.info("playListId is empty ignore"); return; } - for (String id: apiConfig.getPlayListId()) { - PlayListBO playListInfo = getPlayListInfo(id, apiConfig.getCookies()); - if (playListInfo.getCode() != 200) { - log.info("playList get err"); - return; - } - PlayListBO.ResultDTO playList = playListInfo.getResult(); - PlayListBO.ResultDTO.CreatorDTO creator = playList.getCreator(); - NeteaseMusicUser playListUser = NeteaseMusicUser.builder() - .thirdId(creator.getUserId().longValue()) - .avatarUrl(creator.getAvatarUrl()) - .city(creator.getCity()) - .birthday(creator.getBirthday()) - .nickname(creator.getNickname()) - .backgroundImg(creator.getBackgroundUrl()).build(); - Integer playUserId = userService.saveOrUpdateByThirdId(playListUser); - NeteaseMusicPlaylist musicPlaylist = NeteaseMusicPlaylist.builder() - .thirdId(playList.getId()) - .userId(String.valueOf(playUserId)) - .name(playList.getName()) - .description(String.valueOf(playList.getDescription())) - .createTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(playList.getCreateTime()), ZoneId.systemDefault())) - .updateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(playList.getUpdateTime()), ZoneId.systemDefault())).build(); - playlistService.saveIsExist(musicPlaylist); - List tracks = playList.getTracks(); - if (tracks == null || tracks.isEmpty()) { - return; + PlayListBO playListInfo = getPlayListInfo(apiConfig.getPlayListId(), apiConfig.getCookies()); + if (playListInfo.getCode() != 200) { + log.info("playList get err"); + return; + } + PlayListBO.ResultDTO playList = playListInfo.getResult(); + PlayListBO.ResultDTO.CreatorDTO creator = playList.getCreator(); + NeteaseMusicUser playListUser = NeteaseMusicUser.builder() + .thirdId(creator.getUserId().longValue()) + .avatarUrl(creator.getAvatarUrl()) + .city(creator.getCity()) + .birthday(creator.getBirthday()) + .nickname(creator.getNickname()) + .backgroundImg(creator.getBackgroundUrl()).build(); + Integer playUserId = userService.saveOrUpdateByThirdId(playListUser); + NeteaseMusicPlaylist musicPlaylist = NeteaseMusicPlaylist.builder() + .thirdId(playList.getId()) + .userId(String.valueOf(playUserId)) + .name(playList.getName()) + .description(String.valueOf(playList.getDescription())) + .createTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(playList.getCreateTime()), ZoneId.systemDefault())) + .updateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(playList.getUpdateTime()), ZoneId.systemDefault())).build(); + playlistService.saveIsExist(musicPlaylist); + List tracks = playList.getTracks(); + if (tracks == null || tracks.isEmpty()) { + return; + } + Integer trackCount = playList.getTrackCount(); + log.info("test, trackCount: {}, tracksSize: {}", trackCount, tracks.size()); + List songs = new ArrayList<>(tracks.size()); + for (PlayListBO.ResultDTO.TracksDTO track : tracks) { + PlayListBO.ResultDTO.TracksDTO.AlbumDTO album = track.getAlbum(); + NeteaseMusicAlbum musicAlbum = NeteaseMusicAlbum.builder() + .thirdId(album.getId().longValue()) + .name(album.getName()) + .picUrl(album.getPicUrl()) + .type(album.getType()) + .publishTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(album.getPublishTime()), ZoneId.systemDefault())).build(); + NeteaseMusicAlbum dbAlbum = albumService.getOne(new LambdaQueryWrapper() + .eq(NeteaseMusicAlbum::getThirdId, musicAlbum.getThirdId())); + if (dbAlbum == null) { + albumService.save(musicAlbum); } - Integer trackCount = playList.getTrackCount(); - log.info("test, trackCount: {}, tracksSize: {}", trackCount, tracks.size()); - List songs = new ArrayList<>(tracks.size()); - for (PlayListBO.ResultDTO.TracksDTO track : tracks) { - PlayListBO.ResultDTO.TracksDTO.AlbumDTO album = track.getAlbum(); - NeteaseMusicAlbum musicAlbum = NeteaseMusicAlbum.builder() - .thirdId(album.getId().longValue()) - .name(album.getName()) - .picUrl(album.getPicUrl()) - .type(album.getType()) - .publishTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(album.getPublishTime()), ZoneId.systemDefault())).build(); - NeteaseMusicAlbum dbAlbum = albumService.getOne(new LambdaQueryWrapper() - .eq(NeteaseMusicAlbum::getThirdId, musicAlbum.getThirdId())); - if (dbAlbum == null) { - albumService.save(musicAlbum); - } - List artists = track.getArtists(); - List musicUserList = new ArrayList<>(artists.size()); - for (PlayListBO.ResultDTO.TracksDTO.ArtistsDTO artist : artists) { - NeteaseMusicUser musicUser = NeteaseMusicUser.builder() - .thirdId(artist.getId().longValue()) - .nickname(artist.getName()) - .backgroundImg(artist.getPicUrl()) - .build(); - musicUserList.add(musicUser); - } - NeteaseMusicSong song = NeteaseMusicSong.builder() - .name(track.getName()) - .thirdId(Long.valueOf(track.getId())) - .albumId(musicAlbum.getId()) - .artists(musicUserList) + List artists = track.getArtists(); + List musicUserList = new ArrayList<>(artists.size()); + for (PlayListBO.ResultDTO.TracksDTO.ArtistsDTO artist : artists) { + NeteaseMusicUser musicUser = NeteaseMusicUser.builder() + .thirdId(artist.getId().longValue()) + .nickname(artist.getName()) + .backgroundImg(artist.getPicUrl()) .build(); - songs.add(song); - } - songService.saveBatchAndChild(songs); - - - try { - TimeUnit.MINUTES.sleep(5); - } catch (InterruptedException e) { - throw new RuntimeException(e); + musicUserList.add(musicUser); } + NeteaseMusicSong song = NeteaseMusicSong.builder() + .name(track.getName()) + .thirdId(Long.valueOf(track.getId())) + .albumId(musicAlbum.getId()) + .artists(musicUserList) + .build(); + songs.add(song); + } + songService.saveBatchAndChild(songs); + try { + TimeUnit.MINUTES.sleep(5); + } catch (InterruptedException e) { + throw new RuntimeException(e); } } } diff --git a/src/main/resources/META-INF/spring.components b/src/main/resources/META-INF/spring.components index f9a7e31..9ab5376 100644 --- a/src/main/resources/META-INF/spring.components +++ b/src/main/resources/META-INF/spring.components @@ -9,7 +9,7 @@ com.bingchunmoli.api.cert.task.UpdateTencentCdnCert=org.springframework.stereoty com.bingchunmoli.api.config.ApiConfig=org.springframework.stereotype.Component,org.springframework.boot.context.properties.ConfigurationProperties com.bingchunmoli.api.config.SystemController=org.springframework.stereotype.Component com.bingchunmoli.api.config.UserController=org.springframework.stereotype.Component -com.bingchunmoli.api.config.UserServiceImpl=org.springframework.stereotype.Component +com.bingchunmoli.api.config.service.impl.UserServiceImpl=org.springframework.stereotype.Component com.bingchunmoli.api.config.redis.RedisConfig=org.springframework.stereotype.Component com.bingchunmoli.api.config.web.WebMvcConfig=org.springframework.stereotype.Component com.bingchunmoli.api.controller.ErrorController=org.springframework.stereotype.Component diff --git a/src/main/resources/init/db/init.sql b/src/main/resources/init/db/init.sql index cccce4c..0f86536 100644 --- a/src/main/resources/init/db/init.sql +++ b/src/main/resources/init/db/init.sql @@ -259,7 +259,7 @@ create table if not exists bili_media create table if not exists bili_user ( - id int not null + id int not null primary key, name varchar(30) null comment '昵称', face varchar(80) null, @@ -268,6 +268,18 @@ create table if not exists bili_user ) row_format = DYNAMIC; +CREATE TABLE if not exists `config` +( + id INT auto_increment not null, + `key` varchar(100) NOT NULL COMMENT '配置的key', + `value` varchar(500) COMMENT '配置的值', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_time` datetime NOT NULL COMMENT '更新时间', + primary key (`id`), + constraint config_uindex + unique (`key`) +); + INSERT INTO yi_yan (id, uuid, hitokoto, type, `from`, from_who, creator, creator_uid, reviewer, commit_from, created_at, length, deleted, create_time, update_time, version) VALUES (1, '9818ecda-9cbf-4f2a-9af8-8136ef39cfcd', '与众不同的生活方式很累人呢,因为找不到借口。', 'a', '幸运星', null, '跳舞的果果', 0, 0, 'web', '1468605909', 22, 0, null, null, null) ON DUPLICATE KEY UPDATE id = id; INSERT INTO yi_yan (id, uuid, hitokoto, type, `from`, from_who, creator, creator_uid, reviewer, commit_from, created_at, length, deleted, create_time, update_time, version) VALUES (2, '4e71bc61-9f2e-49e1-a62f-d4b8ad9716c6', '面对就好,去经历就好。', 'a', '花伞菌', null, 'umbrella', 0, 0, 'web', '1468605909', 11, 0, null, null, null) ON DUPLICATE KEY UPDATE id = id; INSERT INTO yi_yan (id, uuid, hitokoto, type, `from`, from_who, creator, creator_uid, reviewer, commit_from, created_at, length, deleted, create_time, update_time, version) VALUES (3, '8ea19537-2bae-4f64-8296-b8f1eed8006a', '将愿望倾入不愿忘却的回忆中……', 'a', 'ef-a tale of memories', null, 'lqsasa', 0, 0, 'web', '1468605909', 15, 0, null, null, null) ON DUPLICATE KEY UPDATE id = id; diff --git a/src/main/resources/mapper/ConfigMapper.xml b/src/main/resources/mapper/ConfigMapper.xml new file mode 100644 index 0000000..00f34bb --- /dev/null +++ b/src/main/resources/mapper/ConfigMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + id,key,value, + create_time,update_time + + diff --git a/src/main/vue/admin/src/views/MainView.vue b/src/main/vue/admin/src/views/MainView.vue index 539e347..e956573 100644 --- a/src/main/vue/admin/src/views/MainView.vue +++ b/src/main/vue/admin/src/views/MainView.vue @@ -94,6 +94,35 @@ const resetForm = (formEl: FormInstance | undefined) => { if (!formEl) return getSystemConfig() } + +const submitForm = (formEl: FormInstance | undefined) => { + fetch(import.meta.env.VITE_API_BASE_URL + 'system', { + method: 'post', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(form), + }) + .then((r) => { + if (r.status === 200 && r.ok) { + return r.json() as Promise> + } else { + if (r.status === 401) { + if (!flag) { + router.push({path: '/login'}); + } + } + } + }) + .then((res) => { + if (res && res.code === '00000') { + console.log(res.data) + } + }) + .catch((r) => { + console.log(r) + }) +}