Merge remote-tracking branch 'origin/master'

# Conflicts:
#	ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java
#	ms-dal/src/main/java/com/ms/dal/mapper/PurchaseOrderMapper.java
#	ms-dal/src/main/resources/mapper/PurchaseOrderMapper.xml
20230922-ljl-fixBug
daixiaogang 1 year ago
commit 48733fe8af

@ -24,4 +24,6 @@ public interface OpOrderExtService {
OpOrderExt getByOrderId(String orderId);
List<OpOrderExt> selectByConditions(OpOrderExt ext);
OpOrderExt updateOpOrderShopNote(Long shopId, String orderId, String shopNote);
}

@ -61,6 +61,8 @@ public interface PurchaseOrderService {
int updateStatusByIds(String status, List<Long> ids);
Map<String, Double> getPaymentInfoByOrderId(String orderId);
/**
*
* @param orderId

@ -1,5 +1,6 @@
package com.ms.api.service.impl;
import com.ms.api.consts.AppConst;
import com.ms.api.consts.OrderConst;
import com.ms.api.consts.PurchaseOrderConst;
import com.ms.api.consts.StatusConst;
@ -7,6 +8,8 @@ import com.ms.api.dto.dsapi.request.*;
import com.ms.api.dto.dsapi.response.*;
import com.ms.api.dto.dsorder.*;
import com.ms.api.service.*;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.PurchaseTool;
import com.ms.dal.entity.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
@ -16,6 +19,10 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -72,6 +79,9 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
@Autowired
private DsApiService dsApiService;
@Autowired
private ShopService shopService;
private void batchCreateDistributionOrders(Long shopId, BatchCreateDistributionOrdersRequestDTO request) {
List<PlatformOrderDTO> platformOrders = request.getPlatformOrders();
@ -399,12 +409,211 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
}
}
private void buildAndUpdateNewPurchaseOrderRemark(OpOrder opOrder) {
OpOrderAmountDetail amountDetail = opOrderAmountDetailService.getByOrderId(opOrder.getOrderId());
OpOrderRedpackInfo redpackInfo = opOrderRedpackInfoService.getByOrderId(opOrder.getOrderId());
private HashMap<String, String> buildAndUpdateNewPurchaseOrderRemark(OpOrder opOrder) {
HashMap<String, String> result = new HashMap<>();
PurchaseSetting purchaseSetting = purchaseSettingService.getByShopId(opOrder.getShopId());
List<PurchaseOrder> purchaseOrders = purchaseOrderService.getListByOrderId(opOrder.getShopId(), opOrder.getOpOrderId().toString(), StatusConst.normal,false);
int orderPayment = opOrder.getOrderTotalAmount().intValue() + opOrder.getPostAmount().intValue() + opOrder.getCouponAmount().intValue() + amountDetail.getTalentCouponAmount() + redpackInfo.getPlatformRedpackAmount() + redpackInfo.getTalentRedpackAmount();
List<PurchaseOrder> purchaseOrders = purchaseOrderService.getListByOrderId(opOrder.getShopId(), opOrder.getOpOrderId().toString(), StatusConst.normal,true);
if (purchaseSetting.getIsAppendShopNote() == 0 && purchaseSetting.getIsAppendShopRemark() == 0 && purchaseSetting.getShopRemarkFlag() > 0) {
return result;
}
String newShopNote = buildAndUpdateNewShopNote(opOrder.getShopId(), opOrder.getOrderId(), purchaseSetting.getAppendShopNoteTpl(), purchaseOrders);
String newSellerWords = buildAndUpdateNewSellerWords(opOrder.getShopId(), opOrder.getOrderId(), purchaseSetting.getAppendShopRemarkTpl(), purchaseOrders, purchaseSetting.getShopRemarkFlag());
result.put("shopNote", newShopNote);
result.put("sellerWords", newSellerWords);
return result;
}
private String buildAndUpdateNewSellerWords(Long shopId, String orderId, String remarkTpl, List<PurchaseOrder> purchaseOrders, Integer shopRemarkFlag) {
OpOrder opOrder = opOrderService.selectByOrderId(orderId);
String oldSellerWords = opOrder.getSellerWords();
String newSellerWords = "";
if (StringUtils.isBlank(remarkTpl)) {
return oldSellerWords;
}
String purchaseOrderRemark = buildPurchaseOrderRemark(shopId, remarkTpl, purchaseOrders);
String appChineseName = "";
Pattern p = Pattern.compile("【(" + appChineseName + "|0.0)[^】]*】");
Matcher m = p.matcher(oldSellerWords);
StringBuffer newShopNoteBuffer = new StringBuffer(oldSellerWords.length());
while (m.find()) {
m.appendReplacement(newShopNoteBuffer, purchaseOrderRemark);
}
m.appendTail(newShopNoteBuffer);
newSellerWords = newShopNoteBuffer.toString();
if (newSellerWords.equals(oldSellerWords)) {
return newSellerWords;
}
newSellerWords = newSellerWords.replaceAll(appChineseName, "0.0");
if (newSellerWords.equals(oldSellerWords) && shopRemarkFlag.equals(opOrder.getSellerRemarkStars())) {
return newSellerWords;
}
opOrderExtService.updateOpOrderShopNote(shopId, orderId, newSellerWords);
return newSellerWords;
}
private String buildAndUpdateNewShopNote(Long shopId, String orderId, String remarkTpl, List<PurchaseOrder> purchaseOrders) {
OpOrderExt opOrderExt = opOrderExtService.getByOrderId(orderId);
String oldShopNote = "";
String newShopNote = "";
if (opOrderExt != null) {
oldShopNote = opOrderExt.getShopNote();
}
if (StringUtils.isBlank(remarkTpl)) {
return oldShopNote;
}
String purchaseOrderRemark = buildPurchaseOrderRemark(shopId, remarkTpl, purchaseOrders);
String appChineseName = "";
Pattern p = Pattern.compile("【(" + appChineseName + "|0.0)[^】]*】");
Matcher m = p.matcher(oldShopNote);
StringBuffer newShopNoteBuffer = new StringBuffer(oldShopNote.length());
while (m.find()) {
m.appendReplacement(newShopNoteBuffer, purchaseOrderRemark);
}
m.appendTail(newShopNoteBuffer);
newShopNote = newShopNoteBuffer.toString();
if (newShopNote.equals(oldShopNote)) {
return newShopNote;
}
newShopNote = newShopNote.replaceAll(appChineseName, "0.0");
opOrderExtService.updateOpOrderShopNote(shopId, orderId, newShopNote);
return newShopNote;
}
public String buildPurchaseOrderRemark(Long shopId, String appendRemarkTpl, List<PurchaseOrder> purchaseOrders) {
Shop shop = shopService.getDetailById(shopId);
List<String> purchaseOrderRemarks = new ArrayList<>();
Pattern p = Pattern.compile(PurchaseTool.getRemarkTplRegPattern());
Matcher m = p.matcher(appendRemarkTpl);
List<String> fields = new ArrayList<>();
while (m.find()) {
fields.add(m.group(2));
}
boolean needProfit = false;
boolean needProfitRatio = false;
if (fields.contains(PurchaseOrderConst.TOTAL_PROFIT_FIELD)) {
needProfit = true;
}
if (fields.contains(PurchaseOrderConst.PROFIT_RATIO_FIELD)) {
needProfitRatio = true;
}
PurchaseOrder firstPurchaseOrder = purchaseOrders.iterator().next();
String profitText = "";
String profitRatioText = "";
if (needProfit || needProfitRatio) {
HashMap<String, Double> resuslt = getOrderProfitAndRatioByOrderId(firstPurchaseOrder.getOrderId());
profitText = "(总利润 ¥" + resuslt.get("orderProfitSum") + "";
profitRatioText = "(利润率" + resuslt.get("orderTotalProfitRate") + "%";
}
for (PurchaseOrder purchaseOrder: purchaseOrders) {
if (StringUtils.isBlank(purchaseOrder.getPurchaseOrderSn())) {
continue;
}
Matcher matchRes = p.matcher(appendRemarkTpl);
StringBuffer resString = new StringBuffer();
while (matchRes.find()) {
String result = generatePurchaseOrderRemark(matchRes.toMatchResult(), purchaseOrder, shop, profitText, profitRatioText);
matchRes.appendReplacement(resString, result);
}
matchRes.appendTail(resString);
purchaseOrderRemarks.add(resString.toString());
}
if (purchaseOrderRemarks.isEmpty()) {
return "";
}
String appChineseName = "";
return "【" + appChineseName + "" + String.join(" / ", purchaseOrderRemarks) + "】";
}
private String generatePurchaseOrderRemark(MatchResult result , PurchaseOrder purchaseOrder, Shop shop, String profitText, String profitRatioText) {
String prefix = result.group(1);
String field = result.group(2);
String suffix = result.group(3);
String value = "";
int totalPurchaseNum = 0;
for (PurchaseOrderItem item: purchaseOrder.getItems()) {
totalPurchaseNum += item.getPurchaseNum();
}
switch (field) {
case PurchaseOrderConst.PURCHASE_PLATFORM2_FIELD:
value = PurchaseOrderConst.getPurchasePlatformName(purchaseOrder.getPurchasePlatform());
break;
case PurchaseOrderConst.PURCHASE_ORDER_SN_FIELD:
value = purchaseOrder.getPurchaseOrderSn();
break;
case PurchaseOrderConst.PURCHASE_ORDER_BUYER:
value = purchaseOrder.getPurchaseOrderBuyer();
break;
case PurchaseOrderConst.LOGISTICS_INFO_FIELD:
value = purchaseOrder.getPurchaseOrderLogisticsName() + "#" + purchaseOrder.getPurchaseOrderWaybillCode();
break;
case PurchaseOrderConst.PURCHASE_PAYMENT_FIELD:
value = "¥" + purchaseOrder.getPurchaseOrderPayment();
break;
case PurchaseOrderConst.PURCHASE_ORDER_SELLER_FIELD:
value = purchaseOrder.getPurchaseOrderSeller();
break;
case PurchaseOrderConst.PURCHASE_ORDER_NUM_FIELD:
value = totalPurchaseNum > 0 ? ("采购数量*" + totalPurchaseNum) : "";
break;
case PurchaseOrderConst.SHOP_NAME_FIELD:
value = shop.getShopName();
break;
case PurchaseOrderConst.TOTAL_PROFIT_FIELD:
value = profitText;
break;
case PurchaseOrderConst.PROFIT_RATIO_FIELD:
value = profitRatioText;
break;
default:
value = "";
break;
}
return prefix + value + suffix;
}
private HashMap<String, Double> getOrderProfitAndRatioByOrderId(String orderId) {
OpOrder opOrder = opOrderService.selectByOrderId(orderId);
double orderTotalAmount = CommonTool.correctCentToYuan(opOrder.getOrderTotalAmount());
double freightPrice = CommonTool.correctCentToYuan(opOrder.getPostAmount());
double orderPayment = orderTotalAmount + freightPrice;
OpOrderAmountDetail amountDetail = opOrderAmountDetailService.getByOrderId(orderId);
double postInsuranceAmount = CommonTool.correctCentToYuan(amountDetail.getPostInsuranceAmount());
double platformCostAmount = CommonTool.correctCentToYuan(amountDetail.getPlatformCostAmount());
Map<String, Double> purchasePaymentInfo = purchaseOrderService.getPaymentInfoByOrderId(orderId);
Double purchasePayment = purchasePaymentInfo.get("purchaseOrderPayment");
Double orderCommission = purchasePaymentInfo.get("purchaseOrderCommission");
double orderProfitSum = orderPayment + platformCostAmount + orderCommission - purchasePayment - postInsuranceAmount;
double orderTotalProfitRate = orderPayment > 0 ? orderProfitSum / orderPayment * 100 : 0;
HashMap<String, Double> result = new HashMap<>();
result.put("orderProfitSum", orderProfitSum);
result.put("orderTotalProfitRate", orderTotalProfitRate);
return result;
}
private boolean checkPurchaseOrderStatusCanOutStorage(PurchaseOrderRequestDTO purchaseOrderInfo, OpOrder opOrder) {

@ -1,10 +1,13 @@
package com.ms.api.service.impl;
import java.util.Date;
import java.util.List;
import com.ms.dal.entity.OpOrder;
import com.ms.dal.entity.OpOrderExt;
import com.ms.api.service.OpOrderExtService;
import com.ms.dal.mapper.OpOrderExtMapper;
import com.ms.dal.mapper.OpOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -18,6 +21,9 @@ public class OpOrderExtServiceImpl implements OpOrderExtService{
@Autowired
private OpOrderExtMapper opOrderExtMapper;
@Autowired
private OpOrderMapper opOrderMapper;
@Override
public int deleteByPrimaryKey(Long id) {
return opOrderExtMapper.deleteByPrimaryKey(id);
@ -57,6 +63,30 @@ public class OpOrderExtServiceImpl implements OpOrderExtService{
public List<OpOrderExt> selectByConditions(OpOrderExt ext) {
return opOrderExtMapper.selectByConditions(ext);
}
@Override
public OpOrderExt updateOpOrderShopNote(Long shopId, String orderId, String shopNote) {
OpOrder opOrder = opOrderMapper.selectByOrderId(orderId);
if (opOrder == null || !opOrder.getShopId().equals(shopId)) {
throw new RuntimeException("订单不存在");
}
OpOrderExt opOrderExt = getByOrderId(orderId);
if (opOrderExt == null) {
opOrderExt = new OpOrderExt();
opOrderExt.setOrderId(orderId);
opOrderExt.setShopId(shopId);
opOrderExt.setShopNote(shopNote);
opOrderExt.setGmtCreate(new Date());
}
opOrderExt.setShopNote(shopNote);
opOrderExt.setGmtModified(new Date());
if (opOrderExt.getOpOrderExtId() > 0) {
updateByPrimaryKeySelective(opOrderExt);
} else {
insertSelective(opOrderExt);
}
return opOrderExt;
}
}

@ -559,7 +559,26 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
if (purchaseOrders.isEmpty()) {
return purchaseOrders;
}
// TODO
if (needItems) {
List<String> shopIds = new ArrayList<>();
shopIds.add(String.valueOf(shopId));
List<String> purchaseOrderIds = purchaseOrders.stream().map(x -> x.getPurchaseOrderId().toString()).collect(Collectors.toList());
List<PurchaseOrderItem> allItems = getPurchaseOrderItemsMapByPurchaseOrderIds(shopIds, purchaseOrderIds, status);
Map<Long, List<PurchaseOrderItem>> purchaseOrderIdAndItemMap = new HashMap<>();
for (PurchaseOrderItem item: allItems) {
List<PurchaseOrderItem> subItems = new ArrayList<>();
Long purchaseOrderId = Long.valueOf(item.getPurchaseOrderId());
if (purchaseOrderIdAndItemMap.containsKey(purchaseOrderId)) {
subItems = purchaseOrderIdAndItemMap.get(purchaseOrderId);
}
subItems.add(item);
purchaseOrderIdAndItemMap.put(purchaseOrderId, subItems);
}
for (PurchaseOrder purchaseOrder : purchaseOrders) {
Long purchaseOrderId = purchaseOrder.getPurchaseOrderId();
purchaseOrder.setItems(purchaseOrderIdAndItemMap.get(purchaseOrderId));
}
}
return purchaseOrders;
}
@ -1789,6 +1808,11 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
return orderPrintService.orderMultiPackageOutstorage(shop.getShopId(), orderId, packageList, shop.getAccessToken(), LogisticsConst.outstorageSourcePurchaseManualSend);
}
@Override
public Map<String, Double> getPaymentInfoByOrderId(String orderId) {
return purchaseOrderMapper.getPaymentInfoByOrderId(orderId);
}
@Override
public Integer getDsOrderCount(Integer authShopIds, SearchDsOrderFilterDTO filter) {
List<String> shopIds = Collections.singletonList(ObjectUtil.isNotEmpty(filter.getAuthShopIds()) ? filter.getAuthShopIds() :authShopIds.toString());

@ -27,7 +27,7 @@ public class SearchDsOrderListService implements ExtensionServiceHandler<SearchD
String shopId = req.getAuthId();
SearchDsOrderListRequestDTO dto = req.getData();
if (dto.checkParams()) {
R.fail("参数不合法");
return R.ok(Ret.fail("参数不合法"));
}
PurchaseOrderUtil purchaseOrderUtil = new PurchaseOrderUtil();

@ -49,7 +49,18 @@ public class SearchDsSourceSellerListService extends SPIBaseService implements E
} else {
sourceSellerList = retMap.getJSONArray("sourceSellers");
}
if (sourceSellersObject.size() == 0) {
sourceSellerList = new JSONArray();
JSONObject a = new JSONObject();
a.put("sellerName", "开发人员随便写的店");
a.put("sellerIdMd5", "1234567890qwertyuio");
a.put("isEncryptLogisticsOrderSupportDouyin", 0);
JSONObject b = new JSONObject();
b.put("sellerName", "开发人员的店2");
b.put("sellerIdMd5", "2234567890qwertyuio");
b.put("isEncryptLogisticsOrderSupportDouyin", 0);
sourceSellerList.add(b);
}
JSONObject retObj = new JSONObject();
retObj.put("sourceSellerList", sourceSellerList);
return R.ok(Ret.success(retObj));

@ -38,7 +38,7 @@ public class PurchaseTool {
// }
public static String getRemarkTplRegPattern() {
return "/([^</span>]*)<span.*?data-field=\"([^\"]+)\"[^>]*?>#(?:[^#]+)#</span>([^<span>]*)/is";
return "([^</span>]*)<span.*?data-field=\"([^\"]+)\"[^>]*?>#(?:[^#]+)#</span>([^<span>]*)";
}
/**

@ -1,11 +1,13 @@
package com.ms.dal.mapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.ms.dal.bo.PurchaseOrderBO;
import com.ms.dal.entity.PurchaseOrder;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;
@ -62,6 +64,9 @@ public interface PurchaseOrderMapper {
int updateStatusByIds(String status, List<Long> ids);
@MapKey("id")
Map<String, Double> getPaymentInfoByOrderId(String orderId);
Integer getDsOrderCount(
@Param("countFieldStr") String countFieldStr,
@Param("masterTblAlias") String masterTblAlias,

@ -447,4 +447,10 @@
${whereStr}
</select>
<select id="getPaymentInfoByOrderId" resultType="java.util.Map">
SELECT SUM(purchase_order_payment) as purchaseOrderPayment, sum(purchase_order_commission) as purchaseOrderCommission
from purchase_order
where order_id = #{orderId,jdbcType=VARCHAR}
and status = "normal"
</select>
</mapper>

@ -5,6 +5,7 @@ import com.ms.api.service.DsApiService;
import com.ms.api.service.OpOrderService;
import com.ms.api.service.PurchaseOrderItemService;
import com.ms.api.service.ShopService;
import com.ms.api.tool.PurchaseTool;
import com.ms.common.util.DsClient;
import com.ms.common.util.HttpClient;
import com.ms.dal.entity.PurchaseOrderItem;
@ -22,6 +23,8 @@ import java.util.Base64;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author: laixw
@ -130,7 +133,14 @@ public class Test {
public static void main(String[] args)
{
new Test().go();
String str = "<span contenteditable=\"false\" data-field=\"order_id\">#抖店订单号#</span>d<span contenteditable=\"false\" data-field=\"platform_name\">#抖店平台#</span>";
Pattern p = Pattern.compile(PurchaseTool.getRemarkTplRegPattern());
Matcher m = p.matcher(str);
System.out.println(m.find());
System.out.println(m.group(2));
System.out.println(m.find());
System.out.println(m.group(2));
}
public void go()

Loading…
Cancel
Save