优化代码
This commit is contained in:
parent
ce50a07e93
commit
82ef0063f7
|
|
@ -18,7 +18,6 @@ import com.electromagnetic.industry.software.common.enums.*;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
|
|
@ -31,6 +30,7 @@ import com.electromagnetic.industry.software.manage.service.FileFormatService;
|
||||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -43,12 +43,12 @@ import java.util.stream.Collectors;
|
||||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class CommonService {
|
public class CommonService {
|
||||||
|
|
||||||
private static final Map<Integer, String> PATH_MAP = new HashMap<>();
|
private static final Map<Integer, String> PATH_MAP = new HashMap<>();
|
||||||
|
|
||||||
private final EleLog log = new EleLog(CommonService.class);
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ElePropertyConfig elePropertyConfig;
|
private ElePropertyConfig elePropertyConfig;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.*;
|
import com.electromagnetic.industry.software.manage.service.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
@ -61,10 +62,10 @@ import static com.electromagnetic.industry.software.common.cons.ElectromagneticC
|
||||||
import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE;
|
import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE;
|
||||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||||
|
|
||||||
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
|
||||||
@Resource
|
@Resource
|
||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
@Resource
|
@Resource
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import com.electromagnetic.industry.software.common.enums.*;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
|
|
@ -25,6 +24,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
||||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -33,11 +33,10 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
||||||
|
|
||||||
private final EleLog log = new EleLog(EdPrjServiceImpl.class);
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileSystemService fileSystemService;
|
private FileSystemService fileSystemService;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.parse.*;
|
import com.electromagnetic.industry.software.common.parse.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -17,6 +18,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public final class EleCommonUtil {
|
public final class EleCommonUtil {
|
||||||
|
|
||||||
private static final Map<String, FileParse> PARSE_MAP = new HashMap<>();
|
private static final Map<String, FileParse> PARSE_MAP = new HashMap<>();
|
||||||
|
|
@ -24,8 +26,7 @@ public final class EleCommonUtil {
|
||||||
private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$";
|
private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$";
|
||||||
private static final String TIME_FORMAT1 = "yyMMddHHmmssSSS";
|
private static final String TIME_FORMAT1 = "yyMMddHHmmssSSS";
|
||||||
// 编译正则表达式
|
// 编译正则表达式
|
||||||
private static final Pattern pattern = Pattern.compile(PATTERN);
|
private static final Pattern NAME_PATTERN = Pattern.compile(PATTERN);
|
||||||
private static final EleLog log = new EleLog(EleCommonUtil.class);
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PARSE_MAP.put("doc", new WordParse());
|
PARSE_MAP.put("doc", new WordParse());
|
||||||
|
|
@ -51,7 +52,7 @@ public final class EleCommonUtil {
|
||||||
if (StrUtil.isEmpty(fileFullName) || fileFullName.length() > 32) {
|
if (StrUtil.isEmpty(fileFullName) || fileFullName.length() > 32) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return pattern.matcher(fileFullName).matches();
|
return NAME_PATTERN.matcher(fileFullName).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNowTimeStr() {
|
public static String getNowTimeStr() {
|
||||||
|
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.common.util;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class EleLog {
|
|
||||||
|
|
||||||
private static final String PLACE_HOLDER = "{}";
|
|
||||||
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
public EleLog(Class clazz) {
|
|
||||||
this.logger = LoggerFactory.getLogger(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String format(String strPattern, Object... argArray) {
|
|
||||||
if (!StrUtil.isBlank(strPattern) && !StrUtil.isBlank(PLACE_HOLDER) && !ArrayUtil.isEmpty(argArray)) {
|
|
||||||
int strPatternLength = strPattern.length();
|
|
||||||
int placeHolderLength = PLACE_HOLDER.length();
|
|
||||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
|
||||||
int handledPosition = 0;
|
|
||||||
|
|
||||||
for (int argIndex = 0; argIndex < argArray.length; ++argIndex) {
|
|
||||||
int delimIndex = strPattern.indexOf(PLACE_HOLDER, handledPosition);
|
|
||||||
if (delimIndex == -1) {
|
|
||||||
if (handledPosition == 0) {
|
|
||||||
return strPattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
|
||||||
return sbuf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == '\\') {
|
|
||||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == '\\') {
|
|
||||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
|
||||||
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
|
||||||
handledPosition = delimIndex + placeHolderLength;
|
|
||||||
} else {
|
|
||||||
--argIndex;
|
|
||||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
|
||||||
sbuf.append(PLACE_HOLDER.charAt(0));
|
|
||||||
handledPosition = delimIndex + 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sbuf.append(strPattern, handledPosition, delimIndex);
|
|
||||||
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
|
||||||
handledPosition = delimIndex + placeHolderLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
|
||||||
return sbuf.toString();
|
|
||||||
} else {
|
|
||||||
return strPattern;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void info(String msg, Object... args) {
|
|
||||||
logger.info(format(msg, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void debug(String msg, Object... args) {
|
|
||||||
logger.debug(format(msg, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void warn(String msg, Object... args) {
|
|
||||||
logger.warn(format(msg, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String msg, Object... args) {
|
|
||||||
logger.error(format(msg, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String msg, Throwable e, Object... args) {
|
|
||||||
String info = format(msg, args);
|
|
||||||
logger.error(info, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue