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

Commit e4923cc6 authored by jiangxiulong's avatar jiangxiulong

超时支付

parent 8561c903
......@@ -48,6 +48,8 @@ public class KylinOrderTicketEntitiesVo implements Serializable, Cloneable {
private LocalDateTime changeDate;
private BigDecimal canRefundedPrice;
public BigDecimal getRefundPrice() {
return refundPrice==null?BigDecimal.valueOf(0.00):refundPrice;
}
......
......@@ -8,13 +8,14 @@ import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.vo.mongo.*;
import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderRefundsVo;
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 com.mongodb.BasicDBObject;
import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.client.model.ReturnDocument;
import com.mongodb.client.result.UpdateResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.bson.Document;
......@@ -22,7 +23,6 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
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.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
......@@ -44,18 +44,6 @@ import java.util.List;
@Service
public class KylinRefundsStatusServiceImpl {
@Autowired
private KylinOrderTicketStatusMapper kylinOrderTicketStatusMapper;
@Autowired
private KylinOrderRefundsMapper kylinOrderRefundsMapper;
@Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderRefundsEntitiesMapper kylinOrderRefundsEntitiesMapper;
@Autowired
MongoTemplate mongoTemplate;
......@@ -68,7 +56,7 @@ public class KylinRefundsStatusServiceImpl {
private RabbitTemplate rabbitTemplate;
public Boolean orderTicketRefunding(
KylinOrderTickets orderInfo, String orderTicketsId,
KylinOrderTicketVo orderInfo, String orderTicketsId,
double RefundPriceExpress,
List<String> ticketEntityIds, List<Double> entitiesPrice
) {
......@@ -82,42 +70,47 @@ public class KylinRefundsStatusServiceImpl {
// 本次退款票总金额
double entitiesPriceSum = entitiesPrice.stream().mapToDouble(Double::doubleValue).sum();
// TODO: 2021/5/27 事物 and 部分退款
// 更新数据
// 订单状态表 和 缓存
LocalDateTime nowTime = LocalDateTime.now();
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime);
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId));
orderStatusTable.setUpdatedAt(nowTime);
/*kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId));*/
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
kylinOrderTicketVo.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketVo.setUpdatedAt(nowTimeStr);
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVo)));
Document orderDoc = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
UpdateResult orderResult = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
orderObject
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId, null);
// 订单入场人表 和 缓存
for (String v : ticketEntityIds) {
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", v));
entitiesTable.setUpdatedAt(nowTime);
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
kylinOrderTicketEntitiesVo.setUpdatedAt(nowTimeStr);
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
for (String v : ticketEntityIds) {
/*kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", v));*/
UpdateResult entitiesResult = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketEntitiesId").is(v)).getQueryObject(),
entitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
entitiesObject
);
dataUtils.delOrderTicketEntitiesRedis(v);
}
......@@ -126,24 +119,16 @@ public class KylinRefundsStatusServiceImpl {
String orderRefundsId = IDGenerator.nextSnowId();
kylinOrderRefunds.setOrderRefundsId(orderRefundsId);
kylinOrderRefunds.setOrderTicketsId(orderTicketsId);
Integer refundCount = kylinOrderRefundsMapper.selectCount(
new QueryWrapper<KylinOrderRefunds>()
.eq("order_tickets_id", orderTicketsId)
);
String orderRefundCode = orderInfo.getOrderCode();
String codeNum = StringUtils.leftPad(String.valueOf(refundCount), 3, "0");
String codeNum = StringUtils.leftPad(String.valueOf(5), 3, "0");
kylinOrderRefunds.setOrderRefundCode(orderRefundCode.concat(codeNum));
kylinOrderRefunds.setPrice(BigDecimal.valueOf(entitiesPriceSum));
kylinOrderRefunds.setPriceExpress(BigDecimal.valueOf(RefundPriceExpress));
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_APPLY);
kylinOrderRefunds.setType(KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY);
kylinOrderRefunds.setType(KylinTableStatusConst.ORDER_REFUND_TYPE_AUTO);
kylinOrderRefunds.setApplicantId(authId);
kylinOrderRefunds.setApplicantName(authName);
kylinOrderRefunds.setApplicantAt(LocalDateTime.now());
kylinOrderRefunds.setType(1);
kylinOrderRefunds.setApplicantAt(nowTime);
kylinOrderRefunds.setReason(reason);
if (RefundPriceExpress > 0 && entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE3);
......@@ -152,19 +137,29 @@ public class KylinRefundsStatusServiceImpl {
} else if (entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1);
}
kylinOrderRefunds.setCreatedAt(LocalDateTime.now());
int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds);
kylinOrderRefunds.setCreatedAt(nowTime);
/*int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds);*/
KylinOrderRefundsVo orderRefundsVo = new KylinOrderRefundsVo();
BeanUtils.copyProperties(kylinOrderRefunds,orderRefundsVo);
mongoTemplate.insert(orderRefundsVo, KylinOrderRefundsVo.class.getSimpleName());
// 退款入场人表
KylinOrderRefundEntities kylinOrderRefundEntities = new KylinOrderRefundEntities();
kylinOrderRefundEntities.setOrderRefundsId(orderRefundsId);
kylinOrderRefundEntities.setCreatedAt(LocalDateTime.now());
for (int i = 0; i <= ticketEntityIds.size() - 1; i++) {
String orderRefundsEntitiesId = IDGenerator.nextSnowId();
kylinOrderRefundEntities.setOrderRefundsEntitiesId(orderRefundsEntitiesId);
kylinOrderRefundEntities.setOrderRefundsId(orderRefundsId);
kylinOrderRefundEntities.setRefundPrice(BigDecimal.valueOf(entitiesPrice.get(i)));
kylinOrderRefundEntities.setOrderTicketEntitiesId(ticketEntityIds.get(i));
kylinOrderRefundEntities.setCreatedAt(LocalDateTime.now());
int rowsR = kylinOrderRefundsEntitiesMapper.insert(kylinOrderRefundEntities);
/*int rowsR = kylinOrderRefundsEntitiesMapper.insert(kylinOrderRefundEntities);*/
KylinOrderRefundEntitiesVo orderRefundEntitiesVo = new KylinOrderRefundEntitiesVo();
BeanUtils.copyProperties(kylinOrderRefundEntities,orderRefundEntitiesVo);
mongoTemplate.insert(orderRefundEntitiesVo,KylinOrderRefundEntitiesVo.class.getSimpleName());
}
return true;
......
package com.liquidnet.service.kylin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dao.KylinOrderTicketEntitiesDao;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.service.IKylinOrderRefundsService;
......@@ -16,7 +16,6 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -35,18 +34,6 @@ public class OrderRefundOvertimeServiceImpl extends ServiceImpl<KylinOrderRefund
@Autowired
private KylinRefundsStatusServiceImpl kylinRefundsStatusServiceImpl;
@Autowired
private KylinOrderRefundsMapper kylinOrderRefundsMapper;
@Autowired
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderTicketRelationsMapper kylinOrderTicketRelationsMapper;
@Autowired
MongoTemplate mongoTemplate;
......@@ -54,51 +41,19 @@ public class OrderRefundOvertimeServiceImpl extends ServiceImpl<KylinOrderRefund
private DataUtils dataUtils;
public Boolean refundApply(String orderTicketsId) {
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketRelations orderRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", orderTicketsId)
);
// 传的快递费不能大于实际的快递费=(支付的快递费-已退的快递费)
Double refundPriceExpressSum = kylinOrderRefundsMapper.RefundPriceExpressSum(// 已退快递费
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL
);
if (null == refundPriceExpressSum) {
refundPriceExpressSum = 0.0;
}
Double RefundPriceExpress = orderInfo.getPriceExpress().doubleValue() - refundPriceExpressSum;
// 查询订单入场人
List<KylinOrderTicketEntitiesDao> entitiesListTemp = kylinOrderTicketEntitiesMapper.getOvertimeRefundEntitiesList(orderTicketsId);
List<KylinOrderTicketEntitiesDao> entitiesList = new ArrayList<>();
if(entitiesListTemp.size() > 0) {
KylinOrderTicketVo orderInfo = dataUtils.getOrderTicketVo(orderTicketsId);
// 快递费 未进行判断
Double RefundPriceExpress = orderInfo.getPriceExpress().doubleValue();
double priceActual = orderInfo.getPriceActual().doubleValue();
double priceExpress = orderInfo.getPriceExpress().doubleValue();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderInfo.getOrderTicketsId())
// .ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
// 查询订单入场人
List<KylinOrderTicketEntitiesVo> entitiesList = orderInfo.getEntitiesVoList();
if (!CollectionUtil.isEmpty(entitiesList)) {
int allEntitiesCount = entitiesList.size();// 总入场人数量 排出未付款的 用来计算单入场人的价格
double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
for (KylinOrderTicketEntitiesDao entities : entitiesListTemp) {
Double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 包含退款中
orderInfo.getOrderTicketsId(),
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
entities.getOrderTicketEntitiesId()
);
double canRefundedPrice;
if (null != refundedPrice) {
canRefundedPrice = onePrice - refundedPrice;
} else {
canRefundedPrice = onePrice;
}
entities.setCanRefundedPrice(BigDecimal.valueOf(canRefundedPrice));
if (canRefundedPrice > 0) { // 退款中但是可退款金额为0不展示
entitiesList.add(entities);
}
for (KylinOrderTicketEntitiesVo entities : entitiesList) {
entities.setCanRefundedPrice(BigDecimal.valueOf(onePrice));
}
}
......@@ -112,14 +67,10 @@ public class OrderRefundOvertimeServiceImpl extends ServiceImpl<KylinOrderRefund
);
if (res) {
// 超时直接退还库存
for (String entitiesId : ticketEntityIds) {
KylinOrderTicketEntities entitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderTicketEntities>().eq("order_ticket_entities_id", entitiesId)
);
if (entitiesInfo.getIsPayment() == KylinTableStatusConst.ENTITIES_IS_PAYMENT3) {
for (KylinOrderTicketEntitiesVo entitiesInfo : entitiesList) {
// 因固定状态为未支付 所以无需判断 entitiesInfo.getIsPayment() == KylinTableStatusConst.ENTITIES_IS_PAYMENT3
dataUtils.changeSurplusGeneral(entitiesInfo.getTicketId(), 1);
dataUtils.changeBuyInfo(orderInfo.getUserId(), entitiesInfo.getEnterIdCode(), orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
}
dataUtils.changeBuyInfo(orderInfo.getUserId(), entitiesInfo.getEnterIdCode(), orderInfo.getPerformanceId(), entitiesInfo.getTicketId(), -1);
}
return true;
} else {
......
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