代码更新
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
package org.nl;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:JCccc
|
||||
* @Description:
|
||||
* @Date: created in 15:31 2019/6/12
|
||||
*/
|
||||
public class SnowflakeIdUtils {
|
||||
// ==============================Fields===========================================
|
||||
/**
|
||||
* 开始时间截 (2015-01-01)
|
||||
*/
|
||||
private final long twepoch = 1420041600000L;
|
||||
|
||||
/**
|
||||
* 机器id所占的位数
|
||||
*/
|
||||
private final long workerIdBits = 5L;
|
||||
|
||||
/**
|
||||
* 数据标识id所占的位数
|
||||
*/
|
||||
private final long datacenterIdBits = 5L;
|
||||
|
||||
/**
|
||||
* 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
|
||||
*/
|
||||
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
||||
|
||||
/**
|
||||
* 支持的最大数据标识id,结果是31
|
||||
*/
|
||||
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
|
||||
|
||||
/**
|
||||
* 序列在id中占的位数
|
||||
*/
|
||||
private final long sequenceBits = 12L;
|
||||
|
||||
/**
|
||||
* 机器ID向左移12位
|
||||
*/
|
||||
private final long workerIdShift = sequenceBits;
|
||||
|
||||
/**
|
||||
* 数据标识id向左移17位(12+5)
|
||||
*/
|
||||
private final long datacenterIdShift = sequenceBits + workerIdBits;
|
||||
|
||||
/**
|
||||
* 时间截向左移22位(5+5+12)
|
||||
*/
|
||||
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
|
||||
|
||||
/**
|
||||
* 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
|
||||
*/
|
||||
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
|
||||
|
||||
/**
|
||||
* 工作机器ID(0~31)
|
||||
*/
|
||||
private long workerId;
|
||||
|
||||
/**
|
||||
* 数据中心ID(0~31)
|
||||
*/
|
||||
private long datacenterId;
|
||||
|
||||
/**
|
||||
* 毫秒内序列(0~4095)
|
||||
*/
|
||||
private long sequence = 0L;
|
||||
|
||||
/**
|
||||
* 上次生成ID的时间截
|
||||
*/
|
||||
private long lastTimestamp = -1L;
|
||||
|
||||
//==============================Constructors=====================================
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param workerId 工作ID (0~31)
|
||||
* @param datacenterId 数据中心ID (0~31)
|
||||
*/
|
||||
public SnowflakeIdUtils(long workerId, long datacenterId) {
|
||||
if (workerId > maxWorkerId || workerId < 0) {
|
||||
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
|
||||
}
|
||||
if (datacenterId > maxDatacenterId || datacenterId < 0) {
|
||||
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
|
||||
}
|
||||
this.workerId = workerId;
|
||||
this.datacenterId = datacenterId;
|
||||
}
|
||||
|
||||
// ==============================Methods==========================================
|
||||
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全的)
|
||||
*
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
public synchronized long nextId() {
|
||||
long timestamp = timeGen();
|
||||
|
||||
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(
|
||||
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
//如果是同一时间生成的,则进行毫秒内序列
|
||||
if (lastTimestamp == timestamp) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
//毫秒内序列溢出
|
||||
if (sequence == 0) {
|
||||
//阻塞到下一个毫秒,获得新的时间戳
|
||||
timestamp = tilNextMillis(lastTimestamp);
|
||||
}
|
||||
}
|
||||
//时间戳改变,毫秒内序列重置
|
||||
else {
|
||||
sequence = 0L;
|
||||
}
|
||||
|
||||
//上次生成ID的时间截
|
||||
lastTimestamp = timestamp;
|
||||
|
||||
//移位并通过或运算拼到一起组成64位的ID
|
||||
return ((timestamp - twepoch) << timestampLeftShift) //
|
||||
| (datacenterId << datacenterIdShift) //
|
||||
| (workerId << workerIdShift) //
|
||||
| sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻塞到下一个毫秒,直到获得新的时间戳
|
||||
*
|
||||
* @param lastTimestamp 上次生成ID的时间截
|
||||
* @return 当前时间戳
|
||||
*/
|
||||
protected long tilNextMillis(long lastTimestamp) {
|
||||
long timestamp = timeGen();
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = timeGen();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回以毫秒为单位的当前时间
|
||||
*
|
||||
* @return 当前时间(毫秒)
|
||||
*/
|
||||
protected long timeGen() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
//==============================Test=============================================
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SnowflakeIdUtils idWorker = new SnowflakeIdUtils(3, 1);
|
||||
System.out.println(idWorker.nextId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.config;
|
||||
|
||||
import org.nl.modules.common.config.FileProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* WebMvcConfigurer
|
||||
*
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-30
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||
/** 文件配置 */
|
||||
private final FileProperties properties;
|
||||
|
||||
public ConfigurerAdapter(FileProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
FileProperties.ElPath path = properties.getPath();
|
||||
String avatarUtl = "file:" + path.getAvatar().replace("\\","/");
|
||||
String pathUtl = "file:" + path.getPath().replace("\\","/");
|
||||
registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,31 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ConversionServiceFactoryBean;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* WebMvcConfigurer
|
||||
*
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-30
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig extends WebMvcConfigurerAdapter {
|
||||
/**
|
||||
* 配置全局日期转换器
|
||||
*/
|
||||
@Bean
|
||||
@Autowired
|
||||
public ConversionService getConversionService(StringConverter dateConverter){
|
||||
ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
Set<Converter> converters = new HashSet<Converter>();
|
||||
|
||||
converters.add(dateConverter);
|
||||
|
||||
factoryBean.setConverters(converters);
|
||||
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.nl.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
|
||||
import com.fasterxml.jackson.databind.ser.std.NumberSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 超出 JS 最大最小值 处理
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@JacksonStdImpl
|
||||
public class BigNumberSerializer extends NumberSerializer {
|
||||
|
||||
/**
|
||||
* 根据 JS Number.MAX_SAFE_INTEGER 与 Number.MIN_SAFE_INTEGER 得来
|
||||
*/
|
||||
private static final long MAX_SAFE_INTEGER = 9007199254740991L;
|
||||
private static final long MIN_SAFE_INTEGER = -9007199254740991L;
|
||||
|
||||
/**
|
||||
* 提供实例
|
||||
*/
|
||||
public static final BigNumberSerializer INSTANCE = new BigNumberSerializer(Number.class);
|
||||
|
||||
public BigNumberSerializer(Class<? extends Number> rawType) {
|
||||
super(rawType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
// 超出范围 序列化位字符串
|
||||
if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) {
|
||||
super.serialize(value, gen, provider);
|
||||
} else {
|
||||
gen.writeString(value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.nl.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
|
||||
|
||||
/**
|
||||
* jackson 配置
|
||||
*
|
||||
* @author Lion Li
|
||||
* @author JohanChan
|
||||
* @ProjectName Demo
|
||||
* @Description 与前端交互时对实体类中Long类型的ID字段序列号
|
||||
* @time 2021/6/23 11:30
|
||||
*/
|
||||
/**
|
||||
* @author JohanChan
|
||||
* @ProjectName Demo
|
||||
* @Description 与前端交互时对实体类中Long类型的ID字段序列号
|
||||
* @time 2021/6/23 11:30
|
||||
*/
|
||||
|
||||
/**
|
||||
* 对象映射器:基于jackson将Java对象转为json,或者将json转为Java对象
|
||||
* 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象]
|
||||
* 从Java对象生成JSON的过程称为 [序列化Java对象到JSON]
|
||||
*/
|
||||
public class JacksonObjectMapper extends ObjectMapper {
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
||||
|
||||
public JacksonObjectMapper() {
|
||||
super();
|
||||
//收到未知属性时不报异常
|
||||
this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
//反序列化时,属性不存在的兼容处理
|
||||
this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
||||
SimpleModule simpleModule = new SimpleModule()
|
||||
//将BigInteger型数字转换成字符串,避免丢失精度
|
||||
.addSerializer(BigInteger.class, ToStringSerializer.instance)
|
||||
//将Long型数字转换成字符串,避免丢失精度
|
||||
.addSerializer(Long.class, ToStringSerializer.instance)
|
||||
//将Integer型数字转换成字符串
|
||||
.addSerializer(Integer.class, ToStringSerializer.instance)
|
||||
//将int型数字转换成字符串
|
||||
.addSerializer(int.class, ToStringSerializer.instance)
|
||||
//将long型数字转换成字符串
|
||||
.addSerializer(long.class, ToStringSerializer.instance)
|
||||
//序列化和反序列化日期格式
|
||||
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
||||
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
||||
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)))
|
||||
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
||||
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
||||
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));
|
||||
|
||||
|
||||
//注册功能模块 例如,可以添加自定义序列化器和反序列化器
|
||||
this.registerModule(simpleModule);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BaseDTO implements Serializable {
|
||||
|
||||
private String update_optname;
|
||||
|
||||
private Long update_optid;
|
||||
private Long update_id;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
@@ -68,7 +68,7 @@ public class QuartzJobServiceImpl implements QuartzJobService {
|
||||
resources.put("create_id", userId);
|
||||
resources.put("create_name", nickName);
|
||||
resources.put("create_time", now);
|
||||
resources.put("update_optid", userId);
|
||||
resources.put("update_id", userId);
|
||||
resources.put("update_optname", nickName);
|
||||
resources.put("update_time", now);
|
||||
quartzTab.insert(resources);
|
||||
@@ -124,7 +124,7 @@ public class QuartzJobServiceImpl implements QuartzJobService {
|
||||
throw new BadRequestException("子任务中不能添加当前任务ID");
|
||||
}
|
||||
}
|
||||
resources.put("update_optid", SecurityUtils.getCurrentUserId());
|
||||
resources.put("update_id", SecurityUtils.getCurrentUserId());
|
||||
resources.put("update_optname", SecurityUtils.getCurrentNickName());
|
||||
resources.put("update_time", DateUtil.now());
|
||||
jobTab.update(resources);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DictDto implements Serializable {
|
||||
private String create_time;
|
||||
|
||||
/** 修改人 */
|
||||
private Long update_optid;
|
||||
private Long update_id;
|
||||
|
||||
/** 修改人 */
|
||||
private String update_optname;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GridDto {
|
||||
/**
|
||||
* 更新人id
|
||||
*/
|
||||
private String update_optid;
|
||||
private String update_id;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GridFieldDto {
|
||||
/**
|
||||
* 更新人id
|
||||
*/
|
||||
private String update_optid;
|
||||
private String update_id;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ParamDto implements Serializable {
|
||||
|
||||
private Long create_id;
|
||||
|
||||
private Long update_optid;
|
||||
private Long update_id;
|
||||
|
||||
private String create_name;
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CodeDetailServiceImpl implements CodeDetailService {
|
||||
public void update(JSONObject json) {
|
||||
String now = DateUtil.now();
|
||||
json.put("update_time",now);
|
||||
json.put("update_optid", SecurityUtils.getCurrentUserId());
|
||||
json.put("update_id", SecurityUtils.getCurrentUserId());
|
||||
json.put("update_optname", SecurityUtils.getCurrentNickName());
|
||||
WQLObject.getWQLObject("sys_code_rule_detail").update(json);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
dictObj.put("para1", resources.getPara1());
|
||||
dictObj.put("para2", resources.getPara2());
|
||||
dictObj.put("para3", resources.getPara3());
|
||||
dictObj.put("update_optid", SecurityUtils.getCurrentUserId());
|
||||
dictObj.put("update_id", SecurityUtils.getCurrentUserId());
|
||||
dictObj.put("update_optname", SecurityUtils.getCurrentNickName());
|
||||
dictObj.put("update_time", DateUtil.now());
|
||||
wo.update(dictObj);
|
||||
@@ -89,7 +89,7 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
resources.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
resources.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
resources.setCreate_time(DateUtil.now());
|
||||
resources.setUpdate_optid(SecurityUtils.getCurrentUserId());
|
||||
resources.setUpdate_id(SecurityUtils.getCurrentUserId());
|
||||
resources.setUpdate_optname(SecurityUtils.getCurrentNickName());
|
||||
resources.setUpdate_time(DateUtil.now());
|
||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(resources));
|
||||
@@ -106,7 +106,7 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
}
|
||||
dto.setUpdate_time(DateUtil.now());
|
||||
dto.setUpdate_optname(SecurityUtils.getCurrentNickName());
|
||||
dto.setUpdate_optid(SecurityUtils.getCurrentUserId());
|
||||
dto.setUpdate_id(SecurityUtils.getCurrentUserId());
|
||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
|
||||
dictTab.update(json);
|
||||
// 清理缓存
|
||||
|
||||
@@ -81,7 +81,7 @@ public class DictService2Impl implements DictService2 {
|
||||
dto.setDict_id(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dto.setCreate_id(currentUserId);
|
||||
dto.setCreate_name(nickName);
|
||||
dto.setUpdate_optid(currentUserId);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
dto.setUpdate_time(date);
|
||||
dto.setCreate_time(date);
|
||||
@@ -102,7 +102,7 @@ public class DictService2Impl implements DictService2 {
|
||||
dictObj.put("code", dto.getCode());
|
||||
dictObj.put("name", dto.getName());
|
||||
dictObj.put("update_time", DateUtil.now());
|
||||
dictObj.put("update_optid", currentUserId);
|
||||
dictObj.put("update_id", currentUserId);
|
||||
dictObj.put("update_optname", nickName);
|
||||
wo.update(dictObj);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class GenCodeServiceImpl implements GenCodeService {
|
||||
json.put("code", form.get("code"));
|
||||
json.put("name", form.get("name"));
|
||||
json.put("create_id", currentUserId);
|
||||
json.put("update_optid", currentUserId);
|
||||
json.put("update_id", currentUserId);
|
||||
json.put("create_name", currentUsername);
|
||||
json.put("update_optname", currentUsername);
|
||||
json.put("create_time", now);
|
||||
@@ -89,7 +89,7 @@ public class GenCodeServiceImpl implements GenCodeService {
|
||||
throw new BadRequestException("该编码code已存在,请校验!");
|
||||
}
|
||||
String now = DateUtil.now();
|
||||
json.put("update_optid", SecurityUtils.getCurrentUserId());
|
||||
json.put("update_id", SecurityUtils.getCurrentUserId());
|
||||
json.put("update_time", now);
|
||||
json.put("update_optname", SecurityUtils.getCurrentUsername());
|
||||
WQLObject.getWQLObject("sys_code_rule").update(json);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GridFieldServiceImpl implements GridFieldService {
|
||||
|
||||
dto.setId(IdUtil.simpleUUID());
|
||||
dto.setCreate_id(uid.toString());
|
||||
dto.setUpdate_optid(uid.toString());
|
||||
dto.setUpdate_id(uid.toString());
|
||||
dto.setCreate_name(currentUsername);
|
||||
dto.setUpdate_optname(currentUsername);
|
||||
dto.setUpdate_time(now);
|
||||
@@ -80,7 +80,7 @@ public class GridFieldServiceImpl implements GridFieldService {
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_optid(SecurityUtils.getCurrentUserId().toString());
|
||||
dto.setUpdate_id(SecurityUtils.getCurrentUserId().toString());
|
||||
dto.setUpdate_optname(currentUsername);
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("sys_grid_field");
|
||||
@@ -118,7 +118,7 @@ public class GridFieldServiceImpl implements GridFieldService {
|
||||
fieldData.put("grid_id", grid_id);
|
||||
fieldData.put("id", IdUtil.simpleUUID());
|
||||
fieldData.put("create_id", currentUserId);
|
||||
fieldData.put("update_optid", currentUserId);
|
||||
fieldData.put("update_id", currentUserId);
|
||||
fieldData.put("create_name", currentUsername);
|
||||
fieldData.put("update_optname", currentUsername);
|
||||
fieldData.put("create_time", now);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class GridServiceImpl implements GridService {
|
||||
|
||||
dto.setId(IdUtil.simpleUUID());
|
||||
dto.setCreate_id(uid.toString());
|
||||
dto.setUpdate_optid(uid.toString());
|
||||
dto.setUpdate_id(uid.toString());
|
||||
dto.setCreate_name(currentUsername);
|
||||
dto.setUpdate_optname(currentUsername);
|
||||
dto.setUpdate_time(now);
|
||||
@@ -76,7 +76,7 @@ public class GridServiceImpl implements GridService {
|
||||
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_optid(SecurityUtils.getCurrentUserId().toString());
|
||||
dto.setUpdate_id(SecurityUtils.getCurrentUserId().toString());
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_optname(currentUsername);
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ParamServiceImpl implements ParamService {
|
||||
|
||||
dto.setId(IdUtil.simpleUUID());
|
||||
dto.setCreate_id(currentId);
|
||||
dto.setUpdate_optid(currentId);
|
||||
dto.setUpdate_id(currentId);
|
||||
dto.setCreate_name(currentUsername.getPresonName());
|
||||
dto.setUpdate_optname(currentUsername.getPresonName());
|
||||
dto.setUpdate_time(now);
|
||||
@@ -100,7 +100,7 @@ public class ParamServiceImpl implements ParamService {
|
||||
|
||||
String now = DateUtil.now();
|
||||
|
||||
dto.setUpdate_optid(StpUtil.getLoginIdAsLong());
|
||||
dto.setUpdate_id(StpUtil.getLoginIdAsLong());
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_optname(SecurityUtils.getCurrentNickName());
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class LocalStorage implements Serializable {
|
||||
private String create_time;
|
||||
|
||||
/** 修改人标识 */
|
||||
private String update_optid;
|
||||
private String update_id;
|
||||
|
||||
/** 修改人 */
|
||||
private String update_optname;
|
||||
@@ -67,7 +67,7 @@ public class LocalStorage implements Serializable {
|
||||
this.path = path;
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
this.create_id = this.update_optid = SecurityUtils.getCurrentUserId().toString();
|
||||
this.create_id = this.update_id = SecurityUtils.getCurrentUserId().toString();
|
||||
this.create_name = this.update_optname = SecurityUtils.getCurrentNickName();
|
||||
this.create_time = this.update_time = DateUtil.now();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class LocalStorageServiceImpl implements LocalStorageService {
|
||||
localStorage.put("type", type);
|
||||
localStorage.put("size", FileUtil.getSize(multipartFile.getSize()));
|
||||
localStorage.put("create_id", userId);
|
||||
localStorage.put("update_optid", userId);
|
||||
localStorage.put("update_id", userId);
|
||||
localStorage.put("create_name", nickName);
|
||||
localStorage.put("update_optname", nickName);
|
||||
localStorage.put("create_time", now);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DataPermissionDto implements Serializable {
|
||||
/**
|
||||
* 修改人标识
|
||||
*/
|
||||
private Long update_optid;
|
||||
private Long update_id;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
|
||||
@@ -81,7 +81,7 @@ public class DataPermissionServiceImpl implements DataPermissionService {
|
||||
dto.setPermission_id(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dto.setCreate_id(currentUserId);
|
||||
dto.setCreate_name(nickName);
|
||||
dto.setUpdate_optid(currentUserId);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
dto.setUpdate_time(now);
|
||||
dto.setCreate_time(now);
|
||||
@@ -102,7 +102,7 @@ public class DataPermissionServiceImpl implements DataPermissionService {
|
||||
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_optid(currentUserId);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
|
||||
@@ -122,7 +122,7 @@ public class DataPermissionServiceImpl implements DataPermissionService {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("permission_id", String.valueOf(permission_id));
|
||||
param.put("is_delete", "1");
|
||||
param.put("update_optid", currentUserId);
|
||||
param.put("update_id", currentUserId);
|
||||
param.put("update_optname", nickName);
|
||||
param.put("update_time", now);
|
||||
wo.update(param);
|
||||
|
||||
@@ -2,18 +2,24 @@ package org.nl.system.controller.menu;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.system.service.dto.MenuDto;
|
||||
import org.nl.system.service.menu.ISysMenuService;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -33,8 +39,85 @@ public class SysMenuController {
|
||||
@ApiOperation("查询菜单")
|
||||
@SaCheckPermission("menu:list")
|
||||
public ResponseEntity<Object> pageQuery(@RequestParam Map param, Pageable page) throws Exception {
|
||||
return new ResponseEntity<>(baseService.queryAll(param),HttpStatus.OK);
|
||||
TableDataInfo data = TableDataInfo.build(baseService.queryAll(param));
|
||||
return new ResponseEntity<>(data, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation("返回全部的菜单")
|
||||
@GetMapping(value = "/lazy")//新增时候点击
|
||||
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
||||
public ResponseEntity<Object> query(@RequestParam Long pid) {
|
||||
return new ResponseEntity<>(baseService.getMenus(pid), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@SaCheckPermission("menu:list")
|
||||
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
|
||||
Set<MenuDto> menuDtos = new LinkedHashSet<>();
|
||||
if (CollectionUtil.isNotEmpty(ids)) {
|
||||
for (Long id : ids) {
|
||||
MenuDto menuDto = baseService.doToDto(baseService.findById(id));
|
||||
menuDtos.addAll(baseService.getSuperior(menuDto, new ArrayList<>()));
|
||||
}
|
||||
return new ResponseEntity<>(baseService.buildTree(new ArrayList<>(menuDtos)), HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(baseService.getMenus(null), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/build")
|
||||
@ApiOperation("根据用户获取菜单")
|
||||
public ResponseEntity<Object> buildMenus() {
|
||||
List<MenuDto> menuDtoList = baseService.findByUser(SecurityUtils.getCurrentUserId());
|
||||
List<MenuDto> menuDtos = baseService.buildTree(menuDtoList);
|
||||
return new ResponseEntity<>(baseService.buildMenus(menuDtos), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
||||
@GetMapping(value = "/child")
|
||||
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
||||
public ResponseEntity<Object> child(@RequestParam Long id) {
|
||||
Set<SysMenu> menuSet = new HashSet<>();
|
||||
List<SysMenu> menuList = baseService.getMenus(id);
|
||||
menuSet.add(baseService.findById(id));
|
||||
menuSet = baseService.getChildMenus(menuList, menuSet);
|
||||
Set<Long> ids = menuSet.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
|
||||
return new ResponseEntity<>(ids, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增菜单")
|
||||
@ApiOperation("新增菜单")
|
||||
@PostMapping
|
||||
@SaCheckPermission("menu:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SysMenu resources) {
|
||||
baseService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改菜单")
|
||||
@ApiOperation("修改菜单")
|
||||
@PutMapping
|
||||
@SaCheckPermission("menu:edit")
|
||||
public ResponseEntity<Object> update(@RequestBody SysMenu resources) {
|
||||
baseService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除菜单")
|
||||
@ApiOperation("删除菜单")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("menu:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||
Set<SysMenu> menuSet = new HashSet<>();
|
||||
for (Long id : ids) {
|
||||
//获取所有子节点
|
||||
List<SysMenu> menuList = baseService.getMenus(id);
|
||||
menuSet.add(baseService.findById(id));
|
||||
menuSet = baseService.getChildMenus(menuList, menuSet);
|
||||
}
|
||||
baseService.delete(menuSet);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.dto.ParamQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -72,11 +70,11 @@ class SysParamController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/getValueByCode")
|
||||
@PostMapping("/getValueByCode/{code}")
|
||||
@Log("根据编码获取值")
|
||||
@ApiOperation("根据编码获取值")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> getValueByCode(@RequestBody String code) {
|
||||
public ResponseEntity<Object> getValueByCode(@PathVariable String code) {
|
||||
return new ResponseEntity<>(paramService.findByCode(code), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?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="org.nl.system.service.dict.dao.mapper.SysDictMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.nl.system.service.menu;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.modules.system.domain.vo.MenuVo;
|
||||
import org.nl.modules.system.service.dto.MenuDto;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -25,13 +27,77 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
*/
|
||||
List<MenuDto> queryAll(Map<String, Object> param) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 根据ID获取同级与上级数据
|
||||
* @param menuDto /
|
||||
* @param menus /
|
||||
* @return /
|
||||
*/
|
||||
List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
SysMenu findById(long id);
|
||||
List<SysMenu> findByPid(long pid);
|
||||
List<SysMenu> findByPidIsNull();
|
||||
|
||||
/**
|
||||
* 获取所有子节点,包含自身ID
|
||||
*
|
||||
* @param menuList /
|
||||
* @param menuSet /
|
||||
* @return /
|
||||
*/
|
||||
Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param menu /
|
||||
*/
|
||||
void create(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param menuSet /
|
||||
*/
|
||||
void delete(Set<SysMenu> menuSet);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param menu /
|
||||
*/
|
||||
void update(SysMenu menu);
|
||||
|
||||
|
||||
List<MenuDto> findByUser(Long userId);
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param menuDtos /
|
||||
* @return /
|
||||
*/
|
||||
List<MenuVo> buildMenus(List<MenuDto> menuDtos);
|
||||
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
* @param menuDtos 原始数据
|
||||
* @return /
|
||||
*/
|
||||
List<MenuDto> buildTree(List<MenuDto> menuDtos);
|
||||
|
||||
/**
|
||||
* 懒加载菜单数据
|
||||
*
|
||||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
List<MenuDto> getMenus(Long pid);
|
||||
List<SysMenu> getMenus(Long pid);
|
||||
|
||||
/**
|
||||
* @param sysMenu
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package org.nl.system.service.menu.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 Mapper 接口
|
||||
@@ -12,5 +16,18 @@ import org.nl.system.service.menu.dao.SysMenu;
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
@Select("select * from sys_menu where pid is null")
|
||||
List<SysMenu> findByPidIsNull();
|
||||
|
||||
@Select("select * from sys_menu where pid = #{pid}")
|
||||
List<SysMenu> findByPid(@Param("pid") Long pid);
|
||||
|
||||
/**
|
||||
* 根据用户获取菜单
|
||||
*
|
||||
* @param userId 用户标识
|
||||
* @return 当前用户拥有的菜单列表
|
||||
*/
|
||||
List<SysMenu> findByUser(@Param("userId") Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,20 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.menu.dao.mapper.SysMenuMapper">
|
||||
|
||||
<select id="findByUser" resultType="org.nl.system.service.menu.dao.SysMenu">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_menu
|
||||
WHERE
|
||||
type != '2'
|
||||
AND menu_id IN (
|
||||
SELECT
|
||||
menu_id
|
||||
FROM
|
||||
sys_roles_menus
|
||||
WHERE
|
||||
role_id IN ( SELECT role_id FROM sys_users_roles WHERE 1 = 1 and user_id=#{userId} ))
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package org.nl.system.service.menu.impl;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
||||
import org.nl.modules.system.domain.vo.MenuVo;
|
||||
import org.nl.modules.system.service.dto.MenuDto;
|
||||
import org.nl.system.service.menu.ISysMenuService;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -28,20 +34,225 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
|
||||
@Override
|
||||
public List<MenuDto> queryAll(Map<String, Object> param) throws Exception {
|
||||
Long pid = MapUtil.getLong(param, "pid");
|
||||
/*List<SysMenu> sysMenus = baseMapper.selectList(null);
|
||||
List<MenuDto> menus = sysMenus.stream().map(menu -> doToDto(menu)).collect(Collectors.toList());*/
|
||||
return getMenus(null);
|
||||
return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> getMenus(Long pid) {
|
||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus) {
|
||||
if (menuDto.getPid() == null) {
|
||||
menus.addAll(this.findByPidIsNull());
|
||||
return menus.stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
menus.addAll(baseMapper.findByPid(menuDto.getPid()));
|
||||
|
||||
return getSuperior(this.doToDto(findById(menuDto.getPid())), menus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysMenu findById(long id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByPid(long pid) {
|
||||
return baseMapper.findByPid(pid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByPidIsNull() {
|
||||
return baseMapper.findByPidIsNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet) {
|
||||
for (SysMenu menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SysMenu> menus = this.findByPid(menu.getMenuId());
|
||||
if (menus != null && menus.size() != 0) {
|
||||
getChildMenus(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void create(SysMenu resources) {
|
||||
|
||||
if (resources.getPid().equals(0L)) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
if (resources.getIFrame()) {
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
baseMapper.insert(resources);
|
||||
// 计算子节点数目
|
||||
resources.setSubCount(0);
|
||||
// 更新父节点菜单数目
|
||||
updateSubCnt(resources.getPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<SysMenu> menuSet) {
|
||||
for (SysMenu menu : menuSet) {
|
||||
//解绑菜单
|
||||
// roleService.untiedMenu(menu.getId());
|
||||
baseMapper.deleteById(menu.getMenuId());
|
||||
updateSubCnt(menu.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(SysMenu resources) {
|
||||
if (resources.getMenuId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
SysMenu menu = baseMapper.selectById(resources.getMenuId());
|
||||
if (resources.getIFrame()) {
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
if (resources.getPid().equals(0L)) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
|
||||
// 记录的父节点ID
|
||||
Long oldPid = menu.getPid();
|
||||
Long newPid = resources.getPid();
|
||||
menu.setTitle(resources.getTitle());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIFrame(resources.getIFrame());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setMenuSort(resources.getMenuSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
baseMapper.updateById(menu);
|
||||
// 计算父级菜单节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算菜单子节点数目
|
||||
*
|
||||
* @param menuId
|
||||
*/
|
||||
private void updateSubCnt(Long menuId) {
|
||||
if (menuId != null) {
|
||||
int count = baseMapper.findByPid(menuId).size();
|
||||
SysMenu sysMenu = baseMapper.selectById(menuId);
|
||||
if (ObjectUtil.isEmpty(sysMenu)) return;
|
||||
sysMenu.setSubCount(count);
|
||||
baseMapper.updateById(sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> findByUser(Long userId) {
|
||||
return baseMapper.findByUser(userId).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
|
||||
List<MenuVo> list = new LinkedList<>();
|
||||
menuDtos.forEach(menuDTO -> {
|
||||
if (menuDTO != null) {
|
||||
List<MenuDto> menuDtoList = menuDTO.getChildren();
|
||||
MenuVo menuVo = new MenuVo();
|
||||
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getTitle());
|
||||
// 一级目录需要加斜杠,不然会报警告
|
||||
menuVo.setPath(ObjectUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menuDTO.getIFrame()) {
|
||||
if (ObjectUtil.isEmpty(menuDTO.getPid())) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||
} else if (!ObjectUtil.isEmpty(menuDTO.getPid()) && menuDTO.getType() == 0) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
|
||||
|
||||
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
||||
menuVo.setComponent(menuDTO.getComponent());
|
||||
}
|
||||
}
|
||||
menuVo.setMeta(new MenuMetaVo(menuDTO.getTitle(), menuDTO.getIcon(), !menuDTO.getCache()));
|
||||
if (menuDtoList != null && menuDtoList.size() != 0) {
|
||||
menuVo.setAlwaysShow(true);
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenus(menuDtoList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if (ObjectUtil.isEmpty(menuDTO.getPid())) {
|
||||
MenuVo menuVo1 = new MenuVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
if (!menuDTO.getIFrame()) {
|
||||
menuVo1.setPath("index");
|
||||
menuVo1.setName(menuVo.getName());
|
||||
menuVo1.setComponent(menuVo.getComponent());
|
||||
} else {
|
||||
menuVo1.setPath(menuDTO.getPath());
|
||||
}
|
||||
menuVo.setName(null);
|
||||
menuVo.setMeta(null);
|
||||
menuVo.setComponent("Layout");
|
||||
List<MenuVo> list1 = new ArrayList<>();
|
||||
list1.add(menuVo1);
|
||||
menuVo.setChildren(list1);
|
||||
}
|
||||
list.add(menuVo);
|
||||
}
|
||||
}
|
||||
);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
|
||||
List<MenuDto> trees = new ArrayList<>();
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (MenuDto menuDTO : menuDtos) {
|
||||
if (menuDTO.getPid() == null) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
for (MenuDto it : menuDtos) {
|
||||
if (menuDTO.getMenuId().equals(it.getPid())) {
|
||||
if (menuDTO.getChildren() == null) {
|
||||
menuDTO.setChildren(new ArrayList<>());
|
||||
}
|
||||
menuDTO.getChildren().add(it);
|
||||
ids.add(it.getMenuId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (trees.size() == 0) {
|
||||
trees = menuDtos.stream().filter(s -> !ids.contains(s.getMenuId())).collect(Collectors.toList());
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> getMenus(Long pid) {
|
||||
QueryWrapper<SysMenu> queryWrapper;
|
||||
if (pid != null && !pid.equals(0L)) {
|
||||
queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid);
|
||||
} else {
|
||||
queryWrapper = new QueryWrapper<SysMenu>().isNull("pid");
|
||||
}
|
||||
return baseMapper.selectList(queryWrapper).stream().map(menu -> doToDto(menu)).collect(Collectors.toList());
|
||||
return baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
@@ -14,9 +13,7 @@ import org.nl.modules.tools.MapOf;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.dao.mapper.SysParamMapper;
|
||||
import org.nl.system.service.param.dto.ParamQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -82,7 +79,10 @@ public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, Param> impl
|
||||
|
||||
@Override
|
||||
public Param findByCode(String code) {
|
||||
List<Param> paramList = paramMapper.selectByMap(MapOf.of("code", code));
|
||||
return paramList.get(0);
|
||||
// List<Param> paramList = paramMapper.selectByMap(MapOf.of("code", code));
|
||||
QueryWrapper<Param> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.eq("code",code);
|
||||
Param param = paramMapper.selectOne(queryWrapper);
|
||||
return param;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -13,8 +12,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
import org.nl.system.service.role.dao.mapper.SysRoleMapper;
|
||||
@@ -44,7 +41,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
LambdaQueryWrapper<SysRole> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(blurry), SysRole::getName, blurry);
|
||||
IPage<SysRole> pages = new Page<>(page.getPage(), page.getSize());
|
||||
roleMapper.selectPage(pages, lam);
|
||||
IPage<SysRole> sysRoleIPage = roleMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.nl.system.service.user.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,5 +17,8 @@ import java.util.List;
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
|
||||
List<SysUser> selectAl();
|
||||
@Select("select * from sys_user")
|
||||
List<SysUser> select1();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||
dto.set${pkChangeColName ? cap_first }(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dto.setCreate_id(currentUserId);
|
||||
dto.setCreate_name(nickName);
|
||||
dto.setUpdate_optid(currentUserId);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
dto.setUpdate_time(now);
|
||||
dto.setCreate_time(now);
|
||||
@@ -101,7 +101,7 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_optid(currentUserId);
|
||||
dto.setUpdate_id(currentUserId);
|
||||
dto.setUpdate_optname(nickName);
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("${tableName}");
|
||||
@@ -121,7 +121,7 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("${pkChangeColName}", String.valueOf(${pkChangeColName}));
|
||||
param.put("is_delete", "1");
|
||||
param.put("update_optid", currentUserId);
|
||||
param.put("update_id", currentUserId);
|
||||
param.put("update_optname", nickName);
|
||||
param.put("update_time", now);
|
||||
wo.update(param);
|
||||
|
||||
Reference in New Issue
Block a user