记得上下班打卡 | git大法好,push需谨慎

Commit b326d5fd authored by wangyifan's avatar wangyifan

艺人授权过期后自动下架

parent be9c1b2a
...@@ -33,4 +33,7 @@ public interface FeignGoblinTaskClient { ...@@ -33,4 +33,7 @@ public interface FeignGoblinTaskClient {
@PostMapping("rsc/job/sqb/autoRefund") @PostMapping("rsc/job/sqb/autoRefund")
ResponseDto<String> sqbAutoRefund(@RequestParam(value = "performancesId", required = false) String performancesId); ResponseDto<String> sqbAutoRefund(@RequestParam(value = "performancesId", required = false) String performancesId);
@PostMapping("rsc/job/artistTopic/offlineExpired")
ResponseDto<String> artistTopicOfflineExpired();
} }
...@@ -69,6 +69,20 @@ public class GoblinTaskHandler { ...@@ -69,6 +69,20 @@ public class GoblinTaskHandler {
} }
} }
/**
* 艺人授权过期后自动下架 B 端已上架专题
* xxl-job 配置:JobHandler = sev-goblin:artistTopicOfflineExpired;建议 CRON 0 0/10 * * * ?;无任务参数
*/
@XxlJob(value = "sev-goblin:artistTopicOfflineExpired")
public void artistTopicOfflineExpired() {
try {
XxlJobHelper.handleSuccess("结果:" + feignGoblinTaskClient.artistTopicOfflineExpired().getData());
} catch (Exception e) {
XxlJobHelper.log(e);
XxlJobHelper.handleFail();
}
}
/** /**
* 演出结束自动退款 / 退款中超8小时卡单重试 * 演出结束自动退款 / 退款中超8小时卡单重试
* xxl-job 配置:JobHandler = sev-goblin:sqbAutoRefund;参数为演出ID、或 performancesId=xxx;空则走 goblin 全库候选(慎用) * xxl-job 配置:JobHandler = sev-goblin:sqbAutoRefund;参数为演出ID、或 performancesId=xxx;空则走 goblin 全库候选(慎用)
......
package com.liquidnet.service.goblin.controller.Inner;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.service.impl.inner.GoblinArtistTopicJobServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 艺人专题定时任务入口(供 executor 服务通过 Feign 调用)
*
* xxl-job 配置说明:
* - 在 xxl-job 平台新增定时任务
* - JobHandler:sev-goblin:artistTopicOfflineExpired(接口走 rsc/** 免登录,与 NFT/收钱吧 job 一致)
* - CRON:建议每 10 分钟 0 0/10 * * * ?
* - 执行器:liquidnet-service-executor
* - 任务参数:无
* - 路由策略:第一个
*/
@Slf4j
@Api(tags = "艺人专题定时任务")
@RestController
@RequestMapping("/rsc/job/artistTopic")
public class GoblinArtistTopicJobController {
@Autowired
private GoblinArtistTopicJobServiceImpl goblinArtistTopicJobService;
@PostMapping("/offlineExpired")
@ApiOperation("授权过期自动下架已上架专题(同一店铺+艺人无未过期新授权时)")
public ResponseDto<String> offlineExpired() {
log.info("[艺人专题过期下架] 收到任务");
return goblinArtistTopicJobService.offlineExpired();
}
}
package com.liquidnet.service.goblin.service.impl.inner;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinArtistConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.dto.vo.GoblinArtistAuthApplyVo;
import com.liquidnet.service.goblin.dto.vo.GoblinArtistTopicVo;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 艺人授权过期后,自动将对应已上架专题改为下架
*/
@Slf4j
@Service
public class GoblinArtistTopicJobServiceImpl {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private QueueUtils queueUtils;
public ResponseDto<String> offlineExpired() {
LocalDateTime now = LocalDateTime.now();
Set<String> validKeys = loadValidAuthKeys(now);
List<GoblinArtistTopicVo> onlineTopics = mongoTemplate.find(
new Query(Criteria.where("status").is(GoblinArtistConst.TOPIC_ONLINE)
.and("delFlg").is(GoblinArtistConst.DEL_NO)
.and("artistId").exists(true).ne("")),
GoblinArtistTopicVo.class, GoblinArtistTopicVo.class.getSimpleName());
if (onlineTopics == null || onlineTopics.isEmpty()) {
return ResponseDto.success("无已上架专题");
}
List<GoblinArtistTopicVo> toOffline = onlineTopics.stream()
.filter(t -> StringUtils.isNotBlank(t.getTopicId()))
.filter(t -> StringUtils.isNotBlank(t.getArtistId()))
.filter(t -> !validKeys.contains(t.getStoreId() + "_" + t.getArtistId()))
.collect(Collectors.toList());
if (toOffline.isEmpty()) {
return ResponseDto.success("无需要下架的专题");
}
List<String> topicIds = toOffline.stream()
.map(GoblinArtistTopicVo::getTopicId)
.collect(Collectors.toList());
mongoTemplate.updateMulti(
new Query(Criteria.where("topicId").in(topicIds)),
new Update().set("status", GoblinArtistConst.TOPIC_OFFLINE).set("updatedAt", now),
GoblinArtistTopicVo.class.getSimpleName());
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlObjs = CollectionUtil.linkedListObjectArr();
for (String topicId : topicIds) {
goblinRedisUtils.del(GoblinRedisConst.ARTIST_TOPIC + topicId);
sqls.add(SqlMapping.get("goblin_artist_topic.status"));
sqlObjs.add(new Object[]{GoblinArtistConst.TOPIC_OFFLINE, now, topicId});
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.gets(sqls, sqlObjs));
log.info("[艺人专题过期下架] 下架 {} 个专题, topicIds={}", topicIds.size(), topicIds);
return ResponseDto.success("下架" + topicIds.size() + "个专题");
}
/** 仍有效授权:申请已通过且未过期 */
private Set<String> loadValidAuthKeys(LocalDateTime now) {
List<GoblinArtistAuthApplyVo> auths = mongoTemplate.find(
new Query(Criteria.where("status").is(GoblinArtistConst.APPLY_APPROVED)
.and("authExpireAt").gt(now)),
GoblinArtistAuthApplyVo.class, GoblinArtistAuthApplyVo.class.getSimpleName());
if (auths == null || auths.isEmpty()) {
return Collections.emptySet();
}
return auths.stream()
.filter(a -> StringUtils.isNotBlank(a.getStoreId()) && StringUtils.isNotBlank(a.getArtistId()))
.map(a -> a.getStoreId() + "_" + a.getArtistId())
.collect(Collectors.toSet());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment