# Conflicts:
#	README.md
20230922-ljl-fixBug
wangchaoxu 1 year ago
commit b9ce484b6c

File diff suppressed because one or more lines are too long

@ -9,6 +9,7 @@ import com.ms.api.dto.order.OriginalAndCustomConsigneeInfoResponseDTO;
import com.ms.api.dto.order.RsyncOpOrderByOrderIdsResultDTO;
import com.ms.dal.entity.OpOrder;
import com.ms.dal.entity.OpOrderRsyncPageQueue;
import com.ms.dal.entity.OpOrderRsyncQueue;
import java.util.*;
@ -117,4 +118,6 @@ public interface OpOrderService {
void moveOpPageBufferToQueue(Map<Long, Long> shopIdAndMoveCntMap);
List<OpOrderRsyncQueue> getOpOrderRsyncQueuesByQueueIds(List<String> queueIdsChunk);
}

@ -7,4 +7,6 @@ import com.alibaba.fastjson.JSONObject;
public interface QueueService {
Map<Long, Long> allocBufferToQueueByShopAvg(String bufferName, String queueName, JSONObject filter, int maxQueueCount, Integer shopLimit);
int unlockTimeoutSolidRedisQueue(String tableName, int heartbeatExpiredSeconds, String status);
}

@ -961,7 +961,7 @@ public class OpOrderServiceImpl implements OpOrderService {
afterSaleData.setGmtCreate(new Date());
afterSaleDatas.add(afterSaleData);
Map<String, OpOrderChild> childs = childInfoDatas.stream().collect(Collectors.toMap(OpOrderChild::getChildOrderId, x -> x,(v1,v2)->v1));
Map<String, OpOrderChild> childs = childInfoDatas.stream().collect(Collectors.toMap(OpOrderChild::getChildOrderId, x -> x, (v1, v2) -> v1));
if (ObjectUtil.isNotEmpty(skuOrder.getMasterSkuOrderIdList())) {
for (String masterSkuOrderId : skuOrder.getMasterSkuOrderIdList()) {
OpOrderGivenProduct item = new OpOrderGivenProduct();
@ -1998,11 +1998,19 @@ public class OpOrderServiceImpl implements OpOrderService {
startBufferId = chunkBufferList.stream().map(OpOrderRsyncPageBuffer::getOpOrderRsyncPageBufferId).max(Long::compare).orElse(0L);
startMoveOpPageBufferToQueue(chunkBufferList, shopIdAndMoveCntMap);
shopIdAndMoveCntMap = shopIdAndMoveCntMap.entrySet().stream().filter(r -> r.getValue() > 0)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,(v1,v2)->v1));
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
}
log.info("end moveOpPageBufferToQueue");
}
@Override
public List<OpOrderRsyncQueue> getOpOrderRsyncQueuesByQueueIds(List<String> queueIds) {
if (ObjectUtil.isEmpty(queueIds)) {
return new ArrayList<>();
}
return opOrderRsyncQueueMapper.getByIdList(queueIds);
}
private ApiResult startMoveOpPageBufferToQueue(List<OpOrderRsyncPageBuffer> bufferList, Map<Long, Long> shopIdAndMoveCntMap) {
List<Long> deleteBufferIds = new ArrayList<>();
List<OpOrderRsyncPageQueue> insertQueueList = new ArrayList<>();

@ -299,7 +299,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
List<String> orderIds = orderList.stream().map(OpOrder::getOrderId).collect(Collectors.toList());
Map<String, List<PurchaseOrderBO>> orderIdAndPurchaseOrdersMap = getOrderIdAndPurchaseOrdersMap(shopIds, orderIds, filter, true, false);
Map<Long, Shop> shopIdAndShopInfoMap = shopService.getShopByIds(shopIds).stream().collect(Collectors.toMap(Shop::getShopId, x -> x,(v1,v2)->v1));
Map<Long, Shop> shopIdAndShopInfoMap = shopService.getShopByIds(shopIds).stream().collect(Collectors.toMap(Shop::getShopId, x -> x, (v1, v2) -> v1));
Map<String, String> orderIdAndSameOrderIdsMap = new HashMap<>();
// TODO: 2023/8/28 配置表已经没有相关字段 跳过
// if (ObjectUtil.isNotNull(filter.getIsShowSameReceiverOrder()) && filter.getIsShowSameReceiverOrder()) {
@ -331,7 +331,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
}
List<OpOrderOutstorageHistory> opOrderOutstorageHistoryRows = opOrderOutstorageHistoryService.getByIdList(opOrderOutstorageHistoryIds);
Map<String, OpOrderOutstorageHistory> orderIdAndOpOrderOutstrorageHistoryMap = opOrderOutstorageHistoryRows.stream().collect(Collectors.toMap(OpOrderOutstorageHistory::getOrderId, x -> x,(v1,v2)->v1));
Map<String, OpOrderOutstorageHistory> orderIdAndOpOrderOutstrorageHistoryMap = opOrderOutstorageHistoryRows.stream().collect(Collectors.toMap(OpOrderOutstorageHistory::getOrderId, x -> x, (v1, v2) -> v1));
for (JSONObject order : orders) {
if (isDs && !OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS.equals(order.get("orderStatus"))) {
@ -694,7 +694,8 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
if (needItems) {
List<String> purchaseOrderIds = purchaseOrders.stream().map(x -> x.getPurchaseOrderId().toString()).collect(Collectors.toList());
Map<Integer, PurchaseOrderItem> purchaseOrderItemsMap = getPurchaseOrderItemsMapByPurchaseOrderIds(shopIds, purchaseOrderIds, StatusConst.normal).stream().collect(Collectors.toMap(PurchaseOrderItem::getPurchaseOrderId, x -> x,(v1,v2)->v1));
Map<Integer, List<PurchaseOrderItem>> purchaseOrderItemsMap = getPurchaseOrderItemsMapByPurchaseOrderIds(shopIds, purchaseOrderIds, StatusConst.normal).stream()
.collect(Collectors.groupingBy(PurchaseOrderItem::getPurchaseOrderId));
for (PurchaseOrderBO purchaseOrder : purchaseOrders) {
if (purchaseOrderItemsMap.containsKey(purchaseOrder.getPurchaseOrderId().intValue())) {
purchaseOrder.setItem(purchaseOrderItemsMap.get(purchaseOrder.getPurchaseOrderId().intValue()));
@ -739,7 +740,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
// }
// }
return rows.stream().collect(Collectors.toMap(PurchaseOrderSetting::getPurchaseOrderId, x -> x,(v1,v2)->v1));
return rows.stream().collect(Collectors.toMap(PurchaseOrderSetting::getPurchaseOrderId, x -> x, (v1, v2) -> v1));
}
@Override
@ -1296,7 +1297,9 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
for (Map.Entry<String, List<PurchaseOrderBO>> entry : orderIdAndPurchaseOrdersMap.entrySet()) {
purchaserOrderIds.addAll(entry.getValue().stream().map(PurchaseOrderBO::getPurchaseOrderId).collect(Collectors.toSet()));
for (PurchaseOrderBO orderBO : entry.getValue()) {
purchaserOrderItemIds.add(orderBO.getItem().getPurchaseOrderItemId());
for (PurchaseOrderItem purchasOrderItem : orderBO.getItem()) {
purchaserOrderItemIds.add(purchasOrderItem.getPurchaseOrderItemId());
}
}
}
// TODO: 2023/8/29 跳过 purchase_use_fixed_mobile_log purchase_order_platform_info purchase_order_need_check_status purchase_order_custom purchase_order_item_relate_source
@ -1339,7 +1342,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
List<OpOrderChildBO> items = orderIdAndOpOrderChildMap.get(orderId);
Map<Long, OpOrderChildBO> skuIdAndOrderChildMap = this.mergeOpOrderChildSameSku(items);
List<AfterSale> currentOrderAfterSales = ObjectUtil.isNotEmpty(orderIdAndAftersalesMap.get(orderId)) ? orderIdAndAftersalesMap.get(orderId) : new ArrayList<>();
Map<String, AfterSale> childOrderIdAndAfterSaleMap = currentOrderAfterSales.stream().collect(Collectors.toMap(AfterSale::getOrderId, x -> x,(v1,v2)->v1));
Map<String, AfterSale> childOrderIdAndAfterSaleMap = currentOrderAfterSales.stream().collect(Collectors.toMap(AfterSale::getOrderId, x -> x, (v1, v2) -> v1));
attachSourceItemInfoToOpOrderChilds(skuIdAndOrderChildMap, productIdAndProductToDsItemMap, childOrderIdAndAfterSaleMap);
List<String> sourceItemIds = skuIdAndOrderChildMap.values().stream().map(OpOrderChildBO::getSourceItemId).collect(Collectors.toList());
@ -1372,7 +1375,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
// orderAddressChangeApply = orderIdAndOrderAddressChangeApplyMap[orderId];
Map<String, JSONObject> purchasePlatforms = ObjectUtil.isEmpty(returnPurchaseOrders) ? new HashMap<>() : returnPurchaseOrders.values().stream().collect(Collectors.toMap(x -> x.getString("purchasePlatform"), x -> x,(v1,v2)->v1));
Map<String, JSONObject> purchasePlatforms = ObjectUtil.isEmpty(returnPurchaseOrders) ? new HashMap<>() : returnPurchaseOrders.values().stream().collect(Collectors.toMap(x -> x.getString("purchasePlatform"), x -> x, (v1, v2) -> v1));
if (ObjectUtil.isEmpty(sourceItemIds) && purchasePlatforms.containsKey(PurchaseOrderConst.PURCHASE_PLATFORM1688_D_S)) {
needDeleteOpOrderDsOrderIds.add(orderId);
}
@ -1566,7 +1569,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
private void rebuildNoPurchaseOrderItems(Map<Long, OpOrderChildBO> skuIdAndOrderChildMap, List<Long> hasPurchaseSkuIds, List<OpOrderChildLogistics> childOrderLogistics, List<OpOrderPriceProtection> priceProtectionList,
Map<Long, List<OpOrderGivenProduct>> childOrderIdAndGivenProductsMap, List<JSONObject> returnOrderItems, List<JSONObject> noPurchaseOrderItems, BigDecimal orderTotalAmount) {
Map<String, List<OpOrderChildLogistics>> childOrderIdAndLogisticsMap = childOrderLogistics.stream().collect(Collectors.groupingBy(OpOrderChildLogistics::getChildOrderId));
Map<String, OpOrderPriceProtection> childOrderIdAndPriceProtectionMap = priceProtectionList.stream().collect(Collectors.toMap(OpOrderPriceProtection::getChildOrderId, x -> x,(v1,v2)->v1));
Map<String, OpOrderPriceProtection> childOrderIdAndPriceProtectionMap = priceProtectionList.stream().collect(Collectors.toMap(OpOrderPriceProtection::getChildOrderId, x -> x, (v1, v2) -> v1));
for (Map.Entry<Long, OpOrderChildBO> entry : skuIdAndOrderChildMap.entrySet()) {
OpOrderChildBO item = entry.getValue();
String skuSubNames = item.getSkuSubName();
@ -1614,75 +1617,76 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
if (ObjectUtil.isNotEmpty(purchaseOrders)) {
List<JSONObject> returnPurchaseOrderItems = new ArrayList<>();
for (PurchaseOrderBO purchaseOrder : purchaseOrders) {
PurchaseOrderItem purchaseOrderItem = purchaseOrder.getItem();
hasPurchaseSkuIds.add(purchaseOrderItem.getSkuId());
Long skuId = purchaseOrderItem.getSkuId();
OpOrderChildBO item = skuIdAndOrderChildMap.get(skuId);
List<OpOrderChildLogistics> logisticsInfos = childOrderIdAndLogisticsMap.getOrDefault(item.getChildOrderId(), new ArrayList<>());
List<OpOrderPriceProtection> priceProtectionInfo = childOrderIdAndPriceProtectionMap.getOrDefault(item.getChildOrderId(), new ArrayList<>());
List<OpOrderGivenProduct> giveItems = childOrderIdAndGivenProductsMap.getOrDefault(Long.parseLong(item.getChildOrderId()), new ArrayList<>());
for (PurchaseOrderItem purchaseOrderItem : purchaseOrder.getItem()) {
hasPurchaseSkuIds.add(purchaseOrderItem.getSkuId());
Long skuId = purchaseOrderItem.getSkuId();
OpOrderChildBO item = skuIdAndOrderChildMap.get(skuId);
List<OpOrderChildLogistics> logisticsInfos = childOrderIdAndLogisticsMap.getOrDefault(item.getChildOrderId(), new ArrayList<>());
List<OpOrderPriceProtection> priceProtectionInfo = childOrderIdAndPriceProtectionMap.getOrDefault(item.getChildOrderId(), new ArrayList<>());
List<OpOrderGivenProduct> giveItems = childOrderIdAndGivenProductsMap.getOrDefault(Long.parseLong(item.getChildOrderId()), new ArrayList<>());
String skuSubNames = item.getSkuSubName();
String skuSubNames = item.getSkuSubName();
JSONObject returnPurchaseOrderItem = new JSONObject();
JSONObject returnPurchaseOrderItem = new JSONObject();
returnPurchaseOrderItem.put("purchaseOrderItemId", purchaseOrderItem.getPurchaseOrderItemId());
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("purchaseOrderItemId", purchaseOrderItem.getPurchaseOrderItemId());
// TODO: 2023/8/29 跳过
// returnPurchaseOrderItem.put("purchaseItemCode", purchaseOrderItem.get("code"));
returnPurchaseOrderItem.put("childOrderId", item.getChildOrderId());
returnPurchaseOrderItem.put("orderId", item.getOrderId());
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("childOrderId", item.getChildOrderId());
returnPurchaseOrderItem.put("orderId", item.getOrderId());
// TODO: 2023/8/29 跳过
// returnPurchaseOrderItem.put("shopId", item.get("shop_id"));
returnPurchaseOrderItem.put("code", item.getCode());
returnPurchaseOrderItem.put("itemNum", item.getItemNum());
returnPurchaseOrderItem.put("wareId", purchaseOrderItem.getWareId());
returnPurchaseOrderItem.put("skuId", purchaseOrderItem.getSkuId());
returnPurchaseOrderItem.put("purchaseUrl", purchaseOrderItem.getPurchaseUrl());
returnPurchaseOrderItem.put("purchasePrice", purchaseOrderItem.getPurchasePrice());
returnPurchaseOrderItem.put("purchaseNum", purchaseOrderItem.getPurchaseNum());
returnPurchaseOrderItem.put("outSkuId", item.getOutSkuId());
returnPurchaseOrderItem.put("title", item.getProductName());
returnPurchaseOrderItem.put("skuName", item.getProductName() + "_" + String.join(" ", skuSubNames));
returnPurchaseOrderItem.put("jdPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnPurchaseOrderItem.put("itemTotal", item.getComboNum());
returnPurchaseOrderItem.put("logo", item.getProductPic());
returnPurchaseOrderItem.put("totalPrice", item.getTotalAmount());
returnPurchaseOrderItem.put("orderStatus", item.getOrderStatus());
returnPurchaseOrderItem.put("skuSubName", String.join(" ", skuSubNames));
returnPurchaseOrderItem.put("couponPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnPurchaseOrderItem.put("totalAmount", CommonTool.correctCentToYuan(item.getTotalAmount()));
returnPurchaseOrderItem.put("shopCouponAmount", CommonTool.correctCentToYuan(item.getShopCouponAmount()));
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("url", CommonTool.buildDdProductUrl(item.getProductId()));
returnPurchaseOrderItem.put("sourceItemId", item.getSourceItemId());
returnPurchaseOrderItem.put("sourceSellerId", item.getSourceSellerId());
returnPurchaseOrderItem.put("sourcePlatform", item.getSource_platform());
returnPurchaseOrderItem.put("logisticsInfos", JSONArray.toJSONString(logisticsInfos));
returnPurchaseOrderItem.put("priceProtection", priceProtectionInfo);
returnPurchaseOrderItem.put("dsRefundStatus", item.getDsRefundStatus());
returnPurchaseOrderItem.put("dsRefundStatusName", item.getDsRefundStatusName());
returnPurchaseOrderItem.put("cBiz", item.getCBiz());
returnPurchaseOrderItem.put("isPurchase", hasPurchaseSkuIds.contains(item.getSkuId()) ? 1 : 0);
returnPurchaseOrderItem.put("sourceItem", item.getSourceItem());
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("code", item.getCode());
returnPurchaseOrderItem.put("itemNum", item.getItemNum());
returnPurchaseOrderItem.put("wareId", purchaseOrderItem.getWareId());
returnPurchaseOrderItem.put("skuId", purchaseOrderItem.getSkuId());
returnPurchaseOrderItem.put("purchaseUrl", purchaseOrderItem.getPurchaseUrl());
returnPurchaseOrderItem.put("purchasePrice", purchaseOrderItem.getPurchasePrice());
returnPurchaseOrderItem.put("purchaseNum", purchaseOrderItem.getPurchaseNum());
returnPurchaseOrderItem.put("outSkuId", item.getOutSkuId());
returnPurchaseOrderItem.put("title", item.getProductName());
returnPurchaseOrderItem.put("skuName", item.getProductName() + "_" + String.join(" ", skuSubNames));
returnPurchaseOrderItem.put("jdPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnPurchaseOrderItem.put("itemTotal", item.getComboNum());
returnPurchaseOrderItem.put("logo", item.getProductPic());
returnPurchaseOrderItem.put("totalPrice", item.getTotalAmount());
returnPurchaseOrderItem.put("orderStatus", item.getOrderStatus());
returnPurchaseOrderItem.put("skuSubName", String.join(" ", skuSubNames));
returnPurchaseOrderItem.put("couponPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnPurchaseOrderItem.put("totalAmount", CommonTool.correctCentToYuan(item.getTotalAmount()));
returnPurchaseOrderItem.put("shopCouponAmount", CommonTool.correctCentToYuan(item.getShopCouponAmount()));
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("url", CommonTool.buildDdProductUrl(item.getProductId()));
returnPurchaseOrderItem.put("sourceItemId", item.getSourceItemId());
returnPurchaseOrderItem.put("sourceSellerId", item.getSourceSellerId());
returnPurchaseOrderItem.put("sourcePlatform", item.getSource_platform());
returnPurchaseOrderItem.put("logisticsInfos", JSONArray.toJSONString(logisticsInfos));
returnPurchaseOrderItem.put("priceProtection", priceProtectionInfo);
returnPurchaseOrderItem.put("dsRefundStatus", item.getDsRefundStatus());
returnPurchaseOrderItem.put("dsRefundStatusName", item.getDsRefundStatusName());
returnPurchaseOrderItem.put("cBiz", item.getCBiz());
returnPurchaseOrderItem.put("isPurchase", hasPurchaseSkuIds.contains(item.getSkuId()) ? 1 : 0);
returnPurchaseOrderItem.put("sourceItem", item.getSourceItem());
// TODO: 2023/8/29 跳过
// returnPurchaseOrderItem.put("estimatedCommission", item.get("estimated_commission"));
returnPurchaseOrderItem.put("givenProductItems", JSONArray.toJSONString(giveItems));
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("givenProductItems", JSONArray.toJSONString(giveItems));
// TODO: 2023/8/29 跳过
// if (purchaseOrderItemRelateSourceMap.containsKey(purchaseOrderItem.get("purchase_order_id"))) {
// returnPurchaseOrderItem.put("isManual", purchaseOrderItemRelateSourceMap.get(purchaseOrderItem.get("purchase_order_id")).equals("manual"));
// } else {
// returnPurchaseOrderItem.put("isManual", purchaseOrderItem.get("purchase_url").isEmpty());
// }
returnPurchaseOrderItem.put("isManual", purchaseOrderItem.getPurchaseUrl().isEmpty());
// TODO: 2023/8/29 跳过
returnPurchaseOrderItem.put("isManual", purchaseOrderItem.getPurchaseUrl().isEmpty());
// TODO: 2023/8/29 跳过
// returnPurchaseOrderItem['purchaseClickTimes'] = 0;
// foreach(opItemPurchaseClicks as opItemPurchaseClick) {
// if (opItemPurchaseClick['sku_id'] == item['combo_id']) {
// returnPurchaseOrderItem['purchaseClickTimes'] += opItemPurchaseClick['click_times'];
// }
// }
returnPurchaseOrderItems.add(returnPurchaseOrderItem);
skuIdAndPurchaseOrderIdMap.put(purchaseOrderItem.getSkuId(), purchaseOrder.getPurchaseOrderId());
returnPurchaseOrderItems.add(returnPurchaseOrderItem);
skuIdAndPurchaseOrderIdMap.put(purchaseOrderItem.getSkuId(), purchaseOrder.getPurchaseOrderId());
}
JSONObject returnPurchaseSetting = new JSONObject();
if (ObjectUtil.isNotNull(purchaseOrder.getPurchaseSetting())) {
returnPurchaseSetting.put("isAddConsigneeSuffix", purchaseOrder.getPurchaseSetting().getIsAddConsigneeSuffix());

@ -1,13 +1,20 @@
package com.ms.api.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.ms.api.consts.QueueConst;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.service.QueueService;
import com.ms.api.tool.CommonTool;
import com.ms.dal.mapper.QueueMapper;
@ -36,6 +43,92 @@ public class QueueServiceImpl implements QueueService {
return allotShopMoveBufferCnt(shopIdAndCntMap, allowMoveCnt);
}
@Override
public int unlockTimeoutSolidRedisQueue(String tableName, int heartbeatExpiredSeconds, String status) {
int c1 = unlockSolidRedisDeadQueue(tableName, heartbeatExpiredSeconds, status);
int c2 = unlockSolidRedisSkipQueue(tableName, status);
return c1 + c2;
}
private int unlockSolidRedisSkipQueue(String queueName, String status) {
String queueRedisKey = RedisKeyConst.getQueueRedisKey(queueName, false);
List<String> redisIds = redisTemplate.opsForList().range(queueRedisKey, 0, -1);
if (ObjectUtil.isEmpty(redisIds)) {
redisIds = new ArrayList<>();
}
StringBuilder where = new StringBuilder();
if (StrUtil.isNotBlank(status)) {
where.append(String.format(" AND status = '%s'", status));
}
String queueIdColumnName = QueueConst.getQueueIdColumnName(queueName);
Long startQueueId = 0L;
int limit = 100;
List<Map<String, Object>> allQueueList = new ArrayList<>();
while (true) {
StringBuilder queueIdWhere = new StringBuilder(" WHERE locked = 0 ");
if (startQueueId > 0) {
queueIdWhere.append(String.format(" AND %s > %s", queueIdColumnName, startQueueId));
}
if (ObjectUtil.isNotNull(where) && StrUtil.isNotBlank(where.toString())) {
queueIdWhere.append(where);
}
queueIdWhere.append(String.format(" order by %s asc limit %s", queueIdColumnName, limit));
List<Map<String, Object>> queueList = queueMapper.select(queueName, queueIdWhere.toString());
if (ObjectUtil.isEmpty(queueList)) {
break;
}
startQueueId = (Long) queueList.get(queueList.size() - 1).getOrDefault(queueIdColumnName, null);
allQueueList.addAll(queueList);
if (queueList.size() < limit) {
break;
}
}
if (ObjectUtil.isEmpty(allQueueList)) {
return 0;
}
List<String> newRedisIds = redisTemplate.opsForList().range(queueRedisKey, 0, -1);
if (ObjectUtil.isEmpty(newRedisIds)) {
newRedisIds = new ArrayList<>();
}
Set<String> tempRedisIds = new HashSet<>();
tempRedisIds.addAll(redisIds);
tempRedisIds.addAll(newRedisIds);
for (Map<String, Object> queue : allQueueList) {
Long queueId = (Long) queue.getOrDefault(queueIdColumnName, null);
if (ObjectUtil.isNotNull(queueId)) {
String queueIdStr = queueId.toString();
if (redisIds.contains(queueIdStr)) {
continue;
}
redisTemplate.opsForList().leftPush(queueRedisKey, queueIdStr);
}
}
return allQueueList.size();
}
private int unlockSolidRedisDeadQueue(String tableName, int heartbeatExpiredSeconds, String status) {
DateTime deadTime = DateUtil.offsetSecond(new Date(), -heartbeatExpiredSeconds);
String where = String.format(" WHERE locked > 0 AND gmt_last_heartbeat < '%s' ", DateUtil.formatDateTime(deadTime));
if (StrUtil.isBlank(status)) {
where = where.concat(String.format(" and `status` = %s ", status));
}
List<Map<String, Object>> queueList = queueMapper.select(tableName, where);
if (ObjectUtil.isEmpty(queueList)) {
return 0;
}
String queueIdColumnName = QueueConst.getQueueIdColumnName(tableName);
int ar1 = 0;
for (Map<String, Object> queue : queueList) {
Long queueId = (Long) queue.get(queueIdColumnName);
if (ObjectUtil.isNotNull(queueId)) {
ar1 = queueMapper.updateLocked(tableName, queueIdColumnName, queueId, 0, DateUtil.now());
String queueRedisKey = RedisKeyConst.getQueueRedisKey(queueIdColumnName, false);
redisTemplate.opsForList().leftPush(queueRedisKey, queueId.toString());
}
}
return queueList.size();
}
private Map<Long, Long> rebuildShopIdAndCntMapByShopLimit(Map<Long, Long> shopIdAndCntMap, String queueName, Integer shopLimit) {
if (ObjectUtil.isEmpty(shopIdAndCntMap) || ObjectUtil.isNull(shopLimit)) {
return shopIdAndCntMap;

@ -45,9 +45,13 @@ public class SaveCurrentShopMoveSettingService extends SPIBaseService implements
if (fields.getPriceDecimalTypeRedio().equals("priceTail")) {
moveShopSettings.setPriceTail(fields.getPriceTail());
moveShopSettings.setPriceDecimal(null);
moveShopSettings.setPriceDecimalType(fields.getPriceDecimalType());
moveShopSettings.setPriceDecimalTypeRedio(fields.getPriceDecimalTypeRedio());
} else if (fields.getPriceDecimalTypeRedio().equals("priceDecimalType")) {
moveShopSettings.setPriceTail(0);
moveShopSettings.setPriceDecimal(fields.getPriceDecimalType());
moveShopSettings.setPriceDecimalType(fields.getPriceDecimalType());
moveShopSettings.setPriceDecimalTypeRedio(fields.getPriceDecimalTypeRedio());
}
moveShopSettings.setMoveOnsaleType(fields.getMoveOnsaleType());
moveShopSettings.setFreightTemplateId(fields.getFreightTemplateId());

@ -0,0 +1,73 @@
package com.ms.api.spi.timer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.TimerBaseService;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.consts.StatusConst;
import com.ms.api.dto.ItemDTO;
import com.ms.api.service.OpOrderService;
import com.ms.dal.entity.OpOrderRsyncQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@ExtensionService("clearRedisRsyncOpOrderCompletedMap")
@Slf4j
public class ClearRedisRsyncOpOrderCompletedMapService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private OpOrderService opOrderService;
@Override
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
log.info(" start clearRedisRsyncOpOrderCompletedMap");
List<String> queueIds = new ArrayList<>((Set<String>) (Set) redisTemplate.opsForHash().keys(RedisKeyConst.RSYNC_OP_ORDER_QUEUE_COMPLETED_MAP));
if (ObjectUtil.isEmpty(queueIds)) {
return R.ok(Ret.success());
}
List<List<String>> queueIdsChunks = new ArrayList<>();
for (int i = 0; i < queueIds.size(); i += 50) {
int endIndex = Math.min(i + 50, queueIds.size());
queueIdsChunks.add(CollectionUtil.sub(queueIds, i, endIndex));
}
for (List<String> queueIdsChunk : queueIdsChunks) {
List<OpOrderRsyncQueue> queueInfos = opOrderService.getOpOrderRsyncQueuesByQueueIds(queueIdsChunk);
Map<String, OpOrderRsyncQueue> queueIdAndQueueInfoMap = queueInfos.stream().collect(Collectors.toMap(x -> x.getOpOrderRsyncQueueId().toString(), x -> x, (v1, v2) -> v1));
for (String queueId : queueIdsChunk) {
OpOrderRsyncQueue queueInfo = queueIdAndQueueInfoMap.getOrDefault(queueId, null);
boolean needDelete = false;
if (ObjectUtil.isNull(queueInfo)) {
needDelete = true;
} else if (queueInfo.getStatus().equals(StatusConst.processing) && queueInfo.getGmtCreate().compareTo(DateUtil.offsetDay(new Date(), -1)) < 0) {
needDelete = true;
}
if (!needDelete) {
continue;
}
redisTemplate.opsForHash().delete(RedisKeyConst.RSYNC_OP_ORDER_QUEUE_COMPLETED_MAP, queueId);
log.info("deleteQueueId:[{}]", queueId);
}
}
log.info(" end clearRedisRsyncOpOrderCompletedMap");
return R.ok(Ret.success());
}
}

@ -0,0 +1,31 @@
package com.ms.api.spi.timer;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.TimerBaseService;
import com.ms.api.consts.StatusConst;
import com.ms.api.consts.TblConst;
import com.ms.api.dto.ItemDTO;
import com.ms.api.service.QueueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ExtensionService("opUnlockTimeoutQueueTimer")
@Slf4j
public class OpUnlockTimeoutQueueTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
@Autowired
private QueueService queueService;
@Override
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
queueService.unlockTimeoutSolidRedisQueue(TblConst.op_order_rsync_queue, 300, StatusConst.wait);
queueService.unlockTimeoutSolidRedisQueue(TblConst.op_order_rsync_page_queue, 300, null);
return R.ok(Ret.success());
}
}

@ -1,5 +1,7 @@
package com.ms.dal.bo;
import java.util.List;
import com.ms.dal.entity.PurchaseOrder;
import com.ms.dal.entity.PurchaseOrderItem;
import com.ms.dal.entity.PurchaseOrderSetting;
@ -8,7 +10,7 @@ import lombok.Data;
@Data
public class PurchaseOrderBO extends PurchaseOrder {
private PurchaseOrderItem item;
private List<PurchaseOrderItem> item;
private PurchaseOrderSetting purchaseSetting;

@ -30,5 +30,7 @@ public interface OpOrderRsyncQueueMapper {
OpOrderRsyncQueue queryFirstRowByQueueId(@Param("queueId") String queueId);
OpOrderRsyncQueue getLastByQueueIdAndStatus(@Param("queueId")Long queueId, @Param("status")String status);
OpOrderRsyncQueue getLastByQueueIdAndStatus(@Param("queueId") Long queueId, @Param("status") String status);
List<OpOrderRsyncQueue> getByIdList(@Param("queueIds") List<String> queueIds);
}

@ -1,5 +1,6 @@
package com.ms.dal.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.MapKey;
@ -13,4 +14,12 @@ public interface QueueMapper {
@MapKey("shop_id")
Map<Long, Map<String, Object>> selectShopIdAndCnt(@Param("bufferName") String bufferName, @Param("whereStr") String whereStr);
List<Map<String, Object>> select(@Param("tableName") String tableName, @Param("whereStr") String where);
int updateLocked(@Param("tableName") String tableName,
@Param("queueIdName") String queueIdName,
@Param("queueId") Long queueId,
@Param("locked") int locked,
@Param("gmtModified") String gmtModified);
}

@ -61,6 +61,14 @@
order by `gmt_modified` asc"
limit 1
</select>
<select id="getByIdList" resultType="com.ms.dal.entity.OpOrderRsyncQueue">
select *
from op_order_rsync_queue
where op_order_rsync_queue_id IN
<foreach collection="queueIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from op_order_rsync_queue

@ -3,6 +3,11 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ms.dal.mapper.QueueMapper">
<update id="updateLocked">
update ${bufferName}
set locked =#{locked},gmt_modified='${gmtModified}'
where ${queueIdName} = ${queueId}
</update>
<select id="getQueueCnt" resultType="java.lang.Integer">
@ -16,4 +21,8 @@
GROUP BY shop_id
</select>
<select id="select" resultType="java.util.Map">
SELECT * FROM ${tableName}
${whereStr}
</select>
</mapper>

Loading…
Cancel
Save