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

Commit 34349732 authored by 姜秀龙's avatar 姜秀龙

大麦 完整 1

parent c60eb873
......@@ -54,6 +54,9 @@ public class PerformanceStep2Param implements Serializable,Cloneable {
@NotNull(message = "须知提醒不能为空")
private Integer noticeRemindStatus;
@ApiModelProperty(value = "是否开启大麦同步 0:关闭 1:开启", example = "0")
private Integer isSyncDamai;
private static final PerformanceStep2Param obj = new PerformanceStep2Param();
public static PerformanceStep2Param getNew() {
try {
......
package com.liquidnet.service.kylin.service.other;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.entity.KylinTicketTimes;
import com.liquidnet.service.kylin.entity.KylinTickets;
......@@ -15,4 +16,7 @@ public interface DamaiService {
//订单
Boolean sycOrder(long timeId, String ticketsId, long ticketsmId,long ticketIdMemberKey);
//定时同步大麦(扫描所有开启同步的演出)
ResponseDto<Boolean> scheduledSyncDamai();
}
package com.liquidnet.service.kylin.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.math.BigDecimal;
......@@ -141,6 +142,26 @@ public class KylinOrderTicketEntities implements Serializable ,Cloneable {
};
}
private Integer isDamaiPushSynced;
private Integer isDamaiWithdrawSynced;
/** 以下字段均为非数据库字段,仅定时同步大麦查询时携带,不参与 MyBatis-Plus 自动 INSERT/UPDATE **/
@TableField(exist = false)
private Integer syncType;
@TableField(exist = false)
private String timePay;
@TableField(exist = false)
private Integer isMember;
@TableField(exist = false)
private String getTicketType;
@TableField(exist = false)
private Integer transferStatus;
private static final KylinOrderTicketEntities obj = new KylinOrderTicketEntities();
public static KylinOrderTicketEntities getNew() {
try {
......
......@@ -160,6 +160,12 @@ public class KylinPerformanceStatus implements Serializable ,Cloneable{
*/
private Integer fieldAuditStatus;
/** 是否开启大麦同步 0:关闭 1:开启 */
private Integer isSyncDamai;
/** 该演出的场地场次票种基础信息是否已推过大麦 0否 1是 */
private Integer isDamaiBasicSynced;
/**
* 创建时间
*/
......
......@@ -2,6 +2,7 @@ package com.liquidnet.service.kylin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.kylin.dao.*;
import com.liquidnet.service.kylin.entity.KylinOrderTicketEntities;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import org.apache.ibatis.annotations.Param;
......@@ -61,4 +62,13 @@ public interface KylinOrderTicketsMapper extends BaseMapper<KylinOrderTickets> {
List<String> getAgentIdListByPerId(@Param("performancesId") String performancesId);
Map selectNumAndPrice(@Param("performancesId") String performancesId, @Param("ticketsId") String ticketsId);
List<KylinOrderTicketEntities> getDamaiOrderSyncList(@Param("performanceId") String performanceId);
int updateDamaiPushSyncStatus(@Param("ids") List<String> ids, @Param("status") Integer status);
int updateDamaiWithdrawSyncStatus(@Param("ids") List<String> ids, @Param("status") Integer status);
// 撤单场景:一次 SQL 同时更新推单和撤单状态(减少数据库操作)
int updateDamaiWithdrawAndPushSyncStatus(@Param("ids") List<String> ids, @Param("status") Integer status);
}
......@@ -5,6 +5,7 @@ import com.liquidnet.service.kylin.dao.*;
import com.liquidnet.service.kylin.dao.report.KylinPerformanceSubscribeStatisticalDao;
import com.liquidnet.service.kylin.dao.report.KylinPerformanceSubscribeTicketStatisticalDao;
import com.liquidnet.service.kylin.dao.report.KylinPerformancesDto;
import com.liquidnet.service.kylin.entity.KylinPerformanceStatus;
import com.liquidnet.service.kylin.entity.KylinPerformances;
import org.apache.ibatis.annotations.Param;
......@@ -126,4 +127,8 @@ public interface KylinPerformancesMapper extends BaseMapper<KylinPerformances> {
* @date 2024/3/21 18:02
*/
void updatePerformanceSubscribePushById(@Param("ids")List<Integer> ids);
List<KylinPerformanceStatus> getDamaiSyncPerformances();
int updateDamaiBasicSynced(@Param("performancesId") String performancesId, @Param("val") Integer val);
}
......@@ -577,4 +577,55 @@ WHERE kotr.performance_id = #{performanceId}
AND kots.status IN (1, 3, 6)
AND kots.transfer_status in (0, 1, 3, 5);
</select>
<select id="getDamaiOrderSyncList" resultType="com.liquidnet.service.kylin.entity.KylinOrderTicketEntities">
SELECT ote.order_ticket_entities_id, ote.time_id, ote.ticket_id, ote.performance_id,
ote.enter_name, ote.enter_id_code, ote.enter_type, ote.enter_mobile, ote.is_payment,
ote.is_damai_push_synced,
ot.time_pay, ot.order_tickets_id AS order_id, ot.get_ticket_type,
otr.is_member,
ots.transfer_status,
CASE
WHEN ote.is_payment = 1 AND ote.is_damai_push_synced = 0 THEN 1
WHEN (ote.is_payment IN (2, 3) OR ots.transfer_status IN (2, 6)) AND ote.is_damai_withdraw_synced = 0 THEN 2
END AS sync_type
FROM kylin_order_ticket_entities ote
LEFT JOIN kylin_order_tickets ot ON ote.order_id = ot.order_tickets_id
LEFT JOIN kylin_order_ticket_relations otr ON otr.order_id = ot.order_tickets_id
LEFT JOIN kylin_order_ticket_status ots ON ots.order_id = ot.order_tickets_id
WHERE ote.performance_id = #{performanceId}
AND (
(ote.is_payment = 1 AND ote.is_damai_push_synced = 0)
OR
((ote.is_payment IN (2, 3) OR ots.transfer_status IN (2, 6)) AND ote.is_damai_withdraw_synced = 0)
)
LIMIT 200
</select>
<update id="updateDamaiPushSyncStatus">
UPDATE kylin_order_ticket_entities
SET is_damai_push_synced = #{status}
WHERE order_ticket_entities_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="updateDamaiWithdrawSyncStatus">
UPDATE kylin_order_ticket_entities
SET is_damai_withdraw_synced = #{status}
WHERE order_ticket_entities_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 撤单场景:一次 SQL 同时更新推单和撤单状态,减少数据库操作 -->
<update id="updateDamaiWithdrawAndPushSyncStatus">
UPDATE kylin_order_ticket_entities
SET is_damai_withdraw_synced = #{status}, is_damai_push_synced = #{status}
WHERE order_ticket_entities_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>
......@@ -1327,4 +1327,16 @@ GROUP BY user_mobile,tickets_id;
#{id}
</foreach>
</update>
<select id="getDamaiSyncPerformances" resultType="com.liquidnet.service.kylin.entity.KylinPerformanceStatus">
SELECT kps.performance_id, kps.is_damai_basic_synced
FROM kylin_performance_status kps
LEFT JOIN kylin_performances kp ON kp.performances_id = kps.performance_id
WHERE kps.is_sync_damai = 1
AND kps.status IN (3, 6, 7, 8, 9, 10)
AND kp.time_end > NOW()
</select>
<update id="updateDamaiBasicSynced">
UPDATE kylin_performance_status SET is_damai_basic_synced = #{val} WHERE performance_id = #{performancesId}
</update>
</mapper>
......@@ -54,6 +54,7 @@ public interface FeignPlatformTaskClient {
@GetMapping("platform/refund/failRefund")
ResponseDto<Boolean> failRefund();
@PostMapping("platform/damai/sync")
ResponseDto<Boolean> syncDamai(@RequestParam("performancesId") String performancesId);
@PostMapping("platform/damai/scheduledSync")
ResponseDto<Boolean> scheduledSyncDamai();
}
......@@ -122,15 +122,11 @@ public class KylinTaskHandler {
}
}
@XxlJob(value = "sev-platform:syncDamai")
public void syncDamaiHandler() {
@XxlJob(value = "sev-platform:scheduledSyncDamai")
public void scheduledSyncDamaiHandler() {
try {
String param = XxlJobHelper.getJobParam();
if (param == null || param.isEmpty()) {
XxlJobHelper.handleFail("performancesId is required");
return;
}
XxlJobHelper.handleSuccess("结果:" + feignPlatformTaskClient.syncDamai(param).getData());
XxlJobHelper.handleSuccess("定时大麦同步结果:" + feignPlatformTaskClient.scheduledSyncDamai().getData());
} catch (Exception e) {
XxlJobHelper.log(e);
XxlJobHelper.handleFail();
......
......@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiOperation;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
......@@ -16,10 +16,10 @@ public class PlatformDamaiController {
@Autowired
private DamaiService damaiService;
@ApiOperation("同步大麦")
@PostMapping(value = "/sync")
public ResponseDto<Boolean> syncDamai(@RequestParam("performancesId") String performancesId) {
boolean result = damaiService.sycPerformance(performancesId);
return ResponseDto.success(result);
@ApiOperation("定时同步大麦(扫描所有开启同步的演出)")
@PostMapping(value = "/scheduledSync")
public ResponseDto<Boolean> scheduledSyncDamai() {
return damaiService.scheduledSyncDamai();
}
}
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.liquidnet.client.admin.common.utils.DateUtils;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.dao.OrderPushDamaiDto;
import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.mapper.*;
......@@ -29,6 +30,7 @@ import org.springframework.stereotype.Service;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -56,6 +58,7 @@ public class PlatformDamaiServiceImpl extends ServiceImpl<KylinRoadShowsMapper,
private KylinTicketTimesMapper ticketTimesMapper;
@Autowired
private KylinTicketTimeRelationMapper ticketTimeRelationMapper;
@Autowired
private KylinTicketsMapper ticketsMapper;
@Autowired
......@@ -150,7 +153,7 @@ public class PlatformDamaiServiceImpl extends ServiceImpl<KylinRoadShowsMapper,
}
// 同步订单
for (KylinTicketRelations ticketRelations : ticketRelation) {
/*for (KylinTicketRelations ticketRelations : ticketRelation) {
long ticketTimesKey = IDGenerator.getDamaiCode(ticketRelations.getTimesId());
long ticketIdKey = IDGenerator.getDamaiCode(ticketRelations.getTicketId());
long ticketIdKey2 = Long.valueOf(ticketIdKey + "".concat("010"));
......@@ -158,14 +161,14 @@ public class PlatformDamaiServiceImpl extends ServiceImpl<KylinRoadShowsMapper,
if (!result) {
return false;
}
}
}*/
// 所有同步完成
log.info("[ 同步大麦-完成 ]");
log.info("[ 同步大麦(演出/场次/票种)-完成 ]");
return true;
} catch (Exception e) {
log.error("[同步大麦] 异常:{}", e);
log.error("[同步大麦(演出/场次/票种)] 异常:{}", e);
return false;
}
}
......@@ -450,4 +453,126 @@ public class PlatformDamaiServiceImpl extends ServiceImpl<KylinRoadShowsMapper,
System.out.println(a);
}
}
\ No newline at end of file
@Override
public ResponseDto<Boolean> scheduledSyncDamai() {
List<KylinPerformanceStatus> performancesList = performancesMapper.getDamaiSyncPerformances();
if (performancesList == null || performancesList.isEmpty()) {
log.info("[大麦定时同步] 无需要推送的演出");
return ResponseDto.success(true);
}
for (KylinPerformanceStatus performance : performancesList) {
String performancesId = performance.getPerformanceId();
try {
// 1. 基础信息未推送过,先推场地/场次/票种
if (performance.getIsDamaiBasicSynced() == null || performance.getIsDamaiBasicSynced() == 0) {
try {
sycPerformance(performancesId);
performancesMapper.updateDamaiBasicSynced(performancesId, 1);
} catch (Exception e) {
log.error("[大麦定时同步] 基础信息推送失败 performancesId={}", performancesId, e);
continue;
}
} else {
log.info("[大麦定时同步] 基础信息已存在 performancesId={}", performancesId);
}
// 2. 合并查询:推单(syncType=1) + 撤单(syncType=2),每次最多 LIMIT 200 条
List<KylinOrderTicketEntities> syncList = orderTicketsMapper.getDamaiOrderSyncList(performancesId);
if (syncList == null || syncList.isEmpty()) {
continue;
}
for (KylinOrderTicketEntities ote : syncList) {
Integer syncType = ote.getSyncType();
String oteId = ote.getOrderTicketEntitiesId();
Long damaiTimeId = IDGenerator.getDamaiCode(ote.getTimeId());
// 大麦票单号生成规则:会员票末尾拼 010,普通票末尾拼 020(与 sycOrder 保持一致)
long voucherId = Integer.valueOf(1).equals(ote.getIsMember())
? Long.parseLong(IDGenerator.getDamaiCode(oteId).toString().concat("010"))
: Long.parseLong(IDGenerator.getDamaiCode(oteId).toString().concat("020"));
try {
if (Integer.valueOf(1).equals(syncType)) {
// 推单(购买)
orderTicketsMapper.updateDamaiPushSyncStatus(java.util.Collections.singletonList(oteId), 1);
sycSingleTicketToDamai(ote, damaiTimeId, voucherId);
orderTicketsMapper.updateDamaiPushSyncStatus(java.util.Collections.singletonList(oteId), 2);
} else if (Integer.valueOf(2).equals(syncType)) {
// 撤单(退票/转赠)
// 大麦侧必须先有推单记录才能撤单,如果从未推过则先推
orderTicketsMapper.updateDamaiWithdrawSyncStatus(java.util.Collections.singletonList(oteId), 1);
if (Integer.valueOf(0).equals(ote.getIsDamaiPushSynced())) {
sycSingleTicketToDamai(ote, damaiTimeId, voucherId);
}
taobaoTicketUtils.withdrawDamaiOrder(damaiTimeId, voucherId);
// 撤单成功:一次 SQL 同时标记推单和撤单均为已处理
orderTicketsMapper.updateDamaiWithdrawAndPushSyncStatus(java.util.Collections.singletonList(oteId), 2);
}
} catch (Exception e) {
log.error("[大麦定时同步] 单票处理失败 oteId={} syncType={}", oteId, syncType, e);
if (Integer.valueOf(1).equals(syncType)) {
orderTicketsMapper.updateDamaiPushSyncStatus(java.util.Collections.singletonList(oteId), 3);
} else {
orderTicketsMapper.updateDamaiWithdrawSyncStatus(java.util.Collections.singletonList(oteId), 3);
}
}
}
} catch (Exception e) {
log.error("[大麦定时同步] 处理异常 performancesId={}", performancesId, e);
}
}
return ResponseDto.success(true);
}
/**
* 定时同步单张票推单到大麦(入场人维度)
* 复用 sycOrder 中单张票的参数构建逻辑
*/
private void sycSingleTicketToDamai(KylinOrderTicketEntities ote, long damaiTimeId, long voucherId) throws Exception {
if (ote.getEnterType() == null || ote.getEnterType() == 0
|| ote.getEnterName() == null || ote.getEnterName().equals("")) {
log.error("[大麦定时同步] 入场人信息错误 oteId={} enterType={} enterName={}", ote.getOrderTicketEntitiesId(), ote.getEnterType(), ote.getEnterName());
return;
}
TaobaoClient client = taobaoTicketUtils.initTaobaoClient();
AlibabaDamaiMevOpenBatchpushticketRequest req = new AlibabaDamaiMevOpenBatchpushticketRequest();
ThirdTicketPushOpenParam obj3 = new ThirdTicketPushOpenParam();
obj3.setUserName(ote.getEnterName());
obj3.setCertificateNo(ote.getEnterIdCode());
obj3.setOrderUserMobile(ote.getEnterMobile());
switch (ote.getEnterType()) {
case 1: obj3.setCertificateType(1L); break;
case 2: obj3.setCertificateType(5L); break;
case 3: obj3.setCertificateType(6L); break;
case 4: obj3.setCertificateType(4L); break;
case 5: obj3.setCertificateType(3L); break;
default:
log.error("[大麦定时同步] 入场人类型错误 oteId={} enterType={}", ote.getOrderTicketEntitiesId(), ote.getEnterType());
return;
}
obj3.setPayTime(DateUtils.parseDate(ote.getTimePay()));
obj3.setPerformId(damaiTimeId);
long damaiTicketId = IDGenerator.getDamaiCode(ote.getTicketId());
if (Integer.valueOf(1).equals(ote.getIsMember())) {
obj3.setTicketItemId(Long.valueOf(damaiTicketId + "".concat("010")));
} else {
obj3.setTicketItemId(damaiTicketId);
}
obj3.setExt("");
obj3.setQrCode("http://m.zhengzai.tv?c=" + IDGenerator.ticketQrCode(ote.getOrderTicketEntitiesId()));
obj3.setVoucherId(voucherId);
obj3.setOrderId(IDGenerator.getDamaiCode(ote.getOrderId()));
obj3.setMediumType("express".equals(ote.getGetTicketType()) ? 1L : 2L);
obj3.setSupplierSecret(taobaoTicketUtils.getSupplierSecret());
obj3.setSystemId(taobaoTicketUtils.getSystemId());
obj3.setSeatType(1L);
obj3.setTicketType(1L);
List<ThirdTicketPushOpenParam> paramList = new ArrayList<>();
paramList.add(obj3);
req.setThirdTicketSetOpenParamList(paramList);
AlibabaDamaiMevOpenBatchpushticketResponse rsp = client.execute(req);
if (!rsp.getResult().getSuccess()) {
log.error("[大麦定时同步] 推单失败 oteId={} body={}", ote.getOrderTicketEntitiesId(), rsp.getBody());
throw new RuntimeException("推单失败: " + rsp.getBody());
}
}
}
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