REQ-2699: 追求workspaceType=2
This commit is contained in:
parent
92fca87f9b
commit
0858ffd8df
@ -0,0 +1,89 @@
|
||||
package cn.axzo.msg.center.message.xxl;
|
||||
|
||||
import cn.axzo.msg.center.dal.MessageRouteDetailDao;
|
||||
import cn.axzo.msg.center.dal.MessageRouterConfigDao;
|
||||
import cn.axzo.msg.center.domain.entity.MessageRouteDetail;
|
||||
import cn.axzo.msg.center.domain.entity.MessageRouterConfig;
|
||||
import cn.axzo.msg.center.service.enums.TerminalTypeEnum;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AppendWorkspaceTypeJob extends IJobHandler {
|
||||
|
||||
private final MessageRouteDetailDao messageRouteDetailDao;
|
||||
private final MessageRouterConfigDao messageRouterConfigDao;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@XxlJob("appendWorkspaceTypeJob")
|
||||
public ReturnT<String> execute(String param) throws Exception {
|
||||
List<MessageRouteDetail> details;
|
||||
if (StringUtils.isBlank(param)) {
|
||||
details = messageRouteDetailDao.list();
|
||||
} else {
|
||||
List<String> templateCodes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(param);
|
||||
details = messageRouteDetailDao.lambdaQuery()
|
||||
.in(MessageRouteDetail::getTemplateCode, templateCodes)
|
||||
.list();
|
||||
}
|
||||
for (MessageRouteDetail detail : details) {
|
||||
List<MessageRouterConfig> configs = messageRouterConfigDao.lambdaQuery()
|
||||
.in(MessageRouterConfig::getTerminalType, Arrays.asList(
|
||||
TerminalTypeEnum.ANDROID, TerminalTypeEnum.IOS,
|
||||
TerminalTypeEnum.MINI_PROGRAM, TerminalTypeEnum.WEB_VIEW))
|
||||
.eq(MessageRouterConfig::getRouterCode, detail.getTemplateCode())
|
||||
.list();
|
||||
for (MessageRouterConfig config : configs) {
|
||||
maybeAppendWorkspaceType(config);
|
||||
}
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
private void maybeAppendWorkspaceType(MessageRouterConfig config) throws Exception {
|
||||
if (StringUtils.isBlank(config.getUrl()))
|
||||
return;
|
||||
String url = config.getUrl();
|
||||
int idx1 = url.indexOf("?");
|
||||
int idx2 = url.indexOf("workspaceType=");
|
||||
if (idx2 > -1 && idx2 > idx1) return;
|
||||
if (idx1 > -1) {
|
||||
if (url.endsWith("&")) {
|
||||
url += "workspaceType=2";
|
||||
} else {
|
||||
if (idx1 == url.length() - 1) {
|
||||
url += "workspaceType=2";
|
||||
} else {
|
||||
url += "&workspaceType=2";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (url.endsWith("?")) {
|
||||
url += "workspaceType=2";
|
||||
} else {
|
||||
url += "?workspaceType=2";
|
||||
}
|
||||
}
|
||||
messageRouterConfigDao.lambdaUpdate()
|
||||
.eq(MessageRouterConfig::getId, config.getId())
|
||||
.set(MessageRouterConfig::getUrl, url)
|
||||
.update();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.axzo.msg.center.message.xxl;
|
||||
|
||||
import cn.axzo.msg.center.MsgCenterApplication;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Commit;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@SpringBootTest(classes = MsgCenterApplication.class)
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
class AppendWorkspaceTypeJobTest {
|
||||
|
||||
private final AppendWorkspaceTypeJob appendWorkspaceTypeJob;
|
||||
|
||||
@Test @Commit @Transactional
|
||||
void exec() throws Exception {
|
||||
appendWorkspaceTypeJob.execute("b52da221bff04b47ab0260ed375a44xx");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user