商品模块代码提交
This commit is contained in:
parent
6e2e73fdcd
commit
23f4e36bda
|
|
@ -1,15 +1,18 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.dto.points.OrderDeductionPointsDTO;
|
||||
import com.czg.account.entity.MemberPoints;
|
||||
import com.czg.account.param.ConsumeAwardPointsParam;
|
||||
import com.czg.account.param.MemberPointsParam;
|
||||
import com.czg.account.param.PayedDeductPointsParam;
|
||||
import com.czg.account.service.MemberPointsService;
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -36,4 +39,65 @@ public class MemberPointsController {
|
|||
return CzgResult.success(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 001-会员积分账户信息
|
||||
*/
|
||||
@GetMapping("user-points")
|
||||
public CzgResult<MemberPoints> getMemberPoints(@RequestParam Long userId) {
|
||||
MemberPoints data = memberPointsService.getMemberPoints(userId);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 002-获取订单可用积分及抵扣金额(支付页面使用)
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param orderAmount 订单金额
|
||||
*/
|
||||
@GetMapping("calc-usable-points")
|
||||
public CzgResult<OrderDeductionPointsDTO> getMemberUsablePoints(@RequestParam Long userId, @RequestParam BigDecimal orderAmount) {
|
||||
OrderDeductionPointsDTO usablePoints = memberPointsService.getMemberUsablePoints(userId, orderAmount);
|
||||
return CzgResult.success(usablePoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* 004-根据抵扣金额计算所需积分
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param orderAmount 订单金额
|
||||
* @param deductionAmount 抵扣金额
|
||||
*/
|
||||
@GetMapping("calc-used-points")
|
||||
public CzgResult<Integer> calcUsedPoints(@RequestParam Long userId, @RequestParam BigDecimal orderAmount, @RequestParam BigDecimal deductionAmount) {
|
||||
int points = memberPointsService.calcUsedPoints(userId, orderAmount, deductionAmount);
|
||||
return CzgResult.success(points);
|
||||
}
|
||||
|
||||
/**
|
||||
* 003-根据积分计算可抵扣金额
|
||||
*/
|
||||
@GetMapping("calc-deduction-amount")
|
||||
public CzgResult<BigDecimal> calcDeductionAmount(@RequestParam Long userId, @RequestParam BigDecimal orderAmount, @RequestParam Integer points) {
|
||||
BigDecimal deductionAmount = memberPointsService.calcDeductionAmount(userId, orderAmount, points);
|
||||
return CzgResult.success(deductionAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 005-支付完成扣减积分(支付成功回调中使用)
|
||||
*/
|
||||
@PostMapping("payed-deduct-points")
|
||||
public CzgResult<Boolean> deductPoints(@RequestBody PayedDeductPointsParam param) {
|
||||
boolean ret = memberPointsService.deductPoints(param.getUserId(), param.getPoints(), param.getContent(), param.getOrderId());
|
||||
return CzgResult.success(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 006-消费赠送积分(支付成功回调中使用)
|
||||
*/
|
||||
@PostMapping("consume-award-points")
|
||||
public CzgResult<Void> consumeAwardPoints(@RequestBody ConsumeAwardPointsParam param) {
|
||||
memberPointsService.consumeAwardPoints(param.getUserId(), param.getOrderId());
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -62,10 +62,13 @@ public class UMemberPointsController {
|
|||
|
||||
/**
|
||||
* 003-根据积分计算可抵扣金额
|
||||
* @param userId 用户id
|
||||
* @param orderAmount 订单金额
|
||||
* @param points 使用积分
|
||||
*/
|
||||
@GetMapping("calc-deduction-amount")
|
||||
public CzgResult<BigDecimal> calcDeductionAmount(@RequestParam Long memberId, @RequestParam BigDecimal orderAmount, @RequestParam Integer points) {
|
||||
BigDecimal deductionAmount = memberPointsService.calcDeductionAmount(memberId, orderAmount, points);
|
||||
public CzgResult<BigDecimal> calcDeductionAmount(@RequestParam Long userId, @RequestParam BigDecimal orderAmount, @RequestParam Integer points) {
|
||||
BigDecimal deductionAmount = memberPointsService.calcDeductionAmount(userId, orderAmount, points);
|
||||
return CzgResult.success(deductionAmount);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.czg.mq;
|
|||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.config.RabbitConstants;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.order.service.MqLogService;
|
||||
|
|
@ -58,4 +60,24 @@ public class OrderMqListener {
|
|||
mqLogService.save(mqLog);
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_REFUND_QUEUE})
|
||||
public void orderStockReturn(String jsonObjStr) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
log.info("接收到订单退款返还库存消息:{}", jsonObjStr);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_REFUND_QUEUE).setMsg(jsonObjStr).setType("orderStockReturn").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
try {
|
||||
JSONObject data = JSON.parseObject(jsonObjStr);
|
||||
orderInfoRpcService.orderRefundCallback(data);
|
||||
} catch (Exception e) {
|
||||
log.error("订单退款返还库存失败", e);
|
||||
String errorInfo = ExceptionUtil.stacktraceToString(e);
|
||||
mqLog.setErrInfo(errorInfo);
|
||||
mqLog.setDuration(DateUtil.date().getTime() - startTime);
|
||||
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
|
||||
mqLogService.save(mqLog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class RabbitPublisher {
|
|||
* @param refundMap Map <Long,BigDecimal> 商品Id,退单数量
|
||||
*/
|
||||
public void sendOrderRefundMsg(String refundMap) {
|
||||
sendMsg(RabbitConstants.Queue.ORDER_STOCK_QUEUE, refundMap);
|
||||
sendMsg(RabbitConstants.Queue.ORDER_REFUND_QUEUE, refundMap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.czg.order.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.vo.HandoverCategoryListVo;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
|
||||
|
|
@ -148,6 +149,13 @@ public interface OrderInfoRpcService {
|
|||
*/
|
||||
void orderCancelCallback(Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款回调 返还商品库存及耗材库存
|
||||
*
|
||||
* @param data k-商品id v-数量
|
||||
*/
|
||||
void orderRefundCallback(JSONObject data);
|
||||
|
||||
/**
|
||||
* 订单交班回调 发送答应交班小票消息至MQ
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,4 +28,11 @@ public interface ProductRpcService {
|
|||
* @param dataList 库存恢复数据
|
||||
*/
|
||||
void orderCancelRecoverStock(Long shopId, Long orderId, List<Map<String, Object>> dataList);
|
||||
|
||||
/**
|
||||
* 订单退菜或退款后回退库存
|
||||
*
|
||||
* @param dataList 库存恢复数据
|
||||
*/
|
||||
void orderRefundReturnStock(List<Map<String, Object>> dataList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.czg.service.order.service.impl;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.vo.HandoverCategoryListVo;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
|
|
@ -23,10 +24,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 订单Rpc ServiceImpl
|
||||
|
|
@ -182,6 +180,28 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderRefundCallback(JSONObject data) {
|
||||
Set<String> keys = data.keySet();
|
||||
// 封装扣减库存数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
Long productId = Convert.toLong(key);
|
||||
BigDecimal num = data.getBigDecimal(key);
|
||||
Map<String, Object> row = new HashMap<>(2);
|
||||
data.put("productId", productId);
|
||||
data.put("num", num);
|
||||
dataList.add(row);
|
||||
}
|
||||
try {
|
||||
// 调用商品服务回退库存
|
||||
productRpcService.orderRefundReturnStock(dataList);
|
||||
} catch (Exception e) {
|
||||
log.error("调用商品服务回退库存", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHandoverReceiptPrintMsgToMq(Long handoverRecordId) {
|
||||
rabbitPublisher.sendHandoverPrintMsg(Convert.toStr(handoverRecordId));
|
||||
|
|
|
|||
|
|
@ -163,4 +163,60 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
|||
}
|
||||
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderRefundReturnStock(List<Map<String, Object>> dataList) {
|
||||
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
Long shopId = null;
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
|
||||
// 查询商品绑定耗材信息
|
||||
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
|
||||
if (CollUtil.isEmpty(relationList)) {
|
||||
continue;
|
||||
}
|
||||
for (ProdConsRelation prodConsRelation : relationList) {
|
||||
// 耗材id
|
||||
Long consInfoId = prodConsRelation.getConsInfoId();
|
||||
// 耗材消耗数量
|
||||
BigDecimal surplusStock = prodConsRelation.getSurplusStock();
|
||||
if (surplusStock == null) {
|
||||
continue;
|
||||
}
|
||||
// 实际消耗数量 = 耗材消耗数量 * 商品购买数量
|
||||
surplusStock = NumberUtil.mul(surplusStock, dto.getNum());
|
||||
ConsInfo consInfo = consInfoMapper.selectOneById(consInfoId);
|
||||
if (consInfo == null) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal stockNumber = consInfo.getStockNumber();
|
||||
consInfo.setStockNumber(NumberUtil.add(stockNumber, surplusStock));
|
||||
// 更新耗材库存数量
|
||||
consInfoMapper.update(consInfo);
|
||||
// 插入耗材流水记录
|
||||
ConsStockFlow consStockFlow = new ConsStockFlow();
|
||||
consStockFlow.setShopId(consInfo.getShopId());
|
||||
consStockFlow.setInOutType(InOutTypeEnum.IN.value());
|
||||
consStockFlow.setInOutItem(InOutItemEnum.ORDER_IN.value());
|
||||
consStockFlow.setInOutDate(LocalDate.now());
|
||||
consStockFlow.setConId(consInfo.getId());
|
||||
consStockFlow.setConName(consInfo.getConName());
|
||||
consStockFlow.setUnitName(consInfo.getConUnit());
|
||||
consStockFlow.setBeforeNumber(stockNumber);
|
||||
consStockFlow.setInOutNumber(surplusStock);
|
||||
consStockFlow.setAfterNumber(consInfo.getStockNumber());
|
||||
consStockFlow.setSubTotal(NumberUtil.mul(surplusStock, consInfo.getPrice()));
|
||||
consStockFlow.setProductId(dto.getProductId());
|
||||
// consStockFlow.setSkuId(0L);
|
||||
// TODO 需要订单id
|
||||
// consStockFlow.setOrderId(orderId);
|
||||
shopId = consInfo.getShopId();
|
||||
consStockFlowMapper.insert(consStockFlow);
|
||||
}
|
||||
}
|
||||
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue