فهرست منبع

Merge remote-tracking branch 'origin/zx_saas_goods' into zx_saas_goods

zouxuan 1 سال پیش
والد
کامیت
ffcd0bae4e
18فایلهای تغییر یافته به همراه233 افزوده شده و 39 حذف شده
  1. 3 0
      mec-application/src/main/java/com/ym/mec/web/controller/ReplacementInstrumentActivityController.java
  2. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ReplacementInstrumentActivityStatDto.java
  3. 11 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ReplacementInstrument.java
  4. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsQuery.java
  5. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java
  6. 12 7
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java
  7. 20 13
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java
  8. 18 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentServiceImpl.java
  9. 8 4
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java
  10. 6 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java
  11. 4 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java
  12. 4 1
      mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml
  13. 18 6
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/OmsOrderController.java
  14. 61 3
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java
  15. 2 0
      mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/mapper/PmsProductSkuStockRecordMapper.java
  16. 10 0
      mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/model/OmsOrderItem.java
  17. 18 3
      mec-mall/mall-mbg/src/main/resources/config/mybatis/OmsOrderItemMapper.xml
  18. 15 0
      mec-mall/mall-mbg/src/main/resources/config/mybatis/PmsProductSkuStockRecordMapper.xml

+ 3 - 0
mec-application/src/main/java/com/ym/mec/web/controller/ReplacementInstrumentActivityController.java

@@ -1,5 +1,6 @@
 package com.ym.mec.web.controller;
 
+import com.beust.jcommander.internal.Lists;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
@@ -89,6 +90,7 @@ public class ReplacementInstrumentActivityController extends BaseController {
         ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationService.get(oldReplacementInstrumentActivity.getReplacementInstrumentCooperationId());
         if (byCooperationId.getOpenPay().equals(YesOrNoEnum.YES) && oldReplacementInstrumentActivity.getInstrumentsId() == null && replacementInstrumentActivity.getInstrumentsId() != null) {
             Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = oldReplacementInstrumentActivity.getUserId();
@@ -126,6 +128,7 @@ public class ReplacementInstrumentActivityController extends BaseController {
         }
         if (openFlag == 1) {
             Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ReplacementInstrumentActivityStatDto.java

@@ -19,6 +19,8 @@ public class ReplacementInstrumentActivityStatDto extends ReplacementInstrumentA
     /** 品牌 */
     private String brand;
 
+    private String brandName;
+
     /** 型号 */
     private String specification;
 
@@ -158,4 +160,12 @@ public class ReplacementInstrumentActivityStatDto extends ReplacementInstrumentA
     public void setBalance(BigDecimal balance) {
         this.balance = balance;
     }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
 }

+ 11 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ReplacementInstrument.java

@@ -17,6 +17,8 @@ public class ReplacementInstrument extends BaseEntity {
 	
 	/** 品牌 */
 	private String brand;
+
+	private String brandName;
 	
 	/** 型号 */
 	private String specification;
@@ -129,7 +131,15 @@ public class ReplacementInstrument extends BaseEntity {
 	public java.util.Date getUpdateTime(){
 		return this.updateTime;
 	}
-			
+
+	public String getBrandName() {
+		return brandName;
+	}
+
+	public void setBrandName(String brandName) {
+		this.brandName = brandName;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsQuery.java

@@ -27,6 +27,8 @@ public class GoodsQuery {
 
     private Integer subjectId;
 
+    private Boolean delFlag;
+
     public String getType() {
         return type;
     }
@@ -90,4 +92,12 @@ public class GoodsQuery {
     public void setReplacementShowOrganId(Integer replacementShowOrganId) {
         this.replacementShowOrganId = replacementShowOrganId;
     }
+
+    public Boolean getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(Boolean delFlag) {
+        this.delFlag = delFlag;
+    }
 }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service;
 
 import java.util.List;
+import java.util.Map;
 
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
@@ -161,4 +162,6 @@ public interface GoodsService extends BaseService<Integer, Goods> {
     List<BrandDto> queryGoodsBrandList();
 
     List<ProductCategoryDto> queryGoodsCategoryList();
+
+    Map<String,String> getBrandMap();
 }

+ 12 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -15,18 +15,14 @@ import com.ym.mec.biz.dal.dto.BasicUserDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsCategory;
-import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import com.ym.mec.biz.dal.entity.GoodsSub;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
-import com.ym.mec.biz.dal.enums.SellStatus;
-import com.ym.mec.biz.dal.enums.StockType;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
-import com.ym.mec.biz.dal.mapper.GoodsSubMapper;
 import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
 import com.ym.mec.biz.dal.page.GoodsQuery;
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
@@ -40,7 +36,6 @@ import com.ym.mec.common.dto.ProductAttributeCategoryDto;
 import com.ym.mec.common.dto.ProductCategoryDto;
 import com.ym.mec.common.entity.GoodsSubModel;
 import com.ym.mec.common.entity.GoodsSubStockModel;
-import com.ym.mec.common.entity.UploadReturnBean;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.QueryInfo;
@@ -61,7 +56,6 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.system.ApplicationHome;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
@@ -79,7 +73,6 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -1525,4 +1518,16 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		}
 		return "";
 	}
+
+    @Override
+    public Map<String,String> getBrandMap(){
+
+        try {
+            return mallFeignService.getList().stream().collect(Collectors.toMap(o ->o.getId().toString(), BrandDto::getName));
+
+        }catch (Exception e){
+            log.error("获取品牌信息失败",e);
+        }
+        return new HashMap<>();
+    }
 }

+ 20 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java

@@ -8,7 +8,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.service.*;
+import com.ym.mec.common.dto.BrandDto;
+import com.ym.mec.mall.MallFeignService;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,19 +37,6 @@ import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityDto;
 import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto;
 import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatHead;
 import com.ym.mec.biz.dal.dto.ReplacementPayDto;
-import com.ym.mec.biz.dal.entity.CooperationOrgan;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.QuestionnaireQuestion;
-import com.ym.mec.biz.dal.entity.QuestionnaireQuestionItem;
-import com.ym.mec.biz.dal.entity.QuestionnaireTopic;
-import com.ym.mec.biz.dal.entity.QuestionnaireUserResult;
-import com.ym.mec.biz.dal.entity.ReplacementInstrumentActivity;
-import com.ym.mec.biz.dal.entity.ReplacementInstrumentCooperation;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.Student;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GoodsType;
@@ -68,6 +59,8 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.http.HttpUtil;
 
+import javax.annotation.Resource;
+
 @Service
 public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrumentActivity> implements ReplacementInstrumentActivityService {
 
@@ -121,6 +114,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
     private QuestionnaireQuestionItemDao questionnaireQuestionItemDao;
     @Autowired
     private SysCouponCodeService sysCouponCodeService;
+    @Resource
+    private MallFeignService mallFeignService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -172,6 +167,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
             //换成商品列表中商品4.25
             Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();
@@ -255,6 +251,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
             //换成商品列表中商品4.25
             Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();
@@ -553,6 +550,16 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
                     replacementInstrumentActivityStatDto.setBalance(activityOrders.get(0).getBalancePaymentAmount());
                 }
             }
+            List<String> brandIdList = dataList.stream().map(ReplacementInstrumentActivityStatDto::getBrand).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
+            if (!brandIdList.isEmpty()) {
+                Map<Long, String> idNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+                for (ReplacementInstrumentActivityStatDto statDto : dataList) {
+                    String brand = statDto.getBrand();
+                    if (StringUtils.isNotEmpty(brand) && NumberUtils.isNumber(brand)) {
+                        statDto.setBrandName(idNameMap.getOrDefault(Long.valueOf(brand), ""));
+                    }
+                }
+            }
         }
         pageInfo.setRows(dataList);
         return pageInfo;

+ 18 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentServiceImpl.java

@@ -4,19 +4,25 @@ import com.ym.mec.biz.dal.dao.GoodsDao;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.page.ReplacementInstrumentQueryInfo;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.dto.BrandDto;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.ym.mec.biz.dal.entity.ReplacementInstrument;
 import com.ym.mec.biz.service.ReplacementInstrumentService;
 import com.ym.mec.biz.dal.dao.ReplacementInstrumentDao;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrument> implements ReplacementInstrumentService {
@@ -25,6 +31,8 @@ public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, R
     private ReplacementInstrumentDao replacementInstrumentDao;
     @Autowired
     private GoodsDao goodsDao;
+    @Resource
+    private MallFeignService mallFeignService;
 
     @Override
     public BaseDAO<Integer, ReplacementInstrument> getDAO() {
@@ -44,6 +52,16 @@ public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, R
             pageInfo.setTotal(count);
             params.put("offset", pageInfo.getOffset());
             dataList = goodsDao.getReplacementGoodsPage(params);
+            List<String> brandIdList = dataList.stream().map(ReplacementInstrument::getBrand).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
+            if (!brandIdList.isEmpty()) {
+                Map<Long, String> idNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+                for (ReplacementInstrument instrument : dataList) {
+                    String brand = instrument.getBrand();
+                    if (StringUtils.isNotEmpty(brand) && NumberUtils.isNumber(brand)) {
+                        instrument.setBrandName(idNameMap.getOrDefault(Long.valueOf(brand), ""));
+                    }
+                }
+            }
         }
         pageInfo.setRows(dataList);
         return pageInfo;

+ 8 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java

@@ -12,10 +12,7 @@ import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
-import com.ym.mec.biz.service.StudentGoodsSellService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysTenantConfigService;
-import com.ym.mec.biz.service.TenantInfoService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -46,6 +43,9 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
     @Autowired
     private SysCouponCodeDao sysCouponCodeDao;
 
+    @Autowired
+    private GoodsService goodsService;
+
     @Override
     public BaseDAO<Integer, StudentGoodsSell> getDAO() {
         return studentGoodsSellDao;
@@ -147,6 +147,10 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
             return null;
         }
         List<Goods> goodies = goodsDao.getGoodiesAndCate(goodsIds);
+        Map<String, String> brandMap = goodsService.getBrandMap();
+        for (Goods goody : goodies) {
+            goody.setBrand(brandMap.getOrDefault(goody.getBrand(),goody.getBrand()));
+        }
         List<StudentInstrument> studentInstruments = new ArrayList<>();
         for (Goods goods : goodies) {
             StudentInstrument studentInstrument = new StudentInstrument();

+ 6 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -306,6 +306,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     @Override
     public StudentInstrument addStudentInstrument(StudentInstrument studentInstrument) {
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());
@@ -352,6 +354,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     @Override
     public StudentInstrument updateStudentInstrument(StudentInstrument studentInstrument) {
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());
@@ -395,6 +399,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         }
         
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());

+ 4 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -198,6 +198,9 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     @Resource
     private StudentGoodsSellDao studentGoodsSellDao;
 
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
+
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
     @Override
     public BaseDAO<Long, StudentPaymentOrder> getDAO() {
@@ -730,7 +733,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 memberRankSettingService.liveBuyOrderCallback(order);
             } else if (order.getType().equals(OrderTypeEnum.MALL_BUY)) {
                 // 商城购买订单回调
-                this.mallBuyOrderCallback(order);
+                studentPaymentOrderService.mallBuyOrderCallback(order);
             }
         }
     }

+ 4 - 1
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -405,7 +405,10 @@
 
     <sql id="queryOrganIdSql">
         <where>
-            AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId} and g.del_flag_ = 0
+            AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId}
+            <if test="goodsQuery.delFlag != null">
+                AND g.del_flag_ = #{goodsQuery.delFlag}
+            </if>
             <if test="goodsQuery.subjectId != null">
                 AND sgm.subject_id_ = #{goodsQuery.subjectId}
             </if>

+ 18 - 6
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/OmsOrderController.java

@@ -81,16 +81,28 @@ public class OmsOrderController {
     }
 
 
-    @ApiOperation("批量完成订单")
+    @ApiOperation("批量修改订单")
     @RequestMapping(value = "/update/success", method = RequestMethod.POST)
     @ResponseBody
     public CommonResult success(@RequestBody @Validated OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate) {
 
-         int count = orderService.updateStatus(orderStatusUpdate);
-        // if (count > 0) {
-        //     return CommonResult.success(count);
-        // }
-        return CommonResult.success(true);
+        RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_REFUND_ORDER_MALL + ":delivery");
+        try {
+            boolean b = lock.tryLock(60, 60, TimeUnit.SECONDS);
+            if (b) {
+                int count = orderService.updateStatus(orderStatusUpdate);
+                if (count > 0) {
+                    return CommonResult.success(count);
+                }
+            }
+        } catch (InterruptedException e) {
+            log.error("批量修改订单", e);
+        } finally {
+            if (lock.getHoldCount() >0) {
+                lock.unlock();
+            }
+        }
+        return CommonResult.success(false);
     }
 
 

+ 61 - 3
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.admin.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.google.common.collect.Lists;
 import com.ym.mec.common.dto.SchoolDto;
@@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -202,16 +204,19 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         List<PmsProductSkuStockRecord> updateList = new ArrayList<>();
         Map<String, List<OmsOrderItem>> map = omsOrderItems.stream().collect(Collectors.groupingBy(o -> o.getOrderSn()));
         List<OrderSkuSync> skuSyncList = new ArrayList<>();
+        List<OmsOrderItem> updateItems = new ArrayList<>();
         map.forEach((sn,v) -> {
             OrderSkuSync skuSync = new OrderSkuSync();
             skuSync.setOrderNo(sn);
             List<OrderSkuSync.SkuSync> skuSyncs = new ArrayList<>();
             skuSync.setSkuSyncList(skuSyncs);
             v.stream().forEach(o -> {
+
                 List<PmsProductSkuStockRecord> skuStockRecords = skuStockRecordMap.get(o.getProductSkuId());
                 if (CollectionUtils.isEmpty(skuStockRecords)) {
                     throw new BizException(skuMap.get(o.getProductSkuId()) +"库存不足");
                 }
+                List<OrderSkuSync.SkuSync> itemSkus = new ArrayList<>();
                 int count1 = o.getProductQuantity();
                 // 扣减内部库存
                 for (PmsProductSkuStockRecord skuStockRecord : skuStockRecords) {
@@ -242,6 +247,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                             }
                             updateList.add(record);
                             skuSyncs.add(sync);
+                            itemSkus.add(sync);
                         }
                     }
                 }
@@ -273,23 +279,34 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                             }
                             updateList.add(record);
                             skuSyncs.add(sync);
+                            itemSkus.add(sync);
                         }
                     }
                 }
                 if (count1 > 0) {
                     throw new BizException(skuMap.get(o.getProductSkuId())+"库存不足");
                 }
+                if (CollUtil.isNotEmpty(itemSkus)) {
+
+                    OmsOrderItem orderItem = new OmsOrderItem();
+                    orderItem.setId(o.getId());
+                    orderItem.setStockJson(JSON.toJSONString(itemSkus));
+                    updateItems.add(orderItem);
+                }
             });
             skuSyncList.add(skuSync);
         });
         for (PmsProductSkuStockRecord pmsProductSkuStockRecord : updateList) {
             pmsProductSkuStockRecordMapper.updateByPrimaryKeySelective(pmsProductSkuStockRecord);
         }
+        // 更新订单详情
+        for (OmsOrderItem updateItem : updateItems) {
+            omsOrderItemMapper.updateByPrimaryKeySelective(updateItem);
+        }
 
         // 调用三方发货通知接口
         OmsOrderExample orderExample = new OmsOrderExample();
         orderExample.createCriteria().andIdIn(orderIds);
-        List<OmsOrder> omsOrders = orderMapper.selectByExample(orderExample);
         try {
             HttpResponseResult httpResponseResult = webFeignService.updateShippedStatus(skuSyncList);
             if (httpResponseResult.getCode() != 200 && !httpResponseResult.getStatus()) {
@@ -813,13 +830,54 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     @Transactional
     public int updateStatus(OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate) {
 
+
+        // 如果时关单 并且 是已发货状态 则需要退回库存
+        OmsOrderExample orderExample = new OmsOrderExample();
+        orderExample.createCriteria().andIdIn(orderStatusUpdate.getIds());
+        List<OmsOrder> omsOrders = orderMapper.selectByExample(orderExample);
+        List<Long> orderIds = omsOrders.stream().filter(o -> o.getStatus() == 2 || o.getStatus() == 3)
+            .map(OmsOrder::getId).collect(Collectors.toList());
+        if (orderStatusUpdate.getStatus() ==4 && !CollectionUtils.isEmpty(orderIds)) {
+            OmsOrderItemExample orderItemExample = new OmsOrderItemExample();
+            orderItemExample.createCriteria().andOrderIdIn(orderIds);
+            List<OmsOrderItem> omsOrderItems = omsOrderItemMapper.selectByExample(orderItemExample);
+            List<String> stockJsons = omsOrderItems.stream().map(OmsOrderItem::getStockJson)
+                .filter(o ->!StringUtils.isEmpty(o)).collect(Collectors.toList());
+            List<OrderSkuSync.SkuSync> skuSyncList = new ArrayList<>();
+            for (String stockJson : stockJsons) {
+                List<OrderSkuSync.SkuSync> skuSyncs = JSON.parseArray(stockJson, OrderSkuSync.SkuSync.class);
+                skuSyncList.addAll(skuSyncs);
+            }
+            Map<Long, Integer> internalMap = skuSyncList.stream().filter(o -> "INTERNAL".equals(o.getType()))
+                .collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getRecordId, Collectors.summingInt(OrderSkuSync.SkuSync::getCount)));
+            Map<Long, Integer> taxMap = skuSyncList.stream().filter(o -> "TAX".equals(o.getType()))
+                .collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getRecordId, Collectors.summingInt(OrderSkuSync.SkuSync::getCount)));
+            List<PmsProductSkuStockRecord> updateList = new ArrayList<>();
+            for (Map.Entry<Long, Integer> entry : internalMap.entrySet()) {
+                PmsProductSkuStockRecord skuStockRecord = new PmsProductSkuStockRecord();
+                skuStockRecord.setId(entry.getKey());
+                skuStockRecord.setInternalSaleStock(entry.getValue());
+                updateList.add(skuStockRecord);
+            }
+            for (Map.Entry<Long, Integer> entry : taxMap.entrySet()) {
+                PmsProductSkuStockRecord skuStockRecord = new PmsProductSkuStockRecord();
+                skuStockRecord.setId(entry.getKey());
+                skuStockRecord.setTaxSaleStock(entry.getValue());
+                updateList.add(skuStockRecord);
+            }
+            for (PmsProductSkuStockRecord pmsProductSkuStockRecord : updateList) {
+                pmsProductSkuStockRecordMapper.updateStock(pmsProductSkuStockRecord);
+            }
+
+
+        }
+
         OmsOrder record = new OmsOrder();
         record.setStatus(orderStatusUpdate.getStatus());
         OmsOrderExample example = new OmsOrderExample();
-        example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(orderStatusUpdate.getIds());
+        example.createCriteria().andIdIn(orderStatusUpdate.getIds());
         orderMapper.updateByExampleSelective(record, example);
 
-
         //添加操作记录
         List<OmsOrderOperateHistory> operateHistoryList = orderStatusUpdate.getIds().stream()
             .map(id -> {

+ 2 - 0
mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/mapper/PmsProductSkuStockRecordMapper.java

@@ -32,4 +32,6 @@ public interface PmsProductSkuStockRecordMapper {
     int lockStock(@Param("stockRecordIds") List<Long> stockRecordIds);
 
     int updateByIdAndStockSelective( PmsProductSkuStockRecord pmsProductSkuStockRecord);
+
+    void updateStock(@Param("record") PmsProductSkuStockRecord pmsProductSkuStockRecord);
 }

+ 10 - 0
mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/model/OmsOrderItem.java

@@ -71,6 +71,16 @@ public class OmsOrderItem implements Serializable {
 
     private BigDecimal precisionAmount;
 
+    private String stockJson;
+
+    public String getStockJson() {
+        return stockJson;
+    }
+
+    public void setStockJson(String stockJson) {
+        this.stockJson = stockJson;
+    }
+
     private static final long serialVersionUID = 1L;
 
     public BigDecimal getPrecisionAmount() {

+ 18 - 3
mec-mall/mall-mbg/src/main/resources/config/mybatis/OmsOrderItemMapper.xml

@@ -27,6 +27,7 @@
     <result column="promoter_id" jdbcType="INTEGER" property="promoterId" />
     <result column="share_proportion_" jdbcType="INTEGER" property="shareProportion" />
     <result column="precision_amount" jdbcType="INTEGER" property="precisionAmount" />
+    <result column="stock_json" jdbcType="VARCHAR" property="stockJson" />
   </resultMap>
   <sql id="Example_Where_Clause">
     <where>
@@ -90,7 +91,7 @@
     id, order_id, order_sn, product_id, product_pic, product_name, product_brand, product_sn, 
     product_price, product_quantity, product_sku_id, product_sku_code, product_category_id, 
     promotion_name, promotion_amount, coupon_amount, integration_amount, real_amount, 
-    gift_integration, gift_growth, product_attr,promoter_id,share_proportion_,precision_amount
+    gift_integration, gift_growth, product_attr,promoter_id,share_proportion_,precision_amount,stock_json
   </sql>
   <select id="selectByExample" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItemExample" resultMap="BaseResultMap">
     select a.*,if(oora.status is null,-1,oora.status) as returnStatus from  (
@@ -134,14 +135,14 @@
       product_sku_id, product_sku_code, product_category_id, 
       promotion_name, promotion_amount, coupon_amount, 
       integration_amount, real_amount, gift_integration, 
-      gift_growth, product_attr,promoter_id,share_proportion_,precision_amount)
+      gift_growth, product_attr,promoter_id,share_proportion_,precision_amount,stock_json)
     values (#{orderId,jdbcType=BIGINT}, #{orderSn,jdbcType=VARCHAR}, #{productId,jdbcType=BIGINT}, 
       #{productPic,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR}, #{productBrand,jdbcType=VARCHAR}, 
       #{productSn,jdbcType=VARCHAR}, #{productPrice,jdbcType=DECIMAL}, #{productQuantity,jdbcType=INTEGER}, 
       #{productSkuId,jdbcType=BIGINT}, #{productSkuCode,jdbcType=VARCHAR}, #{productCategoryId,jdbcType=BIGINT}, 
       #{promotionName,jdbcType=VARCHAR}, #{promotionAmount,jdbcType=DECIMAL}, #{couponAmount,jdbcType=DECIMAL}, 
       #{integrationAmount,jdbcType=DECIMAL}, #{realAmount,jdbcType=DECIMAL}, #{giftIntegration,jdbcType=INTEGER}, 
-      #{giftGrowth,jdbcType=INTEGER}, #{productAttr,jdbcType=VARCHAR},#{promoterId},#{shareProportion},#{precisionAmount})
+      #{giftGrowth,jdbcType=INTEGER}, #{productAttr,jdbcType=VARCHAR},#{promoterId},#{shareProportion},#{precisionAmount},#{stockJson})
   </insert>
   <insert id="insertSelective" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItem">
     <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
@@ -218,6 +219,9 @@
       <if test="precisionAmount != null">
         precision_amount,
       </if>
+        <if test="stockJson != null">
+        stock_json,
+        </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="orderId != null">
@@ -289,6 +293,9 @@
       <if test="precisionAmount != null">
         #{precisionAmount},
       </if>
+        <if test="stockJson != null">
+        #{stockJson,jdbcType=VARCHAR},
+        </if>
     </trim>
   </insert>
   <select id="countByExample" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItemExample" resultType="java.lang.Long">
@@ -372,6 +379,9 @@
       <if test="record.precisionAmount != null">
         precision_amount = #{record.precisionAmount,jdbcType=VARCHAR},
       </if>
+        <if test="record.stockJson != null">
+        stock_json = #{record.stockJson,jdbcType=VARCHAR},
+        </if>
     </set>
     <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
@@ -402,6 +412,7 @@
       promoter_id = #{record.promoterId,jdbcType=INTEGER},
       share_proportion_ = #{record.shareProportion},
       precision_amount = #{record.precisionAmount},
+        stock_json = #{record.stockJson},
       product_attr = #{record.productAttr,jdbcType=VARCHAR}
     <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
@@ -479,6 +490,9 @@
       <if test="precisionAmount != null">
         precision_amount = #{precisionAmount,jdbcType=VARCHAR},
       </if>
+        <if test="stockJson != null">
+        stock_json = #{stockJson,jdbcType=VARCHAR},
+        </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -506,6 +520,7 @@
       promoter_id = #{promoterId,jdbcType=INTEGER},
     share_proportion_ = #{shareProportion},
     precision_amount = #{precisionAmount},
+    stock_json = #{stockJson},
       product_attr = #{productAttr,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>

+ 15 - 0
mec-mall/mall-mbg/src/main/resources/config/mybatis/PmsProductSkuStockRecordMapper.xml

@@ -361,4 +361,19 @@
       </set>
       where id = #{id,jdbcType=BIGINT} and internal_sale_stock = 0 and tax_sale_stock = 0
     </update>
+
+  <update id="updateStock">
+
+        update pms_product_sku_stock_record
+        <set>
+            <if test="record.internalSaleStock != null">
+                internal_sale_stock = internal_sale_stock - #{record.internalSaleStock},
+            </if>
+            <if test="record.taxSaleStock != null">
+                tax_sale_stock = tax_sale_stock -#{record.taxSaleStock}
+            </if>
+        </set>
+
+        where id = #{record.id}
+    </update>
 </mapper>