更新了商品管理模块

This commit is contained in:
chen-xin-zhi 2024-12-02 08:30:57 +08:00
parent d5bd947c73
commit 63c52fcc68
6 changed files with 146 additions and 1 deletions

View File

@ -171,6 +171,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>

View File

@ -49,7 +49,7 @@ public class ClothesGradeServiceImpl extends ServiceImpl<ClothesGradeMapper, Clo
if (ObjectUtils.isEmpty(maxPrice) || maxPrice.compareTo(BigDecimal.ZERO) <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "最高价格参数错误");
}
if (minPrice.compareTo(BigDecimal.ZERO) >= maxPrice.compareTo(BigDecimal.ZERO)) {
if (minPrice.compareTo(maxPrice) <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "最低价格不能高于最高价格");
}
if (StringUtils.isAnyBlank(clothesType, image, brief)) {

View File

@ -0,0 +1,22 @@
package com.cultural.heritage.test;
//@Component
//public class TestRedis {
//
// @Resource
// private StringRedisTemplate stringRedisTemplate;
//
// @Resource
// private GoodMapper goodMapper;
//
// @PostConstruct
// public void test() {
// List<Good> goodList = goodMapper.selectList(null);
//
// Map<String, String> map = goodList.stream().collect(Collectors.toMap
// (good -> good.getId().toString(), good -> good.getName()));
// stringRedisTemplate.opsForHash().putAll("test", map);
// stringRedisTemplate.opsForHash().get("test", "238");
// }
//
//}

View File

@ -0,0 +1,62 @@
package com.cultural.heritage.redis;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JedisTest {
private Jedis jedis;
/**
* 初始化Jedis实例
*/
@Before
public void init() {
//指定Redis服务器的IP地址和端口号
jedis = new Jedis("127.0.0.1", 6379);
System.out.println("连接成功");
}
@Test
public void redisJedisTest() {
//操作字符串
//方法名与操作原生redis的命令一致
jedis.set("dec", "hello");
String dec = jedis.get("dec");
System.out.println(dec);
//操作list
jedis.lpush("data", "v1", "v2", "v3");
jedis.rpush("data", "v4", "v5", "v6");
List<String> data = jedis.lrange("data", 0, -1);
for (String s : data) {
System.out.print(s + " ");
}
System.out.println();
//操作hash
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("id", "1");
hashMap.put("name", "huhai");
hashMap.put("age", "24");
jedis.hset("object", hashMap);
Map<String, String> object = jedis.hgetAll("object");
object.forEach((key, value) -> System.out.print(key + "=" + value + " "));
}
/**
* 关闭Jedis连接
*/
@After
public void close() {
jedis.close();
System.out.println("连接已关闭");
}
}

View File

@ -0,0 +1,32 @@
package com.cultural.heritage.redis;
import com.cultural.heritage.mapper.GoodMapper;
import com.cultural.heritage.model.entity.Good;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class TestRedis {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private GoodMapper goodMapper;
@Test
public void test() {
List<Good> goodList = goodMapper.selectList(null);
Map<String, String> map = goodList.stream().collect(Collectors.toMap
(good -> good.getId().toString(), good -> good.getName()));
stringRedisTemplate.opsForHash().putAll("test", map);
stringRedisTemplate.opsForHash().get("test", "238");
}
}

View File

@ -0,0 +1,23 @@
package com.cultural.heritage.test;
import java.math.BigDecimal;
public class Hello {
public static void main(String[] args) {
// Jedis jedis = new Jedis("localhost", 6379);
// System.out.println("连接成功");
// System.out.println("服务正在运行:" + jedis.ping());
//
// System.out.println(jedis.get("name"));
// jedis.lpush("site-list", "Runoob");
// jedis.lpush("site-list", "Google");
// jedis.lpush("site-list", "Taobao");
// List<String> list = jedis.lrange("site-list", 0 ,2);
// for(int i=0; i<list.size(); i++) {
// System.out.println("列表项为: "+list.get(i));
// }
BigDecimal minPrice = new BigDecimal(10);
BigDecimal maxPrice = new BigDecimal(20);
System.out.println(minPrice.compareTo(maxPrice));
}
}