Compare commits

...
4 Commits
Author SHA1 Message Date
timi b373cbbe46 Merge pull request 'v1.0.33' (#45) from dev into master
Reviewed-on: #45
2026-09-07 09:40:39 +00:00
Timi bb5abcb48e v1.0.33
CI / build-deploy (pull_request) Successful in 24s
CI / notify-on-failure (pull_request) Skipped
2026-09-07 17:40:06 +08:00
timi acd97c7b9b Merge pull request 'v1.0.32' (#44) from dev into master
Reviewed-on: #44
2026-09-07 08:42:29 +00:00
Timi 4a549e77cb v1.0.32
CI / build-deploy (pull_request) Successful in 26s
CI / notify-on-failure (pull_request) Skipped
2026-09-07 16:41:53 +08:00
11 changed files with 159 additions and 8 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<groupId>com.imyeyu.timiserverapi</groupId>
<artifactId>TimiServerAPI</artifactId>
<version>1.0.31</version>
<version>1.0.33</version>
<packaging>jar</packaging>
<name>TimiServerAPI</name>
<description>imyeyu.com API</description>
@@ -0,0 +1,39 @@
package com.imyeyu.api.modules.gao.controller;
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
import com.imyeyu.api.modules.gao.service.GaoCustomerConsumptionRecordService;
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPageResult;
import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.annotation.AOPLog;
import com.imyeyu.spring.annotation.RequestRateLimit;
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.RestController;
/// GAO 客户消费事实接口
///
/// @author Codex
/// @since 2026-09-07
@RestController
@RequiredArgsConstructor
@RequestMapping("/gao/customer/consumption-record")
public class GaoCustomerConsumptionRecordController {
private final GaoCustomerConsumptionRecordService service;
private final GaoStoreScopeService storeScopeService;
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_READ)
@PostMapping("/list")
public GaoCustomerConsumptionRecordPageResult list(@RequestBody GaoCustomerConsumptionRecordPage page) {
TimiException.required(page, "not found consumption record page");
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
return service.pageByQuery(page);
}
}
@@ -1,6 +1,7 @@
package com.imyeyu.api.modules.gao.entity;
import com.fasterxml.jackson.databind.JsonNode;
import com.imyeyu.spring.annotation.table.Transient;
import com.imyeyu.spring.entity.UUIDEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -41,4 +42,8 @@ public class GaoCustomerConsumptionRecord extends UUIDEntity {
private Long revokedAt;
private String revokeReason;
private JsonNode sourcePayload;
/// 客户
@Transient
private GaoCustomer customer;
}
@@ -1,6 +1,7 @@
package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPage;
import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
@@ -16,5 +17,11 @@ public interface GaoCustomerConsumptionRecordMapper extends BaseMapper<GaoCustom
List<GaoCustomerConsumptionRecord> selectActiveByWindow(@Param("storeId") String storeId, @Param("customerId") String customerId, @Param("beginAt") long beginAt, @Param("endAt") long endAt);
long countByQuery(GaoCustomerConsumptionRecordPage page);
Long sumAmountByPage(GaoCustomerConsumptionRecordPage page);
List<GaoCustomerConsumptionRecord> selectByQuery(GaoCustomerConsumptionRecordPage page);
int revokeBySource(@Param("sourceType") GaoCustomerConsumptionRecord.SourceType sourceType, @Param("sourceId") String sourceId, @Param("revokedAt") long revokedAt, @Param("revokeReason") String revokeReason);
}
@@ -2,6 +2,7 @@ package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoPackageConfigItem;
import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
@@ -13,6 +14,12 @@ import java.util.List;
/// @since 2026-08-31
public interface GaoPackageConfigItemMapper extends BaseMapper<GaoPackageConfigItem, String> {
/// 物理删除套餐配置的全部权益模板项
///
/// @param packageConfigId 套餐配置 ID
@Delete("DELETE FROM `gao_package_config_item` WHERE `package_config_id` = #{packageConfigId}")
void destroyByPackageConfigId(@Param("packageConfigId") String packageConfigId);
/// 按套餐配置 ID 查询产品
List<GaoPackageConfigItem> selectByPackageConfigId(@Param("packageConfigId") String packageConfigId);
@@ -1,6 +1,8 @@
package com.imyeyu.api.modules.gao.service;
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPageResult;
import com.imyeyu.spring.service.BaseService;
import java.util.List;
@@ -11,6 +13,9 @@ import java.util.List;
/// @since 2026-09-04
public interface GaoCustomerConsumptionRecordService extends BaseService<GaoCustomerConsumptionRecord, String> {
/// 按条件分页查询消费事实
GaoCustomerConsumptionRecordPageResult pageByQuery(GaoCustomerConsumptionRecordPage page);
/// 写入销售订单消费事实
///
/// 幂等,重复执行返回已有事实
@@ -4,7 +4,10 @@ import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
import com.imyeyu.api.modules.gao.mapper.GaoCustomerConsumptionRecordMapper;
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.gao.service.GaoCustomerConsumptionRecordService;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPageResult;
import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService;
@@ -24,12 +27,28 @@ import java.util.List;
public class GaoCustomerConsumptionRecordServiceImplement extends AbstractEntityService<GaoCustomerConsumptionRecord, String> implements GaoCustomerConsumptionRecordService {
private final GaoCustomerConsumptionRecordMapper mapper;
private final GaoCustomerService customerService;
@Override
protected BaseMapper<GaoCustomerConsumptionRecord, String> mapper() {
return mapper;
}
@Override
public GaoCustomerConsumptionRecordPageResult pageByQuery(GaoCustomerConsumptionRecordPage page) {
TimiException.required(page, "not found consumption record page");
GaoCustomerConsumptionRecordPageResult result = new GaoCustomerConsumptionRecordPageResult();
result.setTotal(mapper.countByQuery(page));
result.setAmountTotal(mapper.sumAmountByPage(page));
List<GaoCustomerConsumptionRecord> list = mapper.selectByQuery(page);
result.setList(list);
var customerMap = customerService.mapByIdList(list.stream().map(GaoCustomerConsumptionRecord::getCustomerId).toList());
for (GaoCustomerConsumptionRecord record : list) {
record.setCustomer(customerMap.get(record.getCustomerId()));
}
return result;
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public GaoCustomerConsumptionRecord createSalesOrder(String salesOrderId, String storeId, String customerId, Long amount, Long effectiveAt, GaoSalesOrder.OrderType orderType) {
@@ -132,15 +132,13 @@ public class GaoPackageConfigServiceImplement extends AbstractEntityService<GaoP
dbConfig.setEndAt(request.getEndAt());
dbConfig.setSort(request.getSort());
prepareConfig(dbConfig, dbConfig.getId());
TimiException.required(request.getItemList(), "套餐至少配置一个产品");
verifyItems(dbConfig.getStoreId(), request.getItemList());
dbConfig.setUpdatedBy(userLoginService.getRequireLoginUserId());
super.update(dbConfig);
if (request.getItemList() != null) {
verifyItems(dbConfig.getStoreId(), request.getItemList());
GaoPackageConfigItem example = new GaoPackageConfigItem();
example.setPackageConfigId(dbConfig.getId());
itemMapper.deleteAllByExample(example);
saveItems(dbConfig.getId(), request.getItemList());
}
// 权益项仅是后续购买使用的套餐模板,历史订单已保存独立的订单明细快照
itemMapper.destroyByPackageConfigId(dbConfig.getId());
saveItems(dbConfig.getId(), request.getItemList());
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@@ -0,0 +1,33 @@
package com.imyeyu.api.modules.gao.vo;
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
import com.imyeyu.java.bean.BasePage;
import lombok.Data;
import lombok.EqualsAndHashCode;
/// GAO 客户消费事实分页请求
///
/// @author Codex
/// @since 2026-09-07
@Data
@EqualsAndHashCode(callSuper = true)
public class GaoCustomerConsumptionRecordPage extends BasePage {
/// 门店 ID
private String storeId;
/// 客户 ID
private String customerId;
/// 消费来源
private GaoCustomerConsumptionRecord.SourceType sourceType;
/// 消费状态
private GaoCustomerConsumptionRecord.Status status;
/// 起始生效时间
private Long beginAt;
/// 结束生效时间
private Long endAt;
}
@@ -0,0 +1,18 @@
package com.imyeyu.api.modules.gao.vo;
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
import com.imyeyu.spring.bean.PageResult;
import lombok.Data;
import lombok.EqualsAndHashCode;
/// GAO 客户消费事实分页查询结果
///
/// @author Codex
/// @since 2026-09-07
@Data
@EqualsAndHashCode(callSuper = true)
public class GaoCustomerConsumptionRecordPageResult extends PageResult<GaoCustomerConsumptionRecord> {
/// 当前筛选条件下的消费金额合计,单位分
private Long amountTotal;
}
@@ -12,6 +12,26 @@
AND `effective_at` &gt;= #{beginAt} AND `effective_at` &lt;= #{endAt} AND `deleted_at` IS NULL
ORDER BY `effective_at` ASC, `id` ASC
</select>
<sql id="pageWhere">
r.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND r.`store_id` = #{storeId}</if>
<if test="customerId != null and customerId != ''">AND r.`customer_id` = #{customerId}</if>
<if test="sourceType != null">AND r.`source_type` = #{sourceType}</if>
<if test="status != null">AND r.`status` = #{status}</if>
<if test="beginAt != null">AND r.`effective_at` &gt;= #{beginAt}</if>
<if test="endAt != null">AND r.`effective_at` &lt;= #{endAt}</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1) FROM `gao_customer_consumption_record` r WHERE <include refid="pageWhere"/>
</select>
<select id="sumAmountByPage" resultType="long">
SELECT COALESCE(SUM(r.`amount`), 0) FROM `gao_customer_consumption_record` r WHERE <include refid="pageWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord">
SELECT r.* FROM `gao_customer_consumption_record` r WHERE <include refid="pageWhere"/>
ORDER BY r.`effective_at` DESC, r.`created_at` DESC
LIMIT #{offset}, #{limit}
</select>
<update id="revokeBySource">
UPDATE `gao_customer_consumption_record`
SET `status` = 'REVOKED', `revoked_at` = #{revokedAt}, `revoke_reason` = #{revokeReason}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)