From d99b538fd065debb6afe20c0223c721a9b4480b9 Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Sat, 8 Feb 2025 18:26:36 +0800 Subject: [PATCH] redis --- cash-api/account-server/pom.xml | 1 + .../main/java/com/czg/AccountApplication.java | 2 + .../controller/AuthorizationController.java | 4 +- .../com/czg/controller/FeignController.java | 8 +- .../czg/controller/ShopInfoController.java | 2 +- .../src/main/resources/application-dev.yml | 8 + cash-api/api-config/pom.xml | 26 + .../com/czg/controller/FeignController.java | 2 +- .../src/main/resources/application-dev.yml | 13 + cash-common/cash-common-redis/pom.xml | 23 + .../main/java/com/czg/config/RedisConfig.java | 41 ++ .../java/com/czg/service/RedisService.java | 557 ++++++++++++++++++ cash-dependencies/pom.xml | 12 + .../com/czg/service/AuthorizationService.java | 11 - .../account}/dto/SysLoginDTO.java | 2 +- .../account}/dto/shopuser/ShopUserAddDTO.java | 2 +- .../account}/feign/FeignSystemService.java | 4 +- .../account/service/AuthorizationService.java | 13 + .../service}/ShopInfoService.java | 2 +- .../impl/AuthorizationServiceImpl.java | 6 +- .../service}/impl/ShopInfoServiceImpl.java | 4 +- cash-service/pom.xml | 6 + .../czg/service/system/dto/SysParamsDTO.java | 2 +- .../czg/service/system/entity/SysParams.java | 2 + .../system/service/SysParamsService.java | 2 +- .../service/impl/SysParamsServiceImpl.java | 43 +- pom.xml | 2 + 27 files changed, 769 insertions(+), 31 deletions(-) create mode 100644 cash-api/api-config/pom.xml create mode 100644 cash-common/cash-common-redis/pom.xml create mode 100644 cash-common/cash-common-redis/src/main/java/com/czg/config/RedisConfig.java create mode 100644 cash-common/cash-common-redis/src/main/java/com/czg/service/RedisService.java delete mode 100644 cash-service/account-service/src/main/java/com/czg/service/AuthorizationService.java rename cash-service/account-service/src/main/java/com/czg/{ => service/account}/dto/SysLoginDTO.java (91%) rename cash-service/account-service/src/main/java/com/czg/{ => service/account}/dto/shopuser/ShopUserAddDTO.java (96%) rename cash-service/account-service/src/main/java/com/czg/{ => service/account}/feign/FeignSystemService.java (68%) create mode 100644 cash-service/account-service/src/main/java/com/czg/service/account/service/AuthorizationService.java rename cash-service/account-service/src/main/java/com/czg/service/{ => account/service}/ShopInfoService.java (63%) rename cash-service/account-service/src/main/java/com/czg/service/{ => account/service}/impl/AuthorizationServiceImpl.java (85%) rename cash-service/account-service/src/main/java/com/czg/service/{ => account/service}/impl/ShopInfoServiceImpl.java (60%) diff --git a/cash-api/account-server/pom.xml b/cash-api/account-server/pom.xml index 3c8c04b0..e12b2d66 100644 --- a/cash-api/account-server/pom.xml +++ b/cash-api/account-server/pom.xml @@ -30,6 +30,7 @@ + diff --git a/cash-api/account-server/src/main/java/com/czg/AccountApplication.java b/cash-api/account-server/src/main/java/com/czg/AccountApplication.java index 6c9ddcaf..7907e59b 100644 --- a/cash-api/account-server/src/main/java/com/czg/AccountApplication.java +++ b/cash-api/account-server/src/main/java/com/czg/AccountApplication.java @@ -1,5 +1,6 @@ package com.czg; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -11,6 +12,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableDiscoveryClient @EnableFeignClients +@MapperScan("com.czg.service.account.mapper") public class AccountApplication { public static void main(String[] args) { SpringApplication.run(AccountApplication.class, args); diff --git a/cash-api/account-server/src/main/java/com/czg/controller/AuthorizationController.java b/cash-api/account-server/src/main/java/com/czg/controller/AuthorizationController.java index 92ef7a7a..8ae2af82 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/AuthorizationController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/AuthorizationController.java @@ -1,9 +1,9 @@ package com.czg.controller; -import com.czg.dto.SysLoginDTO; +import com.czg.service.account.dto.SysLoginDTO; import com.czg.resp.CzgResult; import com.czg.sa.StpKit; -import com.czg.service.AuthorizationService; +import com.czg.service.account.service.AuthorizationService; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; diff --git a/cash-api/account-server/src/main/java/com/czg/controller/FeignController.java b/cash-api/account-server/src/main/java/com/czg/controller/FeignController.java index d28396a3..b3725238 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/FeignController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/FeignController.java @@ -1,7 +1,9 @@ package com.czg.controller; -import com.czg.feign.FeignSystemService; +import com.czg.service.account.feign.FeignSystemService; +import com.czg.service.RedisService; import jakarta.annotation.Resource; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,10 +17,14 @@ public class FeignController { @Resource private FeignSystemService feignSystemService; + @Autowired + private RedisService redisService; + @RequestMapping("/test") public String test() { String string = feignSystemService.testCall("sssss"); System.out.println(string); + redisService.set("sssss", string); return "test"; } diff --git a/cash-api/account-server/src/main/java/com/czg/controller/ShopInfoController.java b/cash-api/account-server/src/main/java/com/czg/controller/ShopInfoController.java index e71b94ee..e6aa6c0a 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/ShopInfoController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/ShopInfoController.java @@ -1,7 +1,7 @@ package com.czg.controller; import com.czg.resp.CzgResult; -import com.czg.service.ShopInfoService; +import com.czg.service.account.service.ShopInfoService; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/cash-api/account-server/src/main/resources/application-dev.yml b/cash-api/account-server/src/main/resources/application-dev.yml index e423cf78..509763d8 100644 --- a/cash-api/account-server/src/main/resources/application-dev.yml +++ b/cash-api/account-server/src/main/resources/application-dev.yml @@ -6,6 +6,13 @@ spring: username: cashier password: Cashier@1@ + data: + redis: + host: 121.40.128.145 + port: 6379 + password: 111111 + timeout: 1000 + cloud: nacos: config: @@ -22,3 +29,4 @@ spring: namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca + diff --git a/cash-api/api-config/pom.xml b/cash-api/api-config/pom.xml new file mode 100644 index 00000000..46d17c12 --- /dev/null +++ b/cash-api/api-config/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + com.czg + cash-api + 1.0.0 + + + api-config + maven-plugin + + api-config Maven Plugin + + https://maven.apache.org + + + UTF-8 + + + + + + + + diff --git a/cash-api/system-server/src/main/java/com/czg/controller/FeignController.java b/cash-api/system-server/src/main/java/com/czg/controller/FeignController.java index 87ce8e31..7b642506 100644 --- a/cash-api/system-server/src/main/java/com/czg/controller/FeignController.java +++ b/cash-api/system-server/src/main/java/com/czg/controller/FeignController.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RestController; * @author GYJoker */ @RestController -@RequestMapping("/feign") +@RequestMapping("/admin/feign") public class FeignController { @RequestMapping("/testCall/{name}") diff --git a/cash-api/system-server/src/main/resources/application-dev.yml b/cash-api/system-server/src/main/resources/application-dev.yml index 619267ee..4ec5d1d3 100644 --- a/cash-api/system-server/src/main/resources/application-dev.yml +++ b/cash-api/system-server/src/main/resources/application-dev.yml @@ -6,6 +6,19 @@ spring: username: cashier password: Cashier@1@ + data: + redis: + host: 121.40.128.145 + port: 6379 + password: 111111 + timeout: 1000 + lettuce: + pool: + min-idle: 0 + max-idle: 8 + max-wait: -1ms + max-active: 16 + cloud: nacos: discovery: diff --git a/cash-common/cash-common-redis/pom.xml b/cash-common/cash-common-redis/pom.xml new file mode 100644 index 00000000..eb378626 --- /dev/null +++ b/cash-common/cash-common-redis/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + com.czg + cash-common + 1.0.0 + + cash-common-redis + cash-common-redis + https://maven.apache.org + + + + redis.clients + jedis + + + org.springframework.data + spring-data-redis + + + diff --git a/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisConfig.java b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisConfig.java new file mode 100644 index 00000000..bfd0ab37 --- /dev/null +++ b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisConfig.java @@ -0,0 +1,41 @@ +package com.czg.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * @author GYJoker + */ +@Configuration +public class RedisConfig { + + /** + * redisTemplate相关配置 + * [@Role(BeanDefinition.ROLE_INFRASTRUCTURE)] 表明这个bean是完全后台模式,不需要被代理。 + * + * @param factory Redis连接工厂类 + * @return 返回配置项对象 + */ + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + + RedisTemplate template = new RedisTemplate<>(); + // 配置连接工厂 + template.setConnectionFactory(factory); + + // 使用StringRedisSerializer来序列化和反序列化redis的key值 + template.setKeySerializer(new StringRedisSerializer()); + // 设置hash key 和value序列化模式 + template.setHashKeySerializer(new StringRedisSerializer()); + // template.setHashValueSerializer(jacksonSerial); + template.setHashValueSerializer(new StringRedisSerializer()); + template.setValueSerializer(new StringRedisSerializer()); + template.afterPropertiesSet(); + + return template; + } + +} diff --git a/cash-common/cash-common-redis/src/main/java/com/czg/service/RedisService.java b/cash-common/cash-common-redis/src/main/java/com/czg/service/RedisService.java new file mode 100644 index 00000000..566802fb --- /dev/null +++ b/cash-common/cash-common-redis/src/main/java/com/czg/service/RedisService.java @@ -0,0 +1,557 @@ +package com.czg.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * @author GYJoker + */ +@Component +public class RedisService { + + @Autowired + private final RedisTemplate redisTemplate; + + public RedisService(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + /** + * 删除当前库所有key + * + * @return 返回删除的key数 + */ + public Long deleteAllKeys() { + Set keys = redisTemplate.keys("*"); + assert keys != null; + return redisTemplate.delete(keys); + } + + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + * @return 返回结果 + */ + public boolean expire(String key, long time) { + try { + if (time > 0) { + redisTemplate.expire(key, time, TimeUnit.SECONDS); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 根据key 获取过期时间 + * + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public Long getExpire(String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 判断key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public Boolean hasKey(String key) { + try { + return redisTemplate.hasKey(key); + } catch (Exception e) { + return false; + } + } + + /** + * 删除缓存 + * + * @param key 可以传一个值 或多个 + */ + @SuppressWarnings("unchecked") + public void del(String... key) { + if (key != null && key.length > 0) { + if (key.length == 1) { + redisTemplate.delete(key[0]); + } else { + redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); + } + } + } + + //============================String============================= + + /** + * 普通缓存获取 + * + * @param key 键 + * @return 值 + */ + public Object get(String key) { + return key == null ? null : redisTemplate.opsForValue().get(key); + } + + /** + * 普通缓存放入 + * + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + try { + redisTemplate.opsForValue().set(key, value); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 递增 + * + * @param key 键 + * @param delta 要增加几(大于0) + * @return 返回结果 + */ + public Long incr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递增因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, delta); + } + + /** + * 递减 + * + * @param key 键 + * @param delta 要减少几(小于0) + * @return 返回结果 + */ + public Long decr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递减因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, -delta); + } + + //================================Map================================= + + /** + * HashGet + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * HashSet + * + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * HashSet 并设置时间 + * + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 删除hash表中的值 + * + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + /** + * 判断hash表中是否有该项的值 + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + /** + * hash递减 + * + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + + //============================set============================= + + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + */ + public Set sGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + try { + return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(key, value)); + } catch (Exception e) { + return false; + } + } + + /** + * 将数据放入set缓存 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public Long sSet(String key, Object... values) { + try { + return redisTemplate.opsForSet().add(key, values); + } catch (Exception e) { + return 0L; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public Long sSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + return 0L; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return 返回结果 + */ + public Long sGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + return 0L; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public Long setRemove(String key, Object... values) { + try { + return redisTemplate.opsForSet().remove(key, values); + } catch (Exception e) { + return 0L; + } + } + //===============================list================================= + + /** + * 获取list缓存的内容 + * + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + * @return 返回结果 + */ + public List lGet(String key, long start, long end) { + try { + return redisTemplate.opsForList().range(key, start, end); + } catch (Exception e) { + return null; + } + } + + /** + * 获取list缓存的长度 + * + * @param key 键 + */ + public Long lGetListSize(String key) { + try { + return redisTemplate.opsForList().size(key); + } catch (Exception e) { + return 0L; + } + } + + /** + * 通过索引 获取list中的值 + * + * @param key 键 + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 + * @return 返回结果 + */ + public Object lGetIndex(String key, long index) { + try { + return redisTemplate.opsForList().index(key, index); + } catch (Exception e) { + return null; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return 返回结果 + */ + public boolean lSet(String key, Object value) { + try { + redisTemplate.opsForList().rightPush(key, value); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return 返回结果 + */ + public boolean lSet(String key, Object value, long time) { + try { + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return 返回结果 + */ + public boolean lSet(String key, List value) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return 返回结果 + */ + public boolean lSet(String key, List value, long time) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 根据索引修改list中的某条数据 + * + * @param key 键 + * @param index 索引 + * @param value 值 + * @return 返回结果 + */ + public boolean lUpdateIndex(String key, long index, Object value) { + try { + redisTemplate.opsForList().set(key, index, value); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 移除N个值为value + * + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public Long lRemove(String key, long count, Object value) { + try { + return redisTemplate.opsForList().remove(key, count, value); + } catch (Exception e) { + return 0L; + } + } + +} diff --git a/cash-dependencies/pom.xml b/cash-dependencies/pom.xml index 9d943828..fe979996 100644 --- a/cash-dependencies/pom.xml +++ b/cash-dependencies/pom.xml @@ -29,6 +29,8 @@ 8.2.0 3.0.4 4.2.0 + 5.2.0 + 3.4.2 @@ -178,6 +180,16 @@ ${cloud-starter-loadbalancer.version} + + redis.clients + jedis + ${jedis.version} + + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + diff --git a/cash-service/account-service/src/main/java/com/czg/service/AuthorizationService.java b/cash-service/account-service/src/main/java/com/czg/service/AuthorizationService.java deleted file mode 100644 index b88223e4..00000000 --- a/cash-service/account-service/src/main/java/com/czg/service/AuthorizationService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.czg.service; - - -/** - * @author Administrator - */ -public interface AuthorizationService { - Object getCaptcha(); - - Object login(com.czg.dto.SysLoginDTO loginDTO); -} diff --git a/cash-service/account-service/src/main/java/com/czg/dto/SysLoginDTO.java b/cash-service/account-service/src/main/java/com/czg/service/account/dto/SysLoginDTO.java similarity index 91% rename from cash-service/account-service/src/main/java/com/czg/dto/SysLoginDTO.java rename to cash-service/account-service/src/main/java/com/czg/service/account/dto/SysLoginDTO.java index e7c86470..02e668d2 100644 --- a/cash-service/account-service/src/main/java/com/czg/dto/SysLoginDTO.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/dto/SysLoginDTO.java @@ -1,4 +1,4 @@ -package com.czg.dto; +package com.czg.service.account.dto; import jakarta.validation.constraints.NotEmpty; diff --git a/cash-service/account-service/src/main/java/com/czg/dto/shopuser/ShopUserAddDTO.java b/cash-service/account-service/src/main/java/com/czg/service/account/dto/shopuser/ShopUserAddDTO.java similarity index 96% rename from cash-service/account-service/src/main/java/com/czg/dto/shopuser/ShopUserAddDTO.java rename to cash-service/account-service/src/main/java/com/czg/service/account/dto/shopuser/ShopUserAddDTO.java index bb05a417..7558f256 100644 --- a/cash-service/account-service/src/main/java/com/czg/dto/shopuser/ShopUserAddDTO.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/dto/shopuser/ShopUserAddDTO.java @@ -1,4 +1,4 @@ -package com.czg.dto.shopuser; +package com.czg.service.account.dto.shopuser; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; diff --git a/cash-service/account-service/src/main/java/com/czg/feign/FeignSystemService.java b/cash-service/account-service/src/main/java/com/czg/service/account/feign/FeignSystemService.java similarity index 68% rename from cash-service/account-service/src/main/java/com/czg/feign/FeignSystemService.java rename to cash-service/account-service/src/main/java/com/czg/service/account/feign/FeignSystemService.java index bc151ab6..3a13d924 100644 --- a/cash-service/account-service/src/main/java/com/czg/feign/FeignSystemService.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/feign/FeignSystemService.java @@ -1,4 +1,4 @@ -package com.czg.feign; +package com.czg.service.account.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; @@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.PathVariable; */ @FeignClient("system-server") public interface FeignSystemService { - @GetMapping("/feign/testCall/{name}") // 使用 get 方式,调用服务提供者的 /call/{name} 接口 + @GetMapping("/admin/feign/testCall/{name}") // 使用 get 方式,调用服务提供者的 /call/{name} 接口 String testCall(@PathVariable(value = "name") String name); } diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/service/AuthorizationService.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/AuthorizationService.java new file mode 100644 index 00000000..1d8a9a84 --- /dev/null +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/AuthorizationService.java @@ -0,0 +1,13 @@ +package com.czg.service.account.service; + + +import com.czg.service.account.dto.SysLoginDTO; + +/** + * @author Administrator + */ +public interface AuthorizationService { + Object getCaptcha(); + + Object login(SysLoginDTO loginDTO); +} diff --git a/cash-service/account-service/src/main/java/com/czg/service/ShopInfoService.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/ShopInfoService.java similarity index 63% rename from cash-service/account-service/src/main/java/com/czg/service/ShopInfoService.java rename to cash-service/account-service/src/main/java/com/czg/service/account/service/ShopInfoService.java index c84d5743..d5a23189 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/ShopInfoService.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/ShopInfoService.java @@ -1,4 +1,4 @@ -package com.czg.service; +package com.czg.service.account.service; /** * @author Administrator diff --git a/cash-service/account-service/src/main/java/com/czg/service/impl/AuthorizationServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/AuthorizationServiceImpl.java similarity index 85% rename from cash-service/account-service/src/main/java/com/czg/service/impl/AuthorizationServiceImpl.java rename to cash-service/account-service/src/main/java/com/czg/service/account/service/impl/AuthorizationServiceImpl.java index 89fa31fd..fa4817c4 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/impl/AuthorizationServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/AuthorizationServiceImpl.java @@ -1,9 +1,9 @@ -package com.czg.service.impl; +package com.czg.service.account.service.impl; import cn.hutool.core.util.IdUtil; -import com.czg.dto.SysLoginDTO; +import com.czg.service.account.dto.SysLoginDTO; import com.czg.sa.StpKit; -import com.czg.service.AuthorizationService; +import com.czg.service.account.service.AuthorizationService; import com.wf.captcha.SpecCaptcha; import org.springframework.stereotype.Service; diff --git a/cash-service/account-service/src/main/java/com/czg/service/impl/ShopInfoServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopInfoServiceImpl.java similarity index 60% rename from cash-service/account-service/src/main/java/com/czg/service/impl/ShopInfoServiceImpl.java rename to cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopInfoServiceImpl.java index 03c5fe09..c63179bd 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/impl/ShopInfoServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopInfoServiceImpl.java @@ -1,6 +1,6 @@ -package com.czg.service.impl; +package com.czg.service.account.service.impl; -import com.czg.service.ShopInfoService; +import com.czg.service.account.service.ShopInfoService; import org.springframework.stereotype.Service; /** diff --git a/cash-service/pom.xml b/cash-service/pom.xml index 6d64f3e7..64115f03 100644 --- a/cash-service/pom.xml +++ b/cash-service/pom.xml @@ -34,6 +34,12 @@ 1.0.0 + + com.czg + cash-common-redis + 1.0.0 + + com.czg cash-common-sa-token diff --git a/cash-service/system-service/src/main/java/com/czg/service/system/dto/SysParamsDTO.java b/cash-service/system-service/src/main/java/com/czg/service/system/dto/SysParamsDTO.java index b9103da1..9e90c113 100644 --- a/cash-service/system-service/src/main/java/com/czg/service/system/dto/SysParamsDTO.java +++ b/cash-service/system-service/src/main/java/com/czg/service/system/dto/SysParamsDTO.java @@ -10,6 +10,6 @@ public class SysParamsDTO { private Long id; private String paramCode; private String paramValue; - private String paramType; + private Integer paramType; private String remark; } diff --git a/cash-service/system-service/src/main/java/com/czg/service/system/entity/SysParams.java b/cash-service/system-service/src/main/java/com/czg/service/system/entity/SysParams.java index 77d4c94f..8a8ca926 100644 --- a/cash-service/system-service/src/main/java/com/czg/service/system/entity/SysParams.java +++ b/cash-service/system-service/src/main/java/com/czg/service/system/entity/SysParams.java @@ -13,6 +13,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; /** * 实体类。 @@ -21,6 +22,7 @@ import lombok.NoArgsConstructor; * @since 2025-02-07 */ @Data +@Accessors(chain = true) @Builder @NoArgsConstructor @AllArgsConstructor diff --git a/cash-service/system-service/src/main/java/com/czg/service/system/service/SysParamsService.java b/cash-service/system-service/src/main/java/com/czg/service/system/service/SysParamsService.java index 27e584a1..a650a926 100644 --- a/cash-service/system-service/src/main/java/com/czg/service/system/service/SysParamsService.java +++ b/cash-service/system-service/src/main/java/com/czg/service/system/service/SysParamsService.java @@ -25,5 +25,5 @@ public interface SysParamsService extends IService { * @param paramsDTO 参数 * @return 修改结果 */ - CzgResult updateParams(SysParamsDTO paramsDTO); + CzgResult updateParams(SysParamsDTO paramsDTO); } diff --git a/cash-service/system-service/src/main/java/com/czg/service/system/service/impl/SysParamsServiceImpl.java b/cash-service/system-service/src/main/java/com/czg/service/system/service/impl/SysParamsServiceImpl.java index c8408a86..53de9e3f 100644 --- a/cash-service/system-service/src/main/java/com/czg/service/system/service/impl/SysParamsServiceImpl.java +++ b/cash-service/system-service/src/main/java/com/czg/service/system/service/impl/SysParamsServiceImpl.java @@ -1,7 +1,10 @@ package com.czg.service.system.service.impl; +import cn.dev33.satoken.session.SaSession; import com.czg.resp.CzgResult; +import com.czg.sa.StpKit; import com.czg.service.system.dto.SysParamsDTO; +import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.spring.service.impl.ServiceImpl; import com.czg.service.system.entity.SysParams; import com.czg.service.system.mapper.SysParamsMapper; @@ -19,11 +22,45 @@ public class SysParamsServiceImpl extends ServiceImpl insertParams(SysParamsDTO paramsDTO) { - return null; + // 查询 paramCode 是否存在 + SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode())); + if (sysParams != null) { + return CzgResult.failure("参数编码已存在"); + } + + Long userId = StpKit.ADMIN.getLoginId(1L); + + // 新增参数 + sysParams = new SysParams(); + sysParams.setParamCode(paramsDTO.getParamCode()) + .setParamValue(paramsDTO.getParamValue()) + .setParamType(paramsDTO.getParamType()) + .setRemark(paramsDTO.getRemark()) + .setCreateUserId(userId); + + save(sysParams); + + return CzgResult.success(sysParams.getId()); } @Override - public CzgResult updateParams(SysParamsDTO paramsDTO) { - return null; + public CzgResult updateParams(SysParamsDTO paramsDTO) { + // 查询 paramCode 是否存在 + SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode()) + .ne(SysParams::getId, paramsDTO.getId())); + if (sysParams != null) { + return CzgResult.failure("参数编码已存在"); + } + + Long userId = StpKit.ADMIN.getLoginId(1L); + + // 修改参数 + sysParams = getById(paramsDTO.getId()); + sysParams.setParamCode(paramsDTO.getParamCode()) + .setParamValue(paramsDTO.getParamValue()) + .setParamType(paramsDTO.getParamType()) + .setUpdateUserId(userId); + + return CzgResult.success(sysParams.getId()); } } diff --git a/pom.xml b/pom.xml index dc28a3b3..2ceb51aa 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,8 @@ cash-service cash-sdk cash-dependencies + cash-api/api-config + cash-common/cash-common-redis