add point account list api
This commit is contained in:
@@ -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.entity.GaoPointAccount;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
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.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -32,12 +36,30 @@ public class GaoPointAccountController {
|
|||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
||||||
@PostMapping("/account/detail")
|
@PostMapping("/account/list")
|
||||||
|
public PageResult<GaoPointAccount> 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) {
|
public GaoPointAccount detail(@RequestParam String customerId, @RequestParam(required = false) String storeId) {
|
||||||
storeId = resolveStoreId(storeId);
|
storeId = resolveStoreId(storeId);
|
||||||
return accountService.getByCustomerId(storeId, customerId);
|
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) {
|
private String resolveStoreId(String requestedStoreId) {
|
||||||
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
return requestedStoreId;
|
return requestedStoreId;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -35,4 +36,8 @@ public class GaoPointAccount extends UUIDEntity {
|
|||||||
|
|
||||||
/// 乐观锁版本
|
/// 乐观锁版本
|
||||||
private Long version;
|
private Long version;
|
||||||
|
|
||||||
|
/// 客户信息
|
||||||
|
@Transient
|
||||||
|
private GaoCustomer customer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/// GAO 客户积分账户 Mapper
|
/// GAO 客户积分账户 Mapper
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author Codex
|
||||||
@@ -17,6 +20,25 @@ public interface GaoPointAccountMapper extends BaseMapper<GaoPointAccount, Strin
|
|||||||
/// @return 积分账户
|
/// @return 积分账户
|
||||||
GaoPointAccount selectByStoreIdAndCustomerId(@Param("storeId") String storeId, @Param("customerId") String customerId);
|
GaoPointAccount selectByStoreIdAndCustomerId(@Param("storeId") String storeId, @Param("customerId") String customerId);
|
||||||
|
|
||||||
|
/// 按账户 ID 和门店查询积分账户
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID,可为空
|
||||||
|
/// @param id 账户 ID
|
||||||
|
/// @return 积分账户
|
||||||
|
GaoPointAccount selectByIdAndStoreId(@Param("storeId") String storeId, @Param("id") String id);
|
||||||
|
|
||||||
|
/// 统计积分账户数量
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 账户数量
|
||||||
|
long countByQuery(GaoPointAccountPage page);
|
||||||
|
|
||||||
|
/// 分页查询积分账户
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 账户列表
|
||||||
|
List<GaoPointAccount> selectByQuery(GaoPointAccountPage page);
|
||||||
|
|
||||||
/// 创建客户积分账户,已存在时保持原账户不变
|
/// 创建客户积分账户,已存在时保持原账户不变
|
||||||
///
|
///
|
||||||
/// @param account 积分账户
|
/// @param account 积分账户
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
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;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
/// GAO 客户积分账户服务
|
/// GAO 客户积分账户服务
|
||||||
@@ -9,6 +11,12 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
/// @since 2026-08-11
|
/// @since 2026-08-11
|
||||||
public interface GaoPointAccountService extends BaseService<GaoPointAccount, String> {
|
public interface GaoPointAccountService extends BaseService<GaoPointAccount, String> {
|
||||||
|
|
||||||
|
/// 分页查询积分账户
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 账户分页
|
||||||
|
PageResult<GaoPointAccount> pageByQuery(GaoPointAccountPage page);
|
||||||
|
|
||||||
/// 查询客户当前有效积分账户
|
/// 查询客户当前有效积分账户
|
||||||
///
|
///
|
||||||
/// @param storeId 门店 ID
|
/// @param storeId 门店 ID
|
||||||
@@ -16,6 +24,13 @@ public interface GaoPointAccountService extends BaseService<GaoPointAccount, Str
|
|||||||
/// @return 积分账户,不存在时返回 null
|
/// @return 积分账户,不存在时返回 null
|
||||||
GaoPointAccount getByCustomerId(String storeId, String customerId);
|
GaoPointAccount getByCustomerId(String storeId, String customerId);
|
||||||
|
|
||||||
|
/// 按账户 ID 查询积分账户
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID,可为空
|
||||||
|
/// @param id 账户 ID
|
||||||
|
/// @return 积分账户,不存在时返回 null
|
||||||
|
GaoPointAccount getByIdAndStoreId(String storeId, String id);
|
||||||
|
|
||||||
/// 获取并锁定客户积分账户,不存在时创建
|
/// 获取并锁定客户积分账户,不存在时创建
|
||||||
///
|
///
|
||||||
/// @param storeId 门店 ID
|
/// @param storeId 门店 ID
|
||||||
|
|||||||
+54
@@ -1,10 +1,16 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoPointAccountMapper;
|
import com.imyeyu.api.modules.gao.mapper.GaoPointAccountMapper;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
@@ -12,7 +18,10 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/// GAO 客户积分账户服务实现
|
/// GAO 客户积分账户服务实现
|
||||||
///
|
///
|
||||||
@@ -23,12 +32,24 @@ import java.util.UUID;
|
|||||||
public class GaoPointAccountServiceImplement extends AbstractEntityService<GaoPointAccount, String> implements GaoPointAccountService {
|
public class GaoPointAccountServiceImplement extends AbstractEntityService<GaoPointAccount, String> implements GaoPointAccountService {
|
||||||
|
|
||||||
private final GaoPointAccountMapper mapper;
|
private final GaoPointAccountMapper mapper;
|
||||||
|
private final GaoCustomerMapper customerMapper;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<GaoPointAccount, String> mapper() {
|
protected BaseMapper<GaoPointAccount, String> mapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoPointAccount> pageByQuery(GaoPointAccountPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
PageResult<GaoPointAccount> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countByQuery(page));
|
||||||
|
result.setList(mapper.selectByQuery(page));
|
||||||
|
fillCustomer(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GaoPointAccount getByCustomerId(String storeId, String customerId) {
|
public GaoPointAccount getByCustomerId(String storeId, String customerId) {
|
||||||
TimiException.required(storeId, "not found storeId");
|
TimiException.required(storeId, "not found storeId");
|
||||||
@@ -36,6 +57,39 @@ public class GaoPointAccountServiceImplement extends AbstractEntityService<GaoPo
|
|||||||
return mapper.selectByStoreIdAndCustomerId(storeId, customerId);
|
return mapper.selectByStoreIdAndCustomerId(storeId, customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoPointAccount getByIdAndStoreId(String storeId, String id) {
|
||||||
|
TimiException.required(id, "not found accountId");
|
||||||
|
GaoPointAccount account = mapper.selectByIdAndStoreId(storeId, id);
|
||||||
|
if (account != null) {
|
||||||
|
fillCustomer(List.of(account));
|
||||||
|
}
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillCustomer(List<GaoPointAccount> accountList) {
|
||||||
|
List<String> customerIdList = accountList.stream()
|
||||||
|
.map(GaoPointAccount::getCustomerId)
|
||||||
|
.filter(id -> id != null && !id.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (customerIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, GaoCustomer> customerMap = customerMapper.selectByIdList(customerIdList).stream()
|
||||||
|
.collect(Collectors.toMap(GaoCustomer::getId, item -> item));
|
||||||
|
Map<String, List<Attachment>> 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)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public GaoPointAccount getOrCreateForUpdate(String storeId, String customerId) {
|
public GaoPointAccount getOrCreateForUpdate(String storeId, String customerId) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -10,6 +10,53 @@
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIdAndStoreId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
|
||||||
|
SELECT *
|
||||||
|
FROM `gao_point_account`
|
||||||
|
WHERE `id` = #{id}
|
||||||
|
<if test="storeId != null and storeId != ''">
|
||||||
|
AND `store_id` = #{storeId}
|
||||||
|
</if>
|
||||||
|
AND `deleted_at` IS NULL
|
||||||
|
LIMIT 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<sql id="queryWhere">
|
||||||
|
`a`.`deleted_at` IS NULL
|
||||||
|
AND `c`.`deleted_at` IS NULL
|
||||||
|
<if test="storeId != null and storeId != ''">
|
||||||
|
AND `a`.`store_id` = #{storeId}
|
||||||
|
</if>
|
||||||
|
<if test="keyword != null and keyword != ''">
|
||||||
|
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}, '%')
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="countByQuery" resultType="long">
|
||||||
|
SELECT COUNT(1)
|
||||||
|
FROM `gao_point_account` `a`
|
||||||
|
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
||||||
|
WHERE
|
||||||
|
<include refid="queryWhere"/>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointAccount">
|
||||||
|
SELECT `a`.*
|
||||||
|
FROM `gao_point_account` `a`
|
||||||
|
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
||||||
|
WHERE
|
||||||
|
<include refid="queryWhere"/>
|
||||||
|
ORDER BY `a`.`created_at` DESC, `a`.`id` DESC
|
||||||
|
LIMIT #{offset}, #{limit}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertIfAbsent">
|
<insert id="insertIfAbsent">
|
||||||
INSERT INTO `gao_point_account` (
|
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`
|
`id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_consumed`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`
|
||||||
|
|||||||
Reference in New Issue
Block a user