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

Commit 92e6f59b authored by 胡佳晨's avatar 胡佳晨

封装库存相关

parent e40f01cf
......@@ -377,8 +377,8 @@ public class KylinPerformancesPartnerServiceImpl extends ServiceImpl<KylinPerfor
KylinTicketStatus ticketStatus = ticketStatusMapper.selectOne(new UpdateWrapper<KylinTicketStatus>().eq("ticket_id", ticketItem.getTicketsId()));
int changeGeneral = ticketStatus.getTotalGeneral() - ticketItem.getTotalGeneral();
int changeExchange = ticketStatus.getTotalGeneral() - ticketItem.getTotalExchange();
redisUtil.hincr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketItem.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL, changeGeneral);
redisUtil.hincr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketItem.getTicketsId(), KylinRedisConst.SURPLUS_EXCHANGE, changeExchange);
dataUtils.changeSurplusGeneral(ticketItem.getTicketsId(),changeGeneral);
dataUtils.changeSurplusExchange(ticketItem.getTicketsId(),changeExchange);
}
//修改 mysql 库存
KylinTicketStatus inventory = new KylinTicketStatus();
......@@ -521,22 +521,10 @@ public class KylinPerformancesPartnerServiceImpl extends ServiceImpl<KylinPerfor
);
}
//票种 库存redis TODO 库存可能会丢
TicketInventoryDto ticketInventoryDto = new TicketInventoryDto();
//票种 库存redis
if (!redisUtil.hHasKey(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL)) {
ticketInventoryDto.setSurplusExchange(ticketStatus.getSurplusExchange());
ticketInventoryDto.setSurplusGeneral(ticketStatus.getTotalGeneral());
ticketInventoryDto.setTicketsId(ticketVo.getTicketsId());
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL, ticketInventoryDto.getSurplusGeneral());
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_EXCHANGE, ticketInventoryDto.getSurplusExchange());
} else {
int surplusGeneral = (int) redisUtil.hget(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL);
int surplusExchange = (int) redisUtil.hget(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_EXCHANGE);
ticketInventoryDto.setSurplusExchange(ticketStatus.getSurplusExchange() - surplusGeneral);
ticketInventoryDto.setSurplusGeneral(ticketStatus.getTotalGeneral() - surplusExchange);
ticketInventoryDto.setTicketsId(ticketVo.getTicketsId());
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL, ticketInventoryDto.getSurplusGeneral());
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_EXCHANGE, ticketInventoryDto.getSurplusExchange());
dataUtils.setSurplusGeneral(ticketVo.getTicketsId(),ticketStatus.getTotalGeneral());
dataUtils.setSurplusExchange(ticketVo.getTicketsId(),ticketStatus.getSurplusExchange());
}
if (ticketVo.getIsMember() == 1) {
......
......@@ -15,6 +15,7 @@ import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.service.impl.partner.KylinTicketTimesPartnerServiceImpl;
import com.liquidnet.service.kylin.service.impl.partner.KylinTicketsPartnerServiceImpl;
import com.liquidnet.service.kylin.utils.DataUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.client.model.ReturnDocument;
......@@ -48,6 +49,9 @@ public class PerformanceVoTask {
@Autowired
private RedisUtil redisUtil;
@Autowired
private DataUtils dataUtils;
@Autowired
private KylinPerformancesMapper performancesMapper;
......@@ -148,7 +152,7 @@ public class PerformanceVoTask {
status10Count += 1;
} else {
//库存判断
int surplusGeneral = (int) redisUtil.hget(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVoItem.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL);
int surplusGeneral = dataUtils.getSurplusGeneral(ticketVoItem.getTicketsId());
if (surplusGeneral > 0) {
status = 6;
......@@ -568,8 +572,8 @@ public class PerformanceVoTask {
ticketVo.setTicket(tickets);
ticketVo.setTicketStatus(ticketStatus);
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_GENERAL, ticketStatus.getSurplusGeneral());
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketVo.getTicketsId(), KylinRedisConst.SURPLUS_EXCHANGE, ticketStatus.getSurplusExchange());
dataUtils.setSurplusExchange(ticketVo.getTicketsId(), ticketStatus.getSurplusExchange());
dataUtils.setSurplusGeneral(ticketVo.getTicketsId(), ticketStatus.getSurplusGeneral());
BasicDBObject objectTicketVo = new BasicDBObject("$set", mongoConverter.convertToMongoType(map));
......
package com.liquidnet.service.kylin.utils;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.entity.KylinBuyNotice;
import com.liquidnet.service.kylin.mapper.KylinBuyNoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,9 +17,80 @@ public class DataUtils {
@Autowired
private KylinBuyNoticeMapper buyNoticeMapper;
public String getBuyNoticeJsonString(List<String> buyNoticeIds){
List<KylinBuyNotice> data = buyNoticeMapper.selectList(new UpdateWrapper<KylinBuyNotice>().in("buy_notice_id",buyNoticeIds));
return JsonUtils.toJson(data);
@Autowired
private RedisUtil redisUtil;
/**
* 根据 购票须知 id 获取 购票须知文案
*
* @param buyNoticeIds 购票须知 数组
* @return 购票须知 json串
*/
public String getBuyNoticeJsonString(List<String> buyNoticeIds) {
List<KylinBuyNotice> data = buyNoticeMapper.selectList(new UpdateWrapper<KylinBuyNotice>().in("buy_notice_id", buyNoticeIds));
return JsonUtils.toJson(data);
}
/**
* 初始化普通库存
*
* @param ticketId 票id
* @param totalGeneral 普通库存
*/
public void setSurplusGeneral(String ticketId, int totalGeneral) {
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_GENERAL, totalGeneral);
}
/**
* 获取普通剩余库存
*
* @param ticketId 票id
* @return 普通剩余库存
*/
public int getSurplusGeneral(String ticketId) {
return (int) redisUtil.hget(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_GENERAL);
}
/**
* 修改普通库存 并 返回修改后的数量
*
* @param ticketId 票id
* @param surplusGeneral 普通库存
* @return 普通剩余库存
*/
public int changeSurplusGeneral(String ticketId, int surplusGeneral) {
return (int) redisUtil.hincr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_GENERAL, surplusGeneral);
}
/**
* 初始化兑换库存
*
* @param ticketId 票id
* @param totalExchange 兑换库存
*/
public void setSurplusExchange(String ticketId, int totalExchange) {
redisUtil.hset(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_EXCHANGE, totalExchange);
}
/**
* 获取兑换剩余库存
*
* @param ticketId 票id
* @return 兑换剩余库存
*/
public int getSurplusExchange(String ticketId) {
return (int) redisUtil.hget(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_EXCHANGE);
}
/**
* 变更兑换库存 并 返回 修改后的数量
*
* @param ticketId 票id
* @param surplusExchange 普通库存
* @return 兑换剩余库存
*/
public int changeSurplusExchange(String ticketId, int surplusExchange) {
return (int) redisUtil.hincr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId, KylinRedisConst.SURPLUS_GENERAL, surplusExchange);
}
}
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