diff --git a/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java b/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java index 80990671..71ddbcf0 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java +++ b/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java @@ -2,77 +2,72 @@ package com.suisung.mall.common.exception; import cn.hutool.core.util.StrUtil; import com.suisung.mall.common.api.CommonResult; -import com.suisung.mall.common.api.IErrorCode; import com.suisung.mall.common.api.ResultCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.dao.DataAccessException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.servlet.http.HttpServletRequest; +import java.sql.SQLException; /** - * 全局异常处理 + * 全局异常处理器 + * + *

主要功能: + *

*/ @RestControllerAdvice public class GlobalExceptionHandler { + private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + private static final String UNKNOWN_LOCATION = "未知位置"; + private static final String DB_ERROR_MSG = "数据库操作失败,请稍后重试"; + private static final String LOG_FORMAT = "业务异常 || URI={} || Method={} || Error={} || Location={}"; - private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); - - @ExceptionHandler(value = Exception.class) - public CommonResult exceptionHandler(HttpServletRequest req, Exception e) { - // 获取异常的第一帧堆栈信息 - StackTraceElement[] stackTrace = e.getStackTrace(); - String location = "未知位置"; - - if (stackTrace.length > 0) { - StackTraceElement element = stackTrace[0]; // 第一个异常抛出点 - String className = element.getClassName(); - String methodName = element.getMethodName(); - int lineNumber = element.getLineNumber(); - location = String.format("%s.%s (line: %d)", className, methodName, lineNumber); + /** + * 获取异常发生位置信息 + * + * @param stackTrace 异常堆栈 + * @return 格式化的位置信息(类名.方法名 : 行号) + */ + private String getExceptionLocation(StackTraceElement[] stackTrace) { + if (stackTrace == null || stackTrace.length == 0) { + return UNKNOWN_LOCATION; } + StackTraceElement first = stackTrace[0]; + return String.format("%s.%s:%d", first.getClassName(), first.getMethodName(), first.getLineNumber()); + } - logger.error("Exception全局异常捕获 URI: {} - Method: {} - Error: {} at {}", - req.getRequestURI(), - req.getMethod(), - e.getMessage(), - location, - e); + /** + * 处理系统级异常(数据库异常/通用异常) + */ + @ExceptionHandler({SQLException.class, DataAccessException.class, Exception.class}) + public CommonResult handleSystemException(HttpServletRequest req, Exception e) { + String location = getExceptionLocation(e.getStackTrace()); + logger.error(LOG_FORMAT, req.getRequestURI(), req.getMethod(), e.getMessage(), location, e); + if (e instanceof SQLException || e instanceof DataAccessException) { + return CommonResult.failed(DB_ERROR_MSG); + } return CommonResult.failed(e.getMessage()); } - @ExceptionHandler(value = ApiException.class) - public CommonResult exceptionHandler(HttpServletRequest req, ApiException e) { - // 获取异常位置信息 - StackTraceElement[] stackTrace = e.getStackTrace(); - String location = "未知错误位置"; + /** + * 处理业务API异常 + */ + @ExceptionHandler(ApiException.class) + public CommonResult handleApiException(HttpServletRequest req, ApiException e) { + String location = getExceptionLocation(e.getStackTrace()); + logger.error(LOG_FORMAT, + req.getRequestURI(), req.getMethod(), e.getErrorCode(), location, e); - IErrorCode errorCode = e.getErrorCode(); - String message = e.getMessage(); - - if (stackTrace.length > 0) { - StackTraceElement element = stackTrace[0]; // 第一个异常抛出点 - location = String.format("%s.%s (line: %d)", - element.getClassName(), - element.getMethodName(), - element.getLineNumber() - ); - } - - - logger.error("Exception全局异常捕获 URI:{} - Method:{} - Error:{} at {}", - req.getRequestURI(), - req.getMethod(), - message, - location, - e); - - if (StrUtil.isNotBlank(message)) { - return CommonResult.failed(message); - } else { - return CommonResult.failed(ResultCode.FAILED); - } + return StrUtil.isNotBlank(e.getMessage()) + ? CommonResult.failed(e.getMessage()) + : CommonResult.failed(ResultCode.FAILED); } -} +} \ No newline at end of file diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/config/AsyncConfig.java b/mall-shop/src/main/java/com/suisung/mall/shop/config/AsyncConfig.java index 7539f7ea..9d6ca402 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/config/AsyncConfig.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/config/AsyncConfig.java @@ -9,13 +9,19 @@ package com.suisung.mall.shop.config; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.lang.reflect.Method; import java.util.concurrent.Executor; + +@Configuration public class AsyncConfig implements AsyncConfigurer { + + @Bean(name = "asyncExecutor") @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java index e1e2a1af..9cdb8410 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java @@ -47,7 +47,7 @@ public class LakalaController extends BaseControllerImpl { @ApiOperation(value = "测试案例", notes = "测试案例") @RequestMapping(value = "/testcase", method = RequestMethod.POST) public Object testcase(@RequestBody JSONObject paramsJSON) { - return shopOrderReturnService.sfExpressExpiredForceRefund(paramsJSON.getStr("orderId"), paramsJSON.getInt("returnFlag")); + return shopOrderReturnService.sfExpressExpiredForceRefund(paramsJSON.getStr("orderId")); // return lakalaPayService.applyLedgerMerEc(paramsJSON.getStr("mchMobile")); // return lakalaPayService.LedgerMerEcDownload(975790666910121984L); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java index f5f80263..497b8002 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java @@ -1379,11 +1379,16 @@ public class LakalaApiServiceImpl implements LakalaApiService { // 2. 解析回调参数 JSONObject paramsJSON = JSONUtil.parseObj(checkResult.getSecond()); - if (paramsJSON == null) { - log.error("商家绑定分账接收方异步通知参数转化失败"); - return JSONUtil.createObj().put("code", "FAIL").put("message", "参数转换失败"); - } + if (paramsJSON == null || StrUtil.isBlank(paramsJSON.getStr("applyId"))) { + // https://o.lakala.com/#/home/document/detail?id=386 返回的数据结果有歧义,需处理 + paramsJSON = paramsJSON.getJSONObject("respData"); + if (paramsJSON == null || StrUtil.isBlank(paramsJSON.getStr("applyId"))) { + log.error("商家绑定分账接收方异步通知参数转化失败"); + return JSONUtil.createObj().put("code", "FAIL").put("message", "参数转换失败"); + } + } + // 3. 提取核心参数 String merCupNo = paramsJSON.getStr("merCupNo"); String applyId = paramsJSON.getStr("applyId"); @@ -1426,8 +1431,10 @@ public class LakalaApiServiceImpl implements LakalaApiService { // 7. 成功后更新商户绑定状态为已绑定 shopMchEntryService.updateMulStatus("", merCupNo, 0, 0, 0, 0, 0, 1, CommonConstant.MCH_APPR_STA_PASS); + // 8. 检查商户绑定状态是否完成, 更改总的审核状态 shopMchEntryService.checkMerchEntryFinished("", merCupNo); - // 8. 日志记录并返回成功响应 + + // 9. 日志记录并返回成功响应 log.debug("商家绑定分账接收方异步通知处理完成,merCupNo:{}", merCupNo); return JSONUtil.createObj().put("code", "SUCCESS").put("message", "分账接收方绑定成功"); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java index 8730070c..6cee360d 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java @@ -51,7 +51,7 @@ public class PushMessageServiceImpl implements PushMessageService { * @return */ - @Async("pushAsyncExecutor") + @Async("asyncExecutor") @Override public CompletableFuture noticeMerchantSignEcContract(Integer userId, JSONObject payload) { try { @@ -107,12 +107,16 @@ public class PushMessageServiceImpl implements PushMessageService { * @param content 必填参数 * @param payload 可选参数 */ - @Async("pushAsyncExecutor") + @Async("asyncExecutor") @Override public void noticeMerchantEmployeeOrderAction(Integer storeId, String orderId, String title, String content, JSONObject payload) { - List cidList = shopStoreEmployeeService.selectEmployeeGeTuiCidByStoreId(storeId, orderId, null); - // 获取 商家的 cid - uniCloudPushService.sendPushMessageBatch(cidList, title, content, payload); + try { + List cidList = shopStoreEmployeeService.selectEmployeeGeTuiCidByStoreId(storeId, orderId, null); + // 获取 商家的 cid + uniCloudPushService.sendPushMessageBatch(cidList, title, content, payload); + } catch (Exception e) { + log.error("执行 noticeMerchantEmployeeOrderAction 方法时发生异常,storeId:{}", storeId, e); + } } } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/controller/admin/ShopOrderReturnController.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/controller/admin/ShopOrderReturnController.java index 7b666325..055263b7 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/controller/admin/ShopOrderReturnController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/controller/admin/ShopOrderReturnController.java @@ -3,6 +3,7 @@ package com.suisung.mall.shop.order.controller.admin; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.ResultCode; @@ -198,5 +199,13 @@ public class ShopOrderReturnController extends BaseControllerImpl { return CommonResult.success(shopOrderReturnService.transferToSupplier(return_id)); } + // 商家App 相关接口 + + @ApiOperation(value = "商家退货退款", notes = "商家退货退款,支持整单或个别商品退货") + @RequestMapping(value = "/mch/order/doRefund", method = RequestMethod.POST) + public CommonResult doRefundForMch(@RequestBody JSONObject params) { + return shopOrderReturnService.doRefundForMch(params); + } + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/ShopOrderReturnService.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/ShopOrderReturnService.java index 29548b15..ff88b3bf 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/ShopOrderReturnService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/ShopOrderReturnService.java @@ -1,5 +1,6 @@ package com.suisung.mall.shop.order.service; +import cn.hutool.json.JSONObject; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.modules.order.ShopOrderInfo; import com.suisung.mall.common.modules.order.ShopOrderItem; @@ -85,11 +86,10 @@ public interface ShopOrderReturnService extends IBaseService { /** * 支付订单,顺丰同城配送超时,自动取消订单并退款,加库存 * - * @param orderId 订单Id - * @param returnFlag 退货类型(ENUM): 0-不用退货;1-需要退货 + * @param orderId 订单Id * @return */ - Boolean sfExpressExpiredForceRefund(String orderId, Integer returnFlag); + Boolean sfExpressExpiredForceRefund(String orderId); CommonResult editRefund(String return_id, BigDecimal return_refund_amount); @@ -159,4 +159,12 @@ public interface ShopOrderReturnService extends IBaseService { * @return */ boolean transferToSupplier(String return_id); + + /** + * 商家退货退款,支持全单或个别商品退货 + * + * @param params + * @return + */ + CommonResult doRefundForMch(JSONObject params); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java index 0c16b857..be7ea100 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java @@ -9,6 +9,7 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.PhoneUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -511,7 +512,6 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl return_ids = Collections.singletonList(shopOrderReturn.getReturn_id()); - - //订单已支付,但拣货超时,顺丰同城配送异常超时被取消, 强制退款 - ShopOrderReturn orderReturn = new ShopOrderReturn(); - orderReturn.setReturn_state_id(StateCode.RETURN_PROCESS_RECEIVED); - orderReturn.setReturn_flag(returnFlag); - if (!editShopOrderReturnAndItemNextState(return_ids, StateCode.RETURN_PROCESS_CHECK, orderReturn)) { - throw new ApiException(I18nUtil._("修改订单信息失败!")); - } - - shopOrderReturn.setReturn_state_id(StateCode.RETURN_PROCESS_RECEIVED); - shopOrderReturn.setReturn_store_message("系统自动退款"); - shopOrderReturn.setReturn_flag(returnFlag); - // end 待审核状态 - - if (!edit(shopOrderReturn)) { - throw new ApiException(I18nUtil._("修改订单信息失败!")); - } - - // 订单审核 - return processReviewList(return_ids, Collections.singletonList(shopOrderReturn), StateCode.RETURN_PROCESS_RECEIVED, StateCode.RETURN_PROCESS_FINISH); + // 退货审核(商家同意退款,仅仅退款,因为商品还没有配送出去) + return processReviewList(shopOrderReturn, 0); } /** @@ -1188,81 +1170,78 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl Convert.toInt(getCurrentUser().getStore_id())); - Integer store_id; - if (shopOrderReturn.getStore_id() == null) { - UserDto user = getCurrentUser(); - store_id = Convert.toInt(user.getStore_id()); - } else { - store_id = shopOrderReturn.getStore_id(); - } + List return_ids = Convert.toList(String.class, shopOrderReturn.getReturn_id()); + List orderReturns = gets(return_ids); - String str_return_id = shopOrderReturn.getReturn_id(); - List return_ids = Convert.toList(String.class, str_return_id); + if (!CheckUtil.checkDataRights(store_id, orderReturns, ShopOrderReturn::getStore_id)) { + throw new ApiException(ResultCode.FORBIDDEN); + } - List orderReturns = gets(return_ids); - - if (CheckUtil.checkDataRights(store_id, orderReturns, ShopOrderReturn::getStore_id)) { - - Integer return_flag = shopOrderReturn.getReturn_flag(); - if (ObjectUtil.equal(return_flag, 0)) { - //无需退货:直接修改退货单状态为完成,并调用 review 方法进行审核: + // 2. 根据退货标志处理不同流程 + if (ObjectUtil.equal(shopOrderReturn.getReturn_flag(), 0)) { + // 2.1 无需退货流程 if (!edit(shopOrderReturn)) { throw new ApiException(I18nUtil._("修改订单信息失败!")); } - - Integer return_next_state_id = StateCode.RETURN_PROCESS_FINISH; - // 订单审核 - if (!processReviewList(return_ids, orderReturns, StateCode.RETURN_PROCESS_CHECK, return_next_state_id)) { + if (!processReviewList(return_ids, orderReturns, StateCode.RETURN_PROCESS_CHECK, StateCode.RETURN_PROCESS_FINISH)) { throw new ApiException(I18nUtil._("审核失败!")); } - } else { - //需要退货:获取收货地址信息,并更新退货单的相关字段(如地址、联系方式等)。随后调用 review 方法进行审核: - ShopStoreShippingAddress address_row = shopStoreShippingAddressService.get(receiving_address); - if (address_row != null) { - String return_addr = address_row.getSs_province() + address_row.getSs_city() + address_row.getSs_county() + address_row.getSs_address(); - Long return_mobile = Convert.toLong(address_row.getSs_mobile()); - String return_telephone = address_row.getSs_telephone(); - String return_contact_name = address_row.getSs_name(); - - shopOrderReturn.setReturn_addr(return_addr); - shopOrderReturn.setReturn_mobile(return_mobile); - shopOrderReturn.setReturn_telephone(return_telephone); - shopOrderReturn.setReturn_contact_name(return_contact_name); - if (!edit(shopOrderReturn)) { - throw new ApiException(I18nUtil._("修改订单信息失败!")); - } - - // 订单审核 - if (!processReviewList(return_ids, orderReturns, StateCode.RETURN_PROCESS_CHECK, 0)) { - throw new ApiException(I18nUtil._("审核失败!")); - } - } else { + // 2.2 需要退货流程 + ShopStoreShippingAddress address = shopStoreShippingAddressService.get(receiving_address); + if (address == null) { throw new ApiException(I18nUtil._("请选择收货地址!")); } + + // 设置退货地址信息 + shopOrderReturn.setReturn_addr(address.getSs_province() + address.getSs_city() + address.getSs_county() + address.getSs_address()); + shopOrderReturn.setReturn_mobile(Convert.toLong(address.getSs_mobile())); + shopOrderReturn.setReturn_telephone(address.getSs_telephone()); + shopOrderReturn.setReturn_contact_name(address.getSs_name()); + + if (!edit(shopOrderReturn) || + !processReviewList(return_ids, orderReturns, StateCode.RETURN_PROCESS_CHECK, 0)) { + throw new ApiException(I18nUtil._("退货流程处理失败!")); + } } - } else { - // 没有权限 - throw new ApiException(ResultCode.FORBIDDEN); + + // 3. 通知买家 + messageService.sendNoticeMsg( + shopOrderReturn.getBuyer_user_id(), + 0, + "refunds-and-reminders", + new HashMap() {{ + put("order_id", shopOrderReturn.getReturn_id()); + put("return_refund_amount", shopOrderReturn.getReturn_refund_amount()); + }}); + + return true; + } catch (Exception e) { + logger.error("退货单审核处理异常", e); + throw e instanceof ApiException ? (ApiException) e : + new ApiException(I18nUtil._("系统处理异常: ") + e.getMessage()); } - - // 通知买家退货退款成功 - String message_id = "refunds-and-reminders"; - Map args = new HashMap(); - args.put("order_id", shopOrderReturn.getReturn_id()); - args.put("return_refund_amount", shopOrderReturn.getReturn_refund_amount()); - messageService.sendNoticeMsg(shopOrderReturn.getBuyer_user_id(), 0, message_id, args); - - return true; } /** @@ -2051,7 +2030,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl saveProduct(ShopProductBase shopProductBase, ShopProductIndex shopProductIndex, ShopProductData shopProductData, ShopProductDetail shopProductDetail, ShopProductInfo shopProductInfo, List shopProductItemList, List shopProductImageList, ShopProductValidPeriod shopProductValidPeriod, List shopProductAssistIndexList) { + public synchronized Pair saveProduct(ShopProductBase shopProductBase, ShopProductIndex shopProductIndex, ShopProductData shopProductData, ShopProductDetail shopProductDetail, ShopProductInfo shopProductInfo, List shopProductItemList, List shopProductImageList, ShopProductValidPeriod shopProductValidPeriod, List shopProductAssistIndexList) { Integer store_id = shopProductBase.getStore_id(); if (store_id == null) { return Pair.of(false, I18nUtil._("缺少店铺ID!")); @@ -743,7 +745,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl item_ids_all = (List) CollUtil.union(item_ids_new, item_ids_old); + + List item_ids_deprecate = (List) CollUtil.disjunction(item_ids_all, item_ids_new); + // item_ids_deprecate 的值如:[40,41,42] 商品 SKU ID 集合 +// logger.info("商品 SKU ID item_ids_deprecate: {}", item_ids_deprecate); //start 清理sku相关数据 if (CollUtil.isNotEmpty(item_ids_deprecate)) { @@ -1439,7 +1445,6 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl wrapper, Integer pageNum, Integer pageSize) { Map map = new HashMap(); - Integer store_id = Convert.toInt(getCurrentUser().getStore_id(),1); + Integer store_id = Convert.toInt(getCurrentUser().getStore_id(), 1); Integer nodeid = Convert.toInt(getParameter("nodeid"), 0); if (CheckUtil.isNotEmpty(nodeid)) { @@ -2976,17 +2980,17 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl 0; } - public String initProductLangIndex(Long productId, String productNameIndex) { QueryWrapper queryParams = new QueryWrapper<>(); queryParams.eq("table_name", "shop_product_base"); @@ -5294,7 +5294,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl shopProductDataList, List shopProductDetailList, List shopProductInfoList, List> shopProductItemList, List shopProductImageList, List shopProductValidPeriodList, - List shopProductAssistIndexList,String priorityMode) { + List shopProductAssistIndexList, String priorityMode) { // 1. 参数校验 if (shopProductBaseList == null || shopProductBaseList.isEmpty()) { @@ -5311,26 +5311,26 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl newShopProductIndexList = new ArrayList<>(); List updateShopProductIndexList = new ArrayList<>(); - List newProductDataList=new ArrayList<>(); - List updateProductDataList=new ArrayList<>(); + List newProductDataList = new ArrayList<>(); + List updateProductDataList = new ArrayList<>(); - List newShopProductDetailList=new ArrayList<>(); - List updateShopProductDetailList=new ArrayList<>(); + List newShopProductDetailList = new ArrayList<>(); + List updateShopProductDetailList = new ArrayList<>(); - List newShopProductInfoList=new ArrayList<>(); - List updateShopProductInfoList=new ArrayList<>(); + List newShopProductInfoList = new ArrayList<>(); + List updateShopProductInfoList = new ArrayList<>(); - List> newShopProductItemList=new ArrayList<>(); - List> updateShopProductItemList=new ArrayList<>(); + List> newShopProductItemList = new ArrayList<>(); + List> updateShopProductItemList = new ArrayList<>(); - List newShopProductImageList=new ArrayList<>(); - List updateShopProductImageList=new ArrayList<>(); + List newShopProductImageList = new ArrayList<>(); + List updateShopProductImageList = new ArrayList<>(); - List newShopProductValidPeriodList=new ArrayList<>(); - List updateShopProductValidPeriodList=new ArrayList<>(); + List newShopProductValidPeriodList = new ArrayList<>(); + List updateShopProductValidPeriodList = new ArrayList<>(); - List newShopProductAssistIndexList=new ArrayList<>(); - List updateShopProductAssistIndexList=new ArrayList<>(); + List newShopProductAssistIndexList = new ArrayList<>(); + List updateShopProductAssistIndexList = new ArrayList<>(); try { for (int i = 0; i < shopProductBaseList.size(); i++) { ShopProductBase base = shopProductBaseList.get(i); @@ -5358,36 +5358,36 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl executeBatchOperations(List newProducts, List updateProducts, - List newShopProductIndexList,List updateShopProductIndexList, + List newShopProductIndexList, List updateShopProductIndexList, List newShopProductDataList, List updateShopProductDataList, List newShopProductDetailList, List updateShopProductDetailList, - List newShopProductInfoList, List updateShopProductInfoList, - List> newShopProductItemList,List> udpateShopProductItemList, + List newShopProductInfoList, List updateShopProductInfoList, + List> newShopProductItemList, List> udpateShopProductItemList, List newShopProductImageList, List udpteShopProductImageList, - List newShopProductValidPeriodList, List updateShopProductValidPeriodList, + List newShopProductValidPeriodList, List updateShopProductValidPeriodList, List newShopProductAssistIndexList, List udpateShopProductAssistIndexList, String priorityMode ) { @@ -5463,7 +5462,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl { try { - // Map> productToItemsMap = new HashMap<>(); + // Map> productToItemsMap = new HashMap<>(); List addAnalyticsList = new ArrayList<>(); List udpateAnalyticsList = new ArrayList<>(); @@ -5472,13 +5471,13 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl addItemIds = new ArrayList<>(); List udpateItemIds = new ArrayList<>(); - List addShopProductItems=new ArrayList<>(); - List updateShopProductItems=new ArrayList<>(); + List addShopProductItems = new ArrayList<>(); + List updateShopProductItems = new ArrayList<>(); - List addShopProductSpecItems=new ArrayList<>(); - List updateShopProductSpecItems=new ArrayList<>(); - // int taskCount = 2; - // CountDownLatch latch = new CountDownLatch(taskCount); + List addShopProductSpecItems = new ArrayList<>(); + List updateShopProductSpecItems = new ArrayList<>(); + // int taskCount = 2; + // CountDownLatch latch = new CountDownLatch(taskCount); // 1. 批量新增 if (CollUtil.isNotEmpty(newProducts)) { // 4. 批量生成新商品的ID @@ -5502,39 +5501,39 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl itemIds = processProductItemsId(addShopProductItems, addItemSeqs,newShopProductInfoList); + List itemIds = processProductItemsId(addShopProductItems, addItemSeqs, newShopProductInfoList); addItemIds.addAll(itemIds); // 2. 批量更新 if (CollUtil.isNotEmpty(newProducts)) { - logger.info("保存任务开始执行"); - try { - long startTime=System.nanoTime(); - saveBatch(newProducts,newProducts.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newProducts--{}条数据耗时:{}",newProducts.size(),duration/1000000000); - } catch (Exception e) { - logger.error("系统异常"+e.getMessage()); - } + logger.info("保存任务开始执行"); + try { + long startTime = System.nanoTime(); + saveBatch(newProducts, newProducts.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newProducts--{}条数据耗时:{}", newProducts.size(), duration / 1000000000); + } catch (Exception e) { + logger.error("系统异常" + e.getMessage()); + } } } if (CollUtil.isNotEmpty(updateProducts)) { - for(int i=0;i itemIds = processProductItemsId(updateShopProductItems, updateItemSeqs,newShopProductInfoList); + List itemIds = processProductItemsId(updateShopProductItems, updateItemSeqs, newShopProductInfoList); udpateItemIds.addAll(itemIds); // 2. 批量更新 if (CollUtil.isNotEmpty(updateProducts)) { - logger.info("更新任务开始执行"); - try { - long startTime=System.nanoTime(); - updateBatchById(updateProducts); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateProducts-{}条数据耗时:{}",updateProducts.size(),duration/1000000000); - } catch (Exception e) { - logger.error("系统异常"+e.getMessage()); - } + logger.info("更新任务开始执行"); + try { + long startTime = System.nanoTime(); + updateBatchById(updateProducts); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateProducts-{}条数据耗时:{}", updateProducts.size(), duration / 1000000000); + } catch (Exception e) { + logger.error("系统异常" + e.getMessage()); + } } } // 3. 处理其他表的批量操作(同样需要区分新增和更新) - batchProcessOtherTables(newShopProductIndexList,updateShopProductIndexList,newShopProductDataList,updateShopProductDataList, - newShopProductDetailList,updateShopProductDetailList,newShopProductInfoList,updateShopProductInfoList, - newShopProductValidPeriodList,updateShopProductValidPeriodList,addShopProductItems,updateShopProductItems, - addAnalyticsList,udpateAnalyticsList,addItemSeqs,updateItemSeqs,newShopProductImageList,udpteShopProductImageList); + batchProcessOtherTables(newShopProductIndexList, updateShopProductIndexList, newShopProductDataList, updateShopProductDataList, + newShopProductDetailList, updateShopProductDetailList, newShopProductInfoList, updateShopProductInfoList, + newShopProductValidPeriodList, updateShopProductValidPeriodList, addShopProductItems, updateShopProductItems, + addAnalyticsList, udpateAnalyticsList, addItemSeqs, updateItemSeqs, newShopProductImageList, udpteShopProductImageList); logger.info("处理成功,新增{}条,更新{}条", newProducts.size(), updateProducts.size()); //计算规格 - if(CollUtil.isNotEmpty(newProducts)){ - productMappingService.computeProductMapping(newProducts,newProducts.get(0).getStore_id(),false); + if (CollUtil.isNotEmpty(newProducts)) { + productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(), false); } - if(CollUtil.isNotEmpty(updateProducts)){//如果时自动优先,则按平台规则切割商品 - if(DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)){ - productMappingService.computeProductMapping(updateProducts,updateProducts.get(0).getStore_id(),true); + if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先,则按平台规则切割商品 + if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) { + productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(), true); } } return Pair.of(true, String.format("处理成功,新增%d条,更新%d条", @@ -5613,75 +5612,75 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl newShopProductIndex, List updateShopProductIndex, List newShopProductDataList, List updateShopProductDataList, List newshopProductDetailList, List updateShopProductDetailList, - List newShopProductInfoList,List updateShopProductInfoList, - List newShopProductValidPeriodList,List updateShopProductValidPeriodList, - List newshopProductItemList,List updateshopProductItemList, - List newShopProductAnalyticList,List updateShopProductAnalyticList, - List newShopProductItemSeqList,List updateShopProductItemSeqList, - List addShopProductImageList,List updateShopProductImageList) { + List newShopProductInfoList, List updateShopProductInfoList, + List newShopProductValidPeriodList, List updateShopProductValidPeriodList, + List newshopProductItemList, List updateshopProductItemList, + List newShopProductAnalyticList, List updateShopProductAnalyticList, + List newShopProductItemSeqList, List updateShopProductItemSeqList, + List addShopProductImageList, List updateShopProductImageList) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); transactionTemplate.setTimeout(60); // 60秒超时 transactionTemplate.execute(status -> { - // 并行执行批量保存 + // 并行执行批量保存 //CompletableFuture future1 = CompletableFuture.runAsync(() -> { try { - if (CollUtil.isNotEmpty(newShopProductIndex)) { - // synchronized (this){ - long startTime=System.nanoTime(); - shopProductIndexService.saveBatch(newShopProductIndex,newShopProductIndex.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newShopProductIndex-{}条数据耗时:{}",newShopProductIndex.size(),duration/1000000000); - boolean esearch_enable = accountBaseConfigService.getConfig("esearch_enable", false); - //调用es,create - if (esearch_enable) { - searchService.batchImport(newShopProductIndex);//创建es - } - //} + if (CollUtil.isNotEmpty(newShopProductIndex)) { + // synchronized (this){ + long startTime = System.nanoTime(); + shopProductIndexService.saveBatch(newShopProductIndex, newShopProductIndex.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newShopProductIndex-{}条数据耗时:{}", newShopProductIndex.size(), duration / 1000000000); + boolean esearch_enable = accountBaseConfigService.getConfig("esearch_enable", false); + //调用es,create + if (esearch_enable) { + searchService.batchImport(newShopProductIndex);//创建es + } + //} + } + if (CollUtil.isNotEmpty(updateShopProductIndex)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductIndexService.updateBatchById(updateShopProductIndex); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductIndex-{}条数据耗时:{}", updateShopProductIndex.size(), duration / 1000000000); + boolean esearch_enable = accountBaseConfigService.getConfig("esearch_enable", false); + //调用es,create + if (esearch_enable) { + searchService.batchImport(newShopProductIndex);//创建es } - if (CollUtil.isNotEmpty(updateShopProductIndex)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductIndexService.updateBatchById(updateShopProductIndex); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductIndex-{}条数据耗时:{}",updateShopProductIndex.size(),duration/1000000000); - boolean esearch_enable = accountBaseConfigService.getConfig("esearch_enable", false); - //调用es,create - if (esearch_enable) { - searchService.batchImport(newShopProductIndex);//创建es - } - // } - } + // } + } - if (CollUtil.isNotEmpty(newShopProductDataList)) { - //synchronized (this) { - long startTime=System.nanoTime(); - shopProductDataService.saveBatch(newShopProductDataList, newShopProductDataList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newShopProductDataList-{}条数据耗时:{}",newShopProductDataList.size(),duration/1000000000); - //} - } - if (CollUtil.isNotEmpty(updateShopProductDataList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductDataService.updateBatchById(updateShopProductDataList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductDataList-{}条数据耗时:{}",updateShopProductDataList.size(),duration/1000000000); - // } - } - if(CollectionUtil.isNotEmpty(addShopProductImageList)){ - long startTime=System.nanoTime(); - shopProductImageService.saveBatch(addShopProductImageList,addShopProductImageList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增addShopProductImageList-{}条数据耗时:{}",addShopProductImageList.size(),duration/1000000000); - } + if (CollUtil.isNotEmpty(newShopProductDataList)) { + //synchronized (this) { + long startTime = System.nanoTime(); + shopProductDataService.saveBatch(newShopProductDataList, newShopProductDataList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newShopProductDataList-{}条数据耗时:{}", newShopProductDataList.size(), duration / 1000000000); + //} + } + if (CollUtil.isNotEmpty(updateShopProductDataList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductDataService.updateBatchById(updateShopProductDataList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductDataList-{}条数据耗时:{}", updateShopProductDataList.size(), duration / 1000000000); + // } + } + if (CollectionUtil.isNotEmpty(addShopProductImageList)) { + long startTime = System.nanoTime(); + shopProductImageService.saveBatch(addShopProductImageList, addShopProductImageList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增addShopProductImageList-{}条数据耗时:{}", addShopProductImageList.size(), duration / 1000000000); + } // if(CollectionUtil.isNotEmpty(updateShopProductImageList)){ // long startTime=System.nanoTime(); // // shopProductImageService.batchUpdateByCondition(updateShopProductImageList,"product_id"); @@ -5690,183 +5689,150 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl future2 = CompletableFuture.runAsync(() -> { + try { + if (CollUtil.isNotEmpty(newshopProductDetailList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductDetailService.saveBatch(newshopProductDetailList, newshopProductDetailList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newshopProductDetailList-{}条数据耗时:{}", newshopProductDetailList.size(), duration / 1000000000); + + // } + } + if (CollUtil.isNotEmpty(updateShopProductDetailList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductDetailService.updateBatchById(updateShopProductDetailList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductDetailList-{}条数据耗时:{}", updateShopProductDetailList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(newShopProductInfoList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductInfoService.saveBatch(newShopProductInfoList, newShopProductInfoList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增updateShopProductDetailList-{}条数据耗时:{}", newShopProductInfoList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(updateShopProductInfoList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductInfoService.updateBatchById(updateShopProductInfoList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductInfoList-{}条数据耗时:{}", updateShopProductInfoList.size(), duration / 1000000000); + // } + } + } catch (RuntimeException e) { + logger.info("批量报错附表失败{}", e.getMessage()); + } + //}); + + //CompletableFuture future3 = CompletableFuture.runAsync(() -> { + try { + if (CollUtil.isNotEmpty(newShopProductValidPeriodList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + validPeriodService.saveBatch(newShopProductValidPeriodList, newShopProductValidPeriodList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newShopProductValidPeriodList-{}条数据耗时:{}", newShopProductValidPeriodList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(updateShopProductValidPeriodList)) { + //synchronized (this) { + long startTime = System.nanoTime(); + validPeriodService.updateBatchById(updateShopProductValidPeriodList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductValidPeriodList-{}条数据耗时:{}", updateShopProductValidPeriodList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(newShopProductAnalyticList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductAnalyticsService.saveBatch(newShopProductAnalyticList, newShopProductAnalyticList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newShopProductAnalyticList-{}条数据耗时:{}", newShopProductAnalyticList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(updateShopProductAnalyticList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductAnalyticsService.updateBatchById(updateShopProductAnalyticList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductAnalyticList-{}条数据耗时:{}", updateShopProductAnalyticList.size(), duration / 1000000000); + // } + } + } catch (RuntimeException e) { + logger.info("批量报错附表失败{}", e.getMessage()); + } + + //}); + + //CompletableFuture future4 = CompletableFuture.runAsync(() -> { + try { + if (CollUtil.isNotEmpty(newshopProductItemList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductItemService.saveBatch(newshopProductItemList, newshopProductItemList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新增newshopProductItemList-{}条数据耗时:{}", newshopProductItemList.size(), duration / 1000000000); + //} + } + if (CollUtil.isNotEmpty(updateshopProductItemList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductItemService.updateBatchById(updateshopProductItemList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateshopProductItemList-{}条数据耗时:{}", updateshopProductItemList.size(), duration / 1000000000); + //} + } + if (CollUtil.isNotEmpty(newShopProductItemSeqList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductItemSeqService.saveBatch(newShopProductItemSeqList, newShopProductItemSeqList.size()); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("新曾newShopProductItemSeqList-{}条数据耗时:{}", newShopProductItemSeqList.size(), duration / 1000000000); + // } + } + if (CollUtil.isNotEmpty(updateShopProductItemSeqList)) { + // synchronized (this) { + long startTime = System.nanoTime(); + shopProductItemSeqService.updateBatchById(updateShopProductItemSeqList); + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + logger.info("更新updateShopProductItemSeqList-{}条数据耗时:{}", updateShopProductItemSeqList.size(), duration / 1000000000); + // } } - // }); - - // CompletableFuture future2 = CompletableFuture.runAsync(() -> { - try { - if (CollUtil.isNotEmpty(newshopProductDetailList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductDetailService.saveBatch(newshopProductDetailList, newshopProductDetailList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newshopProductDetailList-{}条数据耗时:{}",newshopProductDetailList.size(),duration/1000000000); - - // } - } - if (CollUtil.isNotEmpty(updateShopProductDetailList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductDetailService.updateBatchById(updateShopProductDetailList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductDetailList-{}条数据耗时:{}",updateShopProductDetailList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(newShopProductInfoList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductInfoService.saveBatch(newShopProductInfoList, newShopProductInfoList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增updateShopProductDetailList-{}条数据耗时:{}",newShopProductInfoList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(updateShopProductInfoList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductInfoService.updateBatchById(updateShopProductInfoList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductInfoList-{}条数据耗时:{}",updateShopProductInfoList.size(),duration/1000000000); - // } - } - }catch (RuntimeException e){ - logger.info("批量报错附表失败{}",e.getMessage()); - } - //}); - - //CompletableFuture future3 = CompletableFuture.runAsync(() -> { - try { - if (CollUtil.isNotEmpty(newShopProductValidPeriodList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - validPeriodService.saveBatch(newShopProductValidPeriodList, newShopProductValidPeriodList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newShopProductValidPeriodList-{}条数据耗时:{}",newShopProductValidPeriodList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(updateShopProductValidPeriodList)) { - //synchronized (this) { - long startTime=System.nanoTime(); - validPeriodService.updateBatchById(updateShopProductValidPeriodList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductValidPeriodList-{}条数据耗时:{}",updateShopProductValidPeriodList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(newShopProductAnalyticList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductAnalyticsService.saveBatch(newShopProductAnalyticList, newShopProductAnalyticList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newShopProductAnalyticList-{}条数据耗时:{}",newShopProductAnalyticList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(updateShopProductAnalyticList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductAnalyticsService.updateBatchById(updateShopProductAnalyticList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductAnalyticList-{}条数据耗时:{}",updateShopProductAnalyticList.size(),duration/1000000000); - // } - } - }catch (RuntimeException e){ - logger.info("批量报错附表失败{}",e.getMessage()); - } - - //}); - - //CompletableFuture future4 = CompletableFuture.runAsync(() -> { - try { - if (CollUtil.isNotEmpty(newshopProductItemList)) { - // synchronized (this) { - long startTime=System.nanoTime(); - shopProductItemService.saveBatch(newshopProductItemList, newshopProductItemList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新增newshopProductItemList-{}条数据耗时:{}",newshopProductItemList.size(),duration/1000000000); - //} - } - if (CollUtil.isNotEmpty(updateshopProductItemList)) { - // synchronized (this) { - long startTime = System.nanoTime(); - shopProductItemService.updateBatchById(updateshopProductItemList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateshopProductItemList-{}条数据耗时:{}",updateshopProductItemList.size(),duration/1000000000); - //} - } - if (CollUtil.isNotEmpty(newShopProductItemSeqList)) { - // synchronized (this) { - long startTime = System.nanoTime(); - shopProductItemSeqService.saveBatch(newShopProductItemSeqList, newShopProductItemSeqList.size()); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("新曾newShopProductItemSeqList-{}条数据耗时:{}",newShopProductItemSeqList.size(),duration/1000000000); - // } - } - if (CollUtil.isNotEmpty(updateShopProductItemSeqList)) { - // synchronized (this) { - long startTime = System.nanoTime(); - shopProductItemSeqService.updateBatchById(updateShopProductItemSeqList); - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - logger.info("更新updateShopProductItemSeqList-{}条数据耗时:{}",updateShopProductItemSeqList.size(),duration/1000000000); - // } - } - - }catch (RuntimeException e){ - logger.info("批量报错附表失败{}",e.getMessage()); - } - //}); + } catch (RuntimeException e) { + logger.info("批量报错附表失败{}", e.getMessage()); + } + //}); // 等待所有操作完成 // CompletableFuture.allOf(future1, future2, future3, future4).join(); - return null; - }); + return null; + }); } - /** - * 批量生产itemid - * @param items - * @param itemSeqs - * @return - */ - private List processProductItemsId(List items,List itemSeqs, - List newShopProductInfoList){ - List itemIds = new ArrayList<>(); - if (CollUtil.isEmpty(items)) return itemIds; - List generatedIds = shopNumberSeqService.batchCreateNextNo("item_id", items.size()); - // Map cacheMap=new HashMap<>(); - for (int i = 0; i < items.size(); i++) { - Long itemId = generatedIds.get(i); - ShopProductItem item = items.get(i); - item.setItem_id(itemId); -// if(StringUtils.isNotEmpty(item.getItem_spec())){ -// String product_uniqid=ShopJsonUtils.generateJsonWithOrgJson(item.getSpec_item_ids(),new Object[]{itemId,item.getItem_unit_price(),"",1002}); -// cacheMap.put(item.getProductName(),product_uniqid); -// } - itemIds.add(itemId); - ShopProductItemSeq field_row= itemSeqs.get(i); - field_row.setItem_id(itemId); - } -// for(ShopProductInfo shopProductInfo:newShopProductInfoList){ -// if(ObjectUtil.isNotEmpty(cacheMap.get(shopProductInfo.getProductName()))){ -// String product_uniqid=cacheMap.get(shopProductInfo.getProductName()); -// shopProductInfo.setProduct_uniqid(product_uniqid); -// } -// } - return itemIds; - } - // /** // * 计算并产生规格 与商品配置表匹配,匹配正确则新增规格商品 // * @return @@ -5916,13 +5882,46 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl processProductItemsId(List items, List itemSeqs, + List newShopProductInfoList) { + List itemIds = new ArrayList<>(); + if (CollUtil.isEmpty(items)) return itemIds; + List generatedIds = shopNumberSeqService.batchCreateNextNo("item_id", items.size()); + // Map cacheMap=new HashMap<>(); + for (int i = 0; i < items.size(); i++) { + Long itemId = generatedIds.get(i); + ShopProductItem item = items.get(i); + item.setItem_id(itemId); +// if(StringUtils.isNotEmpty(item.getItem_spec())){ +// String product_uniqid=ShopJsonUtils.generateJsonWithOrgJson(item.getSpec_item_ids(),new Object[]{itemId,item.getItem_unit_price(),"",1002}); +// cacheMap.put(item.getProductName(),product_uniqid); +// } + itemIds.add(itemId); + ShopProductItemSeq field_row = itemSeqs.get(i); + field_row.setItem_id(itemId); + } +// for(ShopProductInfo shopProductInfo:newShopProductInfoList){ +// if(ObjectUtil.isNotEmpty(cacheMap.get(shopProductInfo.getProductName()))){ +// String product_uniqid=cacheMap.get(shopProductInfo.getProductName()); +// shopProductInfo.setProduct_uniqid(product_uniqid); +// } +// } + return itemIds; + } // 处理商品项 private void processProductItems(List items, Long productId, - List itemSeqs) { + List itemSeqs) { for (int i = 0; i < items.size(); i++) { ShopProductItem item = items.get(i); - // item.setProductName(productName); + // item.setProductName(productName); item.setProduct_id(productId); String item_spec = item.getItem_spec(); // if(null!=shopProductSpecItem){ @@ -5934,8 +5933,8 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl existing = batchGetByStoreAndProductNumber(storeProductPairs,productBases.get(0).getStore_id()); + List existing = batchGetByStoreAndProductNumber(storeProductPairs, productBases.get(0).getStore_id()); // 4. 构建存在商品的映射表 return existing.stream() @@ -6043,11 +6041,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl batchGetByStoreAndProductNumber(List> storeProductPairs,Integer storeId) { + private List batchGetByStoreAndProductNumber(List> storeProductPairs, Integer storeId) { if (CollUtil.isEmpty(storeProductPairs)) { return Collections.emptyList(); } @@ -6065,13 +6062,13 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl assistIndices, Integer storeId,boolean isUpdate) { + private void processAssistIndices(List assistIndices, Integer storeId, boolean isUpdate) { if (CollUtil.isEmpty(assistIndices)) { return; } // 查询现有辅助属性 - // QueryWrapper query = new QueryWrapper<>(); + // QueryWrapper query = new QueryWrapper<>(); //query.eq("product_id", productId); List existingAssists = assistIndexService.getShopProductAssistIndexStoreId(storeId); @@ -6114,10 +6112,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl getProductBasicIdByStore(Integer store_id,List productNumberList) { - QueryWrapper queryWrapper=new QueryWrapper(); - queryWrapper.select("product_number","product_id"); - productNumberList.forEach(productNumber->{ - queryWrapper.or(q->q.eq("store_id",store_id).eq("product_number",productNumber)); + public Map getProductBasicIdByStore(Integer store_id, List productNumberList) { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.select("product_number", "product_id"); + productNumberList.forEach(productNumber -> { + queryWrapper.or(q -> q.eq("store_id", store_id).eq("product_number", productNumber)); }); - List shopProductBaseList= this.list(queryWrapper); - Map resultMap=new HashMap(); - shopProductBaseList.forEach(shopProductBase->{ - if(StringUtils.isNotEmpty(shopProductBase.getProduct_number())){ - resultMap.put(String.valueOf(shopProductBase.getProduct_number()),shopProductBase.getProduct_id()); + List shopProductBaseList = this.list(queryWrapper); + Map resultMap = new HashMap(); + shopProductBaseList.forEach(shopProductBase -> { + if (StringUtils.isNotEmpty(shopProductBase.getProduct_number())) { + resultMap.put(String.valueOf(shopProductBase.getProduct_number()), shopProductBase.getProduct_id()); } }); return resultMap; @@ -6146,75 +6144,69 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl count1 = CompletableFuture.supplyAsync(() -> { - QueryWrapper queryWrapper=new QueryWrapper<>(); - if(ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())){ - queryWrapper.eq("category_id",shopProductIndex.getCategory_id()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())) { + queryWrapper.eq("category_id", shopProductIndex.getCategory_id()); } - queryWrapper.eq("store_id",shopProductIndex.getStore_id()); + queryWrapper.eq("store_id", shopProductIndex.getStore_id()); return ((int) shopProductIndexService.count(queryWrapper)); }); CompletableFuture count2 = CompletableFuture.supplyAsync(() -> { - QueryWrapper queryWrapper=new QueryWrapper<>(); - if(ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())){ - queryWrapper.eq("category_id",shopProductIndex.getCategory_id()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())) { + queryWrapper.eq("category_id", shopProductIndex.getCategory_id()); } - queryWrapper.eq("store_id",shopProductIndex.getStore_id()); - queryWrapper.eq("product_state_id",StateCode.PRODUCT_STATE_NORMAL); + queryWrapper.eq("store_id", shopProductIndex.getStore_id()); + queryWrapper.eq("product_state_id", StateCode.PRODUCT_STATE_NORMAL); return ((int) shopProductIndexService.count(queryWrapper)); }); CompletableFuture count3 = CompletableFuture.supplyAsync(() -> { - QueryWrapper queryWrapper=new QueryWrapper<>(); - if(ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())){ - queryWrapper.eq("category_id",shopProductIndex.getCategory_id()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())) { + queryWrapper.eq("category_id", shopProductIndex.getCategory_id()); } - queryWrapper.eq("store_id",shopProductIndex.getStore_id()); - queryWrapper.eq("product_state_id",StateCode.PRODUCT_STATE_OFF_THE_SHELF); + queryWrapper.eq("store_id", shopProductIndex.getStore_id()); + queryWrapper.eq("product_state_id", StateCode.PRODUCT_STATE_OFF_THE_SHELF); return ((int) shopProductIndexService.count(queryWrapper)); }); CompletableFuture count4 = CompletableFuture.supplyAsync(() -> { - QueryWrapper queryWrapper=new QueryWrapper<>(); - if(ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())){ - queryWrapper.eq("category_id",shopProductIndex.getCategory_id()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())) { + queryWrapper.eq("category_id", shopProductIndex.getCategory_id()); } - queryWrapper.eq("store_id",shopProductIndex.getStore_id()); - queryWrapper.eq("product_state_id",StateCode.PRODUCT_STATE_ILLEGAL); + queryWrapper.eq("store_id", shopProductIndex.getStore_id()); + queryWrapper.eq("product_state_id", StateCode.PRODUCT_STATE_ILLEGAL); return ((int) shopProductIndexService.count(queryWrapper)); }); CompletableFuture count5 = CompletableFuture.supplyAsync(() -> { - QueryWrapper queryWrapper=new QueryWrapper<>(); - if(ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())){ - queryWrapper.eq("category_id",shopProductIndex.getCategory_id()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotEmpty(shopProductIndex.getCategory_id())) { + queryWrapper.eq("category_id", shopProductIndex.getCategory_id()); } - queryWrapper.eq("store_id",shopProductIndex.getStore_id()); - queryWrapper.eq("product_state_id",StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK); + queryWrapper.eq("store_id", shopProductIndex.getStore_id()); + queryWrapper.eq("product_state_id", StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK); return ((int) shopProductIndexService.count(queryWrapper)); }); // 等待所有任务完成 - CompletableFuture allFutures = CompletableFuture.allOf(count1, count2, count3,count4,count5); + CompletableFuture allFutures = CompletableFuture.allOf(count1, count2, count3, count4, count5); allFutures.thenRun(() -> { logger.info("所有统计任务完成"); }); - Integer[] resultInt=new Integer[taskCount]; + Integer[] resultInt = new Integer[taskCount]; try { - resultInt[0]=count1.get(); - resultInt[1]=count2.get(); - resultInt[2]=count3.get(); - resultInt[3]=count4.get(); - resultInt[4]=count5.get(); + resultInt[0] = count1.get(); + resultInt[1] = count2.get(); + resultInt[2] = count3.get(); + resultInt[3] = count4.get(); + resultInt[4] = count5.get(); } catch (Exception e) { throw new RuntimeException(e); } return resultInt; } - public static void main(String[] args) { - AtomicInteger count1=new AtomicInteger(0);//全部 - System.out.println(count1.addAndGet(10)); - System.out.println(count1); - } - } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/controller/mobile/SFExpressController.java b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/controller/mobile/SFExpressController.java index 0ec7dcb1..2d1271a1 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/controller/mobile/SFExpressController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/controller/mobile/SFExpressController.java @@ -8,6 +8,7 @@ package com.suisung.mall.shop.sfexpress.controller.mobile; +import cn.hutool.core.util.StrUtil; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.pojo.res.ThirdApiRes; import com.suisung.mall.common.utils.SseEmitterUtil; @@ -71,6 +72,10 @@ public class SFExpressController { @ApiOperation(value = "查询顺丰同城订单状态流", notes = "查询顺丰同城订单状态流") @RequestMapping(value = "/list-order-feed", method = RequestMethod.POST) public ThirdApiRes listOrderFeed(@RequestParam(name = "order_id", defaultValue = "") String orderId) { + if (StrUtil.isBlank(orderId) || orderId == "undefined" || orderId == "null") { + return new ThirdApiRes().fail(1003, "请求参数有误!"); + } + Map params = new HashMap<>(); params.put("order_id", shopStoreSfOrderService.getSfOrderIdByShopOrderId(orderId)); return sfExpressApiService.listOrderFeed(params); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java index ba2d242e..9541a2be 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sfexpress/service/impl/SFExpressApiServiceImpl.java @@ -313,7 +313,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService { // List orderList = new ArrayList<>(); // orderList.add(shopStoreSfOrderExist.getShop_order_id()); // 取消订单, 流程:订单状态;积分、众宝、库存、礼包、优惠券 有就统统退还 - Boolean success = shopOrderReturnService.sfExpressExpiredForceRefund(shopStoreSfOrderExist.getShop_order_id(), 0); // 不检查订单付款状态 + Boolean success = shopOrderReturnService.sfExpressExpiredForceRefund(shopStoreSfOrderExist.getShop_order_id()); // 不检查订单付款状态 if (!success) { throw new ApiException(I18nUtil._("取消商家订单失败!")); } @@ -578,7 +578,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService { // 重要:订单取消 // success = shopOrderBaseService.cancel(orderList, null, false); - success = shopOrderReturnService.sfExpressExpiredForceRefund(shopOrderId, 0); + success = shopOrderReturnService.sfExpressExpiredForceRefund(shopOrderId); if (!success) { return new ThirdApiRes().fail(-1, "取消订单业务处理失败!"); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java index 7b8715ee..cdd056ab 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java @@ -1315,7 +1315,7 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl 114.132.210.208:8718 - 42.194.196.179 - 3306 - mall_dev - webdev - jbFr9YewcA9Mihx6fnw51Kzq - com.mysql.cj.jdbc.Driver - - - - - - + + + + + + + 42.194.196.179 + 3306 + mall_prod + root + J0XivNvAcR14}pA6Cysm.E27 + com.mysql.cj.jdbc.Driver 114.132.210.208 15