Merge pull request 'v1.0.71' (#83) from dev into master

Reviewed-on: #83
This commit was merged in pull request #83.
This commit is contained in:
2026-11-13 17:11:48 +00:00
13 changed files with 283 additions and 48 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<groupId>com.imyeyu.timiserverapi</groupId>
<artifactId>TimiServerAPI</artifactId>
<version>1.0.70</version>
<version>1.0.71</version>
<packaging>jar</packaging>
<name>TimiServerAPI</name>
<description>imyeyu.com API</description>
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.app.controller;
import com.imyeyu.api.modules.app.service.AppVersionService;
import com.imyeyu.api.modules.app.vo.AppUpdateCheckRequest;
import com.imyeyu.api.modules.app.vo.AppUpdateCheckResponse;
import com.imyeyu.api.modules.app.vo.AppUpdateNotesResponse;
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
import com.imyeyu.spring.annotation.RequestRateLimit;
import lombok.RequiredArgsConstructor;
@@ -39,4 +40,17 @@ public class AppUpdateController {
public AppUpdateCheckResponse check(@RequestBody AppUpdateCheckRequest req) {
return service.check(req);
}
/// 查询更新日志
///
/// 返回当前运行版本到目标版本之间的变更说明,供版本历史页使用
/// 目标版本与 check 用同一套规则解析,包含灰度与兼容区间,保证「有日志」和「能更新」一致
///
/// @param req 插件上报信息,version_name 为当前运行版本
/// @return 更新日志
@RequestRateLimit
@PostMapping("/notes")
public AppUpdateNotesResponse notes(@RequestBody AppUpdateCheckRequest req) {
return service.notes(req);
}
}
@@ -8,6 +8,8 @@ import com.imyeyu.api.modules.app.mapper.AppProductMapper;
import com.imyeyu.api.modules.app.mapper.AppReleaseMapper;
import com.imyeyu.api.modules.app.vo.AppUpdateCheckRequest;
import com.imyeyu.api.modules.app.vo.AppUpdateCheckResponse;
import com.imyeyu.api.modules.app.vo.AppUpdateNote;
import com.imyeyu.api.modules.app.vo.AppUpdateNotesResponse;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.java.TimiJava;
@@ -17,6 +19,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.zip.CRC32;
@@ -38,6 +42,9 @@ public class AppVersionService {
/// 内置包版本标识
public static final String BUILTIN_VERSION = "builtin";
/// 更新日志最多返回的版本条数
public static final int MAX_NOTES = 20;
/// 灰度基数
private static final long GRAY_BASE = 10000L;
@@ -51,54 +58,128 @@ public class AppVersionService {
/// @param req 插件上报信息
/// @return 插件协议响应,无更新时回显当前版本
public AppUpdateCheckResponse check(AppUpdateCheckRequest req) {
String currentVersion = TimiJava.isEmpty(req.getVersionName()) ? BUILTIN_VERSION : req.getVersionName();
AppProduct product = productMapper.selectByAppKey(req.getAppId(), parsePlatform(req.getPlatform()));
if (product == null || !Boolean.TRUE.equals(product.getEnabled())) {
log.warn("应用不存在或已停用,appId={}", req.getAppId());
String currentVersion = currentVersion(req);
AppProduct product = resolveProduct(req);
if (product == null) {
return AppUpdateCheckResponse.none(currentVersion);
}
if (!TimiJava.isEmpty(product.getUpdateKey()) && !product.getUpdateKey().equals(req.getKey())) {
log.warn("更新密钥不匹配,appId={}", req.getAppId());
return AppUpdateCheckResponse.none(currentVersion);
}
String channelCode = TimiJava.isEmpty(req.getChannel()) ? DEFAULT_CHANNEL : req.getChannel();
AppChannel channel = channelMapper.selectByProductAndCode(product.getId(), channelCode);
if (channel == null || TimiJava.isEmpty(channel.getReleaseId())) {
return AppUpdateCheckResponse.none(currentVersion);
}
AppRelease release = releaseMapper.select(channel.getReleaseId());
if (release == null || release.getStatus() != AppRelease.Status.PUBLISHED) {
AppRelease release = resolveChannelRelease(product, req);
if (release == null) {
return AppUpdateCheckResponse.none(currentVersion);
}
int currentCode = parseInt(req.getVersionCode(), 0);
if (release.getKind() == AppRelease.Kind.NATIVE) {
return resolveNative(release, currentCode, currentVersion);
AppRelease target = resolveNative(release, currentCode);
return target == null
? AppUpdateCheckResponse.none(currentVersion)
: buildResponse(target, Boolean.TRUE.equals(target.getMandatory()));
}
return resolveBundle(release, product, currentCode, currentVersion, req.getDeviceId());
AppRelease target = resolveBundle(release, product, currentCode, currentVersion, req.getDeviceId());
return target == null
? AppUpdateCheckResponse.none(currentVersion)
: buildResponse(target, false);
}
/// 原生包更新判断
/// 查询更新日志
///
/// @param release 发布记录
/// 区间上界取通道当前版本,不再走灰度与兼容区间判断。
/// 原因:客户端拿不到原生 versionCode,也无法保证命中灰度分桶,套用检查更新的判定会让日志
/// 大面积为空。日志是「这个产品最近发了什么」,不是「你这台设备能装什么」,分发决策仍由 check 负责
///
/// @param req 插件上报信息
/// @return 当前版本到通道当前版本之间的变更说明
public AppUpdateNotesResponse notes(AppUpdateCheckRequest req) {
String currentVersion = currentVersion(req);
AppProduct product = resolveProduct(req);
if (product == null) {
return new AppUpdateNotesResponse(null, Collections.emptyList());
}
AppRelease target = resolveChannelRelease(product, req);
// 原生包更新走安装包,与热更日志无关
if (target == null || target.getKind() == AppRelease.Kind.NATIVE) {
return new AppUpdateNotesResponse(null, Collections.emptyList());
}
List<AppUpdateNote> notes = new ArrayList<>();
for (AppRelease item : releaseMapper.selectPublished(product.getId(), AppRelease.Kind.BUNDLE)) {
// 只取比当前版本新、且不比目标版本新的记录
if (0 >= compareVersion(item.getVersionName(), currentVersion)) {
continue;
}
if (0 < compareVersion(item.getVersionName(), target.getVersionName())) {
continue;
}
notes.add(new AppUpdateNote(item.getVersionName(), item.getNote(), item.getPublishedAt()));
}
// 按版本号倒序,最新的在最前
notes.sort((a, b) -> compareVersion(b.getVersion(), a.getVersion()));
List<AppUpdateNote> limited = MAX_NOTES < notes.size() ? notes.subList(0, MAX_NOTES) : notes;
return new AppUpdateNotesResponse(target.getVersionName(), limited);
}
/// 取当前运行的 Web 包版本
///
/// @param req 插件上报信息
/// @return 版本号,未上报时为内置包标识
private String currentVersion(AppUpdateCheckRequest req) {
return TimiJava.isEmpty(req.getVersionName()) ? BUILTIN_VERSION : req.getVersionName();
}
/// 解析并校验产品
///
/// @param req 插件上报信息
/// @return 产品,不存在、已停用或密钥不匹配时为 null
private AppProduct resolveProduct(AppUpdateCheckRequest req) {
AppProduct product = productMapper.selectByAppKey(req.getAppId(), parsePlatform(req.getPlatform()));
if (product == null || !Boolean.TRUE.equals(product.getEnabled())) {
log.warn("应用不存在或已停用,appId={}", req.getAppId());
return null;
}
if (!TimiJava.isEmpty(product.getUpdateKey()) && !product.getUpdateKey().equals(req.getKey())) {
log.warn("更新密钥不匹配,appId={}", req.getAppId());
return null;
}
return product;
}
/// 取通道当前指向的发布记录
///
/// @param product 产品
/// @param req 插件上报信息
/// @return 发布记录,通道为空或指向的记录不可用时为 null
private AppRelease resolveChannelRelease(AppProduct product, AppUpdateCheckRequest req) {
String channelCode = TimiJava.isEmpty(req.getChannel()) ? DEFAULT_CHANNEL : req.getChannel();
AppChannel channel = channelMapper.selectByProductAndCode(product.getId(), channelCode);
if (channel == null || TimiJava.isEmpty(channel.getReleaseId())) {
return null;
}
AppRelease release = releaseMapper.select(channel.getReleaseId());
if (release == null || release.getStatus() != AppRelease.Status.PUBLISHED) {
return null;
}
return release;
}
/// 原生包是否需要更新
///
/// @param release 通道当前发布记录
/// @param currentCode 当前原生 versionCode
/// @param currentVersion 当前版本名
/// @return 更新响应
private AppUpdateCheckResponse resolveNative(AppRelease release, int currentCode, String currentVersion) {
/// @return 需要更新时返回发布记录,否则返回 null
private AppRelease resolveNative(AppRelease release, int currentCode) {
if (release.getVersionCode() == null || release.getVersionCode() <= currentCode) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
return buildResponse(release, Boolean.TRUE.equals(release.getMandatory()));
return release;
}
/// 热更包更新判断
/// 热更包是否需要更新
///
/// @param release 发布记录
/// @param release 通道当前发布记录
/// @param product 产品
/// @param currentCode 当前原生 versionCode
/// @param currentVersion 当前 Web 包版本
/// @param deviceId 设备标识
/// @return 更新响应
private AppUpdateCheckResponse resolveBundle(
/// @return 需要更新时返回发布记录,否则返回 null
private AppRelease resolveBundle(
AppRelease release,
AppProduct product,
int currentCode,
@@ -107,23 +188,23 @@ public class AppVersionService {
) {
// 原生版本不在兼容区间内,装了会崩
if (release.getMinVersionCode() != null && currentCode < release.getMinVersionCode()) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
if (release.getMaxVersionCode() != null && release.getMaxVersionCode() < currentCode) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
// 已是最新,或低于当前版本时不做降级
if (release.getVersionName().equals(currentVersion)) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
if (0 < compareVersion(currentVersion, release.getVersionName())) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
// 灰度分桶不能含 releaseId,否则每次发版都会重排用户
if (!hitGray(release.getGrayPermille(), deviceId, product.getAppKey())) {
return AppUpdateCheckResponse.none(currentVersion);
return null;
}
return buildResponse(release, false);
return release;
}
/// 判断设备是否命中灰度
@@ -146,6 +227,8 @@ public class AppVersionService {
/// 构造更新响应
///
/// note 为历史构建号时不下发,避免客户端把它当成更新说明展示
///
/// @param release 发布记录
/// @param mandatory true 为强制更新
/// @return 更新响应
@@ -154,7 +237,7 @@ public class AppVersionService {
.path("/attach/download/")
.path(release.getAttachmentId())
.toUriString();
return new AppUpdateCheckResponse(release.getVersionName(), url, release.getSha256(), mandatory);
return new AppUpdateCheckResponse(release.getVersionName(), url, release.getSha256(), mandatory, release.getNote());
}
/// 比较版本号
@@ -28,11 +28,16 @@ public class AppUpdateCheckResponse {
/// 是否为强制更新
protected Boolean mandatory;
/// 变更说明,供 App 展示更新日志
///
/// 字段名不能叫 message:Capgo 插件把 message 当作错误信息,收到会直接判为检查失败
protected String note;
/// 构建无更新响应,version 与当前一致时插件不会下载
///
/// @param currentVersion 当前运行的 Web 包版本
/// @return 无更新响应
public static AppUpdateCheckResponse none(String currentVersion) {
return new AppUpdateCheckResponse(currentVersion, "", null, false);
return new AppUpdateCheckResponse(currentVersion, "", null, false, null);
}
}
@@ -0,0 +1,23 @@
package com.imyeyu.api.modules.app.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
///
/// 单条版本变更说明
///
/// @author Codex
/// @since 2026-11-13
@Data
@AllArgsConstructor
public class AppUpdateNote {
/// 版本号
protected String version;
/// 变更说明,来自发布记录的 note
protected String note;
/// 首次发布时间
protected Long publishedAt;
}
@@ -0,0 +1,24 @@
package com.imyeyu.api.modules.app.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
///
/// 应用更新日志响应
///
/// 供 App 的版本历史页使用,返回当前运行版本到目标版本之间的全部变更说明
///
/// @author Codex
/// @since 2026-11-13
@Data
@AllArgsConstructor
public class AppUpdateNotesResponse {
/// 目标版本号,为空表示当前没有可更新到的版本
protected String version;
/// 变更说明,按版本号从新到旧
protected List<AppUpdateNote> notes;
}
@@ -76,6 +76,43 @@ public class GaoRecycleAccountController {
return mapper.listAccounts(storeId, customerId);
}
/// 按客户分页返回额度,汇总按回收物分别计算,避免混加不同单位。
@RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_READ)
@PostMapping("/customers")
public Map<String, Object> customers(@RequestParam String storeId, @RequestParam(required = false) String recycleItemId,
@RequestParam(required = false) String keyword, @RequestParam(required = false) List<String> customerIds, @RequestParam(defaultValue = "0") int offset, @RequestParam(defaultValue = "20") int limit) {
scope.checkStoreId(storeId);
int safeOffset = Math.max(0, offset);
int safeLimit = Math.max(1, Math.min(limit, 100));
List<String> ids = mapper.customerPage(storeId, recycleItemId, keyword, customerIds, safeOffset, safeLimit);
List<Map<String, Object>> rows = new java.util.ArrayList<>();
if (!ids.isEmpty()) {
Map<String, GaoCustomer> customers = customerService.mapByIdList(ids);
Map<String, List<Attachment>> photos = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, ids, GaoCustomer.AttachType.PHOTO.name());
List<Map<String, Object>> accounts = mapper.customerAccounts(storeId, ids, recycleItemId);
for (String id : ids) {
GaoCustomer customer = customers.get(id);
if (customer == null) continue;
customer.setAttachmentList(photos.getOrDefault(id, List.of()));
rows.add(Map.of("customer", customer, "accounts", accounts.stream().filter(account -> id.equals(account.get("customerId"))).toList()));
}
}
return Map.of("list", rows, "total", mapper.customerCount(storeId, recycleItemId, keyword, customerIds), "totals", mapper.accountTotals(storeId, keyword, customerIds));
}
@RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_READ)
@PostMapping("/items")
public List<Map<String, Object>> accountItems(@RequestParam String storeId) {
scope.checkStoreId(storeId);
List<Map<String, Object>> items = mapper.accountItems(storeId);
List<String> ids = items.stream().map(item -> (String) item.get("id")).filter(java.util.Objects::nonNull).toList();
if (!ids.isEmpty()) {
Map<String, List<Attachment>> attachments = attachmentService.mapByBizIdList(Attachment.BizType.GAO_RECYCLE_ITEM, ids);
items.forEach(item -> item.put("attachmentList", attachments.getOrDefault(item.get("id"), List.of())));
}
return items;
}
@RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_READ)
@PostMapping("/ledger")
public List<Map<String, Object>> ledger(@RequestParam String storeId, @RequestParam String customerId) {
@@ -27,6 +27,23 @@ public interface GaoRecycleAccountMapper {
"WHERE a.store_id=#{store} AND a.customer_id=#{customer} AND a.deleted_at IS NULL ORDER BY a.recycle_item_id")
List<Map<String, Object>> listAccounts(@Param("store") String store, @Param("customer") String customer);
/// 按客户分页,筛选条件与汇总使用相同的有效账户范围。
@Select("<script>SELECT a.customer_id FROM gao_recycle_account a JOIN gao_customer c ON c.id=a.customer_id AND c.store_id=a.store_id AND c.deleted_at IS NULL WHERE a.store_id=#{store} AND a.deleted_at IS NULL AND a.balance > 0 <if test='customers != null and !customers.isEmpty()'> AND a.customer_id IN <foreach collection='customers' item='customer' open='(' separator=',' close=')'>#{customer}</foreach> </if> <if test='keyword != null and keyword != &quot;&quot;'> AND (c.name LIKE CONCAT('%',#{keyword},'%') OR c.code LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_full LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_initial LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_mixed LIKE CONCAT('%',#{keyword},'%')) </if> <if test='item != null and item != &quot;&quot;'> AND a.recycle_item_id=#{item} </if> GROUP BY a.customer_id ORDER BY a.customer_id LIMIT #{limit} OFFSET #{offset}</script>")
List<String> customerPage(@Param("store") String store, @Param("item") String item, @Param("keyword") String keyword, @Param("customers") List<String> customers, @Param("offset") int offset, @Param("limit") int limit);
@Select("<script>SELECT COUNT(DISTINCT a.customer_id) FROM gao_recycle_account a JOIN gao_customer c ON c.id=a.customer_id AND c.store_id=a.store_id AND c.deleted_at IS NULL WHERE a.store_id=#{store} AND a.deleted_at IS NULL AND a.balance > 0 <if test='customers != null and !customers.isEmpty()'> AND a.customer_id IN <foreach collection='customers' item='customer' open='(' separator=',' close=')'>#{customer}</foreach> </if> <if test='keyword != null and keyword != &quot;&quot;'> AND (c.name LIKE CONCAT('%',#{keyword},'%') OR c.code LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_full LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_initial LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_mixed LIKE CONCAT('%',#{keyword},'%')) </if> <if test='item != null and item != &quot;&quot;'> AND a.recycle_item_id=#{item} </if></script>")
long customerCount(@Param("store") String store, @Param("item") String item, @Param("keyword") String keyword, @Param("customers") List<String> customers);
@Select("<script>SELECT a.customer_id AS customerId, a.recycle_item_id AS recycleItemId, a.balance, a.reserved, i.name AS recycleName, i.unit_name AS recycleUnit FROM gao_recycle_account a LEFT JOIN gao_recycle_item i ON i.id=a.recycle_item_id AND i.store_id=a.store_id WHERE a.store_id=#{store} AND a.deleted_at IS NULL AND a.balance > 0 AND a.customer_id IN <foreach collection='customers' item='customer' open='(' separator=',' close=')'>#{customer}</foreach> <if test='item != null and item != &quot;&quot;'> AND a.recycle_item_id=#{item} </if> ORDER BY a.recycle_item_id</script>")
List<Map<String, Object>> customerAccounts(@Param("store") String store, @Param("customers") List<String> customers, @Param("item") String item);
@Select("<script>SELECT a.recycle_item_id AS recycleItemId, i.name AS recycleName, i.unit_name AS recycleUnit, SUM(a.balance) AS balance, SUM(a.reserved) AS reserved FROM gao_recycle_account a JOIN gao_customer c ON c.id=a.customer_id AND c.store_id=a.store_id AND c.deleted_at IS NULL LEFT JOIN gao_recycle_item i ON i.id=a.recycle_item_id AND i.store_id=a.store_id WHERE a.store_id=#{store} AND a.deleted_at IS NULL AND a.balance > 0 <if test='customers != null and !customers.isEmpty()'> AND a.customer_id IN <foreach collection='customers' item='customer' open='(' separator=',' close=')'>#{customer}</foreach> </if> <if test='keyword != null and keyword != &quot;&quot;'> AND (c.name LIKE CONCAT('%',#{keyword},'%') OR c.code LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_full LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_initial LIKE CONCAT('%',#{keyword},'%') OR c.name_pinyin_mixed LIKE CONCAT('%',#{keyword},'%')) </if> GROUP BY a.recycle_item_id, i.name, i.unit_name ORDER BY i.name, a.recycle_item_id</script>")
List<Map<String, Object>> accountTotals(@Param("store") String store, @Param("keyword") String keyword, @Param("customers") List<String> customers);
/// 额度查询权限可用的回收物选项。
@Select("SELECT id, name, unit_name AS unitName, status FROM gao_recycle_item WHERE store_id=#{store} ORDER BY name, id")
List<Map<String, Object>> accountItems(@Param("store") String store);
@Select("SELECT id, account_id AS accountId, store_id AS storeId, customer_id AS customerId, recycle_item_id AS recycleItemId, " +
"biz_type AS bizType, biz_id AS bizId, request_no AS requestNo, balance_delta AS balanceDelta, reserved_delta AS reservedDelta, " +
"balance_after AS balanceAfter, reserved_after AS reservedAfter, operator_user_id AS operatorUserId, reason, created_at AS createdAt " +
@@ -37,7 +37,7 @@ public interface GaoSalesOrderMapper extends BaseMapper<GaoSalesOrder, String> {
/// 查询客户仍可履约的 SKU 订单行
List<GaoQuickFulfillmentSourceRow> selectQuickFulfillmentSourceRows(@Param("storeId") String storeId,
@Param("customerId") String customerId, @Param("skuIdList") List<String> skuIdList,
@Param("salesOrderIdList") List<String> salesOrderIdList, @Param("allowUnpaid") boolean allowUnpaid);
@Param("salesOrderIdList") List<String> salesOrderIdList, @Param("allowUnpaid") boolean allowUnpaid, @Param("allowUnsettledRecycle") boolean allowUnsettledRecycle);
/// 按条件汇总订单金额
GaoSalesOrderReceivableStatView selectSummaryByQuery(GaoSalesOrderPage page);
@@ -193,7 +193,7 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
TimiException.required(request, "快速履约客户查询请求不能为空");
GaoCustomer customer = getQuickFulfillmentCustomer(request.getCustomerId(), false);
List<GaoQuickFulfillmentSourceRow> sourceRows = salesOrderMapper.selectQuickFulfillmentSourceRows(
customer.getStoreId(), customer.getId(), null, null, canQuickFulfillUnpaidOrder());
customer.getStoreId(), customer.getId(), null, null, canQuickFulfillUnpaidOrder(), canQuickFulfillUnsettledRecycle());
if (sourceRows == null || sourceRows.isEmpty()) {
return List.of();
}
@@ -235,7 +235,7 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
List<String> skuIdList = normalizedIdList(request.getSkuIdList(), "skuIdList");
TimiException.requiredTrue(!skuIdList.isEmpty(), "至少选择一个 SKU");
List<GaoQuickFulfillmentSourceRow> sourceRows = salesOrderMapper.selectQuickFulfillmentSourceRows(
customer.getStoreId(), customer.getId(), skuIdList, null, canQuickFulfillUnpaidOrder());
customer.getStoreId(), customer.getId(), skuIdList, null, canQuickFulfillUnpaidOrder(), canQuickFulfillUnsettledRecycle());
Map<String, GaoQuickFulfillmentSourceOrderView> orderMap = new LinkedHashMap<>();
for (GaoQuickFulfillmentSourceRow row : sourceRows) {
GaoQuickFulfillmentSourceOrderView order = orderMap.computeIfAbsent(row.getSalesOrderId(), key -> {
@@ -244,6 +244,10 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
view.setOrderNo(row.getOrderNo());
view.setOrderType(row.getOrderType());
view.setPaymentStatus(row.getPaymentStatus());
view.setRecycleRequiredQuantity(row.getRecycleRequiredQuantity());
view.setRecycleVerifiedQuantity(row.getRecycleVerifiedQuantity());
view.setRecycleItemName(row.getRecycleItemName());
view.setRecycleUnit(row.getRecycleUnit());
view.setPackageName(row.getPackageName());
view.setSaleAmount(row.getSaleAmount());
view.setPaidAmount(row.getPaidAmount());
@@ -307,7 +311,6 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
Map<String, GaoSalesOrder> orderMap = new LinkedHashMap<>();
for (String orderId : lockOrderIdList) {
GaoSalesOrder order = salesOrderService.getForUpdate(orderId);
TimiException.requiredTrue(order.getOrderType() != GaoSalesOrder.OrderType.RECYCLE, "回收兑换订单请使用普通履约入口");
TimiException.requiredTrue(customerId.equals(order.getCustomerId()), "来源订单不属于当前客户");
TimiException.requiredTrue(customer.getStoreId().equals(order.getStoreId()), "来源订单不属于当前门店");
TimiException.requiredTrue(order.getStatus() != GaoSalesOrder.Status.CANCELLED, "已取消订单不能履约");
@@ -336,7 +339,7 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
List<String> skuIdList = requestItemList.stream().map(GaoQuickFulfillmentCreateItemRequest::getSkuId).toList();
List<GaoQuickFulfillmentSourceRow> sourceRows = salesOrderMapper.selectQuickFulfillmentSourceRows(
customer.getStoreId(), customerId, skuIdList, lockOrderIdList, canQuickFulfillUnpaidOrder());
customer.getStoreId(), customerId, skuIdList, lockOrderIdList, canQuickFulfillUnpaidOrder(), canQuickFulfillUnsettledRecycle());
TimiException.requiredTrue(sourceRows != null && !sourceRows.isEmpty(), "所选订单没有可履约 SKU");
Map<String, GaoQuickFulfillmentSourceRow> sourceRowMap = new HashMap<>();
for (GaoQuickFulfillmentSourceRow sourceRow : sourceRows) {
@@ -1081,9 +1084,12 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
return customer;
}
/// 判断当前用户是否拥有未全额收款订单履约例外
///
/// @return true 为允许查询未全额收款订单
/// 判断是否允许未结清回收订单履约
private boolean canQuickFulfillUnsettledRecycle() {
return permissionChecker.hasAny(ModuleCode.GAO, com.imyeyu.api.modules.gao.bean.GaoPermissionCode.ORDER_FULFILLMENT_UNSETTLED.getValue());
}
/// 判断是否允许未全额收款订单履约
private boolean canQuickFulfillUnpaidOrder() {
return roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.STORE_MANAGER.name());
}
@@ -4,6 +4,7 @@ import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
import lombok.Data;
import java.util.List;
import java.math.BigDecimal;
/// 快速履约来源订单
@Data
@@ -18,6 +19,15 @@ public class GaoQuickFulfillmentSourceOrderView {
/// 订单类型
private GaoSalesOrder.OrderType orderType;
/// 回收物名称
private String recycleItemName;
/// 回收物单位
private String recycleUnit;
/// 应回收数量
private BigDecimal recycleRequiredQuantity;
/// 已核销回收数量
private BigDecimal recycleVerifiedQuantity;
/// 收款状态
private GaoSalesOrder.PaymentStatus paymentStatus;
@@ -15,6 +15,15 @@ public class GaoQuickFulfillmentSourceRow {
private String orderNo;
/// 来源订单类型
private GaoSalesOrder.OrderType orderType;
/// 回收物名称
private String recycleItemName;
/// 回收物单位
private String recycleUnit;
/// 应回收数量
private BigDecimal recycleRequiredQuantity;
/// 已核销回收数量
private BigDecimal recycleVerifiedQuantity;
/// 收款状态
private GaoSalesOrder.PaymentStatus paymentStatus;
/// 套餐名称快照
@@ -105,6 +105,10 @@
<select id="selectQuickFulfillmentSourceRows" resultType="com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSourceRow">
SELECT o.`id` AS `salesOrderId`, o.`order_no` AS `orderNo`, o.`order_type` AS `orderType`,
o.`payment_status` AS `paymentStatus`,
o.`recycle_required_quantity` AS `recycleRequiredQuantity`,
(SELECT COALESCE(SUM(rp.`quantity`), 0) FROM `gao_recycle_payment` rp WHERE rp.`order_id` = o.`id` AND rp.`status` = 'VERIFIED' AND rp.`source_payment_id` IS NULL) AS `recycleVerifiedQuantity`,
(SELECT e.`recycle_name_snapshot` FROM `gao_recycle_exchange` e WHERE e.`sales_order_id` = o.`id` LIMIT 1) AS `recycleItemName`,
(SELECT e.`recycle_unit_snapshot` FROM `gao_recycle_exchange` e WHERE e.`sales_order_id` = o.`id` LIMIT 1) AS `recycleUnit`,
o.`created_at` AS `orderCreatedAt`,
(SELECT cp.`package_name_snapshot` FROM `gao_customer_package` cp
WHERE cp.`sales_order_id` = o.`id` AND cp.`deleted_at` IS NULL LIMIT 1) AS `packageName`,
@@ -121,9 +125,12 @@
INNER JOIN `gao_product` p ON p.`id` = s.`product_id` AND p.`deleted_at` IS NULL
WHERE i.`deleted_at` IS NULL AND o.`store_id` = #{storeId} AND o.`customer_id` = #{customerId}
AND o.`status` &lt;&gt; 'CANCELLED'
AND (#{allowUnpaid} OR o.`sale_amount` = 0 OR o.`paid_amount` = o.`sale_amount`)
AND ((o.`order_type` = 'PACKAGE' AND i.`item_type` = 'PACKAGE_ENTITLEMENT')
OR (o.`order_type` = 'DIRECT_PRODUCT' AND i.`item_type` = 'DIRECT_PRODUCT'))
AND ((o.`order_type` = 'RECYCLE' AND i.`item_type` = 'RECYCLE_ENTITLEMENT'
AND (#{allowUnsettledRecycle} OR (o.`recycle_required_quantity` IS NOT NULL AND
(SELECT COALESCE(SUM(rp.`quantity`), 0) FROM `gao_recycle_payment` rp WHERE rp.`order_id` = o.`id` AND rp.`status` = 'VERIFIED' AND rp.`source_payment_id` IS NULL) &gt;= o.`recycle_required_quantity`)))
OR ((#{allowUnpaid} OR o.`sale_amount` = 0 OR o.`paid_amount` = o.`sale_amount`)
AND ((o.`order_type` = 'PACKAGE' AND i.`item_type` = 'PACKAGE_ENTITLEMENT')
OR (o.`order_type` = 'DIRECT_PRODUCT' AND i.`item_type` = 'DIRECT_PRODUCT'))))
AND COALESCE(i.`base_quantity`, 0) - COALESCE(i.`reserved_base_quantity`, 0) - COALESCE(i.`fulfilled_base_quantity`, 0) &gt; 0
<if test="skuIdList != null and skuIdList.size() &gt; 0">
AND i.`sku_id` IN