v1.0.33
This commit is contained in:
+39
@@ -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;
|
||||
}
|
||||
|
||||
+7
@@ -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);
|
||||
}
|
||||
|
||||
+5
@@ -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);
|
||||
|
||||
/// 写入销售订单消费事实
|
||||
///
|
||||
/// 幂等,重复执行返回已有事实
|
||||
|
||||
+19
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
+18
@@ -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` >= #{beginAt} AND `effective_at` <= #{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` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND r.`effective_at` <= #{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)
|
||||
|
||||
Reference in New Issue
Block a user