You've already forked FrameTour-BE
feat(pricing): 添加优惠券管理功能
- 新增 CouponManagementController 控制器,实现优惠券配置和领取记录的管理 - 新增 ICouponManagementService 接口和 CouponManagementServiceImpl 实现类,提供优惠券管理服务 - 在 PricingConfigController 中添加获取所有优惠券配置和领取记录的接口 - 新增 BundleProductListTypeHandler 类,用于处理一口价商品列表的序列化和反序列化 - 更新 PriceCouponClaimRecordMapper 和 PriceCouponConfigMapper,添加管理端所需的查询接口
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.ycwl.basic.pricing.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ycwl.basic.pricing.dto.BundleProductItem;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 一口价商品列表类型处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class BundleProductListTypeHandler extends BaseTypeHandler<List<BundleProductItem>> {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final TypeReference<List<BundleProductItem>> typeReference = new TypeReference<List<BundleProductItem>>() {};
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<BundleProductItem> parameter, JdbcType jdbcType) throws SQLException {
|
||||
try {
|
||||
String json = objectMapper.writeValueAsString(parameter);
|
||||
ps.setString(i, json);
|
||||
log.debug("序列化商品列表: {}", json);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("序列化商品列表失败", e);
|
||||
throw new SQLException("序列化商品列表失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BundleProductItem> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String json = rs.getString(columnName);
|
||||
return parseJson(json, columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BundleProductItem> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String json = rs.getString(columnIndex);
|
||||
return parseJson(json, "columnIndex:" + columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BundleProductItem> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String json = cs.getString(columnIndex);
|
||||
return parseJson(json, "columnIndex:" + columnIndex);
|
||||
}
|
||||
|
||||
private List<BundleProductItem> parseJson(String json, String source) {
|
||||
if (json == null || json.trim().isEmpty()) {
|
||||
log.debug("从{}获取的JSON为空,返回空列表", source);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
List<BundleProductItem> result = objectMapper.readValue(json, typeReference);
|
||||
log.debug("从{}反序列化商品列表成功,数量: {}", source, result != null ? result.size() : 0);
|
||||
return result != null ? result : new ArrayList<>();
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("从{}反序列化商品列表失败,JSON: {}", source, json, e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user