|
@@ -8,6 +8,7 @@ import com.fs.app.taskService.SopLogsTaskService;
|
|
|
import com.fs.app.taskService.SopWxLogsService;
|
|
import com.fs.app.taskService.SopWxLogsService;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.ResponseResult;
|
|
import com.fs.common.core.domain.ResponseResult;
|
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.domain.FsUserCompanyUserQw;
|
|
import com.fs.course.domain.FsUserCompanyUserQw;
|
|
@@ -17,14 +18,17 @@ import com.fs.course.mapper.FsUserCourseMapper;
|
|
|
import com.fs.course.param.FsUserCourseVideoAddKfUParam;
|
|
import com.fs.course.param.FsUserCourseVideoAddKfUParam;
|
|
|
import com.fs.course.param.newfs.FsUserCourseAddCompanyUserParam;
|
|
import com.fs.course.param.newfs.FsUserCourseAddCompanyUserParam;
|
|
|
import com.fs.course.service.*;
|
|
import com.fs.course.service.*;
|
|
|
|
|
+import com.fs.fastGpt.domain.FastGptPushTokenTotal;
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.service.IFsInquiryOrderService;
|
|
import com.fs.his.service.IFsInquiryOrderService;
|
|
|
import com.fs.his.utils.qrcode.QRCodeUtils;
|
|
import com.fs.his.utils.qrcode.QRCodeUtils;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
|
|
+import com.fs.qw.mapper.QwRestrictionPushRecordMapper;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
|
|
+import com.fs.qw.service.IQwGroupMsgService;
|
|
|
import com.fs.qw.service.IQwMaterialService;
|
|
import com.fs.qw.service.IQwMaterialService;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
@@ -44,9 +48,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Api("公共接口")
|
|
@Api("公共接口")
|
|
|
@RestController
|
|
@RestController
|
|
@@ -129,6 +133,104 @@ public class CommonController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsUserMapper fsUserMapper;
|
|
private FsUserMapper fsUserMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IQwGroupMsgService groupMsgService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwRestrictionPushRecordMapper qwRestrictionPushRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 测试
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/sopPushTokenTotal")
|
|
|
|
|
+ public void sopPushTokenTotal() {
|
|
|
|
|
+ // 判断是否是凌晨 00:00 - 00:59
|
|
|
|
|
+ boolean isEarlyMorning = isEarlyMorning();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取日期字符串(今天或昨天)
|
|
|
|
|
+ String dateTime;
|
|
|
|
|
+ if (isEarlyMorning) {
|
|
|
|
|
+ dateTime = DateUtils.addDateDays(-1); // 昨天
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dateTime = DateUtils.getDate(); // 今天
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("开始执行sop任务token消耗统计");
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ //查侧边栏官方群发的
|
|
|
|
|
+ List<FastGptPushTokenTotal> msgListByToTal = groupMsgService.selectQwGroupMsgListByToTal(dateTime);
|
|
|
|
|
+
|
|
|
|
|
+ List<FastGptPushTokenTotal> fastGptPushTotalList = qwRestrictionPushRecordMapper.selectFastgptPushTokenTotal(dateTime);
|
|
|
|
|
+
|
|
|
|
|
+ //合并
|
|
|
|
|
+ List<FastGptPushTokenTotal> newFastGptPushTotalList = newFastGptPushTotalList(msgListByToTal, fastGptPushTotalList);
|
|
|
|
|
+
|
|
|
|
|
+ if (newFastGptPushTotalList != null && !newFastGptPushTotalList.isEmpty()) {
|
|
|
|
|
+ for (FastGptPushTokenTotal fastGptPushTotal : newFastGptPushTotalList) {
|
|
|
|
|
+ // 获取统计数据
|
|
|
|
|
+ Integer type = fastGptPushTotal.getType();
|
|
|
|
|
+ Long count = 0L;
|
|
|
|
|
+ if(type == 7){
|
|
|
|
|
+ count = fastGptPushTotal.getCount() * 450;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ count = fastGptPushTotal.getCount() * 150;
|
|
|
|
|
+ }
|
|
|
|
|
+ fastGptPushTotal.setCount(count);
|
|
|
|
|
+ FastGptPushTokenTotal pushTotal = qwRestrictionPushRecordMapper.selectFastGptPushTokenTotalByInfo(fastGptPushTotal);
|
|
|
|
|
+ if(pushTotal == null){
|
|
|
|
|
+ qwRestrictionPushRecordMapper.insertPushTokenTotal(fastGptPushTotal);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ fastGptPushTotal.setId(pushTotal.getId());
|
|
|
|
|
+ qwRestrictionPushRecordMapper.updatePushTokenTotal(fastGptPushTotal);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("结束执行sop任务token消耗统计");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("执行sop任务token消耗统计异常", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isEarlyMorning() {
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ java.time.LocalDateTime localDateTime = now.toInstant()
|
|
|
|
|
+ .atZone(java.time.ZoneId.systemDefault())
|
|
|
|
|
+ .toLocalDateTime();
|
|
|
|
|
+ return localDateTime.getHour() == 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 合并 token
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<FastGptPushTokenTotal> newFastGptPushTotalList(List<FastGptPushTokenTotal> msgListByToTal,List<FastGptPushTokenTotal> fastGptPushTotalList){
|
|
|
|
|
+
|
|
|
|
|
+ // 使用Map来合并记录
|
|
|
|
|
+ Map<String, FastGptPushTokenTotal> resultMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 先将fastGptPushTotalList放入Map
|
|
|
|
|
+ for (FastGptPushTokenTotal item : fastGptPushTotalList) {
|
|
|
|
|
+ String key = item.getQwUserId() + "_" + item.getType() + "_" + item.getStatTime();
|
|
|
|
|
+ resultMap.put(key, item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理msgListByToTal,合并或添加
|
|
|
|
|
+ for (FastGptPushTokenTotal item : msgListByToTal) {
|
|
|
|
|
+ String key = item.getQwUserId() + "_" + item.getType() + "_" + item.getStatTime();
|
|
|
|
|
+
|
|
|
|
|
+ if (resultMap.containsKey(key)) {
|
|
|
|
|
+ // 合并count
|
|
|
|
|
+ FastGptPushTokenTotal existing = resultMap.get(key);
|
|
|
|
|
+ existing.setCount(existing.getCount() + item.getCount());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 添加新记录
|
|
|
|
|
+ resultMap.put(key, item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将Map转换回List
|
|
|
|
|
+ return new ArrayList<>(resultMap.values());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 发官方通连
|
|
* 发官方通连
|