商品列表 结构
耗材库存 列表接口 耗材 库存预警值推送更新 cons.info.change.queue
This commit is contained in:
@@ -9,6 +9,7 @@ import com.czg.product.param.ConsSubUnitParam;
|
||||
import com.czg.product.service.ConsInfoService;
|
||||
import com.czg.product.service.ShopSyncService;
|
||||
import com.czg.product.vo.ConsStatisticsVo;
|
||||
import com.czg.product.vo.ConsStockRecord;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.AssertUtil;
|
||||
@@ -44,18 +45,25 @@ public class ConsInfoController {
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("page")
|
||||
@OperationLog("耗材信息-分页")
|
||||
//@SaAdminCheckPermission("consInfo:page")
|
||||
public CzgResult<Page<ConsInfoDTO>> getConsInfoPage(ConsInfoDTO param) {
|
||||
Page<ConsInfoDTO> data = consInfoService.getConsInfoPage(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@GetMapping("consStock")
|
||||
public CzgResult<List<ConsStockRecord>> getConsStockList(Long shopId) {
|
||||
return CzgResult.success(consInfoService.getConsStockList(shopId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@OperationLog("耗材信息-列表")
|
||||
//@SaAdminCheckPermission("consInfo:list")
|
||||
public CzgResult<List<ConsInfoDTO>> getConsInfoList(ConsInfoDTO param) {
|
||||
List<ConsInfoDTO> data = consInfoService.getConsInfoList(param);
|
||||
@@ -68,7 +76,6 @@ public class ConsInfoController {
|
||||
* @param id 耗材信息id
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@OperationLog("耗材信息-详情")
|
||||
//@SaAdminCheckPermission("consInfo:info")
|
||||
public CzgResult<ConsInfoDTO> getConsInfoById(@PathVariable("id") Long id) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
@@ -164,21 +171,6 @@ public class ConsInfoController {
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款退回开关
|
||||
*
|
||||
* @param id 耗材信息id
|
||||
*/
|
||||
@PostMapping("onOffIsRefundStock")
|
||||
@OperationLog("耗材信息-退款退回开关")
|
||||
//@SaAdminCheckPermission("consInfo:on-off")
|
||||
public CzgResult<Void> onOffIsRefundStock(@RequestParam Long id, @RequestParam Integer isRefundStockConsInfo) {
|
||||
//效验数据
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
AssertUtil.isNull(isRefundStockConsInfo, "退款退回开关值不能为空");
|
||||
consInfoService.isRefundStockConsInfo(id, isRefundStockConsInfo);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑副单位
|
||||
@@ -200,7 +192,6 @@ public class ConsInfoController {
|
||||
* 统计
|
||||
*/
|
||||
@GetMapping("statistics")
|
||||
@OperationLog("耗材信息-统计")
|
||||
//@SaAdminCheckPermission("consInfo:info")
|
||||
public CzgResult<ConsStatisticsVo> getConsInfoById(ConsInfoParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
|
||||
@@ -30,6 +30,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -83,7 +84,7 @@ public class ProductController {
|
||||
*/
|
||||
@GetMapping("list")
|
||||
@OperationLog("商品-列表")
|
||||
public CzgResult<Map<String, Object>> getProductList(@RequestParam(required = false) Long categoryId) {
|
||||
public CzgResult<List<ProductDTO>> getProductList(@RequestParam(required = false) Long categoryId) {
|
||||
return CzgResult.success(productService.getProductCacheList(StpKit.USER.getShopId(), categoryId));
|
||||
}
|
||||
|
||||
@@ -231,7 +232,6 @@ public class ProductController {
|
||||
@PostMapping("reportDamage")
|
||||
@OperationLog("商品-报损")
|
||||
public CzgResult<Void> reportDamage(@RequestBody ProductReportDamageParam param) {
|
||||
//TODO 报损功能
|
||||
ValidatorUtil.validateEntity(param, DefaultGroup.class);
|
||||
productService.reportDamage(param);
|
||||
return CzgResult.success();
|
||||
|
||||
@@ -125,6 +125,16 @@ public class RabbitConfig {
|
||||
public Binding bindingProductInfoChange(Queue productInfoChangeQueue, DirectExchange exchange) {
|
||||
return BindingBuilder.bind(productInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE);
|
||||
}
|
||||
//------------------------------------------------------ 耗材信息更新
|
||||
@Bean
|
||||
public Queue consInfoChangeQueue() {
|
||||
return new Queue(activeProfile + "-" + RabbitConstants.Queue.CONS_INFO_CHANGE_QUEUE, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding bindingConsInfoChange(Queue consInfoChangeQueue, DirectExchange exchange) {
|
||||
return BindingBuilder.bind(consInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.CONS_INFO_CHANGE_QUEUE);
|
||||
}
|
||||
|
||||
//------------------------------------------------------ 订单退款
|
||||
@Bean
|
||||
|
||||
@@ -19,6 +19,7 @@ public interface RabbitConstants {
|
||||
public static final String ORDER_HANDOVER_PRINT_QUEUE = "order.handover.print.queue";
|
||||
public static final String CALL_TABLE_QUEUE = "call.table.print.queue";
|
||||
public static final String PRODUCT_INFO_CHANGE_QUEUE = "product.info.change.queue";
|
||||
public static final String CONS_INFO_CHANGE_QUEUE = "cons.info.change.queue";
|
||||
|
||||
/**
|
||||
* 订单商品状态队列
|
||||
|
||||
@@ -102,6 +102,15 @@ public class RabbitPublisher {
|
||||
sendMsg(RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE, shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品信息变动消息
|
||||
*
|
||||
* @param shopId 店铺id
|
||||
*/
|
||||
public void sendConsInfoChangeMsg(String shopId) {
|
||||
sendMsg(RabbitConstants.Queue.CONS_INFO_CHANGE_QUEUE, shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排队叫号小票打印
|
||||
*
|
||||
|
||||
@@ -76,10 +76,6 @@ public class ConsInfoDTO implements Serializable {
|
||||
* 是否检测耗材: 1 检测 0 不检测
|
||||
*/
|
||||
private Integer isStock;
|
||||
/**
|
||||
* 是否退款退回: 1 退回 0 不退回
|
||||
*/
|
||||
private Integer isRefundStock;
|
||||
/**
|
||||
* 第二单位
|
||||
*/
|
||||
|
||||
@@ -41,6 +41,10 @@ public class ProdConsRelationDTO implements Serializable {
|
||||
*/
|
||||
@NotNull(message = "使用数量不能为空", groups = DefaultGroup.class)
|
||||
private BigDecimal surplusStock;
|
||||
/**
|
||||
* 耗材预警值
|
||||
*/
|
||||
private BigDecimal conWarning;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -69,10 +69,6 @@ public class ConsInfo implements Serializable {
|
||||
* 是否检测耗材: 1 检测 0 不检测
|
||||
*/
|
||||
private Integer isStock;
|
||||
/**
|
||||
* 是否退款退回: 1 退回 0 不退回
|
||||
*/
|
||||
private Integer isRefundStock;
|
||||
/**
|
||||
* 第二单位
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.czg.product.entity.ConsInfo;
|
||||
import com.czg.product.param.ConsInfoParam;
|
||||
import com.czg.product.param.ConsSubUnitParam;
|
||||
import com.czg.product.vo.ConsStatisticsVo;
|
||||
import com.czg.product.vo.ConsStockRecord;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
@@ -33,6 +34,9 @@ public interface ConsInfoService extends IService<ConsInfo> {
|
||||
*/
|
||||
List<ConsInfoDTO> getConsInfoList(ConsInfoDTO param);
|
||||
|
||||
|
||||
List<ConsStockRecord> getConsStockList(Long shopId);
|
||||
|
||||
/**
|
||||
* 获取耗材信息详情
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.czg.product.vo.ConsCheckStockRecordVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,7 @@ public interface ConsStockFlowService extends IService<ConsStockFlow> {
|
||||
|
||||
/**
|
||||
* 获取耗材库存变动记录
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 分页数据
|
||||
*/
|
||||
@@ -73,7 +75,16 @@ public interface ConsStockFlowService extends IService<ConsStockFlow> {
|
||||
|
||||
/**
|
||||
* 保存库存变动记录
|
||||
*
|
||||
* @param entity 库存变动记录实体
|
||||
*/
|
||||
void saveFlow(ConsStockFlow entity);
|
||||
void saveFlow(ConsStockFlow entity, BigDecimal conWarning);
|
||||
|
||||
/**
|
||||
* 发送库存消息
|
||||
*
|
||||
* @param entity 库存变动记录实体
|
||||
* @param warning 警戒值
|
||||
*/
|
||||
boolean sendStockMsg(ConsStockFlow entity, BigDecimal warning);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ public interface ProdConsRelationService extends IService<ProdConsRelation> {
|
||||
* 保存商品耗材绑定关系
|
||||
*
|
||||
* @param dto 商品耗材绑定关系DTO
|
||||
* @return 保存结果
|
||||
*/
|
||||
void saveProdConsRelation(ProdConsBindDTO dto);
|
||||
|
||||
List<ProdConsRelationDTO> selectListByProdId(Long prodId);
|
||||
|
||||
List<ProdConsRelationDTO> selectStockByProdId(Long prodId);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.czg.product.service;
|
||||
|
||||
import com.czg.product.dto.ProductDTO;
|
||||
import com.czg.product.entity.ConsStockFlow;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.entity.ProductStockFlow;
|
||||
import com.czg.product.enums.InOutItemEnum;
|
||||
@@ -13,9 +12,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品
|
||||
@@ -49,7 +46,7 @@ public interface ProductService extends IService<Product> {
|
||||
* @param categoryId 商品分类ID
|
||||
* @return 商品列表数据
|
||||
*/
|
||||
Map<String, Object> getProductCacheList(Long shopId, Long categoryId);
|
||||
List<ProductDTO> getProductCacheList(Long shopId, Long categoryId);
|
||||
|
||||
/**
|
||||
* 清除某个商品分类的缓存
|
||||
@@ -133,5 +130,5 @@ public interface ProductService extends IService<Product> {
|
||||
/**
|
||||
* 通过商品 进行耗材库存增减
|
||||
*/
|
||||
void consStockByProduct(InOutTypeEnum type, InOutItemEnum item, List<ProductStockVO> products, Long orderId, String remark);
|
||||
void consStockByProduct(Long shopId, InOutTypeEnum type, InOutItemEnum item, List<ProductStockVO> products, Long orderId, String remark);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.czg.product.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public record ConsStockRecord(Long consId, BigDecimal stockNumber) {
|
||||
}
|
||||
@@ -1698,11 +1698,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
List<OrderDetail> details = orderDetailService.list(QueryWrapper.create().eq(OrderDetail::getOrderId, orderId).eq(OrderDetail::getPlaceNum, placeNum));
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (OrderDetail detail : details) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", detail.getProductId());
|
||||
data.put("num", NumberUtil.sub(detail.getNum(), detail.getReturnNum()));
|
||||
dataList.add(data);
|
||||
dataList.add(Map.of("productId", detail.getProductId(), "number", NumberUtil.sub(detail.getNum(), detail.getReturnNum())));
|
||||
}
|
||||
orderDetailService.remove(new QueryWrapper().eq(OrderDetail::getOrderId, orderId).eq(OrderDetail::getPlaceNum, placeNum));
|
||||
if (CollUtil.isNotEmpty(dataList)) {
|
||||
|
||||
@@ -97,14 +97,10 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
// 封装扣减库存数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (OrderDetail orderDetail : detailList) {
|
||||
Map<String, Object> data = new HashMap<>(16);
|
||||
Long productId = orderDetail.getProductId();
|
||||
BigDecimal num = orderDetail.getNum();
|
||||
BigDecimal refundNum = orderDetail.getRefundNum();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", productId);
|
||||
data.put("num", NumberUtil.sub(num, refundNum));
|
||||
dataList.add(data);
|
||||
dataList.add(Map.of("productId", productId, "number", NumberUtil.sub(num, refundNum)));
|
||||
}
|
||||
try {
|
||||
// 调用商品服务扣减库存
|
||||
@@ -130,22 +126,17 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
if (CollUtil.isEmpty(detailList)) {
|
||||
throw new CzgException("该订单下不存在商品");
|
||||
}
|
||||
Long shopId = orderInfo.getShopId();
|
||||
// 封装扣减库存数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (OrderDetail orderDetail : detailList) {
|
||||
Map<String, Object> data = new HashMap<>(16);
|
||||
Long productId = orderDetail.getProductId();
|
||||
BigDecimal num = orderDetail.getNum();
|
||||
BigDecimal refundNum = orderDetail.getRefundNum();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", productId);
|
||||
data.put("num", NumberUtil.sub(num, refundNum));
|
||||
dataList.add(data);
|
||||
dataList.add(Map.of("productId", productId, "number", NumberUtil.sub(num, refundNum)));
|
||||
}
|
||||
try {
|
||||
// 调用商品服务扣减库存
|
||||
productRpcService.orderCancelRecoverStock(shopId, orderId, dataList);
|
||||
productRpcService.orderCancelRecoverStock(orderInfo.getShopId(), orderId, dataList);
|
||||
} catch (Exception e) {
|
||||
log.error("调用商品服务恢复库存", e);
|
||||
throw e;
|
||||
@@ -171,13 +162,7 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
// 封装扣减库存数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
Long productId = Convert.toLong(key);
|
||||
BigDecimal num = obj.getBigDecimal(key);
|
||||
Map<String, Object> row = new HashMap<>(3);
|
||||
row.put("shopId", orderInfo.getShopId());
|
||||
row.put("productId", productId);
|
||||
row.put("num", num);
|
||||
dataList.add(row);
|
||||
dataList.add(Map.of("productId", key, "number", obj.getBigDecimal(key)));
|
||||
}
|
||||
try {
|
||||
// 调用商品服务回退库存
|
||||
|
||||
@@ -520,6 +520,7 @@ public class OrderPayServiceImpl implements OrderPayService {
|
||||
}
|
||||
//退款返还库存
|
||||
if (!returnProMap.isEmpty()) {
|
||||
//TODO 退款 商品退不退的 校验
|
||||
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
||||
}
|
||||
refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(),
|
||||
|
||||
@@ -21,4 +21,6 @@ public interface ProdConsRelationMapper extends BaseMapper<ProdConsRelation> {
|
||||
List<ProductBriefDTO> getProductListByConId(@Param("conId") Long conId);
|
||||
|
||||
List<ProdConsRelationDTO> selectListByProdId(@Param("prodId") Long prodId);
|
||||
|
||||
List<ProdConsRelationDTO> selectStockByProdId(@Param("prodId") Long prodId);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.czg.product.param.ConsInfoParam;
|
||||
import com.czg.product.param.ConsSubUnitParam;
|
||||
import com.czg.product.service.ConsInfoService;
|
||||
import com.czg.product.vo.ConsStatisticsVo;
|
||||
import com.czg.product.vo.ConsStockRecord;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ConsGroupMapper;
|
||||
import com.czg.service.product.mapper.ConsInfoMapper;
|
||||
@@ -99,6 +100,11 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConsStockRecord> getConsStockList(Long shopId) {
|
||||
return listAs(query().eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getIsStock, SystemConstants.OneZero.ONE), ConsStockRecord.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsInfoDTO getConsInfoById(Long id) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
@@ -178,12 +184,10 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
|
||||
|
||||
@Override
|
||||
public void isRefundStockConsInfo(Long id, Integer isRefundStock) {
|
||||
Long shopId = StpKit.USER.getShopId();
|
||||
ConsInfo entity = super.getOne(query().eq(ConsInfo::getId, id).eq(ConsInfo::getShopId, shopId));
|
||||
entity.setIsRefundStock(isRefundStock);
|
||||
super.updateById(entity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void modifySubUnit(ConsSubUnitParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.czg.service.product.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ConsStockFlowDTO;
|
||||
import com.czg.product.entity.ConsInfo;
|
||||
@@ -52,6 +54,8 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
private final ProductMapper productMapper;
|
||||
@Resource
|
||||
private WxAccountUtil wxAccountUtil;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -176,9 +180,9 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
}
|
||||
entity.setSubTotal(NumberUtil.mul(winLossNumber, param.getPrice()));
|
||||
entity.setRemark(param.getRemark());
|
||||
saveFlow(entity);
|
||||
consInfo.setStockNumber(entity.getAfterNumber());
|
||||
consInfoMapper.update(consInfo);
|
||||
saveFlow(entity, consInfo.getConWarning());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,9 +224,9 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
entity.setInOutItem(InOutItemEnum.DAMAGE_OUT.value());
|
||||
entity.setSubTotal(NumberUtil.mul(param.getNumber(), consInfo.getPrice()));
|
||||
entity.setImgUrls(JSON.toJSONString(param.getImgUrls()));
|
||||
saveFlow(entity);
|
||||
consInfo.setStockNumber(entity.getAfterNumber());
|
||||
consInfoMapper.update(consInfo);
|
||||
saveFlow(entity, consInfo.getConWarning());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,22 +237,29 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFlow(ConsStockFlow entity) {
|
||||
public void saveFlow(ConsStockFlow entity, BigDecimal conWarning) {
|
||||
super.save(entity);
|
||||
Long shopId = entity.getShopId();
|
||||
BigDecimal afterNumber = entity.getAfterNumber();
|
||||
ConsInfo consInfo = consInfoMapper.selectOneById(entity.getConId());
|
||||
String shopName = productMapper.getShopName(shopId);
|
||||
BigDecimal conWarning = consInfo.getConWarning();
|
||||
// 库存小于警告值,发送消息提醒
|
||||
if (NumberUtil.isLess(afterNumber, conWarning)) {
|
||||
List<String> openIdList = consInfoMapper.findOpenIdList(shopId, "con");
|
||||
if (CollUtil.isEmpty(openIdList)) {
|
||||
return;
|
||||
}
|
||||
String conName = StrUtil.format("{}数量<预警值{}", consInfo.getConName(), conWarning);
|
||||
ThreadUtil.execAsync(() -> openIdList.parallelStream().forEach(openId ->
|
||||
wxAccountUtil.sendStockMsg("耗材库存预警", shopName, conName, afterNumber, openId)));
|
||||
boolean b = sendStockMsg(entity, conWarning);
|
||||
if (b) {
|
||||
ThreadUtil.execAsync(() -> rabbitPublisher.sendConsInfoChangeMsg(Convert.toStr(entity.getShopId())));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendStockMsg(ConsStockFlow entity, BigDecimal warning) {
|
||||
boolean result = false;
|
||||
// 库存小于警告值,发送消息提醒
|
||||
if (NumberUtil.isLess(entity.getAfterNumber(), warning)) {
|
||||
result = true;
|
||||
List<String> openIdList = consInfoMapper.findOpenIdList(entity.getShopId(), "con");
|
||||
if (CollUtil.isEmpty(openIdList)) {
|
||||
return result;
|
||||
}
|
||||
String shopName = productMapper.getShopName(entity.getShopId());
|
||||
String conName = StrUtil.format("{}数量<预警值{}", entity.getConName(), warning);
|
||||
ThreadUtil.execAsync(() -> openIdList.parallelStream().forEach(openId ->
|
||||
wxAccountUtil.sendStockMsg("耗材库存预警", shopName, conName, entity.getAfterNumber(), openId)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +80,14 @@ public class ProdConsRelationServiceImpl extends ServiceImpl<ProdConsRelationMap
|
||||
return mapper.selectListByProdId(prodId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扣减库存 使用
|
||||
* @param prodId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ProdConsRelationDTO> selectStockByProdId(Long prodId) {
|
||||
return mapper.selectStockByProdId(prodId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,43 +2,23 @@ package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.product.dto.ProductStockSubtractDTO;
|
||||
import com.czg.product.entity.ConsInfo;
|
||||
import com.czg.product.entity.ConsStockFlow;
|
||||
import com.czg.product.entity.ProdConsRelation;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.enums.InOutItemEnum;
|
||||
import com.czg.product.enums.InOutTypeEnum;
|
||||
import com.czg.product.service.ConsStockFlowService;
|
||||
import com.czg.product.service.ProductRpcService;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.product.service.ProductStockFlowService;
|
||||
import com.czg.product.vo.ProductStockVO;
|
||||
import com.czg.product.vo.ProductVO;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.product.mapper.ConsInfoMapper;
|
||||
import com.czg.service.product.mapper.ProdConsRelationMapper;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.czg.constant.CacheConstant.ADMIN_CLIENT_PRODUCT_LIST;
|
||||
import static com.czg.constant.CacheConstant.SHOP_PRODUCT_STOCK;
|
||||
|
||||
/**
|
||||
* 商品RPC远程调用服务接口实现
|
||||
@@ -60,44 +40,32 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void paySuccessSubtractStock(Long shopId, Long orderId, List<Map<String, Object>> dataList) {
|
||||
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
|
||||
List<ProductStockVO> list = BeanUtil.copyToList(dataList, ProductStockVO.class);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
List<ProductStockVO> productStockList = new ArrayList<>();
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
productStockList.add(new ProductStockVO(dto.getProductId(), dto.getNum()));
|
||||
}
|
||||
productService.consStockByProduct(InOutTypeEnum.OUT, InOutItemEnum.ORDER_OUT, productStockList, orderId, "订单消费");
|
||||
productService.consStockByProduct(shopId, InOutTypeEnum.OUT, InOutItemEnum.ORDER_OUT, list, orderId, "订单消费");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void orderCancelRecoverStock(Long shopId, Long orderId, List<Map<String, Object>> dataList) {
|
||||
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
|
||||
List<ProductStockVO> list = BeanUtil.copyToList(dataList, ProductStockVO.class);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
List<ProductStockVO> productStockList = new ArrayList<>();
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
productStockList.add(new ProductStockVO(dto.getProductId(), dto.getNum()));
|
||||
}
|
||||
productService.consStockByProduct(InOutTypeEnum.IN, InOutItemEnum.ORDER_IN, productStockList, orderId, "订单取消/过期返还库存");
|
||||
productService.consStockByProduct(shopId, InOutTypeEnum.IN, InOutItemEnum.ORDER_IN, list, orderId, "订单取消/过期返还库存");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void orderRefundReturnStock(Long shopId, Long orderId, List<Map<String, Object>> dataList) {
|
||||
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
|
||||
List<ProductStockVO> list = BeanUtil.copyToList(dataList, ProductStockVO.class);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
List<ProductStockVO> productStockList = new ArrayList<>();
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
productStockList.add(new ProductStockVO(dto.getProductId(), dto.getNum()));
|
||||
}
|
||||
productService.consStockByProduct(InOutTypeEnum.IN, InOutItemEnum.ORDER_IN, productStockList, orderId, "订单退菜/退款返还库存");
|
||||
productService.consStockByProduct(shopId, InOutTypeEnum.IN, InOutItemEnum.ORDER_IN, list, orderId, "订单退菜/退款返还库存");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -9,6 +11,7 @@ import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.constant.CacheConstant;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.excel.ExcelExportUtil;
|
||||
@@ -32,6 +35,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -72,6 +76,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
private final ProdGroupRelationMapper prodGroupRelationMapper;
|
||||
private final ProductStockFlowService productStockFlowService;
|
||||
private final RedisService redisService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ProductDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
@@ -334,7 +340,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProductCacheList(Long shopId, Long categoryId) {
|
||||
public List<ProductDTO> getProductCacheList(Long shopId, Long categoryId) {
|
||||
String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId;
|
||||
List<ProductDTO> list;
|
||||
if (categoryId == null) {
|
||||
@@ -361,8 +367,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.sorted(Comparator.comparingLong(ProductDTO::getId).reversed())
|
||||
.toList();
|
||||
}
|
||||
List<ConsInfo> consInfos = consInfoMapper.selectListByQuery(query().eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getStatus, SystemConstants.OneZero.ONE));
|
||||
return Map.of("productList", list, "cons", consInfos);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -731,7 +736,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
productStockFlowService.save(flow);
|
||||
List<ProductStockVO> productStockList = new ArrayList<>();
|
||||
productStockList.add(new ProductStockVO(param.getProductId(), BigDecimal.valueOf(param.getNumber())));
|
||||
consStockByProduct(InOutTypeEnum.OUT, InOutItemEnum.DAMAGE_OUT, productStockList, null, "【商品报损,自动报损相关耗材】");
|
||||
consStockByProduct(shopId, InOutTypeEnum.OUT, InOutItemEnum.DAMAGE_OUT, productStockList, null, "【商品报损,自动报损相关耗材】");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -758,10 +763,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consStockByProduct(InOutTypeEnum type, InOutItemEnum item, List<ProductStockVO> products, Long orderId, String remark) {
|
||||
public void consStockByProduct(Long shopId, InOutTypeEnum type, InOutItemEnum item, List<ProductStockVO> products, Long orderId, String remark) {
|
||||
if (CollUtil.isEmpty(products)) return;
|
||||
boolean isSendUp = false;
|
||||
for (ProductStockVO product : products) {
|
||||
List<ProdConsRelationDTO> consList = prodConsRelationService.selectListByProdId(product.productId());
|
||||
List<ProdConsRelationDTO> consList = prodConsRelationService.selectStockByProdId(product.productId());
|
||||
if (CollUtil.isEmpty(consList)) return;
|
||||
for (ProdConsRelationDTO consInfo : consList) {
|
||||
BigDecimal surplusStock = consInfo.getSurplusStock();
|
||||
@@ -799,8 +805,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
flow.setOrderId(orderId);
|
||||
flow.setRemark(remark);
|
||||
consStockFlowService.save(flow);
|
||||
boolean b = consStockFlowService.sendStockMsg(flow, consInfo.getConWarning());
|
||||
if (b) isSendUp = b;
|
||||
}
|
||||
}
|
||||
if (isSendUp) {
|
||||
ThreadUtil.execAsync(() -> rabbitPublisher.sendConsInfoChangeMsg(Convert.toStr(shopId)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,4 +23,17 @@
|
||||
inner JOIN tb_cons_info t2 on t1.cons_info_id = t2.id
|
||||
WHERE t1.product_id = #{prodId}
|
||||
</select>
|
||||
|
||||
<select id="selectStockByProdId" resultType="com.czg.product.dto.ProdConsRelationDTO">
|
||||
SELECT t1.*,
|
||||
t2.con_unit,
|
||||
t2.con_name,
|
||||
t2.price,
|
||||
t2.stock_number,
|
||||
t2.con_warning,
|
||||
t1.surplus_stock
|
||||
FROM tb_prod_cons_relation t1
|
||||
inner JOIN tb_cons_info t2 on t1.cons_info_id = t2.id and t2.is_stock = 1
|
||||
WHERE t1.product_id = #{prodId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user