Browse Source

👎 处理product的list json

sj
Loki 2 years ago
parent
commit
4b336dfd8e
  1. 46
      yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java
  2. 2
      yudao-server/src/main/java/cn/iocoder/yudao/server/YudaoServerApplication.java
  3. 2
      yudao-server/src/main/resources/application-local.yaml
  4. 28
      zsw-bxg/src/main/java/co/yixiang/config/SsjListHandler.java
  5. 7
      zsw-bxg/src/main/java/co/yixiang/modules/product/domain/YxStoreProduct.java
  6. 3
      zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java
  7. 10
      zsw-bxg/src/main/resources/mapper/bxg/product.xml

46
yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java

@ -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;
// }
}

2
yudao-server/src/main/java/cn/iocoder/yudao/server/YudaoServerApplication.java

@ -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) {

2
yudao-server/src/main/resources/application-local.yaml

@ -70,7 +70,7 @@ spring:
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
host: 192.168.10.250 # 地址
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 0 # 数据库索引

28
zsw-bxg/src/main/java/co/yixiang/config/SsjListHandler.java

@ -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);
}
}

7
zsw-bxg/src/main/java/co/yixiang/modules/product/domain/YxStoreProduct.java

@ -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;
/** 是否包邮 */

3
zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java

@ -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("商品不存在或已下架");
}

10
zsw-bxg/src/main/resources/mapper/bxg/product.xml

@ -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>
Loading…
Cancel
Save