You've already forked FrameTour-BE
2
This commit is contained in:
@ -161,8 +161,8 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
sourceImageContent.setGoodsType(2);
|
||||
sourceVideoContent.setContentType(2);
|
||||
sourceImageContent.setContentType(2);
|
||||
sourceVideoContent.setLockType(1);
|
||||
sourceImageContent.setLockType(1);
|
||||
sourceVideoContent.setLockType(-1);
|
||||
sourceImageContent.setLockType(-1);
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(faceRespVO.getScenicId());
|
||||
if (!Integer.valueOf(1).equals(scenicConfig.getDisableSourceImage())) {
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), 2, faceId);
|
||||
@ -188,10 +188,10 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
}
|
||||
sourceList.stream().collect(Collectors.groupingBy(SourceRespVO::getType)).forEach((type, list) -> {
|
||||
if (type == 1) {
|
||||
sourceVideoContent.setLockType(0);
|
||||
sourceVideoContent.setLockType(-1);
|
||||
sourceVideoContent.setTemplateCoverUrl(list.get(0).getUrl());
|
||||
} else {
|
||||
sourceImageContent.setLockType(0);
|
||||
sourceImageContent.setLockType(-1);
|
||||
sourceImageContent.setTemplateCoverUrl(list.get(0).getUrl());
|
||||
}
|
||||
});
|
||||
|
@ -1,164 +0,0 @@
|
||||
package com.ycwl.basic.service.impl.mobile;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.config.WechatConfig;
|
||||
import com.ycwl.basic.constant.NumberConstant;
|
||||
import com.ycwl.basic.constant.WeiXinConstant;
|
||||
import com.ycwl.basic.enums.BizCodeEnum;
|
||||
import com.ycwl.basic.enums.StatisticEnum;
|
||||
import com.ycwl.basic.exception.AppException;
|
||||
import com.ycwl.basic.mapper.MemberMapper;
|
||||
import com.ycwl.basic.mapper.MessageRecordMapper;
|
||||
import com.ycwl.basic.mapper.ScenicMapper;
|
||||
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||
import com.ycwl.basic.model.mobile.messageRecord.MessageRecordEntity;
|
||||
import com.ycwl.basic.model.mobile.statistic.req.StatisticsRecordAddReq;
|
||||
import com.ycwl.basic.model.wx.WechatAccessTokenVO;
|
||||
import com.ycwl.basic.model.wx.WechatMessageSubscribeForm;
|
||||
import com.ycwl.basic.model.wx.WechatMssVO;
|
||||
import com.ycwl.basic.service.mobile.WxNotifyService;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.ycwl.basic.constant.WeiXinConstant.*;
|
||||
|
||||
/**
|
||||
* @Author: songmingsong
|
||||
* @CreateTime: 2024-12-06
|
||||
* @Description: 微信消息通知实现
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WxNotifyServiceImpl implements WxNotifyService {
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Autowired
|
||||
private WechatConfig wechatConfig;
|
||||
@Autowired
|
||||
private MessageRecordMapper messageRecordMapper;
|
||||
@Autowired
|
||||
private StatisticsMapper statisticsMapper;
|
||||
@Autowired
|
||||
private MemberMapper memberMapper;
|
||||
|
||||
/**
|
||||
* 缓存accessToken
|
||||
*/
|
||||
private final Map<String, AccessTokenCacheEntity> cacheAccessTokenMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
String cacheKey = wechatConfig.getMiniProgramAppId() + wechatConfig.getMiniProgramSecret();
|
||||
AccessTokenCacheEntity accessTokenCacheEntity = cacheAccessTokenMap.get(cacheKey);
|
||||
if (accessTokenCacheEntity != null && accessTokenCacheEntity.expireDate.getTime() > System.currentTimeMillis()) {
|
||||
return accessTokenCacheEntity.accessToken;
|
||||
}
|
||||
String url = String.format(WeiXinConstant.ACCESS_TOKEN_WITH_PARAM, wechatConfig.getMiniProgramAppId(), wechatConfig.getMiniProgramSecret());
|
||||
ResponseEntity<WechatAccessTokenVO> responseEntity = restTemplate.getForEntity(url, WechatAccessTokenVO.class);
|
||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||
WechatAccessTokenVO accessTokenVO = responseEntity.getBody();
|
||||
if (accessTokenVO.isSuccess()) {
|
||||
accessTokenCacheEntity = new AccessTokenCacheEntity();
|
||||
accessTokenCacheEntity.accessToken = accessTokenVO.getAccess_token();
|
||||
// 设置过期时间,减100秒防止网络延迟失效
|
||||
accessTokenCacheEntity.expireDate = new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(accessTokenVO.getExpires_in() - NumberConstant.HUNDRED));
|
||||
// 缓存一份,有效期内避免重复请求
|
||||
cacheAccessTokenMap.put(cacheKey, accessTokenCacheEntity);
|
||||
return accessTokenVO.getAccess_token();
|
||||
} else {
|
||||
log.error("[微信token]请求AccessToken出现异常,错误信息为{}:{}", accessTokenVO.getErrcode(), accessTokenVO.getErrmsg());
|
||||
throw new AppException(BizCodeEnum.REQUEST_WECHAT_FAIL);
|
||||
}
|
||||
}
|
||||
throw new AppException(BizCodeEnum.REQUEST_WECHAT_FAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户发送通知
|
||||
*
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public JSONObject pushMessage(WechatMessageSubscribeForm info) {
|
||||
|
||||
Integer scenicServiceNoticeStatus = memberMapper.getScenicServiceNoticeStatus(info.getScenicId(), info.getMemberId());
|
||||
if (scenicServiceNoticeStatus == NumberConstant.ZERO) {
|
||||
log.info("用户已关闭通知");
|
||||
return null;
|
||||
}else {
|
||||
// 发送通知
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = MESSAGE_SEND_URL + getAccessToken();
|
||||
|
||||
// 拼接推送的模板
|
||||
WechatMssVO wxMssVO = new WechatMssVO();
|
||||
wxMssVO.setTouser(info.getOpenId()); // 用户的openId
|
||||
wxMssVO.setTemplate_id(info.getTemplateId()); // 订阅消息模板id
|
||||
wxMssVO.setLang(info.getLang()); // 语言类型
|
||||
wxMssVO.setMiniprogram_state(info.getMiniprogram_state()); // 跳转小程序类型
|
||||
wxMssVO.setPage(info.getPage());
|
||||
|
||||
// // TODO: 推送的内容
|
||||
// Map<String, WechatTemplateData> map = new HashMap<>();
|
||||
// map.put("msg", new WechatTemplateData("发消息了"));
|
||||
wxMssVO.setData(info.getData());
|
||||
|
||||
// 发送
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, wxMssVO, String.class);
|
||||
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
||||
Integer errcode = jsonObject.getInteger(WECHAT_ERRCODE);
|
||||
String errmsg = jsonObject.getString(WECHAT_ERRMSG);
|
||||
if (errcode != NumberConstant.ZERO) {
|
||||
throw new AppException(errcode, errmsg);
|
||||
}
|
||||
|
||||
// 记录消息记录
|
||||
MessageRecordEntity messageRecord = new MessageRecordEntity();
|
||||
messageRecord.setId(SnowFlakeUtil.getLongId());
|
||||
messageRecord.setMemberId(info.getMemberId());
|
||||
messageRecord.setScenicId(info.getScenicId());
|
||||
messageRecord.setTemplateId(info.getTemplateId());
|
||||
messageRecord.setContent(info.getData().toString());
|
||||
messageRecordMapper.insertMessageRecord(messageRecord);
|
||||
|
||||
// 统计消息记录
|
||||
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
|
||||
statisticsRecordAddReq.setScenicId(info.getScenicId());
|
||||
statisticsRecordAddReq.setMemberId(info.getMemberId());
|
||||
statisticsRecordAddReq.setType(StatisticEnum.MESSAGE_PUSH.code);
|
||||
statisticsRecordAddReq.setMorphId(messageRecord.getId());
|
||||
statisticsMapper.addStatisticsRecord(statisticsRecordAddReq);
|
||||
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class AccessTokenCacheEntity {
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String accessToken;
|
||||
|
||||
/**
|
||||
* 有效期到
|
||||
*/
|
||||
private Date expireDate;
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -39,8 +40,12 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
for (DeviceRespVO deviceRespVO : list) {
|
||||
DeviceEntity onlineStatus = deviceRepository.getOnlineStatus(deviceRespVO.getId());
|
||||
if (onlineStatus != null) {
|
||||
deviceRespVO.setOnline(onlineStatus.getOnline());
|
||||
deviceRespVO.setKeepaliveAt(onlineStatus.getKeepaliveAt());
|
||||
if (new Date().getTime() - onlineStatus.getKeepaliveAt().getTime() > 300000) {
|
||||
deviceRespVO.setOnline(0);
|
||||
} else {
|
||||
deviceRespVO.setOnline(onlineStatus.getOnline());
|
||||
}
|
||||
} else {
|
||||
deviceRespVO.setOnline(0);
|
||||
deviceRespVO.setKeepaliveAt(null);
|
||||
|
@ -152,7 +152,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
WXPayOrderReqVO wxPayOrderReqVO = new WXPayOrderReqVO();
|
||||
String goodsName = null;
|
||||
if (orderItems.size() > 1) {
|
||||
goodsName = "多项景区Vloh商品";
|
||||
goodsName = "多项景区Vlog商品";
|
||||
} else {
|
||||
int type = orderItems.get(NumberConstant.ZERO).getGoodsType();
|
||||
if (type == NumberConstant.ZERO) {
|
||||
|
@ -1,17 +0,0 @@
|
||||
package com.ycwl.basic.service.mobile;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.model.wx.WechatMessageSubscribeForm;
|
||||
|
||||
public interface WxNotifyService {
|
||||
|
||||
/**
|
||||
* 获取微信token
|
||||
*/
|
||||
String getAccessToken();
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
*/
|
||||
JSONObject pushMessage(WechatMessageSubscribeForm info);
|
||||
}
|
@ -64,6 +64,8 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
@ -97,6 +99,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
private final FixedRateLimiter searchFaceLimiter = new FixedRateLimiter(200, TimeUnit.MILLISECONDS);
|
||||
private final FixedRateLimiter deleteDbLimiter = new FixedRateLimiter(600, TimeUnit.MILLISECONDS);
|
||||
private final FixedRateLimiter deleteEntityLimiter = new FixedRateLimiter(600, TimeUnit.MILLISECONDS);
|
||||
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(8, 1024, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1024));
|
||||
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
@ -224,7 +227,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
log.setMatchRawResult("识别错误,错误为:["+e.getLocalizedMessage()+"]");
|
||||
throw new BaseException(e.getMessage());
|
||||
} finally {
|
||||
new Thread(() -> {
|
||||
executor.execute(() -> {
|
||||
if (log.getMatchRawRecord() != null) {
|
||||
List<MatchLocalRecord> collect = log.getMatchRawRecord().parallelStream().map(item -> {
|
||||
MatchLocalRecord record = new MatchLocalRecord();
|
||||
@ -251,7 +254,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
log.setMatchLocalRecord(JSON.toJSONString(collect));
|
||||
}
|
||||
logMapper.insert(log);
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
@ -120,6 +122,7 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
private TaskStatusBiz taskStatusBiz;
|
||||
@Autowired
|
||||
private DeviceRepository deviceRepository;
|
||||
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(8, 1024, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(1024));
|
||||
|
||||
|
||||
private RenderWorkerEntity getWorker(@NonNull WorkerAuthReqVo req) {
|
||||
@ -613,9 +616,9 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
}
|
||||
}
|
||||
videoMapper.updateRelationWhenTaskSuccess(taskId, video.getId(), isBuy);
|
||||
new Thread(() -> {
|
||||
executor.execute(() -> {
|
||||
sendVideoGeneratedServiceNotification(taskId);
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user