Browse Source

no message

FengChaoYu 10 tháng trước cách đây
mục cha
commit
6291ddb56e

+ 30 - 26
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/material/WorkerStockLogic.java

@@ -52,30 +52,33 @@ public class WorkerStockLogic {
     private final WebsitNormRecordService websitNormRecordService;
     private final WebsitGoodsService websitGoodsService;
     private final RedisLockRegistry redisLockRegistry;
+
     /**
      * 我的库存分类
+     *
      * @param webistId
      * @param goodsType
      * @return
      */
-    public List<WebsitGoodsCategory> websitGoodsCategoryList(String webistId, String goodsType){
+    public List<WebsitGoodsCategory> websitGoodsCategoryList(String webistId, String goodsType) {
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
-        List<WebsitGoodsCategory> websitGoodsCategories = workerStockCMapper.queryWebsitGoodsCategoryList(webistId,currentCompanyWechat.getUserId(),  goodsType);
+        List<WebsitGoodsCategory> websitGoodsCategories = workerStockCMapper.queryWebsitGoodsCategoryList(webistId, currentCompanyWechat.getUser().getWorkerNumber(), goodsType);
         return websitGoodsCategories;
     }
 
     /**
      * 我的库存列表
+     *
      * @param websitId
      * @param goodsType
      * @param pageNum
      * @param pageSize
      * @return
      */
-    public IPage<WorkerStockBean> workerStockList(String websitId,String goodsType,String categoryId,Integer pageNum,Integer pageSize){
+    public IPage<WorkerStockBean> workerStockList(String websitId, String goodsType, String categoryId, Integer pageNum, Integer pageSize) {
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
         IPage<WorkerStockBean> workerStockBeanIPage = workerStockCMapper
-                .queryWorkerStockList(new Page(pageNum, pageSize), websitId, currentCompanyWechat.getUserId(), goodsType,categoryId);
+                .queryWorkerStockList(new Page(pageNum, pageSize), websitId, currentCompanyWechat.getUser().getWorkerNumber(), goodsType, categoryId);
 
         return workerStockBeanIPage;
     }
@@ -83,7 +86,7 @@ public class WorkerStockLogic {
     /**
      * 我的辅材配件库存详情
      */
-    public WorkerStock detail(String id){
+    public WorkerStock detail(String id) {
         WorkerStock workerStock = workerStockService.getById(id);
         WorkerStockDetailBean workerStockDetailBean = BeanUtil.copyProperties(workerStock, WorkerStockDetailBean.class);
         String unit = Optional.ofNullable(websitGoodsService.getById(workerStock.getGoodsId()))
@@ -97,26 +100,26 @@ public class WorkerStockLogic {
     /**
      * 我的库存明细
      */
-    public IPage<WorkerStockAccBean> workerStockAccList(String websitId,String websitGoodsId,String month,String directFlag,Integer pageNum,Integer pageSize){
+    public IPage<WorkerStockAccBean> workerStockAccList(String websitId, String websitGoodsId, String month, String directFlag, Integer pageNum, Integer pageSize) {
         String startTime = null;
         String endTime = null;
-        if(StringUtils.isNotBlank(month)) {
+        if (StringUtils.isNotBlank(month)) {
             startTime = month + "-01";
             endTime = DateUtil.offsetMonth(DateUtil.parseDate(startTime), 1).toDateStr();
         }
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
         Page page = workerStockAccService.lambdaQuery()
-                .eq(StringUtils.isNotBlank(websitId),WorkerStockAcc::getWebsitId, websitId)
-                .eq(StringUtils.isNotBlank(directFlag),WorkerStockAcc::getDirectFlag,directFlag)
-                .eq(WorkerStockAcc::getWorkerId, currentCompanyWechat.getUserId())
+                .eq(StringUtils.isNotBlank(websitId), WorkerStockAcc::getWebsitId, websitId)
+                .eq(StringUtils.isNotBlank(directFlag), WorkerStockAcc::getDirectFlag, directFlag)
+                .eq(WorkerStockAcc::getWorkerId, currentCompanyWechat.getUser().getWorkerNumber())
                 .eq(WorkerStockAcc::getGoodsId, websitGoodsId)
-                .between(startTime != null && endTime != null ,WorkerStockAcc::getOperTime, startTime, endTime)
+                .between(startTime != null && endTime != null, WorkerStockAcc::getOperTime, startTime, endTime)
                 .orderByDesc(WorkerStockAcc::getOperTime).page(new Page<>(pageNum, pageSize));
 
         List<WorkerStockAccBean> workerStockAccBeans = BeanUtil.copyToList(page.getRecords(), WorkerStockAccBean.class);
-        for(WorkerStockAccBean workerStockAccBean : workerStockAccBeans){
+        for (WorkerStockAccBean workerStockAccBean : workerStockAccBeans) {
             WebsitGoods websitGoods = websitGoodsService.getById(workerStockAccBean.getGoodsId());
-            if(websitGoods != null){
+            if (websitGoods != null) {
                 workerStockAccBean.setUnit(websitGoods.getGoodsStockUnit());
             }
         }
@@ -132,35 +135,35 @@ public class WorkerStockLogic {
         Integer newRefundCount = websitPartsRetService.lambdaQuery()
                 .eq(WebsitPartsRet::getType, "NEW")
                 .eq(WebsitPartsRet::getFlag, "SUBMIT")
-                .eq(WebsitPartsRet::getWorkerId, wechat.getUserId())
+                .eq(WebsitPartsRet::getWorkerId, wechat.getUser().getWorkerNumber())
                 .eq(WebsitPartsRet::getCompanyWechatId, wechat.getCurrentCompanyWechatId())
                 .count();
         Integer oldRefundCount = websitPartsRetService.lambdaQuery()
                 .eq(WebsitPartsRet::getType, "OLD")
                 .eq(WebsitPartsRet::getFlag, "SUBMIT")
-                .eq(WebsitPartsRet::getWorkerId, wechat.getUserId())
+                .eq(WebsitPartsRet::getWorkerId, wechat.getUser().getWorkerNumber())
                 .eq(WebsitPartsRet::getCompanyWechatId, wechat.getCurrentCompanyWechatId())
                 .count();
         Integer materialSalesCount = websitNormRecordService.query()
                 .select("DISTINCT ref_order")
                 .eq("goods_type", "M")
-                .eq("worker_id", wechat.getUserId())
+                .eq("worker_id", wechat.getUser().getWorkerNumber())
                 .between("create_time", curDate + " 00:00:00", curDate + " 23:59:59")
                 .count();
         List<WebsitNormRecord> normRecords1 = websitNormRecordService.lambdaQuery()
                 .eq(WebsitNormRecord::getGoodsType, "M")
-                .eq(WebsitNormRecord::getWorkerId, wechat.getUserId())
+                .eq(WebsitNormRecord::getWorkerId, wechat.getUser().getWorkerNumber())
                 .between(WebsitNormRecord::getCreateTime, curDate + " 00:00:00", curDate + " 23:59:59")
                 .list();
         Integer partsSalesCount = websitNormRecordService.query()
                 .select("DISTINCT ref_order")
                 .eq("goods_type", "P")
-                .eq("worker_id", wechat.getUserId())
+                .eq("worker_id", wechat.getUser().getWorkerNumber())
                 .between("create_time", curDate + " 00:00:00", curDate + " 23:59:59")
                 .count();
         List<WebsitNormRecord> normRecords2 = websitNormRecordService.lambdaQuery()
                 .eq(WebsitNormRecord::getGoodsType, "P")
-                .eq(WebsitNormRecord::getWorkerId, wechat.getUserId())
+                .eq(WebsitNormRecord::getWorkerId, wechat.getUser().getWorkerNumber())
                 .between(WebsitNormRecord::getCreateTime, curDate + " 00:00:00", curDate + " 23:59:59")
                 .list();
 
@@ -178,11 +181,12 @@ public class WorkerStockLogic {
 
     /**
      * 单个师傅库存处理
+     *
      * @param stockList
      * @throws Exception
      */
     public void handleWorkerStock(List<WorkerStockDTO> stockList) throws Exception {
-        if(!TransactionSynchronizationManager.isSynchronizationActive()) {
+        if (!TransactionSynchronizationManager.isSynchronizationActive()) {
             throw new RemoteServiceException("请先开启事务");
         }
         if (CollectionUtil.isEmpty(stockList)) {
@@ -197,7 +201,7 @@ public class WorkerStockLogic {
                     throw new RuntimeException("变动数量不能少于0");
                 }
             } catch (ValidationException ve) {
-                throw new RemoteServiceException("第" + (i+1) + "行" + ve.getMessage());
+                throw new RemoteServiceException("第" + (i + 1) + "行" + ve.getMessage());
             }
         }
         // 锁定师傅配件库存
@@ -206,11 +210,11 @@ public class WorkerStockLogic {
                 workerStockDTO.getCompanyWechatId() + ":" +
                 workerStockDTO.getWorkerId() + ":" +
                 workerStockDTO.getGoodsType());
-        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+        if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
             throw new RemoteServiceException("库存已冻结:" + workerStockDTO.getWorkerName());
         }
         // 处理师傅库存
-        try{
+        try {
             this.saveWorkerStock(workerStockDTO, stockList);
         } finally {
             this.txCallUnlockWorker(obtain);
@@ -261,16 +265,16 @@ public class WorkerStockLogic {
         return existShopStockMap;
     }
 
-    public void txCallUnlockWorker(Lock obtain){
+    public void txCallUnlockWorker(Lock obtain) {
         //事务提交完成后才释放锁,此方法禁止执行mysql相关操作,否则将导致重大问题。
         if (TransactionSynchronizationManager.isActualTransactionActive()) {
             TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
                 @Override
                 public void afterCompletion(int status) {
 
-                    if(TransactionSynchronization.STATUS_COMMITTED == status){
+                    if (TransactionSynchronization.STATUS_COMMITTED == status) {
                         log.info("=========【师傅库存】======事务提交==============");
-                    }else if(TransactionSynchronization.STATUS_ROLLED_BACK == status){
+                    } else if (TransactionSynchronization.STATUS_ROLLED_BACK == status) {
                         log.info("========【师傅库存】=========事务回滚============");
                     }