v1.0.71 #83
@@ -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 != ""'> 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 != ""'> 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 != ""'> 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 != ""'> 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 != ""'> 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 != ""'> 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 " +
|
||||
|
||||
Reference in New Issue
Block a user