移除了不需要的类,添加了简单的日志记录

This commit is contained in:
zayac 2023-09-09 21:21:46 +08:00
parent f7d68b1dab
commit 5846f5f22f
5 changed files with 31 additions and 22 deletions
pom.xml
src/main
java/com/zayac/changeurl
resources

View File

@ -9,9 +9,9 @@
<relativePath/>
</parent>
<groupId>com.zayac</groupId>
<artifactId>changeURL</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>changeURL</name>
<artifactId>changeUrl</artifactId>
<version>0.0.1-2023.9.9</version>
<name>changeUrl</name>
<description>通过http请求修改指定模板内指定关键词的小工具</description>
<properties>
<java.version>17</java.version>

View File

@ -1,6 +1,7 @@
package com.zayac.changeurl.exception;
import com.zayac.changeurl.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ -11,12 +12,14 @@ import static com.zayac.changeurl.enums.ErrorEnum.INTERNAL_SERVER_ERROR;
* @author zayac
* @since 2023-09-09 17:36
*/
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler{
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public <T> Result<T> handleAllException(Exception e) {
log.error(e.getMessage());
return Result.error(INTERNAL_SERVER_ERROR);
}

View File

@ -7,6 +7,8 @@ import com.zayac.changeurl.entity.HthMsgEntity;
import com.zayac.changeurl.entity.HthTemplateEntity;
import com.zayac.changeurl.entity.KyMsgEntity;
import com.zayac.changeurl.entity.KyTemplateEntity;
import com.zayac.changeurl.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -19,14 +21,15 @@ import java.util.List;
* @author zayac
* @since 2023-08-30 12:08
*/
@Slf4j
@Service
public class ChangeUrlServiceImpl implements ChangeUrlService {
private static final String KYJS = "ky.js";
private static final String HTHJS = "hth.js";
private static final String KYJS = "/www/wwwroot/cdn.static.cdcseo.com/js/ky.js";
private static final String HTHJS = "/www/wwwroot/cdn.static.cdcseo.com/js/hth.js";
@Override
public Boolean change(String text) {
log.info(text);
String[] arr = text.split("\n");
//传入text 包含SEO 专用域名 则为开云
@ -43,7 +46,7 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
"kyPc2",
"kyH51",
"kyH52",
"ky.js.template",
"/www/wwwroot/cdn.static.cdcseo.com/template/ky.js.template",
kyTargets);
//读取模板文件
String template = loadTemplate(kyTemplate.getTemplatePath());
@ -58,13 +61,15 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
modifyFile(template, kyTemplate.getTargets());
//读取修改过的文件 校验修改成功失败
String result = FileUtil.readUtf8String(KYJS);
//如果修改后的js文件中
return ReUtil.count(Constant.URL_PATTERN, result) >= 6;
if (ReUtil.count(Constant.URL_PATTERN, result) < 6) {
throw new BizException(500, "开云链接更新失败,请手动检查文件");
}
log.info("开云js更新成功");
} else {
HthMsgEntity hthMsg = new HthMsgEntity(arr);
List<String> hthTargets = new ArrayList<>();
hthTargets.add(HTHJS);
HthTemplateEntity hthTemplate = new HthTemplateEntity("hthApp", "hthtyApp", "hthPc", "hthH5", "hth.js.template", hthTargets);
HthTemplateEntity hthTemplate = new HthTemplateEntity("hthApp", "hthtyApp", "hthPc", "hthH5", "/www/wwwroot/cdn.static.cdcseo.com/template/ky.js.template/hth.js.template", hthTargets);
//读取模板文件
String template = loadTemplate(hthTemplate.getTemplatePath());
template = template
@ -76,9 +81,12 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
//读取修改过的文件 校验修改成功失败
String result = FileUtil.readUtf8String(files.get(0));
//如果修改后的js文件中
return ReUtil.count(Constant.URL_PATTERN, result) >= 4;
if (ReUtil.count(Constant.URL_PATTERN, result) < 4) {
throw new BizException(500, "华体会链接更新失败,请手动检查文件");
}
log.info("华体会js更新成功");
}
return true;
}
/**

View File

@ -1,8 +0,0 @@
package com.zayac.changeurl.util;
/**
* @author zayac
* @since 2023-08-30 13:12
*/
public class util {
}

View File

@ -6,4 +6,10 @@ spring:
caffeine:
spec: maximumSize=100,expireAfterWrite=10m
profiles:
active: "ky"
active: "ky"
logging:
logback:
rollingpolicy:
max-file-size: 10MB
max-history: 10