|
|
@@ -27,6 +27,9 @@ import com.fs.qw.vo.QwUserVO;
|
|
|
import com.fs.qwApi.domain.QwExternalContactRemarkResult;
|
|
|
import com.fs.qwApi.param.QwExternalContactRemarkParam;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
+import com.fs.sop.domain.SopUserLogsInfo;
|
|
|
+import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
+import com.fs.sop.vo.SopUserLogsInfoVOE;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -36,6 +39,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.regex.Matcher;
|
|
|
@@ -78,6 +82,9 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
@Autowired
|
|
|
private OpenIMService openIMService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SopUserLogsInfoMapper sopUserLogsInfoMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询完课模板
|
|
|
*
|
|
|
@@ -242,6 +249,20 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
}
|
|
|
|
|
|
int isSendMsg = qwUserByRedisForId.getIsSendMsg();
|
|
|
+ log.info("完课备注-员工配置信息: qwUserId={}, isSendMsg={}, 客户ID={}",
|
|
|
+ watchLog.getQwUserId(), isSendMsg, qwExternalContactId);
|
|
|
+
|
|
|
+ // isSendMsg = 6 时,计算营期天数
|
|
|
+ Integer campDays = null;
|
|
|
+ if (isSendMsg == 6) {
|
|
|
+ log.info("【isSendMsg=6】开始计算营期天数,客户ID: {}", qwExternalContactId);
|
|
|
+ campDays = calculateCampDays(qwExternalContactId);
|
|
|
+ if (campDays == null) {
|
|
|
+ log.error("【isSendMsg=6】无法获取营期天数,客户ID: {},跳过处理", qwExternalContactId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("【isSendMsg=6】计算营期天数成功: {}", campDays);
|
|
|
+ }
|
|
|
|
|
|
QwExternalContact externalContact = iQwExternalContactService.selectQwExternalContactByRemark(qwExternalContactId);
|
|
|
|
|
|
@@ -258,23 +279,32 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
|
|
|
// 2. 提取所有旧标记(无论类型)
|
|
|
List<String> allOldMarks = new ArrayList<>();
|
|
|
- Pattern markPattern = Pattern.compile("\\*(\\d{1,4})完");
|
|
|
- Matcher markMatcher = markPattern.matcher(oldRemark);
|
|
|
- while (markMatcher.find()) {
|
|
|
- allOldMarks.add(markMatcher.group());
|
|
|
- }
|
|
|
|
|
|
// 3. 检查是否需要更新
|
|
|
boolean shouldUpdate = true;
|
|
|
|
|
|
- for (String mark : allOldMarks) {
|
|
|
-
|
|
|
- String normalizedOldMark = normalizeMarkFormat(mark);
|
|
|
- // 直接比较字符串是否相等
|
|
|
- if (normalizedOldMark.equals(newNotes) ||
|
|
|
- normalizedOldMark.equals(newNotesDay)) {
|
|
|
+ if (isSendMsg == 6) {
|
|
|
+ // 检查是否已有相同的"*第N课 MMDD完"标记
|
|
|
+ String expectedMark = "*第" + campDays + "课 " + monthDay + "完";
|
|
|
+ if (oldRemark.contains(expectedMark)) {
|
|
|
shouldUpdate = false;
|
|
|
- break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 原有逻辑:检查其他类型的标记
|
|
|
+ Pattern markPattern = Pattern.compile("\\*(\\d{1,4})完");
|
|
|
+ Matcher markMatcher = markPattern.matcher(oldRemark);
|
|
|
+ while (markMatcher.find()) {
|
|
|
+ allOldMarks.add(markMatcher.group());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String mark : allOldMarks) {
|
|
|
+ String normalizedOldMark = normalizeMarkFormat(mark);
|
|
|
+ // 直接比较字符串是否相等
|
|
|
+ if (normalizedOldMark.equals(newNotes) ||
|
|
|
+ normalizedOldMark.equals(newNotesDay)) {
|
|
|
+ shouldUpdate = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -283,10 +313,22 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
}
|
|
|
|
|
|
// 根据 isSendMsg 决定标记格式
|
|
|
- String markToAdd = (isSendMsg == 3 || isSendMsg == 4) ? newNotesDay : newNotes;
|
|
|
+ String markToAdd;
|
|
|
+ if (isSendMsg == 6) {
|
|
|
+ // isSendMsg = 6: 客户名*第N课 MMDD完
|
|
|
+ markToAdd = "*第" + campDays + "课 " + monthDay + "完";
|
|
|
+ } else {
|
|
|
+ markToAdd = (isSendMsg == 3 || isSendMsg == 4) ? newNotesDay : newNotes;
|
|
|
+ }
|
|
|
|
|
|
// 先移除现有标记
|
|
|
- String remarkWithoutMark = oldRemark.replaceAll("\\*\\d{2,4}完", "").trim();
|
|
|
+ String remarkWithoutMark;
|
|
|
+ if (isSendMsg == 6) {
|
|
|
+ // 移除 "*第N课 MMDD完" 格式的标记
|
|
|
+ remarkWithoutMark = oldRemark.replaceAll("\\*第\\d+课 \\d{4}完", "").trim();
|
|
|
+ } else {
|
|
|
+ remarkWithoutMark = oldRemark.replaceAll("\\*\\d{2,4}完", "").trim();
|
|
|
+ }
|
|
|
|
|
|
// 添加新标记(考虑长度限制)
|
|
|
int keepLength = 20 - markToAdd.length();
|
|
|
@@ -296,7 +338,7 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
// 添加到前面
|
|
|
newRemark = markToAdd + (remarkWithoutMark.length() > keepLength ?
|
|
|
remarkWithoutMark.substring(0, keepLength) : remarkWithoutMark);
|
|
|
- } else { // isSendMsg == 2 或 4
|
|
|
+ } else { // isSendMsg == 2 或 4 或 6
|
|
|
// 添加到后面
|
|
|
newRemark = (remarkWithoutMark.length() > keepLength ?
|
|
|
remarkWithoutMark.substring(0, keepLength) : remarkWithoutMark) + markToAdd;
|
|
|
@@ -534,4 +576,47 @@ public class FsCourseFinishTempServiceImpl implements IFsCourseFinishTempService
|
|
|
public int updateFsCourseFinishTempBatch(FsCourseFinishTemp fsCourseFinishTemp){
|
|
|
return fsCourseFinishTempMapper.updateFsCourseFinishTempBatch(fsCourseFinishTemp);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算营期天数(从SOP开始时间到今天的天数)
|
|
|
+ * @param qwExternalContactId 企微外部联系人ID
|
|
|
+ * @return 营期天数,如果查询失败返回null
|
|
|
+ */
|
|
|
+ private Integer calculateCampDays(Long qwExternalContactId) {
|
|
|
+ try {
|
|
|
+ // 查询SOP信息,获取start_time
|
|
|
+ SopUserLogsInfo queryParam = new SopUserLogsInfo();
|
|
|
+ queryParam.setExternalId(qwExternalContactId);
|
|
|
+
|
|
|
+ List<SopUserLogsInfoVOE> sopList = sopUserLogsInfoMapper.selectSopUserLogsInfoListVO(queryParam);
|
|
|
+
|
|
|
+ if (sopList == null || sopList.isEmpty()) {
|
|
|
+ log.error("未找到客户的SOP信息,客户ID: {}", qwExternalContactId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取第一条SOP记录的开始时间
|
|
|
+ String startTimeStr = sopList.get(0).getStartTime();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(startTimeStr)) {
|
|
|
+ log.error("SOP开始时间为空,客户ID: {}", qwExternalContactId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析开始时间
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate startDate = LocalDate.parse(startTimeStr, formatter);
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+
|
|
|
+ // 计算天数差(从开始日期到今天,包含开始日期,所以+1)
|
|
|
+ long daysDiff = java.time.temporal.ChronoUnit.DAYS.between(startDate, today) + 1;
|
|
|
+
|
|
|
+ log.info("计算营期天数成功,客户ID: {}, 开始时间: {}, 营期天数: {}",
|
|
|
+ qwExternalContactId, startTimeStr, daysDiff);
|
|
|
+
|
|
|
+ return (int) daysDiff;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("计算营期天数异常,客户ID: {}", qwExternalContactId, e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|