diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProskuConMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProskuConMapper.java index 357af13..bcd5747 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProskuConMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProskuConMapper.java @@ -29,6 +29,9 @@ public interface TbProskuConMapper { List selectIdBySkuIdAndShopId(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId); + TbProskuCon selectByShopIdAndSkuIdAndProductId(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId,@Param("productId") Integer productId); + + } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbConsInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbConsInfo.java index 895ff83..b88b40a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbConsInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbConsInfo.java @@ -25,6 +25,12 @@ public class TbConsInfo implements Serializable { private BigDecimal conWarning; + private BigDecimal stockConsume; + + private String status; + + private BigDecimal price; + private Date createTime; private Date updateTime; @@ -126,4 +132,28 @@ public class TbConsInfo implements Serializable { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public BigDecimal getStockConsume() { + return stockConsume; + } + + public void setStockConsume(BigDecimal stockConsume) { + this.stockConsume = stockConsume; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProskuCon.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProskuCon.java index d760555..e5912fa 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProskuCon.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProskuCon.java @@ -9,6 +9,8 @@ public class TbProskuCon implements Serializable { private Integer shopId; + private Integer productId; + private Integer productSkuId; private Integer conInfoId; @@ -37,6 +39,14 @@ public class TbProskuCon implements Serializable { this.shopId = shopId; } + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + public Integer getProductSkuId() { return productSkuId; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java index ef03b96..3d0cb35 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java @@ -2,20 +2,15 @@ package com.chaozhanggui.system.cashierservice.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.chaozhanggui.system.cashierservice.dao.TbCashierCartMapper; -import com.chaozhanggui.system.cashierservice.dao.TbConsInfoFlowMapper; -import com.chaozhanggui.system.cashierservice.dao.TbConsInfoMapper; -import com.chaozhanggui.system.cashierservice.dao.TbProskuConMapper; -import com.chaozhanggui.system.cashierservice.entity.TbCashierCart; -import com.chaozhanggui.system.cashierservice.entity.TbConsInfo; -import com.chaozhanggui.system.cashierservice.entity.TbConsInfoFlow; -import com.chaozhanggui.system.cashierservice.entity.TbProskuCon; +import com.chaozhanggui.system.cashierservice.dao.*; +import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.po.ConsInfoPO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.*; @Slf4j @@ -36,6 +31,9 @@ public class ConsService { @Autowired TbConsInfoFlowMapper tbConsInfoFlowMapper; + @Autowired + TbOrderDetailMapper tbOrderDetailMapper; + @Transactional(rollbackFor = Exception.class) public void exect(String message) throws Exception { log.info("耗材信息更新开始:{}",message); @@ -43,109 +41,66 @@ public class ConsService { String type=jsonObject.getString("type"); - if(Objects.nonNull(type)){ - - if("create".equals(type)){ - - String cartId=jsonObject.getString("cartId"); - - TbCashierCart cart= tbCashierCartMapper.selectByPrimaryKey(Integer.valueOf(cartId)); - if(Objects.isNull(cart)){ - log.info("不存在的购物车信息::{}",cartId); - return; - } - - - //减少耗材库存信息 - List tbProskuCons= tbProskuConMapper.selectBySkuIdAndShopId(Integer.valueOf(cart.getSkuId()),Integer.valueOf(cart.getShopId())); - if(Objects.isNull(tbProskuCons)||tbProskuCons.size()<=0){ - log.info("没有对应的耗材配置: skuId:{},shopId:{}",cart.getSkuId(),cart.getShopId()); - return; - } - - List consInfoPOS=new ArrayList<>(); - List consInfoFlows=new ArrayList<>(); - for (TbProskuCon tbProskuCon : tbProskuCons) { - TbConsInfo tbConsInfo= tbConsInfoMapper.selectByPrimaryKey(tbProskuCon.getConInfoId()); - if(Objects.nonNull(tbConsInfo)){ - ConsInfoPO consInfoPO=new ConsInfoPO(tbConsInfo.getId(),tbProskuCon.getSurplusStock()); - consInfoPOS.add(consInfoPO); - - TbConsInfoFlow flow=new TbConsInfoFlow(); - flow.setConsId(tbConsInfo.getId()); - flow.setShopId(tbConsInfo.getShopId()); - flow.setConName(tbConsInfo.getConName()); - flow.setAmount(tbProskuCon.getSurplusStock()); - flow.setBalance(tbConsInfo.getStockNumber().subtract(tbProskuCon.getSurplusStock())); - flow.setBizCode("createCart"); - flow.setBizName("加入购物陈消耗"); - flow.setBizType("-"); - flow.setCreateTime(new Date()); - flow.setUpdateTime(new Date()); - consInfoFlows.add(flow); - } - } + String orderId=jsonObject.getString("orderId"); - //更新耗材信息 - tbConsInfoMapper.batchStock(consInfoPOS); - //记录更新日志 - tbConsInfoFlowMapper.insertBatch(consInfoFlows); - return; - } - - - if("delete".equals(type)){ - - List jsonArray= jsonObject.getJSONArray("skuIds").toJavaList(Integer.class); - - String shopId= jsonObject.getString("shopId"); - if(Objects.isNull(jsonArray)||jsonArray.size()<=0){ - log.info("错误的商品规格信息"); - return; - } - List consInfoPOS=new ArrayList<>(); - List consInfoFlows=new ArrayList<>(); - - for(int i=0;i tbProskuCons= tbProskuConMapper.selectBySkuIdAndShopId(Integer.valueOf(jsonArray.get(i)+""),Integer.valueOf(shopId)); - if(Objects.isNull(tbProskuCons)||tbProskuCons.size()<=0){ - log.info("没有对应的耗材配置: skuId:{},shopId:{}",jsonArray.get(i),shopId); - return; - } - - for (TbProskuCon tbProskuCon : tbProskuCons) { - TbConsInfo tbConsInfo= tbConsInfoMapper.selectByPrimaryKey(tbProskuCon.getConInfoId()); - if(Objects.nonNull(tbConsInfo)){ - ConsInfoPO consInfoPO=new ConsInfoPO(tbConsInfo.getId(),tbProskuCon.getSurplusStock().negate()); - consInfoPOS.add(consInfoPO); - - TbConsInfoFlow flow=new TbConsInfoFlow(); - flow.setConsId(tbConsInfo.getId()); - flow.setShopId(tbConsInfo.getShopId()); - flow.setConName(tbConsInfo.getConName()); - flow.setAmount(tbProskuCon.getSurplusStock()); - flow.setBalance(tbConsInfo.getStockNumber().add(tbProskuCon.getSurplusStock())); - flow.setBizCode("cancelCart"); - flow.setBizName("取消购物车返回"); - flow.setBizType("+"); - flow.setCreateTime(new Date()); - flow.setUpdateTime(new Date()); - consInfoFlows.add(flow); - } - } - } - - //更新耗材信息 - tbConsInfoMapper.batchStock(consInfoPOS); - //记录更新日志 - tbConsInfoFlowMapper.insertBatch(consInfoFlows); - return; - } - + List orderDetails= tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId)); + if(Objects.isNull(orderDetails)||orderDetails.size()<=0){ + log.info("订单信息不存在"); + return; } + List consInfoPOS=new ArrayList<>(); + List consInfoFlows=new ArrayList<>(); + for (TbOrderDetail orderDetail : orderDetails) { + TbProskuCon proskuCon= tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(orderDetail.getProductSkuId(),orderDetail.getShopId(),orderDetail.getProductId()); + if(Objects.isNull(proskuCon)){ + log.info("不存在的耗材信息配置:orderId:{},skuId:{},shopId:{},productId:{}",orderDetail.getOrderId(),orderDetail.getProductSkuId(),orderDetail.getShopId(),orderDetail.getProductId()); + continue; + } + + TbConsInfo tbConsInfo= tbConsInfoMapper.selectByPrimaryKey(proskuCon.getConInfoId()); + if(Objects.nonNull(tbConsInfo)&&"1".equals(tbConsInfo.getStatus())){ + BigDecimal amount=BigDecimal.ZERO; + TbConsInfoFlow flow=new TbConsInfoFlow(); + flow.setConsId(tbConsInfo.getId()); + flow.setShopId(tbConsInfo.getShopId()); + flow.setConName(tbConsInfo.getConName()); + if("create".equals(type)){ + amount=proskuCon.getSurplusStock().multiply(new BigDecimal(orderDetail.getNum())); + + flow.setAmount(amount); + flow.setBalance(tbConsInfo.getStockNumber().subtract(amount)); + flow.setBizCode("createCart"); + flow.setBizName("加入购物车消耗"); + flow.setBizType("-"); + }else if("delete".equals(type)){ + amount=proskuCon.getSurplusStock().multiply(new BigDecimal(orderDetail.getNum())).negate(); + + flow.setAmount(amount.abs()); + flow.setBalance(tbConsInfo.getStockNumber().subtract(amount)); + flow.setBizCode("cancelCart"); + flow.setBizName("取消购物车返回"); + flow.setBizType("+"); + } + + + + ConsInfoPO consInfoPO=new ConsInfoPO(tbConsInfo.getId(),amount); + consInfoPOS.add(consInfoPO); + + flow.setCreateTime(new Date()); + flow.setUpdateTime(new Date()); + consInfoFlows.add(flow); + + + //更新耗材信息 + tbConsInfoMapper.batchStock(consInfoPOS); + //记录更新日志 + tbConsInfoFlowMapper.insertBatch(consInfoFlows); + + } + } } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index a39771a..c8ec5f3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -126,13 +126,6 @@ public class OrderService { } } - JSONObject objectMsg=new JSONObject(); - objectMsg.put("skuId",skuWithBLOBs.getId()); - objectMsg.put("shopId",shopInfo.getId()); - - - producer.con_msg(objectMsg.toString()); - if (StringUtils.isEmpty(masterId)) { boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId); if (flag) { @@ -236,11 +229,7 @@ public class OrderService { redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(),masterId.substring(1,masterId.length())); - //修改耗材数据 - JSONObject jsonObject=new JSONObject(); - jsonObject.put("cartId",cart.getId()); - jsonObject.put("type","create"); - producer.cons(jsonObject.toString()); + CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(skuWithBLOBs, product, shopInfo, number)); return Result.success(CodeEnum.SUCCESS, masterId); @@ -364,14 +353,6 @@ public class OrderService { cashierCartMapper.deleteByCartId(masterId, cartId); - //修改耗材数据 - JSONObject jsonObject=new JSONObject(); - jsonObject.put("type","delete"); - jsonObject.put("skuIds",skuIds); - jsonObject.put("shopId",cashierCart.getShopId()); - producer.cons(jsonObject.toString()); - - return Result.success(CodeEnum.SUCCESS); } @@ -399,6 +380,14 @@ public class OrderService { return Result.fail(CARTEXIST); } for (TbCashierCart cashierCart : list) { + + + JSONObject objectMsg=new JSONObject(); + objectMsg.put("skuId",Integer.valueOf(cashierCart.getSkuId())); + objectMsg.put("shopId",Integer.valueOf(cashierCart.getShopId())); + producer.con_msg(objectMsg.toString()); + + TbProductSkuWithBLOBs tbProduct = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId())); totalAmount = totalAmount.add(cashierCart.getTotalAmount()); packAMount = packAMount.add(cashierCart.getPackFee()); @@ -543,6 +532,17 @@ public class OrderService { redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(orderInfo.getShopId().toString()),object.toString()); + + + //修改耗材数据 + JSONObject jsonObject=new JSONObject(); + jsonObject.put("orderId",orderInfo.getId()); + jsonObject.put("type","create"); + producer.cons(jsonObject.toString()); + + + + return Result.success(CodeEnum.SUCCESS, orderInfo); } @@ -820,15 +820,6 @@ public class OrderService { tbProductSkuMapper.batchStockNum(productSkuPos); } - - - //修改耗材数据 - JSONObject jsonObject=new JSONObject(); - jsonObject.put("type","delete"); - jsonObject.put("skuIds",skuIds); - jsonObject.put("shopId",cartVo.getShopId()); - producer.cons(jsonObject.toString()); - return Result.success(CodeEnum.SUCCESS); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 321a681..88fc200 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -924,6 +924,14 @@ public class PayService { producer.printMechine(String.valueOf(newOrderInfo.getId())); + + + //修改耗材数据 + JSONObject jsonObject1=new JSONObject(); + jsonObject1.put("orderId",orderInfo.getId()); + jsonObject1.put("type","delete"); + producer.cons(jsonObject1.toString()); + // 更新商品库存 for (TbOrderDetail detail : returnDetail) { detail = tbOrderDetailMapper.selectByPrimaryKey(detail.getId());