refactor: optimzie direct comma

This commit is contained in:
tjq 2021-06-20 13:57:02 +08:00
parent 559ce20bf4
commit b4270dac4f
6 changed files with 15 additions and 10 deletions

View File

@ -17,6 +17,7 @@ public class OmsConstant {
public static final String NONE = "N/A"; public static final String NONE = "N/A";
public static final String COMMA = ","; public static final String COMMA = ",";
public static final String MINUS = "-";
public static final String LINE_SEPARATOR = "\r\n"; public static final String LINE_SEPARATOR = "\r\n";
public static final String HTTP_HEADER_CONTENT_TYPE = "Content-Type"; public static final String HTTP_HEADER_CONTENT_TYPE = "Content-Type";

View File

@ -2,6 +2,7 @@ package tech.powerjob.server.common;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import tech.powerjob.common.OmsConstant;
/** /**
* Splitter & Joiner * Splitter & Joiner
@ -11,7 +12,7 @@ import com.google.common.base.Splitter;
*/ */
public class SJ { public class SJ {
public static final Splitter COMMA_SPLITTER = Splitter.on(","); public static final Splitter COMMA_SPLITTER = Splitter.on(OmsConstant.COMMA);
public static final Joiner COMMA_JOINER = Joiner.on(","); public static final Joiner COMMA_JOINER = Joiner.on(OmsConstant.COMMA);
} }

View File

@ -2,6 +2,7 @@ package tech.powerjob.server.common.utils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import tech.powerjob.common.OmsConstant;
import tech.powerjob.common.RemoteConstant; import tech.powerjob.common.RemoteConstant;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -48,9 +49,9 @@ public class TimeUtils {
// 只保留结束时间在当前时间前的生命周期 // 只保留结束时间在当前时间前的生命周期
lifeCycle.forEach(range -> { lifeCycle.forEach(range -> {
String[] split = range.split("-"); String[] split = range.split(OmsConstant.MINUS);
long end = Long.parseLong(split[1]); long end = Long.parseLong(split[1]);
if (end < startTime) { if (end <= startTime) {
return; return;
} }
remainingLifecycle.add(Pair.of(Long.valueOf(split[0]), end)); remainingLifecycle.add(Pair.of(Long.valueOf(split[0]), end));

View File

@ -1,11 +1,11 @@
package tech.powerjob.server.core.service; package tech.powerjob.server.core.service;
import tech.powerjob.server.persistence.remote.model.UserInfoDO;
import tech.powerjob.server.persistence.remote.repository.UserInfoRepository;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import tech.powerjob.server.common.SJ;
import tech.powerjob.server.persistence.remote.model.UserInfoDO;
import tech.powerjob.server.persistence.remote.repository.UserInfoRepository;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
@ -45,7 +45,7 @@ public class UserService {
return Lists.newLinkedList(); return Lists.newLinkedList();
} }
// 去重 // 去重
Set<Long> userIdList = Splitter.on(",").splitToList(userIds).stream().map(Long::valueOf).collect(Collectors.toSet()); Set<Long> userIdList = SJ.COMMA_SPLITTER.splitToList(userIds).stream().map(Long::valueOf).collect(Collectors.toSet());
List<UserInfoDO> res = userInfoRepository.findByIdIn(Lists.newLinkedList(userIdList)); List<UserInfoDO> res = userInfoRepository.findByIdIn(Lists.newLinkedList(userIdList));
res.forEach(x -> x.setPassword(null)); res.forEach(x -> x.setPassword(null));
return res; return res;

View File

@ -1,5 +1,6 @@
package tech.powerjob.agent; package tech.powerjob.agent;
import tech.powerjob.common.OmsConstant;
import tech.powerjob.common.RemoteConstant; import tech.powerjob.common.RemoteConstant;
import tech.powerjob.worker.PowerJobWorker; import tech.powerjob.worker.PowerJobWorker;
import tech.powerjob.worker.common.PowerJobWorkerConfig; import tech.powerjob.worker.common.PowerJobWorkerConfig;
@ -52,7 +53,7 @@ public class MainApplication implements Runnable {
cfg.setAppName(appName); cfg.setAppName(appName);
cfg.setPort(port); cfg.setPort(port);
cfg.setServerAddress(Splitter.on(",").splitToList(server)); cfg.setServerAddress(Splitter.on(OmsConstant.COMMA).splitToList(server));
cfg.setStoreStrategy(StoreStrategy.MEMORY.name().equals(storeStrategy) ? StoreStrategy.MEMORY : StoreStrategy.DISK); cfg.setStoreStrategy(StoreStrategy.MEMORY.name().equals(storeStrategy) ? StoreStrategy.MEMORY : StoreStrategy.DISK);
cfg.setMaxResultLength(length); cfg.setMaxResultLength(length);
cfg.setTag(tag); cfg.setTag(tag);

View File

@ -1,5 +1,6 @@
package tech.powerjob.worker.autoconfigure; package tech.powerjob.worker.autoconfigure;
import tech.powerjob.common.OmsConstant;
import tech.powerjob.common.utils.CommonUtils; import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.common.utils.NetUtils; import tech.powerjob.common.utils.NetUtils;
import tech.powerjob.worker.PowerJobWorker; import tech.powerjob.worker.PowerJobWorker;
@ -37,7 +38,7 @@ public class PowerJobAutoConfiguration {
* any prefix, i.e. http://. * any prefix, i.e. http://.
*/ */
CommonUtils.requireNonNull(worker.getServerAddress(), "serverAddress can't be empty!"); CommonUtils.requireNonNull(worker.getServerAddress(), "serverAddress can't be empty!");
List<String> serverAddress = Arrays.asList(worker.getServerAddress().split(",")); List<String> serverAddress = Arrays.asList(worker.getServerAddress().split(OmsConstant.COMMA));
/* /*
* Create OhMyConfig object for setting properties. * Create OhMyConfig object for setting properties.