This commit is contained in:
GYJ 2025-02-08 18:26:36 +08:00
parent 0204f427cc
commit d99b538fd0
27 changed files with 769 additions and 31 deletions

View File

@ -30,6 +30,7 @@
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash-api</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>api-config</artifactId>
<packaging>maven-plugin</packaging>
<name>api-config Maven Plugin</name>
<url>https://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
</project>

View File

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

View File

@ -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:

View File

@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash-common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cash-common-redis</artifactId>
<name>cash-common-redis</name>
<url>https://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -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<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> 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;
}
}

View File

@ -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<String, Object> redisTemplate;
public RedisService(RedisTemplate<String, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}
/**
* 删除当前库所有key
*
* @return 返回删除的key数
*/
public Long deleteAllKeys() {
Set<String> 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<String>) 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<Object, Object> hmget(String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* HashSet
*
* @param key
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public boolean hmset(String key, Map<String, Object> 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<String, Object> 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<Object> 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<Object> 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<Object> 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<Object> 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;
}
}
}

View File

@ -29,6 +29,8 @@
<mysql-connector-j.version>8.2.0</mysql-connector-j.version>
<mybatis-spring-boot.version>3.0.4</mybatis-spring-boot.version>
<cloud-starter-loadbalancer.version>4.2.0</cloud-starter-loadbalancer.version>
<jedis.version>5.2.0</jedis.version>
<spring-data-redis.version>3.4.2</spring-data-redis.version>
</properties>
<dependencyManagement>
@ -178,6 +180,16 @@
<version>${cloud-starter-loadbalancer.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring-data-redis.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -1,11 +0,0 @@
package com.czg.service;
/**
* @author Administrator
*/
public interface AuthorizationService {
Object getCaptcha();
Object login(com.czg.dto.SysLoginDTO loginDTO);
}

View File

@ -1,4 +1,4 @@
package com.czg.dto;
package com.czg.service.account.dto;
import jakarta.validation.constraints.NotEmpty;

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package com.czg.service;
package com.czg.service.account.service;
/**
* @author Administrator

View File

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

View File

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

View File

@ -34,6 +34,12 @@
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-redis</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-sa-token</artifactId>

View File

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

View File

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

View File

@ -25,5 +25,5 @@ public interface SysParamsService extends IService<SysParams> {
* @param paramsDTO 参数
* @return 修改结果
*/
CzgResult<SysParamsDTO> updateParams(SysParamsDTO paramsDTO);
CzgResult<Long> updateParams(SysParamsDTO paramsDTO);
}

View File

@ -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<SysParamsMapper, SysParams
@Override
public CzgResult<Long> 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<SysParamsDTO> updateParams(SysParamsDTO paramsDTO) {
return null;
public CzgResult<Long> 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());
}
}

View File

@ -26,6 +26,8 @@
<module>cash-service</module>
<module>cash-sdk</module>
<module>cash-dependencies</module>
<module>cash-api/api-config</module>
<module>cash-common/cash-common-redis</module>
</modules>
<properties>