sys param 删除 id
This commit is contained in:
@@ -3,11 +3,13 @@ package com.czg;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ww
|
* @author ww
|
||||||
*/
|
*/
|
||||||
|
@EnableCaching
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@MapperScan("com.czg.service.system.mapper")
|
@MapperScan("com.czg.service.system.mapper")
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author GYJoker
|
* @author GYJoker
|
||||||
*/
|
*/
|
||||||
@@ -26,18 +28,48 @@ public class SysParamController {
|
|||||||
* @return 新增结果
|
* @return 新增结果
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public CzgResult<Long> insertParams(@RequestBody @Validated({InsertGroup.class}) SysParamsDTO paramsDTO) {
|
public CzgResult<String> insertParams(@RequestBody @Validated({InsertGroup.class}) SysParamsDTO paramsDTO) {
|
||||||
return sysParamsService.insertParams(paramsDTO);
|
return sysParamsService.insertParams(paramsDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改参数
|
* 修改参数
|
||||||
* @param paramsDTO 参数
|
* @param paramsDTO 参数
|
||||||
* @return 修改结果
|
* @return 修改结果
|
||||||
*/
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public CzgResult<Long> updateParams(@RequestBody @Validated({UpdateGroup.class}) SysParamsDTO paramsDTO) {
|
public CzgResult<String> updateParams(@RequestBody @Validated({UpdateGroup.class}) SysParamsDTO paramsDTO) {
|
||||||
return sysParamsService.updateParams(paramsDTO);
|
return sysParamsService.updateParams(paramsDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除参数
|
||||||
|
* @param code 参数code
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{code}")
|
||||||
|
public CzgResult<Boolean> deleteParams(@PathVariable String code) {
|
||||||
|
return sysParamsService.deleteParams(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数编码获取参数
|
||||||
|
* @param code 参数编码
|
||||||
|
* @return 参数
|
||||||
|
*/
|
||||||
|
@GetMapping("/code/{code}")
|
||||||
|
public CzgResult<SysParamsDTO> deleteCode(@PathVariable String code) {
|
||||||
|
return sysParamsService.getParamsByCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数类型获取参数
|
||||||
|
* @param type 参数类型
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/type/{type}")
|
||||||
|
public CzgResult<List<SysParamsDTO>> deleteType(@PathVariable String type) {
|
||||||
|
return sysParamsService.getParamsByType(Integer.valueOf(type));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,9 @@
|
|||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-redis</artifactId>
|
<artifactId>spring-data-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,41 +1,74 @@
|
|||||||
package com.czg.config;
|
package com.czg.config;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.*;
|
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author GYJoker
|
* @author GYJoker
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfig {
|
public class RedisConfig {
|
||||||
|
|
||||||
/**
|
@Resource
|
||||||
* redisTemplate相关配置
|
private RedisConnectionFactory factory;
|
||||||
* [@Role(BeanDefinition.ROLE_INFRASTRUCTURE)] 表明这个bean是完全后台模式,不需要被代理。
|
|
||||||
*
|
|
||||||
* @param factory Redis连接工厂类
|
|
||||||
* @return 返回配置项对象
|
|
||||||
*/
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||||
|
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(30))
|
||||||
|
// 设置缓存过期时间为30分钟
|
||||||
|
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||||
|
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
|
||||||
|
.disableCachingNullValues();
|
||||||
|
|
||||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
return RedisCacheManager.builder(redisConnectionFactory)
|
||||||
// 配置连接工厂
|
.cacheDefaults(cacheConfiguration)
|
||||||
template.setConnectionFactory(factory);
|
.build();
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate() {
|
||||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setConnectionFactory(factory);
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
@Bean
|
||||||
template.setKeySerializer(new StringRedisSerializer());
|
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
// 设置hash key 和value序列化模式
|
return redisTemplate.opsForHash();
|
||||||
template.setHashKeySerializer(new StringRedisSerializer());
|
}
|
||||||
// template.setHashValueSerializer(jacksonSerial);
|
|
||||||
template.setHashValueSerializer(new StringRedisSerializer());
|
|
||||||
template.setValueSerializer(new StringRedisSerializer());
|
|
||||||
template.afterPropertiesSet();
|
|
||||||
|
|
||||||
return template;
|
@Bean
|
||||||
|
public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
|
||||||
|
return redisTemplate.opsForValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForZSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import com.czg.group.UpdateGroup;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author GYJoker
|
* @author GYJoker
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
public class SysParamsDTO {
|
public class SysParamsDTO {
|
||||||
@NotNull(message = "id不能为空", groups = {UpdateGroup.class})
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank(message = "参数编码不能为空", groups = {UpdateGroup.class, InsertGroup.class})
|
@NotBlank(message = "参数编码不能为空", groups = {UpdateGroup.class, InsertGroup.class})
|
||||||
private String paramCode;
|
private String paramCode;
|
||||||
|
|||||||
@@ -2,19 +2,17 @@ package com.czg.service.system.entity;
|
|||||||
|
|
||||||
import com.mybatisflex.annotation.Column;
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实体类。
|
* 实体类。
|
||||||
*
|
*
|
||||||
@@ -32,15 +30,10 @@ public class SysParams implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
|
||||||
* ID
|
|
||||||
*/
|
|
||||||
@Id(keyType = KeyType.Auto)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数编码
|
* 参数编码
|
||||||
*/
|
*/
|
||||||
|
@Id
|
||||||
private String paramCode;
|
private String paramCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.czg.service.system.dto.SysParamsDTO;
|
|||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.czg.service.system.entity.SysParams;
|
import com.czg.service.system.entity.SysParams;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务层。
|
* 服务层。
|
||||||
*
|
*
|
||||||
@@ -18,12 +20,34 @@ public interface SysParamsService extends IService<SysParams> {
|
|||||||
* @param paramsDTO 参数
|
* @param paramsDTO 参数
|
||||||
* @return 新增结果
|
* @return 新增结果
|
||||||
*/
|
*/
|
||||||
CzgResult<Long> insertParams(SysParamsDTO paramsDTO);
|
CzgResult<String> insertParams(SysParamsDTO paramsDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改参数
|
* 修改参数
|
||||||
* @param paramsDTO 参数
|
* @param paramsDTO 参数
|
||||||
* @return 修改结果
|
* @return 修改结果
|
||||||
*/
|
*/
|
||||||
CzgResult<Long> updateParams(SysParamsDTO paramsDTO);
|
CzgResult<String> updateParams(SysParamsDTO paramsDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除参数
|
||||||
|
* @param code 参数code
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
CzgResult<Boolean> deleteParams(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数编码获取参数
|
||||||
|
* @param code 参数编码
|
||||||
|
* @return 参数
|
||||||
|
*/
|
||||||
|
CzgResult<SysParamsDTO> getParamsByCode(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数类型获取参数
|
||||||
|
* @param type 参数类型
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
CzgResult<List<SysParamsDTO>> getParamsByType(Integer type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.czg.service.system.service.impl;
|
package com.czg.service.system.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.service.system.dto.SysParamsDTO;
|
import com.czg.service.system.dto.SysParamsDTO;
|
||||||
@@ -8,8 +9,14 @@ import com.czg.service.system.mapper.SysParamsMapper;
|
|||||||
import com.czg.service.system.service.SysParamsService;
|
import com.czg.service.system.service.SysParamsService;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务层实现。
|
* 服务层实现。
|
||||||
*
|
*
|
||||||
@@ -17,10 +24,11 @@ import org.springframework.stereotype.Service;
|
|||||||
* @since 2025-02-07
|
* @since 2025-02-07
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@CacheConfig(cacheNames = "params")
|
||||||
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams> implements SysParamsService{
|
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams> implements SysParamsService{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CzgResult<Long> insertParams(SysParamsDTO paramsDTO) {
|
public CzgResult<String> insertParams(SysParamsDTO paramsDTO) {
|
||||||
// 查询 paramCode 是否存在
|
// 查询 paramCode 是否存在
|
||||||
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode()));
|
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode()));
|
||||||
if (sysParams != null) {
|
if (sysParams != null) {
|
||||||
@@ -39,14 +47,15 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
|
|||||||
|
|
||||||
save(sysParams);
|
save(sysParams);
|
||||||
|
|
||||||
return CzgResult.success(sysParams.getId());
|
return CzgResult.success(sysParams.getParamCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CzgResult<Long> updateParams(SysParamsDTO paramsDTO) {
|
@CacheEvict(key = "#paramsDTO.paramCode")
|
||||||
|
public CzgResult<String> updateParams(SysParamsDTO paramsDTO) {
|
||||||
// 查询 paramCode 是否存在
|
// 查询 paramCode 是否存在
|
||||||
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode())
|
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, paramsDTO.getParamCode())
|
||||||
.ne(SysParams::getId, paramsDTO.getId()));
|
.ne(SysParams::getParamCode, paramsDTO.getParamCode()));
|
||||||
if (sysParams != null) {
|
if (sysParams != null) {
|
||||||
return CzgResult.failure("参数编码已存在");
|
return CzgResult.failure("参数编码已存在");
|
||||||
}
|
}
|
||||||
@@ -54,14 +63,53 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
|
|||||||
Long userId = StpKit.ADMIN.getLoginId(1L);
|
Long userId = StpKit.ADMIN.getLoginId(1L);
|
||||||
|
|
||||||
// 修改参数
|
// 修改参数
|
||||||
sysParams = getById(paramsDTO.getId());
|
sysParams = getById(paramsDTO.getParamCode());
|
||||||
sysParams.setParamCode(paramsDTO.getParamCode())
|
|
||||||
.setParamValue(paramsDTO.getParamValue())
|
if (!sysParams.getParamCode().equals(paramsDTO.getParamCode())) {
|
||||||
|
return CzgResult.failure("参数编码不能修改");
|
||||||
|
}
|
||||||
|
sysParams.setParamValue(paramsDTO.getParamValue())
|
||||||
.setParamType(paramsDTO.getParamType())
|
.setParamType(paramsDTO.getParamType())
|
||||||
.setUpdateUserId(userId);
|
.setUpdateUserId(userId);
|
||||||
|
|
||||||
updateById(sysParams);
|
updateById(sysParams);
|
||||||
|
|
||||||
return CzgResult.success(sysParams.getId());
|
return CzgResult.success(sysParams.getParamCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(key = "#code")
|
||||||
|
public CzgResult<Boolean> deleteParams(String code) {
|
||||||
|
SysParams sysParams = getById(code);
|
||||||
|
if (sysParams == null) {
|
||||||
|
return CzgResult.failure("参数不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
removeById(code);
|
||||||
|
return CzgResult.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Cacheable(key = "#code")
|
||||||
|
public CzgResult<SysParamsDTO> getParamsByCode(String code) {
|
||||||
|
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
|
||||||
|
|
||||||
|
if (sysParams == null) {
|
||||||
|
return CzgResult.failure("参数不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
SysParamsDTO sysParamsDTO = BeanUtil.toBean(sysParams, SysParamsDTO.class);
|
||||||
|
|
||||||
|
return CzgResult.success(sysParamsDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CzgResult<List<SysParamsDTO>> getParamsByType(Integer type) {
|
||||||
|
List<SysParams> sysParamsList = list(new QueryWrapper().eq(SysParams::getParamType, type));
|
||||||
|
List<SysParamsDTO> sysParamsDTOList = new ArrayList<>();
|
||||||
|
for (SysParams sysParams : sysParamsList) {
|
||||||
|
sysParamsDTOList.add(BeanUtil.toBean(sysParams, SysParamsDTO.class));
|
||||||
|
}
|
||||||
|
return CzgResult.success(sysParamsDTOList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user