From c32ecd1f8ca85eac2ee6b2a7463d59a8e7cfb57b Mon Sep 17 00:00:00 2001 From: Timi Date: Sat, 22 Aug 2026 16:42:09 +0800 Subject: [PATCH] add point account list api --- .../controller/GaoPointAccountController.java | 24 ++++++++- .../modules/gao/entity/GaoPointAccount.java | 5 ++ .../gao/mapper/GaoPointAccountMapper.java | 22 ++++++++ .../gao/service/GaoPointAccountService.java | 15 ++++++ .../GaoPointAccountServiceImplement.java | 54 +++++++++++++++++++ .../modules/gao/vo/GaoPointAccountPage.java | 20 +++++++ .../timi-server/gao/GaoPointAccountMapper.xml | 47 ++++++++++++++++ 7 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/imyeyu/api/modules/gao/vo/GaoPointAccountPage.java diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoPointAccountController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoPointAccountController.java index 537e0a1..ef977ac 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoPointAccountController.java +++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoPointAccountController.java @@ -7,11 +7,15 @@ import com.imyeyu.api.modules.gao.bean.GaoRoleCode; import com.imyeyu.api.modules.gao.entity.GaoPointAccount; import com.imyeyu.api.modules.gao.service.GaoPointAccountService; import com.imyeyu.api.modules.gao.service.GaoStoreService; +import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage; import com.imyeyu.api.modules.user.service.RoleChecker; +import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.spring.annotation.AOPLog; import com.imyeyu.spring.annotation.RequestRateLimit; +import com.imyeyu.spring.bean.PageResult; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -32,12 +36,30 @@ public class GaoPointAccountController { @AOPLog @RequestRateLimit @RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ) - @PostMapping("/account/detail") + @PostMapping("/account/list") + public PageResult list(@RequestBody GaoPointAccountPage page) { + TimiException.required(page, "not found page"); + page.setStoreId(resolveStoreId(page.getStoreId())); + return accountService.pageByQuery(page); + } + + @AOPLog + @RequestRateLimit + @RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ) + @PostMapping("/account/detail/customer") public GaoPointAccount detail(@RequestParam String customerId, @RequestParam(required = false) String storeId) { storeId = resolveStoreId(storeId); return accountService.getByCustomerId(storeId, customerId); } + @AOPLog + @RequestRateLimit + @RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ) + @PostMapping("/account/detail") + public GaoPointAccount detailById(@RequestParam String id, @RequestParam(required = false) String storeId) { + return accountService.getByIdAndStoreId(resolveStoreId(storeId), id); + } + private String resolveStoreId(String requestedStoreId) { if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) { return requestedStoreId; diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointAccount.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointAccount.java index cebdf59..f3c8320 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointAccount.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointAccount.java @@ -1,5 +1,6 @@ package com.imyeyu.api.modules.gao.entity; +import com.imyeyu.spring.annotation.table.Transient; import com.imyeyu.spring.entity.UUIDEntity; import lombok.Data; import lombok.EqualsAndHashCode; @@ -35,4 +36,8 @@ public class GaoPointAccount extends UUIDEntity { /// 乐观锁版本 private Long version; + + /// 客户信息 + @Transient + private GaoCustomer customer; } diff --git a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointAccountMapper.java b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointAccountMapper.java index 2176061..e5d1edd 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointAccountMapper.java +++ b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointAccountMapper.java @@ -1,9 +1,12 @@ package com.imyeyu.api.modules.gao.mapper; import com.imyeyu.api.modules.gao.entity.GaoPointAccount; +import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage; import com.imyeyu.spring.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /// GAO 客户积分账户 Mapper /// /// @author Codex @@ -17,6 +20,25 @@ public interface GaoPointAccountMapper extends BaseMapper selectByQuery(GaoPointAccountPage page); + /// 创建客户积分账户,已存在时保持原账户不变 /// /// @param account 积分账户 diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointAccountService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointAccountService.java index 22fe950..2f9e0fe 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointAccountService.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointAccountService.java @@ -1,6 +1,8 @@ package com.imyeyu.api.modules.gao.service; import com.imyeyu.api.modules.gao.entity.GaoPointAccount; +import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage; +import com.imyeyu.spring.bean.PageResult; import com.imyeyu.spring.service.BaseService; /// GAO 客户积分账户服务 @@ -9,6 +11,12 @@ import com.imyeyu.spring.service.BaseService; /// @since 2026-08-11 public interface GaoPointAccountService extends BaseService { + /// 分页查询积分账户 + /// + /// @param page 查询条件 + /// @return 账户分页 + PageResult pageByQuery(GaoPointAccountPage page); + /// 查询客户当前有效积分账户 /// /// @param storeId 门店 ID @@ -16,6 +24,13 @@ public interface GaoPointAccountService extends BaseService implements GaoPointAccountService { private final GaoPointAccountMapper mapper; + private final GaoCustomerMapper customerMapper; + private final AttachmentService attachmentService; @Override protected BaseMapper mapper() { return mapper; } + @Override + public PageResult pageByQuery(GaoPointAccountPage page) { + TimiException.required(page, "not found page"); + PageResult result = new PageResult<>(); + result.setTotal(mapper.countByQuery(page)); + result.setList(mapper.selectByQuery(page)); + fillCustomer(result.getList()); + return result; + } + @Override public GaoPointAccount getByCustomerId(String storeId, String customerId) { TimiException.required(storeId, "not found storeId"); @@ -36,6 +57,39 @@ public class GaoPointAccountServiceImplement extends AbstractEntityService accountList) { + List customerIdList = accountList.stream() + .map(GaoPointAccount::getCustomerId) + .filter(id -> id != null && !id.isBlank()) + .distinct() + .toList(); + if (customerIdList.isEmpty()) { + return; + } + + Map customerMap = customerMapper.selectByIdList(customerIdList).stream() + .collect(Collectors.toMap(GaoCustomer::getId, item -> item)); + Map> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList); + for (GaoPointAccount account : accountList) { + GaoCustomer customer = customerMap.get(account.getCustomerId()); + if (customer == null) { + continue; + } + customer.setAttachmentList(attachmentMap.get(customer.getId())); + account.setCustomer(customer); + } + } + @Transactional(TimiServerDBConfig.ROLLBACKER) @Override public GaoPointAccount getOrCreateForUpdate(String storeId, String customerId) { diff --git a/src/main/java/com/imyeyu/api/modules/gao/vo/GaoPointAccountPage.java b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoPointAccountPage.java new file mode 100644 index 0000000..33ef462 --- /dev/null +++ b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoPointAccountPage.java @@ -0,0 +1,20 @@ +package com.imyeyu.api.modules.gao.vo; + +import com.imyeyu.java.bean.BasePage; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/// GAO 客户积分账户分页查询请求 +/// +/// @author Codex +/// @since 2026-08-22 +@Data +@EqualsAndHashCode(callSuper = true) +public class GaoPointAccountPage extends BasePage { + + /// 门店 ID + private String storeId; + + /// 客户编码、姓名、电话或拼音关键词 + private String keyword; +} diff --git a/src/main/resources/mapper/timi-server/gao/GaoPointAccountMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoPointAccountMapper.xml index f288f85..5451847 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoPointAccountMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoPointAccountMapper.xml @@ -10,6 +10,53 @@ LIMIT 1 + + + + `a`.`deleted_at` IS NULL + AND `c`.`deleted_at` IS NULL + + AND `a`.`store_id` = #{storeId} + + + AND ( + `c`.`code` LIKE CONCAT('%', #{keyword}, '%') + OR `c`.`name` LIKE CONCAT('%', #{keyword}, '%') + OR `c`.`telephone` 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}, '%') + ) + + + + + + + INSERT INTO `gao_point_account` ( `id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_consumed`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`