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

Commit d7a65568 authored by jiangxiulong's avatar jiangxiulong

callback

parent 1f5827df
package com.liquidnet.service.platform.controller.express.shunfeng;
import com.liquidnet.service.platform.service.express.shunfeng.PerformancesExpressCallbackServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 演出快递 顺丰推送
* </p>
*
* @author jiangxiulong
* @since 2021-06-29
*/
@Api(tags = "前端-shunfengBack")
@RestController
@RequestMapping("performancesExpress")
public class PerformancesExpressCallbackController {
@Autowired
private PerformancesExpressCallbackServiceImpl performancesExpressServiceImpl;
/**
* 订单状态推送
*/
/**
* 路由推送
*/
/**
* 清单运费推送
*/
}
package com.liquidnet.service.platform.controller.refund;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.platform.service.refund.OrderRefundsCallbackServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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;
/**
* <p>
* 退款回掉
* </p>
*
* @author jiangxiulong
* @since 2021-06-11 6:10 下午
*/
@Api(tags = "前端-退款回调")
@RestController
@RequestMapping("refund")
public class OrderRefundCallbackController {
@Autowired
private OrderRefundsCallbackServiceImpl orderRefundsCallbackServiceImpl;
@PostMapping("apply")
@ApiOperation("超时退款")
@ApiImplicitParams({
@ApiImplicitParam(type = "body", dataType = "String", name = "orderTicketsId", value = "订单ID", required = true),
})
public Boolean refundApply(@RequestParam() String orderTicketsId) {
try {
Boolean res = orderRefundsCallbackServiceImpl.refundApply(orderTicketsId);
if (res) {
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}
@PostMapping("callback")
@ApiOperation("退款回调")
public String refundCallback(RefundCallbackParam refundCallbackParam) {
String result = orderRefundsCallbackServiceImpl.refundCallback(refundCallbackParam);
return result;
}
}
package com.liquidnet.service.platform.service.express.shunfeng;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.param.PerformanceExpressSearchAdminParam;
import com.liquidnet.service.kylin.entity.KylinOrderExpress;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.service.IKylinOrderExpress;
import com.liquidnet.service.platform.utils.ShunfengSignUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
/**
* <p>
* 演出 服务实现类
* </p>
*
* @author liquidnet
* @since 2021-05-05
*/
@Service
@Slf4j
public class PerformancesExpressCallbackServiceImpl extends ServiceImpl<KylinOrderExpressMapper, KylinOrderExpress> implements IKylinOrderExpress {
@Value("${liquidnet.shunfeng.custid}")
private String custid;
@Value("${liquidnet.shunfeng.jCompany}")
private String jCompany;
@Value("${liquidnet.shunfeng.jContact}")
private String jContact;
@Value("${liquidnet.shunfeng.jTel}")
private String jTel;
@Value("${liquidnet.shunfeng.jProvince}")
private String jProvince;
@Value("${liquidnet.shunfeng.jCity}")
private String jCity;
@Value("${liquidnet.shunfeng.jAddress}")
private String jAddress;
@Value("${liquidnet.shunfeng.expressType}")
private Integer expressType;
@Value("${liquidnet.shunfeng.depositumInfo}")
private String depositumInfo;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
private ShunfengSignUtils shunfengSignUtils;
@Autowired
private KylinPerformancesMapper performancesMapper;
@Autowired
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderExpressMapper kylinOrderExpressMapper;
@Autowired
private KylinOrderExpressFeeInfoMapper kylinOrderExpressFeeInfoMapper;
public ResponseDto getFreight(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
List<String> ids = performanceExpressSearchAdminParam.getIds();
Integer[] expressStatus = {KylinTableStatusConst.ORDER_EXPRESS_STATUS1, KylinTableStatusConst.ORDER_EXPRESS_STATUS3};
for (String orderTicketsId : ids) {
KylinOrderExpress orderExpressInfo = kylinOrderExpressMapper.selectOne(
new QueryWrapper<KylinOrderExpress>().eq("order_tickets_id", orderTicketsId)
.notIn("express_status", expressStatus)
);
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
if (null != orderExpressInfo) {
HashMap<String, Object> hBody = new HashMap<>();
hBody.put("jProvince", jProvince);
hBody.put("jCity", jCity);
hBody.put("jAddress", jAddress);
hBody.put("dProvince", "北京市");
hBody.put("dCity", "北京城区");
hBody.put("dAddress", orderInfo.getExpressAddress());
hBody.put("expressType", expressType);
// hBody.put("parcelWeighs", 2.00);
// hBody.put("volume", "10,10,20");
// 生成签名并请求
String result = shunfengSignUtils.generateSignatureAndRequest(hBody, "/public/order/v1/getFreight");
HashMap hashMap = JsonUtils.fromJson(result, HashMap.class);
System.out.println(result);
if (hashMap.get("succ").equals("fail")) {
String msg = (String) hashMap.get("msg");
return ResponseDto.failure(msg);
} else {
/*HashMap resultResult = (HashMap) hashMap.get("result");
List<HashMap> feeList = (List) resultResult.get("feeList");
if (!CollectionUtil.isEmpty(feeList)) {
for (HashMap feeInfo : feeList) {
KylinOrderExpressFeeInfo kylinOrderExpressFeeInfo = new KylinOrderExpressFeeInfo();
String orderExpressFeeInfoId = IDGenerator.nextSnowId();
kylinOrderExpressFeeInfo.setOrderExpressFeeInfoId(orderExpressFeeInfoId);
kylinOrderExpressFeeInfo.setOrderExpressId(orderExpressInfo.getOrderExpressId());
kylinOrderExpressFeeInfo.setType((String) feeInfo.get("type"));
kylinOrderExpressFeeInfo.setName((String) feeInfo.get("name"));
kylinOrderExpressFeeInfo.setValue(new BigDecimal(feeInfo.get("value").toString()));
kylinOrderExpressFeeInfo.setCreatedAt(DateUtil.getNowTime());
kylinOrderExpressFeeInfoMapper.insert(kylinOrderExpressFeeInfo);
}
}*/
}
}
}
return ResponseDto.success();
}
}
package com.liquidnet.service.platform.service.refund;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.UserPathDto;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.mongo.*;
import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.platform.utils.DataUtils;
import com.liquidnet.service.platform.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;
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;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 订单退款表 服务实现类 处理数据 退款后状态的变化
* </p>
*
* @author jiaangxiulong
* @since 2021-05-26
*/
@Slf4j
@Service
public class KylinRefundsStatusServiceImpl {
@Autowired
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderTicketStatusMapper kylinOrderTicketStatusMapper;
@Autowired
private KylinOrderRefundsMapper kylinOrderRefundsMapper;
@Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderRefundsEntitiesMapper kylinOrderRefundsEntitiesMapper;
@Autowired
private KylinOrderTicketRelationsMapper kylinOrderTicketRelationsMapper;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
private MongoConverter mongoConverter;
@Autowired
private DataUtils dataUtils;
@Autowired
private MongoVoUtils mongoVoUtils;
@Autowired
private RabbitTemplate rabbitTemplate;
public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) {
List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
new QueryWrapper<KylinOrderRefundEntities>().eq("order_refunds_id", refundInfo.getOrderRefundsId())
);
List<String> orderTicketEntitiesIdsArr = refundEntities.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
String orderTicketsId = refundInfo.getOrderTicketsId();
KylinOrderTicketRelations orderRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", orderTicketsId)
);
// 更新数据
// 订单状态表
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
int newStatus = 0;
if (refundCallbackParam.getRefund_price() + orderInfo.getPriceRefund().doubleValue() == orderInfo.getPriceActual().doubleValue()) {
newStatus = KylinTableStatusConst.ORDER_STATUS4;
} else {
newStatus = KylinTableStatusConst.ORDER_STATUS6;
}
orderStatusTable.setStatus(newStatus);
orderStatusTable.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketStatusMapper.update(
orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId)
);
// 入场人
double priceActual = orderInfo.getPriceActual().doubleValue();
double priceExpress = orderInfo.getPriceExpress().doubleValue();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
int refundNumber = 0;
for (String entitiesId : orderTicketEntitiesIdsArr) {
KylinOrderTicketEntities EntitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(//已退完成的
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId)
);
BigDecimal refundedPrice = EntitiesInfo.getRefundPrice();
KylinOrderRefundEntities refundEntitiesInfo = kylinOrderRefundsEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderRefundEntities>()
.eq("order_refunds_id", refundInfo.getOrderRefundsId())
.eq("order_ticket_entities_id", entitiesId)
);
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
double priceNew = refundEntitiesInfo.getRefundPrice().doubleValue() + refundedPrice.doubleValue();
int isPayment = 0;
if (priceNew == onePrice) {
isPayment = KylinTableStatusConst.ENTITIES_IS_PAYMENT3;
refundNumber++;
} else {
isPayment = KylinTableStatusConst.ENTITIES_IS_PAYMENT4;
}
entitiesTable.setIsPayment(isPayment);
entitiesTable.setUpdatedAt(LocalDateTime.now());
entitiesTable.setRefundPrice(BigDecimal.valueOf(priceNew));
Integer[] entitiesTableIsPayment = {KylinTableStatusConst.ENTITIES_IS_PAYMENT2, KylinTableStatusConst.ENTITIES_IS_PAYMENT4};
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId)
.in("is_payment", entitiesTableIsPayment)
);
HashMap<String, Object> EntitiesVo = new HashMap<>();
EntitiesVo.put("updatedAt", DateUtil.getNowTime());
EntitiesVo.put("refundPrice", BigDecimal.valueOf(priceNew));
EntitiesVo.put("isPayment", isPayment);
BasicDBObject EntitiesVov = new BasicDBObject("$set", mongoConverter.convertToMongoType(EntitiesVo));
UpdateResult updateResult = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(),
EntitiesVov
);
dataUtils.delOrderTicketEntitiesRedis(entitiesId);
}
// 订单表
double price = orderInfo.getPriceRefund().doubleValue() + refundCallbackParam.getRefund_price();
Integer num = orderInfo.getRefundNumber() + refundNumber;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(BigDecimal.valueOf(price));
update.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
HashMap<String, Object> orderVo = new HashMap<>();
orderVo.put("updatedAt", DateUtil.getNowTime());
orderVo.put("priceRefund", BigDecimal.valueOf(price));
orderVo.put("status", newStatus);
orderVo.put("refundNumber", num);
BasicDBObject orderVov = new BasicDBObject("$set", mongoConverter.convertToMongoType(orderVo));
UpdateResult orderUpdateResult = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderVov
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId, null);
// 退款单完成
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.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update(
kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId())
);
if (refundInfo.getType() == KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY) {
// 退还库存
for (String entitiesId : orderTicketEntitiesIdsArr) {
KylinOrderTicketEntities entitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderTicketEntities>().eq("order_ticket_entities_id", entitiesId)
);
if (entitiesInfo.getIsPayment() == KylinTableStatusConst.ENTITIES_IS_PAYMENT3) {
dataUtils.changeSurplusGeneral(entitiesInfo.getTicketId(), 1);
log.info(UserPathDto.setData("changeBuyInfo", "UserId=" + orderInfo.getUserId() + "idCard=" + entitiesInfo.getEnterIdCode() + " PerformanceId=" + orderRelations.getPerformanceId() + " TicketId=" + entitiesInfo.getTicketId(), "info"));
dataUtils.changeBuyInfo(orderInfo.getUserId(), entitiesInfo.getEnterIdCode(), orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
}
}
}
return true;
}
public Boolean orderTicketRefunding(
KylinOrderTickets orderInfo, String orderTicketsId,
double RefundPriceExpress,
List<String> ticketEntityIds, List<Double> entitiesPrice
) {
if (CollectionUtil.isEmpty(ticketEntityIds)) {
return false;
}
// 基础数据
String authId = "";
String authName = "system_overtime_order_refund";
String reason = "订单支付超时自动退款";
// 本次退款票总金额
double entitiesPriceSum = entitiesPrice.stream().mapToDouble(Double::doubleValue).sum();
// TODO: 2021/5/27 事物 and 部分退款
// 更新数据
// 订单状态表 和 缓存
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId));
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
kylinOrderTicketVo.setStatus(KylinTableStatusConst.ORDER_STATUS3);
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);
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));
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketEntitiesId").is(v)).getQueryObject(),
entitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketEntitiesRedis(v);
}
// 退款明细
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
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");
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.setApplicantId(authId);
kylinOrderRefunds.setApplicantName(authName);
kylinOrderRefunds.setApplicantAt(LocalDateTime.now());
kylinOrderRefunds.setType(1);
kylinOrderRefunds.setReason(reason);
if (RefundPriceExpress > 0 && entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE3);
} else if (RefundPriceExpress > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE2);
} else if (entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1);
}
kylinOrderRefunds.setCreatedAt(LocalDateTime.now());
int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds);
// 退款入场人表
KylinOrderRefundEntities kylinOrderRefundEntities = new KylinOrderRefundEntities();
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);
}
return true;
}
public Boolean userOrderTicketRefunding(
KylinOrderTicketVo orderInfo,
double refundPrice,
String orderEntitiesId,
String reason,
String picList,
String uid,
String username,
int refundCount
) {
try {
LocalDateTime time = LocalDateTime.now();
String strTime = DateUtil.Formatter.yyyyMMddHHmmss.format(time);
// 订单状态表 和 缓存
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3);
orderStatusTable.setUpdatedAt(time);
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
kylinOrderTicketVo.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketVo.setUpdatedAt(DateUtil.Formatter.yyyyMMddHHmmss.format(time));
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVo)));
mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketsId").is(orderInfo.getOrderTicketsId())).getQueryObject(),
orderObject
);
dataUtils.delOrderTicketRedis(orderInfo.getOrderTicketsId());
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderInfo.getOrderTicketsId(), null);
// 订单入场人表 和 缓存
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
entitiesTable.setUpdatedAt(time);
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
kylinOrderTicketEntitiesVo.setUpdatedAt(strTime);
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketEntitiesId").is(orderEntitiesId)).getQueryObject(),
entitiesObject
);
dataUtils.delOrderTicketEntitiesRedis(orderEntitiesId);
// 退款明细
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
String orderRefundsId = IDGenerator.nextSnowId();
kylinOrderRefunds.setOrderRefundsId(orderRefundsId);
kylinOrderRefunds.setOrderTicketsId(orderInfo.getOrderTicketsId());
String orderRefundCode = orderInfo.getOrderCode();
String codeNum = StringUtils.leftPad(String.valueOf(refundCount), 3, "0");
kylinOrderRefunds.setOrderRefundCode(orderRefundCode.concat(codeNum));
kylinOrderRefunds.setPrice(BigDecimal.valueOf(refundPrice));
kylinOrderRefunds.setPriceExpress(orderInfo.getPriceExpress());
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_APPLY);
kylinOrderRefunds.setType(KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY);
kylinOrderRefunds.setApplicantId(uid);
kylinOrderRefunds.setApplicantName(username);
kylinOrderRefunds.setApplicantAt(time);
kylinOrderRefunds.setReason(reason);
if (orderInfo.getPriceExpress().doubleValue() > 0 && refundPrice > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE3);
} else if (orderInfo.getPriceExpress().doubleValue() > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE2);
} else if (refundPrice > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1);
}
kylinOrderRefunds.setCreatedAt(time);
KylinOrderRefundsVoBase orderRefundsVo = new KylinOrderRefundsVoBase();
BeanUtils.copyProperties(kylinOrderRefunds,orderRefundsVo);
orderRefundsVo.setCreatedAt(strTime);
orderRefundsVo.setApplicantAt(strTime);
mongoTemplate.insert(orderRefundsVo, KylinOrderRefundsVoBase.class.getSimpleName());
// 退款入场人表
KylinOrderRefundEntities kylinOrderRefundEntities = new KylinOrderRefundEntities();
String orderRefundsEntitiesId = IDGenerator.nextSnowId();
kylinOrderRefundEntities.setOrderRefundsEntitiesId(orderRefundsEntitiesId);
kylinOrderRefundEntities.setOrderRefundsId(orderRefundsId);
kylinOrderRefundEntities.setRefundPrice(BigDecimal.valueOf(refundPrice));
kylinOrderRefundEntities.setOrderTicketEntitiesId(orderEntitiesId);
kylinOrderRefundEntities.setCreatedAt(time);
KylinOrderRefundEntitiesVo orderRefundEntitiesVo = new KylinOrderRefundEntitiesVo();
BeanUtils.copyProperties(kylinOrderRefundEntities,orderRefundEntitiesVo);
orderRefundEntitiesVo.setCreatedAt(strTime);
mongoTemplate.insert(orderRefundEntitiesVo,KylinOrderRefundEntitiesVo.class.getSimpleName());
//退款图片
KylinOrderRefundPic orderRefundPic = new KylinOrderRefundPic();
orderRefundPic.setRefundPicId(IDGenerator.nextSnowId());
orderRefundPic.setOrderRefundsId(kylinOrderRefunds.getOrderRefundsId());
orderRefundPic.setPicUrl(picList);
orderRefundPic.setCreatedAt(time);
KylinOrderRefundPicVo orderRefundPicVo = new KylinOrderRefundPicVo();
BeanUtils.copyProperties(orderRefundPic,orderRefundPicVo);
orderRefundPicVo.setCreatedAt(strTime);
mongoTemplate.insert(orderRefundPicVo,KylinOrderRefundPicVo.class.getSimpleName());
dataUtils.delOrderRefundVoByOrderId(orderInfo.getOrderTicketsId());
//MQ
LinkedList<String> sqls = new LinkedList<>();
LinkedList<Object[]> sqlsDataA = new LinkedList<>();
LinkedList<Object[]> sqlsDataB = new LinkedList<>();
LinkedList<Object[]> sqlsDataC = new LinkedList<>();
LinkedList<Object[]> sqlsDataD = new LinkedList<>();
LinkedList <Object[]> sqlsDataE = new LinkedList<>();
sqls.add(SqlMapping.get("kylin_order_ticket_status.refund"));
sqls.add(SqlMapping.get("kylin_order_ticket_entities.refund"));
sqls.add(SqlMapping.get("kylin_order_refund.refund"));
sqls.add(SqlMapping.get("kylin_order_refund_entities.refund"));
sqls.add(SqlMapping.get("kylin_order_refund_pic.refund"));
sqlsDataA.add(new Object[]{
orderStatusTable.getStatus(), orderStatusTable.getUpdatedAt(), orderInfo.getOrderTicketsId(), orderInfo.getChangeDate(), orderInfo.getChangeDate()
});
sqlsDataB.add(new Object[]{
entitiesTable.getIsPayment(), entitiesTable.getUpdatedAt(), orderEntitiesId, orderInfo.getChangeDate(), orderInfo.getChangeDate()
});
sqlsDataC.add(new Object[]{
kylinOrderRefunds.getOrderRefundsId(), kylinOrderRefunds.getOrderTicketsId(), kylinOrderRefunds.getOrderRefundCode(),
kylinOrderRefunds.getPrice(), kylinOrderRefunds.getPriceExpress(), kylinOrderRefunds.getStatus(),
kylinOrderRefunds.getType(), kylinOrderRefunds.getApplicantId(), kylinOrderRefunds.getApplicantName(),
kylinOrderRefunds.getApplicantAt(), kylinOrderRefunds.getReason(),
kylinOrderRefunds.getRefundCate(), kylinOrderRefunds.getCreatedAt()
});
sqlsDataD.add(new Object[]{
kylinOrderRefundEntities.getOrderRefundsEntitiesId(), kylinOrderRefundEntities.getOrderRefundsId(), kylinOrderRefundEntities.getRefundPrice(),
kylinOrderRefundEntities.getOrderTicketEntitiesId(), kylinOrderRefundEntities.getCreatedAt()
});
sqlsDataE.add(new Object[]{
orderRefundPic.getOrderRefundsId(), orderRefundPic.getOrderRefundsId(), orderRefundPic.getPicUrl(), orderRefundPic.getCreatedAt()
});
//TODO 生成新QUERY
rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL_ORDER_REFUND, MQConst.ROUTING_KEY_SQL_ORDER_REFUND,
SqlMapping.gets(sqls, sqlsDataA, sqlsDataB, sqlsDataC, sqlsDataD, sqlsDataE));
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}
}
package com.liquidnet.service.platform.service.refund;
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.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dao.KylinOrderTicketEntitiesDao;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.entity.KylinOrderRefunds;
import com.liquidnet.service.kylin.entity.KylinOrderTicketEntities;
import com.liquidnet.service.kylin.entity.KylinOrderTicketRelations;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.service.IKylinOrderRefundsService;
import com.liquidnet.service.platform.utils.DataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* <p>
* 订单退款表 服务实现类 处理逻辑判断
* </p>
*
* @author jiangxiulong
* @since 2021-05-26
*/
@Slf4j
@Service
public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefundsMapper, KylinOrderRefunds> implements IKylinOrderRefundsService {
@Autowired
private KylinRefundsStatusServiceImpl kylinRefundsStatusServiceImpl;
@Autowired
private KylinOrderRefundsMapper kylinOrderRefundsMapper;
@Autowired
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderTicketRelationsMapper kylinOrderTicketRelationsMapper;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
private DataUtils dataUtils;
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());
kylinOrderRefunds.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update(
kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().eq("order_refund_code", refundCallbackParam.getOrder_refund_code())
);
}
return "success";
}
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) {
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)
);
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);
}
}
}
List<String> ticketEntityIds = entitiesList.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
List<Double> entitiesPrice = entitiesList.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getCanRefundedPrice().doubleValue()).collect(Collectors.toList());
boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding(
orderInfo, orderTicketsId,
RefundPriceExpress,
ticketEntityIds, entitiesPrice
);
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) {
dataUtils.changeSurplusGeneral(entitiesInfo.getTicketId(), 1);
dataUtils.changeBuyInfo(orderInfo.getUserId(), entitiesInfo.getEnterIdCode(), orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
}
}
return true;
} else {
return false;
}
}
}
package com.liquidnet.service.platform.utils;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.UserPathDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
/**
* <p>
* 顺丰
* </p>
*
* @author jiangxiulong
* @since 2021-06-24 8:00 下午
*/
@Component
@Slf4j
public class ShunfengSignUtils {
/**
* appId
*/
@Value("${liquidnet.shunfeng.appid}")
private String APP_ID;
/**
* sk
*/
@Value("${liquidnet.shunfeng.sk}")
private String SK;
/**
* url
*/
@Value("${liquidnet.shunfeng.url}")
private String URL;
/**
* 签名有效期(可根据实际业务设定)单位:毫秒
*/
private final static Long CHECK_TIME = 600000L;
/**
* 生成签名并请求
* @param hbody 请求body
* @return
*/
public String generateSignatureAndRequest(HashMap<String, Object> hbody, String url) {
long currentTimeMillis = System.currentTimeMillis(); // 时间戳
String timestamp = currentTimeMillis + "";
hbody.put("companyId", APP_ID);
String body = JsonUtils.toJson(hbody);
// 生成签名
String sign = genSign(timestamp,body);
CloseableHttpClient client = HttpClients.createDefault();
// 请求下单地址
HttpPost httpPost = new HttpPost(URL + url);
// sendAppId(sendAppId需赋值appId)
httpPost.addHeader("sendAppId", APP_ID);
// 时间戳需和获取验签时一致!!!
httpPost.addHeader("timestamp", timestamp);
// 签名
httpPost.addHeader("sign", sign);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
httpPost.addHeader("Accept", "application/json");
// 请求body体需和获取验签时一致且编码UTF8!!!
httpPost.setEntity(new StringEntity(body, "utf-8"));
CloseableHttpResponse response = null;
log.info(UserPathDto.setData("header", "", httpPost.getAllHeaders()));
log.info(UserPathDto.setData("body", "", body));
try {
response = client.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
System.out.println("发送请求成功");
HttpEntity entity = response.getEntity();
// 发送响应且编码UTF8!!!
return EntityUtils.toString(entity, "utf-8");
}
} catch (Exception e) {
System.out.println("发送请求失败");
e.printStackTrace();
} finally {
if (client != null) {
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
/**
* 生成签名
* @param timestamp 时间戳
* @param body 请求body
* @return
*/
private String genSign(String timestamp, String body) {
if (StringUtils.isEmpty(body)) {
body = "";
}
StringBuffer sb = new StringBuffer();
sb.append(body);
sb.append("&sk=").append(SK);
sb.append("&timestamp=").append(timestamp);
byte[] bytes = DigestUtils.sha512(sb.toString());
return Base64.encodeBase64URLSafeString(bytes);
}
/**
* 接收请求且验签(可在控制层调用此方法)
* @param params 接收请求参数
* @param request 接收请求
* @return
*/
public boolean receiveRequestAndCheckSign(String params, HttpServletRequest request) {
// 请求方APPID
String sendAppId = request.getHeader("sendAppId");
// 请求方时间戳
String timestamp = request.getHeader("timestamp");
// 请求方签名
String sign = request.getHeader("sign");
if (StringUtils.isBlank(sendAppId)) {
System.out.println("参数sendAppId不能为空");
return false;
}
if (StringUtils.isBlank(timestamp)) {
System.out.println("参数timestamp不能为空");
return false;
}
if (StringUtils.isBlank(sign)) {
System.out.println("参数sign不能为空");
return false;
}
// 校验签名是否过期
long requestTime = Long.parseLong(timestamp);
long now = System.currentTimeMillis();
if (Math.abs(now - requestTime) > CHECK_TIME) {
System.out.println("签名过期!");
return false;
}
// 请求方参数+请求方时间戳+SK 生成签名
String thisSign = genSign(timestamp, params);
// 获取的签名和请求方签名比较是否一致
if (!thisSign.equals(sign)) {
System.out.println("签名错误");
return false;
}
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