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

Commit 2bd2183a authored by jiangxiulong's avatar jiangxiulong

callback

parent fdaed432
package com.liquidnet.service.kylin.dto.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* 退款回掉参数
* </p>
*
* @author jiangxiulong
* @since 2021-05-31 11:19 上午
*/
@Data
public class RefundCallbackParam implements Serializable {
@ApiModelProperty(value = "状态", example = "")
private Integer status;
private String order_code;
private String code;
private String order_refund_code;
private String refund_code;
private double refund_price;
private String refund_reason;
private String refund_type;
private String refund_id;
private LocalDateTime refund_at;
private String refund_error;
}
......@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dao.OrderRefundDao;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.KylinOrderRefundsVo;
import com.liquidnet.service.kylin.service.impl.admin.KylinOrderRefundsServiceImpl;
import io.swagger.annotations.Api;
......@@ -33,6 +34,13 @@ public class KylinOrderRefundAdminController {
@Autowired
private KylinOrderRefundsServiceImpl kylinOrderRefundsServiceImpl;
@GetMapping("callback")
@ApiOperation("退款回调")
public String refundCallback(@RequestBody RefundCallbackParam refundCallbackParam) {
String result = kylinOrderRefundsServiceImpl.refundCallback(refundCallbackParam);
return result;
}
@GetMapping("{orderRefundId}")
@ApiOperation("详情")
@ApiImplicitParam(type = "path", dataType = "String", name = "orderRefundId", value = "主键id", required = true)
......
......@@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dao.OrderRefundDao;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.KylinOrderRefundsVo;
import com.liquidnet.service.kylin.entity.KylinOrderRefunds;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
......@@ -13,11 +14,14 @@ import com.liquidnet.service.kylin.mapper.KylinOrderRefundsMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketsMapper;
import com.liquidnet.service.kylin.service.IKylinOrderRefundsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
......@@ -27,6 +31,7 @@ import java.util.List;
* @author jiangxiulong
* @since 2021-05-26
*/
@Slf4j
@Service
public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsMapper, KylinOrderRefunds> implements IKylinOrderRefundsService {
@Autowired
......@@ -201,4 +206,49 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
}
return pageInfoTmp;
}
}
public String refundCallback(RefundCallbackParam refundCallbackParam) {
KylinOrderRefunds refundInfo = kylinOrderRefundsMapper.selectOne(
new UpdateWrapper<KylinOrderRefunds>()
.eq("order_refund_code", refundCallbackParam.getOrder_refund_code())
);
if (refundInfo == null) {
log.info("Failed:{}.RefundController refundCallback: 退款订单查询失败,编号{}", "KylinOrderRefundsServiceImplRefundCallback", refundCallbackParam.getOrder_refund_code());
return "fail";
}
if (refundInfo.getStatus() == KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL) {
log.info("Failed:{}.RefundController refundCallback: 退款订单已取消,编号{}", "KylinOrderRefundsServiceImplRefundCallback", refundCallbackParam.getOrder_refund_code());
return "fail";
}
if (refundInfo.getStatus() == KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED) {
log.info("Failed:{}.RefundController refundCallback: 退款订单已退款,编号{}", "KylinOrderRefundsServiceImplRefundCallback", refundCallbackParam.getOrder_refund_code());
return "success";
}
Integer status = refundCallbackParam.getStatus();
if (1 == status) { // 退款成功
boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunded(refundCallbackParam, refundInfo);
if (res) {
return "success";
} else {
return "fail";
}
}
if (0 == status) { // 退款失败
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_ERROR);
kylinOrderRefunds.setRefundCode(refundCallbackParam.getRefund_code());
kylinOrderRefunds.setRefundType(refundCallbackParam.getRefund_type());
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at());
kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error());
kylinOrderRefundsMapper.update(
kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().eq("order_refund_code", refundCallbackParam.getOrder_refund_code())
);
}
return "success";
}
}
\ No newline at end of file
......@@ -7,7 +7,9 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.entity.*;
......@@ -29,6 +31,7 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import sun.security.krb5.internal.Ticket;
import java.awt.print.Book;
import java.math.BigDecimal;
......@@ -417,4 +420,83 @@ public class KylinRefundsStatusServiceImpl {
return true;
}
public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) {
String orderTicketEntitiesIds = refundInfo.getOrderTicketEntitiesIds();
String[] orderTicketEntitiesIdsArr = orderTicketEntitiesIds.split(",");
Integer EntitiesIdsCount = orderTicketEntitiesIdsArr.length;
String orderTicketsId = refundInfo.getOrderTicketsId();
// 更新数据
// 订单状态表
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new UpdateWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
int newStatus = 0;
if (EntitiesIdsCount + orderInfo.getRefundNumber() == orderInfo.getNumber()) {
newStatus = KylinTableStatusConst.ORDER_STATUS4;
} else {
newStatus = KylinTableStatusConst.ORDER_STATUS6;
}
orderStatusTable.setStatus(newStatus);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_ticket_status_id", orderTicketsId));
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
kylinOrderTicketVo.setStatus(newStatus);
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVo)));
Document orderDoc = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
// 入场人
for (String entitiesId : orderTicketEntitiesIdsArr) {
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
// TODO: 2021/5/27 事物 and 部分退款
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT2)
);
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(),
entitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketEntitiesRedis(entitiesId);
}
// 退款单完成
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED);
kylinOrderRefunds.setRefundCode(refundCallbackParam.getRefund_code());
kylinOrderRefunds.setRefundType(refundCallbackParam.getRefund_type());
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at());
kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error());
kylinOrderRefundsMapper.update(
kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId())
);
if (refundInfo.getType() == KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY) {
// 退还库存
for (String entitiesId : orderTicketEntitiesIdsArr) {
dataUtils.changeSurplusGeneral(entitiesId, 1);
}
}
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