mirror of https://github.com/jeecgboot/jeecg-boot
commit
1456e2eb43
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.RequestBody;
|
import org.jeecg.modules.business.domain.api.mabang.RequestBody;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -18,9 +19,9 @@ public class ChangeOrderRequestBody implements RequestBody {
|
||||||
private String orderStatus;
|
private String orderStatus;
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
private final HashSet<Pair<String, Integer>> oldSkuData;
|
private HashSet<Triple<String, String, Integer>> oldSkuData;
|
||||||
|
|
||||||
private final HashSet<Pair<String, Integer>> newSkuData;
|
private HashSet<Pair<String, Integer>> newSkuData;
|
||||||
|
|
||||||
private final static String DEFAULT_WAREHOUSE_NAME = "SZBA宝安仓";
|
private final static String DEFAULT_WAREHOUSE_NAME = "SZBA宝安仓";
|
||||||
|
|
||||||
|
@ -36,7 +37,25 @@ public class ChangeOrderRequestBody implements RequestBody {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeOrderRequestBody(String platformOrderId, String orderStatus, HashSet<Pair<String, Integer>> oldSkuData,
|
public ChangeOrderRequestBody() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChangeOrderRequestBody buildChangeOrderRequestBody(String platformOrderId, String orderStatus,
|
||||||
|
HashSet<Pair<String, Integer>> oldSkuData,
|
||||||
|
HashSet<Pair<String, Integer>> newSkuData, String remark) {
|
||||||
|
ChangeOrderRequestBody body = new ChangeOrderRequestBody();
|
||||||
|
body.platformOrderId = platformOrderId;
|
||||||
|
body.orderStatus = orderStatus;
|
||||||
|
body.oldSkuData = new HashSet<>();
|
||||||
|
if (oldSkuData != null) {
|
||||||
|
oldSkuData.forEach(pair -> body.oldSkuData.add(Triple.of(pair.getLeft(), null, pair.getRight())));
|
||||||
|
}
|
||||||
|
body.newSkuData = newSkuData;
|
||||||
|
body.remark = remark;
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChangeOrderRequestBody(String platformOrderId, String orderStatus, HashSet<Triple<String, String, Integer>> oldSkuData,
|
||||||
HashSet<Pair<String, Integer>> newSkuData, String remark) {
|
HashSet<Pair<String, Integer>> newSkuData, String remark) {
|
||||||
this.platformOrderId = platformOrderId;
|
this.platformOrderId = platformOrderId;
|
||||||
this.oldSkuData = oldSkuData;
|
this.oldSkuData = oldSkuData;
|
||||||
|
@ -58,17 +77,20 @@ public class ChangeOrderRequestBody implements RequestBody {
|
||||||
putNonNull(json, "remark", remark);
|
putNonNull(json, "remark", remark);
|
||||||
JSONArray stockDataArray = new JSONArray();
|
JSONArray stockDataArray = new JSONArray();
|
||||||
if (oldSkuData != null && !oldSkuData.isEmpty()) {
|
if (oldSkuData != null && !oldSkuData.isEmpty()) {
|
||||||
for (Pair<String, Integer> oldSkuDatum : oldSkuData) {
|
for (Triple<String, String, Integer> oldSkuDatum : oldSkuData) {
|
||||||
JSONObject stockData = new JSONObject();
|
JSONObject stockData = new JSONObject();
|
||||||
stockData.put("warehouseName", DEFAULT_WAREHOUSE_NAME);
|
stockData.put("warehouseName", DEFAULT_WAREHOUSE_NAME);
|
||||||
stockData.put("stockSku", oldSkuDatum.getKey());
|
stockData.put("stockSku", oldSkuDatum.getLeft());
|
||||||
stockData.put("quantity", oldSkuDatum.getValue());
|
if (oldSkuDatum.getMiddle() != null) {
|
||||||
|
stockData.put("erpOrderItemId", oldSkuDatum.getMiddle());
|
||||||
|
}
|
||||||
|
stockData.put("quantity", oldSkuDatum.getRight());
|
||||||
stockData.put("type", OperationType.REMOVE.code);
|
stockData.put("type", OperationType.REMOVE.code);
|
||||||
stockDataArray.add(stockData);
|
stockDataArray.add(stockData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(newSkuData != null) {
|
if (newSkuData != null) {
|
||||||
for (Pair<String, Integer> newSkuDatum : newSkuData) {
|
for (Pair<String, Integer> newSkuDatum : newSkuData) {
|
||||||
JSONObject stockData = new JSONObject();
|
JSONObject stockData = new JSONObject();
|
||||||
stockData.put("warehouseName", DEFAULT_WAREHOUSE_NAME);
|
stockData.put("warehouseName", DEFAULT_WAREHOUSE_NAME);
|
||||||
|
@ -78,7 +100,7 @@ public class ChangeOrderRequestBody implements RequestBody {
|
||||||
stockDataArray.add(stockData);
|
stockDataArray.add(stockData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
putNonNull(json,"stockData", stockDataArray.toJSONString());
|
putNonNull(json, "stockData", stockDataArray.toJSONString());
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ public class AddCardJob implements Job {
|
||||||
// Still no card in order, add one
|
// Still no card in order, add one
|
||||||
HashSet<Pair<String, Integer>> card = new HashSet<>();
|
HashSet<Pair<String, Integer>> card = new HashSet<>();
|
||||||
card.add(Pair.of(CARD_SKU, 1));
|
card.add(Pair.of(CARD_SKU, 1));
|
||||||
ChangeOrderRequestBody changeOrderRequestBody = new ChangeOrderRequestBody(mabangOrder.getPlatformOrderId(), null,
|
ChangeOrderRequestBody changeOrderRequestBody = ChangeOrderRequestBody.buildChangeOrderRequestBody(
|
||||||
null, card, null);
|
mabangOrder.getPlatformOrderId(), null, null, card, null);
|
||||||
changeOrderRequests.add(changeOrderRequestBody);
|
changeOrderRequests.add(changeOrderRequestBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,232 @@
|
||||||
|
package org.jeecg.modules.business.domain.job;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
|
import org.codehaus.jettison.json.JSONException;
|
||||||
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderRequest;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderRequestBody;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderResponse;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
||||||
|
import org.jeecg.modules.business.entity.GiftRule;
|
||||||
|
import org.jeecg.modules.business.entity.PlatformOrder;
|
||||||
|
import org.jeecg.modules.business.service.IGiftRulesService;
|
||||||
|
import org.jeecg.modules.business.service.IPlatformOrderMabangService;
|
||||||
|
import org.jeecg.modules.business.service.IPlatformOrderService;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobDataMap;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.stream.Collector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.groupingBy;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class AddGiftJob implements Job {
|
||||||
|
|
||||||
|
private static final Integer DEFAULT_NUMBER_OF_DAYS = 30;
|
||||||
|
|
||||||
|
private static final List<String> DEFAULT_SHOPS = Arrays.asList("FC Takumiya", "FCFR");
|
||||||
|
private static final Integer DEFAULT_NUMBER_OF_THREADS = 10;
|
||||||
|
private static final String OBSOLETE_STATUS_CODE = "4";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IPlatformOrderService platformOrderService;
|
||||||
|
@Autowired
|
||||||
|
private IGiftRulesService giftRulesService;
|
||||||
|
@Autowired
|
||||||
|
private IPlatformOrderMabangService platformOrderMabangService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
|
LocalDateTime endDateTime = LocalDateTime.now();
|
||||||
|
LocalDateTime startDateTime = endDateTime.minusDays(DEFAULT_NUMBER_OF_DAYS);
|
||||||
|
List<String> shops = DEFAULT_SHOPS;
|
||||||
|
JobDataMap jobDataMap = context.getMergedJobDataMap();
|
||||||
|
String parameter = ((String) jobDataMap.get("parameter"));
|
||||||
|
if (parameter != null) {
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = new JSONObject(parameter);
|
||||||
|
if (!jsonObject.isNull("startDateTime")) {
|
||||||
|
String startDateStr = jsonObject.getString("startDateTime");
|
||||||
|
startDateTime = LocalDateTime.parse(startDateStr);
|
||||||
|
}
|
||||||
|
if (!jsonObject.isNull("endDateTime")) {
|
||||||
|
String endDateStr = jsonObject.getString("endDateTime");
|
||||||
|
endDateTime = LocalDateTime.parse(endDateStr);
|
||||||
|
}
|
||||||
|
if (!jsonObject.isNull("shops")) {
|
||||||
|
JSONArray shopsArray = jsonObject.getJSONArray("shops");
|
||||||
|
List<String> shopList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < shopsArray.length(); i++) {
|
||||||
|
shopList.add(shopsArray.getString(i));
|
||||||
|
}
|
||||||
|
shops = shopList;
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Error while parsing parameter as JSON, falling back to default parameters.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!endDateTime.isAfter(startDateTime)) {
|
||||||
|
throw new RuntimeException("EndDateTime must be strictly greater than StartDateTime !");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PlatformOrder> platformOrders = platformOrderService.fetchUninvoicedOrdersForShops(startDateTime, endDateTime, shops);
|
||||||
|
List<String> platformOrderIds = platformOrders.stream().map(PlatformOrder::getPlatformOrderId).collect(Collectors.toList());
|
||||||
|
List<List<String>> platformOrderIdLists = Lists.partition(platformOrderIds, 10);
|
||||||
|
List<GiftRule> giftRules = giftRulesService.findGiftRulesByShopCode(shops);
|
||||||
|
Map<String, Map<Boolean, List<GiftRule>>> rulesMap = giftRules.stream()
|
||||||
|
.collect(groupingBy(GiftRule::getShopCode,
|
||||||
|
groupingBy(GiftRule::getMatchQuantity)));
|
||||||
|
Map<String, Set<String>> giftSetByShop = giftRules.stream()
|
||||||
|
.collect(Collectors.groupingBy(GiftRule::getShopCode,
|
||||||
|
Collector.of(HashSet::new, (s, rule) -> s.add(rule.getSku()), (s1, s2) -> {
|
||||||
|
s1.addAll(s2);
|
||||||
|
return s1;
|
||||||
|
})));
|
||||||
|
|
||||||
|
List<OrderListRequestBody> requests = new ArrayList<>();
|
||||||
|
for (List<String> platformOrderIdList : platformOrderIdLists) {
|
||||||
|
requests.add(new OrderListRequestBody().setPlatformOrderIds(platformOrderIdList));
|
||||||
|
}
|
||||||
|
List<Order> mabangOrders = new ArrayList<>();
|
||||||
|
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(DEFAULT_NUMBER_OF_THREADS);
|
||||||
|
List<CompletableFuture<Boolean>> futures = requests.stream()
|
||||||
|
.map(request -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
boolean success = false;
|
||||||
|
try {
|
||||||
|
OrderListRawStream rawStream = new OrderListRawStream(request);
|
||||||
|
OrderListStream stream = new OrderListStream(rawStream);
|
||||||
|
List<Order> orders = stream.all();
|
||||||
|
mabangOrders.addAll(orders);
|
||||||
|
success = !orders.isEmpty();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error("Error communicating with MabangAPI", e);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}, executor))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Boolean> results = futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
|
long nbSuccesses = results.stream().filter(b -> b).count();
|
||||||
|
log.info("{}/{} requests have succeeded.", nbSuccesses, requests.size());
|
||||||
|
log.info("{}/{} mabang orders have been retrieved.", mabangOrders.size(), platformOrderIds.size());
|
||||||
|
|
||||||
|
List<Order> ordersWithLogistic = new ArrayList<>();
|
||||||
|
log.info("Constructing gift insertion requests");
|
||||||
|
List<ChangeOrderRequestBody> giftInsertionRequests = constructGiftInsertionRequests(mabangOrders, rulesMap, giftSetByShop, ordersWithLogistic);
|
||||||
|
log.info("{} gift insertion requests to be sent to MabangAPI", giftInsertionRequests.size());
|
||||||
|
|
||||||
|
log.info("Clearing logistic channel names before inserting gifts");
|
||||||
|
platformOrderMabangService.clearLogisticChannel(ordersWithLogistic, executor);
|
||||||
|
|
||||||
|
List<CompletableFuture<Boolean>> giftInsertionFutures = giftInsertionRequests.stream()
|
||||||
|
.map(giftInsertionRequestBody -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
boolean success = false;
|
||||||
|
try {
|
||||||
|
ChangeOrderRequest changeOrderRequest = new ChangeOrderRequest(giftInsertionRequestBody);
|
||||||
|
ChangeOrderResponse response = changeOrderRequest.send();
|
||||||
|
success = response.success();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error("Error communicating with MabangAPI", e);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}, executor))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
results = giftInsertionFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
|
nbSuccesses = results.stream().filter(b -> b).count();
|
||||||
|
log.info("{}/{} gift insertion requests have succeeded.", nbSuccesses, giftInsertionRequests.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<ChangeOrderRequestBody> constructGiftInsertionRequests(List<Order> mabangOrders,
|
||||||
|
Map<String, Map<Boolean, List<GiftRule>>> rulesMap,
|
||||||
|
Map<String, Set<String>> giftSetByShop,
|
||||||
|
List<Order> ordersWithLogistic) {
|
||||||
|
List<ChangeOrderRequestBody> giftInsertionRequests = new ArrayList<>();
|
||||||
|
Map<String, List<Order>> ordersByShop = mabangOrders.stream().collect(groupingBy(Order::getShopErpCode));
|
||||||
|
// Go through orders by Shop
|
||||||
|
for (Map.Entry<String, List<Order>> entry : ordersByShop.entrySet()) {
|
||||||
|
String shopCode = entry.getKey();
|
||||||
|
log.info("Going through orders from shop {}", shopCode);
|
||||||
|
Map<Boolean, List<GiftRule>> rulesByType = rulesMap.get(shopCode);
|
||||||
|
Set<String> giftSkuSet = giftSetByShop.get(shopCode);
|
||||||
|
List<GiftRule> matchingQuantityRules = rulesByType.get(Boolean.TRUE);
|
||||||
|
List<GiftRule> nonMatchingQuantityRules = rulesByType.get(Boolean.FALSE);
|
||||||
|
|
||||||
|
for (Order order : entry.getValue()) {
|
||||||
|
log.info("Processing order {} ", order.getPlatformOrderId());
|
||||||
|
// Non matching-quantity rules only apply once per order
|
||||||
|
boolean nonMatchingRulesApplied = false;
|
||||||
|
HashMap<String, Integer> newGiftMap = new HashMap<>();
|
||||||
|
Map<Boolean, List<OrderItem>> orderItemMap = order.getOrderItems()
|
||||||
|
.stream()
|
||||||
|
.filter(orderItem -> !orderItem.getStatus().equalsIgnoreCase(OBSOLETE_STATUS_CODE))
|
||||||
|
.collect(groupingBy(orderItem -> giftSkuSet.contains(orderItem.getErpCode())));
|
||||||
|
for (OrderItem orderItem : orderItemMap.get(Boolean.FALSE)) {
|
||||||
|
String erpCode = orderItem.getErpCode();
|
||||||
|
if (!nonMatchingRulesApplied) {
|
||||||
|
for (GiftRule giftRule : nonMatchingQuantityRules) {
|
||||||
|
if (erpCode.matches(giftRule.getRegex())) {
|
||||||
|
nonMatchingRulesApplied = true;
|
||||||
|
putValueInMapOrReduce(giftRule.getSku(), 1, newGiftMap);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (GiftRule giftRule : matchingQuantityRules) {
|
||||||
|
if (erpCode.matches(giftRule.getRegex())) {
|
||||||
|
putValueInMapOrReduce(giftRule.getSku(), orderItem.getQuantity(), newGiftMap);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug("Order {} 's new gift map : ", newGiftMap);
|
||||||
|
HashSet<Triple<String, String, Integer>> oldSkuData = new HashSet<>();
|
||||||
|
HashMap<String, Integer> oldGiftMap = new HashMap<>();
|
||||||
|
List<OrderItem> oldGifts = orderItemMap.get(Boolean.TRUE) == null ? new ArrayList<>() : orderItemMap.get(Boolean.TRUE);
|
||||||
|
oldGifts.forEach(orderItem -> {
|
||||||
|
oldSkuData.add(Triple.of(orderItem.getErpCode(),
|
||||||
|
orderItem.getErpOrderItemId(), orderItem.getQuantity()));
|
||||||
|
putValueInMapOrReduce(orderItem.getErpCode(), orderItem.getQuantity(), oldGiftMap);
|
||||||
|
});
|
||||||
|
HashSet<Pair<String, Integer>> newSkuData = new HashSet<>();
|
||||||
|
newGiftMap.forEach((key, value) -> newSkuData.add(Pair.of(key, value)));
|
||||||
|
|
||||||
|
if (!newGiftMap.isEmpty() && !newGiftMap.equals(oldGiftMap)) {
|
||||||
|
ChangeOrderRequestBody changeOrderRequestBody = new ChangeOrderRequestBody(order.getPlatformOrderId(), null,
|
||||||
|
oldSkuData, newSkuData, null);
|
||||||
|
giftInsertionRequests.add(changeOrderRequestBody);
|
||||||
|
|
||||||
|
// If the order already has a logistic channel name, then we need to clear it before inserting gifts
|
||||||
|
if (order.getLogisticChannelName() != null && !order.getLogisticChannelName().isEmpty()) {
|
||||||
|
ordersWithLogistic.add(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("Ended processing orders from shop {}", shopCode);
|
||||||
|
}
|
||||||
|
return giftInsertionRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void putValueInMapOrReduce(String key, Integer value, HashMap<String, Integer> giftMap) {
|
||||||
|
if (giftMap.containsKey(key)) {
|
||||||
|
giftMap.put(key, giftMap.get(key) + value);
|
||||||
|
} else {
|
||||||
|
giftMap.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -142,8 +142,8 @@ public class AddPortraitTubeJob implements Job {
|
||||||
HashSet<Pair<String, Integer>> adequateTubes = currentAndAdequateTubes.getRight();
|
HashSet<Pair<String, Integer>> adequateTubes = currentAndAdequateTubes.getRight();
|
||||||
// Do nothing if current tubes are the adequate tubes
|
// Do nothing if current tubes are the adequate tubes
|
||||||
if (!currentTubes.containsAll(adequateTubes) || !adequateTubes.containsAll(currentTubes)) {
|
if (!currentTubes.containsAll(adequateTubes) || !adequateTubes.containsAll(currentTubes)) {
|
||||||
ChangeOrderRequestBody changeOrderRequestBody = new ChangeOrderRequestBody(mabangOrder.getPlatformOrderId(), null,
|
ChangeOrderRequestBody changeOrderRequestBody = ChangeOrderRequestBody.buildChangeOrderRequestBody(
|
||||||
currentTubes, adequateTubes, null);
|
mabangOrder.getPlatformOrderId(), null, currentTubes, adequateTubes, null);
|
||||||
changeOrderRequests.add(changeOrderRequestBody);
|
changeOrderRequests.add(changeOrderRequestBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ public class AddPortraitTubeJob implements Job {
|
||||||
if (canvasNew46RemainderCount > 0) {
|
if (canvasNew46RemainderCount > 0) {
|
||||||
// TODO 2024-08-28 Temporarily use OLD 50cm tubes for NEW 46cm canvases
|
// TODO 2024-08-28 Temporarily use OLD 50cm tubes for NEW 46cm canvases
|
||||||
tube50SingleCount++;
|
tube50SingleCount++;
|
||||||
} else if (canvas40RemainderCount > 0) {
|
} else if (canvas40RemainderCount > 0 || canvasNew36RemainderCount > 0) {
|
||||||
tube40SingleCount++;
|
tube40SingleCount++;
|
||||||
} else if (canvas30RemainderCount > 0){
|
} else if (canvas30RemainderCount > 0){
|
||||||
tube30SingleDoubleCount++;
|
tube30SingleDoubleCount++;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.jeecg.modules.business.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GiftRule {
|
||||||
|
|
||||||
|
private final String shopCode;
|
||||||
|
|
||||||
|
private final String sku;
|
||||||
|
|
||||||
|
private final String regex;
|
||||||
|
|
||||||
|
private final Boolean matchQuantity;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.jeecg.modules.business.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.jeecg.modules.business.entity.GiftRule;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 添加赠品规则
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2024-09-02
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface GiftRulesMapper extends BaseMapper<GiftRule> {
|
||||||
|
|
||||||
|
List<GiftRule> findByShop(List<String> shopCodes);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.jeecg.modules.business.mapper.GiftRulesMapper">
|
||||||
|
<select id="findByShop" resultType="org.jeecg.modules.business.entity.GiftRule">
|
||||||
|
SELECT s.erp_code AS shop_code,
|
||||||
|
sku.erp_code AS sku,
|
||||||
|
g.normal_sku_regex AS regex,
|
||||||
|
g.match_normal_sku_quantity AS match_quantity
|
||||||
|
FROM gift_rules g JOIN shop s ON g.shop_id = s.id
|
||||||
|
JOIN sku ON g.gift_sku_id = sku.id
|
||||||
|
WHERE s.erp_code IN
|
||||||
|
<foreach collection="shopCodes" separator="," open="(" close=")" item="shopCode">
|
||||||
|
#{shopCode}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.jeecg.modules.business.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.jeecg.modules.business.entity.GiftRule;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 添加赠品规则
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2024-09-02
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface IGiftRulesService extends IService<GiftRule> {
|
||||||
|
|
||||||
|
List<GiftRule> findGiftRulesByShopCode(List<String> shopCodes);
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.jeecg.modules.business.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.modules.business.entity.GiftRule;
|
||||||
|
import org.jeecg.modules.business.mapper.GiftRulesMapper;
|
||||||
|
import org.jeecg.modules.business.service.IGiftRulesService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 添加赠品规则
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2024-09-02
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class GiftRulesServiceImpl extends ServiceImpl<GiftRulesMapper, GiftRule> implements IGiftRulesService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GiftRulesMapper giftRulesMapper;
|
||||||
|
|
||||||
|
public GiftRulesServiceImpl(GiftRulesMapper giftRulesMapper) {
|
||||||
|
this.giftRulesMapper = giftRulesMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GiftRule> findGiftRulesByShopCode(List<String> shopCodes) {
|
||||||
|
return giftRulesMapper.findByShop(shopCodes);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue