👎 处理product的list json

This commit is contained in:
2022-11-19 21:12:30 +08:00
parent 167e3eed85
commit 4b336dfd8e
7 changed files with 69 additions and 29 deletions
@@ -21,28 +21,28 @@ public class YudaoCacheAutoConfiguration {
*
* 参考 org.springframework.boot.autoconfigure.cache.RedisCacheConfiguration 的 createConfiguration 方法
*/
@Bean
@Primary
public RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties) {
// 设置使用 JSON 序列化方式
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()));
// 设置 CacheProperties.Redis 的属性
CacheProperties.Redis redisProperties = cacheProperties.getRedis();
if (redisProperties.getTimeToLive() != null) {
config = config.entryTtl(redisProperties.getTimeToLive());
}
if (redisProperties.getKeyPrefix() != null) {
config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
}
if (!redisProperties.isCacheNullValues()) {
config = config.disableCachingNullValues();
}
if (!redisProperties.isUseKeyPrefix()) {
config = config.disableKeyPrefix();
}
return config;
}
// @Bean
// @Primary
// public RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties) {
// // 设置使用 JSON 序列化方式
// RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
// config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()));
//
// // 设置 CacheProperties.Redis 的属性
// CacheProperties.Redis redisProperties = cacheProperties.getRedis();
// if (redisProperties.getTimeToLive() != null) {
// config = config.entryTtl(redisProperties.getTimeToLive());
// }
// if (redisProperties.getKeyPrefix() != null) {
// config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
// }
// if (!redisProperties.isCacheNullValues()) {
// config = config.disableCachingNullValues();
// }
// if (!redisProperties.isUseKeyPrefix()) {
// config = config.disableKeyPrefix();
// }
// return config;
// }
}
@@ -13,7 +13,7 @@ import java.io.File;
"${yudao.info.base-package}.server", "${yudao.info.base-package}.module",
"co.yixiang", "com.zsw.erp"
})
@EnableDubbo
//@EnableDubbo
public class YudaoServerApplication {
public static void main(String[] args) {
@@ -70,7 +70,7 @@ spring:
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
host: 192.168.10.250 # 地址
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 0 # 数据库索引
@@ -0,0 +1,28 @@
package co.yixiang.config;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import java.util.List;
// 世纪的handler
public class SsjListHandler extends JacksonTypeHandler {
private Class<?> type;
public SsjListHandler(Class<?> type) {
super(type);
this.type = type;
}
@Override
protected List<?> parse(String json) {
// return super.parse(json);
return JSONUtil.toList(json,type);
}
@Override
protected String toJson(Object obj) {
return super.toJson(obj);
}
}
@@ -8,6 +8,7 @@ package co.yixiang.modules.product.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDomain;
import co.yixiang.config.SsjListHandler;
import co.yixiang.modules.category.domain.YxStoreCategory;
import co.yixiang.modules.evaluation.domain.EditableTabs;
import co.yixiang.modules.product.service.dto.Parameter;
@@ -39,7 +40,7 @@ import java.util.List;
*/
@TableName(value = "yx_store_product",autoResultMap = true)
@TableName(value = "yx_store_product",autoResultMap = true,resultMap = "co.yixiang.modules.product.service.mapper.StoreProductMapper.resultMap")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -76,7 +77,7 @@ public class YxStoreProduct extends BaseDomain {
private String storeName;
/**价保和无理由退款等配置**/
@TableField(typeHandler = JacksonTypeHandler.class)
@TableField(typeHandler = SsjListHandler.class)
private List<EditableTabs> config;
/** 商品简介 */
@@ -188,7 +189,7 @@ public class YxStoreProduct extends BaseDomain {
/** 商品参数 */
@ApiModelProperty(value = "商品参数")
@TableField(typeHandler = JacksonTypeHandler.class)
@TableField(typeHandler = SsjListHandler.class)
private List<Parameter> parameter;
/** 是否包邮 */
@@ -73,6 +73,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.qiniu.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -91,6 +92,7 @@ import java.util.stream.Collectors;
* @date 2020-05-12
*/
@Service
@Slf4j
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMapper, YxStoreProduct> implements YxStoreProductService {
@@ -340,7 +342,6 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
wrapper.eq(YxStoreProduct::getIsShow, ShopCommonEnum.SHOW_1.getValue())
.eq(YxStoreProduct::getId, id);
YxStoreProduct storeProduct = storeProductMapper.selectOne(wrapper);
if (ObjectUtil.isNull(storeProduct)) {
throw new ErrorRequestException("商品不存在或已下架");
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="co.yixiang.modules.product.service.mapper.StoreProductMapper">
<resultMap id="resultMap" type="co.yixiang.modules.product.domain.YxStoreProduct">
<result property="config" column="config" typeHandler="co.yixiang.config.SsjListHandler" javaType="co.yixiang.modules.evaluation.domain.EditableTabs"/>
</resultMap>
</mapper>