1
This commit is contained in:
+126
-125
@@ -1,125 +1,126 @@
|
|||||||
package com.ruoyi.jarvis.service.impl;␍
|
package com.ruoyi.jarvis.service.impl;
|
||||||
␍
|
|
||||||
import com.ruoyi.jarvis.domain.WeComInboundTrace;␍
|
import com.ruoyi.jarvis.domain.WeComInboundTrace;
|
||||||
import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob;␍
|
import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob;
|
||||||
import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper;␍
|
import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper;
|
||||||
import com.ruoyi.jarvis.mapper.WeComShareLinkLogisticsJobMapper;␍
|
import com.ruoyi.jarvis.mapper.WeComShareLinkLogisticsJobMapper;
|
||||||
import com.ruoyi.jarvis.service.IWeComShareLinkLogisticsJobService;␍
|
import com.ruoyi.jarvis.service.IWeComShareLinkLogisticsJobService;
|
||||||
import org.slf4j.Logger;␍
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;␍
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;␍
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;␍
|
import org.springframework.util.StringUtils;
|
||||||
␍
|
|
||||||
import javax.annotation.Resource;␍
|
import javax.annotation.Resource;
|
||||||
import java.util.LinkedHashMap;␍
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;␍
|
import java.util.List;
|
||||||
import java.util.Map;␍
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;␍
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;␍
|
import java.util.regex.Pattern;
|
||||||
␍
|
|
||||||
@Service␍
|
@Service
|
||||||
public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLogisticsJobService {␍
|
public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLogisticsJobService {
|
||||||
␍
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(WeComShareLinkLogisticsJobServiceImpl.class);␍
|
private static final Logger log = LoggerFactory.getLogger(WeComShareLinkLogisticsJobServiceImpl.class);
|
||||||
␍
|
|
||||||
/** 与 WeComInboundServiceImpl.replyLogisticsRemarkDone 中文案一致 */␍
|
/** 与 WeComInboundServiceImpl.replyLogisticsRemarkDone 中文案一致 */
|
||||||
private static final String REPLY_MARK_SHARE_LINK_DONE = "已加入查询队列";␍
|
private static final String REPLY_MARK_SHARE_LINK_DONE = "已加入查询队列";
|
||||||
␍
|
|
||||||
private static final Pattern JD_3CN_HTTPS = Pattern.compile("https://3\\.cn/[A-Za-z0-9\\-]+");␍
|
private static final Pattern JD_3CN_HTTPS = Pattern.compile("https://3\\.cn/[A-Za-z0-9\\-]+");
|
||||||
private static final Pattern JD_3CN_HTTP = Pattern.compile("http://3\\.cn/[A-Za-z0-9\\-]+");␍
|
private static final Pattern JD_3CN_HTTP = Pattern.compile("http://3\\.cn/[A-Za-z0-9\\-]+");
|
||||||
␍
|
|
||||||
@Resource␍
|
@Resource
|
||||||
private WeComShareLinkLogisticsJobMapper weComShareLinkLogisticsJobMapper;␍
|
private WeComShareLinkLogisticsJobMapper weComShareLinkLogisticsJobMapper;
|
||||||
@Resource␍
|
@Resource
|
||||||
private WeComInboundTraceMapper weComInboundTraceMapper;␍
|
private WeComInboundTraceMapper weComInboundTraceMapper;
|
||||||
␍
|
|
||||||
@Override␍
|
@Override
|
||||||
public WeComShareLinkLogisticsJob selectByJobKey(String jobKey) {␍
|
public WeComShareLinkLogisticsJob selectByJobKey(String jobKey) {
|
||||||
return weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey);␍
|
return weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey);
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
@Override␍
|
@Override
|
||||||
public List<WeComShareLinkLogisticsJob> selectList(WeComShareLinkLogisticsJob query) {␍
|
public List<WeComShareLinkLogisticsJob> selectList(WeComShareLinkLogisticsJob query) {
|
||||||
return weComShareLinkLogisticsJobMapper.selectWeComShareLinkLogisticsJobList(query);␍
|
return weComShareLinkLogisticsJobMapper.selectWeComShareLinkLogisticsJobList(query);
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
@Override␍
|
@Override
|
||||||
public Map<String, Object> backfillImportedFromInboundTrace() {␍
|
public Map<String, Object> backfillImportedFromInboundTrace() {
|
||||||
int imported = 0;␍
|
int imported = 0;
|
||||||
int skippedDuplicate = 0;␍
|
int skippedDuplicate = 0;
|
||||||
int skippedNoUrl = 0;␍
|
int skippedNoUrl = 0;
|
||||||
int scanned = 0;␍
|
int scanned = 0;
|
||||||
␍
|
|
||||||
List<WeComInboundTrace> traces = weComInboundTraceMapper.selectTracesShareLinkRemarkDone(REPLY_MARK_SHARE_LINK_DONE);␍
|
List<WeComInboundTrace> traces = weComInboundTraceMapper.selectTracesShareLinkRemarkDone(REPLY_MARK_SHARE_LINK_DONE);
|
||||||
if (traces != null) {␍
|
if (traces != null) {
|
||||||
for (WeComInboundTrace t : traces) {␍
|
for (WeComInboundTrace t : traces) {
|
||||||
if (t == null || t.getId() == null || !StringUtils.hasText(t.getFromUserName())) {␍
|
if (t == null || t.getId() == null || !StringUtils.hasText(t.getFromUserName())) {
|
||||||
continue;␍
|
continue;
|
||||||
}␍
|
}
|
||||||
scanned++;␍
|
scanned++;
|
||||||
String jobKey = "tracebf" + t.getId();␍
|
String jobKey = "tracebf" + t.getId();
|
||||||
if (weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey) != null) {␍
|
if (weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey) != null) {
|
||||||
skippedDuplicate++;␍
|
skippedDuplicate++;
|
||||||
continue;␍
|
continue;
|
||||||
}␍
|
}
|
||||||
String url = extractJd3cnUrl(t.getContent());␍
|
String url = extractJd3cnUrl(t.getContent());
|
||||||
if (url == null) {␍
|
if (url == null) {
|
||||||
WeComInboundTrace prior = weComInboundTraceMapper.selectLatestPriorTraceWith3cnLink(␍
|
WeComInboundTrace prior = weComInboundTraceMapper.selectLatestPriorTraceWith3cnLink(
|
||||||
t.getFromUserName(), t.getId());␍
|
t.getFromUserName(), t.getId());
|
||||||
if (prior != null) {␍
|
if (prior != null) {
|
||||||
url = extractJd3cnUrl(prior.getContent());␍
|
url = extractJd3cnUrl(prior.getContent());
|
||||||
}␍
|
}
|
||||||
}␍
|
}
|
||||||
if (!StringUtils.hasText(url)) {␍
|
if (!StringUtils.hasText(url)) {
|
||||||
skippedNoUrl++;␍
|
skippedNoUrl++;
|
||||||
log.debug("补录跳过 traceId={} 无可用 3.cn", t.getId());␍
|
log.debug("补录跳过 traceId={} 无可用 3.cn", t.getId());
|
||||||
continue;␍
|
continue;
|
||||||
}␍
|
}
|
||||||
␍
|
final String trackingUrlResolved = url.trim();
|
||||||
WeComShareLinkLogisticsJob row = new WeComShareLinkLogisticsJob();␍
|
|
||||||
row.setJobKey(jobKey);␍
|
WeComShareLinkLogisticsJob row = new WeComShareLinkLogisticsJob();
|
||||||
row.setFromUserName(t.getFromUserName().trim());␍
|
row.setJobKey(jobKey);
|
||||||
row.setTrackingUrl(url.trim());␍
|
row.setFromUserName(t.getFromUserName().trim());
|
||||||
String remark = t.getContent() != null ? t.getContent() : "";␍
|
row.setTrackingUrl(trackingUrlResolved);
|
||||||
row.setUserRemark(remark);␍
|
String remark = t.getContent() != null ? t.getContent() : "";
|
||||||
row.setTouserPush(t.getFromUserName().trim());␍
|
row.setUserRemark(remark);
|
||||||
row.setStatus("IMPORTED");␍
|
row.setTouserPush(t.getFromUserName().trim());
|
||||||
row.setScanAttempts(0);␍
|
row.setStatus("IMPORTED");
|
||||||
row.setLastNote("from_trace_id=" + t.getId());␍
|
row.setScanAttempts(0);
|
||||||
if (t.getCreateTime() != null) {␍
|
row.setLastNote("from_trace_id=" + t.getId());
|
||||||
row.setCreateTime(t.getCreateTime());␍
|
if (t.getCreateTime() != null) {
|
||||||
row.setUpdateTime(t.getCreateTime());␍
|
row.setCreateTime(t.getCreateTime());
|
||||||
}␍
|
row.setUpdateTime(t.getCreateTime());
|
||||||
try {␍
|
}
|
||||||
weComShareLinkLogisticsJobMapper.insertWeComShareLinkLogisticsJob(row);␍
|
try {
|
||||||
imported++;␍
|
weComShareLinkLogisticsJobMapper.insertWeComShareLinkLogisticsJob(row);
|
||||||
} catch (Exception e) {␍
|
imported++;
|
||||||
log.warn("补录插入失败 traceId={} err={}", t.getId(), e.toString());␍
|
} catch (Exception e) {
|
||||||
}␍
|
log.warn("补录插入失败 traceId={} err={}", t.getId(), e.toString());
|
||||||
}␍
|
}
|
||||||
}␍
|
}
|
||||||
␍
|
}
|
||||||
Map<String, Object> r = new LinkedHashMap<>();␍
|
|
||||||
r.put("scannedRemarkDoneRows", scanned);␍
|
Map<String, Object> r = new LinkedHashMap<>();
|
||||||
r.put("imported", imported);␍
|
r.put("scannedRemarkDoneRows", scanned);
|
||||||
r.put("skippedDuplicate", skippedDuplicate);␍
|
r.put("imported", imported);
|
||||||
r.put("skippedNoUrl", skippedNoUrl);␍
|
r.put("skippedDuplicate", skippedDuplicate);
|
||||||
r.put("hint", "IMPORTED 表示仅从企微消息追踪补录,运单与是否已推送以当时为准,可与 trace_id 对照 wecom_inbound_trace");␍
|
r.put("skippedNoUrl", skippedNoUrl);
|
||||||
return r;␍
|
r.put("hint", "IMPORTED 表示仅从企微消息追踪补录,运单与是否已推送以当时为准,可与 trace_id 对照 wecom_inbound_trace");
|
||||||
}␍
|
return r;
|
||||||
␍
|
}
|
||||||
private static String extractJd3cnUrl(String text) {␍
|
|
||||||
if (!StringUtils.hasText(text)) {␍
|
private static String extractJd3cnUrl(String text) {
|
||||||
return null;␍
|
if (!StringUtils.hasText(text)) {
|
||||||
}␍
|
return null;
|
||||||
Matcher m = JD_3CN_HTTPS.matcher(text);␍
|
}
|
||||||
if (m.find()) {␍
|
Matcher m = JD_3CN_HTTPS.matcher(text);
|
||||||
return m.group();␍
|
if (m.find()) {
|
||||||
}␍
|
return m.group();
|
||||||
Matcher m2 = JD_3CN_HTTP.matcher(text);␍
|
}
|
||||||
if (m2.find()) {␍
|
Matcher m2 = JD_3CN_HTTP.matcher(text);
|
||||||
return m2.group();␍
|
if (m2.find()) {
|
||||||
}␍
|
return m2.group();
|
||||||
return null;␍
|
}
|
||||||
}␍
|
return null;
|
||||||
}␍
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user