Преглед изворни кода

获客链接值班客服定时任务执行同步

zoujiajian пре 2 година
родитељ
комит
4c948ee4f8

+ 5 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -245,4 +245,9 @@ public interface Constant {
 	 * 获客链接 state 标识
 	 * 获客链接 state 标识
 	 */
 	 */
 	String ACQUISTION_LINK_STATE_KEY = "customer_";
 	String ACQUISTION_LINK_STATE_KEY = "customer_";
+
+	/**
+	 * 获客链接 值班客服更新定时任务id
+	 */
+	Integer CORP_LINK_JOB_ID = 192;
 }
 }

+ 20 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpCustomerAcquisitionLinkServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkMapper;
 import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkMapper;
 import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkPopularizeMapper;
 import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkPopularizeMapper;
@@ -15,9 +16,12 @@ import com.cyksj.model.request.corp.link.WxCpLinkAddResp;
 import com.cyksj.model.request.corp.link.WxCpLinkUpd;
 import com.cyksj.model.request.corp.link.WxCpLinkUpd;
 import com.cyksj.service.corp.CorpCustomerAcquisitionLinkService;
 import com.cyksj.service.corp.CorpCustomerAcquisitionLinkService;
 import com.cyksj.service.corp.WxCorpOps;
 import com.cyksj.service.corp.WxCorpOps;
+import com.cyksj.xxljob.XxlJobInfo;
+import com.cyksj.xxljob.XxlJobUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
 import java.util.Optional;
 import java.util.Optional;
 
 
@@ -35,6 +39,7 @@ public class CorpCustomerAcquisitionLinkServiceImpl extends ServiceImpl<CorpCust
     private final CorpCustomerAcquisitionLinkPopularizeMapper corpCustomerAcquisitionLinkPopularizeMapper;
     private final CorpCustomerAcquisitionLinkPopularizeMapper corpCustomerAcquisitionLinkPopularizeMapper;
 
 
     @Override
     @Override
+    @Transactional(rollbackFor = Throwable.class)
     public void add(CorpCustomerAcquisitionLink corpCustomerAcquisitionLink) throws Exception {
     public void add(CorpCustomerAcquisitionLink corpCustomerAcquisitionLink) throws Exception {
         WxCpLinkAdd wxCpLinkAdd = new WxCpLinkAdd();
         WxCpLinkAdd wxCpLinkAdd = new WxCpLinkAdd();
         wxCpLinkAdd.setLinkName(corpCustomerAcquisitionLink.getLinkName());
         wxCpLinkAdd.setLinkName(corpCustomerAcquisitionLink.getLinkName());
@@ -48,11 +53,17 @@ public class CorpCustomerAcquisitionLinkServiceImpl extends ServiceImpl<CorpCust
 
 
         corpCustomerAcquisitionLink.setChooseDutyUsers(corpCustomerAcquisitionLink.getUserList());
         corpCustomerAcquisitionLink.setChooseDutyUsers(corpCustomerAcquisitionLink.getUserList());
         this.save(corpCustomerAcquisitionLink);
         this.save(corpCustomerAcquisitionLink);
+
+        if (corpCustomerAcquisitionLink.getIsDuty() != null && corpCustomerAcquisitionLink.getIsDuty()) {
+            handleCorpLinkSchedulerJob();
+        }
     }
     }
 
 
     @Override
     @Override
+    @Transactional(rollbackFor = Throwable.class)
     public void up(CorpCustomerAcquisitionLink corpCustomerAcquisitionLink) throws Exception {
     public void up(CorpCustomerAcquisitionLink corpCustomerAcquisitionLink) throws Exception {
         CorpCustomerAcquisitionLink link = getById(corpCustomerAcquisitionLink.getId());
         CorpCustomerAcquisitionLink link = getById(corpCustomerAcquisitionLink.getId());
+        String oldUserList = link.getUserList();
         link.setLinkName(corpCustomerAcquisitionLink.getLinkName());
         link.setLinkName(corpCustomerAcquisitionLink.getLinkName());
         link.setUserList(corpCustomerAcquisitionLink.getUserList());
         link.setUserList(corpCustomerAcquisitionLink.getUserList());
 
 
@@ -79,6 +90,10 @@ public class CorpCustomerAcquisitionLinkServiceImpl extends ServiceImpl<CorpCust
         }
         }
 
 
         this.updateById(corpCustomerAcquisitionLink);
         this.updateById(corpCustomerAcquisitionLink);
+
+        if (corpCustomerAcquisitionLink.getIsDuty() != null && corpCustomerAcquisitionLink.getIsDuty() && !StrUtil.equals(oldUserList, corpCustomerAcquisitionLink.getUserList())) {
+            handleCorpLinkSchedulerJob();
+        }
     }
     }
 
 
     @Override
     @Override
@@ -98,4 +113,9 @@ public class CorpCustomerAcquisitionLinkServiceImpl extends ServiceImpl<CorpCust
         WxCpLinkAddResp wxCpLinkAddResp = corpOps.customerAcquisitionDeleteLink(null, wxCpLinkUpd);
         WxCpLinkAddResp wxCpLinkAddResp = corpOps.customerAcquisitionDeleteLink(null, wxCpLinkUpd);
         removeById(id);
         removeById(id);
     }
     }
+
+    public void handleCorpLinkSchedulerJob() throws Exception {
+        //立即执行客服值班定时任务
+        XxlJobUtil.executeMarkDynamicRuleTagJob(XxlJobInfo.getExecuteTaskInstance(Constant.CORP_LINK_JOB_ID, StrUtil.EMPTY).toString());
+    }
 }
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/sys/SysConfigChangeRecordService.java

@@ -10,5 +10,5 @@ import com.cyksj.model.entity.SysConfigChangeRecord;
  * 创建时间:2023/11/24 10:44
  * 创建时间:2023/11/24 10:44
  */
  */
 public interface SysConfigChangeRecordService extends IService<SysConfigChangeRecord> {
 public interface SysConfigChangeRecordService extends IService<SysConfigChangeRecord> {
-	void changeRecord(Long adminId, String sysKey, String sysValue, String updateValue);
+	void changeRecord(Long adminId, String sysKey, String sysValue, String updateValue) throws Exception;
 }
 }

+ 6 - 1
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigChangeRecordServiceImpl.java

@@ -7,6 +7,8 @@ import com.cyksj.mapper.SysConfigChangeRecordMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
 import com.cyksj.model.entity.SysConfigChangeRecord;
 import com.cyksj.model.entity.SysConfigChangeRecord;
 import com.cyksj.service.sys.SysConfigChangeRecordService;
 import com.cyksj.service.sys.SysConfigChangeRecordService;
+import com.cyksj.xxljob.XxlJobInfo;
+import com.cyksj.xxljob.XxlJobUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -24,7 +26,7 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 	private final CmsUserMapper cmsUserMapper;
 	private final CmsUserMapper cmsUserMapper;
 
 
 	@Override
 	@Override
-	public void changeRecord(Long adminId, String sysKey, String sysValue, String updateValue) {
+	public void changeRecord(Long adminId, String sysKey, String sysValue, String updateValue) throws Exception {
 		//保存客服系统配置key前后更新数据
 		//保存客服系统配置key前后更新数据
 		if (Constant.serviceKeys.contains(sysKey)) {
 		if (Constant.serviceKeys.contains(sysKey)) {
 			if (!StrUtil.equals(sysValue, updateValue)) {
 			if (!StrUtil.equals(sysValue, updateValue)) {
@@ -35,6 +37,9 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 				Optional.ofNullable(cmsUserMapper.selectById(adminId))
 				Optional.ofNullable(cmsUserMapper.selectById(adminId))
 						.ifPresent(cm -> sysConfigChangeRecord.setOperator(cm.getNickname()));
 						.ifPresent(cm -> sysConfigChangeRecord.setOperator(cm.getNickname()));
 				this.save(sysConfigChangeRecord);
 				this.save(sysConfigChangeRecord);
+
+				//立即执行客服值班定时任务
+				XxlJobUtil.executeMarkDynamicRuleTagJob(XxlJobInfo.getExecuteTaskInstance(Constant.CORP_LINK_JOB_ID, StrUtil.EMPTY).toString());
 			}
 			}
 		}
 		}
 	}
 	}

+ 5 - 3
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigServiceImpl.java

@@ -1,6 +1,7 @@
 package com.cyksj.service.sys.impl;
 package com.cyksj.service.sys.impl;
 
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -137,10 +138,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig>
 			if (CollUtil.isEmpty(collect)) {
 			if (CollUtil.isEmpty(collect)) {
 				// 如果没有下一个时间段,获取下一个工作时间段的开始时间
 				// 如果没有下一个时间段,获取下一个工作时间段的开始时间
 				DayOfWeek nextWorkDay = getNextWorkDay(currentDayOfWeek);
 				DayOfWeek nextWorkDay = getNextWorkDay(currentDayOfWeek);
-				List<YhServiceDto> nextServices = getDutyService(nextWorkDay, workday, saturday, sunday);
-				//获取下一天的早时
-				return List.of(nextServices.get(0));
+				collect = getDutyService(nextWorkDay, workday, saturday, sunday);
 			}
 			}
+			collect.sort(Comparator.comparing(e -> DateUtil.parse(e.getStartTime(), "HH:mm")));
+			//获取下一天的早时
+			return List.of(collect.get(0));
 		}
 		}
 		return collect;
 		return collect;
 	}
 	}

+ 2 - 0
netflix-web/src/main/java/com/cyksj/web/controller/sys/SysConfigController.java

@@ -24,6 +24,7 @@ import com.cyksj.service.sys.SysConfigChangeRecordService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.sys.SysConfigService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -70,6 +71,7 @@ public class SysConfigController {
 
 
 	@PutMapping("/update")
 	@PutMapping("/update")
 	@Log(module = "系统设置/编辑配置", businessType = BusinessType.PUT, isSaveRequestData = true)
 	@Log(module = "系统设置/编辑配置", businessType = BusinessType.PUT, isSaveRequestData = true)
+	@Transactional(rollbackFor = Throwable.class)
 	public Result<SysConfig> update(@RequestBody SysConfig sysConfig) throws Exception {
 	public Result<SysConfig> update(@RequestBody SysConfig sysConfig) throws Exception {
 		long adminId = StpUtil.getLoginIdAsLong();
 		long adminId = StpUtil.getLoginIdAsLong();
 		Long id = sysConfig.getId();
 		Long id = sysConfig.getId();