已重命名56个文件
已添加142个文件
已删除241个文件
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| | | import com.se.common.swagger.annotation.EnableCustomSwagger2; |
| | | |
| | | /** |
| | | * æä»¶æå¡ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableCustomSwagger2 |
| | | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) |
| | | public class SeFileApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeFileApplication.class, args); |
| | | System.out.println(" æä»¶æ¨¡åå¯å¨æå "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.config; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import io.minio.MinioClient; |
| | | |
| | | /** |
| | | * Minio é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | @ConfigurationProperties(prefix = "minio") |
| | | public class MinioConfig |
| | | { |
| | | /** |
| | | * æå¡å°å |
| | | */ |
| | | private String url; |
| | | |
| | | /** |
| | | * ç¨æ·å |
| | | */ |
| | | private String accessKey; |
| | | |
| | | /** |
| | | * å¯ç |
| | | */ |
| | | private String secretKey; |
| | | |
| | | /** |
| | | * å卿¡¶åç§° |
| | | */ |
| | | private String bucketName; |
| | | |
| | | public String getUrl() |
| | | { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) |
| | | { |
| | | this.url = url; |
| | | } |
| | | |
| | | public String getAccessKey() |
| | | { |
| | | return accessKey; |
| | | } |
| | | |
| | | public void setAccessKey(String accessKey) |
| | | { |
| | | this.accessKey = accessKey; |
| | | } |
| | | |
| | | public String getSecretKey() |
| | | { |
| | | return secretKey; |
| | | } |
| | | |
| | | public void setSecretKey(String secretKey) |
| | | { |
| | | this.secretKey = secretKey; |
| | | } |
| | | |
| | | public String getBucketName() |
| | | { |
| | | return bucketName; |
| | | } |
| | | |
| | | public void setBucketName(String bucketName) |
| | | { |
| | | this.bucketName = bucketName; |
| | | } |
| | | |
| | | @Bean |
| | | public MinioClient getMinioClient() |
| | | { |
| | | return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.config; |
| | | |
| | | import java.io.File; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.CorsRegistry; |
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | /** |
| | | * éç¨æ å°é
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | public class ResourcesConfig implements WebMvcConfigurer |
| | | { |
| | | /** |
| | | * ä¸ä¼ æä»¶åå¨å¨æ¬å°çæ ¹è·¯å¾ |
| | | */ |
| | | @Value("${file.path}") |
| | | private String localFilePath; |
| | | |
| | | /** |
| | | * èµæºæ å°è·¯å¾ åç¼ |
| | | */ |
| | | @Value("${file.prefix}") |
| | | public String localFilePrefix; |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) |
| | | { |
| | | /** æ¬å°æä»¶ä¸ä¼ è·¯å¾ */ |
| | | registry.addResourceHandler(localFilePrefix + "/**") |
| | | .addResourceLocations("file:" + localFilePath + File.separator); |
| | | } |
| | | |
| | | /** |
| | | * å¼å¯è·¨å |
| | | */ |
| | | @Override |
| | | public void addCorsMappings(CorsRegistry registry) { |
| | | // 设置å
许跨åçè·¯ç± |
| | | registry.addMapping(localFilePrefix + "/**") |
| | | // 设置å
许跨å请æ±çåå |
| | | .allowedOrigins("*") |
| | | // 设置å
è®¸çæ¹æ³ |
| | | .allowedMethods("GET"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.controller; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.se.common.core.domain.R; |
| | | import com.se.common.core.utils.file.FileUtils; |
| | | import com.se.file.service.ISysFileService; |
| | | import com.se.system.api.domain.SysFile; |
| | | |
| | | /** |
| | | * æä»¶è¯·æ±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | public class SysFileController |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(SysFileController.class); |
| | | |
| | | @Autowired |
| | | private ISysFileService sysFileService; |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ è¯·æ± |
| | | */ |
| | | @PostMapping("upload") |
| | | public R<SysFile> upload(MultipartFile file) |
| | | { |
| | | try |
| | | { |
| | | // ä¸ä¼ å¹¶è¿å访é®å°å |
| | | String url = sysFileService.uploadFile(file); |
| | | SysFile sysFile = new SysFile(); |
| | | sysFile.setName(FileUtils.getName(url)); |
| | | sysFile.setUrl(url); |
| | | return R.ok(sysFile); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("ä¸ä¼ æä»¶å¤±è´¥", e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.service; |
| | | |
| | | import java.io.InputStream; |
| | | import com.alibaba.nacos.common.utils.IoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.github.tobato.fastdfs.domain.fdfs.StorePath; |
| | | import com.github.tobato.fastdfs.service.FastFileStorageClient; |
| | | import com.se.common.core.utils.file.FileTypeUtils; |
| | | |
| | | /** |
| | | * FastDFS æä»¶åå¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class FastDfsSysFileServiceImpl implements ISysFileService |
| | | { |
| | | /** |
| | | * ååææ¬æºè®¿é®å°å |
| | | */ |
| | | @Value("${fdfs.domain}") |
| | | public String domain; |
| | | |
| | | @Autowired |
| | | private FastFileStorageClient storageClient; |
| | | |
| | | /** |
| | | * FastDfsæä»¶ä¸ä¼ æ¥å£ |
| | | * |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @return 访é®å°å |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public String uploadFile(MultipartFile file) throws Exception |
| | | { |
| | | InputStream inputStream = file.getInputStream(); |
| | | StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), |
| | | FileTypeUtils.getExtension(file), null); |
| | | IoUtils.closeQuietly(inputStream); |
| | | return domain + "/" + storePath.getFullPath(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.service; |
| | | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ æ¥å£ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysFileService |
| | | { |
| | | /** |
| | | * æä»¶ä¸ä¼ æ¥å£ |
| | | * |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @return 访é®å°å |
| | | * @throws Exception |
| | | */ |
| | | public String uploadFile(MultipartFile file) throws Exception; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.service; |
| | | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.se.file.utils.FileUploadUtils; |
| | | |
| | | /** |
| | | * æ¬å°æä»¶åå¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Primary |
| | | @Service |
| | | public class LocalSysFileServiceImpl implements ISysFileService |
| | | { |
| | | /** |
| | | * èµæºæ å°è·¯å¾ åç¼ |
| | | */ |
| | | @Value("${file.prefix}") |
| | | public String localFilePrefix; |
| | | |
| | | /** |
| | | * ååææ¬æºè®¿é®å°å |
| | | */ |
| | | @Value("${file.domain}") |
| | | public String domain; |
| | | |
| | | /** |
| | | * ä¸ä¼ æä»¶åå¨å¨æ¬å°çæ ¹è·¯å¾ |
| | | */ |
| | | @Value("${file.path}") |
| | | private String localFilePath; |
| | | |
| | | /** |
| | | * æ¬å°æä»¶ä¸ä¼ æ¥å£ |
| | | * |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @return 访é®å°å |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public String uploadFile(MultipartFile file) throws Exception |
| | | { |
| | | String name = FileUploadUtils.upload(localFilePath, file); |
| | | String url = domain + localFilePrefix + name; |
| | | return url; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.service; |
| | | |
| | | import java.io.InputStream; |
| | | |
| | | import com.se.file.config.MinioConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.alibaba.nacos.common.utils.IoUtils; |
| | | import com.se.file.utils.FileUploadUtils; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectArgs; |
| | | |
| | | /** |
| | | * Minio æä»¶åå¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class MinioSysFileServiceImpl implements ISysFileService |
| | | { |
| | | @Autowired |
| | | private MinioConfig minioConfig; |
| | | |
| | | @Autowired |
| | | private MinioClient client; |
| | | |
| | | /** |
| | | * Minioæä»¶ä¸ä¼ æ¥å£ |
| | | * |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @return 访é®å°å |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public String uploadFile(MultipartFile file) throws Exception |
| | | { |
| | | String fileName = FileUploadUtils.extractFilename(file); |
| | | InputStream inputStream = file.getInputStream(); |
| | | PutObjectArgs args = PutObjectArgs.builder() |
| | | .bucket(minioConfig.getBucketName()) |
| | | .object(fileName) |
| | | .stream(inputStream, file.getSize(), -1) |
| | | .contentType(file.getContentType()) |
| | | .build(); |
| | | client.putObject(args); |
| | | IoUtils.closeQuietly(inputStream); |
| | | return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.file.utils; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Paths; |
| | | import java.util.Objects; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.se.common.core.exception.file.FileException; |
| | | import com.se.common.core.exception.file.FileNameLengthLimitExceededException; |
| | | import com.se.common.core.exception.file.FileSizeLimitExceededException; |
| | | import com.se.common.core.exception.file.InvalidExtensionException; |
| | | import com.se.common.core.utils.DateUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.file.FileTypeUtils; |
| | | import com.se.common.core.utils.file.MimeTypeUtils; |
| | | import com.se.common.core.utils.uuid.Seq; |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ å·¥å
·ç±» |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class FileUploadUtils |
| | | { |
| | | /** |
| | | * é»è®¤å¤§å° 50M |
| | | */ |
| | | public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024L; |
| | | |
| | | /** |
| | | * é»è®¤çæä»¶åæå¤§é¿åº¦ 100 |
| | | */ |
| | | public static final int DEFAULT_FILE_NAME_LENGTH = 100; |
| | | |
| | | /** |
| | | * æ ¹æ®æä»¶è·¯å¾ä¸ä¼ |
| | | * |
| | | * @param baseDir ç¸å¯¹åºç¨çåºç®å½ |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @return æä»¶åç§° |
| | | * @throws IOException |
| | | */ |
| | | public static final String upload(String baseDir, MultipartFile file) throws IOException |
| | | { |
| | | try |
| | | { |
| | | return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | } |
| | | catch (FileException fe) |
| | | { |
| | | throw new IOException(fe.getDefaultMessage(), fe); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new IOException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ |
| | | * |
| | | * @param baseDir ç¸å¯¹åºç¨çåºç®å½ |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @param allowedExtension ä¸ä¼ æä»¶ç±»å |
| | | * @return è¿åä¸ä¼ æåçæä»¶å |
| | | * @throws FileSizeLimitExceededException 妿è¶
åºæå¤§å¤§å° |
| | | * @throws FileNameLengthLimitExceededException æä»¶åå¤ªé¿ |
| | | * @throws IOException æ¯å¦è¯»åæä»¶åºéæ¶ |
| | | * @throws InvalidExtensionException æä»¶æ ¡éªå¼å¸¸ |
| | | */ |
| | | public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) |
| | | throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, |
| | | InvalidExtensionException |
| | | { |
| | | int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length(); |
| | | if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) |
| | | { |
| | | throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); |
| | | } |
| | | |
| | | assertAllowed(file, allowedExtension); |
| | | |
| | | String fileName = extractFilename(file); |
| | | |
| | | String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); |
| | | file.transferTo(Paths.get(absPath)); |
| | | return getPathFileName(fileName); |
| | | } |
| | | |
| | | /** |
| | | * ç¼ç æä»¶å |
| | | */ |
| | | public static final String extractFilename(MultipartFile file) |
| | | { |
| | | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| | | FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), FileTypeUtils.getExtension(file)); |
| | | } |
| | | |
| | | private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException |
| | | { |
| | | File desc = new File(uploadDir + File.separator + fileName); |
| | | |
| | | if (!desc.exists()) |
| | | { |
| | | if (!desc.getParentFile().exists()) |
| | | { |
| | | desc.getParentFile().mkdirs(); |
| | | } |
| | | } |
| | | return desc.isAbsolute() ? desc : desc.getAbsoluteFile(); |
| | | } |
| | | |
| | | private static final String getPathFileName(String fileName) throws IOException |
| | | { |
| | | String pathFileName = "/" + fileName; |
| | | return pathFileName; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶å¤§å°æ ¡éª |
| | | * |
| | | * @param file ä¸ä¼ çæä»¶ |
| | | * @throws FileSizeLimitExceededException 妿è¶
åºæå¤§å¤§å° |
| | | * @throws InvalidExtensionException æä»¶æ ¡éªå¼å¸¸ |
| | | */ |
| | | public static final void assertAllowed(MultipartFile file, String[] allowedExtension) |
| | | throws FileSizeLimitExceededException, InvalidExtensionException |
| | | { |
| | | long size = file.getSize(); |
| | | if (size > DEFAULT_MAX_SIZE) |
| | | { |
| | | throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024); |
| | | } |
| | | |
| | | String fileName = file.getOriginalFilename(); |
| | | String extension = FileTypeUtils.getExtension(file); |
| | | if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) |
| | | { |
| | | if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) |
| | | { |
| | | throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension, |
| | | fileName); |
| | | } |
| | | else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) |
| | | { |
| | | throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension, |
| | | fileName); |
| | | } |
| | | else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) |
| | | { |
| | | throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, |
| | | fileName); |
| | | } |
| | | else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) |
| | | { |
| | | throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension, |
| | | fileName); |
| | | } |
| | | else |
| | | { |
| | | throw new InvalidExtensionException(allowedExtension, extension, fileName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 夿MIMEç±»åæ¯å¦æ¯å
许çMIMEç±»å |
| | | * |
| | | * @param extension ä¸ä¼ æä»¶ç±»å |
| | | * @param allowedExtension å
许ä¸ä¼ æä»¶ç±»å |
| | | * @return true/false |
| | | */ |
| | | public static final boolean isAllowedExtension(String extension, String[] allowedExtension) |
| | | { |
| | | for (String str : allowedExtension) |
| | | { |
| | | if (str.equalsIgnoreCase(extension)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import com.se.common.security.annotation.EnableCustomConfig; |
| | | import com.se.common.security.annotation.EnableRyFeignClients; |
| | | import com.se.common.swagger.annotation.EnableCustomSwagger2; |
| | | |
| | | /** |
| | | * 代ç çæ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableCustomConfig |
| | | @EnableCustomSwagger2 |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | public class SeGenApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeGenApplication.class, args); |
| | | System.out.println("(â¥â â¿â )ï¾ï¾ 代ç çææ¨¡åå¯å¨æå á(´ڡ`á)ï¾ \n" + |
| | | " .-------. ____ __ \n" + |
| | | " | _ _ \\ \\ \\ / / \n" + |
| | | " | ( ' ) | \\ _. / ' \n" + |
| | | " |(_ o _) / _( )_ .' \n" + |
| | | " | (_,_).' __ ___(_ o _)' \n" + |
| | | " | |\\ \\ | || |(_,_)' \n" + |
| | | " | | \\ `' /| `-' / \n" + |
| | | " | | \\ / \\ / \n" + |
| | | " ''-' `'-' `-..-' "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.config; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 代ç çæç¸å
³é
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | @ConfigurationProperties(prefix = "gen") |
| | | public class GenConfig |
| | | { |
| | | /** ä½è
*/ |
| | | public static String author; |
| | | |
| | | /** çæå
è·¯å¾ */ |
| | | public static String packageName; |
| | | |
| | | /** èªå¨å»é¤è¡¨åç¼ï¼é»è®¤æ¯false */ |
| | | public static boolean autoRemovePre; |
| | | |
| | | /** 表åç¼(ç±»åä¸ä¼å
å«è¡¨åç¼) */ |
| | | public static String tablePrefix; |
| | | |
| | | public static String getAuthor() |
| | | { |
| | | return author; |
| | | } |
| | | |
| | | public void setAuthor(String author) |
| | | { |
| | | GenConfig.author = author; |
| | | } |
| | | |
| | | public static String getPackageName() |
| | | { |
| | | return packageName; |
| | | } |
| | | |
| | | public void setPackageName(String packageName) |
| | | { |
| | | GenConfig.packageName = packageName; |
| | | } |
| | | |
| | | public static boolean getAutoRemovePre() |
| | | { |
| | | return autoRemovePre; |
| | | } |
| | | |
| | | public void setAutoRemovePre(boolean autoRemovePre) |
| | | { |
| | | GenConfig.autoRemovePre = autoRemovePre; |
| | | } |
| | | |
| | | public static String getTablePrefix() |
| | | { |
| | | return tablePrefix; |
| | | } |
| | | |
| | | public void setTablePrefix(String tablePrefix) |
| | | { |
| | | GenConfig.tablePrefix = tablePrefix; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.gen.domain.GenTableColumn; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.text.Convert; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.gen.domain.GenTable; |
| | | import com.se.gen.service.IGenTableColumnService; |
| | | import com.se.gen.service.IGenTableService; |
| | | |
| | | /** |
| | | * 代ç çæ æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RequestMapping("/gen") |
| | | @RestController |
| | | public class GenController extends BaseController |
| | | { |
| | | @Autowired |
| | | private IGenTableService genTableService; |
| | | |
| | | @Autowired |
| | | private IGenTableColumnService genTableColumnService; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä»£ç çæå表 |
| | | */ |
| | | @RequiresPermissions("tool:gen:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo genList(GenTable genTable) |
| | | { |
| | | startPage(); |
| | | List<GenTable> list = genTableService.selectGenTableList(genTable); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä»£ç çæä¸å¡ |
| | | */ |
| | | @RequiresPermissions("tool:gen:query") |
| | | @GetMapping(value = "/{tableId}") |
| | | public AjaxResult getInfo(@PathVariable Long tableId) |
| | | { |
| | | GenTable table = genTableService.selectGenTableById(tableId); |
| | | List<GenTable> tables = genTableService.selectGenTableAll(); |
| | | List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("info", table); |
| | | map.put("rows", list); |
| | | map.put("tables", tables); |
| | | return success(map); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°æ®åºå表 |
| | | */ |
| | | @RequiresPermissions("tool:gen:list") |
| | | @GetMapping("/db/list") |
| | | public TableDataInfo dataList(GenTable genTable) |
| | | { |
| | | startPage(); |
| | | List<GenTable> list = genTableService.selectDbTableList(genTable); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°æ®è¡¨å段å表 |
| | | */ |
| | | @GetMapping(value = "/column/{tableId}") |
| | | public TableDataInfo columnList(Long tableId) |
| | | { |
| | | TableDataInfo dataInfo = new TableDataInfo(); |
| | | List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); |
| | | dataInfo.setRows(list); |
| | | dataInfo.setTotal(list.size()); |
| | | return dataInfo; |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥è¡¨ç»æï¼ä¿åï¼ |
| | | */ |
| | | @RequiresPermissions("tool:gen:import") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importTable") |
| | | public AjaxResult importTableSave(String tables) |
| | | { |
| | | String[] tableNames = Convert.toStrArray(tables); |
| | | // æ¥è¯¢è¡¨ä¿¡æ¯ |
| | | List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); |
| | | genTableService.importGenTable(tableList); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿å代ç çæä¸å¡ |
| | | */ |
| | | @RequiresPermissions("tool:gen:edit") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult editSave(@Validated @RequestBody GenTable genTable) |
| | | { |
| | | genTableService.validateEdit(genTable); |
| | | genTableService.updateGenTable(genTable); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä»£ç çæ |
| | | */ |
| | | @RequiresPermissions("tool:gen:remove") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{tableIds}") |
| | | public AjaxResult remove(@PathVariable Long[] tableIds) |
| | | { |
| | | genTableService.deleteGenTableByIds(tableIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * é¢è§ä»£ç |
| | | */ |
| | | @RequiresPermissions("tool:gen:preview") |
| | | @GetMapping("/preview/{tableId}") |
| | | public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException |
| | | { |
| | | Map<String, String> dataMap = genTableService.previewCode(tableId); |
| | | return success(dataMap); |
| | | } |
| | | |
| | | /** |
| | | * çæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | */ |
| | | @RequiresPermissions("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/download/{tableName}") |
| | | public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException |
| | | { |
| | | byte[] data = genTableService.downloadCode(tableName); |
| | | genCode(response, data); |
| | | } |
| | | |
| | | /** |
| | | * çæä»£ç ï¼èªå®ä¹è·¯å¾ï¼ |
| | | */ |
| | | @RequiresPermissions("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/genCode/{tableName}") |
| | | public AjaxResult genCode(@PathVariable("tableName") String tableName) |
| | | { |
| | | genTableService.generatorCode(tableName); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * åæ¥æ°æ®åº |
| | | */ |
| | | @RequiresPermissions("tool:gen:edit") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.UPDATE) |
| | | @GetMapping("/synchDb/{tableName}") |
| | | public AjaxResult synchDb(@PathVariable("tableName") String tableName) |
| | | { |
| | | genTableService.synchDb(tableName); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éçæä»£ç |
| | | */ |
| | | @RequiresPermissions("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/batchGenCode") |
| | | public void batchGenCode(HttpServletResponse response, String tables) throws IOException |
| | | { |
| | | String[] tableNames = Convert.toStrArray(tables); |
| | | byte[] data = genTableService.downloadCode(tableNames); |
| | | genCode(response, data); |
| | | } |
| | | |
| | | /** |
| | | * çæzipæä»¶ |
| | | */ |
| | | private void genCode(HttpServletResponse response, byte[] data) throws IOException |
| | | { |
| | | response.reset(); |
| | | response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); |
| | | response.addHeader("Content-Length", "" + data.length); |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.domain; |
| | | |
| | | import java.util.List; |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotBlank; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import com.se.common.core.constant.GenConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * ä¸å¡è¡¨ gen_table |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class GenTable extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ç¼å· */ |
| | | private Long tableId; |
| | | |
| | | /** 表åç§° */ |
| | | @NotBlank(message = "表åç§°ä¸è½ä¸ºç©º") |
| | | private String tableName; |
| | | |
| | | /** 表æè¿° */ |
| | | @NotBlank(message = "表æè¿°ä¸è½ä¸ºç©º") |
| | | private String tableComment; |
| | | |
| | | /** å
³èç¶è¡¨ç表å */ |
| | | private String subTableName; |
| | | |
| | | /** æ¬è¡¨å
³èç¶è¡¨çå¤é®å */ |
| | | private String subTableFkName; |
| | | |
| | | /** å®ä½ç±»åç§°(é¦åæ¯å¤§å) */ |
| | | @NotBlank(message = "å®ä½ç±»åç§°ä¸è½ä¸ºç©º") |
| | | private String className; |
| | | |
| | | /** 使ç¨ç模æ¿ï¼crudå表æä½ treeæ 表æä½ sub主å表æä½ï¼ */ |
| | | private String tplCategory; |
| | | |
| | | /** å端类åï¼element-ui模ç element-plus模çï¼ */ |
| | | private String tplWebType; |
| | | |
| | | /** çæå
è·¯å¾ */ |
| | | @NotBlank(message = "çæå
è·¯å¾ä¸è½ä¸ºç©º") |
| | | private String packageName; |
| | | |
| | | /** çææ¨¡åå */ |
| | | @NotBlank(message = "çææ¨¡ååä¸è½ä¸ºç©º") |
| | | private String moduleName; |
| | | |
| | | /** çæä¸å¡å */ |
| | | @NotBlank(message = "çæä¸å¡åä¸è½ä¸ºç©º") |
| | | private String businessName; |
| | | |
| | | /** çæåè½å */ |
| | | @NotBlank(message = "çæåè½åä¸è½ä¸ºç©º") |
| | | private String functionName; |
| | | |
| | | /** çæä½è
*/ |
| | | @NotBlank(message = "ä½è
ä¸è½ä¸ºç©º") |
| | | private String functionAuthor; |
| | | |
| | | /** çæä»£ç æ¹å¼ï¼0zipå缩å
1èªå®ä¹è·¯å¾ï¼ */ |
| | | private String genType; |
| | | |
| | | /** çæè·¯å¾ï¼ä¸å¡«é»è®¤é¡¹ç®è·¯å¾ï¼ */ |
| | | private String genPath; |
| | | |
| | | /** 主é®ä¿¡æ¯ */ |
| | | private GenTableColumn pkColumn; |
| | | |
| | | /** åè¡¨ä¿¡æ¯ */ |
| | | private GenTable subTable; |
| | | |
| | | /** 表åä¿¡æ¯ */ |
| | | @Valid |
| | | private List<GenTableColumn> columns; |
| | | |
| | | /** å
¶å®çæé项 */ |
| | | private String options; |
| | | |
| | | /** æ ç¼ç åæ®µ */ |
| | | private String treeCode; |
| | | |
| | | /** æ ç¶ç¼ç åæ®µ */ |
| | | private String treeParentCode; |
| | | |
| | | /** æ åç§°åæ®µ */ |
| | | private String treeName; |
| | | |
| | | /** ä¸çº§èåIDåæ®µ */ |
| | | private String parentMenuId; |
| | | |
| | | /** ä¸çº§èååç§°åæ®µ */ |
| | | private String parentMenuName; |
| | | |
| | | public Long getTableId() |
| | | { |
| | | return tableId; |
| | | } |
| | | |
| | | public void setTableId(Long tableId) |
| | | { |
| | | this.tableId = tableId; |
| | | } |
| | | |
| | | public String getTableName() |
| | | { |
| | | return tableName; |
| | | } |
| | | |
| | | public void setTableName(String tableName) |
| | | { |
| | | this.tableName = tableName; |
| | | } |
| | | |
| | | public String getTableComment() |
| | | { |
| | | return tableComment; |
| | | } |
| | | |
| | | public void setTableComment(String tableComment) |
| | | { |
| | | this.tableComment = tableComment; |
| | | } |
| | | |
| | | public String getSubTableName() |
| | | { |
| | | return subTableName; |
| | | } |
| | | |
| | | public void setSubTableName(String subTableName) |
| | | { |
| | | this.subTableName = subTableName; |
| | | } |
| | | |
| | | public String getSubTableFkName() |
| | | { |
| | | return subTableFkName; |
| | | } |
| | | |
| | | public void setSubTableFkName(String subTableFkName) |
| | | { |
| | | this.subTableFkName = subTableFkName; |
| | | } |
| | | |
| | | public String getClassName() |
| | | { |
| | | return className; |
| | | } |
| | | |
| | | public void setClassName(String className) |
| | | { |
| | | this.className = className; |
| | | } |
| | | |
| | | public String getTplCategory() |
| | | { |
| | | return tplCategory; |
| | | } |
| | | |
| | | public void setTplCategory(String tplCategory) |
| | | { |
| | | this.tplCategory = tplCategory; |
| | | } |
| | | |
| | | public String getTplWebType() |
| | | { |
| | | return tplWebType; |
| | | } |
| | | |
| | | public void setTplWebType(String tplWebType) |
| | | { |
| | | this.tplWebType = tplWebType; |
| | | } |
| | | |
| | | public String getPackageName() |
| | | { |
| | | return packageName; |
| | | } |
| | | |
| | | public void setPackageName(String packageName) |
| | | { |
| | | this.packageName = packageName; |
| | | } |
| | | |
| | | public String getModuleName() |
| | | { |
| | | return moduleName; |
| | | } |
| | | |
| | | public void setModuleName(String moduleName) |
| | | { |
| | | this.moduleName = moduleName; |
| | | } |
| | | |
| | | public String getBusinessName() |
| | | { |
| | | return businessName; |
| | | } |
| | | |
| | | public void setBusinessName(String businessName) |
| | | { |
| | | this.businessName = businessName; |
| | | } |
| | | |
| | | public String getFunctionName() |
| | | { |
| | | return functionName; |
| | | } |
| | | |
| | | public void setFunctionName(String functionName) |
| | | { |
| | | this.functionName = functionName; |
| | | } |
| | | |
| | | public String getFunctionAuthor() |
| | | { |
| | | return functionAuthor; |
| | | } |
| | | |
| | | public void setFunctionAuthor(String functionAuthor) |
| | | { |
| | | this.functionAuthor = functionAuthor; |
| | | } |
| | | |
| | | public String getGenType() |
| | | { |
| | | return genType; |
| | | } |
| | | |
| | | public void setGenType(String genType) |
| | | { |
| | | this.genType = genType; |
| | | } |
| | | |
| | | public String getGenPath() |
| | | { |
| | | return genPath; |
| | | } |
| | | |
| | | public void setGenPath(String genPath) |
| | | { |
| | | this.genPath = genPath; |
| | | } |
| | | |
| | | public GenTableColumn getPkColumn() |
| | | { |
| | | return pkColumn; |
| | | } |
| | | |
| | | public void setPkColumn(GenTableColumn pkColumn) |
| | | { |
| | | this.pkColumn = pkColumn; |
| | | } |
| | | |
| | | public GenTable getSubTable() |
| | | { |
| | | return subTable; |
| | | } |
| | | |
| | | public void setSubTable(GenTable subTable) |
| | | { |
| | | this.subTable = subTable; |
| | | } |
| | | public List<GenTableColumn> getColumns() |
| | | { |
| | | return columns; |
| | | } |
| | | |
| | | public void setColumns(List<GenTableColumn> columns) |
| | | { |
| | | this.columns = columns; |
| | | } |
| | | |
| | | public String getOptions() |
| | | { |
| | | return options; |
| | | } |
| | | |
| | | public void setOptions(String options) |
| | | { |
| | | this.options = options; |
| | | } |
| | | |
| | | public String getTreeCode() |
| | | { |
| | | return treeCode; |
| | | } |
| | | |
| | | public void setTreeCode(String treeCode) |
| | | { |
| | | this.treeCode = treeCode; |
| | | } |
| | | |
| | | public String getTreeParentCode() |
| | | { |
| | | return treeParentCode; |
| | | } |
| | | |
| | | public void setTreeParentCode(String treeParentCode) |
| | | { |
| | | this.treeParentCode = treeParentCode; |
| | | } |
| | | |
| | | public String getTreeName() |
| | | { |
| | | return treeName; |
| | | } |
| | | |
| | | public void setTreeName(String treeName) |
| | | { |
| | | this.treeName = treeName; |
| | | } |
| | | |
| | | public String getParentMenuId() |
| | | { |
| | | return parentMenuId; |
| | | } |
| | | |
| | | public void setParentMenuId(String parentMenuId) |
| | | { |
| | | this.parentMenuId = parentMenuId; |
| | | } |
| | | |
| | | public String getParentMenuName() |
| | | { |
| | | return parentMenuName; |
| | | } |
| | | |
| | | public void setParentMenuName(String parentMenuName) |
| | | { |
| | | this.parentMenuName = parentMenuName; |
| | | } |
| | | |
| | | public boolean isSub() |
| | | { |
| | | return isSub(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isSub(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); |
| | | } |
| | | public boolean isTree() |
| | | { |
| | | return isTree(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isTree(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); |
| | | } |
| | | |
| | | public boolean isCrud() |
| | | { |
| | | return isCrud(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isCrud(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | } |
| | | |
| | | public boolean isSuperColumn(String javaField) |
| | | { |
| | | return isSuperColumn(this.tplCategory, javaField); |
| | | } |
| | | |
| | | public static boolean isSuperColumn(String tplCategory, String javaField) |
| | | { |
| | | if (isTree(tplCategory)) |
| | | { |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); |
| | | } |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.domain; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * 代ç çæä¸å¡å段表 gen_table_column |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class GenTableColumn extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ç¼å· */ |
| | | private Long columnId; |
| | | |
| | | /** å½å±è¡¨ç¼å· */ |
| | | private Long tableId; |
| | | |
| | | /** ååç§° */ |
| | | private String columnName; |
| | | |
| | | /** åæè¿° */ |
| | | private String columnComment; |
| | | |
| | | /** åç±»å */ |
| | | private String columnType; |
| | | |
| | | /** JAVAç±»å */ |
| | | private String javaType; |
| | | |
| | | /** JAVAåæ®µå */ |
| | | @NotBlank(message = "Java屿§ä¸è½ä¸ºç©º") |
| | | private String javaField; |
| | | |
| | | /** æ¯å¦ä¸»é®ï¼1æ¯ï¼ */ |
| | | private String isPk; |
| | | |
| | | /** æ¯å¦èªå¢ï¼1æ¯ï¼ */ |
| | | private String isIncrement; |
| | | |
| | | /** æ¯å¦å¿
å¡«ï¼1æ¯ï¼ */ |
| | | private String isRequired; |
| | | |
| | | /** æ¯å¦ä¸ºæå
¥å段ï¼1æ¯ï¼ */ |
| | | private String isInsert; |
| | | |
| | | /** æ¯å¦ç¼è¾å段ï¼1æ¯ï¼ */ |
| | | private String isEdit; |
| | | |
| | | /** æ¯å¦åè¡¨åæ®µï¼1æ¯ï¼ */ |
| | | private String isList; |
| | | |
| | | /** æ¯å¦æ¥è¯¢å段ï¼1æ¯ï¼ */ |
| | | private String isQuery; |
| | | |
| | | /** æ¥è¯¢æ¹å¼ï¼EQçäºãNEä¸çäºãGT大äºãLTå°äºãLIKE模ç³ãBETWEENèå´ï¼ */ |
| | | private String queryType; |
| | | |
| | | /** æ¾ç¤ºç±»åï¼inputææ¬æ¡ãtextareaææ¬åãselect䏿æ¡ãcheckboxå¤éæ¡ãradioåéæ¡ãdatetimeæ¥ææ§ä»¶ãimageå¾çä¸ä¼ æ§ä»¶ãuploadæä»¶ä¸ä¼ æ§ä»¶ãeditorå¯ææ¬æ§ä»¶ï¼ */ |
| | | private String htmlType; |
| | | |
| | | /** åå
¸ç±»å */ |
| | | private String dictType; |
| | | |
| | | /** æåº */ |
| | | private Integer sort; |
| | | |
| | | public void setColumnId(Long columnId) |
| | | { |
| | | this.columnId = columnId; |
| | | } |
| | | |
| | | public Long getColumnId() |
| | | { |
| | | return columnId; |
| | | } |
| | | |
| | | public void setTableId(Long tableId) |
| | | { |
| | | this.tableId = tableId; |
| | | } |
| | | |
| | | public Long getTableId() |
| | | { |
| | | return tableId; |
| | | } |
| | | |
| | | public void setColumnName(String columnName) |
| | | { |
| | | this.columnName = columnName; |
| | | } |
| | | |
| | | public String getColumnName() |
| | | { |
| | | return columnName; |
| | | } |
| | | |
| | | public void setColumnComment(String columnComment) |
| | | { |
| | | this.columnComment = columnComment; |
| | | } |
| | | |
| | | public String getColumnComment() |
| | | { |
| | | return columnComment; |
| | | } |
| | | |
| | | public void setColumnType(String columnType) |
| | | { |
| | | this.columnType = columnType; |
| | | } |
| | | |
| | | public String getColumnType() |
| | | { |
| | | return columnType; |
| | | } |
| | | |
| | | public void setJavaType(String javaType) |
| | | { |
| | | this.javaType = javaType; |
| | | } |
| | | |
| | | public String getJavaType() |
| | | { |
| | | return javaType; |
| | | } |
| | | |
| | | public void setJavaField(String javaField) |
| | | { |
| | | this.javaField = javaField; |
| | | } |
| | | |
| | | public String getJavaField() |
| | | { |
| | | return javaField; |
| | | } |
| | | |
| | | public String getCapJavaField() |
| | | { |
| | | return StringUtils.capitalize(javaField); |
| | | } |
| | | |
| | | public void setIsPk(String isPk) |
| | | { |
| | | this.isPk = isPk; |
| | | } |
| | | |
| | | public String getIsPk() |
| | | { |
| | | return isPk; |
| | | } |
| | | |
| | | public boolean isPk() |
| | | { |
| | | return isPk(this.isPk); |
| | | } |
| | | |
| | | public boolean isPk(String isPk) |
| | | { |
| | | return isPk != null && StringUtils.equals("1", isPk); |
| | | } |
| | | |
| | | public String getIsIncrement() |
| | | { |
| | | return isIncrement; |
| | | } |
| | | |
| | | public void setIsIncrement(String isIncrement) |
| | | { |
| | | this.isIncrement = isIncrement; |
| | | } |
| | | |
| | | public boolean isIncrement() |
| | | { |
| | | return isIncrement(this.isIncrement); |
| | | } |
| | | |
| | | public boolean isIncrement(String isIncrement) |
| | | { |
| | | return isIncrement != null && StringUtils.equals("1", isIncrement); |
| | | } |
| | | |
| | | public void setIsRequired(String isRequired) |
| | | { |
| | | this.isRequired = isRequired; |
| | | } |
| | | |
| | | public String getIsRequired() |
| | | { |
| | | return isRequired; |
| | | } |
| | | |
| | | public boolean isRequired() |
| | | { |
| | | return isRequired(this.isRequired); |
| | | } |
| | | |
| | | public boolean isRequired(String isRequired) |
| | | { |
| | | return isRequired != null && StringUtils.equals("1", isRequired); |
| | | } |
| | | |
| | | public void setIsInsert(String isInsert) |
| | | { |
| | | this.isInsert = isInsert; |
| | | } |
| | | |
| | | public String getIsInsert() |
| | | { |
| | | return isInsert; |
| | | } |
| | | |
| | | public boolean isInsert() |
| | | { |
| | | return isInsert(this.isInsert); |
| | | } |
| | | |
| | | public boolean isInsert(String isInsert) |
| | | { |
| | | return isInsert != null && StringUtils.equals("1", isInsert); |
| | | } |
| | | |
| | | public void setIsEdit(String isEdit) |
| | | { |
| | | this.isEdit = isEdit; |
| | | } |
| | | |
| | | public String getIsEdit() |
| | | { |
| | | return isEdit; |
| | | } |
| | | |
| | | public boolean isEdit() |
| | | { |
| | | return isInsert(this.isEdit); |
| | | } |
| | | |
| | | public boolean isEdit(String isEdit) |
| | | { |
| | | return isEdit != null && StringUtils.equals("1", isEdit); |
| | | } |
| | | |
| | | public void setIsList(String isList) |
| | | { |
| | | this.isList = isList; |
| | | } |
| | | |
| | | public String getIsList() |
| | | { |
| | | return isList; |
| | | } |
| | | |
| | | public boolean isList() |
| | | { |
| | | return isList(this.isList); |
| | | } |
| | | |
| | | public boolean isList(String isList) |
| | | { |
| | | return isList != null && StringUtils.equals("1", isList); |
| | | } |
| | | |
| | | public void setIsQuery(String isQuery) |
| | | { |
| | | this.isQuery = isQuery; |
| | | } |
| | | |
| | | public String getIsQuery() |
| | | { |
| | | return isQuery; |
| | | } |
| | | |
| | | public boolean isQuery() |
| | | { |
| | | return isQuery(this.isQuery); |
| | | } |
| | | |
| | | public boolean isQuery(String isQuery) |
| | | { |
| | | return isQuery != null && StringUtils.equals("1", isQuery); |
| | | } |
| | | |
| | | public void setQueryType(String queryType) |
| | | { |
| | | this.queryType = queryType; |
| | | } |
| | | |
| | | public String getQueryType() |
| | | { |
| | | return queryType; |
| | | } |
| | | |
| | | public String getHtmlType() |
| | | { |
| | | return htmlType; |
| | | } |
| | | |
| | | public void setHtmlType(String htmlType) |
| | | { |
| | | this.htmlType = htmlType; |
| | | } |
| | | |
| | | public void setDictType(String dictType) |
| | | { |
| | | this.dictType = dictType; |
| | | } |
| | | |
| | | public String getDictType() |
| | | { |
| | | return dictType; |
| | | } |
| | | |
| | | public void setSort(Integer sort) |
| | | { |
| | | this.sort = sort; |
| | | } |
| | | |
| | | public Integer getSort() |
| | | { |
| | | return sort; |
| | | } |
| | | |
| | | public boolean isSuperColumn() |
| | | { |
| | | return isSuperColumn(this.javaField); |
| | | } |
| | | |
| | | public static boolean isSuperColumn(String javaField) |
| | | { |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | // BaseEntity |
| | | "createBy", "createTime", "updateBy", "updateTime", "remark", |
| | | // TreeEntity |
| | | "parentName", "parentId", "orderNum", "ancestors"); |
| | | } |
| | | |
| | | public boolean isUsableColumn() |
| | | { |
| | | return isUsableColumn(javaField); |
| | | } |
| | | |
| | | public static boolean isUsableColumn(String javaField) |
| | | { |
| | | // isSuperColumn()ä¸çååç¨äºé¿å
çæå¤ä½Domain屿§ï¼è¥æäºå±æ§å¨çæé¡µé¢æ¶éè¦ç¨å°ä¸è½å¿½ç¥ï¼åæ¾å¨æ¤å¤ç½åå |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | } |
| | | |
| | | public String readConverterExp() |
| | | { |
| | | String remarks = StringUtils.substringBetween(this.columnComment, "ï¼", "ï¼"); |
| | | StringBuffer sb = new StringBuffer(); |
| | | if (StringUtils.isNotEmpty(remarks)) |
| | | { |
| | | for (String value : remarks.split(" ")) |
| | | { |
| | | if (StringUtils.isNotEmpty(value)) |
| | | { |
| | | Object startStr = value.subSequence(0, 1); |
| | | String endStr = value.substring(1); |
| | | sb.append("").append(startStr).append("=").append(endStr).append(","); |
| | | } |
| | | } |
| | | return sb.deleteCharAt(sb.length() - 1).toString(); |
| | | } |
| | | else |
| | | { |
| | | return this.columnComment; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.gen.domain.GenTableColumn; |
| | | |
| | | /** |
| | | * ä¸å¡å段 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface GenTableColumnMapper |
| | | { |
| | | /** |
| | | * æ ¹æ®è¡¨åç§°æ¥è¯¢åä¿¡æ¯ |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return åä¿¡æ¯ |
| | | */ |
| | | public List<GenTableColumn> selectDbTableColumnsByName(String tableName); |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å段å表 |
| | | * |
| | | * @param tableId ä¸å¡å段ç¼å· |
| | | * @return ä¸å¡å段éå |
| | | */ |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); |
| | | |
| | | /** |
| | | * æ°å¢ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * å é¤ä¸å¡å段 |
| | | * |
| | | * @param genTableColumns åæ°æ® |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteGenTableColumns(List<GenTableColumn> genTableColumns); |
| | | |
| | | /** |
| | | * æ¹éå é¤ä¸å¡å段 |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteGenTableColumnByIds(Long[] ids); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.gen.domain.GenTable; |
| | | |
| | | /** |
| | | * ä¸å¡ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface GenTableMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ä¸å¡éå |
| | | */ |
| | | public List<GenTable> selectGenTableList(GenTable genTable); |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | public List<GenTable> selectDbTableList(GenTable genTable); |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param tableNames 表åç§°ç» |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè¡¨ä¿¡æ¯ |
| | | * |
| | | * @return 表信æ¯éå |
| | | */ |
| | | public List<GenTable> selectGenTableAll(); |
| | | |
| | | /** |
| | | * æ¥è¯¢è¡¨IDä¸å¡ä¿¡æ¯ |
| | | * |
| | | * @param id ä¸å¡ID |
| | | * @return ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | public GenTable selectGenTableById(Long id); |
| | | |
| | | /** |
| | | * æ¥è¯¢è¡¨åç§°ä¸å¡ä¿¡æ¯ |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | public GenTable selectGenTableByName(String tableName); |
| | | |
| | | /** |
| | | * æ°å¢ä¸å¡ |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertGenTable(GenTable genTable); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡ |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateGenTable(GenTable genTable); |
| | | |
| | | /** |
| | | * æ¹éå é¤ä¸å¡ |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteGenTableByIds(Long[] ids); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.service; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.gen.domain.GenTableColumn; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.text.Convert; |
| | | import com.se.gen.mapper.GenTableColumnMapper; |
| | | |
| | | /** |
| | | * ä¸å¡å段 æå¡å±å®ç° |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class GenTableColumnServiceImpl implements IGenTableColumnService |
| | | { |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å段å表 |
| | | * |
| | | * @param tableId ä¸å¡å段ç¼å· |
| | | * @return ä¸å¡å段éå |
| | | */ |
| | | @Override |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) |
| | | { |
| | | return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn) |
| | | { |
| | | return genTableColumnMapper.insertGenTableColumn(genTableColumn); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn) |
| | | { |
| | | return genTableColumnMapper.updateGenTableColumn(genTableColumn); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä¸å¡å段对象 |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteGenTableColumnByIds(String ids) |
| | | { |
| | | return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.service; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.StringWriter; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | import com.se.gen.domain.GenTableColumn; |
| | | import com.se.gen.util.GenUtils; |
| | | import com.se.gen.util.VelocityInitializer; |
| | | import com.se.gen.util.VelocityUtils; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.velocity.Template; |
| | | import org.apache.velocity.VelocityContext; |
| | | import org.apache.velocity.app.Velocity; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.constant.GenConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.text.CharsetKit; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.gen.domain.GenTable; |
| | | import com.se.gen.mapper.GenTableColumnMapper; |
| | | import com.se.gen.mapper.GenTableMapper; |
| | | |
| | | /** |
| | | * ä¸å¡ æå¡å±å®ç° |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class GenTableServiceImpl implements IGenTableService |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private GenTableMapper genTableMapper; |
| | | |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡ä¿¡æ¯ |
| | | * |
| | | * @param id ä¸å¡ID |
| | | * @return ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public GenTable selectGenTableById(Long id) |
| | | { |
| | | GenTable genTable = genTableMapper.selectGenTableById(id); |
| | | setTableFromOptions(genTable); |
| | | return genTable; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ä¸å¡éå |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectGenTableList(GenTable genTable) |
| | | { |
| | | return genTableMapper.selectGenTableList(genTable); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectDbTableList(GenTable genTable) |
| | | { |
| | | return genTableMapper.selectDbTableList(genTable); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param tableNames 表åç§°ç» |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames) |
| | | { |
| | | return genTableMapper.selectDbTableListByNames(tableNames); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè¡¨ä¿¡æ¯ |
| | | * |
| | | * @return 表信æ¯éå |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectGenTableAll() |
| | | { |
| | | return genTableMapper.selectGenTableAll(); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡ |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateGenTable(GenTable genTable) |
| | | { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | genTable.setOptions(options); |
| | | int row = genTableMapper.updateGenTable(genTable); |
| | | if (row > 0) |
| | | { |
| | | for (GenTableColumn cenTableColumn : genTable.getColumns()) |
| | | { |
| | | genTableColumnMapper.updateGenTableColumn(cenTableColumn); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä¸å¡å¯¹è±¡ |
| | | * |
| | | * @param tableIds éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteGenTableByIds(Long[] tableIds) |
| | | { |
| | | genTableMapper.deleteGenTableByIds(tableIds); |
| | | genTableColumnMapper.deleteGenTableColumnByIds(tableIds); |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥è¡¨ç»æ |
| | | * |
| | | * @param tableList 导å
¥è¡¨å表 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importGenTable(List<GenTable> tableList) |
| | | { |
| | | String operName = SecurityUtils.getUsername(); |
| | | try |
| | | { |
| | | for (GenTable table : tableList) |
| | | { |
| | | String tableName = table.getTableName(); |
| | | GenUtils.initTable(table, operName); |
| | | int row = genTableMapper.insertGenTable(table); |
| | | if (row > 0) |
| | | { |
| | | // ä¿ååä¿¡æ¯ |
| | | List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | for (GenTableColumn column : genTableColumns) |
| | | { |
| | | GenUtils.initColumnField(column, table); |
| | | genTableColumnMapper.insertGenTableColumn(column); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("导å
¥å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * é¢è§ä»£ç |
| | | * |
| | | * @param tableId 表ç¼å· |
| | | * @return é¢è§æ°æ®å表 |
| | | */ |
| | | @Override |
| | | public Map<String, String> previewCode(Long tableId) |
| | | { |
| | | Map<String, String> dataMap = new LinkedHashMap<>(); |
| | | // æ¥è¯¢è¡¨ä¿¡æ¯ |
| | | GenTable table = genTableMapper.selectGenTableById(tableId); |
| | | // 设置主åè¡¨ä¿¡æ¯ |
| | | setSubTable(table); |
| | | // 设置主é®åä¿¡æ¯ |
| | | setPkColumn(table); |
| | | VelocityInitializer.initVelocity(); |
| | | |
| | | VelocityContext context = VelocityUtils.prepareContext(table); |
| | | |
| | | // è·å模æ¿å表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); |
| | | for (String template : templates) |
| | | { |
| | | // æ¸²ææ¨¡æ¿ |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | dataMap.put(template, sw.toString()); |
| | | } |
| | | return dataMap; |
| | | } |
| | | |
| | | /** |
| | | * çæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return æ°æ® |
| | | */ |
| | | @Override |
| | | public byte[] downloadCode(String tableName) |
| | | { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | ZipOutputStream zip = new ZipOutputStream(outputStream); |
| | | generatorCode(tableName, zip); |
| | | IOUtils.closeQuietly(zip); |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * çæä»£ç ï¼èªå®ä¹è·¯å¾ï¼ |
| | | * |
| | | * @param tableName 表åç§° |
| | | */ |
| | | @Override |
| | | public void generatorCode(String tableName) |
| | | { |
| | | // æ¥è¯¢è¡¨ä¿¡æ¯ |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | // 设置主åè¡¨ä¿¡æ¯ |
| | | setSubTable(table); |
| | | // 设置主é®åä¿¡æ¯ |
| | | setPkColumn(table); |
| | | |
| | | VelocityInitializer.initVelocity(); |
| | | |
| | | VelocityContext context = VelocityUtils.prepareContext(table); |
| | | |
| | | // è·å模æ¿å表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); |
| | | for (String template : templates) |
| | | { |
| | | if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) |
| | | { |
| | | // æ¸²ææ¨¡æ¿ |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try |
| | | { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | throw new ServiceException("æ¸²ææ¨¡æ¿å¤±è´¥ï¼è¡¨åï¼" + table.getTableName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åæ¥æ°æ®åº |
| | | * |
| | | * @param tableName 表åç§° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void synchDb(String tableName) |
| | | { |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | List<GenTableColumn> tableColumns = table.getColumns(); |
| | | Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); |
| | | |
| | | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | if (StringUtils.isEmpty(dbTableColumns)) |
| | | { |
| | | throw new ServiceException("åæ¥æ°æ®å¤±è´¥ï¼åè¡¨ç»æä¸åå¨"); |
| | | } |
| | | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | | |
| | | dbTableColumns.forEach(column -> { |
| | | GenUtils.initColumnField(column, table); |
| | | if (tableColumnMap.containsKey(column.getColumnName())) |
| | | { |
| | | GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); |
| | | column.setColumnId(prevColumn.getColumnId()); |
| | | if (column.isList()) |
| | | { |
| | | // 妿æ¯å表ï¼ç»§ç»ä¿çæ¥è¯¢æ¹å¼/åå
¸ç±»åé项 |
| | | column.setDictType(prevColumn.getDictType()); |
| | | column.setQueryType(prevColumn.getQueryType()); |
| | | } |
| | | if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() |
| | | && (column.isInsert() || column.isEdit()) |
| | | && ((column.isUsableColumn()) || (!column.isSuperColumn()))) |
| | | { |
| | | // 妿æ¯(æ°å¢/ä¿®æ¹&é主é®/é忽ç¥åç¶å±æ§)ï¼ç»§ç»ä¿çå¿
å¡«/æ¾ç¤ºç±»åé项 |
| | | column.setIsRequired(prevColumn.getIsRequired()); |
| | | column.setHtmlType(prevColumn.getHtmlType()); |
| | | } |
| | | genTableColumnMapper.updateGenTableColumn(column); |
| | | } |
| | | else |
| | | { |
| | | genTableColumnMapper.insertGenTableColumn(column); |
| | | } |
| | | }); |
| | | |
| | | List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); |
| | | if (StringUtils.isNotEmpty(delColumns)) |
| | | { |
| | | genTableColumnMapper.deleteGenTableColumns(delColumns); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¹éçæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | * |
| | | * @param tableNames 表æ°ç» |
| | | * @return æ°æ® |
| | | */ |
| | | @Override |
| | | public byte[] downloadCode(String[] tableNames) |
| | | { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | ZipOutputStream zip = new ZipOutputStream(outputStream); |
| | | for (String tableName : tableNames) |
| | | { |
| | | generatorCode(tableName, zip); |
| | | } |
| | | IOUtils.closeQuietly(zip); |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è¡¨ä¿¡æ¯å¹¶çæä»£ç |
| | | */ |
| | | private void generatorCode(String tableName, ZipOutputStream zip) |
| | | { |
| | | // æ¥è¯¢è¡¨ä¿¡æ¯ |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | // 设置主åè¡¨ä¿¡æ¯ |
| | | setSubTable(table); |
| | | // 设置主é®åä¿¡æ¯ |
| | | setPkColumn(table); |
| | | |
| | | VelocityInitializer.initVelocity(); |
| | | |
| | | VelocityContext context = VelocityUtils.prepareContext(table); |
| | | |
| | | // è·å模æ¿å表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); |
| | | for (String template : templates) |
| | | { |
| | | // æ¸²ææ¨¡æ¿ |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try |
| | | { |
| | | // æ·»å å°zip |
| | | zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); |
| | | IOUtils.write(sw.toString(), zip, Constants.UTF8); |
| | | IOUtils.closeQuietly(sw); |
| | | zip.flush(); |
| | | zip.closeEntry(); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("æ¸²ææ¨¡æ¿å¤±è´¥ï¼è¡¨åï¼" + table.getTableName(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååæ°æ ¡éª |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public void validateEdit(GenTable genTable) |
| | | { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) |
| | | { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | JSONObject paramsObj = JSON.parseObject(options); |
| | | if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) |
| | | { |
| | | throw new ServiceException("æ ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) |
| | | { |
| | | throw new ServiceException("æ ç¶ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) |
| | | { |
| | | throw new ServiceException("æ åç§°åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) |
| | | { |
| | | if (StringUtils.isEmpty(genTable.getSubTableName())) |
| | | { |
| | | throw new ServiceException("å
³èå表ç表åä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(genTable.getSubTableFkName())) |
| | | { |
| | | throw new ServiceException("å表å
³èçå¤é®åä¸è½ä¸ºç©º"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置主é®åä¿¡æ¯ |
| | | * |
| | | * @param table ä¸å¡è¡¨ä¿¡æ¯ |
| | | */ |
| | | public void setPkColumn(GenTable table) |
| | | { |
| | | for (GenTableColumn column : table.getColumns()) |
| | | { |
| | | if (column.isPk()) |
| | | { |
| | | table.setPkColumn(column); |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getPkColumn())) |
| | | { |
| | | table.setPkColumn(table.getColumns().get(0)); |
| | | } |
| | | if (GenConstants.TPL_SUB.equals(table.getTplCategory())) |
| | | { |
| | | for (GenTableColumn column : table.getSubTable().getColumns()) |
| | | { |
| | | if (column.isPk()) |
| | | { |
| | | table.getSubTable().setPkColumn(column); |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getSubTable().getPkColumn())) |
| | | { |
| | | table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置主åè¡¨ä¿¡æ¯ |
| | | * |
| | | * @param table ä¸å¡è¡¨ä¿¡æ¯ |
| | | */ |
| | | public void setSubTable(GenTable table) |
| | | { |
| | | String subTableName = table.getSubTableName(); |
| | | if (StringUtils.isNotEmpty(subTableName)) |
| | | { |
| | | table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置代ç çæå
¶ä»éé¡¹å¼ |
| | | * |
| | | * @param genTable 设置åççæå¯¹è±¡ |
| | | */ |
| | | public void setTableFromOptions(GenTable genTable) |
| | | { |
| | | JSONObject paramsObj = JSON.parseObject(genTable.getOptions()); |
| | | if (StringUtils.isNotNull(paramsObj)) |
| | | { |
| | | String treeCode = paramsObj.getString(GenConstants.TREE_CODE); |
| | | String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); |
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME); |
| | | String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); |
| | | |
| | | genTable.setTreeCode(treeCode); |
| | | genTable.setTreeParentCode(treeParentCode); |
| | | genTable.setTreeName(treeName); |
| | | genTable.setParentMenuId(parentMenuId); |
| | | genTable.setParentMenuName(parentMenuName); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å代ç çæå°å |
| | | * |
| | | * @param table ä¸å¡è¡¨ä¿¡æ¯ |
| | | * @param template æ¨¡æ¿æä»¶è·¯å¾ |
| | | * @return çæå°å |
| | | */ |
| | | public static String getGenPath(GenTable table, String template) |
| | | { |
| | | String genPath = table.getGenPath(); |
| | | if (StringUtils.equals(genPath, "/")) |
| | | { |
| | | return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | | return genPath + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.gen.domain.GenTableColumn; |
| | | |
| | | /** |
| | | * ä¸å¡å段 æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface IGenTableColumnService |
| | | { |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å段å表 |
| | | * |
| | | * @param tableId ä¸å¡å段ç¼å· |
| | | * @return ä¸å¡å段éå |
| | | */ |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); |
| | | |
| | | /** |
| | | * æ°å¢ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡å段 |
| | | * |
| | | * @param genTableColumn ä¸å¡åæ®µä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * å é¤ä¸å¡åæ®µä¿¡æ¯ |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteGenTableColumnByIds(String ids); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import com.se.gen.domain.GenTable; |
| | | |
| | | /** |
| | | * ä¸å¡ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface IGenTableService |
| | | { |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ä¸å¡éå |
| | | */ |
| | | public List<GenTable> selectGenTableList(GenTable genTable); |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | public List<GenTable> selectDbTableList(GenTable genTable); |
| | | |
| | | /** |
| | | * æ¥è¯¢æ®åºå表 |
| | | * |
| | | * @param tableNames 表åç§°ç» |
| | | * @return æ°æ®åºè¡¨éå |
| | | */ |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè¡¨ä¿¡æ¯ |
| | | * |
| | | * @return 表信æ¯éå |
| | | */ |
| | | public List<GenTable> selectGenTableAll(); |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡ä¿¡æ¯ |
| | | * |
| | | * @param id ä¸å¡ID |
| | | * @return ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | public GenTable selectGenTableById(Long id); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡ |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public void updateGenTable(GenTable genTable); |
| | | |
| | | /** |
| | | * å é¤ä¸å¡ä¿¡æ¯ |
| | | * |
| | | * @param tableIds éè¦å é¤çè¡¨æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public void deleteGenTableByIds(Long[] tableIds); |
| | | |
| | | /** |
| | | * 导å
¥è¡¨ç»æ |
| | | * |
| | | * @param tableList 导å
¥è¡¨å表 |
| | | */ |
| | | public void importGenTable(List<GenTable> tableList); |
| | | |
| | | /** |
| | | * é¢è§ä»£ç |
| | | * |
| | | * @param tableId 表ç¼å· |
| | | * @return é¢è§æ°æ®å表 |
| | | */ |
| | | public Map<String, String> previewCode(Long tableId); |
| | | |
| | | /** |
| | | * çæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return æ°æ® |
| | | */ |
| | | public byte[] downloadCode(String tableName); |
| | | |
| | | /** |
| | | * çæä»£ç ï¼èªå®ä¹è·¯å¾ï¼ |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return æ°æ® |
| | | */ |
| | | public void generatorCode(String tableName); |
| | | |
| | | /** |
| | | * åæ¥æ°æ®åº |
| | | * |
| | | * @param tableName 表åç§° |
| | | */ |
| | | public void synchDb(String tableName); |
| | | |
| | | /** |
| | | * æ¹éçæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | * |
| | | * @param tableNames 表æ°ç» |
| | | * @return æ°æ® |
| | | */ |
| | | public byte[] downloadCode(String[] tableNames); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååæ°æ ¡éª |
| | | * |
| | | * @param genTable ä¸å¡ä¿¡æ¯ |
| | | */ |
| | | public void validateEdit(GenTable genTable); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.util; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import com.se.gen.config.GenConfig; |
| | | import com.se.gen.domain.GenTableColumn; |
| | | import org.apache.commons.lang3.RegExUtils; |
| | | import com.se.common.core.constant.GenConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.gen.domain.GenTable; |
| | | |
| | | /** |
| | | * 代ç çæå¨ å·¥å
·ç±» |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class GenUtils |
| | | { |
| | | /** |
| | | * åå§åè¡¨ä¿¡æ¯ |
| | | */ |
| | | public static void initTable(GenTable genTable, String operName) |
| | | { |
| | | genTable.setClassName(convertClassName(genTable.getTableName())); |
| | | genTable.setPackageName(GenConfig.getPackageName()); |
| | | genTable.setModuleName(getModuleName(GenConfig.getPackageName())); |
| | | genTable.setBusinessName(getBusinessName(genTable.getTableName())); |
| | | genTable.setFunctionName(replaceText(genTable.getTableComment())); |
| | | genTable.setFunctionAuthor(GenConfig.getAuthor()); |
| | | genTable.setCreateBy(operName); |
| | | } |
| | | |
| | | /** |
| | | * åå§åå屿§å段 |
| | | */ |
| | | public static void initColumnField(GenTableColumn column, GenTable table) |
| | | { |
| | | String dataType = getDbType(column.getColumnType()); |
| | | String columnName = column.getColumnName(); |
| | | column.setTableId(table.getTableId()); |
| | | column.setCreateBy(table.getCreateBy()); |
| | | // 设置javaåæ®µå |
| | | column.setJavaField(StringUtils.toCamelCase(columnName)); |
| | | // 设置é»è®¤ç±»å |
| | | column.setJavaType(GenConstants.TYPE_STRING); |
| | | column.setQueryType(GenConstants.QUERY_EQ); |
| | | |
| | | if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) |
| | | { |
| | | // å符串é¿åº¦è¶
è¿500è®¾ç½®ä¸ºææ¬å |
| | | Integer columnLength = getColumnLength(column.getColumnType()); |
| | | String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; |
| | | column.setHtmlType(htmlType); |
| | | } |
| | | else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_DATE); |
| | | column.setHtmlType(GenConstants.HTML_DATETIME); |
| | | } |
| | | else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_INPUT); |
| | | |
| | | // å¦ææ¯æµ®ç¹å ç»ä¸ç¨BigDecimal |
| | | String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); |
| | | if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_BIGDECIMAL); |
| | | } |
| | | // å¦ææ¯æ´å½¢ |
| | | else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_INTEGER); |
| | | } |
| | | // é¿æ´å½¢ |
| | | else |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_LONG); |
| | | } |
| | | } |
| | | |
| | | // æå
¥å段ï¼é»è®¤ææå段é½éè¦æå
¥ï¼ |
| | | column.setIsInsert(GenConstants.REQUIRE); |
| | | |
| | | // ç¼è¾å段 |
| | | if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) |
| | | { |
| | | column.setIsEdit(GenConstants.REQUIRE); |
| | | } |
| | | // åè¡¨åæ®µ |
| | | if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) |
| | | { |
| | | column.setIsList(GenConstants.REQUIRE); |
| | | } |
| | | // æ¥è¯¢å段 |
| | | if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) |
| | | { |
| | | column.setIsQuery(GenConstants.REQUIRE); |
| | | } |
| | | |
| | | // æ¥è¯¢å段类å |
| | | if (StringUtils.endsWithIgnoreCase(columnName, "name")) |
| | | { |
| | | column.setQueryType(GenConstants.QUERY_LIKE); |
| | | } |
| | | // ç¶æåæ®µè®¾ç½®åéæ¡ |
| | | if (StringUtils.endsWithIgnoreCase(columnName, "status")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_RADIO); |
| | | } |
| | | // ç±»å&æ§å«åæ®µè®¾ç½®ä¸ææ¡ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "type") |
| | | || StringUtils.endsWithIgnoreCase(columnName, "sex")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_SELECT); |
| | | } |
| | | // å¾çåæ®µè®¾ç½®å¾çä¸ä¼ æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "image")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); |
| | | } |
| | | // æä»¶å段设置æä»¶ä¸ä¼ æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "file")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); |
| | | } |
| | | // å
容忮µè®¾ç½®å¯ææ¬æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "content")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_EDITOR); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ°ç»æ¯å¦å
嫿å®å¼ |
| | | * |
| | | * @param arr æ°ç» |
| | | * @param targetValue å¼ |
| | | * @return æ¯å¦å
å« |
| | | */ |
| | | public static boolean arraysContains(String[] arr, String targetValue) |
| | | { |
| | | return Arrays.asList(arr).contains(targetValue); |
| | | } |
| | | |
| | | /** |
| | | * è·å模åå |
| | | * |
| | | * @param packageName å
å |
| | | * @return 模åå |
| | | */ |
| | | public static String getModuleName(String packageName) |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | int nameLength = packageName.length(); |
| | | return StringUtils.substring(packageName, lastIndex + 1, nameLength); |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸å¡å |
| | | * |
| | | * @param tableName 表å |
| | | * @return ä¸å¡å |
| | | */ |
| | | public static String getBusinessName(String tableName) |
| | | { |
| | | int lastIndex = tableName.lastIndexOf("_"); |
| | | int nameLength = tableName.length(); |
| | | return StringUtils.substring(tableName, lastIndex + 1, nameLength); |
| | | } |
| | | |
| | | /** |
| | | * 表åè½¬æ¢æJavaç±»å |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return ç±»å |
| | | */ |
| | | public static String convertClassName(String tableName) |
| | | { |
| | | boolean autoRemovePre = GenConfig.getAutoRemovePre(); |
| | | String tablePrefix = GenConfig.getTablePrefix(); |
| | | if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) |
| | | { |
| | | String[] searchList = StringUtils.split(tablePrefix, ","); |
| | | tableName = replaceFirst(tableName, searchList); |
| | | } |
| | | return StringUtils.convertToCamelCase(tableName); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éæ¿æ¢åç¼ |
| | | * |
| | | * @param replacementm æ¿æ¢å¼ |
| | | * @param searchList æ¿æ¢å表 |
| | | * @return |
| | | */ |
| | | public static String replaceFirst(String replacementm, String[] searchList) |
| | | { |
| | | String text = replacementm; |
| | | for (String searchString : searchList) |
| | | { |
| | | if (replacementm.startsWith(searchString)) |
| | | { |
| | | text = replacementm.replaceFirst(searchString, ""); |
| | | break; |
| | | } |
| | | } |
| | | return text; |
| | | } |
| | | |
| | | /** |
| | | * å
³é®åæ¿æ¢ |
| | | * |
| | | * @param text éè¦è¢«æ¿æ¢çåå |
| | | * @return æ¿æ¢åçåå |
| | | */ |
| | | public static String replaceText(String text) |
| | | { |
| | | return RegExUtils.replaceAll(text, "(?:表|è¥ä¾)", ""); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ°æ®åºç±»ååæ®µ |
| | | * |
| | | * @param columnType åç±»å |
| | | * @return æªååçåç±»å |
| | | */ |
| | | public static String getDbType(String columnType) |
| | | { |
| | | if (StringUtils.indexOf(columnType, "(") > 0) |
| | | { |
| | | return StringUtils.substringBefore(columnType, "("); |
| | | } |
| | | else |
| | | { |
| | | return columnType; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ®µé¿åº¦ |
| | | * |
| | | * @param columnType åç±»å |
| | | * @return æªååçåç±»å |
| | | */ |
| | | public static Integer getColumnLength(String columnType) |
| | | { |
| | | if (StringUtils.indexOf(columnType, "(") > 0) |
| | | { |
| | | String length = StringUtils.substringBetween(columnType, "(", ")"); |
| | | return Integer.valueOf(length); |
| | | } |
| | | else |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.util; |
| | | |
| | | import java.util.Properties; |
| | | import org.apache.velocity.app.Velocity; |
| | | import com.se.common.core.constant.Constants; |
| | | |
| | | /** |
| | | * VelocityEngineå·¥å |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class VelocityInitializer |
| | | { |
| | | /** |
| | | * åå§åvmæ¹æ³ |
| | | */ |
| | | public static void initVelocity() |
| | | { |
| | | Properties p = new Properties(); |
| | | try |
| | | { |
| | | // å è½½classpathç®å½ä¸çvmæä»¶ |
| | | p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); |
| | | // å®ä¹å符é |
| | | p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8); |
| | | // åå§åVelocityå¼æï¼æå®é
ç½®Properties |
| | | Velocity.init(p); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gen.util; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import com.se.gen.domain.GenTableColumn; |
| | | import org.apache.velocity.VelocityContext; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.se.common.core.constant.GenConstants; |
| | | import com.se.common.core.utils.DateUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.gen.domain.GenTable; |
| | | |
| | | /** |
| | | * 模æ¿å·¥å
·ç±» |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class VelocityUtils |
| | | { |
| | | /** 项ç®ç©ºé´è·¯å¾ */ |
| | | private static final String PROJECT_PATH = "main/java"; |
| | | |
| | | /** mybatis空é´è·¯å¾ */ |
| | | private static final String MYBATIS_PATH = "main/resources/mapper"; |
| | | |
| | | /** é»è®¤ä¸çº§èåï¼ç³»ç»å·¥å
· */ |
| | | private static final String DEFAULT_PARENT_MENU_ID = "3"; |
| | | |
| | | /** |
| | | * 设置模æ¿åéä¿¡æ¯ |
| | | * |
| | | * @return 模æ¿å表 |
| | | */ |
| | | public static VelocityContext prepareContext(GenTable genTable) |
| | | { |
| | | String moduleName = genTable.getModuleName(); |
| | | String businessName = genTable.getBusinessName(); |
| | | String packageName = genTable.getPackageName(); |
| | | String tplCategory = genTable.getTplCategory(); |
| | | String functionName = genTable.getFunctionName(); |
| | | |
| | | VelocityContext velocityContext = new VelocityContext(); |
| | | velocityContext.put("tplCategory", genTable.getTplCategory()); |
| | | velocityContext.put("tableName", genTable.getTableName()); |
| | | velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "ã请填ååè½åç§°ã"); |
| | | velocityContext.put("ClassName", genTable.getClassName()); |
| | | velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); |
| | | velocityContext.put("moduleName", genTable.getModuleName()); |
| | | velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); |
| | | velocityContext.put("businessName", genTable.getBusinessName()); |
| | | velocityContext.put("basePackage", getPackagePrefix(packageName)); |
| | | velocityContext.put("packageName", packageName); |
| | | velocityContext.put("author", genTable.getFunctionAuthor()); |
| | | velocityContext.put("datetime", DateUtils.getDate()); |
| | | velocityContext.put("pkColumn", genTable.getPkColumn()); |
| | | velocityContext.put("importList", getImportList(genTable)); |
| | | velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); |
| | | velocityContext.put("columns", genTable.getColumns()); |
| | | velocityContext.put("table", genTable); |
| | | velocityContext.put("dicts", getDicts(genTable)); |
| | | setMenuVelocityContext(velocityContext, genTable); |
| | | if (GenConstants.TPL_TREE.equals(tplCategory)) |
| | | { |
| | | setTreeVelocityContext(velocityContext, genTable); |
| | | } |
| | | if (GenConstants.TPL_SUB.equals(tplCategory)) |
| | | { |
| | | setSubVelocityContext(velocityContext, genTable); |
| | | } |
| | | return velocityContext; |
| | | } |
| | | |
| | | public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSON.parseObject(options); |
| | | String parentMenuId = getParentMenuId(paramsObj); |
| | | context.put("parentMenuId", parentMenuId); |
| | | } |
| | | |
| | | public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSON.parseObject(options); |
| | | String treeCode = getTreecode(paramsObj); |
| | | String treeParentCode = getTreeParentCode(paramsObj); |
| | | String treeName = getTreeName(paramsObj); |
| | | |
| | | context.put("treeCode", treeCode); |
| | | context.put("treeParentCode", treeParentCode); |
| | | context.put("treeName", treeName); |
| | | context.put("expandColumn", getExpandColumn(genTable)); |
| | | if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | } |
| | | if (paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); |
| | | } |
| | | } |
| | | |
| | | public static void setSubVelocityContext(VelocityContext context, GenTable genTable) |
| | | { |
| | | GenTable subTable = genTable.getSubTable(); |
| | | String subTableName = genTable.getSubTableName(); |
| | | String subTableFkName = genTable.getSubTableFkName(); |
| | | String subClassName = genTable.getSubTable().getClassName(); |
| | | String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); |
| | | |
| | | context.put("subTable", subTable); |
| | | context.put("subTableName", subTableName); |
| | | context.put("subTableFkName", subTableFkName); |
| | | context.put("subTableFkClassName", subTableFkClassName); |
| | | context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); |
| | | context.put("subClassName", subClassName); |
| | | context.put("subclassName", StringUtils.uncapitalize(subClassName)); |
| | | context.put("subImportList", getImportList(genTable.getSubTable())); |
| | | } |
| | | |
| | | /** |
| | | * è·å模æ¿ä¿¡æ¯ |
| | | * @param tplCategory çæçæ¨¡æ¿ |
| | | * @param tplWebType å端类å |
| | | * @return 模æ¿å表 |
| | | */ |
| | | public static List<String> getTemplateList(String tplCategory, String tplWebType) |
| | | { |
| | | String useWebType = "vm/vue"; |
| | | if ("element-plus".equals(tplWebType)) |
| | | { |
| | | useWebType = "vm/vue/v3"; |
| | | } |
| | | List<String> templates = new ArrayList<String>(); |
| | | templates.add("vm/java/domain.java.vm"); |
| | | templates.add("vm/java/mapper.java.vm"); |
| | | templates.add("vm/java/service.java.vm"); |
| | | templates.add("vm/java/serviceImpl.java.vm"); |
| | | templates.add("vm/java/controller.java.vm"); |
| | | templates.add("vm/xml/mapper.xml.vm"); |
| | | templates.add("vm/sql/sql.vm"); |
| | | templates.add("vm/js/api.js.vm"); |
| | | if (GenConstants.TPL_CRUD.equals(tplCategory)) |
| | | { |
| | | templates.add(useWebType + "/index.vue.vm"); |
| | | } |
| | | else if (GenConstants.TPL_TREE.equals(tplCategory)) |
| | | { |
| | | templates.add(useWebType + "/index-tree.vue.vm"); |
| | | } |
| | | else if (GenConstants.TPL_SUB.equals(tplCategory)) |
| | | { |
| | | templates.add(useWebType + "/index.vue.vm"); |
| | | templates.add("vm/java/sub-domain.java.vm"); |
| | | } |
| | | return templates; |
| | | } |
| | | |
| | | /** |
| | | * è·åæä»¶å |
| | | */ |
| | | public static String getFileName(String template, GenTable genTable) |
| | | { |
| | | // æä»¶åç§° |
| | | String fileName = ""; |
| | | // å
è·¯å¾ |
| | | String packageName = genTable.getPackageName(); |
| | | // 模åå |
| | | String moduleName = genTable.getModuleName(); |
| | | // 大åç±»å |
| | | String className = genTable.getClassName(); |
| | | // ä¸å¡åç§° |
| | | String businessName = genTable.getBusinessName(); |
| | | |
| | | String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); |
| | | String mybatisPath = MYBATIS_PATH + "/" + moduleName; |
| | | String vuePath = "vue"; |
| | | |
| | | if (template.contains("domain.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); |
| | | } |
| | | if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) |
| | | { |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); |
| | | } |
| | | else if (template.contains("mapper.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); |
| | | } |
| | | else if (template.contains("service.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); |
| | | } |
| | | else if (template.contains("serviceImpl.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); |
| | | } |
| | | else if (template.contains("controller.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); |
| | | } |
| | | else if (template.contains("mapper.xml.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); |
| | | } |
| | | else if (template.contains("sql.vm")) |
| | | { |
| | | fileName = businessName + "Menu.sql"; |
| | | } |
| | | else if (template.contains("api.js.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index.vue.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index-tree.vue.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | return fileName; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
åç¼ |
| | | * |
| | | * @param packageName å
åç§° |
| | | * @return å
åç¼åç§° |
| | | */ |
| | | public static String getPackagePrefix(String packageName) |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | return StringUtils.substring(packageName, 0, lastIndex); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åç±»åè·å导å
¥å
|
| | | * |
| | | * @param genTable ä¸å¡è¡¨å¯¹è±¡ |
| | | * @return è¿åéè¦å¯¼å
¥çå
å表 |
| | | */ |
| | | public static HashSet<String> getImportList(GenTable genTable) |
| | | { |
| | | List<GenTableColumn> columns = genTable.getColumns(); |
| | | GenTable subGenTable = genTable.getSubTable(); |
| | | HashSet<String> importList = new HashSet<String>(); |
| | | if (StringUtils.isNotNull(subGenTable)) |
| | | { |
| | | importList.add("java.util.List"); |
| | | } |
| | | for (GenTableColumn column : columns) |
| | | { |
| | | if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) |
| | | { |
| | | importList.add("java.util.Date"); |
| | | importList.add("com.fasterxml.jackson.annotation.JsonFormat"); |
| | | } |
| | | else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) |
| | | { |
| | | importList.add("java.math.BigDecimal"); |
| | | } |
| | | } |
| | | return importList; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åç±»åè·ååå
¸ç» |
| | | * |
| | | * @param genTable ä¸å¡è¡¨å¯¹è±¡ |
| | | * @return è¿ååå
¸ç» |
| | | */ |
| | | public static String getDicts(GenTable genTable) |
| | | { |
| | | List<GenTableColumn> columns = genTable.getColumns(); |
| | | Set<String> dicts = new HashSet<String>(); |
| | | addDicts(dicts, columns); |
| | | if (StringUtils.isNotNull(genTable.getSubTable())) |
| | | { |
| | | List<GenTableColumn> subColumns = genTable.getSubTable().getColumns(); |
| | | addDicts(dicts, subColumns); |
| | | } |
| | | return StringUtils.join(dicts, ", "); |
| | | } |
| | | |
| | | /** |
| | | * æ·»å åå
¸å表 |
| | | * |
| | | * @param dicts åå
¸å表 |
| | | * @param columns åéå |
| | | */ |
| | | public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) |
| | | { |
| | | for (GenTableColumn column : columns) |
| | | { |
| | | if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( |
| | | column.getHtmlType(), |
| | | new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) |
| | | { |
| | | dicts.add("'" + column.getDictType() + "'"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæéåç¼ |
| | | * |
| | | * @param moduleName 模ååç§° |
| | | * @param businessName ä¸å¡åç§° |
| | | * @return è¿åæéåç¼ |
| | | */ |
| | | public static String getPermissionPrefix(String moduleName, String businessName) |
| | | { |
| | | return StringUtils.format("{}:{}", moduleName, businessName); |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸çº§èåIDåæ®µ |
| | | * |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return ä¸çº§èåIDåæ®µ |
| | | */ |
| | | public static String getParentMenuId(JSONObject paramsObj) |
| | | { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) |
| | | && StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) |
| | | { |
| | | return paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | } |
| | | return DEFAULT_PARENT_MENU_ID; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ ç¼ç |
| | | * |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ ç¼ç |
| | | */ |
| | | public static String getTreecode(JSONObject paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_CODE)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ ç¶ç¼ç |
| | | * |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ ç¶ç¼ç |
| | | */ |
| | | public static String getTreeParentCode(JSONObject paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ åç§° |
| | | * |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ åç§° |
| | | */ |
| | | public static String getTreeName(JSONObject paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | | * è·åéè¦å¨åªä¸åä¸é¢æ¾ç¤ºå±å¼æé® |
| | | * |
| | | * @param genTable ä¸å¡è¡¨å¯¹è±¡ |
| | | * @return å±å¼æé®ååºå· |
| | | */ |
| | | public static int getExpandColumn(GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSON.parseObject(options); |
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME); |
| | | int num = 0; |
| | | for (GenTableColumn column : genTable.getColumns()) |
| | | { |
| | | if (column.isList()) |
| | | { |
| | | num++; |
| | | String columnName = column.getColumnName(); |
| | | if (columnName.equals(treeName)) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return num; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?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="com.se.gen.mapper.GenTableColumnMapper"> |
| | | |
| | | <resultMap type="GenTableColumn" id="GenTableColumnResult"> |
| | | <id property="columnId" column="column_id" /> |
| | | <result property="tableId" column="table_id" /> |
| | | <result property="columnName" column="column_name" /> |
| | | <result property="columnComment" column="column_comment" /> |
| | | <result property="columnType" column="column_type" /> |
| | | <result property="javaType" column="java_type" /> |
| | | <result property="javaField" column="java_field" /> |
| | | <result property="isPk" column="is_pk" /> |
| | | <result property="isIncrement" column="is_increment" /> |
| | | <result property="isRequired" column="is_required" /> |
| | | <result property="isInsert" column="is_insert" /> |
| | | <result property="isEdit" column="is_edit" /> |
| | | <result property="isList" column="is_list" /> |
| | | <result property="isQuery" column="is_query" /> |
| | | <result property="queryType" column="query_type" /> |
| | | <result property="htmlType" column="html_type" /> |
| | | <result property="dictType" column="dict_type" /> |
| | | <result property="sort" column="sort" /> |
| | | <result property="createBy" column="create_by" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectGenTableColumnVo"> |
| | | select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column |
| | | </sql> |
| | | |
| | | <select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult"> |
| | | <include refid="selectGenTableColumnVo"/> |
| | | where table_id = #{tableId} |
| | | order by sort |
| | | </select> |
| | | |
| | | <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> |
| | | select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type |
| | | from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) |
| | | order by ordinal_position |
| | | </select> |
| | | |
| | | <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> |
| | | insert into gen_table_column ( |
| | | <if test="tableId != null and tableId != ''">table_id,</if> |
| | | <if test="columnName != null and columnName != ''">column_name,</if> |
| | | <if test="columnComment != null and columnComment != ''">column_comment,</if> |
| | | <if test="columnType != null and columnType != ''">column_type,</if> |
| | | <if test="javaType != null and javaType != ''">java_type,</if> |
| | | <if test="javaField != null and javaField != ''">java_field,</if> |
| | | <if test="isPk != null and isPk != ''">is_pk,</if> |
| | | <if test="isIncrement != null and isIncrement != ''">is_increment,</if> |
| | | <if test="isRequired != null and isRequired != ''">is_required,</if> |
| | | <if test="isInsert != null and isInsert != ''">is_insert,</if> |
| | | <if test="isEdit != null and isEdit != ''">is_edit,</if> |
| | | <if test="isList != null and isList != ''">is_list,</if> |
| | | <if test="isQuery != null and isQuery != ''">is_query,</if> |
| | | <if test="queryType != null and queryType != ''">query_type,</if> |
| | | <if test="htmlType != null and htmlType != ''">html_type,</if> |
| | | <if test="dictType != null and dictType != ''">dict_type,</if> |
| | | <if test="sort != null">sort,</if> |
| | | <if test="createBy != null and createBy != ''">create_by,</if> |
| | | create_time |
| | | )values( |
| | | <if test="tableId != null and tableId != ''">#{tableId},</if> |
| | | <if test="columnName != null and columnName != ''">#{columnName},</if> |
| | | <if test="columnComment != null and columnComment != ''">#{columnComment},</if> |
| | | <if test="columnType != null and columnType != ''">#{columnType},</if> |
| | | <if test="javaType != null and javaType != ''">#{javaType},</if> |
| | | <if test="javaField != null and javaField != ''">#{javaField},</if> |
| | | <if test="isPk != null and isPk != ''">#{isPk},</if> |
| | | <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> |
| | | <if test="isRequired != null and isRequired != ''">#{isRequired},</if> |
| | | <if test="isInsert != null and isInsert != ''">#{isInsert},</if> |
| | | <if test="isEdit != null and isEdit != ''">#{isEdit},</if> |
| | | <if test="isList != null and isList != ''">#{isList},</if> |
| | | <if test="isQuery != null and isQuery != ''">#{isQuery},</if> |
| | | <if test="queryType != null and queryType != ''">#{queryType},</if> |
| | | <if test="htmlType != null and htmlType != ''">#{htmlType},</if> |
| | | <if test="dictType != null and dictType != ''">#{dictType},</if> |
| | | <if test="sort != null">#{sort},</if> |
| | | <if test="createBy != null and createBy != ''">#{createBy},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <update id="updateGenTableColumn" parameterType="GenTableColumn"> |
| | | update gen_table_column |
| | | <set> |
| | | <if test="columnComment != null">column_comment = #{columnComment},</if> |
| | | <if test="javaType != null">java_type = #{javaType},</if> |
| | | <if test="javaField != null">java_field = #{javaField},</if> |
| | | <if test="isInsert != null">is_insert = #{isInsert},</if> |
| | | <if test="isEdit != null">is_edit = #{isEdit},</if> |
| | | <if test="isList != null">is_list = #{isList},</if> |
| | | <if test="isQuery != null">is_query = #{isQuery},</if> |
| | | <if test="isRequired != null">is_required = #{isRequired},</if> |
| | | <if test="queryType != null">query_type = #{queryType},</if> |
| | | <if test="htmlType != null">html_type = #{htmlType},</if> |
| | | <if test="dictType != null">dict_type = #{dictType},</if> |
| | | <if test="sort != null">sort = #{sort},</if> |
| | | <if test="updateBy != null">update_by = #{updateBy},</if> |
| | | update_time = sysdate() |
| | | </set> |
| | | where column_id = #{columnId} |
| | | </update> |
| | | |
| | | <delete id="deleteGenTableColumnByIds" parameterType="Long"> |
| | | delete from gen_table_column where table_id in |
| | | <foreach collection="array" item="tableId" open="(" separator="," close=")"> |
| | | #{tableId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <delete id="deleteGenTableColumns"> |
| | | delete from gen_table_column where column_id in |
| | | <foreach collection="list" item="item" open="(" separator="," close=")"> |
| | | #{item.columnId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?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="com.se.gen.mapper.GenTableMapper"> |
| | | |
| | | <resultMap type="GenTable" id="GenTableResult"> |
| | | <id property="tableId" column="table_id" /> |
| | | <result property="tableName" column="table_name" /> |
| | | <result property="tableComment" column="table_comment" /> |
| | | <result property="subTableName" column="sub_table_name" /> |
| | | <result property="subTableFkName" column="sub_table_fk_name" /> |
| | | <result property="className" column="class_name" /> |
| | | <result property="tplCategory" column="tpl_category" /> |
| | | <result property="tplWebType" column="tpl_web_type" /> |
| | | <result property="packageName" column="package_name" /> |
| | | <result property="moduleName" column="module_name" /> |
| | | <result property="businessName" column="business_name" /> |
| | | <result property="functionName" column="function_name" /> |
| | | <result property="functionAuthor" column="function_author" /> |
| | | <result property="genType" column="gen_type" /> |
| | | <result property="genPath" column="gen_path" /> |
| | | <result property="options" column="options" /> |
| | | <result property="createBy" column="create_by" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | <result property="remark" column="remark" /> |
| | | <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" /> |
| | | </resultMap> |
| | | |
| | | <resultMap type="GenTableColumn" id="GenTableColumnResult"> |
| | | <id property="columnId" column="column_id" /> |
| | | <result property="tableId" column="table_id" /> |
| | | <result property="columnName" column="column_name" /> |
| | | <result property="columnComment" column="column_comment" /> |
| | | <result property="columnType" column="column_type" /> |
| | | <result property="javaType" column="java_type" /> |
| | | <result property="javaField" column="java_field" /> |
| | | <result property="isPk" column="is_pk" /> |
| | | <result property="isIncrement" column="is_increment" /> |
| | | <result property="isRequired" column="is_required" /> |
| | | <result property="isInsert" column="is_insert" /> |
| | | <result property="isEdit" column="is_edit" /> |
| | | <result property="isList" column="is_list" /> |
| | | <result property="isQuery" column="is_query" /> |
| | | <result property="queryType" column="query_type" /> |
| | | <result property="htmlType" column="html_type" /> |
| | | <result property="dictType" column="dict_type" /> |
| | | <result property="sort" column="sort" /> |
| | | <result property="createBy" column="create_by" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectGenTableVo"> |
| | | select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table |
| | | </sql> |
| | | |
| | | <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> |
| | | <include refid="selectGenTableVo"/> |
| | | <where> |
| | | <if test="tableName != null and tableName != ''"> |
| | | AND lower(table_name) like lower(concat('%', #{tableName}, '%')) |
| | | </if> |
| | | <if test="tableComment != null and tableComment != ''"> |
| | | AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) |
| | | </if> |
| | | <if test="params.beginTime != null and params.beginTime != ''"><!-- å¼å§æ¶é´æ£ç´¢ --> |
| | | AND date_format(create_time,'%Y%m%d') >= date_format(#{params.beginTime},'%Y%m%d') |
| | | </if> |
| | | <if test="params.endTime != null and params.endTime != ''"><!-- ç»ææ¶é´æ£ç´¢ --> |
| | | AND date_format(create_time,'%Y%m%d') <= date_format(#{params.endTime},'%Y%m%d') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> |
| | | select table_name, table_comment, create_time, update_time from information_schema.tables |
| | | where table_schema = (select database()) |
| | | AND table_name NOT LIKE 'qrtz\_%' AND table_name NOT LIKE 'gen\_%' |
| | | AND table_name NOT IN (select table_name from gen_table) |
| | | <if test="tableName != null and tableName != ''"> |
| | | AND lower(table_name) like lower(concat('%', #{tableName}, '%')) |
| | | </if> |
| | | <if test="tableComment != null and tableComment != ''"> |
| | | AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) |
| | | </if> |
| | | <if test="params.beginTime != null and params.beginTime != ''"><!-- å¼å§æ¶é´æ£ç´¢ --> |
| | | AND date_format(create_time,'%Y%m%d') >= date_format(#{params.beginTime},'%Y%m%d') |
| | | </if> |
| | | <if test="params.endTime != null and params.endTime != ''"><!-- ç»ææ¶é´æ£ç´¢ --> |
| | | AND date_format(create_time,'%Y%m%d') <= date_format(#{params.endTime},'%Y%m%d') |
| | | </if> |
| | | order by create_time desc |
| | | </select> |
| | | |
| | | <select id="selectDbTableListByNames" resultMap="GenTableResult"> |
| | | select table_name, table_comment, create_time, update_time from information_schema.tables |
| | | where table_name NOT LIKE 'qrtz\_%' and table_name NOT LIKE 'gen\_%' and table_schema = (select database()) |
| | | and table_name in |
| | | <foreach collection="array" item="name" open="(" separator="," close=")"> |
| | | #{name} |
| | | </foreach> |
| | | </select> |
| | | |
| | | <select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> |
| | | select table_name, table_comment, create_time, update_time from information_schema.tables |
| | | where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database()) |
| | | and table_name = #{tableName} |
| | | </select> |
| | | |
| | | <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> |
| | | SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, |
| | | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort |
| | | FROM gen_table t |
| | | LEFT JOIN gen_table_column c ON t.table_id = c.table_id |
| | | where t.table_id = #{tableId} order by c.sort |
| | | </select> |
| | | |
| | | <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> |
| | | SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, |
| | | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort |
| | | FROM gen_table t |
| | | LEFT JOIN gen_table_column c ON t.table_id = c.table_id |
| | | where t.table_name = #{tableName} order by c.sort |
| | | </select> |
| | | |
| | | <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> |
| | | SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, |
| | | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort |
| | | FROM gen_table t |
| | | LEFT JOIN gen_table_column c ON t.table_id = c.table_id |
| | | order by c.sort |
| | | </select> |
| | | |
| | | <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> |
| | | insert into gen_table ( |
| | | <if test="tableName != null">table_name,</if> |
| | | <if test="tableComment != null and tableComment != ''">table_comment,</if> |
| | | <if test="className != null and className != ''">class_name,</if> |
| | | <if test="tplCategory != null and tplCategory != ''">tpl_category,</if> |
| | | <if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if> |
| | | <if test="packageName != null and packageName != ''">package_name,</if> |
| | | <if test="moduleName != null and moduleName != ''">module_name,</if> |
| | | <if test="businessName != null and businessName != ''">business_name,</if> |
| | | <if test="functionName != null and functionName != ''">function_name,</if> |
| | | <if test="functionAuthor != null and functionAuthor != ''">function_author,</if> |
| | | <if test="genType != null and genType != ''">gen_type,</if> |
| | | <if test="genPath != null and genPath != ''">gen_path,</if> |
| | | <if test="remark != null and remark != ''">remark,</if> |
| | | <if test="createBy != null and createBy != ''">create_by,</if> |
| | | create_time |
| | | )values( |
| | | <if test="tableName != null">#{tableName},</if> |
| | | <if test="tableComment != null and tableComment != ''">#{tableComment},</if> |
| | | <if test="className != null and className != ''">#{className},</if> |
| | | <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> |
| | | <if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if> |
| | | <if test="packageName != null and packageName != ''">#{packageName},</if> |
| | | <if test="moduleName != null and moduleName != ''">#{moduleName},</if> |
| | | <if test="businessName != null and businessName != ''">#{businessName},</if> |
| | | <if test="functionName != null and functionName != ''">#{functionName},</if> |
| | | <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> |
| | | <if test="genType != null and genType != ''">#{genType},</if> |
| | | <if test="genPath != null and genPath != ''">#{genPath},</if> |
| | | <if test="remark != null and remark != ''">#{remark},</if> |
| | | <if test="createBy != null and createBy != ''">#{createBy},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <update id="updateGenTable" parameterType="GenTable"> |
| | | update gen_table |
| | | <set> |
| | | <if test="tableName != null">table_name = #{tableName},</if> |
| | | <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> |
| | | <if test="subTableName != null">sub_table_name = #{subTableName},</if> |
| | | <if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if> |
| | | <if test="className != null and className != ''">class_name = #{className},</if> |
| | | <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> |
| | | <if test="genType != null and genType != ''">gen_type = #{genType},</if> |
| | | <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> |
| | | <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> |
| | | <if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if> |
| | | <if test="packageName != null and packageName != ''">package_name = #{packageName},</if> |
| | | <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> |
| | | <if test="businessName != null and businessName != ''">business_name = #{businessName},</if> |
| | | <if test="functionName != null and functionName != ''">function_name = #{functionName},</if> |
| | | <if test="options != null and options != ''">options = #{options},</if> |
| | | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| | | <if test="remark != null">remark = #{remark},</if> |
| | | update_time = sysdate() |
| | | </set> |
| | | where table_id = #{tableId} |
| | | </update> |
| | | |
| | | <delete id="deleteGenTableByIds" parameterType="Long"> |
| | | delete from gen_table where table_id in |
| | | <foreach collection="array" item="tableId" open="(" separator="," close=")"> |
| | | #{tableId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import com.se.common.security.annotation.EnableCustomConfig; |
| | | import com.se.common.security.annotation.EnableRyFeignClients; |
| | | import com.se.common.swagger.annotation.EnableCustomSwagger2; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableCustomConfig |
| | | @EnableCustomSwagger2 |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | public class SeJobApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeJobApplication.class, args); |
| | | System.out.println("(â¥â â¿â )ï¾ï¾ 宿¶ä»»å¡æ¨¡åå¯å¨æå á(´ڡ`á)ï¾ \n" + |
| | | " .-------. ____ __ \n" + |
| | | " | _ _ \\ \\ \\ / / \n" + |
| | | " | ( ' ) | \\ _. / ' \n" + |
| | | " |(_ o _) / _( )_ .' \n" + |
| | | " | (_,_).' __ ___(_ o _)' \n" + |
| | | " | |\\ \\ | || |(_,_)' \n" + |
| | | " | | \\ `' /| `-' / \n" + |
| | | " | | \\ / \\ / \n" + |
| | | " ''-' `'-' `-..-' "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.job.domain.SysJob; |
| | | import com.se.job.service.ISysJobService; |
| | | import com.se.job.util.ScheduleUtils; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.exception.job.TaskException; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.job.util.CronUtils; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/job") |
| | | public class SysJobController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysJobService jobService; |
| | | |
| | | /** |
| | | * æ¥è¯¢å®æ¶ä»»å¡å表 |
| | | */ |
| | | @RequiresPermissions("monitor:job:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysJob sysJob) |
| | | { |
| | | startPage(); |
| | | List<SysJob> list = jobService.selectJobList(sysJob); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导åºå®æ¶ä»»å¡å表 |
| | | */ |
| | | @RequiresPermissions("monitor:job:export") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysJob sysJob) |
| | | { |
| | | List<SysJob> list = jobService.selectJobList(sysJob); |
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); |
| | | util.exportExcel(response, list, "宿¶ä»»å¡"); |
| | | } |
| | | |
| | | /** |
| | | * è·å宿¶ä»»å¡è¯¦ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("monitor:job:query") |
| | | @GetMapping(value = "/{jobId}") |
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId) |
| | | { |
| | | return success(jobService.selectJobById(jobId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å®æ¶ä»»å¡ |
| | | */ |
| | | @RequiresPermissions("monitor:job:add") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(job.getCronExpression())) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼Cron表达å¼ä¸æ£ç¡®"); |
| | | } |
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS })) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'ldap(s)'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'http(s)'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串åå¨è¿è§"); |
| | | } |
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å¨ç½ååå
"); |
| | | } |
| | | job.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.insertJob(job)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹å®æ¶ä»»å¡ |
| | | */ |
| | | @RequiresPermissions("monitor:job:edit") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(job.getCronExpression())) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼Cron表达å¼ä¸æ£ç¡®"); |
| | | } |
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS })) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'ldap(s)'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'http(s)'è°ç¨"); |
| | | } |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串åå¨è¿è§"); |
| | | } |
| | | else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å¨ç½ååå
"); |
| | | } |
| | | job.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.updateJob(job)); |
| | | } |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡ç¶æä¿®æ¹ |
| | | */ |
| | | @RequiresPermissions("monitor:job:changeStatus") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | SysJob newJob = jobService.selectJobById(job.getJobId()); |
| | | newJob.setStatus(job.getStatus()); |
| | | return toAjax(jobService.changeStatus(newJob)); |
| | | } |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡ç«å³æ§è¡ä¸æ¬¡ |
| | | */ |
| | | @RequiresPermissions("monitor:job:changeStatus") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/run") |
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | boolean result = jobService.run(job); |
| | | return result ? success() : error("ä»»å¡ä¸åå¨æå·²è¿æï¼"); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å®æ¶ä»»å¡ |
| | | */ |
| | | @RequiresPermissions("monitor:job:remove") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{jobIds}") |
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException |
| | | { |
| | | jobService.deleteJobByIds(jobIds); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.job.domain.SysJobLog; |
| | | import com.se.job.service.ISysJobLogService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | |
| | | /** |
| | | * è°åº¦æ¥å¿æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/job/log") |
| | | public class SysJobLogController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysJobLogService jobLogService; |
| | | |
| | | /** |
| | | * æ¥è¯¢å®æ¶ä»»å¡è°åº¦æ¥å¿å表 |
| | | */ |
| | | @RequiresPermissions("monitor:job:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysJobLog sysJobLog) |
| | | { |
| | | startPage(); |
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导åºå®æ¶ä»»å¡è°åº¦æ¥å¿å表 |
| | | */ |
| | | @RequiresPermissions("monitor:job:export") |
| | | @Log(title = "ä»»å¡è°åº¦æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysJobLog sysJobLog) |
| | | { |
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| | | ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); |
| | | util.exportExcel(response, list, "è°åº¦æ¥å¿"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è°åº¦ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("monitor:job:query") |
| | | @GetMapping(value = "/{jobLogId}") |
| | | public AjaxResult getInfo(@PathVariable Long jobLogId) |
| | | { |
| | | return success(jobLogService.selectJobLogById(jobLogId)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å®æ¶ä»»å¡è°åº¦æ¥å¿ |
| | | */ |
| | | @RequiresPermissions("monitor:job:remove") |
| | | @Log(title = "宿¶ä»»å¡è°åº¦æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{jobLogIds}") |
| | | public AjaxResult remove(@PathVariable Long[] jobLogIds) |
| | | { |
| | | return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
ç©ºå®æ¶ä»»å¡è°åº¦æ¥å¿ |
| | | */ |
| | | @RequiresPermissions("monitor:job:remove") |
| | | @Log(title = "è°åº¦æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | jobLogService.cleanJobLog(); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.domain; |
| | | |
| | | import java.util.Date; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.se.common.core.annotation.Excel; |
| | | import com.se.common.core.annotation.Excel.ColumnType; |
| | | import com.se.common.core.constant.ScheduleConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | import com.se.job.util.CronUtils; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦è¡¨ sys_job |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysJob extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ä»»å¡ID */ |
| | | @Excel(name = "ä»»å¡åºå·", cellType = ColumnType.NUMERIC) |
| | | private Long jobId; |
| | | |
| | | /** ä»»å¡åç§° */ |
| | | @Excel(name = "ä»»å¡åç§°") |
| | | private String jobName; |
| | | |
| | | /** ä»»å¡ç»å */ |
| | | @Excel(name = "ä»»å¡ç»å") |
| | | private String jobGroup; |
| | | |
| | | /** è°ç¨ç®æ å符串 */ |
| | | @Excel(name = "è°ç¨ç®æ å符串") |
| | | private String invokeTarget; |
| | | |
| | | /** cronæ§è¡è¡¨è¾¾å¼ */ |
| | | @Excel(name = "æ§è¡è¡¨è¾¾å¼ ") |
| | | private String cronExpression; |
| | | |
| | | /** cron计åçç¥ */ |
| | | @Excel(name = "计åçç¥ ", readConverterExp = "0=é»è®¤,1=ç«å³è§¦åæ§è¡,2=触å䏿¬¡æ§è¡,3=ä¸è§¦åç«å³æ§è¡") |
| | | private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT; |
| | | |
| | | /** æ¯å¦å¹¶åæ§è¡ï¼0å
许 1ç¦æ¢ï¼ */ |
| | | @Excel(name = "å¹¶åæ§è¡", readConverterExp = "0=å
许,1=ç¦æ¢") |
| | | private String concurrent; |
| | | |
| | | /** ä»»å¡ç¶æï¼0æ£å¸¸ 1æåï¼ */ |
| | | @Excel(name = "ä»»å¡ç¶æ", readConverterExp = "0=æ£å¸¸,1=æå") |
| | | private String status; |
| | | |
| | | public Long getJobId() |
| | | { |
| | | return jobId; |
| | | } |
| | | |
| | | public void setJobId(Long jobId) |
| | | { |
| | | this.jobId = jobId; |
| | | } |
| | | |
| | | @NotBlank(message = "ä»»å¡åç§°ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 64, message = "ä»»å¡åç§°ä¸è½è¶
è¿64个å符") |
| | | public String getJobName() |
| | | { |
| | | return jobName; |
| | | } |
| | | |
| | | public void setJobName(String jobName) |
| | | { |
| | | this.jobName = jobName; |
| | | } |
| | | |
| | | public String getJobGroup() |
| | | { |
| | | return jobGroup; |
| | | } |
| | | |
| | | public void setJobGroup(String jobGroup) |
| | | { |
| | | this.jobGroup = jobGroup; |
| | | } |
| | | |
| | | @NotBlank(message = "è°ç¨ç®æ å符串ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 500, message = "è°ç¨ç®æ å符串é¿åº¦ä¸è½è¶
è¿500个å符") |
| | | public String getInvokeTarget() |
| | | { |
| | | return invokeTarget; |
| | | } |
| | | |
| | | public void setInvokeTarget(String invokeTarget) |
| | | { |
| | | this.invokeTarget = invokeTarget; |
| | | } |
| | | |
| | | @NotBlank(message = "Cronæ§è¡è¡¨è¾¾å¼ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 255, message = "Cronæ§è¡è¡¨è¾¾å¼ä¸è½è¶
è¿255个å符") |
| | | public String getCronExpression() |
| | | { |
| | | return cronExpression; |
| | | } |
| | | |
| | | public void setCronExpression(String cronExpression) |
| | | { |
| | | this.cronExpression = cronExpression; |
| | | } |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | public Date getNextValidTime() |
| | | { |
| | | if (StringUtils.isNotEmpty(cronExpression)) |
| | | { |
| | | return CronUtils.getNextExecution(cronExpression); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getMisfirePolicy() |
| | | { |
| | | return misfirePolicy; |
| | | } |
| | | |
| | | public void setMisfirePolicy(String misfirePolicy) |
| | | { |
| | | this.misfirePolicy = misfirePolicy; |
| | | } |
| | | |
| | | public String getConcurrent() |
| | | { |
| | | return concurrent; |
| | | } |
| | | |
| | | public void setConcurrent(String concurrent) |
| | | { |
| | | this.concurrent = concurrent; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("jobId", getJobId()) |
| | | .append("jobName", getJobName()) |
| | | .append("jobGroup", getJobGroup()) |
| | | .append("cronExpression", getCronExpression()) |
| | | .append("nextValidTime", getNextValidTime()) |
| | | .append("misfirePolicy", getMisfirePolicy()) |
| | | .append("concurrent", getConcurrent()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.domain; |
| | | |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.se.common.core.annotation.Excel; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿è¡¨ sys_job_log |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysJobLog extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ID */ |
| | | @Excel(name = "æ¥å¿åºå·") |
| | | private Long jobLogId; |
| | | |
| | | /** ä»»å¡åç§° */ |
| | | @Excel(name = "ä»»å¡åç§°") |
| | | private String jobName; |
| | | |
| | | /** ä»»å¡ç»å */ |
| | | @Excel(name = "ä»»å¡ç»å") |
| | | private String jobGroup; |
| | | |
| | | /** è°ç¨ç®æ å符串 */ |
| | | @Excel(name = "è°ç¨ç®æ å符串") |
| | | private String invokeTarget; |
| | | |
| | | /** æ¥å¿ä¿¡æ¯ */ |
| | | @Excel(name = "æ¥å¿ä¿¡æ¯") |
| | | private String jobMessage; |
| | | |
| | | /** æ§è¡ç¶æï¼0æ£å¸¸ 1å¤±è´¥ï¼ */ |
| | | @Excel(name = "æ§è¡ç¶æ", readConverterExp = "0=æ£å¸¸,1=失败") |
| | | private String status; |
| | | |
| | | /** å¼å¸¸ä¿¡æ¯ */ |
| | | @Excel(name = "å¼å¸¸ä¿¡æ¯") |
| | | private String exceptionInfo; |
| | | |
| | | /** å¼å§æ¶é´ */ |
| | | private Date startTime; |
| | | |
| | | /** 忢æ¶é´ */ |
| | | private Date stopTime; |
| | | |
| | | public Long getJobLogId() |
| | | { |
| | | return jobLogId; |
| | | } |
| | | |
| | | public void setJobLogId(Long jobLogId) |
| | | { |
| | | this.jobLogId = jobLogId; |
| | | } |
| | | |
| | | public String getJobName() |
| | | { |
| | | return jobName; |
| | | } |
| | | |
| | | public void setJobName(String jobName) |
| | | { |
| | | this.jobName = jobName; |
| | | } |
| | | |
| | | public String getJobGroup() |
| | | { |
| | | return jobGroup; |
| | | } |
| | | |
| | | public void setJobGroup(String jobGroup) |
| | | { |
| | | this.jobGroup = jobGroup; |
| | | } |
| | | |
| | | public String getInvokeTarget() |
| | | { |
| | | return invokeTarget; |
| | | } |
| | | |
| | | public void setInvokeTarget(String invokeTarget) |
| | | { |
| | | this.invokeTarget = invokeTarget; |
| | | } |
| | | |
| | | public String getJobMessage() |
| | | { |
| | | return jobMessage; |
| | | } |
| | | |
| | | public void setJobMessage(String jobMessage) |
| | | { |
| | | this.jobMessage = jobMessage; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getExceptionInfo() |
| | | { |
| | | return exceptionInfo; |
| | | } |
| | | |
| | | public void setExceptionInfo(String exceptionInfo) |
| | | { |
| | | this.exceptionInfo = exceptionInfo; |
| | | } |
| | | |
| | | public Date getStartTime() |
| | | { |
| | | return startTime; |
| | | } |
| | | |
| | | public void setStartTime(Date startTime) |
| | | { |
| | | this.startTime = startTime; |
| | | } |
| | | |
| | | public Date getStopTime() |
| | | { |
| | | return stopTime; |
| | | } |
| | | |
| | | public void setStopTime(Date stopTime) |
| | | { |
| | | this.stopTime = stopTime; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("jobLogId", getJobLogId()) |
| | | .append("jobName", getJobName()) |
| | | .append("jobGroup", getJobGroup()) |
| | | .append("jobMessage", getJobMessage()) |
| | | .append("status", getStatus()) |
| | | .append("exceptionInfo", getExceptionInfo()) |
| | | .append("startTime", getStartTime()) |
| | | .append("stopTime", getStopTime()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.job.domain.SysJobLog; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡æ¥å¿ä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysJobLogMapper |
| | | { |
| | | /** |
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡æ¥å¿éå |
| | | */ |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè°åº¦ä»»å¡æ¥å¿ |
| | | * |
| | | * @return è°åº¦ä»»å¡æ¥å¿å表 |
| | | */ |
| | | public List<SysJobLog> selectJobLogAll(); |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID |
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJobLog selectJobLogById(Long jobLogId); |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertJobLog(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * |
| | | * @param logIds éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogByIds(Long[] logIds); |
| | | |
| | | /** |
| | | * å é¤ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobId è°åº¦æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogById(Long jobId); |
| | | |
| | | /** |
| | | * æ¸
ç©ºä»»å¡æ¥å¿ |
| | | */ |
| | | public void cleanJobLog(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.job.domain.SysJob; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡ä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysJobMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢è°åº¦ä»»å¡æ¥å¿éå |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return æä½æ¥å¿éå |
| | | */ |
| | | public List<SysJob> selectJobList(SysJob job); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè°åº¦ä»»å¡ |
| | | * |
| | | * @return è°åº¦ä»»å¡å表 |
| | | */ |
| | | public List<SysJob> selectJobAll(); |
| | | |
| | | /** |
| | | * éè¿è°åº¦IDæ¥è¯¢è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJob selectJobById(Long jobId); |
| | | |
| | | /** |
| | | * éè¿è°åº¦IDå é¤è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobById(Long jobId); |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobByIds(Long[] ids); |
| | | |
| | | /** |
| | | * ä¿®æ¹è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * |
| | | * @param job è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateJob(SysJob job); |
| | | |
| | | /** |
| | | * æ°å¢è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * |
| | | * @param job è°åº¦ä»»å¡ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertJob(SysJob job); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.job.domain.SysJobLog; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysJobLogService |
| | | { |
| | | /** |
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡æ¥å¿éå |
| | | */ |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID |
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJobLog selectJobLogById(Long jobLogId); |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | */ |
| | | public void addJobLog(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * |
| | | * @param logIds éè¦å é¤çæ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogByIds(Long[] logIds); |
| | | |
| | | /** |
| | | * å é¤ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobId è°åº¦æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogById(Long jobId); |
| | | |
| | | /** |
| | | * æ¸
ç©ºä»»å¡æ¥å¿ |
| | | */ |
| | | public void cleanJobLog(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.service; |
| | | |
| | | import java.util.List; |
| | | import org.quartz.SchedulerException; |
| | | import com.se.common.core.exception.job.TaskException; |
| | | import com.se.job.domain.SysJob; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysJobService |
| | | { |
| | | /** |
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡éå |
| | | */ |
| | | public List<SysJob> selectJobList(SysJob job); |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ä»»å¡ID |
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJob selectJobById(Long jobId); |
| | | |
| | | /** |
| | | * æåä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int pauseJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ¢å¤ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int resumeJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobIds éè¦å é¤çä»»å¡ID |
| | | * @return ç»æ |
| | | */ |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException; |
| | | |
| | | /** |
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int changeStatus(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * ç«å³è¿è¡ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean run(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ |
| | | * |
| | | * @param cronExpression è¡¨è¾¾å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkCronExpressionIsValid(String cronExpression); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.service; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.job.domain.SysJobLog; |
| | | import com.se.job.mapper.SysJobLogMapper; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysJobLogServiceImpl implements ISysJobLogService |
| | | { |
| | | @Autowired |
| | | private SysJobLogMapper jobLogMapper; |
| | | |
| | | /** |
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡æ¥å¿éå |
| | | */ |
| | | @Override |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) |
| | | { |
| | | return jobLogMapper.selectJobLogList(jobLog); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID |
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysJobLog selectJobLogById(Long jobLogId) |
| | | { |
| | | return jobLogMapper.selectJobLogById(jobLogId); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public void addJobLog(SysJobLog jobLog) |
| | | { |
| | | jobLogMapper.insertJobLog(jobLog); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * |
| | | * @param logIds éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteJobLogByIds(Long[] logIds) |
| | | { |
| | | return jobLogMapper.deleteJobLogByIds(logIds); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobId è°åº¦æ¥å¿ID |
| | | */ |
| | | @Override |
| | | public int deleteJobLogById(Long jobId) |
| | | { |
| | | return jobLogMapper.deleteJobLogById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
ç©ºä»»å¡æ¥å¿ |
| | | */ |
| | | @Override |
| | | public void cleanJobLog() |
| | | { |
| | | jobLogMapper.cleanJobLog(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.service; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.PostConstruct; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.se.common.core.constant.ScheduleConstants; |
| | | import com.se.common.core.exception.job.TaskException; |
| | | import com.se.job.domain.SysJob; |
| | | import com.se.job.mapper.SysJobMapper; |
| | | import com.se.job.util.CronUtils; |
| | | import com.se.job.util.ScheduleUtils; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysJobServiceImpl implements ISysJobService |
| | | { |
| | | @Autowired |
| | | private Scheduler scheduler; |
| | | |
| | | @Autowired |
| | | private SysJobMapper jobMapper; |
| | | |
| | | /** |
| | | * 项ç®å¯å¨æ¶ï¼åå§å宿¶å¨ ä¸»è¦æ¯é²æ¢æå¨ä¿®æ¹æ°æ®åºå¯¼è´æªåæ¥å°å®æ¶ä»»å¡å¤çï¼æ³¨ï¼ä¸è½æå¨ä¿®æ¹æ°æ®åºIDåä»»å¡ç»åï¼å¦åä¼å¯¼è´èæ°æ®ï¼ |
| | | */ |
| | | @PostConstruct |
| | | public void init() throws SchedulerException, TaskException |
| | | { |
| | | scheduler.clear(); |
| | | List<SysJob> jobList = jobMapper.selectJobAll(); |
| | | for (SysJob job : jobList) |
| | | { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡å表 |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SysJob> selectJobList(SysJob job) |
| | | { |
| | | return jobMapper.selectJobList(job); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ä»»å¡ID |
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysJob selectJobById(Long jobId) |
| | | { |
| | | return jobMapper.selectJobById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * æåä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int pauseJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ¢å¤ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int resumeJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | int rows = jobMapper.deleteJobById(jobId); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobIds éè¦å é¤çä»»å¡ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException |
| | | { |
| | | for (Long jobId : jobIds) |
| | | { |
| | | SysJob job = jobMapper.selectJobById(jobId); |
| | | deleteJob(job); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int changeStatus(SysJob job) throws SchedulerException |
| | | { |
| | | int rows = 0; |
| | | String status = job.getStatus(); |
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) |
| | | { |
| | | rows = resumeJob(job); |
| | | } |
| | | else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) |
| | | { |
| | | rows = pauseJob(job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * ç«å³è¿è¡ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean run(SysJob job) throws SchedulerException |
| | | { |
| | | boolean result = false; |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | // åæ° |
| | | JobDataMap dataMap = new JobDataMap(); |
| | | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); |
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| | | if (scheduler.checkExists(jobKey)) |
| | | { |
| | | result = true; |
| | | scheduler.triggerJob(jobKey, dataMap); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = jobMapper.insertJob(job); |
| | | if (rows > 0) |
| | | { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡çæ¶é´è¡¨è¾¾å¼ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | updateSchedulerJob(job, properties.getJobGroup()); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡ |
| | | * |
| | | * @param job ä»»å¡å¯¹è±¡ |
| | | * @param jobGroup ä»»å¡ç»å |
| | | */ |
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | // 夿æ¯å¦åå¨ |
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| | | if (scheduler.checkExists(jobKey)) |
| | | { |
| | | // 鲿¢å建æ¶å卿°æ®é®é¢ å
ç§»é¤ï¼ç¶å卿§è¡å建æä½ |
| | | scheduler.deleteJob(jobKey); |
| | | } |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ |
| | | * |
| | | * @param cronExpression è¡¨è¾¾å¼ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkCronExpressionIsValid(String cronExpression) |
| | | { |
| | | return CronUtils.isValid(cronExpression); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.task; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | import com.se.common.core.utils.StringUtils; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æµè¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component("ryTask") |
| | | public class RyTask |
| | | { |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) |
| | | { |
| | | System.out.println(StringUtils.format("æ§è¡å¤åæ¹æ³ï¼ å符串类å{}ï¼å¸å°ç±»å{}ï¼é¿æ´å{}ï¼æµ®ç¹å{}ï¼æ´å½¢{}", s, b, l, d, i)); |
| | | } |
| | | |
| | | public void ryParams(String params) |
| | | { |
| | | System.out.println("æ§è¡æåæ¹æ³ï¼" + params); |
| | | } |
| | | |
| | | public void ryNoParams() |
| | | { |
| | | System.out.println("æ§è¡æ åæ¹æ³"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import com.se.job.domain.SysJob; |
| | | import com.se.job.domain.SysJobLog; |
| | | import com.se.job.service.ISysJobLogService; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.se.common.core.constant.ScheduleConstants; |
| | | import com.se.common.core.utils.ExceptionUtil; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.bean.BeanUtils; |
| | | |
| | | /** |
| | | * æ½è±¡quartzè°ç¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public abstract class AbstractQuartzJob implements Job |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); |
| | | |
| | | /** |
| | | * çº¿ç¨æ¬å°åé |
| | | */ |
| | | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | SysJob sysJob = new SysJob(); |
| | | BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); |
| | | try |
| | | { |
| | | before(context, sysJob); |
| | | if (sysJob != null) |
| | | { |
| | | doExecute(context, sysJob); |
| | | } |
| | | after(context, sysJob, null); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("任塿§è¡å¼å¸¸ - ï¼", e); |
| | | after(context, sysJob, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | */ |
| | | protected void before(JobExecutionContext context, SysJob sysJob) |
| | | { |
| | | threadLocal.set(new Date()); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | */ |
| | | protected void after(JobExecutionContext context, SysJob sysJob, Exception e) |
| | | { |
| | | Date startTime = threadLocal.get(); |
| | | threadLocal.remove(); |
| | | |
| | | final SysJobLog sysJobLog = new SysJobLog(); |
| | | sysJobLog.setJobName(sysJob.getJobName()); |
| | | sysJobLog.setJobGroup(sysJob.getJobGroup()); |
| | | sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); |
| | | sysJobLog.setStartTime(startTime); |
| | | sysJobLog.setStopTime(new Date()); |
| | | long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); |
| | | sysJobLog.setJobMessage(sysJobLog.getJobName() + " æ»å
±èæ¶ï¼" + runMs + "毫ç§"); |
| | | if (e != null) |
| | | { |
| | | sysJobLog.setStatus("1"); |
| | | String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); |
| | | sysJobLog.setExceptionInfo(errorMsg); |
| | | } |
| | | else |
| | | { |
| | | sysJobLog.setStatus("0"); |
| | | } |
| | | |
| | | // åå
¥æ°æ®åºå½ä¸ |
| | | SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æ¹æ³ï¼ç±åç±»éè½½ |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | * @throws Exception æ§è¡è¿ç¨ä¸çå¼å¸¸ |
| | | */ |
| | | protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.Date; |
| | | import org.quartz.CronExpression; |
| | | |
| | | /** |
| | | * cron表达å¼å·¥å
·ç±» |
| | | * |
| | | * @author admin |
| | | * |
| | | */ |
| | | public class CronUtils |
| | | { |
| | | /** |
| | | * è¿åä¸ä¸ªå¸å°å¼ä»£è¡¨ä¸ä¸ªç»å®çCron表达å¼çæææ§ |
| | | * |
| | | * @param cronExpression Cronè¡¨è¾¾å¼ |
| | | * @return boolean è¡¨è¾¾å¼æ¯å¦ææ |
| | | */ |
| | | public static boolean isValid(String cronExpression) |
| | | { |
| | | return CronExpression.isValidExpression(cronExpression); |
| | | } |
| | | |
| | | /** |
| | | * è¿åä¸ä¸ªå符串å¼,è¡¨ç¤ºè¯¥æ¶æ¯æ æCron表达å¼ç»åºæææ§ |
| | | * |
| | | * @param cronExpression Cronè¡¨è¾¾å¼ |
| | | * @return String æ ææ¶è¿å表达å¼é误æè¿°,妿ææè¿ånull |
| | | */ |
| | | public static String getInvalidMessage(String cronExpression) |
| | | { |
| | | try |
| | | { |
| | | new CronExpression(cronExpression); |
| | | return null; |
| | | } |
| | | catch (ParseException pe) |
| | | { |
| | | return pe.getMessage(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¿åä¸ä¸ä¸ªæ§è¡æ¶é´æ ¹æ®ç»å®çCronè¡¨è¾¾å¼ |
| | | * |
| | | * @param cronExpression Cronè¡¨è¾¾å¼ |
| | | * @return Date 䏿¬¡Cronè¡¨è¾¾å¼æ§è¡æ¶é´ |
| | | */ |
| | | public static Date getNextExecution(String cronExpression) |
| | | { |
| | | try |
| | | { |
| | | CronExpression cron = new CronExpression(cronExpression); |
| | | return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); |
| | | } |
| | | catch (ParseException e) |
| | | { |
| | | throw new IllegalArgumentException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.job.domain.SysJob; |
| | | |
| | | /** |
| | | * 任塿§è¡å·¥å
· |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class JobInvokeUtil |
| | | { |
| | | /** |
| | | * æ§è¡æ¹æ³ |
| | | * |
| | | * @param sysJob ç³»ç»ä»»å¡ |
| | | */ |
| | | public static void invokeMethod(SysJob sysJob) throws Exception |
| | | { |
| | | String invokeTarget = sysJob.getInvokeTarget(); |
| | | String beanName = getBeanName(invokeTarget); |
| | | String methodName = getMethodName(invokeTarget); |
| | | List<Object[]> methodParams = getMethodParams(invokeTarget); |
| | | |
| | | if (!isValidClassName(beanName)) |
| | | { |
| | | Object bean = SpringUtils.getBean(beanName); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | else |
| | | { |
| | | Object bean = Class.forName(beanName).getDeclaredConstructor().newInstance(); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è°ç¨ä»»å¡æ¹æ³ |
| | | * |
| | | * @param bean ç®æ 对象 |
| | | * @param methodName æ¹æ³åç§° |
| | | * @param methodParams æ¹æ³åæ° |
| | | */ |
| | | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) |
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, |
| | | InvocationTargetException |
| | | { |
| | | if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) |
| | | { |
| | | Method method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams)); |
| | | method.invoke(bean, getMethodParamsValue(methodParams)); |
| | | } |
| | | else |
| | | { |
| | | Method method = bean.getClass().getMethod(methodName); |
| | | method.invoke(bean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ¯å¦ä¸ºä¸ºclasså
å |
| | | * |
| | | * @param invokeTarget åç§° |
| | | * @return trueæ¯ falseå¦ |
| | | */ |
| | | public static boolean isValidClassName(String invokeTarget) |
| | | { |
| | | return StringUtils.countMatches(invokeTarget, ".") > 1; |
| | | } |
| | | |
| | | /** |
| | | * è·åbeanåç§° |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return beanåç§° |
| | | */ |
| | | public static String getBeanName(String invokeTarget) |
| | | { |
| | | String beanName = StringUtils.substringBefore(invokeTarget, "("); |
| | | return StringUtils.substringBeforeLast(beanName, "."); |
| | | } |
| | | |
| | | /** |
| | | * è·åbeanæ¹æ³ |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return methodæ¹æ³ |
| | | */ |
| | | public static String getMethodName(String invokeTarget) |
| | | { |
| | | String methodName = StringUtils.substringBefore(invokeTarget, "("); |
| | | return StringUtils.substringAfterLast(methodName, "."); |
| | | } |
| | | |
| | | /** |
| | | * è·åmethodæ¹æ³åæ°ç¸å
³å表 |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return methodæ¹æ³ç¸å
³åæ°å表 |
| | | */ |
| | | public static List<Object[]> getMethodParams(String invokeTarget) |
| | | { |
| | | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); |
| | | if (StringUtils.isEmpty(methodStr)) |
| | | { |
| | | return null; |
| | | } |
| | | String[] methodParams = methodStr.split(",(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)"); |
| | | List<Object[]> classs = new LinkedList<>(); |
| | | for (int i = 0; i < methodParams.length; i++) |
| | | { |
| | | String str = StringUtils.trimToEmpty(methodParams[i]); |
| | | // Stringå符串类åï¼ä»¥'æ"å¼å¤´ |
| | | if (StringUtils.startsWithAny(str, "'", "\"")) |
| | | { |
| | | classs.add(new Object[] { StringUtils.substring(str, 1, str.length() - 1), String.class }); |
| | | } |
| | | // booleanå¸å°ç±»åï¼çäºtrueæè
false |
| | | else if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) |
| | | { |
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); |
| | | } |
| | | // longé¿æ´å½¢ï¼ä»¥Lç»å°¾ |
| | | else if (StringUtils.endsWith(str, "L")) |
| | | { |
| | | classs.add(new Object[] { Long.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Long.class }); |
| | | } |
| | | // doubleæµ®ç¹ç±»åï¼ä»¥Dç»å°¾ |
| | | else if (StringUtils.endsWith(str, "D")) |
| | | { |
| | | classs.add(new Object[] { Double.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Double.class }); |
| | | } |
| | | // å
¶ä»ç±»åå½ç±»ä¸ºæ´å½¢ |
| | | else |
| | | { |
| | | classs.add(new Object[] { Integer.valueOf(str), Integer.class }); |
| | | } |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ°ç±»å |
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表 |
| | | * @return åæ°ç±»åå表 |
| | | */ |
| | | public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) |
| | | { |
| | | Class<?>[] classs = new Class<?>[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Class<?>) os[1]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ°å¼ |
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表 |
| | | * @return åæ°å¼å表 |
| | | */ |
| | | public static Object[] getMethodParamsValue(List<Object[]> methodParams) |
| | | { |
| | | Object[] classs = new Object[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Object) os[0]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import com.se.job.domain.SysJob; |
| | | import org.quartz.DisallowConcurrentExecution; |
| | | import org.quartz.JobExecutionContext; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡å¤çï¼ç¦æ¢å¹¶åæ§è¡ï¼ |
| | | * |
| | | * @author admin |
| | | * |
| | | */ |
| | | @DisallowConcurrentExecution |
| | | public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob |
| | | { |
| | | @Override |
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception |
| | | { |
| | | JobInvokeUtil.invokeMethod(sysJob); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import com.se.job.domain.SysJob; |
| | | import org.quartz.JobExecutionContext; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡å¤çï¼å
è®¸å¹¶åæ§è¡ï¼ |
| | | * |
| | | * @author admin |
| | | * |
| | | */ |
| | | public class QuartzJobExecution extends AbstractQuartzJob |
| | | { |
| | | @Override |
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception |
| | | { |
| | | JobInvokeUtil.invokeMethod(sysJob); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.job.util; |
| | | |
| | | import com.se.job.domain.SysJob; |
| | | import org.quartz.CronScheduleBuilder; |
| | | import org.quartz.CronTrigger; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobBuilder; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.quartz.TriggerBuilder; |
| | | import org.quartz.TriggerKey; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.constant.ScheduleConstants; |
| | | import com.se.common.core.exception.job.TaskException; |
| | | import com.se.common.core.exception.job.TaskException.Code; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡å·¥å
·ç±» |
| | | * |
| | | * @author admin |
| | | * |
| | | */ |
| | | public class ScheduleUtils |
| | | { |
| | | /** |
| | | * å¾å°quartzä»»å¡ç±» |
| | | * |
| | | * @param sysJob æ§è¡è®¡å |
| | | * @return å
·ä½æ§è¡ä»»å¡ç±» |
| | | */ |
| | | private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) |
| | | { |
| | | boolean isConcurrent = "0".equals(sysJob.getConcurrent()); |
| | | return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; |
| | | } |
| | | |
| | | /** |
| | | * æå»ºä»»å¡è§¦å对象 |
| | | */ |
| | | public static TriggerKey getTriggerKey(Long jobId, String jobGroup) |
| | | { |
| | | return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); |
| | | } |
| | | |
| | | /** |
| | | * æå»ºä»»å¡é®å¯¹è±¡ |
| | | */ |
| | | public static JobKey getJobKey(Long jobId, String jobGroup) |
| | | { |
| | | return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); |
| | | } |
| | | |
| | | /** |
| | | * åå»ºå®æ¶ä»»å¡ |
| | | */ |
| | | public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | Class<? extends Job> jobClass = getQuartzJobClass(job); |
| | | // æå»ºjobä¿¡æ¯ |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); |
| | | |
| | | // 表达å¼è°åº¦æå»ºå¨ |
| | | CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); |
| | | cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); |
| | | |
| | | // ææ°çcronExpressionè¡¨è¾¾å¼æå»ºä¸ä¸ªæ°çtrigger |
| | | CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) |
| | | .withSchedule(cronScheduleBuilder).build(); |
| | | |
| | | // æ¾å
¥åæ°ï¼è¿è¡æ¶çæ¹æ³å¯ä»¥è·å |
| | | jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); |
| | | |
| | | // 夿æ¯å¦åå¨ |
| | | if (scheduler.checkExists(getJobKey(jobId, jobGroup))) |
| | | { |
| | | // 鲿¢å建æ¶å卿°æ®é®é¢ å
ç§»é¤ï¼ç¶å卿§è¡å建æä½ |
| | | scheduler.deleteJob(getJobKey(jobId, jobGroup)); |
| | | } |
| | | |
| | | // 夿任塿¯å¦è¿æ |
| | | if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression()))) |
| | | { |
| | | // æ§è¡è°åº¦ä»»å¡ |
| | | scheduler.scheduleJob(jobDetail, trigger); |
| | | } |
| | | |
| | | // æåä»»å¡ |
| | | if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) |
| | | { |
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¾ç½®å®æ¶ä»»å¡çç¥ |
| | | */ |
| | | public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) |
| | | throws TaskException |
| | | { |
| | | switch (job.getMisfirePolicy()) |
| | | { |
| | | case ScheduleConstants.MISFIRE_DEFAULT: |
| | | return cb; |
| | | case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: |
| | | return cb.withMisfireHandlingInstructionIgnoreMisfires(); |
| | | case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED: |
| | | return cb.withMisfireHandlingInstructionFireAndProceed(); |
| | | case ScheduleConstants.MISFIRE_DO_NOTHING: |
| | | return cb.withMisfireHandlingInstructionDoNothing(); |
| | | default: |
| | | throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() |
| | | + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥å
忝å¦ä¸ºç½ååé
ç½® |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean whiteList(String invokeTarget) |
| | | { |
| | | String packageName = StringUtils.substringBefore(invokeTarget, "("); |
| | | int count = StringUtils.countMatches(packageName, "."); |
| | | if (count > 1) |
| | | { |
| | | return StringUtils.containsAnyIgnoreCase(invokeTarget, Constants.JOB_WHITELIST_STR); |
| | | } |
| | | Object obj = SpringUtils.getBean(StringUtils.split(invokeTarget, ".")[0]); |
| | | String beanPackageName = obj.getClass().getPackage().getName(); |
| | | return StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_WHITELIST_STR) |
| | | && !StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_ERROR_STR); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import com.se.common.security.annotation.EnableCustomConfig; |
| | | import com.se.common.security.annotation.EnableRyFeignClients; |
| | | import com.se.common.swagger.annotation.EnableCustomSwagger2; |
| | | |
| | | /** |
| | | * ç³»ç»æ¨¡å |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableCustomConfig |
| | | @EnableCustomSwagger2 |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | public class RuoYiSystemApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(RuoYiSystemApplication.class, args); |
| | | System.out.println(" ç³»ç»æ¨¡åå¯å¨æå "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.system.domain.SysConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.service.ISysConfigService; |
| | | |
| | | /** |
| | | * åæ°é
ç½® ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/config") |
| | | public class SysConfigController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | /** |
| | | * è·ååæ°é
ç½®å表 |
| | | */ |
| | | @RequiresPermissions("system:config:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysConfig config) |
| | | { |
| | | startPage(); |
| | | List<SysConfig> list = configService.selectConfigList(config); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:config:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysConfig config) |
| | | { |
| | | List<SysConfig> list = configService.selectConfigList(config); |
| | | ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class); |
| | | util.exportExcel(response, list, "åæ°æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åæ°ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @GetMapping(value = "/{configId}") |
| | | public AjaxResult getInfo(@PathVariable Long configId) |
| | | { |
| | | return success(configService.selectConfigById(configId)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åæ°é®åæ¥è¯¢åæ°å¼ |
| | | */ |
| | | @GetMapping(value = "/configKey/{configKey}") |
| | | public AjaxResult getConfigKey(@PathVariable String configKey) |
| | | { |
| | | return success(configService.selectConfigByKey(configKey)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åæ°é
ç½® |
| | | */ |
| | | @RequiresPermissions("system:config:add") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysConfig config) |
| | | { |
| | | if (!configService.checkConfigKeyUnique(config)) |
| | | { |
| | | return error("æ°å¢åæ°'" + config.getConfigName() + "'失败ï¼åæ°é®åå·²åå¨"); |
| | | } |
| | | config.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(configService.insertConfig(config)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | */ |
| | | @RequiresPermissions("system:config:edit") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysConfig config) |
| | | { |
| | | if (!configService.checkConfigKeyUnique(config)) |
| | | { |
| | | return error("ä¿®æ¹åæ°'" + config.getConfigName() + "'失败ï¼åæ°é®åå·²åå¨"); |
| | | } |
| | | config.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(configService.updateConfig(config)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åæ°é
ç½® |
| | | */ |
| | | @RequiresPermissions("system:config:remove") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{configIds}") |
| | | public AjaxResult remove(@PathVariable Long[] configIds) |
| | | { |
| | | configService.deleteConfigByIds(configIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * å·æ°åæ°ç¼å |
| | | */ |
| | | @RequiresPermissions("system:config:remove") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/refreshCache") |
| | | public AjaxResult refreshCache() |
| | | { |
| | | configService.resetConfigCache(); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.service.ISysDeptService; |
| | | |
| | | /** |
| | | * é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/dept") |
| | | public class SysDeptController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | /** |
| | | * è·åé¨é¨å表 |
| | | */ |
| | | @RequiresPermissions("system:dept:list") |
| | | @GetMapping("/list") |
| | | public AjaxResult list(SysDept dept) |
| | | { |
| | | List<SysDept> depts = deptService.selectDeptList(dept); |
| | | return success(depts); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨åè¡¨ï¼æé¤èç¹ï¼ |
| | | */ |
| | | @RequiresPermissions("system:dept:list") |
| | | @GetMapping("/list/exclude/{deptId}") |
| | | public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) |
| | | { |
| | | List<SysDept> depts = deptService.selectDeptList(new SysDept()); |
| | | depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); |
| | | return success(depts); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é¨é¨ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:dept:query") |
| | | @GetMapping(value = "/{deptId}") |
| | | public AjaxResult getInfo(@PathVariable Long deptId) |
| | | { |
| | | deptService.checkDeptDataScope(deptId); |
| | | return success(deptService.selectDeptById(deptId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢é¨é¨ |
| | | */ |
| | | @RequiresPermissions("system:dept:add") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysDept dept) |
| | | { |
| | | if (!deptService.checkDeptNameUnique(dept)) |
| | | { |
| | | return error("æ°å¢é¨é¨'" + dept.getDeptName() + "'失败ï¼é¨é¨åç§°å·²åå¨"); |
| | | } |
| | | dept.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(deptService.insertDept(dept)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹é¨é¨ |
| | | */ |
| | | @RequiresPermissions("system:dept:edit") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysDept dept) |
| | | { |
| | | Long deptId = dept.getDeptId(); |
| | | deptService.checkDeptDataScope(deptId); |
| | | if (!deptService.checkDeptNameUnique(dept)) |
| | | { |
| | | return error("ä¿®æ¹é¨é¨'" + dept.getDeptName() + "'失败ï¼é¨é¨åç§°å·²åå¨"); |
| | | } |
| | | else if (dept.getParentId().equals(deptId)) |
| | | { |
| | | return error("ä¿®æ¹é¨é¨'" + dept.getDeptName() + "'失败ï¼ä¸çº§é¨é¨ä¸è½æ¯èªå·±"); |
| | | } |
| | | else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) |
| | | { |
| | | return error("该é¨é¨å
嫿ªåç¨çåé¨é¨ï¼"); |
| | | } |
| | | dept.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(deptService.updateDept(dept)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤é¨é¨ |
| | | */ |
| | | @RequiresPermissions("system:dept:remove") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{deptId}") |
| | | public AjaxResult remove(@PathVariable Long deptId) |
| | | { |
| | | if (deptService.hasChildByDeptId(deptId)) |
| | | { |
| | | return warn("åå¨ä¸çº§é¨é¨,ä¸å
许å é¤"); |
| | | } |
| | | if (deptService.checkDeptExistUser(deptId)) |
| | | { |
| | | return warn("é¨é¨åå¨ç¨æ·,ä¸å
许å é¤"); |
| | | } |
| | | deptService.checkDeptDataScope(deptId); |
| | | return toAjax(deptService.deleteDeptById(deptId)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDictData; |
| | | import com.se.system.service.ISysDictDataService; |
| | | import com.se.system.service.ISysDictTypeService; |
| | | |
| | | /** |
| | | * æ°æ®åå
¸ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/dict/data") |
| | | public class SysDictDataController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDictDataService dictDataService; |
| | | |
| | | @Autowired |
| | | private ISysDictTypeService dictTypeService; |
| | | |
| | | @RequiresPermissions("system:dict:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysDictData dictData) |
| | | { |
| | | startPage(); |
| | | List<SysDictData> list = dictDataService.selectDictDataList(dictData); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:dict:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysDictData dictData) |
| | | { |
| | | List<SysDictData> list = dictDataService.selectDictDataList(dictData); |
| | | ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class); |
| | | util.exportExcel(response, list, "åå
¸æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åå
¸æ°æ®è¯¦ç» |
| | | */ |
| | | @RequiresPermissions("system:dict:query") |
| | | @GetMapping(value = "/{dictCode}") |
| | | public AjaxResult getInfo(@PathVariable Long dictCode) |
| | | { |
| | | return success(dictDataService.selectDictDataById(dictCode)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢åå
¸æ°æ®ä¿¡æ¯ |
| | | */ |
| | | @GetMapping(value = "/type/{dictType}") |
| | | public AjaxResult dictType(@PathVariable String dictType) |
| | | { |
| | | List<SysDictData> data = dictTypeService.selectDictDataByType(dictType); |
| | | if (StringUtils.isNull(data)) |
| | | { |
| | | data = new ArrayList<SysDictData>(); |
| | | } |
| | | return success(data); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:add") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysDictData dict) |
| | | { |
| | | dict.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(dictDataService.insertDictData(dict)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:edit") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysDictData dict) |
| | | { |
| | | dict.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(dictDataService.updateDictData(dict)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictCodes}") |
| | | public AjaxResult remove(@PathVariable Long[] dictCodes) |
| | | { |
| | | dictDataService.deleteDictDataByIds(dictCodes); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDictType; |
| | | import com.se.system.service.ISysDictTypeService; |
| | | |
| | | /** |
| | | * æ°æ®åå
¸ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/dict/type") |
| | | public class SysDictTypeController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDictTypeService dictTypeService; |
| | | |
| | | @RequiresPermissions("system:dict:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysDictType dictType) |
| | | { |
| | | startPage(); |
| | | List<SysDictType> list = dictTypeService.selectDictTypeList(dictType); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:dict:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysDictType dictType) |
| | | { |
| | | List<SysDictType> list = dictTypeService.selectDictTypeList(dictType); |
| | | ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class); |
| | | util.exportExcel(response, list, "åå
¸ç±»å"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åå
¸ç±»åè¯¦ç» |
| | | */ |
| | | @RequiresPermissions("system:dict:query") |
| | | @GetMapping(value = "/{dictId}") |
| | | public AjaxResult getInfo(@PathVariable Long dictId) |
| | | { |
| | | return success(dictTypeService.selectDictTypeById(dictId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:add") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysDictType dict) |
| | | { |
| | | if (!dictTypeService.checkDictTypeUnique(dict)) |
| | | { |
| | | return error("æ°å¢åå
¸'" + dict.getDictName() + "'失败ï¼åå
¸ç±»åå·²åå¨"); |
| | | } |
| | | dict.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(dictTypeService.insertDictType(dict)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:edit") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysDictType dict) |
| | | { |
| | | if (!dictTypeService.checkDictTypeUnique(dict)) |
| | | { |
| | | return error("ä¿®æ¹åå
¸'" + dict.getDictName() + "'失败ï¼åå
¸ç±»åå·²åå¨"); |
| | | } |
| | | dict.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(dictTypeService.updateDictType(dict)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @RequiresPermissions("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictIds}") |
| | | public AjaxResult remove(@PathVariable Long[] dictIds) |
| | | { |
| | | dictTypeService.deleteDictTypeByIds(dictIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * å·æ°åå
¸ç¼å |
| | | */ |
| | | @RequiresPermissions("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/refreshCache") |
| | | public AjaxResult refreshCache() |
| | | { |
| | | dictTypeService.resetDictCache(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
¸éæ©æ¡å表 |
| | | */ |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult optionselect() |
| | | { |
| | | List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll(); |
| | | return success(dictTypes); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.redis.service.RedisService; |
| | | import com.se.common.security.annotation.InnerAuth; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.system.api.domain.SysLogininfor; |
| | | import com.se.system.service.ISysLogininforService; |
| | | |
| | | /** |
| | | * ç³»ç»è®¿é®è®°å½ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/logininfor") |
| | | public class SysLogininforController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysLogininforService logininforService; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @RequiresPermissions("system:logininfor:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysLogininfor logininfor) |
| | | { |
| | | startPage(); |
| | | List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:logininfor:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysLogininfor logininfor) |
| | | { |
| | | List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); |
| | | ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class); |
| | | util.exportExcel(response, list, "ç»å½æ¥å¿"); |
| | | } |
| | | |
| | | @RequiresPermissions("system:logininfor:remove") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{infoIds}") |
| | | public AjaxResult remove(@PathVariable Long[] infoIds) |
| | | { |
| | | return toAjax(logininforService.deleteLogininforByIds(infoIds)); |
| | | } |
| | | |
| | | @RequiresPermissions("system:logininfor:remove") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | logininforService.cleanLogininfor(); |
| | | return success(); |
| | | } |
| | | |
| | | @RequiresPermissions("system:logininfor:unlock") |
| | | @Log(title = "è´¦æ·è§£é", businessType = BusinessType.OTHER) |
| | | @GetMapping("/unlock/{userName}") |
| | | public AjaxResult unlock(@PathVariable("userName") String userName) |
| | | { |
| | | redisService.deleteObject(CacheConstants.PWD_ERR_CNT_KEY + userName); |
| | | return success(); |
| | | } |
| | | |
| | | @InnerAuth |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysLogininfor logininfor) |
| | | { |
| | | return toAjax(logininforService.insertLogininfor(logininfor)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysMenu; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.service.ISysMenuService; |
| | | |
| | | /** |
| | | * èåä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/menu") |
| | | public class SysMenuController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | /** |
| | | * è·åèåå表 |
| | | */ |
| | | @RequiresPermissions("system:menu:list") |
| | | @GetMapping("/list") |
| | | public AjaxResult list(SysMenu menu) |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuList(menu, userId); |
| | | return success(menus); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®èåç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:menu:query") |
| | | @GetMapping(value = "/{menuId}") |
| | | public AjaxResult getInfo(@PathVariable Long menuId) |
| | | { |
| | | return success(menuService.selectMenuById(menuId)); |
| | | } |
| | | |
| | | /** |
| | | * è·åèå䏿æ å表 |
| | | */ |
| | | @GetMapping("/treeselect") |
| | | public AjaxResult treeselect(SysMenu menu) |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuList(menu, userId); |
| | | return success(menuService.buildMenuTreeSelect(menus)); |
| | | } |
| | | |
| | | /** |
| | | * å 载对åºè§è²èåå表æ |
| | | */ |
| | | @GetMapping(value = "/roleMenuTreeselect/{roleId}") |
| | | public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuList(userId); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); |
| | | ajax.put("menus", menuService.buildMenuTreeSelect(menus)); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢èå |
| | | */ |
| | | @RequiresPermissions("system:menu:add") |
| | | @Log(title = "èå管ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysMenu menu) |
| | | { |
| | | if (!menuService.checkMenuNameUnique(menu)) |
| | | { |
| | | return error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
| | | { |
| | | return error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | | menu.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(menuService.insertMenu(menu)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹èå |
| | | */ |
| | | @RequiresPermissions("system:menu:edit") |
| | | @Log(title = "èå管ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysMenu menu) |
| | | { |
| | | if (!menuService.checkMenuNameUnique(menu)) |
| | | { |
| | | return error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
| | | { |
| | | return error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | | else if (menu.getMenuId().equals(menu.getParentId())) |
| | | { |
| | | return error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼ä¸çº§èåä¸è½éæ©èªå·±"); |
| | | } |
| | | menu.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(menuService.updateMenu(menu)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤èå |
| | | */ |
| | | @RequiresPermissions("system:menu:remove") |
| | | @Log(title = "èå管ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{menuId}") |
| | | public AjaxResult remove(@PathVariable("menuId") Long menuId) |
| | | { |
| | | if (menuService.hasChildByMenuId(menuId)) |
| | | { |
| | | return warn("åå¨åèå,ä¸å
许å é¤"); |
| | | } |
| | | if (menuService.checkMenuExistRole(menuId)) |
| | | { |
| | | return warn("èåå·²åé
,ä¸å
许å é¤"); |
| | | } |
| | | return toAjax(menuService.deleteMenuById(menuId)); |
| | | } |
| | | |
| | | /** |
| | | * è·åè·¯ç±ä¿¡æ¯ |
| | | * |
| | | * @return è·¯ç±ä¿¡æ¯ |
| | | */ |
| | | @GetMapping("getRouters") |
| | | public AjaxResult getRouters() |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return success(menuService.buildMenus(menus)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysNotice; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.service.ISysNoticeService; |
| | | |
| | | /** |
| | | * å
¬å ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/notice") |
| | | public class SysNoticeController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysNoticeService noticeService; |
| | | |
| | | /** |
| | | * è·åéç¥å
¬åå表 |
| | | */ |
| | | @RequiresPermissions("system:notice:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysNotice notice) |
| | | { |
| | | startPage(); |
| | | List<SysNotice> list = noticeService.selectNoticeList(notice); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®éç¥å
¬åç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:notice:query") |
| | | @GetMapping(value = "/{noticeId}") |
| | | public AjaxResult getInfo(@PathVariable Long noticeId) |
| | | { |
| | | return success(noticeService.selectNoticeById(noticeId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢éç¥å
Œ |
| | | */ |
| | | @RequiresPermissions("system:notice:add") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysNotice notice) |
| | | { |
| | | notice.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(noticeService.insertNotice(notice)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹éç¥å
Œ |
| | | */ |
| | | @RequiresPermissions("system:notice:edit") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysNotice notice) |
| | | { |
| | | notice.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(noticeService.updateNotice(notice)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤éç¥å
Œ |
| | | */ |
| | | @RequiresPermissions("system:notice:remove") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{noticeIds}") |
| | | public AjaxResult remove(@PathVariable Long[] noticeIds) |
| | | { |
| | | return toAjax(noticeService.deleteNoticeByIds(noticeIds)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.InnerAuth; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.system.api.domain.SysOperLog; |
| | | import com.se.system.service.ISysOperLogService; |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/operlog") |
| | | public class SysOperlogController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysOperLogService operLogService; |
| | | |
| | | @RequiresPermissions("system:operlog:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysOperLog operLog) |
| | | { |
| | | startPage(); |
| | | List<SysOperLog> list = operLogService.selectOperLogList(operLog); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:operlog:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysOperLog operLog) |
| | | { |
| | | List<SysOperLog> list = operLogService.selectOperLogList(operLog); |
| | | ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class); |
| | | util.exportExcel(response, list, "æä½æ¥å¿"); |
| | | } |
| | | |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @RequiresPermissions("system:operlog:remove") |
| | | @DeleteMapping("/{operIds}") |
| | | public AjaxResult remove(@PathVariable Long[] operIds) |
| | | { |
| | | return toAjax(operLogService.deleteOperLogByIds(operIds)); |
| | | } |
| | | |
| | | @RequiresPermissions("system:operlog:remove") |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | operLogService.cleanOperLog(); |
| | | return success(); |
| | | } |
| | | |
| | | @InnerAuth |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysOperLog operLog) |
| | | { |
| | | return toAjax(operLogService.insertOperlog(operLog)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.system.domain.SysPost; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.service.ISysPostService; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/post") |
| | | public class SysPostController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysPostService postService; |
| | | |
| | | /** |
| | | * è·åå²ä½å表 |
| | | */ |
| | | @RequiresPermissions("system:post:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysPost post) |
| | | { |
| | | startPage(); |
| | | List<SysPost> list = postService.selectPostList(post); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:post:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysPost post) |
| | | { |
| | | List<SysPost> list = postService.selectPostList(post); |
| | | ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class); |
| | | util.exportExcel(response, list, "å²ä½æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å²ä½ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:post:query") |
| | | @GetMapping(value = "/{postId}") |
| | | public AjaxResult getInfo(@PathVariable Long postId) |
| | | { |
| | | return success(postService.selectPostById(postId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å²ä½ |
| | | */ |
| | | @RequiresPermissions("system:post:add") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysPost post) |
| | | { |
| | | if (!postService.checkPostNameUnique(post)) |
| | | { |
| | | return error("æ°å¢å²ä½'" + post.getPostName() + "'失败ï¼å²ä½åç§°å·²åå¨"); |
| | | } |
| | | else if (!postService.checkPostCodeUnique(post)) |
| | | { |
| | | return error("æ°å¢å²ä½'" + post.getPostName() + "'失败ï¼å²ä½ç¼ç å·²åå¨"); |
| | | } |
| | | post.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(postService.insertPost(post)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹å²ä½ |
| | | */ |
| | | @RequiresPermissions("system:post:edit") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysPost post) |
| | | { |
| | | if (!postService.checkPostNameUnique(post)) |
| | | { |
| | | return error("ä¿®æ¹å²ä½'" + post.getPostName() + "'失败ï¼å²ä½åç§°å·²åå¨"); |
| | | } |
| | | else if (!postService.checkPostCodeUnique(post)) |
| | | { |
| | | return error("ä¿®æ¹å²ä½'" + post.getPostName() + "'失败ï¼å²ä½ç¼ç å·²åå¨"); |
| | | } |
| | | post.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(postService.updatePost(post)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å²ä½ |
| | | */ |
| | | @RequiresPermissions("system:post:remove") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{postIds}") |
| | | public AjaxResult remove(@PathVariable Long[] postIds) |
| | | { |
| | | return toAjax(postService.deletePostByIds(postIds)); |
| | | } |
| | | |
| | | /** |
| | | * è·åå²ä½éæ©æ¡å表 |
| | | */ |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult optionselect() |
| | | { |
| | | List<SysPost> posts = postService.selectPostAll(); |
| | | return success(posts); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.Arrays; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.se.common.core.domain.R; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.file.FileTypeUtils; |
| | | import com.se.common.core.utils.file.MimeTypeUtils; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.service.TokenService; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.RemoteFileService; |
| | | import com.se.system.api.domain.SysFile; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.api.model.LoginUser; |
| | | import com.se.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ä¸ªäººä¿¡æ¯ ä¸å¡å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/user/profile") |
| | | public class SysProfileController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private RemoteFileService remoteFileService; |
| | | |
| | | /** |
| | | * ä¸ªäººä¿¡æ¯ |
| | | */ |
| | | @GetMapping |
| | | public AjaxResult profile() |
| | | { |
| | | String username = SecurityUtils.getUsername(); |
| | | SysUser user = userService.selectUserByUserName(username); |
| | | AjaxResult ajax = AjaxResult.success(user); |
| | | ajax.put("roleGroup", userService.selectUserRoleGroup(username)); |
| | | ajax.put("postGroup", userService.selectUserPostGroup(username)); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ· |
| | | */ |
| | | @Log(title = "个人信æ¯", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) |
| | | { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | SysUser currentUser = loginUser.getSysUser(); |
| | | currentUser.setNickName(user.getNickName()); |
| | | currentUser.setEmail(user.getEmail()); |
| | | currentUser.setPhonenumber(user.getPhonenumber()); |
| | | currentUser.setSex(user.getSex()); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) |
| | | { |
| | | return error("ä¿®æ¹ç¨æ·'" + loginUser.getUsername() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) |
| | | { |
| | | return error("ä¿®æ¹ç¨æ·'" + loginUser.getUsername() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | | } |
| | | if (userService.updateUserProfile(currentUser)) |
| | | { |
| | | // æ´æ°ç¼åç¨æ·ä¿¡æ¯ |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | return error("ä¿®æ¹ä¸ªäººä¿¡æ¯å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | /** |
| | | * éç½®å¯ç |
| | | */ |
| | | @Log(title = "个人信æ¯", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/updatePwd") |
| | | public AjaxResult updatePwd(String oldPassword, String newPassword) |
| | | { |
| | | String username = SecurityUtils.getUsername(); |
| | | SysUser user = userService.selectUserByUserName(username); |
| | | String password = user.getPassword(); |
| | | if (!SecurityUtils.matchesPassword(oldPassword, password)) |
| | | { |
| | | return error("ä¿®æ¹å¯ç å¤±è´¥ï¼æ§å¯ç é误"); |
| | | } |
| | | if (SecurityUtils.matchesPassword(newPassword, password)) |
| | | { |
| | | return error("æ°å¯ç ä¸è½ä¸æ§å¯ç ç¸å"); |
| | | } |
| | | newPassword = SecurityUtils.encryptPassword(newPassword); |
| | | if (userService.resetUserPwd(username, newPassword) > 0) |
| | | { |
| | | // æ´æ°ç¼åç¨æ·å¯ç |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | loginUser.getSysUser().setPassword(newPassword); |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | return error("ä¿®æ¹å¯ç å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | /** |
| | | * 头åä¸ä¼ |
| | | */ |
| | | @Log(title = "ç¨æ·å¤´å", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/avatar") |
| | | public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) |
| | | { |
| | | if (!file.isEmpty()) |
| | | { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | String extension = FileTypeUtils.getExtension(file); |
| | | if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) |
| | | { |
| | | return error("æä»¶æ ¼å¼ä¸æ£ç¡®ï¼è¯·ä¸ä¼ " + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "æ ¼å¼"); |
| | | } |
| | | R<SysFile> fileResult = remoteFileService.upload(file); |
| | | if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) |
| | | { |
| | | return error("æä»¶æå¡å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | String url = fileResult.getData().getUrl(); |
| | | if (userService.updateUserAvatar(loginUser.getUsername(), url)) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("imgUrl", url); |
| | | // æ´æ°ç¼åç¨æ·å¤´å |
| | | loginUser.getSysUser().setAvatar(url); |
| | | tokenService.setLoginUser(loginUser); |
| | | return ajax; |
| | | } |
| | | } |
| | | return error("ä¸ä¼ å¾çå¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.se.system.domain.SysUserRole; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.service.ISysDeptService; |
| | | import com.se.system.service.ISysRoleService; |
| | | import com.se.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * è§è²ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/role") |
| | | public class SysRoleController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @RequiresPermissions("system:role:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysRole role) |
| | | { |
| | | startPage(); |
| | | List<SysRole> list = roleService.selectRoleList(role); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:role:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysRole role) |
| | | { |
| | | List<SysRole> list = roleService.selectRoleList(role); |
| | | ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class); |
| | | util.exportExcel(response, list, "è§è²æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:role:query") |
| | | @GetMapping(value = "/{roleId}") |
| | | public AjaxResult getInfo(@PathVariable Long roleId) |
| | | { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return success(roleService.selectRoleById(roleId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢è§è² |
| | | */ |
| | | @RequiresPermissions("system:role:add") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysRole role) |
| | | { |
| | | if (!roleService.checkRoleNameUnique(role)) |
| | | { |
| | | return error("æ°å¢è§è²'" + role.getRoleName() + "'失败ï¼è§è²åç§°å·²åå¨"); |
| | | } |
| | | else if (!roleService.checkRoleKeyUnique(role)) |
| | | { |
| | | return error("æ°å¢è§è²'" + role.getRoleName() + "'失败ï¼è§è²æéå·²åå¨"); |
| | | } |
| | | role.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(roleService.insertRole(role)); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åè§è² |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | if (!roleService.checkRoleNameUnique(role)) |
| | | { |
| | | return error("ä¿®æ¹è§è²'" + role.getRoleName() + "'失败ï¼è§è²åç§°å·²åå¨"); |
| | | } |
| | | else if (!roleService.checkRoleKeyUnique(role)) |
| | | { |
| | | return error("ä¿®æ¹è§è²'" + role.getRoleName() + "'失败ï¼è§è²æéå·²åå¨"); |
| | | } |
| | | role.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(roleService.updateRole(role)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åæ°æ®æé |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/dataScope") |
| | | public AjaxResult dataScope(@RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | return toAjax(roleService.authDataScope(role)); |
| | | } |
| | | |
| | | /** |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | role.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(roleService.updateRoleStatus(role)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤è§è² |
| | | */ |
| | | @RequiresPermissions("system:role:remove") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{roleIds}") |
| | | public AjaxResult remove(@PathVariable Long[] roleIds) |
| | | { |
| | | return toAjax(roleService.deleteRoleByIds(roleIds)); |
| | | } |
| | | |
| | | /** |
| | | * è·åè§è²éæ©æ¡å表 |
| | | */ |
| | | @RequiresPermissions("system:role:query") |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult optionselect() |
| | | { |
| | | return success(roleService.selectRoleAll()); |
| | | } |
| | | /** |
| | | * æ¥è¯¢å·²åé
ç¨æ·è§è²å表 |
| | | */ |
| | | @RequiresPermissions("system:role:list") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo allocatedList(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectAllocatedList(user); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | */ |
| | | @RequiresPermissions("system:role:list") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo unallocatedList(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectUnallocatedList(user); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * åæ¶ææç¨æ· |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancel") |
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | { |
| | | return toAjax(roleService.deleteAuthUser(userRole)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éåæ¶ææç¨æ· |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancelAll") |
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | return toAjax(roleService.deleteAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹ééæ©ç¨æ·ææ |
| | | */ |
| | | @RequiresPermissions("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/selectAll") |
| | | public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return toAjax(roleService.insertAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | | /** |
| | | * è·å对åºè§è²é¨é¨æ å表 |
| | | */ |
| | | @RequiresPermissions("system:role:query") |
| | | @GetMapping(value = "/deptTree/{roleId}") |
| | | public AjaxResult deptTree(@PathVariable("roleId") Long roleId) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
| | | ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |
| | | return ajax; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.se.common.core.domain.R; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.security.annotation.InnerAuth; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.api.model.LoginUser; |
| | | import com.se.system.service.ISysConfigService; |
| | | import com.se.system.service.ISysDeptService; |
| | | import com.se.system.service.ISysPermissionService; |
| | | import com.se.system.service.ISysPostService; |
| | | import com.se.system.service.ISysRoleService; |
| | | import com.se.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/user") |
| | | public class SysUserController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @Autowired |
| | | private ISysPostService postService; |
| | | |
| | | @Autowired |
| | | private ISysPermissionService permissionService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | /** |
| | | * è·åç¨æ·å表 |
| | | */ |
| | | @RequiresPermissions("system:user:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @RequiresPermissions("system:user:export") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysUser user) |
| | | { |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | util.exportExcel(response, list, "ç¨æ·æ°æ®"); |
| | | } |
| | | |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.IMPORT) |
| | | @RequiresPermissions("system:user:import") |
| | | @PostMapping("/importData") |
| | | public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception |
| | | { |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | List<SysUser> userList = util.importExcel(file.getInputStream()); |
| | | String operName = SecurityUtils.getUsername(); |
| | | String message = userService.importUser(userList, updateSupport, operName); |
| | | return success(message); |
| | | } |
| | | |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) throws IOException |
| | | { |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | util.importTemplateExcel(response, "ç¨æ·æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @InnerAuth |
| | | @GetMapping("/info/{username}") |
| | | public R<LoginUser> info(@PathVariable("username") String username) |
| | | { |
| | | SysUser sysUser = userService.selectUserByUserName(username); |
| | | if (StringUtils.isNull(sysUser)) |
| | | { |
| | | return R.fail("ç¨æ·åæå¯ç é误"); |
| | | } |
| | | // è§è²éå |
| | | Set<String> roles = permissionService.getRolePermission(sysUser); |
| | | // æééå |
| | | Set<String> permissions = permissionService.getMenuPermission(sysUser); |
| | | LoginUser sysUserVo = new LoginUser(); |
| | | sysUserVo.setSysUser(sysUser); |
| | | sysUserVo.setRoles(roles); |
| | | sysUserVo.setPermissions(permissions); |
| | | return R.ok(sysUserVo); |
| | | } |
| | | |
| | | /** |
| | | * 注åç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @InnerAuth |
| | | @PostMapping("/register") |
| | | public R<Boolean> register(@RequestBody SysUser sysUser) |
| | | { |
| | | String username = sysUser.getUserName(); |
| | | if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) |
| | | { |
| | | return R.fail("å½åç³»ç»æ²¡æå¼å¯æ³¨ååè½ï¼"); |
| | | } |
| | | if (!userService.checkUserNameUnique(sysUser)) |
| | | { |
| | | return R.fail("ä¿åç¨æ·'" + username + "'å¤±è´¥ï¼æ³¨åè´¦å·å·²åå¨"); |
| | | } |
| | | return R.ok(userService.registerUser(sysUser)); |
| | | } |
| | | |
| | | /** |
| | | *è®°å½ç¨æ·ç»å½IPå°ååç»å½æ¶é´ |
| | | */ |
| | | @InnerAuth |
| | | @PutMapping("/recordlogin") |
| | | public R<Boolean> recordlogin(@RequestBody SysUser sysUser) |
| | | { |
| | | return R.ok(userService.updateUserProfile(sysUser)); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @return ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @GetMapping("getInfo") |
| | | public AjaxResult getInfo() |
| | | { |
| | | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); |
| | | // è§è²éå |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | // æééå |
| | | Set<String> permissions = permissionService.getMenuPermission(user); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("user", user); |
| | | ajax.put("roles", roles); |
| | | ajax.put("permissions", permissions); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @RequiresPermissions("system:user:query") |
| | | @GetMapping(value = { "/", "/{userId}" }) |
| | | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) |
| | | { |
| | | userService.checkUserDataScope(userId); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | List<SysRole> roles = roleService.selectRoleAll(); |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | ajax.put("posts", postService.selectPostAll()); |
| | | if (StringUtils.isNotNull(userId)) |
| | | { |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | | ajax.put(AjaxResult.DATA_TAG, sysUser); |
| | | ajax.put("postIds", postService.selectPostListByUserId(userId)); |
| | | ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList())); |
| | | } |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ· |
| | | */ |
| | | @RequiresPermissions("system:user:add") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | | { |
| | | deptService.checkDeptDataScope(user.getDeptId()); |
| | | roleService.checkRoleDataScope(user.getRoleIds()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("æ°å¢ç¨æ·'" + user.getUserName() + "'失败ï¼ç»å½è´¦å·å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("æ°å¢ç¨æ·'" + user.getUserName() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) |
| | | { |
| | | return error("æ°å¢ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | | } |
| | | user.setCreateBy(SecurityUtils.getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | return toAjax(userService.insertUser(user)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ· |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | deptService.checkDeptDataScope(user.getDeptId()); |
| | | roleService.checkRoleDataScope(user.getRoleIds()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'失败ï¼ç»å½è´¦å·å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) |
| | | { |
| | | return error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | | } |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(userService.updateUser(user)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ç¨æ· |
| | | */ |
| | | @RequiresPermissions("system:user:remove") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public AjaxResult remove(@PathVariable Long[] userIds) |
| | | { |
| | | if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) |
| | | { |
| | | return error("å½åç¨æ·ä¸è½å é¤"); |
| | | } |
| | | return toAjax(userService.deleteUserByIds(userIds)); |
| | | } |
| | | |
| | | /** |
| | | * éç½®å¯ç |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody SysUser user) |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(userService.resetPwd(user)); |
| | | } |
| | | |
| | | /** |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysUser user) |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(userService.updateUserStatus(user)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·ç¼å·è·åææè§è² |
| | | */ |
| | | @RequiresPermissions("system:user:query") |
| | | @GetMapping("/authRole/{userId}") |
| | | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | SysUser user = userService.selectUserById(userId); |
| | | List<SysRole> roles = roleService.selectRolesByUserId(userId); |
| | | ajax.put("user", user); |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * ç¨æ·ææè§è² |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| | | { |
| | | userService.checkUserDataScope(userId); |
| | | roleService.checkRoleDataScope(roleIds); |
| | | userService.insertUserAuth(userId, roleIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * è·åé¨é¨æ å表 |
| | | */ |
| | | @RequiresPermissions("system:user:list") |
| | | @GetMapping("/deptTree") |
| | | public AjaxResult deptTree(SysDept dept) |
| | | { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.controller; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysUserOnline; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.web.controller.BaseController; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | import com.se.common.log.annotation.Log; |
| | | import com.se.common.log.enums.BusinessType; |
| | | import com.se.common.redis.service.RedisService; |
| | | import com.se.common.security.annotation.RequiresPermissions; |
| | | import com.se.system.api.model.LoginUser; |
| | | import com.se.system.service.ISysUserOnlineService; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ·çæ§ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/online") |
| | | public class SysUserOnlineController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserOnlineService userOnlineService; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @RequiresPermissions("monitor:online:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(String ipaddr, String userName) |
| | | { |
| | | Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| | | for (String key : keys) |
| | | { |
| | | LoginUser user = redisService.getCacheObject(key); |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); |
| | | } |
| | | else if (StringUtils.isNotEmpty(ipaddr)) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); |
| | | } |
| | | else if (StringUtils.isNotEmpty(userName)) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
| | | } |
| | | else |
| | | { |
| | | userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); |
| | | } |
| | | } |
| | | Collections.reverse(userOnlineList); |
| | | userOnlineList.removeAll(Collections.singleton(null)); |
| | | return getDataTable(userOnlineList); |
| | | } |
| | | |
| | | /** |
| | | * 强éç¨æ· |
| | | */ |
| | | @RequiresPermissions("monitor:online:forceLogout") |
| | | @Log(title = "å¨çº¿ç¨æ·", businessType = BusinessType.FORCE) |
| | | @DeleteMapping("/{tokenId}") |
| | | public AjaxResult forceLogout(@PathVariable String tokenId) |
| | | { |
| | | redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.se.common.core.annotation.Excel; |
| | | import com.se.common.core.annotation.Excel.ColumnType; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * åæ°é
置表 sys_config |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysConfig extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** åæ°ä¸»é® */ |
| | | @Excel(name = "忰䏻é®", cellType = ColumnType.NUMERIC) |
| | | private Long configId; |
| | | |
| | | /** åæ°åç§° */ |
| | | @Excel(name = "åæ°åç§°") |
| | | private String configName; |
| | | |
| | | /** åæ°é®å */ |
| | | @Excel(name = "åæ°é®å") |
| | | private String configKey; |
| | | |
| | | /** åæ°é®å¼ */ |
| | | @Excel(name = "åæ°é®å¼") |
| | | private String configValue; |
| | | |
| | | /** ç³»ç»å
ç½®ï¼Yæ¯ Nå¦ï¼ */ |
| | | @Excel(name = "ç³»ç»å
ç½®", readConverterExp = "Y=æ¯,N=å¦") |
| | | private String configType; |
| | | |
| | | public Long getConfigId() |
| | | { |
| | | return configId; |
| | | } |
| | | |
| | | public void setConfigId(Long configId) |
| | | { |
| | | this.configId = configId; |
| | | } |
| | | |
| | | @NotBlank(message = "åæ°åç§°ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åæ°åç§°ä¸è½è¶
è¿100个å符") |
| | | public String getConfigName() |
| | | { |
| | | return configName; |
| | | } |
| | | |
| | | public void setConfigName(String configName) |
| | | { |
| | | this.configName = configName; |
| | | } |
| | | |
| | | @NotBlank(message = "åæ°é®åé¿åº¦ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åæ°é®åé¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getConfigKey() |
| | | { |
| | | return configKey; |
| | | } |
| | | |
| | | public void setConfigKey(String configKey) |
| | | { |
| | | this.configKey = configKey; |
| | | } |
| | | |
| | | @NotBlank(message = "åæ°é®å¼ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 500, message = "åæ°é®å¼é¿åº¦ä¸è½è¶
è¿500个å符") |
| | | public String getConfigValue() |
| | | { |
| | | return configValue; |
| | | } |
| | | |
| | | public void setConfigValue(String configValue) |
| | | { |
| | | this.configValue = configValue; |
| | | } |
| | | |
| | | public String getConfigType() |
| | | { |
| | | return configType; |
| | | } |
| | | |
| | | public void setConfigType(String configType) |
| | | { |
| | | this.configType = configType; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("configId", getConfigId()) |
| | | .append("configName", getConfigName()) |
| | | .append("configKey", getConfigKey()) |
| | | .append("configValue", getConfigValue()) |
| | | .append("configType", getConfigType()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * èåæé表 sys_menu |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysMenu extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** èåID */ |
| | | private Long menuId; |
| | | |
| | | /** èååç§° */ |
| | | private String menuName; |
| | | |
| | | /** ç¶èååç§° */ |
| | | private String parentName; |
| | | |
| | | /** ç¶èåID */ |
| | | private Long parentId; |
| | | |
| | | /** æ¾ç¤ºé¡ºåº */ |
| | | private Integer orderNum; |
| | | |
| | | /** è·¯ç±å°å */ |
| | | private String path; |
| | | |
| | | /** ç»ä»¶è·¯å¾ */ |
| | | private String component; |
| | | |
| | | /** è·¯ç±åæ° */ |
| | | private String query; |
| | | |
| | | /** è·¯ç±åç§°ï¼é»è®¤åè·¯ç±å°åç¸åçé©¼å³°æ ¼å¼ï¼æ³¨æï¼å 为vue3çæ¬çrouterä¼å é¤åç§°ç¸åè·¯ç±ï¼ä¸ºé¿å
ååçå²çªï¼ç¹æ®æ
åµå¯ä»¥èªå®ä¹ï¼ */ |
| | | private String routeName; |
| | | |
| | | /** æ¯å¦ä¸ºå¤é¾ï¼0æ¯ 1å¦ï¼ */ |
| | | private String isFrame; |
| | | |
| | | /** æ¯å¦ç¼åï¼0ç¼å 1ä¸ç¼åï¼ */ |
| | | private String isCache; |
| | | |
| | | /** ç±»åï¼Mç®å½ Cèå Fæé®ï¼ */ |
| | | private String menuType; |
| | | |
| | | /** æ¾ç¤ºç¶æï¼0æ¾ç¤º 1éèï¼ */ |
| | | private String visible; |
| | | |
| | | /** èåç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | private String status; |
| | | |
| | | /** æéå符串 */ |
| | | private String perms; |
| | | |
| | | /** èå徿 */ |
| | | private String icon; |
| | | |
| | | /** åèå */ |
| | | private List<SysMenu> children = new ArrayList<SysMenu>(); |
| | | |
| | | public Long getMenuId() |
| | | { |
| | | return menuId; |
| | | } |
| | | |
| | | public void setMenuId(Long menuId) |
| | | { |
| | | this.menuId = menuId; |
| | | } |
| | | |
| | | @NotBlank(message = "èååç§°ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 50, message = "èååç§°é¿åº¦ä¸è½è¶
è¿50个å符") |
| | | public String getMenuName() |
| | | { |
| | | return menuName; |
| | | } |
| | | |
| | | public void setMenuName(String menuName) |
| | | { |
| | | this.menuName = menuName; |
| | | } |
| | | |
| | | public String getParentName() |
| | | { |
| | | return parentName; |
| | | } |
| | | |
| | | public void setParentName(String parentName) |
| | | { |
| | | this.parentName = parentName; |
| | | } |
| | | |
| | | public Long getParentId() |
| | | { |
| | | return parentId; |
| | | } |
| | | |
| | | public void setParentId(Long parentId) |
| | | { |
| | | this.parentId = parentId; |
| | | } |
| | | |
| | | @NotNull(message = "æ¾ç¤ºé¡ºåºä¸è½ä¸ºç©º") |
| | | public Integer getOrderNum() |
| | | { |
| | | return orderNum; |
| | | } |
| | | |
| | | public void setOrderNum(Integer orderNum) |
| | | { |
| | | this.orderNum = orderNum; |
| | | } |
| | | |
| | | @Size(min = 0, max = 200, message = "è·¯ç±å°åä¸è½è¶
è¿200个å符") |
| | | public String getPath() |
| | | { |
| | | return path; |
| | | } |
| | | |
| | | public void setPath(String path) |
| | | { |
| | | this.path = path; |
| | | } |
| | | |
| | | @Size(min = 0, max = 200, message = "ç»ä»¶è·¯å¾ä¸è½è¶
è¿255个å符") |
| | | public String getComponent() |
| | | { |
| | | return component; |
| | | } |
| | | |
| | | public void setComponent(String component) |
| | | { |
| | | this.component = component; |
| | | } |
| | | |
| | | public String getQuery() |
| | | { |
| | | return query; |
| | | } |
| | | |
| | | public void setQuery(String query) |
| | | { |
| | | this.query = query; |
| | | } |
| | | |
| | | public String getRouteName() |
| | | { |
| | | return routeName; |
| | | } |
| | | |
| | | public void setRouteName(String routeName) |
| | | { |
| | | this.routeName = routeName; |
| | | } |
| | | |
| | | public String getIsFrame() |
| | | { |
| | | return isFrame; |
| | | } |
| | | |
| | | public void setIsFrame(String isFrame) |
| | | { |
| | | this.isFrame = isFrame; |
| | | } |
| | | |
| | | public String getIsCache() |
| | | { |
| | | return isCache; |
| | | } |
| | | |
| | | public void setIsCache(String isCache) |
| | | { |
| | | this.isCache = isCache; |
| | | } |
| | | |
| | | @NotBlank(message = "èåç±»åä¸è½ä¸ºç©º") |
| | | public String getMenuType() |
| | | { |
| | | return menuType; |
| | | } |
| | | |
| | | public void setMenuType(String menuType) |
| | | { |
| | | this.menuType = menuType; |
| | | } |
| | | |
| | | public String getVisible() |
| | | { |
| | | return visible; |
| | | } |
| | | |
| | | public void setVisible(String visible) |
| | | { |
| | | this.visible = visible; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | @Size(min = 0, max = 100, message = "æéæ è¯é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getPerms() |
| | | { |
| | | return perms; |
| | | } |
| | | |
| | | public void setPerms(String perms) |
| | | { |
| | | this.perms = perms; |
| | | } |
| | | |
| | | public String getIcon() |
| | | { |
| | | return icon; |
| | | } |
| | | |
| | | public void setIcon(String icon) |
| | | { |
| | | this.icon = icon; |
| | | } |
| | | |
| | | public List<SysMenu> getChildren() |
| | | { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<SysMenu> children) |
| | | { |
| | | this.children = children; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("menuId", getMenuId()) |
| | | .append("menuName", getMenuName()) |
| | | .append("parentId", getParentId()) |
| | | .append("orderNum", getOrderNum()) |
| | | .append("path", getPath()) |
| | | .append("component", getComponent()) |
| | | .append("query", getQuery()) |
| | | .append("routeName", getRouteName()) |
| | | .append("isFrame", getIsFrame()) |
| | | .append("IsCache", getIsCache()) |
| | | .append("menuType", getMenuType()) |
| | | .append("visible", getVisible()) |
| | | .append("status ", getStatus()) |
| | | .append("perms", getPerms()) |
| | | .append("icon", getIcon()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | import com.se.common.core.xss.Xss; |
| | | |
| | | /** |
| | | * éç¥å
¬å表 sys_notice |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysNotice extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** å
ŒID */ |
| | | private Long noticeId; |
| | | |
| | | /** å
¬åæ é¢ */ |
| | | private String noticeTitle; |
| | | |
| | | /** å
¬åç±»åï¼1éç¥ 2å
¬åï¼ */ |
| | | private String noticeType; |
| | | |
| | | /** å
¬åå
容 */ |
| | | private String noticeContent; |
| | | |
| | | /** å
¬åç¶æï¼0æ£å¸¸ 1å
³éï¼ */ |
| | | private String status; |
| | | |
| | | public Long getNoticeId() |
| | | { |
| | | return noticeId; |
| | | } |
| | | |
| | | public void setNoticeId(Long noticeId) |
| | | { |
| | | this.noticeId = noticeId; |
| | | } |
| | | |
| | | public void setNoticeTitle(String noticeTitle) |
| | | { |
| | | this.noticeTitle = noticeTitle; |
| | | } |
| | | |
| | | @Xss(message = "å
¬åæ é¢ä¸è½å
å«èæ¬å符") |
| | | @NotBlank(message = "å
¬åæ é¢ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 50, message = "å
¬åæ é¢ä¸è½è¶
è¿50个å符") |
| | | public String getNoticeTitle() |
| | | { |
| | | return noticeTitle; |
| | | } |
| | | |
| | | public void setNoticeType(String noticeType) |
| | | { |
| | | this.noticeType = noticeType; |
| | | } |
| | | |
| | | public String getNoticeType() |
| | | { |
| | | return noticeType; |
| | | } |
| | | |
| | | public void setNoticeContent(String noticeContent) |
| | | { |
| | | this.noticeContent = noticeContent; |
| | | } |
| | | |
| | | public String getNoticeContent() |
| | | { |
| | | return noticeContent; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("noticeId", getNoticeId()) |
| | | .append("noticeTitle", getNoticeTitle()) |
| | | .append("noticeType", getNoticeType()) |
| | | .append("noticeContent", getNoticeContent()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.se.common.core.annotation.Excel; |
| | | import com.se.common.core.annotation.Excel.ColumnType; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * å²ä½è¡¨ sys_post |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysPost extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** å²ä½åºå· */ |
| | | @Excel(name = "å²ä½åºå·", cellType = ColumnType.NUMERIC) |
| | | private Long postId; |
| | | |
| | | /** å²ä½ç¼ç */ |
| | | @Excel(name = "å²ä½ç¼ç ") |
| | | private String postCode; |
| | | |
| | | /** å²ä½åç§° */ |
| | | @Excel(name = "å²ä½åç§°") |
| | | private String postName; |
| | | |
| | | /** å²ä½æåº */ |
| | | @Excel(name = "å²ä½æåº") |
| | | private Integer postSort; |
| | | |
| | | /** ç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | @Excel(name = "ç¶æ", readConverterExp = "0=æ£å¸¸,1=åç¨") |
| | | private String status; |
| | | |
| | | /** ç¨æ·æ¯å¦å卿¤å²ä½æ è¯ é»è®¤ä¸åå¨ */ |
| | | private boolean flag = false; |
| | | |
| | | public Long getPostId() |
| | | { |
| | | return postId; |
| | | } |
| | | |
| | | public void setPostId(Long postId) |
| | | { |
| | | this.postId = postId; |
| | | } |
| | | |
| | | @NotBlank(message = "å²ä½ç¼ç ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 64, message = "å²ä½ç¼ç é¿åº¦ä¸è½è¶
è¿64个å符") |
| | | public String getPostCode() |
| | | { |
| | | return postCode; |
| | | } |
| | | |
| | | public void setPostCode(String postCode) |
| | | { |
| | | this.postCode = postCode; |
| | | } |
| | | |
| | | @NotBlank(message = "å²ä½åç§°ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 50, message = "å²ä½åç§°é¿åº¦ä¸è½è¶
è¿50个å符") |
| | | public String getPostName() |
| | | { |
| | | return postName; |
| | | } |
| | | |
| | | public void setPostName(String postName) |
| | | { |
| | | this.postName = postName; |
| | | } |
| | | |
| | | @NotNull(message = "æ¾ç¤ºé¡ºåºä¸è½ä¸ºç©º") |
| | | public Integer getPostSort() |
| | | { |
| | | return postSort; |
| | | } |
| | | |
| | | public void setPostSort(Integer postSort) |
| | | { |
| | | this.postSort = postSort; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public boolean isFlag() |
| | | { |
| | | return flag; |
| | | } |
| | | |
| | | public void setFlag(boolean flag) |
| | | { |
| | | this.flag = flag; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("postId", getPostId()) |
| | | .append("postCode", getPostCode()) |
| | | .append("postName", getPostName()) |
| | | .append("postSort", getPostSort()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | |
| | | /** |
| | | * è§è²åé¨é¨å
³è sys_role_dept |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysRoleDept |
| | | { |
| | | /** è§è²ID */ |
| | | private Long roleId; |
| | | |
| | | /** é¨é¨ID */ |
| | | private Long deptId; |
| | | |
| | | public Long getRoleId() |
| | | { |
| | | return roleId; |
| | | } |
| | | |
| | | public void setRoleId(Long roleId) |
| | | { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | public Long getDeptId() |
| | | { |
| | | return deptId; |
| | | } |
| | | |
| | | public void setDeptId(Long deptId) |
| | | { |
| | | this.deptId = deptId; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("roleId", getRoleId()) |
| | | .append("deptId", getDeptId()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | |
| | | /** |
| | | * è§è²åèåå
³è sys_role_menu |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysRoleMenu |
| | | { |
| | | /** è§è²ID */ |
| | | private Long roleId; |
| | | |
| | | /** èåID */ |
| | | private Long menuId; |
| | | |
| | | public Long getRoleId() |
| | | { |
| | | return roleId; |
| | | } |
| | | |
| | | public void setRoleId(Long roleId) |
| | | { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | public Long getMenuId() |
| | | { |
| | | return menuId; |
| | | } |
| | | |
| | | public void setMenuId(Long menuId) |
| | | { |
| | | this.menuId = menuId; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("roleId", getRoleId()) |
| | | .append("menuId", getMenuId()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | /** |
| | | * å½åå¨çº¿ä¼è¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysUserOnline |
| | | { |
| | | /** ä¼è¯ç¼å· */ |
| | | private String tokenId; |
| | | |
| | | /** ç¨æ·åç§° */ |
| | | private String userName; |
| | | |
| | | /** ç»å½IPå°å */ |
| | | private String ipaddr; |
| | | |
| | | /** ç»å½å°å */ |
| | | private String loginLocation; |
| | | |
| | | /** æµè§å¨ç±»å */ |
| | | private String browser; |
| | | |
| | | /** æä½ç³»ç» */ |
| | | private String os; |
| | | |
| | | /** ç»å½æ¶é´ */ |
| | | private Long loginTime; |
| | | |
| | | public String getTokenId() |
| | | { |
| | | return tokenId; |
| | | } |
| | | |
| | | public void setTokenId(String tokenId) |
| | | { |
| | | this.tokenId = tokenId; |
| | | } |
| | | |
| | | public String getUserName() |
| | | { |
| | | return userName; |
| | | } |
| | | |
| | | public void setUserName(String userName) |
| | | { |
| | | this.userName = userName; |
| | | } |
| | | |
| | | public String getIpaddr() |
| | | { |
| | | return ipaddr; |
| | | } |
| | | |
| | | public void setIpaddr(String ipaddr) |
| | | { |
| | | this.ipaddr = ipaddr; |
| | | } |
| | | |
| | | public String getLoginLocation() |
| | | { |
| | | return loginLocation; |
| | | } |
| | | |
| | | public void setLoginLocation(String loginLocation) |
| | | { |
| | | this.loginLocation = loginLocation; |
| | | } |
| | | |
| | | public String getBrowser() |
| | | { |
| | | return browser; |
| | | } |
| | | |
| | | public void setBrowser(String browser) |
| | | { |
| | | this.browser = browser; |
| | | } |
| | | |
| | | public String getOs() |
| | | { |
| | | return os; |
| | | } |
| | | |
| | | public void setOs(String os) |
| | | { |
| | | this.os = os; |
| | | } |
| | | |
| | | public Long getLoginTime() |
| | | { |
| | | return loginTime; |
| | | } |
| | | |
| | | public void setLoginTime(Long loginTime) |
| | | { |
| | | this.loginTime = loginTime; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | |
| | | /** |
| | | * ç¨æ·åå²ä½å
³è sys_user_post |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysUserPost |
| | | { |
| | | /** ç¨æ·ID */ |
| | | private Long userId; |
| | | |
| | | /** å²ä½ID */ |
| | | private Long postId; |
| | | |
| | | public Long getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Long userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public Long getPostId() |
| | | { |
| | | return postId; |
| | | } |
| | | |
| | | public void setPostId(Long postId) |
| | | { |
| | | this.postId = postId; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("userId", getUserId()) |
| | | .append("postId", getPostId()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain; |
| | | |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | |
| | | /** |
| | | * ç¨æ·åè§è²å
³è sys_user_role |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SysUserRole |
| | | { |
| | | /** ç¨æ·ID */ |
| | | private Long userId; |
| | | |
| | | /** è§è²ID */ |
| | | private Long roleId; |
| | | |
| | | public Long getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Long userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public Long getRoleId() |
| | | { |
| | | return roleId; |
| | | } |
| | | |
| | | public void setRoleId(Long roleId) |
| | | { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("userId", getUserId()) |
| | | .append("roleId", getRoleId()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain.vo; |
| | | |
| | | import com.se.common.core.utils.StringUtils; |
| | | |
| | | /** |
| | | * è·¯ç±æ¾ç¤ºä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class MetaVo |
| | | { |
| | | /** |
| | | * 设置该路ç±å¨ä¾§è¾¹æ åé¢å
å±ä¸å±ç¤ºçåå |
| | | */ |
| | | private String title; |
| | | |
| | | /** |
| | | * 设置该路ç±ç徿 ï¼å¯¹åºè·¯å¾src/assets/icons/svg |
| | | */ |
| | | private String icon; |
| | | |
| | | /** |
| | | * 设置为trueï¼åä¸ä¼è¢« <keep-alive>ç¼å |
| | | */ |
| | | private boolean noCache; |
| | | |
| | | /** |
| | | * å
é¾å°åï¼http(s)://å¼å¤´ï¼ |
| | | */ |
| | | private String link; |
| | | |
| | | public MetaVo() |
| | | { |
| | | } |
| | | |
| | | public MetaVo(String title, String icon) |
| | | { |
| | | this.title = title; |
| | | this.icon = icon; |
| | | } |
| | | |
| | | public MetaVo(String title, String icon, boolean noCache) |
| | | { |
| | | this.title = title; |
| | | this.icon = icon; |
| | | this.noCache = noCache; |
| | | } |
| | | |
| | | public MetaVo(String title, String icon, String link) |
| | | { |
| | | this.title = title; |
| | | this.icon = icon; |
| | | this.link = link; |
| | | } |
| | | |
| | | public MetaVo(String title, String icon, boolean noCache, String link) |
| | | { |
| | | this.title = title; |
| | | this.icon = icon; |
| | | this.noCache = noCache; |
| | | if (StringUtils.ishttp(link)) |
| | | { |
| | | this.link = link; |
| | | } |
| | | } |
| | | |
| | | public boolean isNoCache() |
| | | { |
| | | return noCache; |
| | | } |
| | | |
| | | public void setNoCache(boolean noCache) |
| | | { |
| | | this.noCache = noCache; |
| | | } |
| | | |
| | | public String getTitle() |
| | | { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) |
| | | { |
| | | this.title = title; |
| | | } |
| | | |
| | | public String getIcon() |
| | | { |
| | | return icon; |
| | | } |
| | | |
| | | public void setIcon(String icon) |
| | | { |
| | | this.icon = icon; |
| | | } |
| | | |
| | | public String getLink() |
| | | { |
| | | return link; |
| | | } |
| | | |
| | | public void setLink(String link) |
| | | { |
| | | this.link = link; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain.vo; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è·¯ç±é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| | | public class RouterVo |
| | | { |
| | | /** |
| | | * è·¯ç±åå |
| | | */ |
| | | private String name; |
| | | |
| | | /** |
| | | * è·¯ç±å°å |
| | | */ |
| | | private String path; |
| | | |
| | | /** |
| | | * æ¯å¦éèè·¯ç±ï¼å½è®¾ç½® true çæ¶å该路ç±ä¸ä¼åä¾§è¾¹æ åºç° |
| | | */ |
| | | private boolean hidden; |
| | | |
| | | /** |
| | | * éå®åå°åï¼å½è®¾ç½® noRedirect çæ¶å该路ç±å¨é¢å
å±å¯¼èªä¸ä¸å¯è¢«ç¹å» |
| | | */ |
| | | private String redirect; |
| | | |
| | | /** |
| | | * ç»ä»¶å°å |
| | | */ |
| | | private String component; |
| | | |
| | | /** |
| | | * è·¯ç±åæ°ï¼å¦ {"id": 1, "name": "ry"} |
| | | */ |
| | | private String query; |
| | | |
| | | /** |
| | | * å½ä½ ä¸ä¸ªè·¯ç±ä¸é¢ç children 声æçè·¯ç±å¤§äº1个æ¶ï¼èªå¨ä¼åæåµå¥ç模å¼--å¦ç»ä»¶é¡µé¢ |
| | | */ |
| | | private Boolean alwaysShow; |
| | | |
| | | /** |
| | | * å
¶ä»å
ç´ |
| | | */ |
| | | private MetaVo meta; |
| | | |
| | | /** |
| | | * åè·¯ç± |
| | | */ |
| | | private List<RouterVo> children; |
| | | |
| | | public String getName() |
| | | { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) |
| | | { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getPath() |
| | | { |
| | | return path; |
| | | } |
| | | |
| | | public void setPath(String path) |
| | | { |
| | | this.path = path; |
| | | } |
| | | |
| | | public boolean getHidden() |
| | | { |
| | | return hidden; |
| | | } |
| | | |
| | | public void setHidden(boolean hidden) |
| | | { |
| | | this.hidden = hidden; |
| | | } |
| | | |
| | | public String getRedirect() |
| | | { |
| | | return redirect; |
| | | } |
| | | |
| | | public void setRedirect(String redirect) |
| | | { |
| | | this.redirect = redirect; |
| | | } |
| | | |
| | | public String getComponent() |
| | | { |
| | | return component; |
| | | } |
| | | |
| | | public void setComponent(String component) |
| | | { |
| | | this.component = component; |
| | | } |
| | | |
| | | public String getQuery() |
| | | { |
| | | return query; |
| | | } |
| | | |
| | | public void setQuery(String query) |
| | | { |
| | | this.query = query; |
| | | } |
| | | |
| | | public Boolean getAlwaysShow() |
| | | { |
| | | return alwaysShow; |
| | | } |
| | | |
| | | public void setAlwaysShow(Boolean alwaysShow) |
| | | { |
| | | this.alwaysShow = alwaysShow; |
| | | } |
| | | |
| | | public MetaVo getMeta() |
| | | { |
| | | return meta; |
| | | } |
| | | |
| | | public void setMeta(MetaVo meta) |
| | | { |
| | | this.meta = meta; |
| | | } |
| | | |
| | | public List<RouterVo> getChildren() |
| | | { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<RouterVo> children) |
| | | { |
| | | this.children = children; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.domain.vo; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.domain.SysMenu; |
| | | |
| | | /** |
| | | * Treeselectæ ç»æå®ä½ç±» |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class TreeSelect implements Serializable |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** èç¹ID */ |
| | | private Long id; |
| | | |
| | | /** èç¹åç§° */ |
| | | private String label; |
| | | |
| | | /** åèç¹ */ |
| | | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| | | private List<TreeSelect> children; |
| | | |
| | | public TreeSelect() |
| | | { |
| | | |
| | | } |
| | | |
| | | public TreeSelect(SysDept dept) |
| | | { |
| | | this.id = dept.getDeptId(); |
| | | this.label = dept.getDeptName(); |
| | | this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); |
| | | } |
| | | |
| | | public TreeSelect(SysMenu menu) |
| | | { |
| | | this.id = menu.getMenuId(); |
| | | this.label = menu.getMenuName(); |
| | | this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); |
| | | } |
| | | |
| | | public Long getId() |
| | | { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) |
| | | { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getLabel() |
| | | { |
| | | return label; |
| | | } |
| | | |
| | | public void setLabel(String label) |
| | | { |
| | | this.label = label; |
| | | } |
| | | |
| | | public List<TreeSelect> getChildren() |
| | | { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<TreeSelect> children) |
| | | { |
| | | this.children = children; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysConfig; |
| | | |
| | | /** |
| | | * åæ°é
ç½® æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysConfigMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return åæ°é
ç½®ä¿¡æ¯ |
| | | */ |
| | | public SysConfig selectConfig(SysConfig config); |
| | | |
| | | /** |
| | | * éè¿IDæ¥è¯¢é
ç½® |
| | | * |
| | | * @param configId åæ°ID |
| | | * @return åæ°é
ç½®ä¿¡æ¯ |
| | | */ |
| | | public SysConfig selectConfigById(Long configId); |
| | | |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®å表 |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return åæ°é
ç½®éå |
| | | */ |
| | | public List<SysConfig> selectConfigList(SysConfig config); |
| | | |
| | | /** |
| | | * æ ¹æ®é®åæ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param configKey åæ°é®å |
| | | * @return åæ°é
ç½®ä¿¡æ¯ |
| | | */ |
| | | public SysConfig checkConfigKeyUnique(String configKey); |
| | | |
| | | /** |
| | | * æ°å¢åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertConfig(SysConfig config); |
| | | |
| | | /** |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateConfig(SysConfig config); |
| | | |
| | | /** |
| | | * å é¤åæ°é
ç½® |
| | | * |
| | | * @param configId åæ°ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteConfigById(Long configId); |
| | | |
| | | /** |
| | | * æ¹éå é¤åæ°ä¿¡æ¯ |
| | | * |
| | | * @param configIds éè¦å é¤çåæ°ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteConfigByIds(Long[] configIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import com.se.system.api.domain.SysDept; |
| | | |
| | | /** |
| | | * é¨é¨ç®¡ç æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysDeptMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢é¨é¨ç®¡çæ°æ® |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return é¨é¨ä¿¡æ¯éå |
| | | */ |
| | | public List<SysDept> selectDeptList(SysDept dept); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢é¨é¨æ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param deptCheckStrictly é¨é¨æ 鿩项æ¯å¦å
³èæ¾ç¤º |
| | | * @return éä¸é¨é¨å表 |
| | | */ |
| | | public List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); |
| | | |
| | | /** |
| | | * æ ¹æ®é¨é¨IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return é¨é¨ä¿¡æ¯ |
| | | */ |
| | | public SysDept selectDeptById(Long deptId); |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ææåé¨é¨ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return é¨é¨å表 |
| | | */ |
| | | public List<SysDept> selectChildrenDeptById(Long deptId); |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ææåé¨é¨ï¼æ£å¸¸ç¶æï¼ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return åé¨é¨æ° |
| | | */ |
| | | public int selectNormalChildrenDeptById(Long deptId); |
| | | |
| | | /** |
| | | * æ¯å¦åå¨åèç¹ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public int hasChildByDeptId(Long deptId); |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨æ¯å¦åå¨ç¨æ· |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public int checkDeptExistUser(Long deptId); |
| | | |
| | | /** |
| | | * æ ¡éªé¨é¨åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param deptName é¨é¨åç§° |
| | | * @param parentId ç¶é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); |
| | | |
| | | /** |
| | | * æ°å¢é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDept(SysDept dept); |
| | | |
| | | /** |
| | | * ä¿®æ¹é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDept(SysDept dept); |
| | | |
| | | /** |
| | | * ä¿®æ¹æå¨é¨é¨æ£å¸¸ç¶æ |
| | | * |
| | | * @param deptIds é¨é¨IDç» |
| | | */ |
| | | public void updateDeptStatusNormal(Long[] deptIds); |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
ç´ å
³ç³» |
| | | * |
| | | * @param depts åå
ç´ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDeptChildren(@Param("depts") List<SysDept> depts); |
| | | |
| | | /** |
| | | * å é¤é¨é¨ç®¡çä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDeptById(Long deptId); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import com.se.system.api.domain.SysDictData; |
| | | |
| | | /** |
| | | * åå
¸è¡¨ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysDictDataMapper |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictData> selectDictDataList(SysDictData dictData); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictData> selectDictDataByType(String dictType); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸é®å¼æ¥è¯¢åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸é®å¼ |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸æ°æ®IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictCode åå
¸æ°æ®ID |
| | | * @return åå
¸æ°æ® |
| | | */ |
| | | public SysDictData selectDictDataById(Long dictCode); |
| | | |
| | | /** |
| | | * æ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸æ°æ® |
| | | */ |
| | | public int countDictDataByType(String dictType); |
| | | |
| | | /** |
| | | * éè¿åå
¸IDå é¤åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictCode åå
¸æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDictDataById(Long dictCode); |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictCodes éè¦å é¤çåå
¸æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDictDataByIds(Long[] dictCodes); |
| | | |
| | | /** |
| | | * æ°å¢åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDictData(SysDictData dictData); |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDictData(SysDictData dictData); |
| | | |
| | | /** |
| | | * åæ¥ä¿®æ¹åå
¸ç±»å |
| | | * |
| | | * @param oldDictType æ§åå
¸ç±»å |
| | | * @param newDictType æ°æ§åå
¸ç±»å |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysDictType; |
| | | |
| | | /** |
| | | * åå
¸è¡¨ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysDictTypeMapper |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸ç±»å |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictType> selectDictTypeList(SysDictType dictType); |
| | | |
| | | /** |
| | | * æ ¹æ®ææåå
¸ç±»å |
| | | * |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictType> selectDictTypeAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictId åå
¸ç±»åID |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | public SysDictType selectDictTypeById(Long dictId); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | public SysDictType selectDictTypeByType(String dictType); |
| | | |
| | | /** |
| | | * éè¿åå
¸IDå é¤åå
¸ä¿¡æ¯ |
| | | * |
| | | * @param dictId åå
¸ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDictTypeById(Long dictId); |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictIds éè¦å é¤çåå
¸ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDictTypeByIds(Long[] dictIds); |
| | | |
| | | /** |
| | | * æ°å¢åå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDictType(SysDictType dictType); |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDictType(SysDictType dictType); |
| | | |
| | | /** |
| | | * æ ¡éªåå
¸ç±»åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return ç»æ |
| | | */ |
| | | public SysDictType checkDictTypeUnique(String dictType); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysLogininfor; |
| | | |
| | | /** |
| | | * ç³»ç»è®¿é®æ¥å¿æ
åµä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysLogininforMapper |
| | | { |
| | | /** |
| | | * æ°å¢ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | */ |
| | | public int insertLogininfor(SysLogininfor logininfor); |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»ç»å½æ¥å¿éå |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | * @return ç»å½è®°å½éå |
| | | */ |
| | | public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param infoIds éè¦å é¤çç»å½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteLogininforByIds(Long[] infoIds); |
| | | |
| | | /** |
| | | * æ¸
空系ç»ç»å½æ¥å¿ |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public int cleanLogininfor(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysMenu; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | /** |
| | | * èå表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysMenuMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuList(SysMenu menu); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·æææé |
| | | * |
| | | * @return æéå表 |
| | | */ |
| | | public List<String> selectMenuPerms(); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuListByUserId(SysMenu menu); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢æé |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return æéå表 |
| | | */ |
| | | public List<String> selectMenuPermsByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢æé |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return æéå表 |
| | | */ |
| | | public List<String> selectMenuPermsByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢èå |
| | | * |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuTreeAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢èå |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuTreeByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢èåæ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param menuCheckStrictly èåæ éæ©é¡¹æ¯å¦å
³èæ¾ç¤º |
| | | * @return éä¸èåå表 |
| | | */ |
| | | public List<Long> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly); |
| | | |
| | | /** |
| | | * æ ¹æ®èåIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return èåä¿¡æ¯ |
| | | */ |
| | | public SysMenu selectMenuById(Long menuId); |
| | | |
| | | /** |
| | | * æ¯å¦åå¨èååèç¹ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | public int hasChildByMenuId(Long menuId); |
| | | |
| | | /** |
| | | * æ°å¢èåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertMenu(SysMenu menu); |
| | | |
| | | /** |
| | | * ä¿®æ¹èåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateMenu(SysMenu menu); |
| | | |
| | | /** |
| | | * å é¤èå管çä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteMenuById(Long menuId); |
| | | |
| | | /** |
| | | * æ ¡éªèååç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param menuName èååç§° |
| | | * @param parentId ç¶èåID |
| | | * @return ç»æ |
| | | */ |
| | | public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysNotice; |
| | | |
| | | /** |
| | | * éç¥å
¬å表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysNoticeMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return å
¬åä¿¡æ¯ |
| | | */ |
| | | public SysNotice selectNoticeById(Long noticeId); |
| | | |
| | | /** |
| | | * æ¥è¯¢å
¬åå表 |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return å
¬åéå |
| | | */ |
| | | public List<SysNotice> selectNoticeList(SysNotice notice); |
| | | |
| | | /** |
| | | * æ°å¢å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertNotice(SysNotice notice); |
| | | |
| | | /** |
| | | * ä¿®æ¹å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateNotice(SysNotice notice); |
| | | |
| | | /** |
| | | * æ¹éå é¤å
Œ |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteNoticeById(Long noticeId); |
| | | |
| | | /** |
| | | * æ¹éå é¤å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeIds éè¦å é¤çå
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteNoticeByIds(Long[] noticeIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysOperLog; |
| | | |
| | | /** |
| | | * æä½æ¥å¿ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysOperLogMapper |
| | | { |
| | | /** |
| | | * æ°å¢æä½æ¥å¿ |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | */ |
| | | public int insertOperlog(SysOperLog operLog); |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»æä½æ¥å¿éå |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | * @return æä½æ¥å¿éå |
| | | */ |
| | | public List<SysOperLog> selectOperLogList(SysOperLog operLog); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»æä½æ¥å¿ |
| | | * |
| | | * @param operIds éè¦å é¤çæä½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteOperLogByIds(Long[] operIds); |
| | | |
| | | /** |
| | | * æ¥è¯¢æä½æ¥å¿è¯¦ç» |
| | | * |
| | | * @param operId æä½ID |
| | | * @return æä½æ¥å¿å¯¹è±¡ |
| | | */ |
| | | public SysOperLog selectOperLogById(Long operId); |
| | | |
| | | /** |
| | | * æ¸
空æä½æ¥å¿ |
| | | */ |
| | | public void cleanOperLog(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysPost; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysPostMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢å²ä½æ°æ®éå |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return å²ä½æ°æ®éå |
| | | */ |
| | | public List<SysPost> selectPostList(SysPost post); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææå²ä½ |
| | | * |
| | | * @return å²ä½å表 |
| | | */ |
| | | public List<SysPost> selectPostAll(); |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysPost selectPostById(Long postId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åå²ä½éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸å²ä½IDå表 |
| | | */ |
| | | public List<Long> selectPostListByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ¥è¯¢ç¨æ·æå±å²ä½ç» |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç»æ |
| | | */ |
| | | public List<SysPost> selectPostsByUserName(String userName); |
| | | |
| | | /** |
| | | * å é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deletePostById(Long postId); |
| | | |
| | | /** |
| | | * æ¹éå é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postIds éè¦å é¤çå²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deletePostByIds(Long[] postIds); |
| | | |
| | | /** |
| | | * ä¿®æ¹å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updatePost(SysPost post); |
| | | |
| | | /** |
| | | * æ°å¢å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertPost(SysPost post); |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½åç§° |
| | | * |
| | | * @param postName å²ä½åç§° |
| | | * @return ç»æ |
| | | */ |
| | | public SysPost checkPostNameUnique(String postName); |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½ç¼ç |
| | | * |
| | | * @param postCode å²ä½ç¼ç |
| | | * @return ç»æ |
| | | */ |
| | | public SysPost checkPostCodeUnique(String postCode); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysRoleDept; |
| | | |
| | | /** |
| | | * è§è²ä¸é¨é¨å
³è表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysRoleDeptMapper |
| | | { |
| | | /** |
| | | * éè¿è§è²IDå é¤è§è²åé¨é¨å
³è |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleDeptByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ¹éå é¤è§è²é¨é¨å
³èä¿¡æ¯ |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleDept(Long[] ids); |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨ä½¿ç¨æ°é |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public int selectCountRoleDeptByDeptId(Long deptId); |
| | | |
| | | /** |
| | | * æ¹éæ°å¢è§è²é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param roleDeptList è§è²é¨é¨å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchRoleDept(List<SysRoleDept> roleDeptList); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysRole; |
| | | |
| | | /** |
| | | * è§è²è¡¨ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysRoleMapper |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢è§è²æ°æ® |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return è§è²æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysRole> selectRoleList(SysRole role); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢è§è² |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return è§è²å表 |
| | | */ |
| | | public List<SysRole> selectRolePermissionByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè§è² |
| | | * |
| | | * @return è§è²å表 |
| | | */ |
| | | public List<SysRole> selectRoleAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åè§è²éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸è§è²IDå表 |
| | | */ |
| | | public List<Long> selectRoleListByUserId(Long userId); |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysRole selectRoleById(Long roleId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢è§è² |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return è§è²å表 |
| | | */ |
| | | public List<SysRole> selectRolesByUserName(String userName); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param roleName è§è²åç§° |
| | | * @return è§è²ä¿¡æ¯ |
| | | */ |
| | | public SysRole checkRoleNameUnique(String roleName); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æéæ¯å¦å¯ä¸ |
| | | * |
| | | * @param roleKey è§è²æé |
| | | * @return è§è²ä¿¡æ¯ |
| | | */ |
| | | public SysRole checkRoleKeyUnique(String roleKey); |
| | | |
| | | /** |
| | | * ä¿®æ¹è§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateRole(SysRole role); |
| | | |
| | | /** |
| | | * æ°å¢è§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertRole(SysRole role); |
| | | |
| | | /** |
| | | * éè¿è§è²IDå é¤è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleById(Long roleId); |
| | | |
| | | /** |
| | | * æ¹éå é¤è§è²ä¿¡æ¯ |
| | | * |
| | | * @param roleIds éè¦å é¤çè§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleByIds(Long[] roleIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysRoleMenu; |
| | | |
| | | /** |
| | | * è§è²ä¸èåå
³è表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysRoleMenuMapper |
| | | { |
| | | /** |
| | | * æ¥è¯¢èåä½¿ç¨æ°é |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | public int checkMenuExistRole(Long menuId); |
| | | |
| | | /** |
| | | * éè¿è§è²IDå é¤è§è²åèåå
³è |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleMenuByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ¹éå é¤è§è²èåå
³èä¿¡æ¯ |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleMenu(Long[] ids); |
| | | |
| | | /** |
| | | * æ¹éæ°å¢è§è²èåä¿¡æ¯ |
| | | * |
| | | * @param roleMenuList è§è²èåå表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchRoleMenu(List<SysRoleMenu> roleMenuList); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import com.se.system.api.domain.SysUser; |
| | | |
| | | /** |
| | | * ç¨æ·è¡¨ æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysUserMapper |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢ç¨æ·å表 |
| | | * |
| | | * @param sysUser ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectUserList(SysUser sysUser); |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢å·²é
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectAllocatedList(SysUser user); |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectUnallocatedList(SysUser user); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysUser selectUserByUserName(String userName); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysUser selectUserById(Long userId); |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertUser(SysUser user); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateUser(SysUser user); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·å¤´å |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param avatar 头åå°å |
| | | * @return ç»æ |
| | | */ |
| | | public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar); |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param password å¯ç |
| | | * @return ç»æ |
| | | */ |
| | | public int resetUserPwd(@Param("userName") String userName, @Param("password") String password); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserById(Long userId); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param userIds éè¦å é¤çç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserByIds(Long[] userIds); |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param userName ç¨æ·åç§° |
| | | * @return ç»æ |
| | | */ |
| | | public SysUser checkUserNameUnique(String userName); |
| | | |
| | | /** |
| | | * æ ¡éªææºå·ç æ¯å¦å¯ä¸ |
| | | * |
| | | * @param phonenumber ææºå·ç |
| | | * @return ç»æ |
| | | */ |
| | | public SysUser checkPhoneUnique(String phonenumber); |
| | | |
| | | /** |
| | | * æ ¡éªemailæ¯å¦å¯ä¸ |
| | | * |
| | | * @param email ç¨æ·é®ç®± |
| | | * @return ç»æ |
| | | */ |
| | | public SysUser checkEmailUnique(String email); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysUserPost; |
| | | |
| | | /** |
| | | * ç¨æ·ä¸å²ä½å
³è表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysUserPostMapper |
| | | { |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ·åå²ä½å
³è |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserPostByUserId(Long userId); |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä½¿ç¨æ°é |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int countUserPostById(Long postId); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·åå²ä½å
³è |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserPost(Long[] ids); |
| | | |
| | | /** |
| | | * æ¹éæ°å¢ç¨æ·å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param userPostList ç¨æ·å²ä½å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchUserPost(List<SysUserPost> userPostList); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysUserRole; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | /** |
| | | * ç¨æ·ä¸è§è²å
³è表 æ°æ®å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface SysUserRoleMapper |
| | | { |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ·åè§è²å
³è |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserRoleByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·åè§è²å
³è |
| | | * |
| | | * @param ids éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserRole(Long[] ids); |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è²ä½¿ç¨æ°é |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int countUserRoleByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ¹éæ°å¢ç¨æ·è§è²ä¿¡æ¯ |
| | | * |
| | | * @param userRoleList ç¨æ·è§è²å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchUserRole(List<SysUserRole> userRoleList); |
| | | |
| | | /** |
| | | * å é¤ç¨æ·åè§è²å
³èä¿¡æ¯ |
| | | * |
| | | * @param userRole ç¨æ·åè§è²å
³èä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserRoleInfo(SysUserRole userRole); |
| | | |
| | | /** |
| | | * æ¹éåæ¶ææç¨æ·è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param userIds éè¦å é¤çç¨æ·æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysConfig; |
| | | |
| | | /** |
| | | * åæ°é
ç½® æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysConfigService |
| | | { |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param configId åæ°é
ç½®ID |
| | | * @return åæ°é
ç½®ä¿¡æ¯ |
| | | */ |
| | | public SysConfig selectConfigById(Long configId); |
| | | |
| | | /** |
| | | * æ ¹æ®é®åæ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param configKey åæ°é®å |
| | | * @return åæ°é®å¼ |
| | | */ |
| | | public String selectConfigByKey(String configKey); |
| | | |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®å表 |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return åæ°é
ç½®éå |
| | | */ |
| | | public List<SysConfig> selectConfigList(SysConfig config); |
| | | |
| | | /** |
| | | * æ°å¢åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertConfig(SysConfig config); |
| | | |
| | | /** |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateConfig(SysConfig config); |
| | | |
| | | /** |
| | | * æ¹éå é¤åæ°ä¿¡æ¯ |
| | | * |
| | | * @param configIds éè¦å é¤çåæ°ID |
| | | */ |
| | | public void deleteConfigByIds(Long[] configIds); |
| | | |
| | | /** |
| | | * å è½½åæ°ç¼åæ°æ® |
| | | */ |
| | | public void loadingConfigCache(); |
| | | |
| | | /** |
| | | * æ¸
ç©ºåæ°ç¼åæ°æ® |
| | | */ |
| | | public void clearConfigCache(); |
| | | |
| | | /** |
| | | * éç½®åæ°ç¼åæ°æ® |
| | | */ |
| | | public void resetConfigCache(); |
| | | |
| | | /** |
| | | * æ ¡éªåæ°é®åæ¯å¦å¯ä¸ |
| | | * |
| | | * @param config åæ°ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkConfigKeyUnique(SysConfig config); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.domain.vo.TreeSelect; |
| | | |
| | | /** |
| | | * é¨é¨ç®¡ç æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysDeptService |
| | | { |
| | | /** |
| | | * æ¥è¯¢é¨é¨ç®¡çæ°æ® |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return é¨é¨ä¿¡æ¯éå |
| | | */ |
| | | public List<SysDept> selectDeptList(SysDept dept); |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨æ ç»æä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return é¨é¨æ ä¿¡æ¯éå |
| | | */ |
| | | public List<TreeSelect> selectDeptTreeList(SysDept dept); |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦æ ç»æ |
| | | * |
| | | * @param depts é¨é¨å表 |
| | | * @return æ ç»æå表 |
| | | */ |
| | | public List<SysDept> buildDeptTree(List<SysDept> depts); |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦ä¸ææ ç»æ |
| | | * |
| | | * @param depts é¨é¨å表 |
| | | * @return 䏿æ ç»æå表 |
| | | */ |
| | | public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢é¨é¨æ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return éä¸é¨é¨å表 |
| | | */ |
| | | public List<Long> selectDeptListByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ ¹æ®é¨é¨IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return é¨é¨ä¿¡æ¯ |
| | | */ |
| | | public SysDept selectDeptById(Long deptId); |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ææåé¨é¨ï¼æ£å¸¸ç¶æï¼ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return åé¨é¨æ° |
| | | */ |
| | | public int selectNormalChildrenDeptById(Long deptId); |
| | | |
| | | /** |
| | | * æ¯å¦åå¨é¨é¨åèç¹ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public boolean hasChildByDeptId(Long deptId); |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨æ¯å¦åå¨ç¨æ· |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ true åå¨ false ä¸åå¨ |
| | | */ |
| | | public boolean checkDeptExistUser(Long deptId); |
| | | |
| | | /** |
| | | * æ ¡éªé¨é¨åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkDeptNameUnique(SysDept dept); |
| | | |
| | | /** |
| | | * æ ¡éªé¨é¨æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param deptId é¨é¨id |
| | | */ |
| | | public void checkDeptDataScope(Long deptId); |
| | | |
| | | /** |
| | | * æ°å¢ä¿åé¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDept(SysDept dept); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åé¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDept(SysDept dept); |
| | | |
| | | /** |
| | | * å é¤é¨é¨ç®¡çä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteDeptById(Long deptId); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysDictData; |
| | | |
| | | /** |
| | | * åå
¸ ä¸å¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysDictDataService |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictData> selectDictDataList(SysDictData dictData); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸é®å¼æ¥è¯¢åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸é®å¼ |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public String selectDictLabel(String dictType, String dictValue); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸æ°æ®IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictCode åå
¸æ°æ®ID |
| | | * @return åå
¸æ°æ® |
| | | */ |
| | | public SysDictData selectDictDataById(Long dictCode); |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictCodes éè¦å é¤çåå
¸æ°æ®ID |
| | | */ |
| | | public void deleteDictDataByIds(Long[] dictCodes); |
| | | |
| | | /** |
| | | * æ°å¢ä¿ååå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDictData(SysDictData dictData); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDictData(SysDictData dictData); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysDictData; |
| | | import com.se.system.api.domain.SysDictType; |
| | | |
| | | /** |
| | | * åå
¸ ä¸å¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysDictTypeService |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸ç±»å |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictType> selectDictTypeList(SysDictType dictType); |
| | | |
| | | /** |
| | | * æ ¹æ®ææåå
¸ç±»å |
| | | * |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictType> selectDictTypeAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysDictData> selectDictDataByType(String dictType); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictId åå
¸ç±»åID |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | public SysDictType selectDictTypeById(Long dictId); |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | public SysDictType selectDictTypeByType(String dictType); |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸ä¿¡æ¯ |
| | | * |
| | | * @param dictIds éè¦å é¤çåå
¸ID |
| | | */ |
| | | public void deleteDictTypeByIds(Long[] dictIds); |
| | | |
| | | /** |
| | | * å è½½åå
¸ç¼åæ°æ® |
| | | */ |
| | | public void loadingDictCache(); |
| | | |
| | | /** |
| | | * æ¸
空åå
¸ç¼åæ°æ® |
| | | */ |
| | | public void clearDictCache(); |
| | | |
| | | /** |
| | | * éç½®åå
¸ç¼åæ°æ® |
| | | */ |
| | | public void resetDictCache(); |
| | | |
| | | /** |
| | | * æ°å¢ä¿ååå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertDictType(SysDictType dictType); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateDictType(SysDictType dictType); |
| | | |
| | | /** |
| | | * æ ¡éªåå
¸ç±»åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkDictTypeUnique(SysDictType dictType); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysLogininfor; |
| | | |
| | | /** |
| | | * ç³»ç»è®¿é®æ¥å¿æ
åµä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysLogininforService |
| | | { |
| | | /** |
| | | * æ°å¢ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | */ |
| | | public int insertLogininfor(SysLogininfor logininfor); |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»ç»å½æ¥å¿éå |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | * @return ç»å½è®°å½éå |
| | | */ |
| | | public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param infoIds éè¦å é¤çç»å½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteLogininforByIds(Long[] infoIds); |
| | | |
| | | /** |
| | | * æ¸
空系ç»ç»å½æ¥å¿ |
| | | */ |
| | | public void cleanLogininfor(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import com.se.system.domain.SysMenu; |
| | | import com.se.system.domain.vo.RouterVo; |
| | | import com.se.system.domain.vo.TreeSelect; |
| | | |
| | | /** |
| | | * èå ä¸å¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysMenuService |
| | | { |
| | | /** |
| | | * æ ¹æ®ç¨æ·æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuList(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @param userId ç¨æ·ID |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuList(SysMenu menu, Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢æé |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return æéå表 |
| | | */ |
| | | public Set<String> selectMenuPermsByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢æé |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return æéå表 |
| | | */ |
| | | public Set<String> selectMenuPermsByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢èåæ ä¿¡æ¯ |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return èåå表 |
| | | */ |
| | | public List<SysMenu> selectMenuTreeByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢èåæ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return éä¸èåå表 |
| | | */ |
| | | public List<Long> selectMenuListByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æå»ºåç«¯è·¯ç±æéè¦çèå |
| | | * |
| | | * @param menus èåå表 |
| | | * @return è·¯ç±å表 |
| | | */ |
| | | public List<RouterVo> buildMenus(List<SysMenu> menus); |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦æ ç»æ |
| | | * |
| | | * @param menus èåå表 |
| | | * @return æ ç»æå表 |
| | | */ |
| | | public List<SysMenu> buildMenuTree(List<SysMenu> menus); |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦ä¸ææ ç»æ |
| | | * |
| | | * @param menus èåå表 |
| | | * @return 䏿æ ç»æå表 |
| | | */ |
| | | public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus); |
| | | |
| | | /** |
| | | * æ ¹æ®èåIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return èåä¿¡æ¯ |
| | | */ |
| | | public SysMenu selectMenuById(Long menuId); |
| | | |
| | | /** |
| | | * æ¯å¦åå¨èååèç¹ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ true åå¨ false ä¸åå¨ |
| | | */ |
| | | public boolean hasChildByMenuId(Long menuId); |
| | | |
| | | /** |
| | | * æ¥è¯¢è忝å¦åå¨è§è² |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ true åå¨ false ä¸åå¨ |
| | | */ |
| | | public boolean checkMenuExistRole(Long menuId); |
| | | |
| | | /** |
| | | * æ°å¢ä¿åèåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertMenu(SysMenu menu); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åèåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateMenu(SysMenu menu); |
| | | |
| | | /** |
| | | * å é¤èå管çä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteMenuById(Long menuId); |
| | | |
| | | /** |
| | | * æ ¡éªèååç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkMenuNameUnique(SysMenu menu); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysNotice; |
| | | |
| | | /** |
| | | * å
¬å æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysNoticeService |
| | | { |
| | | /** |
| | | * æ¥è¯¢å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return å
¬åä¿¡æ¯ |
| | | */ |
| | | public SysNotice selectNoticeById(Long noticeId); |
| | | |
| | | /** |
| | | * æ¥è¯¢å
¬åå表 |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return å
¬åéå |
| | | */ |
| | | public List<SysNotice> selectNoticeList(SysNotice notice); |
| | | |
| | | /** |
| | | * æ°å¢å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertNotice(SysNotice notice); |
| | | |
| | | /** |
| | | * ä¿®æ¹å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateNotice(SysNotice notice); |
| | | |
| | | /** |
| | | * å é¤å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteNoticeById(Long noticeId); |
| | | |
| | | /** |
| | | * æ¹éå é¤å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeIds éè¦å é¤çå
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteNoticeByIds(Long[] noticeIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysOperLog; |
| | | |
| | | /** |
| | | * æä½æ¥å¿ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysOperLogService |
| | | { |
| | | /** |
| | | * æ°å¢æä½æ¥å¿ |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertOperlog(SysOperLog operLog); |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»æä½æ¥å¿éå |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | * @return æä½æ¥å¿éå |
| | | */ |
| | | public List<SysOperLog> selectOperLogList(SysOperLog operLog); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»æä½æ¥å¿ |
| | | * |
| | | * @param operIds éè¦å é¤çæä½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteOperLogByIds(Long[] operIds); |
| | | |
| | | /** |
| | | * æ¥è¯¢æä½æ¥å¿è¯¦ç» |
| | | * |
| | | * @param operId æä½ID |
| | | * @return æä½æ¥å¿å¯¹è±¡ |
| | | */ |
| | | public SysOperLog selectOperLogById(Long operId); |
| | | |
| | | /** |
| | | * æ¸
空æä½æ¥å¿ |
| | | */ |
| | | public void cleanOperLog(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.Set; |
| | | |
| | | import com.se.system.api.domain.SysUser; |
| | | |
| | | /** |
| | | * æéä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysPermissionService |
| | | { |
| | | /** |
| | | * è·åè§è²æ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·Id |
| | | * @return è§è²æéä¿¡æ¯ |
| | | */ |
| | | public Set<String> getRolePermission(SysUser user); |
| | | |
| | | /** |
| | | * è·åèåæ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·Id |
| | | * @return èåæéä¿¡æ¯ |
| | | */ |
| | | public Set<String> getMenuPermission(SysUser user); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.domain.SysPost; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysPostService |
| | | { |
| | | /** |
| | | * æ¥è¯¢å²ä½ä¿¡æ¯éå |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return å²ä½å表 |
| | | */ |
| | | public List<SysPost> selectPostList(SysPost post); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææå²ä½ |
| | | * |
| | | * @return å²ä½å表 |
| | | */ |
| | | public List<SysPost> selectPostAll(); |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysPost selectPostById(Long postId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åå²ä½éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸å²ä½IDå表 |
| | | */ |
| | | public List<Long> selectPostListByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½åç§° |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkPostNameUnique(SysPost post); |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½ç¼ç |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkPostCodeUnique(SysPost post); |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä½¿ç¨æ°é |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int countUserPostById(Long postId); |
| | | |
| | | /** |
| | | * å é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deletePostById(Long postId); |
| | | |
| | | /** |
| | | * æ¹éå é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postIds éè¦å é¤çå²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deletePostByIds(Long[] postIds); |
| | | |
| | | /** |
| | | * æ°å¢ä¿åå²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertPost(SysPost post); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åå²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updatePost(SysPost post); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.domain.SysUserRole; |
| | | |
| | | /** |
| | | * è§è²ä¸å¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysRoleService |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢è§è²æ°æ® |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return è§è²æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | public List<SysRole> selectRoleList(SysRole role); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢è§è²å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return è§è²å表 |
| | | */ |
| | | public List<SysRole> selectRolesByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢è§è²æé |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return æéå表 |
| | | */ |
| | | public Set<String> selectRolePermissionByUserId(Long userId); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè§è² |
| | | * |
| | | * @return è§è²å表 |
| | | */ |
| | | public List<SysRole> selectRoleAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åè§è²éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸è§è²IDå表 |
| | | */ |
| | | public List<Long> selectRoleListByUserId(Long userId); |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysRole selectRoleById(Long roleId); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkRoleNameUnique(SysRole role); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æéæ¯å¦å¯ä¸ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkRoleKeyUnique(SysRole role); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æ¯å¦å
许æä½ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | */ |
| | | public void checkRoleAllowed(SysRole role); |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param roleIds è§è²id |
| | | */ |
| | | public void checkRoleDataScope(Long... roleIds); |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è²ä½¿ç¨æ°é |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int countUserRoleByRoleId(Long roleId); |
| | | |
| | | /** |
| | | * æ°å¢ä¿åè§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertRole(SysRole role); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åè§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateRole(SysRole role); |
| | | |
| | | /** |
| | | * ä¿®æ¹è§è²ç¶æ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateRoleStatus(SysRole role); |
| | | |
| | | /** |
| | | * ä¿®æ¹æ°æ®æéä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int authDataScope(SysRole role); |
| | | |
| | | /** |
| | | * éè¿è§è²IDå é¤è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleById(Long roleId); |
| | | |
| | | /** |
| | | * æ¹éå é¤è§è²ä¿¡æ¯ |
| | | * |
| | | * @param roleIds éè¦å é¤çè§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteRoleByIds(Long[] roleIds); |
| | | |
| | | /** |
| | | * åæ¶ææç¨æ·è§è² |
| | | * |
| | | * @param userRole ç¨æ·åè§è²å
³èä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteAuthUser(SysUserRole userRole); |
| | | |
| | | /** |
| | | * æ¹éåæ¶ææç¨æ·è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param userIds éè¦åæ¶ææçç¨æ·æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteAuthUsers(Long roleId, Long[] userIds); |
| | | |
| | | /** |
| | | * æ¹ééæ©ææç¨æ·è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param userIds éè¦å é¤çç¨æ·æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | public int insertAuthUsers(Long roleId, Long[] userIds); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import com.se.system.api.model.LoginUser; |
| | | import com.se.system.domain.SysUserOnline; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ· æå¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysUserOnlineService |
| | | { |
| | | /** |
| | | * éè¿ç»å½å°åæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param ipaddr ç»å½å°å |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åç§°æ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param userName ç¨æ·åç§° |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public SysUserOnline selectOnlineByUserName(String userName, LoginUser user); |
| | | |
| | | /** |
| | | * éè¿ç»å½å°å/ç¨æ·åç§°æ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param ipaddr ç»å½å°å |
| | | * @param userName ç¨æ·åç§° |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user); |
| | | |
| | | /** |
| | | * 设置å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ· |
| | | */ |
| | | public SysUserOnline loginUserToUserOnline(LoginUser user); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import java.util.List; |
| | | import com.se.system.api.domain.SysUser; |
| | | |
| | | /** |
| | | * ç¨æ· ä¸å¡å± |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ISysUserService |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢ç¨æ·å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectUserList(SysUser user); |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢å·²åé
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectAllocatedList(SysUser user); |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | public List<SysUser> selectUnallocatedList(SysUser user); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysUser selectUserByUserName(String userName); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysUser selectUserById(Long userId); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢ç¨æ·æå±è§è²ç» |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç»æ |
| | | */ |
| | | public String selectUserRoleGroup(String userName); |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢ç¨æ·æå±å²ä½ç» |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç»æ |
| | | */ |
| | | public String selectUserPostGroup(String userName); |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkUserNameUnique(SysUser user); |
| | | |
| | | /** |
| | | * æ ¡éªææºå·ç æ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkPhoneUnique(SysUser user); |
| | | |
| | | /** |
| | | * æ ¡éªemailæ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkEmailUnique(SysUser user); |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·æ¯å¦å
许æä½ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public void checkUserAllowed(SysUser user); |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·id |
| | | */ |
| | | public void checkUserDataScope(Long userId); |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertUser(SysUser user); |
| | | |
| | | /** |
| | | * 注åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean registerUser(SysUser user); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateUser(SysUser user); |
| | | |
| | | /** |
| | | * ç¨æ·ææè§è² |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @param roleIds è§è²ç» |
| | | */ |
| | | public void insertUserAuth(Long userId, Long[] roleIds); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·ç¶æ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateUserStatus(SysUser user); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·åºæ¬ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean updateUserProfile(SysUser user); |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·å¤´å |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param avatar 头åå°å |
| | | * @return ç»æ |
| | | */ |
| | | public boolean updateUserAvatar(String userName, String avatar); |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int resetPwd(SysUser user); |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param password å¯ç |
| | | * @return ç»æ |
| | | */ |
| | | public int resetUserPwd(String userName, String password); |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserById(Long userId); |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param userIds éè¦å é¤çç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteUserByIds(Long[] userIds); |
| | | |
| | | /** |
| | | * 导å
¥ç¨æ·æ°æ® |
| | | * |
| | | * @param userList ç¨æ·æ°æ®å表 |
| | | * @param isUpdateSupport æ¯å¦æ´æ°æ¯æï¼å¦æå·²åå¨ï¼åè¿è¡æ´æ°æ°æ® |
| | | * @param operName æä½ç¨æ· |
| | | * @return ç»æ |
| | | */ |
| | | public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | import com.se.system.domain.SysConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.text.Convert; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.redis.service.RedisService; |
| | | import com.se.system.mapper.SysConfigMapper; |
| | | import com.se.system.service.ISysConfigService; |
| | | |
| | | /** |
| | | * åæ°é
ç½® æå¡å±å®ç° |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysConfigServiceImpl implements ISysConfigService |
| | | { |
| | | @Autowired |
| | | private SysConfigMapper configMapper; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * 项ç®å¯å¨æ¶ï¼åå§ååæ°å°ç¼å |
| | | */ |
| | | @PostConstruct |
| | | public void init() |
| | | { |
| | | loadingConfigCache(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param configId åæ°é
ç½®ID |
| | | * @return åæ°é
ç½®ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysConfig selectConfigById(Long configId) |
| | | { |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigId(configId); |
| | | return configMapper.selectConfig(config); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é®åæ¥è¯¢åæ°é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param configKey åæ°key |
| | | * @return åæ°é®å¼ |
| | | */ |
| | | @Override |
| | | public String selectConfigByKey(String configKey) |
| | | { |
| | | String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey))); |
| | | if (StringUtils.isNotEmpty(configValue)) |
| | | { |
| | | return configValue; |
| | | } |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey(configKey); |
| | | SysConfig retConfig = configMapper.selectConfig(config); |
| | | if (StringUtils.isNotNull(retConfig)) |
| | | { |
| | | redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); |
| | | return retConfig.getConfigValue(); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åæ°é
ç½®å表 |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return åæ°é
ç½®éå |
| | | */ |
| | | @Override |
| | | public List<SysConfig> selectConfigList(SysConfig config) |
| | | { |
| | | return configMapper.selectConfigList(config); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertConfig(SysConfig config) |
| | | { |
| | | int row = configMapper.insertConfig(config); |
| | | if (row > 0) |
| | | { |
| | | redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateConfig(SysConfig config) |
| | | { |
| | | SysConfig temp = configMapper.selectConfigById(config.getConfigId()); |
| | | if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) |
| | | { |
| | | redisService.deleteObject(getCacheKey(temp.getConfigKey())); |
| | | } |
| | | |
| | | int row = configMapper.updateConfig(config); |
| | | if (row > 0) |
| | | { |
| | | redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤åæ°ä¿¡æ¯ |
| | | * |
| | | * @param configIds éè¦å é¤çåæ°ID |
| | | */ |
| | | @Override |
| | | public void deleteConfigByIds(Long[] configIds) |
| | | { |
| | | for (Long configId : configIds) |
| | | { |
| | | SysConfig config = selectConfigById(configId); |
| | | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) |
| | | { |
| | | throw new ServiceException(String.format("å
ç½®åæ°ã%1$sãä¸è½å é¤ ", config.getConfigKey())); |
| | | } |
| | | configMapper.deleteConfigById(configId); |
| | | redisService.deleteObject(getCacheKey(config.getConfigKey())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å è½½åæ°ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void loadingConfigCache() |
| | | { |
| | | List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig()); |
| | | for (SysConfig config : configsList) |
| | | { |
| | | redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¸
ç©ºåæ°ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void clearConfigCache() |
| | | { |
| | | Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*"); |
| | | redisService.deleteObject(keys); |
| | | } |
| | | |
| | | /** |
| | | * éç½®åæ°ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void resetConfigCache() |
| | | { |
| | | clearConfigCache(); |
| | | loadingConfigCache(); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªåæ°é®åæ¯å¦å¯ä¸ |
| | | * |
| | | * @param config åæ°é
ç½®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkConfigKeyUnique(SysConfig config) |
| | | { |
| | | Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); |
| | | SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey()); |
| | | if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * 设置cache key |
| | | * |
| | | * @param configKey åæ°é® |
| | | * @return ç¼åé®key |
| | | */ |
| | | private String getCacheKey(String configKey) |
| | | { |
| | | return CacheConstants.SYS_CONFIG_KEY + configKey; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.text.Convert; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.datascope.annotation.DataScope; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysDept; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.domain.vo.TreeSelect; |
| | | import com.se.system.mapper.SysDeptMapper; |
| | | import com.se.system.mapper.SysRoleMapper; |
| | | import com.se.system.service.ISysDeptService; |
| | | |
| | | /** |
| | | * é¨é¨ç®¡ç æå¡å®ç° |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl implements ISysDeptService |
| | | { |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨ç®¡çæ°æ® |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return é¨é¨ä¿¡æ¯éå |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysDept> selectDeptList(SysDept dept) |
| | | { |
| | | return deptMapper.selectDeptList(dept); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨æ ç»æä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return é¨é¨æ ä¿¡æ¯éå |
| | | */ |
| | | @Override |
| | | public List<TreeSelect> selectDeptTreeList(SysDept dept) |
| | | { |
| | | List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); |
| | | return buildDeptTreeSelect(depts); |
| | | } |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦æ ç»æ |
| | | * |
| | | * @param depts é¨é¨å表 |
| | | * @return æ ç»æå表 |
| | | */ |
| | | @Override |
| | | public List<SysDept> buildDeptTree(List<SysDept> depts) |
| | | { |
| | | List<SysDept> returnList = new ArrayList<SysDept>(); |
| | | List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); |
| | | for (SysDept dept : depts) |
| | | { |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(dept.getParentId())) |
| | | { |
| | | recursionFn(depts, dept); |
| | | returnList.add(dept); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) |
| | | { |
| | | returnList = depts; |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦ä¸ææ ç»æ |
| | | * |
| | | * @param depts é¨é¨å表 |
| | | * @return 䏿æ ç»æå表 |
| | | */ |
| | | @Override |
| | | public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts) |
| | | { |
| | | List<SysDept> deptTrees = buildDeptTree(depts); |
| | | return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢é¨é¨æ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return éä¸é¨é¨å表 |
| | | */ |
| | | @Override |
| | | public List<Long> selectDeptListByRoleId(Long roleId) |
| | | { |
| | | SysRole role = roleMapper.selectRoleById(roleId); |
| | | return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é¨é¨IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return é¨é¨ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysDept selectDeptById(Long deptId) |
| | | { |
| | | return deptMapper.selectDeptById(deptId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ææåé¨é¨ï¼æ£å¸¸ç¶æï¼ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return åé¨é¨æ° |
| | | */ |
| | | @Override |
| | | public int selectNormalChildrenDeptById(Long deptId) |
| | | { |
| | | return deptMapper.selectNormalChildrenDeptById(deptId); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦åå¨åèç¹ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean hasChildByDeptId(Long deptId) |
| | | { |
| | | int result = deptMapper.hasChildByDeptId(deptId); |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨æ¯å¦åå¨ç¨æ· |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ true åå¨ false ä¸åå¨ |
| | | */ |
| | | @Override |
| | | public boolean checkDeptExistUser(Long deptId) |
| | | { |
| | | int result = deptMapper.checkDeptExistUser(deptId); |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªé¨é¨åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkDeptNameUnique(SysDept dept) |
| | | { |
| | | Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); |
| | | SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); |
| | | if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªé¨é¨æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param deptId é¨é¨id |
| | | */ |
| | | @Override |
| | | public void checkDeptDataScope(Long deptId) |
| | | { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId)) |
| | | { |
| | | SysDept dept = new SysDept(); |
| | | dept.setDeptId(deptId); |
| | | List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); |
| | | if (StringUtils.isEmpty(depts)) |
| | | { |
| | | throw new ServiceException("没ææé访é®é¨é¨æ°æ®ï¼"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿åé¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertDept(SysDept dept) |
| | | { |
| | | SysDept info = deptMapper.selectDeptById(dept.getParentId()); |
| | | // 妿ç¶èç¹ä¸ä¸ºæ£å¸¸ç¶æ,åä¸å
许æ°å¢åèç¹ |
| | | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) |
| | | { |
| | | throw new ServiceException("é¨é¨åç¨ï¼ä¸å
许æ°å¢"); |
| | | } |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | return deptMapper.insertDept(dept); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åé¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param dept é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateDept(SysDept dept) |
| | | { |
| | | SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); |
| | | SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); |
| | | if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) |
| | | { |
| | | String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); |
| | | String oldAncestors = oldDept.getAncestors(); |
| | | dept.setAncestors(newAncestors); |
| | | updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); |
| | | } |
| | | int result = deptMapper.updateDept(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) |
| | | && !StringUtils.equals("0", dept.getAncestors())) |
| | | { |
| | | // å¦æè¯¥é¨é¨æ¯å¯ç¨ç¶æï¼åå¯ç¨è¯¥é¨é¨çææä¸çº§é¨é¨ |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹è¯¥é¨é¨çç¶çº§é¨é¨ç¶æ |
| | | * |
| | | * @param dept å½åé¨é¨ |
| | | */ |
| | | private void updateParentDeptStatusNormal(SysDept dept) |
| | | { |
| | | String ancestors = dept.getAncestors(); |
| | | Long[] deptIds = Convert.toLongArray(ancestors); |
| | | deptMapper.updateDeptStatusNormal(deptIds); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
ç´ å
³ç³» |
| | | * |
| | | * @param deptId 被修æ¹çé¨é¨ID |
| | | * @param newAncestors æ°çç¶IDéå |
| | | * @param oldAncestors æ§çç¶IDéå |
| | | */ |
| | | public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) |
| | | { |
| | | List<SysDept> children = deptMapper.selectChildrenDeptById(deptId); |
| | | for (SysDept child : children) |
| | | { |
| | | child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); |
| | | } |
| | | if (children.size() > 0) |
| | | { |
| | | deptMapper.updateDeptChildren(children); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤é¨é¨ç®¡çä¿¡æ¯ |
| | | * |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteDeptById(Long deptId) |
| | | { |
| | | return deptMapper.deleteDeptById(deptId); |
| | | } |
| | | |
| | | /** |
| | | * éå½å表 |
| | | */ |
| | | private void recursionFn(List<SysDept> list, SysDept t) |
| | | { |
| | | // å¾å°åèç¹å表 |
| | | List<SysDept> childList = getChildList(list, t); |
| | | t.setChildren(childList); |
| | | for (SysDept tChild : childList) |
| | | { |
| | | if (hasChild(list, tChild)) |
| | | { |
| | | recursionFn(list, tChild); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¾å°åèç¹å表 |
| | | */ |
| | | private List<SysDept> getChildList(List<SysDept> list, SysDept t) |
| | | { |
| | | List<SysDept> tlist = new ArrayList<SysDept>(); |
| | | Iterator<SysDept> it = list.iterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | SysDept n = (SysDept) it.next(); |
| | | if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) |
| | | { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦æåèç¹ |
| | | */ |
| | | private boolean hasChild(List<SysDept> list, SysDept t) |
| | | { |
| | | return getChildList(list, t).size() > 0 ? true : false; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.security.utils.DictUtils; |
| | | import com.se.system.api.domain.SysDictData; |
| | | import com.se.system.mapper.SysDictDataMapper; |
| | | import com.se.system.service.ISysDictDataService; |
| | | |
| | | /** |
| | | * åå
¸ ä¸å¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysDictDataServiceImpl implements ISysDictDataService |
| | | { |
| | | @Autowired |
| | | private SysDictDataMapper dictDataMapper; |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictData åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<SysDictData> selectDictDataList(SysDictData dictData) |
| | | { |
| | | return dictDataMapper.selectDictDataList(dictData); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸é®å¼æ¥è¯¢åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸é®å¼ |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | @Override |
| | | public String selectDictLabel(String dictType, String dictValue) |
| | | { |
| | | return dictDataMapper.selectDictLabel(dictType, dictValue); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸æ°æ®IDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictCode åå
¸æ°æ®ID |
| | | * @return åå
¸æ°æ® |
| | | */ |
| | | @Override |
| | | public SysDictData selectDictDataById(Long dictCode) |
| | | { |
| | | return dictDataMapper.selectDictDataById(dictCode); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param dictCodes éè¦å é¤çåå
¸æ°æ®ID |
| | | */ |
| | | @Override |
| | | public void deleteDictDataByIds(Long[] dictCodes) |
| | | { |
| | | for (Long dictCode : dictCodes) |
| | | { |
| | | SysDictData data = selectDictDataById(dictCode); |
| | | dictDataMapper.deleteDictDataById(dictCode); |
| | | List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); |
| | | DictUtils.setDictCache(data.getDictType(), dictDatas); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿ååå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param data åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertDictData(SysDictData data) |
| | | { |
| | | int row = dictDataMapper.insertDictData(data); |
| | | if (row > 0) |
| | | { |
| | | List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); |
| | | DictUtils.setDictCache(data.getDictType(), dictDatas); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸æ°æ®ä¿¡æ¯ |
| | | * |
| | | * @param data åå
¸æ°æ®ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateDictData(SysDictData data) |
| | | { |
| | | int row = dictDataMapper.updateDictData(data); |
| | | if (row > 0) |
| | | { |
| | | List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); |
| | | DictUtils.setDictCache(data.getDictType(), dictDatas); |
| | | } |
| | | return row; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.PostConstruct; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.security.utils.DictUtils; |
| | | import com.se.system.api.domain.SysDictData; |
| | | import com.se.system.api.domain.SysDictType; |
| | | import com.se.system.mapper.SysDictDataMapper; |
| | | import com.se.system.mapper.SysDictTypeMapper; |
| | | import com.se.system.service.ISysDictTypeService; |
| | | |
| | | /** |
| | | * åå
¸ ä¸å¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysDictTypeServiceImpl implements ISysDictTypeService |
| | | { |
| | | @Autowired |
| | | private SysDictTypeMapper dictTypeMapper; |
| | | |
| | | @Autowired |
| | | private SysDictDataMapper dictDataMapper; |
| | | |
| | | /** |
| | | * 项ç®å¯å¨æ¶ï¼åå§ååå
¸å°ç¼å |
| | | */ |
| | | @PostConstruct |
| | | public void init() |
| | | { |
| | | loadingDictCache(); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢åå
¸ç±»å |
| | | * |
| | | * @param dictType åå
¸ç±»åä¿¡æ¯ |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<SysDictType> selectDictTypeList(SysDictType dictType) |
| | | { |
| | | return dictTypeMapper.selectDictTypeList(dictType); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ææåå
¸ç±»å |
| | | * |
| | | * @return åå
¸ç±»åéåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<SysDictType> selectDictTypeAll() |
| | | { |
| | | return dictTypeMapper.selectDictTypeAll(); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢åå
¸æ°æ® |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<SysDictData> selectDictDataByType(String dictType) |
| | | { |
| | | List<SysDictData> dictDatas = DictUtils.getDictCache(dictType); |
| | | if (StringUtils.isNotEmpty(dictDatas)) |
| | | { |
| | | return dictDatas; |
| | | } |
| | | dictDatas = dictDataMapper.selectDictDataByType(dictType); |
| | | if (StringUtils.isNotEmpty(dictDatas)) |
| | | { |
| | | DictUtils.setDictCache(dictType, dictDatas); |
| | | return dictDatas; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictId åå
¸ç±»åID |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | @Override |
| | | public SysDictType selectDictTypeById(Long dictId) |
| | | { |
| | | return dictTypeMapper.selectDictTypeById(dictId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @return åå
¸ç±»å |
| | | */ |
| | | @Override |
| | | public SysDictType selectDictTypeByType(String dictType) |
| | | { |
| | | return dictTypeMapper.selectDictTypeByType(dictType); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤åå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dictIds éè¦å é¤çåå
¸ID |
| | | */ |
| | | @Override |
| | | public void deleteDictTypeByIds(Long[] dictIds) |
| | | { |
| | | for (Long dictId : dictIds) |
| | | { |
| | | SysDictType dictType = selectDictTypeById(dictId); |
| | | if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) |
| | | { |
| | | throw new ServiceException(String.format("%1$så·²åé
,ä¸è½å é¤", dictType.getDictName())); |
| | | } |
| | | dictTypeMapper.deleteDictTypeById(dictId); |
| | | DictUtils.removeDictCache(dictType.getDictType()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å è½½åå
¸ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void loadingDictCache() |
| | | { |
| | | SysDictData dictData = new SysDictData(); |
| | | dictData.setStatus("0"); |
| | | Map<String, List<SysDictData>> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType)); |
| | | for (Map.Entry<String, List<SysDictData>> entry : dictDataMap.entrySet()) |
| | | { |
| | | DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空åå
¸ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void clearDictCache() |
| | | { |
| | | DictUtils.clearDictCache(); |
| | | } |
| | | |
| | | /** |
| | | * éç½®åå
¸ç¼åæ°æ® |
| | | */ |
| | | @Override |
| | | public void resetDictCache() |
| | | { |
| | | clearDictCache(); |
| | | loadingDictCache(); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿ååå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dict åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertDictType(SysDictType dict) |
| | | { |
| | | int row = dictTypeMapper.insertDictType(dict); |
| | | if (row > 0) |
| | | { |
| | | DictUtils.setDictCache(dict.getDictType(), null); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸ç±»åä¿¡æ¯ |
| | | * |
| | | * @param dict åå
¸ç±»åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateDictType(SysDictType dict) |
| | | { |
| | | SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); |
| | | dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); |
| | | int row = dictTypeMapper.updateDictType(dict); |
| | | if (row > 0) |
| | | { |
| | | List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); |
| | | DictUtils.setDictCache(dict.getDictType(), dictDatas); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªåå
¸ç±»åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param dict åå
¸ç±»å |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkDictTypeUnique(SysDictType dict) |
| | | { |
| | | Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); |
| | | SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); |
| | | if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.system.api.domain.SysLogininfor; |
| | | import com.se.system.mapper.SysLogininforMapper; |
| | | import com.se.system.service.ISysLogininforService; |
| | | |
| | | /** |
| | | * ç³»ç»è®¿é®æ¥å¿æ
åµä¿¡æ¯ æå¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysLogininforServiceImpl implements ISysLogininforService |
| | | { |
| | | |
| | | @Autowired |
| | | private SysLogininforMapper logininforMapper; |
| | | |
| | | /** |
| | | * æ°å¢ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | */ |
| | | @Override |
| | | public int insertLogininfor(SysLogininfor logininfor) |
| | | { |
| | | return logininforMapper.insertLogininfor(logininfor); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»ç»å½æ¥å¿éå |
| | | * |
| | | * @param logininfor è®¿é®æ¥å¿å¯¹è±¡ |
| | | * @return ç»å½è®°å½éå |
| | | */ |
| | | @Override |
| | | public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor) |
| | | { |
| | | return logininforMapper.selectLogininforList(logininfor); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»ç»å½æ¥å¿ |
| | | * |
| | | * @param infoIds éè¦å é¤çç»å½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteLogininforByIds(Long[] infoIds) |
| | | { |
| | | return logininforMapper.deleteLogininforByIds(infoIds); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空系ç»ç»å½æ¥å¿ |
| | | */ |
| | | @Override |
| | | public void cleanLogininfor() |
| | | { |
| | | logininforMapper.cleanLogininfor(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.se.system.domain.SysMenu; |
| | | import com.se.system.domain.vo.MetaVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.domain.vo.RouterVo; |
| | | import com.se.system.domain.vo.TreeSelect; |
| | | import com.se.system.mapper.SysMenuMapper; |
| | | import com.se.system.mapper.SysRoleMapper; |
| | | import com.se.system.mapper.SysRoleMenuMapper; |
| | | import com.se.system.service.ISysMenuService; |
| | | |
| | | /** |
| | | * èå ä¸å¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysMenuServiceImpl implements ISysMenuService |
| | | { |
| | | public static final String PREMISSION_STRING = "perms[\"{0}\"]"; |
| | | |
| | | @Autowired |
| | | private SysMenuMapper menuMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMenuMapper roleMenuMapper; |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return èåå表 |
| | | */ |
| | | @Override |
| | | public List<SysMenu> selectMenuList(Long userId) |
| | | { |
| | | return selectMenuList(new SysMenu(), userId); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»èåå表 |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return èåå表 |
| | | */ |
| | | @Override |
| | | public List<SysMenu> selectMenuList(SysMenu menu, Long userId) |
| | | { |
| | | List<SysMenu> menuList = null; |
| | | // 管çåæ¾ç¤ºææèåä¿¡æ¯ |
| | | if (SysUser.isAdmin(userId)) |
| | | { |
| | | menuList = menuMapper.selectMenuList(menu); |
| | | } |
| | | else |
| | | { |
| | | menu.getParams().put("userId", userId); |
| | | menuList = menuMapper.selectMenuListByUserId(menu); |
| | | } |
| | | return menuList; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢æé |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return æéå表 |
| | | */ |
| | | @Override |
| | | public Set<String> selectMenuPermsByUserId(Long userId) |
| | | { |
| | | List<String> perms = menuMapper.selectMenuPermsByUserId(userId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) |
| | | { |
| | | if (StringUtils.isNotEmpty(perm)) |
| | | { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | } |
| | | } |
| | | return permsSet; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢æé |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return æéå表 |
| | | */ |
| | | @Override |
| | | public Set<String> selectMenuPermsByRoleId(Long roleId) |
| | | { |
| | | List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) |
| | | { |
| | | if (StringUtils.isNotEmpty(perm)) |
| | | { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | } |
| | | } |
| | | return permsSet; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢èå |
| | | * |
| | | * @param userId ç¨æ·åç§° |
| | | * @return èåå表 |
| | | */ |
| | | @Override |
| | | public List<SysMenu> selectMenuTreeByUserId(Long userId) |
| | | { |
| | | List<SysMenu> menus = null; |
| | | if (SecurityUtils.isAdmin(userId)) |
| | | { |
| | | menus = menuMapper.selectMenuTreeAll(); |
| | | } |
| | | else |
| | | { |
| | | menus = menuMapper.selectMenuTreeByUserId(userId); |
| | | } |
| | | return getChildPerms(menus, 0); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢èåæ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return éä¸èåå表 |
| | | */ |
| | | @Override |
| | | public List<Long> selectMenuListByRoleId(Long roleId) |
| | | { |
| | | SysRole role = roleMapper.selectRoleById(roleId); |
| | | return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); |
| | | } |
| | | |
| | | /** |
| | | * æå»ºåç«¯è·¯ç±æéè¦çèå |
| | | * |
| | | * @param menus èåå表 |
| | | * @return è·¯ç±å表 |
| | | */ |
| | | @Override |
| | | public List<RouterVo> buildMenus(List<SysMenu> menus) |
| | | { |
| | | List<RouterVo> routers = new LinkedList<RouterVo>(); |
| | | for (SysMenu menu : menus) |
| | | { |
| | | RouterVo router = new RouterVo(); |
| | | router.setHidden("1".equals(menu.getVisible())); |
| | | router.setName(getRouteName(menu)); |
| | | router.setPath(getRouterPath(menu)); |
| | | router.setComponent(getComponent(menu)); |
| | | router.setQuery(menu.getQuery()); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | List<SysMenu> cMenus = menu.getChildren(); |
| | | if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) |
| | | { |
| | | router.setAlwaysShow(true); |
| | | router.setRedirect("noRedirect"); |
| | | router.setChildren(buildMenus(cMenus)); |
| | | } |
| | | else if (isMenuFrame(menu)) |
| | | { |
| | | router.setMeta(null); |
| | | List<RouterVo> childrenList = new ArrayList<RouterVo>(); |
| | | RouterVo children = new RouterVo(); |
| | | children.setPath(menu.getPath()); |
| | | children.setComponent(menu.getComponent()); |
| | | children.setName(getRouteName(menu.getRouteName(), menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | children.setQuery(menu.getQuery()); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | | } |
| | | else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) |
| | | { |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); |
| | | router.setPath("/"); |
| | | List<RouterVo> childrenList = new ArrayList<RouterVo>(); |
| | | RouterVo children = new RouterVo(); |
| | | String routerPath = innerLinkReplaceEach(menu.getPath()); |
| | | children.setPath(routerPath); |
| | | children.setComponent(UserConstants.INNER_LINK); |
| | | children.setName(getRouteName(menu.getRouteName(), routerPath)); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath())); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | | } |
| | | routers.add(router); |
| | | } |
| | | return routers; |
| | | } |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦æ ç»æ |
| | | * |
| | | * @param menus èåå表 |
| | | * @return æ ç»æå表 |
| | | */ |
| | | @Override |
| | | public List<SysMenu> buildMenuTree(List<SysMenu> menus) |
| | | { |
| | | List<SysMenu> returnList = new ArrayList<SysMenu>(); |
| | | List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); |
| | | for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();) |
| | | { |
| | | SysMenu menu = (SysMenu) iterator.next(); |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(menu.getParentId())) |
| | | { |
| | | recursionFn(menus, menu); |
| | | returnList.add(menu); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) |
| | | { |
| | | returnList = menus; |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | /** |
| | | * æå»ºå端æéè¦ä¸ææ ç»æ |
| | | * |
| | | * @param menus èåå表 |
| | | * @return 䏿æ ç»æå表 |
| | | */ |
| | | @Override |
| | | public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) |
| | | { |
| | | List<SysMenu> menuTrees = buildMenuTree(menus); |
| | | return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®èåIDæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return èåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysMenu selectMenuById(Long menuId) |
| | | { |
| | | return menuMapper.selectMenuById(menuId); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦åå¨èååèç¹ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean hasChildByMenuId(Long menuId) |
| | | { |
| | | int result = menuMapper.hasChildByMenuId(menuId); |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢èåä½¿ç¨æ°é |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkMenuExistRole(Long menuId) |
| | | { |
| | | int result = roleMenuMapper.checkMenuExistRole(menuId); |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿åèåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertMenu(SysMenu menu) |
| | | { |
| | | return menuMapper.insertMenu(menu); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åèåä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateMenu(SysMenu menu) |
| | | { |
| | | return menuMapper.updateMenu(menu); |
| | | } |
| | | |
| | | /** |
| | | * å é¤èå管çä¿¡æ¯ |
| | | * |
| | | * @param menuId èåID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteMenuById(Long menuId) |
| | | { |
| | | return menuMapper.deleteMenuById(menuId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªèååç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkMenuNameUnique(SysMenu menu) |
| | | { |
| | | Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); |
| | | SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); |
| | | if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * è·åè·¯ç±åç§° |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return è·¯ç±åç§° |
| | | */ |
| | | public String getRouteName(SysMenu menu) |
| | | { |
| | | // éå¤é¾å¹¶ä¸æ¯ä¸çº§ç®å½ï¼ç±»å为ç®å½ï¼ |
| | | if (isMenuFrame(menu)) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | return getRouteName(menu.getRouteName(), menu.getPath()); |
| | | } |
| | | |
| | | /** |
| | | * è·åè·¯ç±åç§°ï¼å¦æ²¡æé
置路ç±åç§°ååè·¯ç±å°å |
| | | * |
| | | * @param routerName è·¯ç±åç§° |
| | | * @param path è·¯ç±å°å |
| | | * @return è·¯ç±åç§°ï¼é©¼å³°æ ¼å¼ï¼ |
| | | */ |
| | | public String getRouteName(String name, String path) |
| | | { |
| | | String routerName = StringUtils.isNotEmpty(name) ? name : path; |
| | | return StringUtils.capitalize(routerName); |
| | | } |
| | | |
| | | /** |
| | | * è·åè·¯ç±å°å |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return è·¯ç±å°å |
| | | */ |
| | | public String getRouterPath(SysMenu menu) |
| | | { |
| | | String routerPath = menu.getPath(); |
| | | // å
龿å¼å¤ç½æ¹å¼ |
| | | if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) |
| | | { |
| | | routerPath = innerLinkReplaceEach(routerPath); |
| | | } |
| | | // éå¤é¾å¹¶ä¸æ¯ä¸çº§ç®å½ï¼ç±»å为ç®å½ï¼ |
| | | if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) |
| | | && UserConstants.NO_FRAME.equals(menu.getIsFrame())) |
| | | { |
| | | routerPath = "/" + menu.getPath(); |
| | | } |
| | | // éå¤é¾å¹¶ä¸æ¯ä¸çº§ç®å½ï¼ç±»å为èåï¼ |
| | | else if (isMenuFrame(menu)) |
| | | { |
| | | routerPath = "/"; |
| | | } |
| | | return routerPath; |
| | | } |
| | | |
| | | /** |
| | | * è·åç»ä»¶ä¿¡æ¯ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»ä»¶ä¿¡æ¯ |
| | | */ |
| | | public String getComponent(SysMenu menu) |
| | | { |
| | | String component = UserConstants.LAYOUT; |
| | | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) |
| | | { |
| | | component = menu.getComponent(); |
| | | } |
| | | else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) |
| | | { |
| | | component = UserConstants.INNER_LINK; |
| | | } |
| | | else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) |
| | | { |
| | | component = UserConstants.PARENT_VIEW; |
| | | } |
| | | return component; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºèåå
é¨è·³è½¬ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isMenuFrame(SysMenu menu) |
| | | { |
| | | return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) |
| | | && menu.getIsFrame().equals(UserConstants.NO_FRAME); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºå
é¾ç»ä»¶ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isInnerLink(SysMenu menu) |
| | | { |
| | | return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºparent_viewç»ä»¶ |
| | | * |
| | | * @param menu èåä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isParentView(SysMenu menu) |
| | | { |
| | | return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¶èç¹çIDè·åææåèç¹ |
| | | * |
| | | * @param list å类表 |
| | | * @param parentId ä¼ å
¥çç¶èç¹ID |
| | | * @return String |
| | | */ |
| | | public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) |
| | | { |
| | | List<SysMenu> returnList = new ArrayList<SysMenu>(); |
| | | for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext();) |
| | | { |
| | | SysMenu t = (SysMenu) iterator.next(); |
| | | // ä¸ãæ ¹æ®ä¼ å
¥çæä¸ªç¶èç¹ID,éå该ç¶èç¹çææåèç¹ |
| | | if (t.getParentId() == parentId) |
| | | { |
| | | recursionFn(list, t); |
| | | returnList.add(t); |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | /** |
| | | * éå½å表 |
| | | * |
| | | * @param list å类表 |
| | | * @param t åèç¹ |
| | | */ |
| | | private void recursionFn(List<SysMenu> list, SysMenu t) |
| | | { |
| | | // å¾å°åèç¹å表 |
| | | List<SysMenu> childList = getChildList(list, t); |
| | | t.setChildren(childList); |
| | | for (SysMenu tChild : childList) |
| | | { |
| | | if (hasChild(list, tChild)) |
| | | { |
| | | recursionFn(list, tChild); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¾å°åèç¹å表 |
| | | */ |
| | | private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) |
| | | { |
| | | List<SysMenu> tlist = new ArrayList<SysMenu>(); |
| | | Iterator<SysMenu> it = list.iterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | SysMenu n = (SysMenu) it.next(); |
| | | if (n.getParentId().longValue() == t.getMenuId().longValue()) |
| | | { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦æåèç¹ |
| | | */ |
| | | private boolean hasChild(List<SysMenu> list, SysMenu t) |
| | | { |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | |
| | | /** |
| | | * å
é¾ååç¹æ®åç¬¦æ¿æ¢ |
| | | * |
| | | * @return æ¿æ¢åçå
é¾åå |
| | | */ |
| | | public String innerLinkReplaceEach(String path) |
| | | { |
| | | return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":" }, |
| | | new String[] { "", "", "", "/", "/" }); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysNotice; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.system.mapper.SysNoticeMapper; |
| | | import com.se.system.service.ISysNoticeService; |
| | | |
| | | /** |
| | | * å
¬å æå¡å±å®ç° |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysNoticeServiceImpl implements ISysNoticeService |
| | | { |
| | | @Autowired |
| | | private SysNoticeMapper noticeMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return å
¬åä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysNotice selectNoticeById(Long noticeId) |
| | | { |
| | | return noticeMapper.selectNoticeById(noticeId); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å
¬åå表 |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return å
¬åéå |
| | | */ |
| | | @Override |
| | | public List<SysNotice> selectNoticeList(SysNotice notice) |
| | | { |
| | | return noticeMapper.selectNoticeList(notice); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertNotice(SysNotice notice) |
| | | { |
| | | return noticeMapper.insertNotice(notice); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹å
Œ |
| | | * |
| | | * @param notice å
¬åä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateNotice(SysNotice notice) |
| | | { |
| | | return noticeMapper.updateNotice(notice); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å
¬å对象 |
| | | * |
| | | * @param noticeId å
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteNoticeById(Long noticeId) |
| | | { |
| | | return noticeMapper.deleteNoticeById(noticeId); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤å
¬åä¿¡æ¯ |
| | | * |
| | | * @param noticeIds éè¦å é¤çå
ŒID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteNoticeByIds(Long[] noticeIds) |
| | | { |
| | | return noticeMapper.deleteNoticeByIds(noticeIds); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.system.api.domain.SysOperLog; |
| | | import com.se.system.mapper.SysOperLogMapper; |
| | | import com.se.system.service.ISysOperLogService; |
| | | |
| | | /** |
| | | * æä½æ¥å¿ æå¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysOperLogServiceImpl implements ISysOperLogService |
| | | { |
| | | @Autowired |
| | | private SysOperLogMapper operLogMapper; |
| | | |
| | | /** |
| | | * æ°å¢æä½æ¥å¿ |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertOperlog(SysOperLog operLog) |
| | | { |
| | | return operLogMapper.insertOperlog(operLog); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ç³»ç»æä½æ¥å¿éå |
| | | * |
| | | * @param operLog æä½æ¥å¿å¯¹è±¡ |
| | | * @return æä½æ¥å¿éå |
| | | */ |
| | | @Override |
| | | public List<SysOperLog> selectOperLogList(SysOperLog operLog) |
| | | { |
| | | return operLogMapper.selectOperLogList(operLog); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤ç³»ç»æä½æ¥å¿ |
| | | * |
| | | * @param operIds éè¦å é¤çæä½æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteOperLogByIds(Long[] operIds) |
| | | { |
| | | return operLogMapper.deleteOperLogByIds(operIds); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æä½æ¥å¿è¯¦ç» |
| | | * |
| | | * @param operId æä½ID |
| | | * @return æä½æ¥å¿å¯¹è±¡ |
| | | */ |
| | | @Override |
| | | public SysOperLog selectOperLogById(Long operId) |
| | | { |
| | | return operLogMapper.selectOperLogById(operId); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空æä½æ¥å¿ |
| | | */ |
| | | @Override |
| | | public void cleanOperLog() |
| | | { |
| | | operLogMapper.cleanOperLog(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.service.ISysMenuService; |
| | | import com.se.system.service.ISysPermissionService; |
| | | import com.se.system.service.ISysRoleService; |
| | | |
| | | /** |
| | | * ç¨æ·æéå¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysPermissionServiceImpl implements ISysPermissionService |
| | | { |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | /** |
| | | * è·åè§è²æ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·Id |
| | | * @return è§è²æéä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public Set<String> getRolePermission(SysUser user) |
| | | { |
| | | Set<String> roles = new HashSet<String>(); |
| | | // 管çåæ¥ææææé |
| | | if (user.isAdmin()) |
| | | { |
| | | roles.add("admin"); |
| | | } |
| | | else |
| | | { |
| | | roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
| | | } |
| | | return roles; |
| | | } |
| | | |
| | | /** |
| | | * è·åèåæ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·Id |
| | | * @return èåæéä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public Set<String> getMenuPermission(SysUser user) |
| | | { |
| | | Set<String> perms = new HashSet<String>(); |
| | | // 管çåæ¥ææææé |
| | | if (user.isAdmin()) |
| | | { |
| | | perms.add("*:*:*"); |
| | | } |
| | | else |
| | | { |
| | | List<SysRole> roles = user.getRoles(); |
| | | if (!CollectionUtils.isEmpty(roles)) |
| | | { |
| | | // å¤è§è²è®¾ç½®permissions屿§ï¼ä»¥ä¾¿æ°æ®æéå¹é
æé |
| | | for (SysRole role : roles) |
| | | { |
| | | Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); |
| | | role.setPermissions(rolePerms); |
| | | perms.addAll(rolePerms); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
| | | } |
| | | } |
| | | return perms; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.se.system.domain.SysPost; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.system.mapper.SysPostMapper; |
| | | import com.se.system.mapper.SysUserPostMapper; |
| | | import com.se.system.service.ISysPostService; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯ æå¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysPostServiceImpl implements ISysPostService |
| | | { |
| | | @Autowired |
| | | private SysPostMapper postMapper; |
| | | |
| | | @Autowired |
| | | private SysUserPostMapper userPostMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢å²ä½ä¿¡æ¯éå |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return å²ä½ä¿¡æ¯éå |
| | | */ |
| | | @Override |
| | | public List<SysPost> selectPostList(SysPost post) |
| | | { |
| | | return postMapper.selectPostList(post); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ææå²ä½ |
| | | * |
| | | * @return å²ä½å表 |
| | | */ |
| | | @Override |
| | | public List<SysPost> selectPostAll() |
| | | { |
| | | return postMapper.selectPostAll(); |
| | | } |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysPost selectPostById(Long postId) |
| | | { |
| | | return postMapper.selectPostById(postId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åå²ä½éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸å²ä½IDå表 |
| | | */ |
| | | @Override |
| | | public List<Long> selectPostListByUserId(Long userId) |
| | | { |
| | | return postMapper.selectPostListByUserId(userId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkPostNameUnique(SysPost post) |
| | | { |
| | | Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = postMapper.checkPostNameUnique(post.getPostName()); |
| | | if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªå²ä½ç¼ç æ¯å¦å¯ä¸ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkPostCodeUnique(SysPost post) |
| | | { |
| | | Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); |
| | | if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * éè¿å²ä½IDæ¥è¯¢å²ä½ä½¿ç¨æ°é |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int countUserPostById(Long postId) |
| | | { |
| | | return userPostMapper.countUserPostById(postId); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postId å²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deletePostById(Long postId) |
| | | { |
| | | return postMapper.deletePostById(postId); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param postIds éè¦å é¤çå²ä½ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deletePostByIds(Long[] postIds) |
| | | { |
| | | for (Long postId : postIds) |
| | | { |
| | | SysPost post = selectPostById(postId); |
| | | if (countUserPostById(postId) > 0) |
| | | { |
| | | throw new ServiceException(String.format("%1$så·²åé
,ä¸è½å é¤", post.getPostName())); |
| | | } |
| | | } |
| | | return postMapper.deletePostByIds(postIds); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿åå²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertPost(SysPost post) |
| | | { |
| | | return postMapper.insertPost(post); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åå²ä½ä¿¡æ¯ |
| | | * |
| | | * @param post å²ä½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updatePost(SysPost post) |
| | | { |
| | | return postMapper.updatePost(post); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import com.se.system.domain.SysRoleDept; |
| | | import com.se.system.domain.SysRoleMenu; |
| | | import com.se.system.domain.SysUserRole; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.datascope.annotation.DataScope; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.mapper.SysRoleDeptMapper; |
| | | import com.se.system.mapper.SysRoleMapper; |
| | | import com.se.system.mapper.SysRoleMenuMapper; |
| | | import com.se.system.mapper.SysUserRoleMapper; |
| | | import com.se.system.service.ISysRoleService; |
| | | |
| | | /** |
| | | * è§è² ä¸å¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysRoleServiceImpl implements ISysRoleService |
| | | { |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMenuMapper roleMenuMapper; |
| | | |
| | | @Autowired |
| | | private SysUserRoleMapper userRoleMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleDeptMapper roleDeptMapper; |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢è§è²æ°æ® |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return è§è²æ°æ®éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysRole> selectRoleList(SysRole role) |
| | | { |
| | | return roleMapper.selectRoleList(role); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢è§è² |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return è§è²å表 |
| | | */ |
| | | @Override |
| | | public List<SysRole> selectRolesByUserId(Long userId) |
| | | { |
| | | List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId); |
| | | List<SysRole> roles = selectRoleAll(); |
| | | for (SysRole role : roles) |
| | | { |
| | | for (SysRole userRole : userRoles) |
| | | { |
| | | if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) |
| | | { |
| | | role.setFlag(true); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return roles; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDæ¥è¯¢æé |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return æéå表 |
| | | */ |
| | | @Override |
| | | public Set<String> selectRolePermissionByUserId(Long userId) |
| | | { |
| | | List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (SysRole perm : perms) |
| | | { |
| | | if (StringUtils.isNotNull(perm)) |
| | | { |
| | | permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); |
| | | } |
| | | } |
| | | return permsSet; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ææè§è² |
| | | * |
| | | * @return è§è²å表 |
| | | */ |
| | | @Override |
| | | public List<SysRole> selectRoleAll() |
| | | { |
| | | return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·IDè·åè§è²éæ©æ¡å表 |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return éä¸è§è²IDå表 |
| | | */ |
| | | @Override |
| | | public List<Long> selectRoleListByUserId(Long userId) |
| | | { |
| | | return roleMapper.selectRoleListByUserId(userId); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return è§è²å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysRole selectRoleById(Long roleId) |
| | | { |
| | | return roleMapper.selectRoleById(roleId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè§è²åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkRoleNameUnique(SysRole role) |
| | | { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æéæ¯å¦å¯ä¸ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkRoleKeyUnique(SysRole role) |
| | | { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æ¯å¦å
许æä½ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public void checkRoleAllowed(SysRole role) |
| | | { |
| | | if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) |
| | | { |
| | | throw new ServiceException("ä¸å
许æä½è¶
级管çåè§è²"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè§è²æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param roleIds è§è²id |
| | | */ |
| | | @Override |
| | | public void checkRoleDataScope(Long... roleIds) |
| | | { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId())) |
| | | { |
| | | for (Long roleId : roleIds) |
| | | { |
| | | SysRole role = new SysRole(); |
| | | role.setRoleId(roleId); |
| | | List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); |
| | | if (StringUtils.isEmpty(roles)) |
| | | { |
| | | throw new ServiceException("没ææé访é®è§è²æ°æ®ï¼"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éè¿è§è²IDæ¥è¯¢è§è²ä½¿ç¨æ°é |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int countUserRoleByRoleId(Long roleId) |
| | | { |
| | | return userRoleMapper.countUserRoleByRoleId(roleId); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿åè§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertRole(SysRole role) |
| | | { |
| | | // æ°å¢è§è²ä¿¡æ¯ |
| | | roleMapper.insertRole(role); |
| | | return insertRoleMenu(role); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åè§è²ä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateRole(SysRole role) |
| | | { |
| | | // ä¿®æ¹è§è²ä¿¡æ¯ |
| | | roleMapper.updateRole(role); |
| | | // å é¤è§è²ä¸èåå
³è |
| | | roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId()); |
| | | return insertRoleMenu(role); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹è§è²ç¶æ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateRoleStatus(SysRole role) |
| | | { |
| | | return roleMapper.updateRole(role); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹æ°æ®æéä¿¡æ¯ |
| | | * |
| | | * @param role è§è²ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int authDataScope(SysRole role) |
| | | { |
| | | // ä¿®æ¹è§è²ä¿¡æ¯ |
| | | roleMapper.updateRole(role); |
| | | // å é¤è§è²ä¸é¨é¨å
³è |
| | | roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId()); |
| | | // æ°å¢è§è²åé¨é¨ä¿¡æ¯ï¼æ°æ®æéï¼ |
| | | return insertRoleDept(role); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢è§è²èåä¿¡æ¯ |
| | | * |
| | | * @param role è§è²å¯¹è±¡ |
| | | */ |
| | | public int insertRoleMenu(SysRole role) |
| | | { |
| | | int rows = 1; |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); |
| | | for (Long menuId : role.getMenuIds()) |
| | | { |
| | | SysRoleMenu rm = new SysRoleMenu(); |
| | | rm.setRoleId(role.getRoleId()); |
| | | rm.setMenuId(menuId); |
| | | list.add(rm); |
| | | } |
| | | if (list.size() > 0) |
| | | { |
| | | rows = roleMenuMapper.batchRoleMenu(list); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢è§è²é¨é¨ä¿¡æ¯(æ°æ®æé) |
| | | * |
| | | * @param role è§è²å¯¹è±¡ |
| | | */ |
| | | public int insertRoleDept(SysRole role) |
| | | { |
| | | int rows = 1; |
| | | // æ°å¢è§è²ä¸é¨é¨ï¼æ°æ®æéï¼ç®¡ç |
| | | List<SysRoleDept> list = new ArrayList<SysRoleDept>(); |
| | | for (Long deptId : role.getDeptIds()) |
| | | { |
| | | SysRoleDept rd = new SysRoleDept(); |
| | | rd.setRoleId(role.getRoleId()); |
| | | rd.setDeptId(deptId); |
| | | list.add(rd); |
| | | } |
| | | if (list.size() > 0) |
| | | { |
| | | rows = roleDeptMapper.batchRoleDept(list); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * éè¿è§è²IDå é¤è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteRoleById(Long roleId) |
| | | { |
| | | // å é¤è§è²ä¸èåå
³è |
| | | roleMenuMapper.deleteRoleMenuByRoleId(roleId); |
| | | // å é¤è§è²ä¸é¨é¨å
³è |
| | | roleDeptMapper.deleteRoleDeptByRoleId(roleId); |
| | | return roleMapper.deleteRoleById(roleId); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è§è²ä¿¡æ¯ |
| | | * |
| | | * @param roleIds éè¦å é¤çè§è²ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteRoleByIds(Long[] roleIds) |
| | | { |
| | | for (Long roleId : roleIds) |
| | | { |
| | | checkRoleAllowed(new SysRole(roleId)); |
| | | checkRoleDataScope(roleId); |
| | | SysRole role = selectRoleById(roleId); |
| | | if (countUserRoleByRoleId(roleId) > 0) |
| | | { |
| | | throw new ServiceException(String.format("%1$så·²åé
,ä¸è½å é¤", role.getRoleName())); |
| | | } |
| | | } |
| | | // å é¤è§è²ä¸èåå
³è |
| | | roleMenuMapper.deleteRoleMenu(roleIds); |
| | | // å é¤è§è²ä¸é¨é¨å
³è |
| | | roleDeptMapper.deleteRoleDept(roleIds); |
| | | return roleMapper.deleteRoleByIds(roleIds); |
| | | } |
| | | |
| | | /** |
| | | * åæ¶ææç¨æ·è§è² |
| | | * |
| | | * @param userRole ç¨æ·åè§è²å
³èä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteAuthUser(SysUserRole userRole) |
| | | { |
| | | return userRoleMapper.deleteUserRoleInfo(userRole); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éåæ¶ææç¨æ·è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param userIds éè¦åæ¶ææçç¨æ·æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteAuthUsers(Long roleId, Long[] userIds) |
| | | { |
| | | return userRoleMapper.deleteUserRoleInfos(roleId, userIds); |
| | | } |
| | | |
| | | /** |
| | | * æ¹ééæ©ææç¨æ·è§è² |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param userIds éè¦ææçç¨æ·æ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertAuthUsers(Long roleId, Long[] userIds) |
| | | { |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | List<SysUserRole> list = new ArrayList<SysUserRole>(); |
| | | for (Long userId : userIds) |
| | | { |
| | | SysUserRole ur = new SysUserRole(); |
| | | ur.setUserId(userId); |
| | | ur.setRoleId(roleId); |
| | | list.add(ur); |
| | | } |
| | | return userRoleMapper.batchUserRole(list); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import com.se.system.domain.SysUserOnline; |
| | | import org.springframework.stereotype.Service; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.system.api.model.LoginUser; |
| | | import com.se.system.service.ISysUserOnlineService; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ· æå¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysUserOnlineServiceImpl implements ISysUserOnlineService |
| | | { |
| | | /** |
| | | * éè¿ç»å½å°åæ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param ipaddr ç»å½å°å |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åç§°æ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param userName ç¨æ·åç§° |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(userName, user.getUsername())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * éè¿ç»å½å°å/ç¨æ·åç§°æ¥è¯¢ä¿¡æ¯ |
| | | * |
| | | * @param ipaddr ç»å½å°å |
| | | * @param userName ç¨æ·åç§° |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 设置å¨çº¿ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return å¨çº¿ç¨æ· |
| | | */ |
| | | @Override |
| | | public SysUserOnline loginUserToUserOnline(LoginUser user) |
| | | { |
| | | if (StringUtils.isNull(user)) |
| | | { |
| | | return null; |
| | | } |
| | | SysUserOnline sysUserOnline = new SysUserOnline(); |
| | | sysUserOnline.setTokenId(user.getToken()); |
| | | sysUserOnline.setUserName(user.getUsername()); |
| | | sysUserOnline.setIpaddr(user.getIpaddr()); |
| | | sysUserOnline.setLoginTime(user.getLoginTime()); |
| | | return sysUserOnline; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import javax.validation.Validator; |
| | | |
| | | import com.se.system.domain.SysPost; |
| | | import com.se.system.domain.SysUserPost; |
| | | import com.se.system.domain.SysUserRole; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.utils.SpringUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.bean.BeanValidators; |
| | | import com.se.common.datascope.annotation.DataScope; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysRole; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.mapper.SysPostMapper; |
| | | import com.se.system.mapper.SysRoleMapper; |
| | | import com.se.system.mapper.SysUserMapper; |
| | | import com.se.system.mapper.SysUserPostMapper; |
| | | import com.se.system.mapper.SysUserRoleMapper; |
| | | import com.se.system.service.ISysConfigService; |
| | | import com.se.system.service.ISysDeptService; |
| | | import com.se.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ç¨æ· ä¸å¡å±å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysUserServiceImpl implements ISysUserService |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | @Autowired |
| | | private SysPostMapper postMapper; |
| | | |
| | | @Autowired |
| | | private SysUserRoleMapper userRoleMapper; |
| | | |
| | | @Autowired |
| | | private SysUserPostMapper userPostMapper; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @Autowired |
| | | protected Validator validator; |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢ç¨æ·å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u") |
| | | public List<SysUser> selectUserList(SysUser user) |
| | | { |
| | | return userMapper.selectUserList(user); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢å·²åé
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u") |
| | | public List<SysUser> selectAllocatedList(SysUser user) |
| | | { |
| | | return userMapper.selectAllocatedList(user); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u") |
| | | public List<SysUser> selectUnallocatedList(SysUser user) |
| | | { |
| | | return userMapper.selectUnallocatedList(user); |
| | | } |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysUser selectUserByUserName(String userName) |
| | | { |
| | | return userMapper.selectUserByUserName(userName); |
| | | } |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDæ¥è¯¢ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysUser selectUserById(Long userId) |
| | | { |
| | | return userMapper.selectUserById(userId); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ç¨æ·æå±è§è²ç» |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public String selectUserRoleGroup(String userName) |
| | | { |
| | | List<SysRole> list = roleMapper.selectRolesByUserName(userName); |
| | | if (CollectionUtils.isEmpty(list)) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(",")); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ç¨æ·æå±å²ä½ç» |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public String selectUserPostGroup(String userName) |
| | | { |
| | | List<SysPost> list = postMapper.selectPostsByUserName(userName); |
| | | if (CollectionUtils.isEmpty(list)) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | return list.stream().map(SysPost::getPostName).collect(Collectors.joining(",")); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkUserNameUnique(SysUser user) |
| | | { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | SysUser info = userMapper.checkUserNameUnique(user.getUserName()); |
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªææºå·ç æ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean checkPhoneUnique(SysUser user) |
| | | { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber()); |
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªemailæ¯å¦å¯ä¸ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean checkEmailUnique(SysUser user) |
| | | { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | SysUser info = userMapper.checkEmailUnique(user.getEmail()); |
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·æ¯å¦å
许æä½ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public void checkUserAllowed(SysUser user) |
| | | { |
| | | if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) |
| | | { |
| | | throw new ServiceException("ä¸å
许æä½è¶
级管çåç¨æ·"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·æ¯å¦ææ°æ®æé |
| | | * |
| | | * @param userId ç¨æ·id |
| | | */ |
| | | @Override |
| | | public void checkUserDataScope(Long userId) |
| | | { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId())) |
| | | { |
| | | SysUser user = new SysUser(); |
| | | user.setUserId(userId); |
| | | List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user); |
| | | if (StringUtils.isEmpty(users)) |
| | | { |
| | | throw new ServiceException("没ææé访é®ç¨æ·æ°æ®ï¼"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä¿åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertUser(SysUser user) |
| | | { |
| | | // æ°å¢ç¨æ·ä¿¡æ¯ |
| | | int rows = userMapper.insertUser(user); |
| | | // æ°å¢ç¨æ·å²ä½å
³è |
| | | insertUserPost(user); |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | insertUserRole(user); |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 注åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean registerUser(SysUser user) |
| | | { |
| | | return userMapper.insertUser(user) > 0; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateUser(SysUser user) |
| | | { |
| | | Long userId = user.getUserId(); |
| | | // å é¤ç¨æ·ä¸è§è²å
³è |
| | | userRoleMapper.deleteUserRoleByUserId(userId); |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | insertUserRole(user); |
| | | // å é¤ç¨æ·ä¸å²ä½å
³è |
| | | userPostMapper.deleteUserPostByUserId(userId); |
| | | // æ°å¢ç¨æ·ä¸å²ä½ç®¡ç |
| | | insertUserPost(user); |
| | | return userMapper.updateUser(user); |
| | | } |
| | | |
| | | /** |
| | | * ç¨æ·ææè§è² |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @param roleIds è§è²ç» |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void insertUserAuth(Long userId, Long[] roleIds) |
| | | { |
| | | userRoleMapper.deleteUserRoleByUserId(userId); |
| | | insertUserRole(userId, roleIds); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·ç¶æ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateUserStatus(SysUser user) |
| | | { |
| | | return userMapper.updateUser(user); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·åºæ¬ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean updateUserProfile(SysUser user) |
| | | { |
| | | return userMapper.updateUser(user) > 0; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·å¤´å |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param avatar 头åå°å |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean updateUserAvatar(String userName, String avatar) |
| | | { |
| | | return userMapper.updateUserAvatar(userName, avatar) > 0; |
| | | } |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int resetPwd(SysUser user) |
| | | { |
| | | return userMapper.updateUser(user); |
| | | } |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param password å¯ç |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int resetUserPwd(String userName, String password) |
| | | { |
| | | return userMapper.resetUserPwd(userName, password); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·è§è²ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·å¯¹è±¡ |
| | | */ |
| | | public void insertUserRole(SysUser user) |
| | | { |
| | | this.insertUserRole(user.getUserId(), user.getRoleIds()); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param user ç¨æ·å¯¹è±¡ |
| | | */ |
| | | public void insertUserPost(SysUser user) |
| | | { |
| | | Long[] posts = user.getPostIds(); |
| | | if (StringUtils.isNotEmpty(posts)) |
| | | { |
| | | // æ°å¢ç¨æ·ä¸å²ä½ç®¡ç |
| | | List<SysUserPost> list = new ArrayList<SysUserPost>(); |
| | | for (Long postId : posts) |
| | | { |
| | | SysUserPost up = new SysUserPost(); |
| | | up.setUserId(user.getUserId()); |
| | | up.setPostId(postId); |
| | | list.add(up); |
| | | } |
| | | userPostMapper.batchUserPost(list); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·è§è²ä¿¡æ¯ |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @param roleIds è§è²ç» |
| | | */ |
| | | public void insertUserRole(Long userId, Long[] roleIds) |
| | | { |
| | | if (StringUtils.isNotEmpty(roleIds)) |
| | | { |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | List<SysUserRole> list = new ArrayList<SysUserRole>(); |
| | | for (Long roleId : roleIds) |
| | | { |
| | | SysUserRole ur = new SysUserRole(); |
| | | ur.setUserId(userId); |
| | | ur.setRoleId(roleId); |
| | | list.add(ur); |
| | | } |
| | | userRoleMapper.batchUserRole(list); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ· |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteUserById(Long userId) |
| | | { |
| | | // å é¤ç¨æ·ä¸è§è²å
³è |
| | | userRoleMapper.deleteUserRoleByUserId(userId); |
| | | // å é¤ç¨æ·ä¸å²ä½è¡¨ |
| | | userPostMapper.deleteUserPostByUserId(userId); |
| | | return userMapper.deleteUserById(userId); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @param userIds éè¦å é¤çç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteUserByIds(Long[] userIds) |
| | | { |
| | | for (Long userId : userIds) |
| | | { |
| | | checkUserAllowed(new SysUser(userId)); |
| | | checkUserDataScope(userId); |
| | | } |
| | | // å é¤ç¨æ·ä¸è§è²å
³è |
| | | userRoleMapper.deleteUserRole(userIds); |
| | | // å é¤ç¨æ·ä¸å²ä½å
³è |
| | | userPostMapper.deleteUserPost(userIds); |
| | | return userMapper.deleteUserByIds(userIds); |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥ç¨æ·æ°æ® |
| | | * |
| | | * @param userList ç¨æ·æ°æ®å表 |
| | | * @param isUpdateSupport æ¯å¦æ´æ°æ¯æï¼å¦æå·²åå¨ï¼åè¿è¡æ´æ°æ°æ® |
| | | * @param operName æä½ç¨æ· |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) |
| | | { |
| | | if (StringUtils.isNull(userList) || userList.size() == 0) |
| | | { |
| | | throw new ServiceException("导å
¥ç¨æ·æ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | } |
| | | int successNum = 0; |
| | | int failureNum = 0; |
| | | StringBuilder successMsg = new StringBuilder(); |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | for (SysUser user : userList) |
| | | { |
| | | try |
| | | { |
| | | // éªè¯æ¯å¦åå¨è¿ä¸ªç¨æ· |
| | | SysUser u = userMapper.selectUserByUserName(user.getUserName()); |
| | | if (StringUtils.isNull(u)) |
| | | { |
| | | BeanValidators.validateWithException(validator, user); |
| | | deptService.checkDeptDataScope(user.getDeptId()); |
| | | String password = configService.selectConfigByKey("sys.user.initPassword"); |
| | | user.setPassword(SecurityUtils.encryptPassword(password)); |
| | | user.setCreateBy(operName); |
| | | userMapper.insertUser(user); |
| | | successNum++; |
| | | successMsg.append("<br/>" + successNum + "ãè´¦å· " + user.getUserName() + " 导å
¥æå"); |
| | | } |
| | | else if (isUpdateSupport) |
| | | { |
| | | BeanValidators.validateWithException(validator, user); |
| | | checkUserAllowed(u); |
| | | checkUserDataScope(u.getUserId()); |
| | | deptService.checkDeptDataScope(user.getDeptId()); |
| | | user.setUserId(u.getUserId()); |
| | | user.setUpdateBy(operName); |
| | | userMapper.updateUser(user); |
| | | successNum++; |
| | | successMsg.append("<br/>" + successNum + "ãè´¦å· " + user.getUserName() + " æ´æ°æå"); |
| | | } |
| | | else |
| | | { |
| | | failureNum++; |
| | | failureMsg.append("<br/>" + failureNum + "ãè´¦å· " + user.getUserName() + " å·²åå¨"); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | failureNum++; |
| | | String msg = "<br/>" + failureNum + "ãè´¦å· " + user.getUserName() + " 导å
¥å¤±è´¥ï¼"; |
| | | failureMsg.append(msg + e.getMessage()); |
| | | log.error(msg, e); |
| | | } |
| | | } |
| | | if (failureNum > 0) |
| | | { |
| | | failureMsg.insert(0, "徿±æï¼å¯¼å
¥å¤±è´¥ï¼å
± " + failureNum + " æ¡æ°æ®æ ¼å¼ä¸æ£ç¡®ï¼é误å¦ä¸ï¼"); |
| | | throw new ServiceException(failureMsg.toString()); |
| | | } |
| | | else |
| | | { |
| | | successMsg.insert(0, "æåæ¨ï¼æ°æ®å·²å
¨é¨å¯¼å
¥æåï¼å
± " + successNum + " æ¡ï¼æ°æ®å¦ä¸ï¼"); |
| | | } |
| | | return successMsg.toString(); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| | | import com.se.common.security.annotation.EnableRyFeignClients; |
| | | |
| | | /** |
| | | * è®¤è¯ææä¸å¿ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) |
| | | public class SeAuthApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeAuthApplication.class, args); |
| | | System.out.println(" ææä¸å¿å¯å¨æå "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.controller; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.se.auth.form.LoginBody; |
| | | import com.se.auth.form.RegisterBody; |
| | | import com.se.auth.service.SysLoginService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.se.common.core.domain.R; |
| | | import com.se.common.core.utils.JwtUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.security.auth.AuthUtil; |
| | | import com.se.common.security.service.TokenService; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.model.LoginUser; |
| | | |
| | | /** |
| | | * token æ§å¶ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @RestController |
| | | public class TokenController |
| | | { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private SysLoginService sysLoginService; |
| | | |
| | | @PostMapping("login") |
| | | public R<?> login(@RequestBody LoginBody form) |
| | | { |
| | | // ç¨æ·ç»å½ |
| | | LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); |
| | | // è·åç»å½token |
| | | return R.ok(tokenService.createToken(userInfo)); |
| | | } |
| | | |
| | | @DeleteMapping("logout") |
| | | public R<?> logout(HttpServletRequest request) |
| | | { |
| | | String token = SecurityUtils.getToken(request); |
| | | if (StringUtils.isNotEmpty(token)) |
| | | { |
| | | String username = JwtUtils.getUserName(token); |
| | | // å é¤ç¨æ·ç¼åè®°å½ |
| | | AuthUtil.logoutByToken(token); |
| | | // è®°å½ç¨æ·éåºæ¥å¿ |
| | | sysLoginService.logout(username); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("refresh") |
| | | public R<?> refresh(HttpServletRequest request) |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | { |
| | | // å·æ°ä»¤çæææ |
| | | tokenService.refreshToken(loginUser); |
| | | return R.ok(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("register") |
| | | public R<?> register(@RequestBody RegisterBody registerBody) |
| | | { |
| | | // ç¨æ·æ³¨å |
| | | sysLoginService.register(registerBody.getUsername(), registerBody.getPassword()); |
| | | return R.ok(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.form; |
| | | |
| | | /** |
| | | * ç¨æ·ç»å½å¯¹è±¡ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class LoginBody |
| | | { |
| | | /** |
| | | * ç¨æ·å |
| | | */ |
| | | private String username; |
| | | |
| | | /** |
| | | * ç¨æ·å¯ç |
| | | */ |
| | | private String password; |
| | | |
| | | public String getUsername() |
| | | { |
| | | return username; |
| | | } |
| | | |
| | | public void setUsername(String username) |
| | | { |
| | | this.username = username; |
| | | } |
| | | |
| | | public String getPassword() |
| | | { |
| | | return password; |
| | | } |
| | | |
| | | public void setPassword(String password) |
| | | { |
| | | this.password = password; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.form; |
| | | |
| | | /** |
| | | * ç¨æ·æ³¨å对象 |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class RegisterBody extends LoginBody |
| | | { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.service; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.constant.SecurityConstants; |
| | | import com.se.common.core.constant.UserConstants; |
| | | import com.se.common.core.domain.R; |
| | | import com.se.common.core.enums.UserStatus; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.core.text.Convert; |
| | | import com.se.common.core.utils.DateUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.ip.IpUtils; |
| | | import com.se.common.redis.service.RedisService; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.RemoteUserService; |
| | | import com.se.system.api.domain.SysUser; |
| | | import com.se.system.api.model.LoginUser; |
| | | |
| | | /** |
| | | * ç»å½æ ¡éªæ¹æ³ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class SysLoginService |
| | | { |
| | | @Autowired |
| | | private RemoteUserService remoteUserService; |
| | | |
| | | @Autowired |
| | | private SysPasswordService passwordService; |
| | | |
| | | @Autowired |
| | | private SysRecordLogService recordLogService; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * ç»å½ |
| | | */ |
| | | public LoginUser login(String username, String password) |
| | | { |
| | | // ç¨æ·åæå¯ç 为空 é误 |
| | | if (StringUtils.isAnyBlank(username, password)) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "ç¨æ·/å¯ç å¿
须填å"); |
| | | throw new ServiceException("ç¨æ·/å¯ç å¿
须填å"); |
| | | } |
| | | // å¯ç 妿ä¸å¨æå®èå´å
é误 |
| | | if (password.length() < UserConstants.PASSWORD_MIN_LENGTH |
| | | || password.length() > UserConstants.PASSWORD_MAX_LENGTH) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "ç¨æ·å¯ç ä¸å¨æå®èå´"); |
| | | throw new ServiceException("ç¨æ·å¯ç ä¸å¨æå®èå´"); |
| | | } |
| | | // ç¨æ·åä¸å¨æå®èå´å
é误 |
| | | if (username.length() < UserConstants.USERNAME_MIN_LENGTH |
| | | || username.length() > UserConstants.USERNAME_MAX_LENGTH) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "ç¨æ·åä¸å¨æå®èå´"); |
| | | throw new ServiceException("ç¨æ·åä¸å¨æå®èå´"); |
| | | } |
| | | // IPé»ååæ ¡éª |
| | | String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); |
| | | if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "å¾éæ¾ï¼è®¿é®IP已被åå
¥ç³»ç»é»åå"); |
| | | throw new ServiceException("å¾éæ¾ï¼è®¿é®IP已被åå
¥ç³»ç»é»åå"); |
| | | } |
| | | // æ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); |
| | | |
| | | if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "ç»å½ç¨æ·ä¸åå¨"); |
| | | throw new ServiceException("ç»å½ç¨æ·ï¼" + username + " ä¸åå¨"); |
| | | } |
| | | |
| | | if (R.FAIL == userResult.getCode()) |
| | | { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | |
| | | LoginUser userInfo = userResult.getData(); |
| | | SysUser user = userResult.getData().getSysUser(); |
| | | if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对ä¸èµ·ï¼æ¨çè´¦å·å·²è¢«å é¤"); |
| | | throw new ServiceException("对ä¸èµ·ï¼æ¨çè´¦å·ï¼" + username + " 已被å é¤"); |
| | | } |
| | | if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "ç¨æ·å·²åç¨ï¼è¯·è系管çå"); |
| | | throw new ServiceException("对ä¸èµ·ï¼æ¨çè´¦å·ï¼" + username + " å·²åç¨"); |
| | | } |
| | | passwordService.validate(user, password); |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "ç»å½æå"); |
| | | recordLoginInfo(user.getUserId()); |
| | | return userInfo; |
| | | } |
| | | |
| | | /** |
| | | * è®°å½ç»å½ä¿¡æ¯ |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | */ |
| | | public void recordLoginInfo(Long userId) |
| | | { |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserId(userId); |
| | | // æ´æ°ç¨æ·ç»å½IP |
| | | sysUser.setLoginIp(IpUtils.getIpAddr()); |
| | | // æ´æ°ç¨æ·ç»å½æ¶é´ |
| | | sysUser.setLoginDate(DateUtils.getNowDate()); |
| | | remoteUserService.recordUserLogin(sysUser, SecurityConstants.INNER); |
| | | } |
| | | |
| | | public void logout(String loginName) |
| | | { |
| | | recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "éåºæå"); |
| | | } |
| | | |
| | | /** |
| | | * 注å |
| | | */ |
| | | public void register(String username, String password) |
| | | { |
| | | // ç¨æ·åæå¯ç 为空 é误 |
| | | if (StringUtils.isAnyBlank(username, password)) |
| | | { |
| | | throw new ServiceException("ç¨æ·/å¯ç å¿
须填å"); |
| | | } |
| | | if (username.length() < UserConstants.USERNAME_MIN_LENGTH |
| | | || username.length() > UserConstants.USERNAME_MAX_LENGTH) |
| | | { |
| | | throw new ServiceException("è´¦æ·é¿åº¦å¿
é¡»å¨2å°20个å符ä¹é´"); |
| | | } |
| | | if (password.length() < UserConstants.PASSWORD_MIN_LENGTH |
| | | || password.length() > UserConstants.PASSWORD_MAX_LENGTH) |
| | | { |
| | | throw new ServiceException("å¯ç é¿åº¦å¿
é¡»å¨5å°20个å符ä¹é´"); |
| | | } |
| | | |
| | | // 注åç¨æ·ä¿¡æ¯ |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserName(username); |
| | | sysUser.setNickName(username); |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(password)); |
| | | R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER); |
| | | |
| | | if (R.FAIL == registerResult.getCode()) |
| | | { |
| | | throw new ServiceException(registerResult.getMsg()); |
| | | } |
| | | recordLogService.recordLogininfor(username, Constants.REGISTER, "注åæå"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.service; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.exception.ServiceException; |
| | | import com.se.common.redis.service.RedisService; |
| | | import com.se.common.security.utils.SecurityUtils; |
| | | import com.se.system.api.domain.SysUser; |
| | | |
| | | /** |
| | | * ç»å½å¯ç æ¹æ³ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class SysPasswordService |
| | | { |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT; |
| | | |
| | | private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME; |
| | | |
| | | @Autowired |
| | | private SysRecordLogService recordLogService; |
| | | |
| | | /** |
| | | * ç»å½è´¦æ·å¯ç é误次æ°ç¼åé®å |
| | | * |
| | | * @param username ç¨æ·å |
| | | * @return ç¼åé®key |
| | | */ |
| | | private String getCacheKey(String username) |
| | | { |
| | | return CacheConstants.PWD_ERR_CNT_KEY + username; |
| | | } |
| | | |
| | | public void validate(SysUser user, String password) |
| | | { |
| | | String username = user.getUserName(); |
| | | |
| | | Integer retryCount = redisService.getCacheObject(getCacheKey(username)); |
| | | |
| | | if (retryCount == null) |
| | | { |
| | | retryCount = 0; |
| | | } |
| | | |
| | | if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) |
| | | { |
| | | String errMsg = String.format("å¯ç è¾å
¥é误%s次ï¼å¸æ·éå®%såé", maxRetryCount, lockTime); |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL,errMsg); |
| | | throw new ServiceException(errMsg); |
| | | } |
| | | |
| | | if (!matches(user, password)) |
| | | { |
| | | retryCount = retryCount + 1; |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("å¯ç è¾å
¥é误%s次", retryCount)); |
| | | redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); |
| | | throw new ServiceException("ç¨æ·ä¸åå¨/å¯ç é误"); |
| | | } |
| | | else |
| | | { |
| | | clearLoginRecordCache(username); |
| | | } |
| | | } |
| | | |
| | | public boolean matches(SysUser user, String rawPassword) |
| | | { |
| | | return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); |
| | | } |
| | | |
| | | public void clearLoginRecordCache(String loginName) |
| | | { |
| | | if (redisService.hasKey(getCacheKey(loginName))) |
| | | { |
| | | redisService.deleteObject(getCacheKey(loginName)); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.auth.service; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.constant.SecurityConstants; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.ip.IpUtils; |
| | | import com.se.system.api.RemoteLogService; |
| | | import com.se.system.api.domain.SysLogininfor; |
| | | |
| | | /** |
| | | * è®°å½æ¥å¿æ¹æ³ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class SysRecordLogService |
| | | { |
| | | @Autowired |
| | | private RemoteLogService remoteLogService; |
| | | |
| | | /** |
| | | * è®°å½ç»å½ä¿¡æ¯ |
| | | * |
| | | * @param username ç¨æ·å |
| | | * @param status ç¶æ |
| | | * @param message æ¶æ¯å
容 |
| | | * @return |
| | | */ |
| | | public void recordLogininfor(String username, String status, String message) |
| | | { |
| | | SysLogininfor logininfor = new SysLogininfor(); |
| | | logininfor.setUserName(username); |
| | | logininfor.setIpaddr(IpUtils.getIpAddr()); |
| | | logininfor.setMsg(message); |
| | | // æ¥å¿ç¶æ |
| | | if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) |
| | | { |
| | | logininfor.setStatus(Constants.LOGIN_SUCCESS_STATUS); |
| | | } |
| | | else if (Constants.LOGIN_FAIL.equals(status)) |
| | | { |
| | | logininfor.setStatus(Constants.LOGIN_FAIL_STATUS); |
| | | } |
| | | remoteLogService.saveLogininfor(logininfor, SecurityConstants.INNER); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | Spring Boot Version: ${spring-boot.version} |
| | | Spring Application Name: ${spring.application.name} |
| | | SeAuthApplicationï¼å·²ç»å¯å¨ |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| | | |
| | | /** |
| | | * ç½å
³å¯å¨ç¨åº |
| | | * |
| | | * @author admin |
| | | */ |
| | | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) |
| | | public class SeGatewayApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeGatewayApplication.class, args); |
| | | System.out.println(" ç½å
³å¯å¨æå "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config; |
| | | |
| | | import java.util.Properties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import com.google.code.kaptcha.impl.DefaultKaptcha; |
| | | import com.google.code.kaptcha.util.Config; |
| | | import static com.google.code.kaptcha.Constants.*; |
| | | |
| | | /** |
| | | * éªè¯ç é
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | public class CaptchaConfig |
| | | { |
| | | @Bean(name = "captchaProducer") |
| | | public DefaultKaptcha getKaptchaBean() |
| | | { |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | Properties properties = new Properties(); |
| | | // æ¯å¦æè¾¹æ¡ é»è®¤ä¸ºtrue æä»¬å¯ä»¥èªå·±è®¾ç½®yesï¼no |
| | | properties.setProperty(KAPTCHA_BORDER, "yes"); |
| | | // éªè¯ç ææ¬å符é¢è² é»è®¤ä¸ºColor.BLACK |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); |
| | | // éªè¯ç å¾ç宽度 é»è®¤ä¸º200 |
| | | properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); |
| | | // éªè¯ç å¾çé«åº¦ é»è®¤ä¸º50 |
| | | properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); |
| | | // éªè¯ç ææ¬åç¬¦å¤§å° é»è®¤ä¸º40 |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); |
| | | // KAPTCHA_SESSION_KEY |
| | | properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); |
| | | // éªè¯ç ææ¬å符é¿åº¦ é»è®¤ä¸º5 |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); |
| | | // éªè¯ç ææ¬å使 ·å¼ é»è®¤ä¸ºnew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); |
| | | // å¾çæ ·å¼ æ°´çº¹com.google.code.kaptcha.impl.WaterRipple é±¼ç¼com.google.code.kaptcha.impl.FishEyeGimpy é´å½±com.google.code.kaptcha.impl.ShadowGimpy |
| | | properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); |
| | | Config config = new Config(properties); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | |
| | | @Bean(name = "captchaProducerMath") |
| | | public DefaultKaptcha getKaptchaBeanMath() |
| | | { |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | Properties properties = new Properties(); |
| | | // æ¯å¦æè¾¹æ¡ é»è®¤ä¸ºtrue æä»¬å¯ä»¥èªå·±è®¾ç½®yesï¼no |
| | | properties.setProperty(KAPTCHA_BORDER, "yes"); |
| | | // è¾¹æ¡é¢è² é»è®¤ä¸ºColor.BLACK |
| | | properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); |
| | | // éªè¯ç ææ¬å符é¢è² é»è®¤ä¸ºColor.BLACK |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); |
| | | // éªè¯ç å¾ç宽度 é»è®¤ä¸º200 |
| | | properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); |
| | | // éªè¯ç å¾çé«åº¦ é»è®¤ä¸º50 |
| | | properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); |
| | | // éªè¯ç ææ¬åç¬¦å¤§å° é»è®¤ä¸º40 |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); |
| | | // KAPTCHA_SESSION_KEY |
| | | properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); |
| | | // éªè¯ç ææ¬çæå¨ |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "KaptchaTextCreator"); |
| | | // éªè¯ç ææ¬å符é´è· é»è®¤ä¸º2 |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); |
| | | // éªè¯ç ææ¬å符é¿åº¦ é»è®¤ä¸º5 |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); |
| | | // éªè¯ç ææ¬å使 ·å¼ é»è®¤ä¸ºnew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) |
| | | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); |
| | | // éªè¯ç åªç¹é¢è² é»è®¤ä¸ºColor.BLACK |
| | | properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); |
| | | // å¹²æ°å®ç°ç±» |
| | | properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); |
| | | // å¾çæ ·å¼ æ°´çº¹com.google.code.kaptcha.impl.WaterRipple é±¼ç¼com.google.code.kaptcha.impl.FishEyeGimpy é´å½±com.google.code.kaptcha.impl.ShadowGimpy |
| | | properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); |
| | | Config config = new Config(properties); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.Ordered; |
| | | import org.springframework.core.annotation.Order; |
| | | import com.se.gateway.handler.SentinelFallbackHandler; |
| | | |
| | | /** |
| | | * ç½å
³éæµé
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | public class GatewayConfig |
| | | { |
| | | @Bean |
| | | @Order(Ordered.HIGHEST_PRECEDENCE) |
| | | public SentinelFallbackHandler sentinelGatewayExceptionHandler() |
| | | { |
| | | return new SentinelFallbackHandler(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config; |
| | | |
| | | import java.util.Random; |
| | | import com.google.code.kaptcha.text.impl.DefaultTextCreator; |
| | | |
| | | /** |
| | | * éªè¯ç ææ¬çæå¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class KaptchaTextCreator extends DefaultTextCreator |
| | | { |
| | | private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); |
| | | |
| | | @Override |
| | | public String getText() |
| | | { |
| | | Integer result = 0; |
| | | Random random = new Random(); |
| | | int x = random.nextInt(10); |
| | | int y = random.nextInt(10); |
| | | StringBuilder suChinese = new StringBuilder(); |
| | | int randomoperands = random.nextInt(3); |
| | | if (randomoperands == 0) |
| | | { |
| | | result = x * y; |
| | | suChinese.append(CNUMBERS[x]); |
| | | suChinese.append("*"); |
| | | suChinese.append(CNUMBERS[y]); |
| | | } |
| | | else if (randomoperands == 1) |
| | | { |
| | | if ((x != 0) && y % x == 0) |
| | | { |
| | | result = y / x; |
| | | suChinese.append(CNUMBERS[y]); |
| | | suChinese.append("/"); |
| | | suChinese.append(CNUMBERS[x]); |
| | | } |
| | | else |
| | | { |
| | | result = x + y; |
| | | suChinese.append(CNUMBERS[x]); |
| | | suChinese.append("+"); |
| | | suChinese.append(CNUMBERS[y]); |
| | | } |
| | | } |
| | | else if (randomoperands == 2) |
| | | { |
| | | if (x >= y) |
| | | { |
| | | result = x - y; |
| | | suChinese.append(CNUMBERS[x]); |
| | | suChinese.append("-"); |
| | | suChinese.append(CNUMBERS[y]); |
| | | } |
| | | else |
| | | { |
| | | result = y - x; |
| | | suChinese.append(CNUMBERS[y]); |
| | | suChinese.append("-"); |
| | | suChinese.append(CNUMBERS[x]); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result = x + y; |
| | | suChinese.append(CNUMBERS[x]); |
| | | suChinese.append("+"); |
| | | suChinese.append(CNUMBERS[y]); |
| | | } |
| | | suChinese.append("=?@" + result); |
| | | return suChinese.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config; |
| | | |
| | | import com.se.gateway.handler.ValidateCodeHandler; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.reactive.function.server.RequestPredicates; |
| | | import org.springframework.web.reactive.function.server.RouterFunction; |
| | | import org.springframework.web.reactive.function.server.RouterFunctions; |
| | | |
| | | /** |
| | | * è·¯ç±é
ç½®ä¿¡æ¯ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | public class RouterFunctionConfiguration |
| | | { |
| | | @Autowired |
| | | private ValidateCodeHandler validateCodeHandler; |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | @Bean |
| | | public RouterFunction routerFunction() |
| | | { |
| | | return RouterFunctions.route( |
| | | RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), |
| | | validateCodeHandler); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.gateway.config.GatewayProperties; |
| | | import org.springframework.cloud.gateway.route.RouteLocator; |
| | | import org.springframework.cloud.gateway.support.NameUtils; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.reactive.config.ResourceHandlerRegistry; |
| | | import org.springframework.web.reactive.config.WebFluxConfigurer; |
| | | import springfox.documentation.swagger.web.SwaggerResource; |
| | | import springfox.documentation.swagger.web.SwaggerResourcesProvider; |
| | | |
| | | /** |
| | | * èåç³»ç»æ¥å£ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer |
| | | { |
| | | /** |
| | | * Swagger2é»è®¤çurlåç¼ |
| | | */ |
| | | public static final String SWAGGER2URL = "/v2/api-docs"; |
| | | |
| | | /** |
| | | * ç½å
³è·¯ç± |
| | | */ |
| | | @Lazy |
| | | @Autowired |
| | | private RouteLocator routeLocator; |
| | | |
| | | @Autowired |
| | | private GatewayProperties gatewayProperties; |
| | | |
| | | /** |
| | | * èåå
¶ä»æå¡æ¥å£ |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SwaggerResource> get() |
| | | { |
| | | List<SwaggerResource> resourceList = new ArrayList<>(); |
| | | List<String> routes = new ArrayList<>(); |
| | | // è·åç½å
³ä¸é
ç½®çroute |
| | | routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); |
| | | gatewayProperties.getRoutes().stream() |
| | | .filter(routeDefinition -> routes |
| | | .contains(routeDefinition.getId())) |
| | | .forEach(routeDefinition -> routeDefinition.getPredicates().stream() |
| | | .filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName())) |
| | | .filter(predicateDefinition -> !"ruoyi-auth".equalsIgnoreCase(routeDefinition.getId())) |
| | | .forEach(predicateDefinition -> resourceList |
| | | .add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs() |
| | | .get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", SWAGGER2URL))))); |
| | | return resourceList; |
| | | } |
| | | |
| | | private SwaggerResource swaggerResource(String name, String location) |
| | | { |
| | | SwaggerResource swaggerResource = new SwaggerResource(); |
| | | swaggerResource.setName(name); |
| | | swaggerResource.setLocation(location); |
| | | swaggerResource.setSwaggerVersion("2.0"); |
| | | return swaggerResource; |
| | | } |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) |
| | | { |
| | | /** swagger-ui å°å */ |
| | | registry.addResourceHandler("/swagger-ui/**") |
| | | .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config.properties; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.cloud.context.config.annotation.RefreshScope; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * éªè¯ç é
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | @RefreshScope |
| | | @ConfigurationProperties(prefix = "security.captcha") |
| | | public class CaptchaProperties |
| | | { |
| | | /** |
| | | * éªè¯ç å¼å
³ |
| | | */ |
| | | private Boolean enabled; |
| | | |
| | | /** |
| | | * éªè¯ç ç±»åï¼math æ°ç»è®¡ç® char åç¬¦ï¼ |
| | | */ |
| | | private String type; |
| | | |
| | | public Boolean getEnabled() |
| | | { |
| | | return enabled; |
| | | } |
| | | |
| | | public void setEnabled(Boolean enabled) |
| | | { |
| | | this.enabled = enabled; |
| | | } |
| | | |
| | | public String getType() |
| | | { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) |
| | | { |
| | | this.type = type; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config.properties; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.cloud.context.config.annotation.RefreshScope; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * æ¾è¡ç½ååé
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | @RefreshScope |
| | | @ConfigurationProperties(prefix = "security.ignore") |
| | | public class IgnoreWhiteProperties |
| | | { |
| | | /** |
| | | * æ¾è¡ç½ååé
ç½®ï¼ç½å
³ä¸æ ¡éªæ¤å¤çç½åå |
| | | */ |
| | | private List<String> whites = new ArrayList<>(); |
| | | |
| | | public List<String> getWhites() |
| | | { |
| | | return whites; |
| | | } |
| | | |
| | | public void setWhites(List<String> whites) |
| | | { |
| | | this.whites = whites; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.config.properties; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.cloud.context.config.annotation.RefreshScope; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * XSSè·¨ç«èæ¬é
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Configuration |
| | | @RefreshScope |
| | | @ConfigurationProperties(prefix = "security.xss") |
| | | public class XssProperties |
| | | { |
| | | /** |
| | | * Xsså¼å
³ |
| | | */ |
| | | private Boolean enabled; |
| | | |
| | | /** |
| | | * æé¤è·¯å¾ |
| | | */ |
| | | private List<String> excludeUrls = new ArrayList<>(); |
| | | |
| | | public Boolean getEnabled() |
| | | { |
| | | return enabled; |
| | | } |
| | | |
| | | public void setEnabled(Boolean enabled) |
| | | { |
| | | this.enabled = enabled; |
| | | } |
| | | |
| | | public List<String> getExcludeUrls() |
| | | { |
| | | return excludeUrls; |
| | | } |
| | | |
| | | public void setExcludeUrls(List<String> excludeUrls) |
| | | { |
| | | this.excludeUrls = excludeUrls; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.filter; |
| | | |
| | | import com.se.gateway.config.properties.IgnoreWhiteProperties; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.GlobalFilter; |
| | | import org.springframework.core.Ordered; |
| | | import org.springframework.http.server.reactive.ServerHttpRequest; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.constant.HttpStatus; |
| | | import com.se.common.core.constant.SecurityConstants; |
| | | import com.se.common.core.constant.TokenConstants; |
| | | import com.se.common.core.utils.JwtUtils; |
| | | import com.se.common.core.utils.ServletUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.redis.service.RedisService; |
| | | import io.jsonwebtoken.Claims; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * ç½å
³é´æ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class AuthFilter implements GlobalFilter, Ordered |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | // æé¤è¿æ»¤ç uri å°åï¼nacosèªè¡æ·»å |
| | | @Autowired |
| | | private IgnoreWhiteProperties ignoreWhite; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | |
| | | @Override |
| | | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) |
| | | { |
| | | ServerHttpRequest request = exchange.getRequest(); |
| | | ServerHttpRequest.Builder mutate = request.mutate(); |
| | | |
| | | String url = request.getURI().getPath(); |
| | | // è·³è¿ä¸éè¦éªè¯çè·¯å¾ |
| | | if (StringUtils.matches(url, ignoreWhite.getWhites())) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | String token = getToken(request); |
| | | if (StringUtils.isEmpty(token)) |
| | | { |
| | | return unauthorizedResponse(exchange, "令çä¸è½ä¸ºç©º"); |
| | | } |
| | | Claims claims = JwtUtils.parseToken(token); |
| | | if (claims == null) |
| | | { |
| | | return unauthorizedResponse(exchange, "令çå·²è¿ææéªè¯ä¸æ£ç¡®ï¼"); |
| | | } |
| | | String userkey = JwtUtils.getUserKey(claims); |
| | | boolean islogin = redisService.hasKey(getTokenKey(userkey)); |
| | | if (!islogin) |
| | | { |
| | | return unauthorizedResponse(exchange, "ç»å½ç¶æå·²è¿æ"); |
| | | } |
| | | String userid = JwtUtils.getUserId(claims); |
| | | String username = JwtUtils.getUserName(claims); |
| | | if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) |
| | | { |
| | | return unauthorizedResponse(exchange, "令çéªè¯å¤±è´¥"); |
| | | } |
| | | |
| | | // è®¾ç½®ç¨æ·ä¿¡æ¯å°è¯·æ± |
| | | addHeader(mutate, SecurityConstants.USER_KEY, userkey); |
| | | addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); |
| | | addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username); |
| | | // å
é¨è¯·æ±æ¥æºåæ°æ¸
é¤ |
| | | removeHeader(mutate, SecurityConstants.FROM_SOURCE); |
| | | return chain.filter(exchange.mutate().request(mutate.build()).build()); |
| | | } |
| | | |
| | | private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return; |
| | | } |
| | | String valueStr = value.toString(); |
| | | String valueEncode = ServletUtils.urlEncode(valueStr); |
| | | mutate.header(name, valueEncode); |
| | | } |
| | | |
| | | private void removeHeader(ServerHttpRequest.Builder mutate, String name) |
| | | { |
| | | mutate.headers(httpHeaders -> httpHeaders.remove(name)).build(); |
| | | } |
| | | |
| | | private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) |
| | | { |
| | | log.error("[é´æå¼å¸¸å¤ç]请æ±è·¯å¾:{}", exchange.getRequest().getPath()); |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¼åkey |
| | | */ |
| | | private String getTokenKey(String token) |
| | | { |
| | | return CacheConstants.LOGIN_TOKEN_KEY + token; |
| | | } |
| | | |
| | | /** |
| | | * è·å请æ±token |
| | | */ |
| | | private String getToken(ServerHttpRequest request) |
| | | { |
| | | String token = request.getHeaders().getFirst(TokenConstants.AUTHENTICATION); |
| | | // 妿å端设置äºä»¤çåç¼ï¼åè£åªæåç¼ |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) |
| | | { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | @Override |
| | | public int getOrder() |
| | | { |
| | | return -200; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.filter; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Pattern; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilter; |
| | | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import com.se.common.core.utils.ServletUtils; |
| | | |
| | | /** |
| | | * é»ååè¿æ»¤å¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUrlFilter.Config> |
| | | { |
| | | @Override |
| | | public GatewayFilter apply(Config config) |
| | | { |
| | | return (exchange, chain) -> { |
| | | |
| | | String url = exchange.getRequest().getURI().getPath(); |
| | | if (config.matchBlacklist(url)) |
| | | { |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请æ±å°åä¸å
许访é®"); |
| | | } |
| | | |
| | | return chain.filter(exchange); |
| | | }; |
| | | } |
| | | |
| | | public BlackListUrlFilter() |
| | | { |
| | | super(Config.class); |
| | | } |
| | | |
| | | public static class Config |
| | | { |
| | | private List<String> blacklistUrl; |
| | | |
| | | private List<Pattern> blacklistUrlPattern = new ArrayList<>(); |
| | | |
| | | public boolean matchBlacklist(String url) |
| | | { |
| | | return !blacklistUrlPattern.isEmpty() && blacklistUrlPattern.stream().anyMatch(p -> p.matcher(url).find()); |
| | | } |
| | | |
| | | public List<String> getBlacklistUrl() |
| | | { |
| | | return blacklistUrl; |
| | | } |
| | | |
| | | public void setBlacklistUrl(List<String> blacklistUrl) |
| | | { |
| | | this.blacklistUrl = blacklistUrl; |
| | | this.blacklistUrlPattern.clear(); |
| | | this.blacklistUrl.forEach(url -> { |
| | | this.blacklistUrlPattern.add(Pattern.compile(url.replaceAll("\\*\\*", "(.*?)"), Pattern.CASE_INSENSITIVE)); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.filter; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilter; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.OrderedGatewayFilter; |
| | | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; |
| | | import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * è·åbodyè¯·æ±æ°æ®ï¼è§£å³æµä¸è½éå¤è¯»åé®é¢ï¼ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class CacheRequestFilter extends AbstractGatewayFilterFactory<CacheRequestFilter.Config> |
| | | { |
| | | public CacheRequestFilter() |
| | | { |
| | | super(Config.class); |
| | | } |
| | | |
| | | @Override |
| | | public String name() |
| | | { |
| | | return "CacheRequestFilter"; |
| | | } |
| | | |
| | | @Override |
| | | public GatewayFilter apply(Config config) |
| | | { |
| | | CacheRequestGatewayFilter cacheRequestGatewayFilter = new CacheRequestGatewayFilter(); |
| | | Integer order = config.getOrder(); |
| | | if (order == null) |
| | | { |
| | | return cacheRequestGatewayFilter; |
| | | } |
| | | return new OrderedGatewayFilter(cacheRequestGatewayFilter, order); |
| | | } |
| | | |
| | | public static class CacheRequestGatewayFilter implements GatewayFilter |
| | | { |
| | | @Override |
| | | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) |
| | | { |
| | | // GET DELETE ä¸è¿æ»¤ |
| | | HttpMethod method = exchange.getRequest().getMethod(); |
| | | if (method == null || method == HttpMethod.GET || method == HttpMethod.DELETE) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | return ServerWebExchangeUtils.cacheRequestBodyAndRequest(exchange, (serverHttpRequest) -> { |
| | | if (serverHttpRequest == exchange.getRequest()) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | return chain.filter(exchange.mutate().request(serverHttpRequest).build()); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<String> shortcutFieldOrder() |
| | | { |
| | | return Collections.singletonList("order"); |
| | | } |
| | | |
| | | static class Config |
| | | { |
| | | private Integer order; |
| | | |
| | | public Integer getOrder() |
| | | { |
| | | return order; |
| | | } |
| | | |
| | | public void setOrder(Integer order) |
| | | { |
| | | this.order = order; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.filter; |
| | | |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | import com.se.gateway.service.ValidateCodeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilter; |
| | | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; |
| | | import org.springframework.core.io.buffer.DataBuffer; |
| | | import org.springframework.core.io.buffer.DataBufferUtils; |
| | | import org.springframework.http.server.reactive.ServerHttpRequest; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.se.common.core.utils.ServletUtils; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.gateway.config.properties.CaptchaProperties; |
| | | import reactor.core.publisher.Flux; |
| | | |
| | | /** |
| | | * éªè¯ç è¿æ»¤å¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> |
| | | { |
| | | private final static String[] VALIDATE_URL = new String[] { "/auth/login", "/auth/register" }; |
| | | |
| | | @Autowired |
| | | private ValidateCodeService validateCodeService; |
| | | |
| | | @Autowired |
| | | private CaptchaProperties captchaProperties; |
| | | |
| | | private static final String CODE = "code"; |
| | | |
| | | private static final String UUID = "uuid"; |
| | | |
| | | @Override |
| | | public GatewayFilter apply(Object config) |
| | | { |
| | | return (exchange, chain) -> { |
| | | ServerHttpRequest request = exchange.getRequest(); |
| | | |
| | | // éç»å½/注åè¯·æ±æéªè¯ç å
³éï¼ä¸å¤ç |
| | | if (!StringUtils.equalsAnyIgnoreCase(request.getURI().getPath(), VALIDATE_URL) || !captchaProperties.getEnabled()) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | |
| | | try |
| | | { |
| | | String rspStr = resolveBodyFromRequest(request); |
| | | JSONObject obj = JSON.parseObject(rspStr); |
| | | validateCodeService.checkCaptcha(obj.getString(CODE), obj.getString(UUID)); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage()); |
| | | } |
| | | return chain.filter(exchange); |
| | | }; |
| | | } |
| | | |
| | | private String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest) |
| | | { |
| | | // è·å请æ±ä½ |
| | | Flux<DataBuffer> body = serverHttpRequest.getBody(); |
| | | AtomicReference<String> bodyRef = new AtomicReference<>(); |
| | | body.subscribe(buffer -> { |
| | | CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer()); |
| | | DataBufferUtils.release(buffer); |
| | | bodyRef.set(charBuffer.toString()); |
| | | }); |
| | | return bodyRef.get(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.filter; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.GlobalFilter; |
| | | import org.springframework.core.Ordered; |
| | | import org.springframework.core.io.buffer.DataBuffer; |
| | | import org.springframework.core.io.buffer.DataBufferFactory; |
| | | import org.springframework.core.io.buffer.DataBufferUtils; |
| | | import org.springframework.core.io.buffer.DefaultDataBufferFactory; |
| | | import org.springframework.core.io.buffer.NettyDataBufferFactory; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.server.reactive.ServerHttpRequest; |
| | | import org.springframework.http.server.reactive.ServerHttpRequestDecorator; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.html.EscapeUtil; |
| | | import com.se.gateway.config.properties.XssProperties; |
| | | import io.netty.buffer.ByteBufAllocator; |
| | | import reactor.core.publisher.Flux; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * è·¨ç«èæ¬è¿æ»¤å¨ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | @ConditionalOnProperty(value = "security.xss.enabled", havingValue = "true") |
| | | public class XssFilter implements GlobalFilter, Ordered |
| | | { |
| | | // è·¨ç«èæ¬ç xss é
ç½®ï¼nacosèªè¡æ·»å |
| | | @Autowired |
| | | private XssProperties xss; |
| | | |
| | | @Override |
| | | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) |
| | | { |
| | | ServerHttpRequest request = exchange.getRequest(); |
| | | // xsså¼å
³æªå¼å¯ æ éè¿nacoså
³éï¼ä¸è¿æ»¤ |
| | | if (!xss.getEnabled()) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | // GET DELETE ä¸è¿æ»¤ |
| | | HttpMethod method = request.getMethod(); |
| | | if (method == null || method == HttpMethod.GET || method == HttpMethod.DELETE) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | // éjsonç±»åï¼ä¸è¿æ»¤ |
| | | if (!isJsonRequest(exchange)) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | // excludeUrls ä¸è¿æ»¤ |
| | | String url = request.getURI().getPath(); |
| | | if (StringUtils.matches(url, xss.getExcludeUrls())) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | ServerHttpRequestDecorator httpRequestDecorator = requestDecorator(exchange); |
| | | return chain.filter(exchange.mutate().request(httpRequestDecorator).build()); |
| | | |
| | | } |
| | | |
| | | private ServerHttpRequestDecorator requestDecorator(ServerWebExchange exchange) |
| | | { |
| | | ServerHttpRequestDecorator serverHttpRequestDecorator = new ServerHttpRequestDecorator(exchange.getRequest()) |
| | | { |
| | | @Override |
| | | public Flux<DataBuffer> getBody() |
| | | { |
| | | Flux<DataBuffer> body = super.getBody(); |
| | | return body.buffer().map(dataBuffers -> { |
| | | DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); |
| | | DataBuffer join = dataBufferFactory.join(dataBuffers); |
| | | byte[] content = new byte[join.readableByteCount()]; |
| | | join.read(content); |
| | | DataBufferUtils.release(join); |
| | | String bodyStr = new String(content, StandardCharsets.UTF_8); |
| | | // é²xssæ»å»è¿æ»¤ |
| | | bodyStr = EscapeUtil.clean(bodyStr); |
| | | // 转æåè |
| | | byte[] bytes = bodyStr.getBytes(StandardCharsets.UTF_8); |
| | | NettyDataBufferFactory nettyDataBufferFactory = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT); |
| | | DataBuffer buffer = nettyDataBufferFactory.allocateBuffer(bytes.length); |
| | | buffer.write(bytes); |
| | | return buffer; |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public HttpHeaders getHeaders() |
| | | { |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | httpHeaders.putAll(super.getHeaders()); |
| | | // ç±äºä¿®æ¹äºè¯·æ±ä½çbodyï¼å¯¼è´content-lengthé¿åº¦ä¸ç¡®å®ï¼å æ¤éè¦å é¤åå
çcontent-length |
| | | httpHeaders.remove(HttpHeaders.CONTENT_LENGTH); |
| | | httpHeaders.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); |
| | | return httpHeaders; |
| | | } |
| | | |
| | | }; |
| | | return serverHttpRequestDecorator; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ¯Jsonè¯·æ± |
| | | * |
| | | * @param exchange HTTPè¯·æ± |
| | | */ |
| | | public boolean isJsonRequest(ServerWebExchange exchange) |
| | | { |
| | | String header = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); |
| | | return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | } |
| | | |
| | | @Override |
| | | public int getOrder() |
| | | { |
| | | return -100; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.handler; |
| | | |
| | | import org.springframework.cloud.gateway.support.NotFoundException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.http.server.reactive.ServerHttpResponse; |
| | | import org.springframework.web.server.ResponseStatusException; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import com.se.common.core.utils.ServletUtils; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * ç½å
³ç»ä¸å¼å¸¸å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Order(-1) |
| | | @Configuration |
| | | public class GatewayExceptionHandler implements ErrorWebExceptionHandler |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(GatewayExceptionHandler.class); |
| | | |
| | | @Override |
| | | public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) |
| | | { |
| | | ServerHttpResponse response = exchange.getResponse(); |
| | | |
| | | if (exchange.getResponse().isCommitted()) |
| | | { |
| | | return Mono.error(ex); |
| | | } |
| | | |
| | | String msg; |
| | | |
| | | if (ex instanceof NotFoundException) |
| | | { |
| | | msg = "æå¡æªæ¾å°"; |
| | | } |
| | | else if (ex instanceof ResponseStatusException) |
| | | { |
| | | ResponseStatusException responseStatusException = (ResponseStatusException) ex; |
| | | msg = responseStatusException.getMessage(); |
| | | } |
| | | else |
| | | { |
| | | msg = "å
鍿å¡å¨é误"; |
| | | } |
| | | |
| | | log.error("[ç½å
³å¼å¸¸å¤ç]请æ±è·¯å¾:{},å¼å¸¸ä¿¡æ¯:{}", exchange.getRequest().getPath(), ex.getMessage()); |
| | | |
| | | return ServletUtils.webFluxResponseWriter(response, msg); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.handler; |
| | | |
| | | import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; |
| | | import com.alibaba.csp.sentinel.slots.block.BlockException; |
| | | import com.se.common.core.utils.ServletUtils; |
| | | import org.springframework.web.reactive.function.server.ServerResponse; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import org.springframework.web.server.WebExceptionHandler; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * èªå®ä¹éæµå¼å¸¸å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | public class SentinelFallbackHandler implements WebExceptionHandler |
| | | { |
| | | private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) |
| | | { |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请æ±è¶
è¿æå¤§æ°ï¼è¯·ç¨ååè¯"); |
| | | } |
| | | |
| | | @Override |
| | | public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) |
| | | { |
| | | if (exchange.getResponse().isCommitted()) |
| | | { |
| | | return Mono.error(ex); |
| | | } |
| | | if (!BlockException.isBlockException(ex)) |
| | | { |
| | | return Mono.error(ex); |
| | | } |
| | | return handleBlockedRequest(exchange, ex).flatMap(response -> writeResponse(response, exchange)); |
| | | } |
| | | |
| | | private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable) |
| | | { |
| | | return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.handler; |
| | | |
| | | import java.util.Optional; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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.RestController; |
| | | import reactor.core.publisher.Mono; |
| | | import springfox.documentation.swagger.web.SecurityConfiguration; |
| | | import springfox.documentation.swagger.web.SecurityConfigurationBuilder; |
| | | import springfox.documentation.swagger.web.SwaggerResourcesProvider; |
| | | import springfox.documentation.swagger.web.UiConfiguration; |
| | | import springfox.documentation.swagger.web.UiConfigurationBuilder; |
| | | |
| | | @RestController |
| | | @RequestMapping("/swagger-resources") |
| | | public class SwaggerHandler |
| | | { |
| | | @Autowired(required = false) |
| | | private SecurityConfiguration securityConfiguration; |
| | | |
| | | @Autowired(required = false) |
| | | private UiConfiguration uiConfiguration; |
| | | |
| | | private final SwaggerResourcesProvider swaggerResources; |
| | | |
| | | @Autowired |
| | | public SwaggerHandler(SwaggerResourcesProvider swaggerResources) |
| | | { |
| | | this.swaggerResources = swaggerResources; |
| | | } |
| | | |
| | | @GetMapping("/configuration/security") |
| | | public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() |
| | | { |
| | | return Mono.just(new ResponseEntity<>( |
| | | Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()), |
| | | HttpStatus.OK)); |
| | | } |
| | | |
| | | @GetMapping("/configuration/ui") |
| | | public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() |
| | | { |
| | | return Mono.just(new ResponseEntity<>( |
| | | Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK)); |
| | | } |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | @GetMapping("") |
| | | public Mono<ResponseEntity> swaggerResources() |
| | | { |
| | | return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK))); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.handler; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import com.se.gateway.service.ValidateCodeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.reactive.function.BodyInserters; |
| | | import org.springframework.web.reactive.function.server.HandlerFunction; |
| | | import org.springframework.web.reactive.function.server.ServerRequest; |
| | | import org.springframework.web.reactive.function.server.ServerResponse; |
| | | import com.se.common.core.exception.CaptchaException; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | /** |
| | | * éªè¯ç è·å |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Component |
| | | public class ValidateCodeHandler implements HandlerFunction<ServerResponse> |
| | | { |
| | | @Autowired |
| | | private ValidateCodeService validateCodeService; |
| | | |
| | | @Override |
| | | public Mono<ServerResponse> handle(ServerRequest serverRequest) |
| | | { |
| | | AjaxResult ajax; |
| | | try |
| | | { |
| | | ajax = validateCodeService.createCaptcha(); |
| | | } |
| | | catch (CaptchaException | IOException e) |
| | | { |
| | | return Mono.error(e); |
| | | } |
| | | return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.service; |
| | | |
| | | import java.io.IOException; |
| | | import com.se.common.core.exception.CaptchaException; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | |
| | | /** |
| | | * éªè¯ç å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | public interface ValidateCodeService |
| | | { |
| | | /** |
| | | * çæéªè¯ç |
| | | */ |
| | | public AjaxResult createCaptcha() throws IOException, CaptchaException; |
| | | |
| | | /** |
| | | * æ ¡éªéªè¯ç |
| | | */ |
| | | public void checkCaptcha(String key, String value) throws CaptchaException; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.gateway.service.impl; |
| | | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | |
| | | import com.se.gateway.config.properties.CaptchaProperties; |
| | | import com.se.gateway.service.ValidateCodeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.FastByteArrayOutputStream; |
| | | import com.google.code.kaptcha.Producer; |
| | | import com.se.common.core.constant.CacheConstants; |
| | | import com.se.common.core.constant.Constants; |
| | | import com.se.common.core.exception.CaptchaException; |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.common.core.utils.sign.Base64; |
| | | import com.se.common.core.utils.uuid.IdUtils; |
| | | import com.se.common.core.web.domain.AjaxResult; |
| | | import com.se.common.redis.service.RedisService; |
| | | |
| | | /** |
| | | * éªè¯ç å®ç°å¤ç |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class ValidateCodeServiceImpl implements ValidateCodeService |
| | | { |
| | | @Resource(name = "captchaProducer") |
| | | private Producer captchaProducer; |
| | | |
| | | @Resource(name = "captchaProducerMath") |
| | | private Producer captchaProducerMath; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Autowired |
| | | private CaptchaProperties captchaProperties; |
| | | |
| | | /** |
| | | * çæéªè¯ç |
| | | */ |
| | | @Override |
| | | public AjaxResult createCaptcha() throws IOException, CaptchaException |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | boolean captchaEnabled = captchaProperties.getEnabled(); |
| | | ajax.put("captchaEnabled", captchaEnabled); |
| | | if (!captchaEnabled) |
| | | { |
| | | return ajax; |
| | | } |
| | | |
| | | // ä¿åéªè¯ç ä¿¡æ¯ |
| | | String uuid = IdUtils.simpleUUID(); |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | |
| | | String capStr = null, code = null; |
| | | BufferedImage image = null; |
| | | |
| | | String captchaType = captchaProperties.getType(); |
| | | // çæéªè¯ç |
| | | if ("math".equals(captchaType)) |
| | | { |
| | | String capText = captchaProducerMath.createText(); |
| | | capStr = capText.substring(0, capText.lastIndexOf("@")); |
| | | code = capText.substring(capText.lastIndexOf("@") + 1); |
| | | image = captchaProducerMath.createImage(capStr); |
| | | } |
| | | else if ("char".equals(captchaType)) |
| | | { |
| | | capStr = code = captchaProducer.createText(); |
| | | image = captchaProducer.createImage(capStr); |
| | | } |
| | | |
| | | redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); |
| | | // è½¬æ¢æµä¿¡æ¯ååº |
| | | FastByteArrayOutputStream os = new FastByteArrayOutputStream(); |
| | | try |
| | | { |
| | | ImageIO.write(image, "jpg", os); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | |
| | | ajax.put("uuid", uuid); |
| | | ajax.put("img", Base64.encode(os.toByteArray())); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªéªè¯ç |
| | | */ |
| | | @Override |
| | | public void checkCaptcha(String code, String uuid) throws CaptchaException |
| | | { |
| | | if (StringUtils.isEmpty(code)) |
| | | { |
| | | throw new CaptchaException("éªè¯ç ä¸è½ä¸ºç©º"); |
| | | } |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); |
| | | String captcha = redisService.getCacheObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | throw new CaptchaException("éªè¯ç 已失æ"); |
| | | } |
| | | redisService.deleteObject(verifyKey); |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | throw new CaptchaException("éªè¯ç é误"); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | Spring Boot Version: ${spring-boot.version} |
| | | Spring Application Name: ${spring.application.name} |
| | | SeGatewayApplicationï¼å·²ç»å¯å¨ |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.modules.monitor; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import de.codecentric.boot.admin.server.config.EnableAdminServer; |
| | | |
| | | /** |
| | | * çæ§ä¸å¿ |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableAdminServer |
| | | @SpringBootApplication |
| | | public class SeMonitorApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | SpringApplication.run(SeMonitorApplication.class, args); |
| | | System.out.println("(â¥â â¿â )ï¾ï¾ çæ§ä¸å¿å¯å¨æå á(´ڡ`á)ï¾ \n" + |
| | | " .-------. ____ __ \n" + |
| | | " | _ _ \\ \\ \\ / / \n" + |
| | | " | ( ' ) | \\ _. / ' \n" + |
| | | " |(_ o _) / _( )_ .' \n" + |
| | | " | (_,_).' __ ___(_ o _)' \n" + |
| | | " | |\\ \\ | || |(_,_)' \n" + |
| | | " | | \\ `' /| `-' / \n" + |
| | | " | | \\ / \\ / \n" + |
| | | " ''-' `'-' `-..-' "); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.modules.monitor.config; |
| | | |
| | | import de.codecentric.boot.admin.server.config.AdminServerProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| | | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
| | | import org.springframework.security.web.SecurityFilterChain; |
| | | import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; |
| | | |
| | | /** |
| | | * çæ§æéé
ç½® |
| | | * |
| | | * @author admin |
| | | */ |
| | | @EnableWebSecurity |
| | | public class WebSecurityConfigurer |
| | | { |
| | | private final String adminContextPath; |
| | | |
| | | public WebSecurityConfigurer(AdminServerProperties adminServerProperties) |
| | | { |
| | | this.adminContextPath = adminServerProperties.getContextPath(); |
| | | } |
| | | |
| | | @Bean |
| | | public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception |
| | | { |
| | | SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); |
| | | successHandler.setTargetUrlParameter("redirectTo"); |
| | | successHandler.setDefaultTargetUrl(adminContextPath + "/"); |
| | | |
| | | return httpSecurity |
| | | .headers().frameOptions().disable() |
| | | .and().authorizeRequests() |
| | | .antMatchers(adminContextPath + "/assets/**" |
| | | , adminContextPath + "/login" |
| | | , adminContextPath + "/actuator/**" |
| | | , adminContextPath + "/instances/**" |
| | | ).permitAll() |
| | | .anyRequest().authenticated() |
| | | .and() |
| | | .formLogin().loginPage(adminContextPath + "/login") |
| | | .successHandler(successHandler).and() |
| | | .logout().logoutUrl(adminContextPath + "/logout") |
| | | .and() |
| | | .httpBasic().and() |
| | | .csrf() |
| | | .disable() |
| | | .build(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | Spring Boot Version: ${spring-boot.version} |
| | | Spring Application Name: ${spring.application.name} |
| | | SeMonitorApplicationï¼å·²ç»å¯å¨ |