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

Commit d2b3306c authored by 胡佳晨's avatar 胡佳晨

performance 数据迁移

orderimpl 增加 redisLock
parent 96d1e958
......@@ -130,7 +130,7 @@ CREATE TABLE `kylin_performances`
`sponsor` varchar(255) NOT NULL DEFAULT '' COMMENT '主办方',
`contacts` varchar(255) NOT NULL DEFAULT '' COMMENT '联系人',
`mobile` varchar(255) NOT NULL DEFAULT '' COMMENT '联系电话',
`describes` varchar(255) NOT NULL DEFAULT '' COMMENT '演出简介',
`describes` text NULL DEFAULT NULL COMMENT '演出简介',
`details` longtext DEFAULT NULL COMMENT '演出详情',
`notice_image` text DEFAULT NULL COMMENT '购票须知',
`time_start` datetime NOT NULL DEFAULT '2000-01-01 12:00:00' COMMENT '演出开始时间',
......
package com.liquidnet.service.kylin.controller;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.service.impl.DataImpl;
import io.swagger.annotations.Api;
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.RestController;
@Api(tags = "数据迁移 (会重复)")
@RestController
@RequestMapping("data")
public class DataController {
@Autowired
private DataImpl data;
@PostMapping("performance")
@ApiOperation("演出数据迁移")
public ResponseDto<Boolean> performance() {
Boolean result = data.performance();
return ResponseDto.success(result);
}
}
package com.liquidnet.service.kylin.service.impl;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.kylin.dto.param.PerformancePartnerVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo;
import com.liquidnet.service.kylin.dto.vo.partner.KylinTicketPartnerVo;
import com.liquidnet.service.kylin.dto.vo.partner.KylinTicketTimesPartnerVo;
import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.utils.DataUtils;
import com.liquidnet.service.kylin.utils.MongoVoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
@Service
public class DataImpl {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private KylinPerformancesMapper performancesMapper;
@Autowired
private KylinPerformanceStatusMapper performanceStatusMapper;
@Autowired
private KylinPerformanceRelationsMapper performanceRelationsMapper;
@Autowired
private KylinTicketTimesMapper ticketTimesMapper;
@Autowired
private KylinTicketTimeRelationMapper ticketTimeRelationMapper;
@Autowired
private KylinTicketsMapper ticketsMapper;
@Autowired
private KylinTicketStatusMapper ticketStatusMapper;
@Autowired
private KylinTicketRelationsMapper ticketRelationsMapper;
@Autowired
private DataUtils dataUtils;
public boolean performance() {
try {
String driverClassName = "com.mysql.cj.jdbc.Driver"; //启动驱动
String url = "jdbc:mysql://39.106.122.201:3308/testmall"; //设置连接路径
String username = "testmall"; //数据库用户名
String password = "zhengzai!mYT"; //数据库连接密码
Connection con = null; //连接
PreparedStatement pstmt = null; //使用预编译语句
ResultSet rs = null; //获取的结果集
//演出实体类
KylinPerformances performances = new KylinPerformances();
KylinPerformanceRelations performanceRelations = new KylinPerformanceRelations();
KylinPerformanceStatus performanceStatus = new KylinPerformanceStatus();
//场次实体类
KylinTicketTimes ticketTimes = new KylinTicketTimes();
KylinTicketTimeRelation ticketTimeRelation = new KylinTicketTimeRelation();
//票实体类
KylinTickets tickets = new KylinTickets();
KylinTicketRelations ticketRelations = new KylinTicketRelations();
KylinTicketStatus ticketStatus = new KylinTicketStatus();
// 第三方Vo
PerformancePartnerVo performancePartnerVo = new PerformancePartnerVo();
KylinTicketTimesPartnerVo ticketTimesPartnerVo = new KylinTicketTimesPartnerVo();
KylinTicketPartnerVo ticketPartnerVo = new KylinTicketPartnerVo();
int count = 100;
int page = 0;
try {
Class.forName(driverClassName); //执行驱动
con = DriverManager.getConnection(url, username, password); //获取连接
String sqlAllCount = "select count(0) as 'allCount' from performances where status >= 3"; //设置的预编译语句格式
pstmt = con.prepareStatement(sqlAllCount);
ResultSet allCount = pstmt.executeQuery();
ArrayList<String> performanceIds = new ArrayList<>();
int allCountResult = 0;//共多少条
int rowCount = 0;//当前多少条
boolean isBreak = false;//是否终端循环
while (allCount.next()) {
allCountResult = allCount.getInt("allCount");
}
do {
String sql = "select * from performances where status >= 3 limit " + count * page + " ," + count; //设置的预编译语句格式
pstmt = con.prepareStatement(sql);
ResultSet resultData = pstmt.executeQuery();
int performanceId = 0;
//演出数据
while (resultData.next()) {
performanceId = resultData.getInt("id");
// performances.setPerformancesId(IDGenerator.nextSnowId().toString());
performances.setPerformancesId(resultData.getInt("id") + "");
performanceIds.add(performances.getPerformancesId());
performances.setTitle(resultData.getString("title"));
performances.setType(resultData.getInt("type") == 1 ? 101 : 102);
if (resultData.getInt("road_show_id") > 0) {
performances.setType(103);
}
performances.setImgPoster(resultData.getString("img_poster"));
performances.setApprovalUrl(resultData.getString("approval_url"));
performances.setNotice(resultData.getString("notice"));
performances.setSponsorId(resultData.getString("sponsor_id"));
performances.setSponsorType(resultData.getString("sponsor_type"));
performances.setSponsor(resultData.getString("sponsor"));
performances.setContacts(resultData.getString("contacts"));
performances.setMobile(resultData.getString("mobile"));
performances.setDescribes(resultData.getString("describe"));
performances.setDetails(resultData.getString("detail"));
performances.setNoticeImage("[{\"id\":1,\"sort\":1,\"text\":\"因演出票品非普通商品,其背后承载的文化服务具有时效性、稀缺性等特征,故不适用7天无理由退货政策。因“不可抗力”导致的演出取消或延期除外。\",\"title\":\"门票退换\",\"type\":\"image\",\"url\":\"http://img-zhengzai-tv.oss-cn-hangzhou.aliyuncs.com/partner/2019/01/21/5c45722882a13.png\"},{\"id\":7,\"sort\":2,\"text\":\"凭订单二维码或手机号兑票入场,二维码或手机号请勿泄露,以免影响入场。个人原因导致的信息泄露,主办方/平台方不承担任何责任。\",\"title\":\"电子票\",\"type\":\"image\",\"url\":\"http://img-zhengzai-tv.oss-cn-hangzhou.aliyuncs.com/partner/2019/01/21/5c456d9482fb9.png\"},{\"id\":3,\"sort\":3,\"text\":\"本场演出不设座位,均为站席观演。\",\"title\":\"仅设站席\",\"type\":\"image\",\"url\":\"http://img-zhengzai-tv.oss-cn-hangzhou.aliyuncs.com/partner/2019/01/21/5c456e93db0b9.png\"},{\"id\":12,\"sort\":4,\"text\":\"每场现场票数量由场地方决定,具体请到现场询问。\",\"title\":\"现场票\",\"type\":\"image\",\"url\":\"http://img-zhengzai-tv.oss-cn-hangzhou.aliyuncs.com/partner/2019/06/17/5d07647eaa55f.png\"}]");
performances.setTimeStart(DateUtil.Formatter.yyyyMMddHHmmssS.parse(resultData.getTimestamp("time_start").toString()));
performances.setTimeEnd(DateUtil.Formatter.yyyyMMddHHmmssS.parse(resultData.getTimestamp("time_end").toString()));
performances.setAuditTime(DateUtil.Formatter.yyyyMMddHHmmss.parse(resultData.getString("audit_submit_time")));
performances.setRejectTxt(resultData.getString("reject_text"));
performances.setSort(resultData.getInt("sort"));
performances.setComment("");
performances.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmssS.parse(resultData.getTimestamp("created_at").toString()));
if (null != resultData.getTimestamp("updated_at")) {
performances.setUpdatedAt(DateUtil.Formatter.yyyyMMddHHmmssS.parse(resultData.getTimestamp("updated_at").toString()));
}
//Status
performanceStatus.setPerformanceStatusId(IDGenerator.nextSnowId().toString());
performanceStatus.setPerformanceId(performances.getPerformancesId());
performanceStatus.setIsShow(resultData.getInt("show"));
performanceStatus.setStatus(resultData.getInt("status"));
performanceStatus.setStatusSell(1);
performanceStatus.setIsDistribution(0);
performanceStatus.setSyncAgent(0);
performanceStatus.setSyncDamai(0);
performanceStatus.setAuditStatus(1);
performanceStatus.setIsTrueName(resultData.getString("need_id_card").equals("yes") ? 1 : 2);
performanceStatus.setLimitCount(resultData.getInt("num_limit_mobile"));
performanceStatus.setLimitCountMember(1);
performanceStatus.setIsRecommend(resultData.getInt("is_recommend"));
performanceStatus.setCreatedAt(performances.getCreatedAt());
performanceStatus.setUpdatedAt(performances.getUpdatedAt());
//Relation
performanceRelations.setPerformanceRelationsId(IDGenerator.nextSnowId().toString());
performanceRelations.setPerformanceId(performances.getPerformancesId());
performanceRelations.setCopyId(resultData.getInt("copy_id") + "");
performanceRelations.setMerchantId(resultData.getInt("merchant_id") + "");
performanceRelations.setFieldId(resultData.getInt("field_id") + "");
performanceRelations.setRoadShowId(resultData.getInt("road_show_id") + "");
performanceRelations.setProjectId("");
performanceRelations.setVideoId("");
performanceRelations.setCreatedAt(performances.getCreatedAt());
performanceRelations.setUpdatedAt(performances.getUpdatedAt());
performancesMapper.insert(performances);
performanceStatusMapper.insert(performanceStatus);
performanceRelationsMapper.insert(performanceRelations);
performancePartnerVo.setPerformancesId(performances.getPerformancesId());
performancePartnerVo.setImgPoster(performances.getImgPoster());
performancePartnerVo.setTitle(performances.getTitle());
performancePartnerVo.setType(performances.getType());
performancePartnerVo.setTimeStart(DateUtil.Formatter.yyyyMMddHHmmss.format(performances.getTimeStart()));
performancePartnerVo.setTimeEnd(DateUtil.Formatter.yyyyMMddHHmmss.format(performances.getTimeEnd()));
performancePartnerVo.setFieldId(performanceRelations.getFieldId());
// performancePartnerVo.setFieldName(performances.getFieldName());
performancePartnerVo.setNotice(performances.getNotice());
performancePartnerVo.setSponsorId(performances.getSponsorId());
performancePartnerVo.setSponsorType(performances.getSponsorType());
performancePartnerVo.setSponsor(performances.getSponsor());
performancePartnerVo.setContacts(performances.getContacts());
performancePartnerVo.setMobile(performances.getMobile());
performancePartnerVo.setDetails(performances.getDetails());
performancePartnerVo.setApprovalUrl(performances.getApprovalUrl());
performancePartnerVo.setPayCountdownMinute(5);
performancePartnerVo.setNoticeImage(performances.getNoticeImage());
performancePartnerVo.setIsTrueName(performanceStatus.getIsTrueName());
performancePartnerVo.setLimitCount(performanceStatus.getLimitCount());
performancePartnerVo.setIsSubmit(1);
performancePartnerVo.setStatus(performanceStatus.getStatus());
performancePartnerVo.setMerchantId(performanceRelations.getMerchantId());
performancePartnerVo.setDescribes(performances.getDescribes());
performancePartnerVo.setStatusSell(performanceStatus.getStatusSell());
performancePartnerVo.setRoadShowId(performanceRelations.getRoadShowId());
performancePartnerVo.setRejectTxt(performances.getRejectTxt());
performancePartnerVo.setAuditStatus(1);
performancePartnerVo.setIsShow(performanceStatus.getIsShow());
performancePartnerVo.setProjectId(performances.getProvinceId());
// performancePartnerVo.setNoticeIds();
performancePartnerVo.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(performances.getCreatedAt()));
performancePartnerVo.setUpdatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(performances.getUpdatedAt()));
performancePartnerVo.setIsCreateSave(0);
mongoTemplate.insert(performancePartnerVo, PerformancePartnerVo.class.getSimpleName());
//场次相关
String timesSql = "select type,use_start,use_end,created_at from tickets where performance_id = " + performanceId + " GROUP BY use_start,use_end"; //设置的预编译语句格式
pstmt = con.prepareStatement(timesSql);
ResultSet timesData = pstmt.executeQuery();
HashMap<String, String> timeMap = new HashMap<>();
while (timesData.next()) {
String title = "";
String useStart = DateUtil.Formatter.yyyyMMddHHmmssS.parse(timesData.getTimestamp("use_start").toString()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
;
String useEnd = DateUtil.Formatter.yyyyMMddHHmmssS.parse(timesData.getTimestamp("use_end").toString()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
;
if (timesData.getInt("type") == 1) {
title = useStart;
} else {
title = useStart + "-" + useEnd;
}
//times
ticketTimes.setTicketTimesId(IDGenerator.nextSnowId().toString());
ticketTimes.setTitle(title);
ticketTimes.setType(timesData.getInt("type"));
ticketTimes.setStatus(1);
ticketTimes.setUseStart(DateUtil.Formatter.yyyyMMddHHmmssS.parse(timesData.getTimestamp("use_start").toString()));
ticketTimes.setUseEnd(DateUtil.Formatter.yyyyMMddHHmmssS.parse(timesData.getTimestamp("use_end").toString()));
ticketTimes.setComment("");
if (null != timesData.getTimestamp("created_at")) {
ticketTimes.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmssS.parse(timesData.getTimestamp("created_at").toString()));
}
ticketTimes.setUpdatedAt(null);
//Relation
ticketTimeRelation.setTicketTimeRelationId(IDGenerator.nextSnowId().toString());
ticketTimeRelation.setTimesId(ticketTimes.getTicketTimesId());
ticketTimeRelation.setPerformanceId(performanceId + "");
ticketTimeRelation.setCreatedAt(ticketTimes.getCreatedAt());
timeMap.put(title, ticketTimes.getTicketTimesId());
ticketTimesMapper.insert(ticketTimes);
ticketTimeRelationMapper.insert(ticketTimeRelation);
ticketTimesPartnerVo.setTicketTimesId(ticketTimes.getTicketTimesId());
ticketTimesPartnerVo.setPerformancesId(ticketTimeRelation.getPerformanceId());
ticketTimesPartnerVo.setType(ticketTimes.getType());
ticketTimesPartnerVo.setTitle(ticketTimes.getTitle());
ticketTimesPartnerVo.setStatus(ticketTimes.getStatus());
ticketTimesPartnerVo.setUseEnd(DateUtil.Formatter.yyyyMMddHHmmss.format(ticketTimes.getUseEnd()));
ticketTimesPartnerVo.setUseStart(DateUtil.Formatter.yyyyMMddHHmmss.format(ticketTimes.getUseStart()));
ticketTimesPartnerVo.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(ticketTimes.getCreatedAt()));
mongoTemplate.insert(ticketTimesPartnerVo, KylinTicketTimesPartnerVo.class.getSimpleName());
}
//票sql
String ticketSql = "select * from tickets where performance_id = " + performanceId; //设置的预编译语句格式
pstmt = con.prepareStatement(ticketSql);
ResultSet ticketData = pstmt.executeQuery();
while (ticketData.next()) {
//会员sql
String memberSql = "select status from performance_members where performance_id = " + performanceId; //设置的预编译语句格式
pstmt = con.prepareStatement(memberSql);
int isMember = 0;
ResultSet memberData = pstmt.executeQuery();
while (memberData.next()) {
isMember = memberData.getInt("status") == 1 ? 1 : 0;
}
String title = "";
String useStart = DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("use_start").toString()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
;
String useEnd = DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("use_end").toString()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
;
if (ticketData.getInt("type") == 1) {
title = useStart;
} else {
title = useStart + "-" + useEnd;
}
//Ticket
// tickets.setPerformancesId(IDGenerator.nextSnowId().toString());
tickets.setTicketsId(ticketData.getInt("id") + "");
tickets.setTitle(ticketData.getString("title"));
tickets.setType(ticketData.getInt("type"));
tickets.setPrice(ticketData.getBigDecimal("price"));
tickets.setPriceExpress(ticketData.getBigDecimal("price_express"));
tickets.setPriceDiscountMember(new BigDecimal("0.00"));
tickets.setPriceDiscount(new BigDecimal("0.00"));
tickets.setDescribes(ticketData.getString("describe_express"));
tickets.setDescribeExpress(ticketData.getString("describe_express"));
tickets.setDescribeElectronic(ticketData.getString("describe_electronic"));
tickets.setAdvanceMinuteMember(5);
tickets.setTimeStart(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("time_start").toString()));
tickets.setTimeEnd(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("time_end").toString()));
tickets.setTimeEndExpress(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("time_end_express").toString()));
tickets.setUseStart(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("use_start").toString()));
tickets.setUseEnd(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("use_end").toString()));
tickets.setPayCountdownMinute(5);
tickets.setSaleRemindMinute(60);
tickets.setComment("");
if (null != ticketData.getTimestamp("created_at")) {
tickets.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("created_at").toString()));
}
if (null != ticketData.getTimestamp("updated_at")) {
tickets.setUpdatedAt(DateUtil.Formatter.yyyyMMddHHmmssS.parse(ticketData.getTimestamp("updated_at").toString()));
}
//Status
ticketStatus.setTicketStatusId(IDGenerator.nextSnowId().toString());
ticketStatus.setTicketId(tickets.getTicketsId());
ticketStatus.setIsStudent(ticketData.getString("student").equals("yes") ? 1 : 0);
ticketStatus.setIsElectronic(ticketData.getInt("is_electronic"));
ticketStatus.setIsExpress(ticketData.getInt("is_express"));
ticketStatus.setStatus(ticketData.getInt("status"));
ticketStatus.setCounts(1);
ticketStatus.setStatusExchange(7);
ticketStatus.setIsShowCode(0);
// ticketStatus.setQrCodeShowTime();
ticketStatus.setIsLackRegister(ticketData.getInt("is_lack_register"));
ticketStatus.setTotalGeneral(ticketData.getInt("total_general"));
ticketStatus.setTotalExchange(ticketData.getInt("total_exchange"));
ticketStatus.setSurplusGeneral(ticketData.getInt("surplus_general"));
ticketStatus.setSurplusExchange(ticketData.getInt("surplus_exchange"));
ticketStatus.setExpressType(ticketData.getInt("express_type"));
ticketStatus.setIsTrueName(ticketData.getString("need_id_card").equals("yes") ? 1 : 0);
ticketStatus.setLimitCount(0);
ticketStatus.setMemberLimitCount(1);
ticketStatus.setIsTransfer(0);
ticketStatus.setIsExclusive(ticketData.getInt("is_exclusive"));
ticketStatus.setIsMember(isMember);
ticketStatus.setIsAgent(0);
ticketStatus.setSyncDamai(0);
ticketStatus.setCreatedAt(tickets.getCreatedAt());
if (null != ticketData.getTimestamp("updated_at")) {
ticketStatus.setUpdatedAt(tickets.getUpdatedAt());
}
//Relation
ticketRelations.setTicketRelationsId(IDGenerator.nextSnowId().toString());
ticketRelations.setTicketId(tickets.getTicketsId());
ticketRelations.setTimesId(timeMap.get(title));
ticketRelations.setCreatedAt(tickets.getCreatedAt());
if (null != ticketData.getTimestamp("updated_at")) {
ticketRelations.setUpdatedAt(tickets.getUpdatedAt());
}
ticketsMapper.insert(tickets);
ticketStatusMapper.insert(ticketStatus);
ticketRelationsMapper.insert(ticketRelations);
dataUtils.setSurplusGeneral(tickets.getTicketsId(),ticketStatus.getSurplusGeneral());
dataUtils.setSurplusExchange(tickets.getTicketsId(),ticketStatus.getSurplusExchange());
//Vo
ticketPartnerVo.setTicketsId(tickets.getTicketsId());
ticketPartnerVo.setTitle(tickets.getTitle());
ticketPartnerVo.setIsStudent(ticketStatus.getIsStudent());
ticketPartnerVo.setIsElectronic(ticketStatus.getIsElectronic());
ticketPartnerVo.setIsExpress(ticketStatus.getIsExpress());
ticketPartnerVo.setType(tickets.getType());
ticketPartnerVo.setPrice(tickets.getPrice());
ticketPartnerVo.setTimeEndExpress(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getTimeEndExpress()));
ticketPartnerVo.setTotalGeneral(ticketStatus.getTotalGeneral());
ticketPartnerVo.setTotalExchange(ticketStatus.getTotalExchange());
ticketPartnerVo.setLimitCount(ticketStatus.getLimitCount());
ticketPartnerVo.setCounts(1);
ticketPartnerVo.setTimeStart(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getTimeStart()));
ticketPartnerVo.setTimeEnd(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getTimeEnd()));
ticketPartnerVo.setUseStart(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getUseStart()));
ticketPartnerVo.setUseEnd(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getUseEnd()));
ticketPartnerVo.setDescribes(tickets.getDescribes());
ticketPartnerVo.setDescribesExpress(tickets.getDescribeExpress());
ticketPartnerVo.setDescribeElectronic(tickets.getDescribeElectronic());
ticketPartnerVo.setStatus(ticketStatus.getStatus());
ticketPartnerVo.setIsShowCode(ticketStatus.getIsShowCode());
// ticketPartnerVo.setQrCodeShowTime();
ticketPartnerVo.setTimesId(ticketRelations.getTimesId());
ticketPartnerVo.setIsLackRegister(ticketStatus.getIsLackRegister());
ticketPartnerVo.setSurplusGeneral(ticketStatus.getSurplusGeneral());
ticketPartnerVo.setSurplusExchange(ticketStatus.getSurplusExchange());
ticketPartnerVo.setExpressType(ticketStatus.getExpressType());
ticketPartnerVo.setIsTransfer(ticketStatus.getIsTransfer());
ticketPartnerVo.setIsMember(ticketStatus.getIsMember());
ticketPartnerVo.setIsExclusive(ticketStatus.getIsExclusive());
ticketPartnerVo.setCreatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getCreatedAt()));
ticketPartnerVo.setUpdatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(tickets.getUpdatedAt()));
mongoTemplate.insert(ticketPartnerVo, KylinTicketPartnerVo.class.getSimpleName());
}
}
for (int i = 0; i < performanceIds.size(); i++) {
dataUtils.updatePerformanceMongo(performanceIds.get(i));
}
resultData.last();
rowCount += resultData.getRow();
if (allCountResult > rowCount) {
isBreak = true;
page+=1;
} else {
isBreak = false;
}
} while (isBreak);
return true;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
//关闭资源,倒关
try {
if (rs != null) rs.close();
if (pstmt != null) pstmt.close();
if (con != null) con.close(); //必须要关
} catch (Exception e) {
}
}
} catch (Exception e) {
return false;
}
}
}
......@@ -90,10 +90,10 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
@Autowired
private OtherUtils otherUtils;
@Autowired
private MongoVoUtils mongoVoUtils;
@Autowired
private RedisLockUtil redisLockUtil;
@Autowired
private MongoVoUtils mongoVoUtils;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private MongoConverter mongoConverter;
......@@ -112,10 +112,10 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
public ResponseDto<PayResultVo> checkCanOrder(PayOrderParam payOrderParam) {
boolean isDownGeneral = false;
String uid = CurrentUtil.getCurrentUid();
if (!RedisLockUtil.tryLock("userId:" + uid, 2, 2)) {
String lock = "userId:" + uid;
if (!redisLockUtil.tryLock(lock, 2, 2)) {
return ResponseDto.failure("请求频繁");//参数错误
}
RLock lock = RedisLockUtil.lock("userId:" + uid, 2);
try {
KylinPerformanceVo performanceData = dataUtils.getPerformanceVo(payOrderParam.getPerformanceId());
KylinTicketTimesVo ticketTimesData = null;
......@@ -136,16 +136,16 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
}
if (performanceData == null || ticketTimesData == null || ticketData == null) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("参数错误");//参数错误
}
if (!ticketData.getTimeId().equals(payOrderParam.getTimeId()) || !ticketTimesData.getPerformanceId().equals(payOrderParam.getPerformanceId())) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("参数错误");//参数错误List<AdamEntersVo> entersVoList
}
//判断代理
if (!checkAgent(payOrderParam.getAgentId(), ticketData)) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("无权购买");
}
......@@ -161,7 +161,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
if (ticketData.getIsExclusive() == 1) {
memberType = 2;
if (!isMember) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("非会员用户暂不可购买");//没有会员权限
}
} else {
......@@ -169,7 +169,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
// 会员购买逻辑
memberType = 1;
if (!isMember) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("非会员用户暂不可购买");//没有会员权限
}
} else {
......@@ -188,38 +188,38 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
//通用判断时间
if (isMember) {
if (DateUtil.compareStrDay(DateUtil.getNowTime(), memberTimeStart) == -1) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("未开始售卖");//未开始
}
} else {
if (DateUtil.compareStrDay(DateUtil.getNowTime(), timeStart) == -1) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("未开始售卖");//未开始
}
}
if (DateUtil.compareStrDay(DateUtil.getNowTime(), timeEnd) == 1) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("售卖已结束");//已结束
}
//快递票判断
if (payOrderParam.getIsExpress() != null) {
if (payOrderParam.getIsExpress() == 1 && DateUtil.compareStrDay(DateUtil.getNowTime(), timeExpressEnd) == 1) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("已超过快递票截止时间");//快递票不卖
}
if (payOrderParam.getIsExpress() == 1 && payOrderParam.getAddressId().isEmpty()) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("快递票未填写收货地址");//快递票未填写收货地址
}
}
//实名判断
if (isTrueName == 1 && payOrderParam.getEnterIdList().size() <= 0) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("入场人数量错误");//需要实名 未实名
}
if (isTrueName == 1 && payOrderParam.getEnterIdList().size() != payOrderParam.getNumber()) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("入场人数量错误");//入场人数量错误
}
......@@ -227,7 +227,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
int surplusGeneral = dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), -payOrderParam.getNumber());
if (surplusGeneral < 0) {//库存回滚
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("该票种已售罄");//没抢到
} else {
isDownGeneral = true;
......@@ -241,7 +241,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
if (isStudent == 1) {
int age = IDCard.getAgeByIdCard(adamEnters.getIdCard());
if (age > 25) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("年龄不符合");//年龄超了
}
}
......@@ -259,18 +259,18 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
for (int i = 0; i < entersVoList.size(); i++) {
String res1 = orderUtils.judgeOrderLimit(performanceData.getType(), uid, entersVoList.get(i).getIdCard(), payOrderParam.getPerformanceId(), payOrderParam.getTicketId(), performanceLimit, performanceMemberLimit, ticketLimit, ticketMemberLimit, 1, 1, memberType, isTrueName);
if (!res1.equals("")) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure(res1);//乱七八糟异常
}
}
} else {
String res1 = orderUtils.judgeOrderLimit(performanceData.getType(), uid, "", payOrderParam.getPerformanceId(), payOrderParam.getTicketId(), performanceLimit, performanceMemberLimit, ticketLimit, ticketMemberLimit, payOrderParam.getNumber(), payOrderParam.getNumber(), memberType, isTrueName);
if (!res1.equals("")) {
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure(res1);//乱七八糟异常
}
}
lock.unlock();
redisLockUtil.unlock(lock);
return order(payOrderParam, uid, isMember, isTrueName, performanceData, ticketData, entersVoList, isStudent, ticketTimesData);
}
} catch (Exception e) {
......@@ -279,7 +279,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
}
e.printStackTrace();
log.error("Kylin Order Pay Error = " + e.getMessage());
lock.unlock();
redisLockUtil.unlock(lock);
return ResponseDto.failure("下单失败");//乱七八糟异常
}
}
......@@ -602,8 +602,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE)
);
KylinOrderTicketVo orderTicketVo = BsonUtil.toBean(doc, KylinOrderTicketVo.class);
LocalDateTime strTime = orderTicketVo.getChangeDate();
LocalDateTime strTime = orderTicketData.getChangeDate();
dataUtils.delOrderTicketRedis(orderTickets.getOrderTicketsId());
LinkedList<String> sqls = new LinkedList<>();
......@@ -633,34 +632,32 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
public String syncOrder(SyncOrderParam syncOrderParam) {
//支付时间
LocalDateTime now = LocalDateTime.now();
//
// if (!RedisLockUtil.tryLock("order_lock:" + syncOrderParam.getOrder_code(), 240, 240)) {
// return "fail";//参数错误
// }
// RLock lock = RedisLockUtil.lock("order_lock:" + syncOrderParam.getOrder_code(), 240);
String lock = "order_lock:" + syncOrderParam.getOrder_code();
if (!redisLockUtil.tryLock(lock, 240, 240)) {
return "fail";//参数错误
}
String timePay = DateUtil.Formatter.yyyyMMddHHmmss.format(now);
KylinOrderTicketVo orderTicketData = mongoTemplate.findOne(Query.query(Criteria.where("orderCode").is(syncOrderParam.getOrder_code())), KylinOrderTicketVo.class, KylinOrderTicketVo.class.getSimpleName());
if (orderTicketData == null) {
// lock.unlock();
redisLockUtil.unlock(lock);
return "fail";//订单不存在
}
if (orderTicketData.getStatus() != KylinTableStatusConst.ORDER_STATUS0) {
if (orderTicketData.getPayCode().equals(syncOrderParam.getCode()) && orderTicketData.getStatus() == KylinTableStatusConst.ORDER_STATUS1) {
// lock.unlock();
redisLockUtil.unlock(lock);
return "success";//已经支付
}
if (!orderTicketData.getPayCode().equals(syncOrderParam.getCode())) {
// lock.unlock();
redisLockUtil.unlock(lock);
return "fail";//重复支付
}
}
if (orderTicketData.getPriceActual().compareTo(syncOrderParam.getPrice()) != 0) {
// lock.unlock();
redisLockUtil.unlock(lock);
return "fail";//价格不符
}
......@@ -768,6 +765,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
// 大麦回调
sycDamaiOrder(orderTickets.getOrderTicketsId());
redisLockUtil.unlock(lock);
return "success";
}
......@@ -896,12 +894,11 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
public boolean checkOrderTime(String userId) {
List<OrderScriptDto> dtoData = orderTicketsMapper.orderScriptDto(userId);
LinkedList<String> sqls = new LinkedList<>();
for (OrderScriptDto item : dtoData) {
// if (!RedisLockUtil.tryLock("order_lock:" + item.getOrderCode(), 30, 240)) {
// continue;
// }
// RLock lock = redisLockUtil.lock("order_lock:" + item.getOrderCode(), 240);
String lock = "order_lock:" + item.getOrderCode();
if (!redisLockUtil.tryLock(lock, 30, 240)) {
continue;
}
if (item.getStatus() == KylinTableStatusConst.ORDER_STATUS0) {
LocalDateTime now = LocalDateTime.now();
try {
......@@ -935,8 +932,7 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE)
);
KylinOrderTicketVo orderTicketVo = BsonUtil.toBean(doc, KylinOrderTicketVo.class);
LocalDateTime strTime = orderTicketVo.getChangeDate();
LocalDateTime strTime = vo.getChangeDate();
dataUtils.delOrderTicketRedis(orderTickets.getOrderTicketsId());
dataUtils.changeSurplusGeneral(item.getTicketId(), item.getNumber());
......@@ -963,12 +959,12 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
rabbitTemplate.convertSendAndReceive(MQConst.EXCHANGES_LIQUIDNET_SQL_ORDER_CLOSE, MQConst.ROUTING_KEY_SQL_ORDER_CLOSE, SqlMapping.gets(sqls, sqlsDataA, sqlsDataB,sqlsDataC));
} catch (Exception e) {
// lock.unlock();
redisLockUtil.unlock(lock);
e.printStackTrace();
return false;
}
} else {
// lock.unlock();
redisLockUtil.unlock(lock);
}
}
return true;
......
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