¶Ô±ÈÐÂÎļþ |
| | |
| | | ###################################################################### |
| | | # Build Tools |
| | | |
| | | .gradle |
| | | /build/ |
| | | !gradle/wrapper/gradle-wrapper.jar |
| | | |
| | | target/ |
| | | !.mvn/wrapper/maven-wrapper.jar |
| | | |
| | | ###################################################################### |
| | | # IDE |
| | | |
| | | ### STS ### |
| | | .apt_generated |
| | | .classpath |
| | | .factorypath |
| | | .project |
| | | .settings |
| | | .springBeans |
| | | |
| | | ### IntelliJ IDEA ### |
| | | .idea |
| | | *.iws |
| | | *.iml |
| | | *.ipr |
| | | |
| | | ### JRebel ### |
| | | rebel.xml |
| | | |
| | | ### NetBeans ### |
| | | nbproject/private/ |
| | | build/* |
| | | nbbuild/ |
| | | dist/ |
| | | nbdist/ |
| | | .nb-gradle/ |
| | | |
| | | ###################################################################### |
| | | # Others |
| | | *.log |
| | | *.xml.versionsBackup |
| | | *.swp |
| | | |
| | | !*/build/*.java |
| | | !*/build/*.html |
| | | !*/build/*.xml |
¶Ô±ÈÐÂÎļþ |
| | |
| | | The MIT License (MIT) |
| | | |
| | | Copyright (c) 2018 Jcdm |
| | | |
| | | Permission is hereby granted, free of charge, to any person obtaining a copy of |
| | | this software and associated documentation files (the "Software"), to deal in |
| | | the Software without restriction, including without limitation the rights to |
| | | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| | | the Software, and to permit persons to whom the Software is furnished to do so, |
| | | subject to the following conditions: |
| | | |
| | | The above copyright notice and this permission notice shall be included in all |
| | | copies or substantial portions of the Software. |
| | | |
| | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| | | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| | | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| | | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| | | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
¶Ô±ÈÐÂÎļþ |
| | |
| | | @echo off |
| | | echo. |
| | | echo [ä¿¡æ¯] æ¸
çå·¥ç¨targetçæè·¯å¾ã |
| | | echo. |
| | | |
| | | %~d0 |
| | | cd %~dp0 |
| | | |
| | | cd .. |
| | | call mvn clean |
| | | |
| | | pause |
¶Ô±ÈÐÂÎļþ |
| | |
| | | @echo off |
| | | echo. |
| | | echo [ä¿¡æ¯] æå
Webå·¥ç¨ï¼çæwar/jarå
æ件ã |
| | | echo. |
| | | |
| | | %~d0 |
| | | cd %~dp0 |
| | | |
| | | cd .. |
| | | call mvn clean package -Dmaven.test.skip=true |
| | | |
| | | pause |
¶Ô±ÈÐÂÎļþ |
| | |
| | | @echo off |
| | | echo. |
| | | echo [ä¿¡æ¯] 使ç¨Jarå½ä»¤è¿è¡Webå·¥ç¨ã |
| | | echo. |
| | | |
| | | cd %~dp0 |
| | | cd ../jcdm-admin/target |
| | | |
| | | set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m |
| | | |
| | | java -jar %JAVA_OPTS% jcdm-admin.jar |
| | | |
| | | cd bin |
| | | pause |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <parent> |
| | | <artifactId>jcdm</artifactId> |
| | | <groupId>com.jcdm</groupId> |
| | | <version>3.8.6</version> |
| | | </parent> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | <packaging>jar</packaging> |
| | | <artifactId>jcdm-admin</artifactId> |
| | | |
| | | <description> |
| | | webæå¡å
¥å£ |
| | | </description> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- spring-boot-devtools --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-devtools</artifactId> |
| | | <optional>true</optional> <!-- 表示ä¾èµä¸ä¼ä¼ é --> |
| | | </dependency> |
| | | |
| | | <!-- swagger3--> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- é²æ¢è¿å
¥swagger页é¢æ¥ç±»å转æ¢é误ï¼æé¤3.0.0ä¸çå¼ç¨ï¼æå¨å¢å 1.6.2çæ¬ --> |
| | | <dependency> |
| | | <groupId>io.swagger</groupId> |
| | | <artifactId>swagger-models</artifactId> |
| | | <version>1.6.2</version> |
| | | </dependency> |
| | | |
| | | <!-- Mysql驱å¨å
--> |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!--sqlserveræ°æ®åºé
ç½®--> |
| | | <dependency> |
| | | <groupId>com.microsoft.sqlserver</groupId> |
| | | <artifactId>mssql-jdbc</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- æ ¸å¿æ¨¡å--> |
| | | <dependency> |
| | | <groupId>com.jcdm</groupId> |
| | | <artifactId>jcdm-framework</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- å®æ¶ä»»å¡--> |
| | | <dependency> |
| | | <groupId>com.jcdm</groupId> |
| | | <artifactId>jcdm-quartz</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- 代ç çæ--> |
| | | <dependency> |
| | | <groupId>com.jcdm</groupId> |
| | | <artifactId>jcdm-generator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- JCDM模å--> |
| | | <dependency> |
| | | <groupId>com.jcdm</groupId> |
| | | <artifactId>jcdm-main</artifactId> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-maven-plugin</artifactId> |
| | | <version>2.5.15</version> |
| | | <configuration> |
| | | <fork>true</fork> <!-- å¦æ没æ该é
ç½®ï¼devtoolsä¸ä¼çæ --> |
| | | </configuration> |
| | | <executions> |
| | | <execution> |
| | | <goals> |
| | | <goal>repackage</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>3.1.0</version> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <warName>${project.artifactId}</warName> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | <finalName>${project.artifactId}</finalName> |
| | | </build> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm; |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| | | |
| | | /** |
| | | * å¯å¨ç¨åº |
| | | * |
| | | * @author jc |
| | | */ |
| | | |
| | | |
| | | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) |
| | | public class MesApplication |
| | | { |
| | | public static void main(String[] args) |
| | | { |
| | | // System.setProperty("spring.devtools.restart.enabled", "false"); |
| | | SpringApplication.run(MesApplication.class, args); |
| | | System.out.println("(â¥â â¿â )ï¾ï¾ ç³»ç»å¯å¨æå á(´ڡ`á)ï¾ \n" /*+ |
| | | " .-------. ____ __ \n" + |
| | | " | _ _ \\ \\ \\ / / \n" + |
| | | " | ( ' ) | \\ _. / ' \n" + |
| | | " |(_ o _) / _( )_ .' \n" + |
| | | " | (_,_).' __ ___(_ o _)' \n" + |
| | | " | |\\ \\ | || |(_,_)' \n" + |
| | | " | | \\ `' /| `-' / \n" + |
| | | " | | \\ / \\ / \n" + |
| | | " ''-' `'-' `-..-' " */ |
| | | ); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm; |
| | | |
| | | import org.springframework.boot.builder.SpringApplicationBuilder; |
| | | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| | | |
| | | /** |
| | | * web容å¨ä¸è¿è¡é¨ç½² |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class MesServletInitializer extends SpringBootServletInitializer |
| | | { |
| | | @Override |
| | | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) |
| | | { |
| | | return application.sources(MesApplication.class); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.common; |
| | | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.FastByteArrayOutputStream; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.google.code.kaptcha.Producer; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.redis.RedisCache; |
| | | import com.jcdm.common.utils.sign.Base64; |
| | | import com.jcdm.common.utils.uuid.IdUtils; |
| | | import com.jcdm.system.service.ISysConfigService; |
| | | |
| | | /** |
| | | * éªè¯ç æä½å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | public class CaptchaController |
| | | { |
| | | @Resource(name = "captchaProducer") |
| | | private Producer captchaProducer; |
| | | |
| | | @Resource(name = "captchaProducerMath") |
| | | private Producer captchaProducerMath; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | /** |
| | | * çæéªè¯ç |
| | | */ |
| | | @GetMapping("/captchaImage") |
| | | public AjaxResult getCode(HttpServletResponse response) throws IOException |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | boolean captchaEnabled = configService.selectCaptchaEnabled(); |
| | | 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 = MesConfig.getCaptchaType(); |
| | | 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); |
| | | } |
| | | |
| | | redisCache.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; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.common; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.file.FileUploadUtils; |
| | | import com.jcdm.common.utils.file.FileUtils; |
| | | import com.jcdm.framework.config.ServerConfig; |
| | | |
| | | /** |
| | | * éç¨è¯·æ±å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/common") |
| | | public class CommonController |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(CommonController.class); |
| | | |
| | | @Autowired |
| | | private ServerConfig serverConfig; |
| | | |
| | | private static final String FILE_DELIMETER = ","; |
| | | |
| | | /** |
| | | * éç¨ä¸è½½è¯·æ± |
| | | * |
| | | * @param fileName æ件å称 |
| | | * @param delete æ¯å¦å é¤ |
| | | */ |
| | | @GetMapping("/download") |
| | | public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) |
| | | { |
| | | try |
| | | { |
| | | if (!FileUtils.checkAllowDownload(fileName)) |
| | | { |
| | | throw new Exception(StringUtils.format("æ件å称({})éæ³ï¼ä¸å
许ä¸è½½ã ", fileName)); |
| | | } |
| | | String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
| | | String filePath = MesConfig.getDownloadPath() + fileName; |
| | | |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |
| | | if (delete) |
| | | { |
| | | FileUtils.deleteFile(filePath); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("ä¸è½½æ件失败", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éç¨ä¸ä¼ 请æ±ï¼åä¸ªï¼ |
| | | */ |
| | | @PostMapping("/upload") |
| | | public AjaxResult uploadFile(MultipartFile file) throws Exception |
| | | { |
| | | try |
| | | { |
| | | // ä¸ä¼ æä»¶è·¯å¾ |
| | | String filePath = MesConfig.getUploadPath(); |
| | | // ä¸ä¼ 并è¿åæ°æ件å称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("url", url); |
| | | ajax.put("fileName", fileName); |
| | | ajax.put("newFileName", FileUtils.getName(fileName)); |
| | | ajax.put("originalFilename", file.getOriginalFilename()); |
| | | return ajax; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éç¨ä¸ä¼ 请æ±ï¼å¤ä¸ªï¼ |
| | | */ |
| | | @PostMapping("/uploads") |
| | | public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception |
| | | { |
| | | try |
| | | { |
| | | // ä¸ä¼ æä»¶è·¯å¾ |
| | | String filePath = MesConfig.getUploadPath(); |
| | | List<String> urls = new ArrayList<String>(); |
| | | List<String> fileNames = new ArrayList<String>(); |
| | | List<String> newFileNames = new ArrayList<String>(); |
| | | List<String> originalFilenames = new ArrayList<String>(); |
| | | for (MultipartFile file : files) |
| | | { |
| | | // ä¸ä¼ 并è¿åæ°æ件å称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | urls.add(url); |
| | | fileNames.add(fileName); |
| | | newFileNames.add(FileUtils.getName(fileName)); |
| | | originalFilenames.add(file.getOriginalFilename()); |
| | | } |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); |
| | | ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | return ajax; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¬å°èµæºéç¨ä¸è½½ |
| | | */ |
| | | @GetMapping("/download/resource") |
| | | public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) |
| | | throws Exception |
| | | { |
| | | try |
| | | { |
| | | if (!FileUtils.checkAllowDownload(resource)) |
| | | { |
| | | throw new Exception(StringUtils.format("èµæºæ件({})éæ³ï¼ä¸å
许ä¸è½½ã ", resource)); |
| | | } |
| | | // æ¬å°èµæºè·¯å¾ |
| | | String localPath = MesConfig.getProfile(); |
| | | // æ°æ®åºèµæºå°å |
| | | String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); |
| | | // ä¸è½½å称 |
| | | String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, downloadName); |
| | | FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("ä¸è½½æ件失败", e); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.monitor; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Properties; |
| | | import java.util.Set; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisCallback; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.system.domain.SysCache; |
| | | |
| | | /** |
| | | * ç¼åçæ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/cache") |
| | | public class CacheController |
| | | { |
| | | @Autowired |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | |
| | | private final static List<SysCache> caches = new ArrayList<SysCache>(); |
| | | { |
| | | caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "ç¨æ·ä¿¡æ¯")); |
| | | caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "é
置信æ¯")); |
| | | caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "æ°æ®åå
¸")); |
| | | caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "éªè¯ç ")); |
| | | caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "é²éæ交")); |
| | | caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "éæµå¤ç")); |
| | | caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "å¯ç é误次æ°")); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @GetMapping() |
| | | public AjaxResult getInfo() throws Exception |
| | | { |
| | | Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info()); |
| | | Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats")); |
| | | Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize()); |
| | | |
| | | Map<String, Object> result = new HashMap<>(3); |
| | | result.put("info", info); |
| | | result.put("dbSize", dbSize); |
| | | |
| | | List<Map<String, String>> pieList = new ArrayList<>(); |
| | | commandStats.stringPropertyNames().forEach(key -> { |
| | | Map<String, String> data = new HashMap<>(2); |
| | | String property = commandStats.getProperty(key); |
| | | data.put("name", StringUtils.removeStart(key, "cmdstat_")); |
| | | data.put("value", StringUtils.substringBetween(property, "calls=", ",usec")); |
| | | pieList.add(data); |
| | | }); |
| | | result.put("commandStats", pieList); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @GetMapping("/getNames") |
| | | public AjaxResult cache() |
| | | { |
| | | return AjaxResult.success(caches); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @GetMapping("/getKeys/{cacheName}") |
| | | public AjaxResult getCacheKeys(@PathVariable String cacheName) |
| | | { |
| | | Set<String> cacheKeys = redisTemplate.keys(cacheName + "*"); |
| | | return AjaxResult.success(cacheKeys); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @GetMapping("/getValue/{cacheName}/{cacheKey}") |
| | | public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) |
| | | { |
| | | String cacheValue = redisTemplate.opsForValue().get(cacheKey); |
| | | SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue); |
| | | return AjaxResult.success(sysCache); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @DeleteMapping("/clearCacheName/{cacheName}") |
| | | public AjaxResult clearCacheName(@PathVariable String cacheName) |
| | | { |
| | | Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*"); |
| | | redisTemplate.delete(cacheKeys); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @DeleteMapping("/clearCacheKey/{cacheKey}") |
| | | public AjaxResult clearCacheKey(@PathVariable String cacheKey) |
| | | { |
| | | redisTemplate.delete(cacheKey); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @DeleteMapping("/clearCacheAll") |
| | | public AjaxResult clearCacheAll() |
| | | { |
| | | Collection<String> cacheKeys = redisTemplate.keys("*"); |
| | | redisTemplate.delete(cacheKeys); |
| | | return AjaxResult.success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.monitor; |
| | | |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.framework.web.domain.Server; |
| | | |
| | | /** |
| | | * æå¡å¨çæ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/server") |
| | | public class ServerController |
| | | { |
| | | @PreAuthorize("@ss.hasPermi('monitor:server:list')") |
| | | @GetMapping() |
| | | public AjaxResult getInfo() throws Exception |
| | | { |
| | | Server server = new Server(); |
| | | server.copyTo(); |
| | | return AjaxResult.success(server); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.monitor; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.framework.web.service.SysPasswordService; |
| | | import com.jcdm.system.domain.SysLogininfor; |
| | | import com.jcdm.system.service.ISysLogininforService; |
| | | |
| | | /** |
| | | * ç³»ç»è®¿é®è®°å½ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/logininfor") |
| | | public class SysLogininforController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysLogininforService logininforService; |
| | | |
| | | @Autowired |
| | | private SysPasswordService passwordService; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysLogininfor logininfor) |
| | | { |
| | | startPage(); |
| | | List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('monitor: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, "ç»å½æ¥å¿"); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{infoIds}") |
| | | public AjaxResult remove(@PathVariable Long[] infoIds) |
| | | { |
| | | return toAjax(logininforService.deleteLogininforByIds(infoIds)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | logininforService.cleanLogininfor(); |
| | | return success(); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:unlock')") |
| | | @Log(title = "è´¦æ·è§£é", businessType = BusinessType.OTHER) |
| | | @GetMapping("/unlock/{userName}") |
| | | public AjaxResult unlock(@PathVariable("userName") String userName) |
| | | { |
| | | passwordService.clearLoginRecordCache(userName); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.monitor; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.domain.SysOperLog; |
| | | import com.jcdm.system.service.ISysOperLogService; |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/operlog") |
| | | public class SysOperlogController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysOperLogService operLogService; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysOperLog operLog) |
| | | { |
| | | startPage(); |
| | | List<SysOperLog> list = operLogService.selectOperLogList(operLog); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('monitor: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) |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") |
| | | @DeleteMapping("/{operIds}") |
| | | public AjaxResult remove(@PathVariable Long[] operIds) |
| | | { |
| | | return toAjax(operLogService.deleteOperLogByIds(operIds)); |
| | | } |
| | | |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | operLogService.cleanOperLog(); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.monitor; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.core.redis.RedisCache; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.system.domain.SysUserOnline; |
| | | import com.jcdm.system.service.ISysUserOnlineService; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ·çæ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/online") |
| | | public class SysUserOnlineController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserOnlineService userOnlineService; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(String ipaddr, String userName) |
| | | { |
| | | Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| | | for (String key : keys) |
| | | { |
| | | LoginUser user = redisCache.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) && StringUtils.isNotNull(user.getUser())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
| | | } |
| | | else |
| | | { |
| | | userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); |
| | | } |
| | | } |
| | | Collections.reverse(userOnlineList); |
| | | userOnlineList.removeAll(Collections.singleton(null)); |
| | | return getDataTable(userOnlineList); |
| | | } |
| | | |
| | | /** |
| | | * 强éç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") |
| | | @Log(title = "å¨çº¿ç¨æ·", businessType = BusinessType.FORCE) |
| | | @DeleteMapping("/{tokenId}") |
| | | public AjaxResult forceLogout(@PathVariable String tokenId) |
| | | { |
| | | redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.domain.SysConfig; |
| | | import com.jcdm.system.service.ISysConfigService; |
| | | |
| | | /** |
| | | * åæ°é
ç½® ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/config") |
| | | public class SysConfigController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | /** |
| | | * è·ååæ°é
ç½®å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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, "åæ°æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åæ°ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:config:query')") |
| | | @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)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åæ°é
ç½® |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(configService.insertConfig(config)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(configService.updateConfig(config)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åæ°é
ç½® |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:config:remove')") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{configIds}") |
| | | public AjaxResult remove(@PathVariable Long[] configIds) |
| | | { |
| | | configService.deleteConfigByIds(configIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * å·æ°åæ°ç¼å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:config:remove')") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/refreshCache") |
| | | public AjaxResult refreshCache() |
| | | { |
| | | configService.resetConfigCache(); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.constant.UserConstants; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysDept; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.system.service.ISysDeptService; |
| | | |
| | | /** |
| | | * é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/dept") |
| | | public class SysDeptController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | /** |
| | | * è·åé¨é¨å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| | | @GetMapping("/list") |
| | | public AjaxResult list(SysDept dept) |
| | | { |
| | | List<SysDept> depts = deptService.selectDeptList(dept); |
| | | return success(depts); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é¨é¨å表ï¼æé¤èç¹ï¼ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é¨é¨ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dept:query')") |
| | | @GetMapping(value = "/{deptId}") |
| | | public AjaxResult getInfo(@PathVariable Long deptId) |
| | | { |
| | | deptService.checkDeptDataScope(deptId); |
| | | return success(deptService.selectDeptById(deptId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢é¨é¨ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(deptService.insertDept(dept)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹é¨é¨ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(deptService.updateDept(dept)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤é¨é¨ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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.jcdm.web.controller.system; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysDictData; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.service.ISysDictDataService; |
| | | import com.jcdm.system.service.ISysDictTypeService; |
| | | |
| | | /** |
| | | * æ°æ®åå
¸ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/dict/data") |
| | | public class SysDictDataController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDictDataService dictDataService; |
| | | |
| | | @Autowired |
| | | private ISysDictTypeService dictTypeService; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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, "åå
¸æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åå
¸æ°æ®è¯¦ç» |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dict:add')") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysDictData dict) |
| | | { |
| | | dict.setCreateBy(getUsername()); |
| | | return toAjax(dictDataService.insertDictData(dict)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿ååå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dict:edit')") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysDictData dict) |
| | | { |
| | | dict.setUpdateBy(getUsername()); |
| | | return toAjax(dictDataService.updateDictData(dict)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictCodes}") |
| | | public AjaxResult remove(@PathVariable Long[] dictCodes) |
| | | { |
| | | dictDataService.deleteDictDataByIds(dictCodes); |
| | | return success(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysDictType; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.service.ISysDictTypeService; |
| | | |
| | | /** |
| | | * æ°æ®åå
¸ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/dict/type") |
| | | public class SysDictTypeController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysDictTypeService dictTypeService; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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, "åå
¸ç±»å"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åå
¸ç±»åè¯¦ç» |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| | | @GetMapping(value = "/{dictId}") |
| | | public AjaxResult getInfo(@PathVariable Long dictId) |
| | | { |
| | | return success(dictTypeService.selectDictTypeById(dictId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(dictTypeService.insertDictType(dict)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(dictTypeService.updateDictType(dict)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictIds}") |
| | | public AjaxResult remove(@PathVariable Long[] dictIds) |
| | | { |
| | | dictTypeService.deleteDictTypeByIds(dictIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * å·æ°åå
¸ç¼å |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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.jcdm.web.controller.system; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * é¦é¡µ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | public class SysIndexController |
| | | { |
| | | /** ç³»ç»åºç¡é
ç½® */ |
| | | @Autowired |
| | | private MesConfig mesConfig; |
| | | |
| | | /** |
| | | * 访é®é¦é¡µï¼æç¤ºè¯ |
| | | */ |
| | | @RequestMapping("/") |
| | | public String index() |
| | | { |
| | | return StringUtils.format("欢è¿ä½¿ç¨{}åå°ç®¡çæ¡æ¶ï¼å½åçæ¬ï¼v{}ï¼è¯·éè¿å端å°å访é®ã", mesConfig.getName(), mesConfig.getVersion()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | 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.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysMenu; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import com.jcdm.common.core.domain.model.LoginBody; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.framework.web.service.SysLoginService; |
| | | import com.jcdm.framework.web.service.SysPermissionService; |
| | | import com.jcdm.system.service.ISysMenuService; |
| | | |
| | | /** |
| | | * ç»å½éªè¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | public class SysLoginController |
| | | { |
| | | @Autowired |
| | | private SysLoginService loginService; |
| | | |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | /** |
| | | * ç»å½æ¹æ³ |
| | | * |
| | | * @param loginBody ç»å½ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @PostMapping("/login") |
| | | public AjaxResult login(@RequestBody LoginBody loginBody) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // çæ令ç |
| | | String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), |
| | | loginBody.getUuid()); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @return ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | @GetMapping("getInfo") |
| | | public AjaxResult getInfo() |
| | | { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | // è§è²éå |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * è·åè·¯ç±ä¿¡æ¯ |
| | | * |
| | | * @return è·¯ç±ä¿¡æ¯ |
| | | */ |
| | | @GetMapping("getRouters") |
| | | public AjaxResult getRouters() |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.constant.UserConstants; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysMenu; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.system.service.ISysMenuService; |
| | | |
| | | /** |
| | | * èåä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/menu") |
| | | public class SysMenuController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | /** |
| | | * è·åèåå表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:menu:list')") |
| | | @GetMapping("/list") |
| | | public AjaxResult list(SysMenu menu) |
| | | { |
| | | List<SysMenu> menus = menuService.selectMenuList(menu, getUserId()); |
| | | return success(menus); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®èåç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:menu:query')") |
| | | @GetMapping(value = "/{menuId}") |
| | | public AjaxResult getInfo(@PathVariable Long menuId) |
| | | { |
| | | return success(menuService.selectMenuById(menuId)); |
| | | } |
| | | |
| | | /** |
| | | * è·åèåä¸ææ å表 |
| | | */ |
| | | @GetMapping("/treeselect") |
| | | public AjaxResult treeselect(SysMenu menu) |
| | | { |
| | | List<SysMenu> menus = menuService.selectMenuList(menu, getUserId()); |
| | | return success(menuService.buildMenuTreeSelect(menus)); |
| | | } |
| | | |
| | | /** |
| | | * å 载对åºè§è²èåå表æ |
| | | */ |
| | | @GetMapping(value = "/roleMenuTreeselect/{roleId}") |
| | | public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) |
| | | { |
| | | List<SysMenu> menus = menuService.selectMenuList(getUserId()); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); |
| | | ajax.put("menus", menuService.buildMenuTreeSelect(menus)); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢èå |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(menuService.insertMenu(menu)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹èå |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(menuService.updateMenu(menu)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤èå |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.system.domain.SysNotice; |
| | | import com.jcdm.system.service.ISysNoticeService; |
| | | |
| | | /** |
| | | * å
¬å ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/notice") |
| | | public class SysNoticeController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysNoticeService noticeService; |
| | | |
| | | /** |
| | | * è·åéç¥å
¬åå表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:notice:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysNotice notice) |
| | | { |
| | | startPage(); |
| | | List<SysNotice> list = noticeService.selectNoticeList(notice); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®éç¥å
¬åç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:notice:query')") |
| | | @GetMapping(value = "/{noticeId}") |
| | | public AjaxResult getInfo(@PathVariable Long noticeId) |
| | | { |
| | | return success(noticeService.selectNoticeById(noticeId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢éç¥å
Œ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:notice:add')") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysNotice notice) |
| | | { |
| | | notice.setCreateBy(getUsername()); |
| | | return toAjax(noticeService.insertNotice(notice)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹éç¥å
Œ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:notice:edit')") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysNotice notice) |
| | | { |
| | | notice.setUpdateBy(getUsername()); |
| | | return toAjax(noticeService.updateNotice(notice)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤éç¥å
Œ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:notice:remove')") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{noticeIds}") |
| | | public AjaxResult remove(@PathVariable Long[] noticeIds) |
| | | { |
| | | return toAjax(noticeService.deleteNoticeByIds(noticeIds)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.domain.SysPost; |
| | | import com.jcdm.system.service.ISysPostService; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/post") |
| | | public class SysPostController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysPostService postService; |
| | | |
| | | /** |
| | | * è·åå²ä½å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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, "å²ä½æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å²ä½ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:post:query')") |
| | | @GetMapping(value = "/{postId}") |
| | | public AjaxResult getInfo(@PathVariable Long postId) |
| | | { |
| | | return success(postService.selectPostById(postId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å²ä½ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(postService.insertPost(post)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹å²ä½ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(postService.updatePost(post)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å²ä½ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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.jcdm.web.controller.system; |
| | | |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.file.FileUploadUtils; |
| | | import com.jcdm.common.utils.file.MimeTypeUtils; |
| | | import com.jcdm.framework.web.service.TokenService; |
| | | import com.jcdm.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ä¸ªäººä¿¡æ¯ ä¸å¡å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/user/profile") |
| | | public class SysProfileController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | /** |
| | | * ä¸ªäººä¿¡æ¯ |
| | | */ |
| | | @GetMapping |
| | | public AjaxResult profile() |
| | | { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser user = loginUser.getUser(); |
| | | AjaxResult ajax = AjaxResult.success(user); |
| | | ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); |
| | | ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername())); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ· |
| | | */ |
| | | @Log(title = "个人信æ¯", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) |
| | | { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser currentUser = loginUser.getUser(); |
| | | 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) > 0) |
| | | { |
| | | // æ´æ°ç¼åç¨æ·ä¿¡æ¯ |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | return error("ä¿®æ¹ä¸ªäººä¿¡æ¯å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | /** |
| | | * éç½®å¯ç |
| | | */ |
| | | @Log(title = "个人信æ¯", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/updatePwd") |
| | | public AjaxResult updatePwd(String oldPassword, String newPassword) |
| | | { |
| | | LoginUser loginUser = getLoginUser(); |
| | | String userName = loginUser.getUsername(); |
| | | String password = loginUser.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.getUser().setPassword(newPassword); |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | return error("ä¿®æ¹å¯ç å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | /** |
| | | * 头åä¸ä¼ |
| | | */ |
| | | @Log(title = "ç¨æ·å¤´å", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/avatar") |
| | | public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception |
| | | { |
| | | if (!file.isEmpty()) |
| | | { |
| | | LoginUser loginUser = getLoginUser(); |
| | | String avatar = FileUploadUtils.upload(MesConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); |
| | | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("imgUrl", avatar); |
| | | // æ´æ°ç¼åç¨æ·å¤´å |
| | | loginUser.getUser().setAvatar(avatar); |
| | | tokenService.setLoginUser(loginUser); |
| | | return ajax; |
| | | } |
| | | } |
| | | return error("ä¸ä¼ å¾çå¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.model.RegisterBody; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.framework.web.service.SysRegisterService; |
| | | import com.jcdm.system.service.ISysConfigService; |
| | | |
| | | /** |
| | | * 注åéªè¯ |
| | | * |
| | | * @author JC |
| | | */ |
| | | @RestController |
| | | public class SysRegisterController extends BaseController |
| | | { |
| | | @Autowired |
| | | private SysRegisterService registerService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @PostMapping("/register") |
| | | public AjaxResult register(@RequestBody RegisterBody user) |
| | | { |
| | | if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) |
| | | { |
| | | return error("å½åç³»ç»æ²¡æå¼å¯æ³¨ååè½ï¼"); |
| | | } |
| | | String msg = registerService.register(user); |
| | | return StringUtils.isEmpty(msg) ? success() : error(msg); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysDept; |
| | | import com.jcdm.common.core.domain.entity.SysRole; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.framework.web.service.SysPermissionService; |
| | | import com.jcdm.framework.web.service.TokenService; |
| | | import com.jcdm.system.domain.SysUserRole; |
| | | import com.jcdm.system.service.ISysDeptService; |
| | | import com.jcdm.system.service.ISysRoleService; |
| | | import com.jcdm.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * è§è²ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/role") |
| | | public class SysRoleController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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, "è§è²æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è§è²ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping(value = "/{roleId}") |
| | | public AjaxResult getInfo(@PathVariable Long roleId) |
| | | { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return success(roleService.selectRoleById(roleId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢è§è² |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(roleService.insertRole(role)); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åè§è² |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | |
| | | if (roleService.updateRole(role) > 0) |
| | | { |
| | | // æ´æ°ç¼åç¨æ·æé |
| | | LoginUser loginUser = getLoginUser(); |
| | | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) |
| | | { |
| | | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); |
| | | loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); |
| | | tokenService.setLoginUser(loginUser); |
| | | } |
| | | return success(); |
| | | } |
| | | return error("ä¿®æ¹è§è²'" + role.getRoleName() + "'失败ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¿åæ°æ®æé |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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)); |
| | | } |
| | | |
| | | /** |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(roleService.updateRoleStatus(role)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤è§è² |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:remove')") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{roleIds}") |
| | | public AjaxResult remove(@PathVariable Long[] roleIds) |
| | | { |
| | | return toAjax(roleService.deleteRoleByIds(roleIds)); |
| | | } |
| | | |
| | | /** |
| | | * è·åè§è²éæ©æ¡å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult optionselect() |
| | | { |
| | | return success(roleService.selectRoleAll()); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å·²åé
ç¨æ·è§è²å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo allocatedList(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectAllocatedList(user); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo unallocatedList(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectUnallocatedList(user); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * åæ¶ææç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancel") |
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | { |
| | | return toAjax(roleService.deleteAuthUser(userRole)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éåæ¶ææç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancelAll") |
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | return toAjax(roleService.deleteAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹ééæ©ç¨æ·ææ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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)); |
| | | } |
| | | |
| | | /** |
| | | * è·å对åºè§è²é¨é¨æ å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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.jcdm.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | 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.security.access.prepost.PreAuthorize; |
| | | 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.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.entity.SysDept; |
| | | import com.jcdm.common.core.domain.entity.SysRole; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.poi.ExcelUtil; |
| | | import com.jcdm.system.service.ISysDeptService; |
| | | import com.jcdm.system.service.ISysPostService; |
| | | import com.jcdm.system.service.ISysRoleService; |
| | | import com.jcdm.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/user") |
| | | public class SysUserController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @Autowired |
| | | private ISysPostService postService; |
| | | |
| | | /** |
| | | * è·åç¨æ·å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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) |
| | | @PreAuthorize("@ss.hasPermi('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 = getUsername(); |
| | | String message = userService.importUser(userList, updateSupport, operName); |
| | | return success(message); |
| | | } |
| | | |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) |
| | | { |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | util.importTemplateExcel(response, "ç¨æ·æ°æ®"); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | | { |
| | | 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(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | return toAjax(userService.insertUser(user)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | 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(getUsername()); |
| | | return toAjax(userService.updateUser(user)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ç¨æ· |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public AjaxResult remove(@PathVariable Long[] userIds) |
| | | { |
| | | if (ArrayUtils.contains(userIds, getUserId())) |
| | | { |
| | | return error("å½åç¨æ·ä¸è½å é¤"); |
| | | } |
| | | return toAjax(userService.deleteUserByIds(userIds)); |
| | | } |
| | | |
| | | /** |
| | | * éç½®å¯ç |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @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(getUsername()); |
| | | return toAjax(userService.resetPwd(user)); |
| | | } |
| | | |
| | | /** |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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(getUsername()); |
| | | return toAjax(userService.updateUserStatus(user)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¨æ·ç¼å·è·åææè§è² |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('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; |
| | | } |
| | | |
| | | /** |
| | | * ç¨æ·ææè§è² |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| | | { |
| | | userService.checkUserDataScope(userId); |
| | | userService.insertUserAuth(userId, roleIds); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * è·åé¨é¨æ å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | @GetMapping("/deptTree") |
| | | public AjaxResult deptTree(SysDept dept) |
| | | { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.controller.tool; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | 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.jcdm.common.core.controller.BaseController; |
| | | import com.jcdm.common.core.domain.R; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | /** |
| | | * swagger ç¨æ·æµè¯æ¹æ³ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Api("ç¨æ·ä¿¡æ¯ç®¡ç") |
| | | @RestController |
| | | @RequestMapping("/test/user") |
| | | public class TestController extends BaseController |
| | | { |
| | | private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>(); |
| | | { |
| | | users.put(1, new UserEntity(1, "admin", "admin123", "15888888888")); |
| | | users.put(2, new UserEntity(2, "ry", "admin123", "15666666666")); |
| | | } |
| | | |
| | | @ApiOperation("è·åç¨æ·å表") |
| | | @GetMapping("/list") |
| | | public R<List<UserEntity>> userList() |
| | | { |
| | | List<UserEntity> userList = new ArrayList<UserEntity>(users.values()); |
| | | return R.ok(userList); |
| | | } |
| | | |
| | | @ApiOperation("è·åç¨æ·è¯¦ç»") |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class) |
| | | @GetMapping("/{userId}") |
| | | public R<UserEntity> getUser(@PathVariable Integer userId) |
| | | { |
| | | if (!users.isEmpty() && users.containsKey(userId)) |
| | | { |
| | | return R.ok(users.get(userId)); |
| | | } |
| | | else |
| | | { |
| | | return R.fail("ç¨æ·ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("æ°å¢ç¨æ·") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·id", dataType = "Integer", dataTypeClass = Integer.class), |
| | | @ApiImplicitParam(name = "username", value = "ç¨æ·å称", dataType = "String", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "password", value = "ç¨æ·å¯ç ", dataType = "String", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "mobile", value = "ç¨æ·ææº", dataType = "String", dataTypeClass = String.class) |
| | | }) |
| | | @PostMapping("/save") |
| | | public R<String> save(UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | { |
| | | return R.fail("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | | users.put(user.getUserId(), user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("æ´æ°ç¨æ·") |
| | | @PutMapping("/update") |
| | | public R<String> update(@RequestBody UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | { |
| | | return R.fail("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | | if (users.isEmpty() || !users.containsKey(user.getUserId())) |
| | | { |
| | | return R.fail("ç¨æ·ä¸åå¨"); |
| | | } |
| | | users.remove(user.getUserId()); |
| | | users.put(user.getUserId(), user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("å é¤ç¨æ·ä¿¡æ¯") |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class) |
| | | @DeleteMapping("/{userId}") |
| | | public R<String> delete(@PathVariable Integer userId) |
| | | { |
| | | if (!users.isEmpty() && users.containsKey(userId)) |
| | | { |
| | | users.remove(userId); |
| | | return R.ok(); |
| | | } |
| | | else |
| | | { |
| | | return R.fail("ç¨æ·ä¸åå¨"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiModel(value = "UserEntity", description = "ç¨æ·å®ä½") |
| | | class UserEntity |
| | | { |
| | | @ApiModelProperty("ç¨æ·ID") |
| | | private Integer userId; |
| | | |
| | | @ApiModelProperty("ç¨æ·å称") |
| | | private String username; |
| | | |
| | | @ApiModelProperty("ç¨æ·å¯ç ") |
| | | private String password; |
| | | |
| | | @ApiModelProperty("ç¨æ·ææº") |
| | | private String mobile; |
| | | |
| | | public UserEntity() |
| | | { |
| | | |
| | | } |
| | | |
| | | public UserEntity(Integer userId, String username, String password, String mobile) |
| | | { |
| | | this.userId = userId; |
| | | this.username = username; |
| | | this.password = password; |
| | | this.mobile = mobile; |
| | | } |
| | | |
| | | public Integer getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Integer userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public String getMobile() |
| | | { |
| | | return mobile; |
| | | } |
| | | |
| | | public void setMobile(String mobile) |
| | | { |
| | | this.mobile = mobile; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.web.core.config; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.models.auth.In; |
| | | import springfox.documentation.builders.ApiInfoBuilder; |
| | | import springfox.documentation.builders.PathSelectors; |
| | | import springfox.documentation.builders.RequestHandlerSelectors; |
| | | import springfox.documentation.service.ApiInfo; |
| | | import springfox.documentation.service.ApiKey; |
| | | import springfox.documentation.service.AuthorizationScope; |
| | | import springfox.documentation.service.Contact; |
| | | import springfox.documentation.service.SecurityReference; |
| | | import springfox.documentation.service.SecurityScheme; |
| | | import springfox.documentation.spi.DocumentationType; |
| | | import springfox.documentation.spi.service.contexts.SecurityContext; |
| | | import springfox.documentation.spring.web.plugins.Docket; |
| | | |
| | | /** |
| | | * Swagger2çæ¥å£é
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class SwaggerConfig |
| | | { |
| | | /** ç³»ç»åºç¡é
ç½® */ |
| | | @Autowired |
| | | private MesConfig mesConfig; |
| | | |
| | | /** æ¯å¦å¼å¯swagger */ |
| | | @Value("${swagger.enabled}") |
| | | private boolean enabled; |
| | | |
| | | /** 设置请æ±çç»ä¸åç¼ */ |
| | | @Value("${swagger.pathMapping}") |
| | | private String pathMapping; |
| | | |
| | | /** |
| | | * å建API |
| | | */ |
| | | @Bean |
| | | public Docket createRestApi() |
| | | { |
| | | return new Docket(DocumentationType.OAS_30) |
| | | // æ¯å¦å¯ç¨Swagger |
| | | .enable(enabled) |
| | | // ç¨æ¥å建该APIçåºæ¬ä¿¡æ¯ï¼å±ç¤ºå¨ææ¡£ç页é¢ä¸ï¼èªå®ä¹å±ç¤ºçä¿¡æ¯ï¼ |
| | | .apiInfo(apiInfo()) |
| | | // 设置åªäºæ¥å£æ´é²ç»Swaggerå±ç¤º |
| | | .select() |
| | | // æ«ææææ注解çapiï¼ç¨è¿ç§æ¹å¼æ´çµæ´» |
| | | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
| | | // æ«ææå®å
ä¸çswagger注解 |
| | | // .apis(RequestHandlerSelectors.basePackage("com.jcdm.project.tool.swagger")) |
| | | // æ«æææ .apis(RequestHandlerSelectors.any()) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置å®å
¨æ¨¡å¼ï¼swaggerå¯ä»¥è®¾ç½®è®¿é®token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()) |
| | | .pathMapping(pathMapping); |
| | | } |
| | | |
| | | /** |
| | | * å®å
¨æ¨¡å¼ï¼è¿éæå®tokenéè¿Authorization头请æ±å¤´ä¼ é |
| | | */ |
| | | private List<SecurityScheme> securitySchemes() |
| | | { |
| | | List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>(); |
| | | apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue())); |
| | | return apiKeyList; |
| | | } |
| | | |
| | | /** |
| | | * å®å
¨ä¸ä¸æ |
| | | */ |
| | | private List<SecurityContext> securityContexts() |
| | | { |
| | | List<SecurityContext> securityContexts = new ArrayList<>(); |
| | | securityContexts.add( |
| | | SecurityContext.builder() |
| | | .securityReferences(defaultAuth()) |
| | | .operationSelector(o -> o.requestMappingPattern().matches("/.*")) |
| | | .build()); |
| | | return securityContexts; |
| | | } |
| | | |
| | | /** |
| | | * é»è®¤çå®å
¨ä¸å¼ç¨ |
| | | */ |
| | | private List<SecurityReference> defaultAuth() |
| | | { |
| | | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); |
| | | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; |
| | | authorizationScopes[0] = authorizationScope; |
| | | List<SecurityReference> securityReferences = new ArrayList<>(); |
| | | securityReferences.add(new SecurityReference("Authorization", authorizationScopes)); |
| | | return securityReferences; |
| | | } |
| | | |
| | | /** |
| | | * æ·»å æè¦ä¿¡æ¯ |
| | | */ |
| | | private ApiInfo apiInfo() |
| | | { |
| | | // ç¨ApiInfoBuilderè¿è¡å®å¶ |
| | | return new ApiInfoBuilder() |
| | | // 设置æ é¢ |
| | | .title("æ é¢ï¼æ±å®¸MES管çç³»ç»_æ¥å£ææ¡£") |
| | | // æè¿° |
| | | .description("æè¿°ï¼ç¨äºå·¥åç产ç°åºç®¡ç") |
| | | // ä½è
ä¿¡æ¯ |
| | | .contact(new Contact(mesConfig.getName(), null, null)) |
| | | // çæ¬ |
| | | .version("çæ¬å·:" + mesConfig.getVersion()) |
| | | .build(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | restart.include.json=/com.alibaba.fastjson.*.jar |
¶Ô±ÈÐÂÎļþ |
| | |
| | | # æ°æ®æºé
ç½® |
| | | spring: |
| | | # datasource: |
| | | # type: com.alibaba.druid.pool.DruidDataSource |
| | | # driverClassName: com.mysql.cj.jdbc.Driver |
| | | # druid: |
| | | # # 主åºæ°æ®æº |
| | | # master: |
| | | # url: jdbc:mysql://192.168.0.189:3306/jcdm-mes-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 |
| | | # username: root |
| | | # password: root |
| | | # æ°æ®æºé
ç½® |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | druid: |
| | | # 主åºæ°æ®æº |
| | | master: |
| | | url: jdbc:sqlserver://192.168.0.189:1433;DataBaseName=jcdm-mes |
| | | username: sa |
| | | password: JCDM@2023 |
| | | # ä»åºæ°æ®æº |
| | | slave: |
| | | # ä»æ°æ®æºå¼å
³/é»è®¤å
³é |
| | | enabled: false |
| | | url: |
| | | username: |
| | | password: |
| | | # åå§è¿æ¥æ° |
| | | initialSize: 5 |
| | | # æå°è¿æ¥æ± æ°é |
| | | minIdle: 10 |
| | | # æ大è¿æ¥æ± æ°é |
| | | maxActive: 20 |
| | | # é
ç½®è·åè¿æ¥çå¾
è¶
æ¶çæ¶é´ |
| | | maxWait: 60000 |
| | | # é
ç½®è¿æ¥è¶
æ¶æ¶é´ |
| | | connectTimeout: 30000 |
| | | # é
ç½®ç½ç»è¶
æ¶æ¶é´ |
| | | socketTimeout: 60000 |
| | | # é
ç½®é´éå¤ä¹
æè¿è¡ä¸æ¬¡æ£æµï¼æ£æµéè¦å
³éç空é²è¿æ¥ï¼åä½æ¯æ¯«ç§ |
| | | timeBetweenEvictionRunsMillis: 60000 |
| | | # é
ç½®ä¸ä¸ªè¿æ¥å¨æ± ä¸æå°çåçæ¶é´ï¼åä½æ¯æ¯«ç§ |
| | | minEvictableIdleTimeMillis: 300000 |
| | | # é
ç½®ä¸ä¸ªè¿æ¥å¨æ± ä¸æ大çåçæ¶é´ï¼åä½æ¯æ¯«ç§ |
| | | maxEvictableIdleTimeMillis: 900000 |
| | | # é
ç½®æ£æµè¿æ¥æ¯å¦ææ |
| | | # validationQuery: SELECT 1 FROM DUAL |
| | | validationQuery: SELECT 1 |
| | | testWhileIdle: true |
| | | testOnBorrow: false |
| | | testOnReturn: false |
| | | webStatFilter: |
| | | enabled: true |
| | | statViewServlet: |
| | | enabled: true |
| | | # 设置ç½ååï¼ä¸å¡«åå
许ææè®¿é® |
| | | allow: |
| | | url-pattern: /druid/* |
| | | # æ§å¶å°ç®¡çç¨æ·ååå¯ç |
| | | login-username: jcdm |
| | | login-password: 123456 |
| | | filter: |
| | | stat: |
| | | enabled: true |
| | | # æ
¢SQLè®°å½ |
| | | log-slow-sql: true |
| | | slow-sql-millis: 1000 |
| | | merge-sql: true |
| | | wall: |
| | | config: |
| | | multi-statement-allow: true |
¶Ô±ÈÐÂÎļþ |
| | |
| | | # 项ç®ç¸å
³é
ç½® |
| | | ruoyi: |
| | | # å称 |
| | | name: RuoYi |
| | | # çæ¬ |
| | | version: 3.8.6 |
| | | # çæ年份 |
| | | copyrightYear: 2023 |
| | | # å®ä¾æ¼ç¤ºå¼å
³ |
| | | demoEnabled: true |
| | | # æä»¶è·¯å¾ ç¤ºä¾ï¼ Windowsé
ç½®D:/jcdm/uploadPathï¼Linuxé
ç½® /home/jcdm/uploadPathï¼ |
| | | profile: D:/mes/uploadPath |
| | | # è·åipå°åå¼å
³ |
| | | addressEnabled: false |
| | | # éªè¯ç ç±»å math æ°åè®¡ç® char å符éªè¯ |
| | | captchaType: math |
| | | |
| | | # å¼åç¯å¢é
ç½® |
| | | server: |
| | | # æå¡å¨çHTTP端å£ï¼é»è®¤ä¸º8080 |
| | | port: 8080 |
| | | servlet: |
| | | # åºç¨ç访é®è·¯å¾ |
| | | context-path: / |
| | | tomcat: |
| | | # tomcatçURIç¼ç |
| | | uri-encoding: UTF-8 |
| | | # è¿æ¥æ°æ»¡åçæéæ°ï¼é»è®¤ä¸º100 |
| | | accept-count: 1000 |
| | | threads: |
| | | # tomcatæ大线ç¨æ°ï¼é»è®¤ä¸º200 |
| | | max: 800 |
| | | # Tomcatå¯å¨åå§åç线ç¨æ°ï¼é»è®¤å¼10 |
| | | min-spare: 100 |
| | | |
| | | # æ¥å¿é
ç½® |
| | | logging: |
| | | level: |
| | | com.jcdm: debug |
| | | org.springframework: warn |
| | | |
| | | # ç¨æ·é
ç½® |
| | | user: |
| | | password: |
| | | # å¯ç æ大éè¯¯æ¬¡æ° |
| | | maxRetryCount: 5 |
| | | # å¯ç éå®æ¶é´ï¼é»è®¤10åéï¼ |
| | | lockTime: 10 |
| | | |
| | | # Springé
ç½® |
| | | spring: |
| | | # èµæºä¿¡æ¯ |
| | | messages: |
| | | # å½é
åèµæºæä»¶è·¯å¾ |
| | | basename: i18n/messages |
| | | profiles: |
| | | active: druid |
| | | # æ件ä¸ä¼ |
| | | servlet: |
| | | multipart: |
| | | # å个æä»¶å¤§å° |
| | | max-file-size: 10MB |
| | | # 设置æ»ä¸ä¼ çæä»¶å¤§å° |
| | | max-request-size: 20MB |
| | | # æå¡æ¨¡å |
| | | devtools: |
| | | restart: |
| | | # çé¨ç½²å¼å
³ |
| | | enabled: true |
| | | # redis é
ç½® |
| | | # redis: |
| | | # # å°å |
| | | # host: localhost |
| | | # # 端å£ï¼é»è®¤ä¸º6379 |
| | | # port: 6379 |
| | | # # æ°æ®åºç´¢å¼ |
| | | # database: 0 |
| | | # # å¯ç |
| | | # password: |
| | | # # è¿æ¥è¶
æ¶æ¶é´ |
| | | # timeout: 10s |
| | | # lettuce: |
| | | # pool: |
| | | # # è¿æ¥æ± ä¸çæå°ç©ºé²è¿æ¥ |
| | | # min-idle: 0 |
| | | # # è¿æ¥æ± ä¸çæ大空é²è¿æ¥ |
| | | # max-idle: 8 |
| | | # # è¿æ¥æ± çæ大æ°æ®åºè¿æ¥æ° |
| | | # max-active: 8 |
| | | # # #è¿æ¥æ± æ大é»å¡çå¾
æ¶é´ï¼ä½¿ç¨è´å¼è¡¨ç¤ºæ²¡æéå¶ï¼ |
| | | # max-wait: -1ms |
| | | |
| | | # tokené
ç½® |
| | | token: |
| | | # 令çèªå®ä¹æ è¯ |
| | | header: Authorization |
| | | # 令çå¯é¥ |
| | | secret: abcdefghijklmnopqrstuvwxyz |
| | | # 令çæææï¼é»è®¤30åéï¼ |
| | | expireTime: 30 |
| | | |
| | | # MyBatisé
ç½® |
| | | mybatis: |
| | | # æç´¢æå®å
å«å |
| | | typeAliasesPackage: com.jcdm.**.domain |
| | | # é
ç½®mapperçæ«æï¼æ¾å°ææçmapper.xmlæ å°æ件 |
| | | mapperLocations: classpath*:mapper/**/*Mapper.xml |
| | | # å è½½å
¨å±çé
ç½®æ件 |
| | | configLocation: classpath:mybatis/mybatis-config.xml |
| | | |
| | | # PageHelperå页æ件 |
| | | pagehelper: |
| | | # helperDialect: mysql |
| | | supportMethodsArguments: true |
| | | params: count=countSql |
| | | autoRuntimeDialect: true |
| | | |
| | | # Swaggeré
ç½® |
| | | swagger: |
| | | # æ¯å¦å¼å¯swagger |
| | | enabled: true |
| | | # 请æ±åç¼ |
| | | pathMapping: /dev-api |
| | | |
| | | # é²æ¢XSSæ»å» |
| | | xss: |
| | | # è¿æ»¤å¼å
³ |
| | | enabled: true |
| | | # æé¤é¾æ¥ï¼å¤ä¸ªç¨éå·åéï¼ |
| | | excludes: /system/notice |
| | | # å¹é
é¾æ¥ |
| | | urlPatterns: /system/*,/monitor/*,/tool/* |
¶Ô±ÈÐÂÎļþ |
| | |
| | | Application Version: ${ruoyi.version} |
| | | Spring Boot Version: ${spring-boot.version} |
| | | //////////////////////////////////////////////////////////////////// |
| | | // _ooOoo_ // |
| | | // o8888888o // |
| | | // 88" . "88 // |
| | | // (| ^_^ |) // |
| | | // O\ = /O // |
| | | // ____/`---'\____ // |
| | | // .' \\| |// `. // |
| | | // / \\||| : |||// \ // |
| | | // / _||||| -:- |||||- \ // |
| | | // | | \\\ - /// | | // |
| | | // | \_| ''\---/'' | | // |
| | | // \ .-\__ `-` ___/-. / // |
| | | // ___`. .' /--.--\ `. . ___ // |
| | | // ."" '< `.___\_<|>_/___.' >'"". // |
| | | // | | : `- \`.;`\ _ /`;.`/ - ` : | | // |
| | | // \ \ `-. \_ __\ /__ _/ .-` / / // |
| | | // ========`-.____`-.___\_____/___.-`____.-'======== // |
| | | // `=---=' // |
| | | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // |
| | | // ä½ç¥ä¿ä½ æ°¸ä¸å®æº æ°¸æ BUG // |
| | | //////////////////////////////////////////////////////////////////// |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #é误æ¶æ¯ |
| | | not.null=* å¿
须填å |
| | | user.jcaptcha.error=éªè¯ç é误 |
| | | user.jcaptcha.expire=éªè¯ç 已失æ |
| | | user.not.exists=ç¨æ·ä¸åå¨/å¯ç é误 |
| | | user.password.not.match=ç¨æ·ä¸åå¨/å¯ç é误 |
| | | user.password.retry.limit.count=å¯ç è¾å
¥é误{0}次 |
| | | user.password.retry.limit.exceed=å¯ç è¾å
¥é误{0}次ï¼å¸æ·éå®{1}åé |
| | | user.password.delete=对ä¸èµ·ï¼æ¨çè´¦å·å·²è¢«å é¤ |
| | | user.blocked=ç¨æ·å·²å°ç¦ï¼è¯·è系管çå |
| | | role.blocked=è§è²å·²å°ç¦ï¼è¯·è系管çå |
| | | login.blocked=å¾éæ¾ï¼è®¿é®IP已被åå
¥ç³»ç»é»åå |
| | | user.logout.success=éåºæå |
| | | |
| | | length.not.valid=é¿åº¦å¿
é¡»å¨{min}å°{max}个å符ä¹é´ |
| | | |
| | | user.username.not.valid=* 2å°20个æ±åãåæ¯ãæ°åæä¸å线ç»æï¼ä¸å¿
须以éæ°åå¼å¤´ |
| | | user.password.not.valid=* 5-50个å符 |
| | | |
| | | user.email.not.valid=é®ç®±æ ¼å¼é误 |
| | | user.mobile.phone.number.not.valid=ææºå·æ ¼å¼é误 |
| | | user.login.success=ç»å½æå |
| | | user.register.success=注åæå |
| | | user.notfound=请éæ°ç»å½ |
| | | user.forcelogout=管çå强å¶éåºï¼è¯·éæ°ç»å½ |
| | | user.unknown.error=æªç¥é误ï¼è¯·éæ°ç»å½ |
| | | |
| | | ##æ件ä¸ä¼ æ¶æ¯ |
| | | upload.exceed.maxSize=ä¸ä¼ çæ件大å°è¶
åºéå¶çæ件大å°ï¼<br/>å
许çæ件æ大大å°æ¯ï¼{0}MBï¼ |
| | | upload.filename.exceed.length=ä¸ä¼ çæ件åæé¿{0}个å符 |
| | | |
| | | ##æé |
| | | no.permission=æ¨æ²¡ææ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
| | | no.create.permission=æ¨æ²¡æå建æ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
| | | no.update.permission=æ¨æ²¡æä¿®æ¹æ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
| | | no.delete.permission=æ¨æ²¡æå é¤æ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
| | | no.export.permission=æ¨æ²¡æ导åºæ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
| | | no.view.permission=æ¨æ²¡ææ¥çæ°æ®çæéï¼è¯·è系管çåæ·»å æé [{0}] |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <configuration> |
| | | <!-- æ¥å¿åæ¾è·¯å¾ --> |
| | | <property name="log.path" value="/home/mes/logs" /> |
| | | <!-- æ¥å¿è¾åºæ ¼å¼ --> |
| | | <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" /> |
| | | |
| | | <!-- æ§å¶å°è¾åº --> |
| | | <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- ç³»ç»æ¥å¿è¾åº --> |
| | | <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.path}/sys-info.log</file> |
| | | <!-- 循ç¯æ¿çï¼åºäºæ¶é´å建æ¥å¿æ件 --> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!-- æ¥å¿æ件åæ ¼å¼ --> |
| | | <fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern> |
| | | <!-- æ¥å¿æ大çåå² 60天 --> |
| | | <maxHistory>60</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <!-- è¿æ»¤ççº§å« --> |
| | | <level>INFO</level> |
| | | <!-- å¹é
æ¶çæä½ï¼æ¥æ¶ï¼è®°å½ï¼ --> |
| | | <onMatch>ACCEPT</onMatch> |
| | | <!-- ä¸å¹é
æ¶çæä½ï¼æç»ï¼ä¸è®°å½ï¼ --> |
| | | <onMismatch>DENY</onMismatch> |
| | | </filter> |
| | | </appender> |
| | | |
| | | <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.path}/sys-error.log</file> |
| | | <!-- 循ç¯æ¿çï¼åºäºæ¶é´å建æ¥å¿æ件 --> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!-- æ¥å¿æ件åæ ¼å¼ --> |
| | | <fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern> |
| | | <!-- æ¥å¿æ大çåå² 60天 --> |
| | | <maxHistory>60</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <!-- è¿æ»¤ççº§å« --> |
| | | <level>ERROR</level> |
| | | <!-- å¹é
æ¶çæä½ï¼æ¥æ¶ï¼è®°å½ï¼ --> |
| | | <onMatch>ACCEPT</onMatch> |
| | | <!-- ä¸å¹é
æ¶çæä½ï¼æç»ï¼ä¸è®°å½ï¼ --> |
| | | <onMismatch>DENY</onMismatch> |
| | | </filter> |
| | | </appender> |
| | | |
| | | <!-- ç¨æ·è®¿é®æ¥å¿è¾åº --> |
| | | <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.path}/sys-user.log</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!-- æ天åæ» daily --> |
| | | <fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern> |
| | | <!-- æ¥å¿æ大çåå² 60天 --> |
| | | <maxHistory>60</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- ç³»ç»æ¨¡åæ¥å¿çº§å«æ§å¶ --> |
| | | <logger name="com.jcdm" level="info" /> |
| | | <!-- Springæ¥å¿çº§å«æ§å¶ --> |
| | | <logger name="org.springframework" level="warn" /> |
| | | |
| | | <root level="info"> |
| | | <appender-ref ref="console" /> |
| | | </root> |
| | | |
| | | <!--ç³»ç»æä½æ¥å¿--> |
| | | <root level="info"> |
| | | <appender-ref ref="file_info" /> |
| | | <appender-ref ref="file_error" /> |
| | | </root> |
| | | |
| | | <!--ç³»ç»ç¨æ·æä½æ¥å¿--> |
| | | <logger name="sys-user" level="info"> |
| | | <appender-ref ref="sys-user"/> |
| | | </logger> |
| | | </configuration> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE configuration |
| | | PUBLIC "-//mybatis.org//DTD Config 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-config.dtd"> |
| | | <configuration> |
| | | <!-- å
¨å±åæ° --> |
| | | <settings> |
| | | <!-- 使å
¨å±çæ å°å¨å¯ç¨æç¦ç¨ç¼å --> |
| | | <setting name="cacheEnabled" value="true" /> |
| | | <!-- å
许JDBC æ¯æèªå¨çæä¸»é® --> |
| | | <setting name="useGeneratedKeys" value="true" /> |
| | | <!-- é
ç½®é»è®¤çæ§è¡å¨.SIMPLEå°±æ¯æ®éæ§è¡å¨;REUSEæ§è¡å¨ä¼éç¨é¢å¤çè¯å¥(prepared statements);BATCHæ§è¡å¨å°éç¨è¯å¥å¹¶æ§è¡æ¹éæ´æ° --> |
| | | <setting name="defaultExecutorType" value="SIMPLE" /> |
| | | <!-- æå® MyBatis æç¨æ¥å¿çå
·ä½å®ç° --> |
| | | <setting name="logImpl" value="SLF4J" /> |
| | | <!-- 使ç¨é©¼å³°å½åæ³è½¬æ¢å段 --> |
| | | <!-- <setting name="mapUnderscoreToCamelCase" value="true"/> --> |
| | | </settings> |
| | | |
| | | </configuration> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <parent> |
| | | <artifactId>jcdm</artifactId> |
| | | <groupId>com.jcdm</groupId> |
| | | <version>3.8.6</version> |
| | | </parent> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <artifactId>jcdm-common</artifactId> |
| | | |
| | | <description> |
| | | commonéç¨å·¥å
· |
| | | </description> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- Springæ¡æ¶åºæ¬çæ ¸å¿å·¥å
· --> |
| | | <dependency> |
| | | <groupId>org.springframework</groupId> |
| | | <artifactId>spring-context-support</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringWeb模å --> |
| | | <dependency> |
| | | <groupId>org.springframework</groupId> |
| | | <artifactId>spring-web</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- spring security å®å
¨è®¤è¯ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-security</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- pagehelper å页æ件 --> |
| | | <dependency> |
| | | <groupId>com.github.pagehelper</groupId> |
| | | <artifactId>pagehelper-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- mybatis-plus å¢å¼ºCRUD --> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> |
| | | <version>3.4.2</version> |
| | | </dependency> |
| | | |
| | | <!-- èªå®ä¹éªè¯æ³¨è§£ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-validation</artifactId> |
| | | </dependency> |
| | | |
| | | <!--常ç¨å·¥å
·ç±» --> |
| | | <dependency> |
| | | <groupId>org.apache.commons</groupId> |
| | | <artifactId>commons-lang3</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- JSONå·¥å
·ç±» --> |
| | | <dependency> |
| | | <groupId>com.fasterxml.jackson.core</groupId> |
| | | <artifactId>jackson-databind</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- å¨ææ°æ®æº --> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
| | | <version>3.5.2</version> |
| | | </dependency> |
| | | |
| | | <!-- é¿éJSON解æå¨ --> |
| | | <dependency> |
| | | <groupId>com.alibaba.fastjson2</groupId> |
| | | <artifactId>fastjson2</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- io常ç¨å·¥å
·ç±» --> |
| | | <dependency> |
| | | <groupId>commons-io</groupId> |
| | | <artifactId>commons-io</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- excelå·¥å
· --> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi-ooxml</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- yml解æå¨ --> |
| | | <dependency> |
| | | <groupId>org.yaml</groupId> |
| | | <artifactId>snakeyaml</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Tokençæä¸è§£æ--> |
| | | <dependency> |
| | | <groupId>io.jsonwebtoken</groupId> |
| | | <artifactId>jjwt</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Jaxb --> |
| | | <dependency> |
| | | <groupId>javax.xml.bind</groupId> |
| | | <artifactId>jaxb-api</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- redis ç¼åæä½ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-data-redis</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- pool å¯¹è±¡æ± --> |
| | | <dependency> |
| | | <groupId>org.apache.commons</groupId> |
| | | <artifactId>commons-pool2</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- 解æ客æ·ç«¯æä½ç³»ç»ãæµè§å¨ç --> |
| | | <dependency> |
| | | <groupId>eu.bitwalker</groupId> |
| | | <artifactId>UserAgentUtils</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- servletå
--> |
| | | <dependency> |
| | | <groupId>javax.servlet</groupId> |
| | | <artifactId>javax.servlet-api</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- mybatis-plus å¢å¼ºCRUD --> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> |
| | | <version>3.4.1</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * å¿å访é®ä¸é´æ注解 |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Target({ ElementType.METHOD, ElementType.TYPE }) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface Anonymous |
| | | { |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * æ°æ®æéè¿æ»¤æ³¨è§£ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface DataScope |
| | | { |
| | | /** |
| | | * é¨é¨è¡¨çå«å |
| | | */ |
| | | public String deptAlias() default ""; |
| | | |
| | | /** |
| | | * ç¨æ·è¡¨çå«å |
| | | */ |
| | | public String userAlias() default ""; |
| | | |
| | | /** |
| | | * æéå符ï¼ç¨äºå¤ä¸ªè§è²å¹é
符åè¦æ±çæéï¼é»è®¤æ ¹æ®æé注解@ssè·åï¼å¤ä¸ªæéç¨éå·åéå¼æ¥ |
| | | */ |
| | | public String permission() default ""; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Inherited; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | import com.jcdm.common.enums.DataSourceType; |
| | | |
| | | /** |
| | | * èªå®ä¹å¤æ°æ®æºåæ¢æ³¨è§£ |
| | | * |
| | | * ä¼å
级ï¼å
æ¹æ³ï¼åç±»ï¼å¦ææ¹æ³è¦çäºç±»ä¸çæ°æ®æºç±»åï¼ä»¥æ¹æ³ç为åï¼å¦å以类ä¸ç为å |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Target({ ElementType.METHOD, ElementType.TYPE }) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | @Inherited |
| | | public @interface DataSource |
| | | { |
| | | /** |
| | | * åæ¢æ°æ®æºå称 |
| | | */ |
| | | public DataSourceType value() default DataSourceType.MASTER; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | import java.math.BigDecimal; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import com.jcdm.common.utils.poi.ExcelHandlerAdapter; |
| | | |
| | | /** |
| | | * èªå®ä¹å¯¼åºExcelæ°æ®æ³¨è§£ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Target(ElementType.FIELD) |
| | | public @interface Excel |
| | | { |
| | | /** |
| | | * 导åºæ¶å¨excelä¸æåº |
| | | */ |
| | | public int sort() default Integer.MAX_VALUE; |
| | | |
| | | /** |
| | | * 导åºå°Excelä¸çåå. |
| | | */ |
| | | public String name() default ""; |
| | | |
| | | /** |
| | | * æ¥ææ ¼å¼, å¦: yyyy-MM-dd |
| | | */ |
| | | public String dateFormat() default ""; |
| | | |
| | | /** |
| | | * å¦ææ¯åå
¸ç±»åï¼è¯·è®¾ç½®åå
¸çtypeå¼ (å¦: sys_user_sex) |
| | | */ |
| | | public String dictType() default ""; |
| | | |
| | | /** |
| | | * 读åå
å®¹è½¬è¡¨è¾¾å¼ (å¦: 0=ç·,1=女,2=æªç¥) |
| | | */ |
| | | public String readConverterExp() default ""; |
| | | |
| | | /** |
| | | * åé符ï¼è¯»åå符串ç»å
容 |
| | | */ |
| | | public String separator() default ","; |
| | | |
| | | /** |
| | | * BigDecimal 精度 é»è®¤:-1(é»è®¤ä¸å¼å¯BigDecimalæ ¼å¼å) |
| | | */ |
| | | public int scale() default -1; |
| | | |
| | | /** |
| | | * BigDecimal èå
¥è§å é»è®¤:BigDecimal.ROUND_HALF_EVEN |
| | | */ |
| | | public int roundingMode() default BigDecimal.ROUND_HALF_EVEN; |
| | | |
| | | /** |
| | | * 导åºæ¶å¨excelä¸æ¯ä¸ªåçé«åº¦ |
| | | */ |
| | | public double height() default 14; |
| | | |
| | | /** |
| | | * 导åºæ¶å¨excelä¸æ¯ä¸ªåç宽度 |
| | | */ |
| | | public double width() default 16; |
| | | |
| | | /** |
| | | * æååç¼,å¦% 90 åæ90% |
| | | */ |
| | | public String suffix() default ""; |
| | | |
| | | /** |
| | | * å½å¼ä¸ºç©ºæ¶,å段çé»è®¤å¼ |
| | | */ |
| | | public String defaultValue() default ""; |
| | | |
| | | /** |
| | | * æç¤ºä¿¡æ¯ |
| | | */ |
| | | public String prompt() default ""; |
| | | |
| | | /** |
| | | * 设置åªè½éæ©ä¸è½è¾å
¥çåå
容. |
| | | */ |
| | | public String[] combo() default {}; |
| | | |
| | | /** |
| | | * æ¯å¦éè¦çºµåå并åå
æ ¼,åºå¯¹éæ±:å«ælistéååå
æ ¼) |
| | | */ |
| | | public boolean needMerge() default false; |
| | | |
| | | /** |
| | | * æ¯å¦å¯¼åºæ°æ®,åºå¯¹éæ±:ææ¶æ们éè¦å¯¼åºä¸ä»½æ¨¡æ¿,è¿æ¯æ é¢éè¦ä½å
容éè¦ç¨æ·æ工填å. |
| | | */ |
| | | public boolean isExport() default true; |
| | | |
| | | /** |
| | | * å¦ä¸ä¸ªç±»ä¸çå±æ§å称,æ¯æå¤çº§è·å,以å°æ°ç¹éå¼ |
| | | */ |
| | | public String targetAttr() default ""; |
| | | |
| | | /** |
| | | * æ¯å¦èªå¨ç»è®¡æ°æ®,å¨æå追å ä¸è¡ç»è®¡æ°æ®æ»å |
| | | */ |
| | | public boolean isStatistics() default false; |
| | | |
| | | /** |
| | | * 导åºç±»åï¼0æ°å 1å符串 2å¾çï¼ |
| | | */ |
| | | public ColumnType cellType() default ColumnType.STRING; |
| | | |
| | | /** |
| | | * 导åºå头èæ¯é¢è² |
| | | */ |
| | | public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT; |
| | | |
| | | /** |
| | | * 导åºå头åä½é¢è² |
| | | */ |
| | | public IndexedColors headerColor() default IndexedColors.WHITE; |
| | | |
| | | /** |
| | | * 导åºåå
æ ¼èæ¯é¢è² |
| | | */ |
| | | public IndexedColors backgroundColor() default IndexedColors.WHITE; |
| | | |
| | | /** |
| | | * 导åºåå
æ ¼åä½é¢è² |
| | | */ |
| | | public IndexedColors color() default IndexedColors.BLACK; |
| | | |
| | | /** |
| | | * 导åºå段对é½æ¹å¼ |
| | | */ |
| | | public HorizontalAlignment align() default HorizontalAlignment.CENTER; |
| | | |
| | | /** |
| | | * èªå®ä¹æ°æ®å¤çå¨ |
| | | */ |
| | | public Class<?> handler() default ExcelHandlerAdapter.class; |
| | | |
| | | /** |
| | | * èªå®ä¹æ°æ®å¤çå¨åæ° |
| | | */ |
| | | public String[] args() default {}; |
| | | |
| | | /** |
| | | * å段类åï¼0ï¼å¯¼åºå¯¼å
¥ï¼1ï¼ä»
导åºï¼2ï¼ä»
导å
¥ï¼ |
| | | */ |
| | | Type type() default Type.ALL; |
| | | |
| | | public enum Type |
| | | { |
| | | ALL(0), EXPORT(1), IMPORT(2); |
| | | private final int value; |
| | | |
| | | Type(int value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int value() |
| | | { |
| | | return this.value; |
| | | } |
| | | } |
| | | |
| | | public enum ColumnType |
| | | { |
| | | NUMERIC(0), STRING(1), IMAGE(2); |
| | | private final int value; |
| | | |
| | | ColumnType(int value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int value() |
| | | { |
| | | return this.value; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * Excel注解é |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Target(ElementType.FIELD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | public @interface Excels |
| | | { |
| | | public Excel[] value(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | import com.jcdm.common.enums.BusinessType; |
| | | import com.jcdm.common.enums.OperatorType; |
| | | |
| | | /** |
| | | * èªå®ä¹æä½æ¥å¿è®°å½æ³¨è§£ |
| | | * |
| | | * @author jc |
| | | * |
| | | */ |
| | | @Target({ ElementType.PARAMETER, ElementType.METHOD }) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface Log |
| | | { |
| | | /** |
| | | * 模å |
| | | */ |
| | | public String title() default ""; |
| | | |
| | | /** |
| | | * åè½ |
| | | */ |
| | | public BusinessType businessType() default BusinessType.OTHER; |
| | | |
| | | /** |
| | | * æä½äººç±»å« |
| | | */ |
| | | public OperatorType operatorType() default OperatorType.MANAGE; |
| | | |
| | | /** |
| | | * æ¯å¦ä¿å请æ±çåæ° |
| | | */ |
| | | public boolean isSaveRequestData() default true; |
| | | |
| | | /** |
| | | * æ¯å¦ä¿åååºçåæ° |
| | | */ |
| | | public boolean isSaveResponseData() default true; |
| | | |
| | | /** |
| | | * æé¤æå®ç请æ±åæ° |
| | | */ |
| | | public String[] excludeParamNames() default {}; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | import com.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.enums.LimitType; |
| | | |
| | | /** |
| | | * éæµæ³¨è§£ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface RateLimiter |
| | | { |
| | | /** |
| | | * éæµkey |
| | | */ |
| | | public String key() default CacheConstants.RATE_LIMIT_KEY; |
| | | |
| | | /** |
| | | * éæµæ¶é´,åä½ç§ |
| | | */ |
| | | public int time() default 60; |
| | | |
| | | /** |
| | | * éæµæ¬¡æ° |
| | | */ |
| | | public int count() default 100; |
| | | |
| | | /** |
| | | * éæµç±»å |
| | | */ |
| | | public LimitType limitType() default LimitType.DEFAULT; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Inherited; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * èªå®ä¹æ³¨è§£é²æ¢è¡¨åéå¤æ交 |
| | | * |
| | | * @author jc |
| | | * |
| | | */ |
| | | @Inherited |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface RepeatSubmit |
| | | { |
| | | /** |
| | | * é´éæ¶é´(ms)ï¼å°äºæ¤æ¶é´è§ä¸ºéå¤æ交 |
| | | */ |
| | | public int interval() default 5000; |
| | | |
| | | /** |
| | | * æ示æ¶æ¯ |
| | | */ |
| | | public String message() default "ä¸å
许éå¤æ交ï¼è¯·ç¨ååè¯"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.config; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 读å项ç®ç¸å
³é
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | @ConfigurationProperties(prefix = "ruoyi") |
| | | public class MesConfig |
| | | { |
| | | /** 项ç®å称 */ |
| | | private String name; |
| | | |
| | | /** çæ¬ */ |
| | | private String version; |
| | | |
| | | /** çæ年份 */ |
| | | private String copyrightYear; |
| | | |
| | | /** å®ä¾æ¼ç¤ºå¼å
³ */ |
| | | private boolean demoEnabled; |
| | | |
| | | /** ä¸ä¼ è·¯å¾ */ |
| | | private static String profile; |
| | | |
| | | /** è·åå°åå¼å
³ */ |
| | | private static boolean addressEnabled; |
| | | |
| | | /** éªè¯ç ç±»å */ |
| | | private static String captchaType; |
| | | |
| | | public String getName() |
| | | { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) |
| | | { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getVersion() |
| | | { |
| | | return version; |
| | | } |
| | | |
| | | public void setVersion(String version) |
| | | { |
| | | this.version = version; |
| | | } |
| | | |
| | | public String getCopyrightYear() |
| | | { |
| | | return copyrightYear; |
| | | } |
| | | |
| | | public void setCopyrightYear(String copyrightYear) |
| | | { |
| | | this.copyrightYear = copyrightYear; |
| | | } |
| | | |
| | | public boolean isDemoEnabled() |
| | | { |
| | | return demoEnabled; |
| | | } |
| | | |
| | | public void setDemoEnabled(boolean demoEnabled) |
| | | { |
| | | this.demoEnabled = demoEnabled; |
| | | } |
| | | |
| | | public static String getProfile() |
| | | { |
| | | return profile; |
| | | } |
| | | |
| | | public void setProfile(String profile) |
| | | { |
| | | MesConfig.profile = profile; |
| | | } |
| | | |
| | | public static boolean isAddressEnabled() |
| | | { |
| | | return addressEnabled; |
| | | } |
| | | |
| | | public void setAddressEnabled(boolean addressEnabled) |
| | | { |
| | | MesConfig.addressEnabled = addressEnabled; |
| | | } |
| | | |
| | | public static String getCaptchaType() { |
| | | return captchaType; |
| | | } |
| | | |
| | | public void setCaptchaType(String captchaType) { |
| | | MesConfig.captchaType = captchaType; |
| | | } |
| | | |
| | | /** |
| | | * è·å导å
¥ä¸ä¼ è·¯å¾ |
| | | */ |
| | | public static String getImportPath() |
| | | { |
| | | return getProfile() + "/import"; |
| | | } |
| | | |
| | | /** |
| | | * è·å头åä¸ä¼ è·¯å¾ |
| | | */ |
| | | public static String getAvatarPath() |
| | | { |
| | | return getProfile() + "/avatar"; |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸è½½è·¯å¾ |
| | | */ |
| | | public static String getDownloadPath() |
| | | { |
| | | return getProfile() + "/download/"; |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸ä¼ è·¯å¾ |
| | | */ |
| | | public static String getUploadPath() |
| | | { |
| | | return getProfile() + "/upload"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | /** |
| | | * ç¼åçkey 常é |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class CacheConstants |
| | | { |
| | | /** |
| | | * ç»å½ç¨æ· redis key |
| | | */ |
| | | public static final String LOGIN_TOKEN_KEY = "login_tokens:"; |
| | | |
| | | /** |
| | | * éªè¯ç redis key |
| | | */ |
| | | public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; |
| | | |
| | | /** |
| | | * åæ°ç®¡ç cache key |
| | | */ |
| | | public static final String SYS_CONFIG_KEY = "sys_config:"; |
| | | |
| | | /** |
| | | * åå
¸ç®¡ç cache key |
| | | */ |
| | | public static final String SYS_DICT_KEY = "sys_dict:"; |
| | | |
| | | /** |
| | | * é²éæ交 redis key |
| | | */ |
| | | public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; |
| | | |
| | | /** |
| | | * éæµ redis key |
| | | */ |
| | | public static final String RATE_LIMIT_KEY = "rate_limit:"; |
| | | |
| | | /** |
| | | * ç»å½è´¦æ·å¯ç éè¯¯æ¬¡æ° redis key |
| | | */ |
| | | public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | import io.jsonwebtoken.Claims; |
| | | |
| | | /** |
| | | * éç¨å¸¸éä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class Constants |
| | | { |
| | | /** |
| | | * UTF-8 å符é |
| | | */ |
| | | public static final String UTF8 = "UTF-8"; |
| | | |
| | | /** |
| | | * GBK å符é |
| | | */ |
| | | public static final String GBK = "GBK"; |
| | | |
| | | /** |
| | | * www主å |
| | | */ |
| | | public static final String WWW = "www."; |
| | | |
| | | /** |
| | | * httpè¯·æ± |
| | | */ |
| | | public static final String HTTP = "http://"; |
| | | |
| | | /** |
| | | * httpsè¯·æ± |
| | | */ |
| | | public static final String HTTPS = "https://"; |
| | | |
| | | /** |
| | | * éç¨æåæ è¯ |
| | | */ |
| | | public static final String SUCCESS = "0"; |
| | | |
| | | /** |
| | | * éç¨å¤±è´¥æ è¯ |
| | | */ |
| | | public static final String FAIL = "1"; |
| | | |
| | | /** |
| | | * ç»å½æå |
| | | */ |
| | | public static final String LOGIN_SUCCESS = "Success"; |
| | | |
| | | /** |
| | | * 注é |
| | | */ |
| | | public static final String LOGOUT = "Logout"; |
| | | |
| | | /** |
| | | * 注å |
| | | */ |
| | | public static final String REGISTER = "Register"; |
| | | |
| | | /** |
| | | * ç»å½å¤±è´¥ |
| | | */ |
| | | public static final String LOGIN_FAIL = "Error"; |
| | | |
| | | /** |
| | | * æææéæ è¯ |
| | | */ |
| | | public static final String ALL_PERMISSION = "*:*:*"; |
| | | |
| | | /** |
| | | * 管çåè§è²æéæ è¯ |
| | | */ |
| | | public static final String SUPER_ADMIN = "admin"; |
| | | |
| | | /** |
| | | * è§è²æéåé符 |
| | | */ |
| | | public static final String ROLE_DELIMETER = ","; |
| | | |
| | | /** |
| | | * æéæ è¯åé符 |
| | | */ |
| | | public static final String PERMISSION_DELIMETER = ","; |
| | | |
| | | /** |
| | | * éªè¯ç æææï¼åéï¼ |
| | | */ |
| | | public static final Integer CAPTCHA_EXPIRATION = 2; |
| | | |
| | | /** |
| | | * 令ç |
| | | */ |
| | | public static final String TOKEN = "token"; |
| | | |
| | | /** |
| | | * 令çåç¼ |
| | | */ |
| | | public static final String TOKEN_PREFIX = "Bearer "; |
| | | |
| | | /** |
| | | * 令çåç¼ |
| | | */ |
| | | public static final String LOGIN_USER_KEY = "login_user_key"; |
| | | |
| | | /** |
| | | * ç¨æ·ID |
| | | */ |
| | | public static final String JWT_USERID = "userid"; |
| | | |
| | | /** |
| | | * ç¨æ·å称 |
| | | */ |
| | | public static final String JWT_USERNAME = Claims.SUBJECT; |
| | | |
| | | /** |
| | | * ç¨æ·å¤´å |
| | | */ |
| | | public static final String JWT_AVATAR = "avatar"; |
| | | |
| | | /** |
| | | * å建æ¶é´ |
| | | */ |
| | | public static final String JWT_CREATED = "created"; |
| | | |
| | | /** |
| | | * ç¨æ·æé |
| | | */ |
| | | public static final String JWT_AUTHORITIES = "authorities"; |
| | | |
| | | /** |
| | | * èµæºæ å°è·¯å¾ åç¼ |
| | | */ |
| | | public static final String RESOURCE_PREFIX = "/profile"; |
| | | |
| | | /** |
| | | * RMI è¿ç¨æ¹æ³è°ç¨ |
| | | */ |
| | | public static final String LOOKUP_RMI = "rmi:"; |
| | | |
| | | /** |
| | | * LDAP è¿ç¨æ¹æ³è°ç¨ |
| | | */ |
| | | public static final String LOOKUP_LDAP = "ldap:"; |
| | | |
| | | /** |
| | | * LDAPS è¿ç¨æ¹æ³è°ç¨ |
| | | */ |
| | | public static final String LOOKUP_LDAPS = "ldaps:"; |
| | | |
| | | /** |
| | | * èªå¨è¯å«json对象ç½ååé
ç½®ï¼ä»
å
许解æçå
åï¼èå´è¶å°è¶å®å
¨ï¼ |
| | | */ |
| | | public static final String[] JSON_WHITELIST_STR = { "org.springframework", "com.jcdm" }; |
| | | |
| | | /** |
| | | * å®æ¶ä»»å¡ç½ååé
ç½®ï¼ä»
å
许访é®çå
åï¼å¦å
¶ä»éè¦å¯ä»¥èªè¡æ·»å ï¼ |
| | | */ |
| | | public static final String[] JOB_WHITELIST_STR = { "com.jcdm" }; |
| | | |
| | | /** |
| | | * å®æ¶ä»»å¡è¿è§çå符 |
| | | */ |
| | | public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", |
| | | "org.springframework", "org.apache", "com.jcdm.common.utils.file", "com.jcdm.common.config" }; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | /** |
| | | * 代ç çæéç¨å¸¸é |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class GenConstants |
| | | { |
| | | /** å表ï¼å¢å æ¹æ¥ï¼ */ |
| | | public static final String TPL_CRUD = "crud"; |
| | | |
| | | /** æ 表ï¼å¢å æ¹æ¥ï¼ */ |
| | | public static final String TPL_TREE = "tree"; |
| | | |
| | | /** 主å表ï¼å¢å æ¹æ¥ï¼ */ |
| | | public static final String TPL_SUB = "sub"; |
| | | |
| | | /** æ ç¼ç å段 */ |
| | | public static final String TREE_CODE = "treeCode"; |
| | | |
| | | /** æ ç¶ç¼ç å段 */ |
| | | public static final String TREE_PARENT_CODE = "treeParentCode"; |
| | | |
| | | /** æ å称å段 */ |
| | | public static final String TREE_NAME = "treeName"; |
| | | |
| | | /** ä¸çº§èåIDå段 */ |
| | | public static final String PARENT_MENU_ID = "parentMenuId"; |
| | | |
| | | /** ä¸çº§èåå称å段 */ |
| | | public static final String PARENT_MENU_NAME = "parentMenuName"; |
| | | |
| | | /** æ°æ®åºå符串类å */ |
| | | public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; |
| | | |
| | | /** æ°æ®åºææ¬ç±»å */ |
| | | public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" }; |
| | | |
| | | /** æ°æ®åºæ¶é´ç±»å */ |
| | | public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; |
| | | |
| | | /** æ°æ®åºæ°åç±»å */ |
| | | public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer", |
| | | "bit", "bigint", "float", "double", "decimal" }; |
| | | |
| | | /** 页é¢ä¸éè¦ç¼è¾å段 */ |
| | | public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" }; |
| | | |
| | | /** 页é¢ä¸éè¦æ¾ç¤ºçå表å段 */ |
| | | public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", |
| | | "update_time" }; |
| | | |
| | | /** 页é¢ä¸éè¦æ¥è¯¢å段 */ |
| | | public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by", |
| | | "update_time", "remark" }; |
| | | |
| | | /** Entityåºç±»å段 */ |
| | | public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; |
| | | |
| | | /** Treeåºç±»å段 */ |
| | | public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" }; |
| | | |
| | | /** ææ¬æ¡ */ |
| | | public static final String HTML_INPUT = "input"; |
| | | |
| | | /** ææ¬å */ |
| | | public static final String HTML_TEXTAREA = "textarea"; |
| | | |
| | | /** ä¸ææ¡ */ |
| | | public static final String HTML_SELECT = "select"; |
| | | |
| | | /** åéæ¡ */ |
| | | public static final String HTML_RADIO = "radio"; |
| | | |
| | | /** å¤éæ¡ */ |
| | | public static final String HTML_CHECKBOX = "checkbox"; |
| | | |
| | | /** æ¥ææ§ä»¶ */ |
| | | public static final String HTML_DATETIME = "datetime"; |
| | | |
| | | /** å¾çä¸ä¼ æ§ä»¶ */ |
| | | public static final String HTML_IMAGE_UPLOAD = "imageUpload"; |
| | | |
| | | /** æ件ä¸ä¼ æ§ä»¶ */ |
| | | public static final String HTML_FILE_UPLOAD = "fileUpload"; |
| | | |
| | | /** å¯ææ¬æ§ä»¶ */ |
| | | public static final String HTML_EDITOR = "editor"; |
| | | |
| | | /** å符串类å */ |
| | | public static final String TYPE_STRING = "String"; |
| | | |
| | | /** æ´å */ |
| | | public static final String TYPE_INTEGER = "Integer"; |
| | | |
| | | /** é¿æ´å */ |
| | | public static final String TYPE_LONG = "Long"; |
| | | |
| | | /** æµ®ç¹å */ |
| | | public static final String TYPE_DOUBLE = "Double"; |
| | | |
| | | /** é«ç²¾åº¦è®¡ç®ç±»å */ |
| | | public static final String TYPE_BIGDECIMAL = "BigDecimal"; |
| | | |
| | | /** æ¶é´ç±»å */ |
| | | public static final String TYPE_DATE = "Date"; |
| | | |
| | | /** 模ç³æ¥è¯¢ */ |
| | | public static final String QUERY_LIKE = "LIKE"; |
| | | |
| | | /** ç¸çæ¥è¯¢ */ |
| | | public static final String QUERY_EQ = "EQ"; |
| | | |
| | | /** éè¦ */ |
| | | public static final String REQUIRE = "1"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | /** |
| | | * è¿åç¶æç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class HttpStatus |
| | | { |
| | | /** |
| | | * æä½æå |
| | | */ |
| | | public static final int SUCCESS = 200; |
| | | |
| | | /** |
| | | * 对象å建æå |
| | | */ |
| | | public static final int CREATED = 201; |
| | | |
| | | /** |
| | | * 请æ±å·²ç»è¢«æ¥å |
| | | */ |
| | | public static final int ACCEPTED = 202; |
| | | |
| | | /** |
| | | * æä½å·²ç»æ§è¡æåï¼ä½æ¯æ²¡æè¿åæ°æ® |
| | | */ |
| | | public static final int NO_CONTENT = 204; |
| | | |
| | | /** |
| | | * èµæºå·²è¢«ç§»é¤ |
| | | */ |
| | | public static final int MOVED_PERM = 301; |
| | | |
| | | /** |
| | | * éå®å |
| | | */ |
| | | public static final int SEE_OTHER = 303; |
| | | |
| | | /** |
| | | * èµæºæ²¡æè¢«ä¿®æ¹ |
| | | */ |
| | | public static final int NOT_MODIFIED = 304; |
| | | |
| | | /** |
| | | * åæ°å表é误ï¼ç¼ºå°ï¼æ ¼å¼ä¸å¹é
ï¼ |
| | | */ |
| | | public static final int BAD_REQUEST = 400; |
| | | |
| | | /** |
| | | * æªææ |
| | | */ |
| | | public static final int UNAUTHORIZED = 401; |
| | | |
| | | /** |
| | | * 访é®åéï¼ææè¿æ |
| | | */ |
| | | public static final int FORBIDDEN = 403; |
| | | |
| | | /** |
| | | * èµæºï¼æå¡æªæ¾å° |
| | | */ |
| | | public static final int NOT_FOUND = 404; |
| | | |
| | | /** |
| | | * ä¸å
许çhttpæ¹æ³ |
| | | */ |
| | | public static final int BAD_METHOD = 405; |
| | | |
| | | /** |
| | | * èµæºå²çªï¼æè
èµæºè¢«é |
| | | */ |
| | | public static final int CONFLICT = 409; |
| | | |
| | | /** |
| | | * ä¸æ¯æçæ°æ®ï¼åªä½ç±»å |
| | | */ |
| | | public static final int UNSUPPORTED_TYPE = 415; |
| | | |
| | | /** |
| | | * ç³»ç»å
é¨é误 |
| | | */ |
| | | public static final int ERROR = 500; |
| | | |
| | | /** |
| | | * æ¥å£æªå®ç° |
| | | */ |
| | | public static final int NOT_IMPLEMENTED = 501; |
| | | |
| | | /** |
| | | * ç³»ç»è¦åæ¶æ¯ |
| | | */ |
| | | public static final int WARN = 601; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | /** |
| | | * ä»»å¡è°åº¦éç¨å¸¸é |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class ScheduleConstants |
| | | { |
| | | public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; |
| | | |
| | | /** æ§è¡ç®æ key */ |
| | | public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; |
| | | |
| | | /** é»è®¤ */ |
| | | public static final String MISFIRE_DEFAULT = "0"; |
| | | |
| | | /** ç«å³è§¦åæ§è¡ */ |
| | | public static final String MISFIRE_IGNORE_MISFIRES = "1"; |
| | | |
| | | /** 触åä¸æ¬¡æ§è¡ */ |
| | | public static final String MISFIRE_FIRE_AND_PROCEED = "2"; |
| | | |
| | | /** ä¸è§¦åç«å³æ§è¡ */ |
| | | public static final String MISFIRE_DO_NOTHING = "3"; |
| | | |
| | | public enum Status |
| | | { |
| | | /** |
| | | * æ£å¸¸ |
| | | */ |
| | | NORMAL("0"), |
| | | /** |
| | | * æå |
| | | */ |
| | | PAUSE("1"); |
| | | |
| | | private String value; |
| | | |
| | | private Status(String value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public String getValue() |
| | | { |
| | | return value; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.constant; |
| | | |
| | | /** |
| | | * ç¨æ·å¸¸éä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UserConstants |
| | | { |
| | | /** |
| | | * å¹³å°å
ç³»ç»ç¨æ·çå¯ä¸æ å¿ |
| | | */ |
| | | public static final String SYS_USER = "SYS_USER"; |
| | | |
| | | /** æ£å¸¸ç¶æ */ |
| | | public static final String NORMAL = "0"; |
| | | |
| | | /** å¼å¸¸ç¶æ */ |
| | | public static final String EXCEPTION = "1"; |
| | | |
| | | /** ç¨æ·å°ç¦ç¶æ */ |
| | | public static final String USER_DISABLE = "1"; |
| | | |
| | | /** è§è²å°ç¦ç¶æ */ |
| | | public static final String ROLE_DISABLE = "1"; |
| | | |
| | | /** é¨é¨æ£å¸¸ç¶æ */ |
| | | public static final String DEPT_NORMAL = "0"; |
| | | |
| | | /** é¨é¨åç¨ç¶æ */ |
| | | public static final String DEPT_DISABLE = "1"; |
| | | |
| | | /** åå
¸æ£å¸¸ç¶æ */ |
| | | public static final String DICT_NORMAL = "0"; |
| | | |
| | | /** æ¯å¦ä¸ºç³»ç»é»è®¤ï¼æ¯ï¼ */ |
| | | public static final String YES = "Y"; |
| | | |
| | | /** æ¯å¦èåå¤é¾ï¼æ¯ï¼ */ |
| | | public static final String YES_FRAME = "0"; |
| | | |
| | | /** æ¯å¦èåå¤é¾ï¼å¦ï¼ */ |
| | | public static final String NO_FRAME = "1"; |
| | | |
| | | /** èåç±»åï¼ç®å½ï¼ */ |
| | | public static final String TYPE_DIR = "M"; |
| | | |
| | | /** èåç±»åï¼èåï¼ */ |
| | | public static final String TYPE_MENU = "C"; |
| | | |
| | | /** èåç±»åï¼æé®ï¼ */ |
| | | public static final String TYPE_BUTTON = "F"; |
| | | |
| | | /** Layoutç»ä»¶æ è¯ */ |
| | | public final static String LAYOUT = "Layout"; |
| | | |
| | | /** ParentViewç»ä»¶æ è¯ */ |
| | | public final static String PARENT_VIEW = "ParentView"; |
| | | |
| | | /** InnerLinkç»ä»¶æ è¯ */ |
| | | public final static String INNER_LINK = "InnerLink"; |
| | | |
| | | /** æ ¡éªæ¯å¦å¯ä¸çè¿åæ è¯ */ |
| | | public final static boolean UNIQUE = true; |
| | | public final static boolean NOT_UNIQUE = false; |
| | | |
| | | /** |
| | | * ç¨æ·åé¿åº¦éå¶ |
| | | */ |
| | | public static final int USERNAME_MIN_LENGTH = 2; |
| | | public static final int USERNAME_MAX_LENGTH = 20; |
| | | |
| | | /** |
| | | * å¯ç é¿åº¦éå¶ |
| | | */ |
| | | public static final int PASSWORD_MIN_LENGTH = 5; |
| | | public static final int PASSWORD_MAX_LENGTH = 20; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.controller; |
| | | |
| | | import java.beans.PropertyEditorSupport; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.web.bind.annotation.InitBinder; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.jcdm.common.constant.HttpStatus; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.core.page.PageDomain; |
| | | import com.jcdm.common.core.page.TableDataInfo; |
| | | import com.jcdm.common.core.page.TableSupport; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | import com.jcdm.common.utils.PageUtils; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.sql.SqlUtil; |
| | | |
| | | /** |
| | | * webå±éç¨æ°æ®å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BaseController |
| | | { |
| | | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| | | |
| | | /** |
| | | * å°åå°ä¼ éè¿æ¥çæ¥ææ ¼å¼çå符串ï¼èªå¨è½¬å为Dateç±»å |
| | | */ |
| | | @InitBinder |
| | | public void initBinder(WebDataBinder binder) |
| | | { |
| | | // Date ç±»åè½¬æ¢ |
| | | binder.registerCustomEditor(Date.class, new PropertyEditorSupport() |
| | | { |
| | | @Override |
| | | public void setAsText(String text) |
| | | { |
| | | setValue(DateUtils.parseDate(text)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 设置请æ±å页æ°æ® |
| | | */ |
| | | protected void startPage() |
| | | { |
| | | PageUtils.startPage(); |
| | | } |
| | | |
| | | /** |
| | | * 设置请æ±æåºæ°æ® |
| | | */ |
| | | protected void startOrderBy() |
| | | { |
| | | PageDomain pageDomain = TableSupport.buildPageRequest(); |
| | | if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) |
| | | { |
| | | String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); |
| | | PageHelper.orderBy(orderBy); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¸
çå页ç线ç¨åé |
| | | */ |
| | | protected void clearPage() |
| | | { |
| | | PageUtils.clearPage(); |
| | | } |
| | | |
| | | /** |
| | | * ååºè¯·æ±å页æ°æ® |
| | | */ |
| | | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| | | protected TableDataInfo getDataTable(List<?> list) |
| | | { |
| | | TableDataInfo rspData = new TableDataInfo(); |
| | | rspData.setCode(HttpStatus.SUCCESS); |
| | | rspData.setMsg("æ¥è¯¢æå"); |
| | | rspData.setRows(list); |
| | | rspData.setTotal(new PageInfo(list).getTotal()); |
| | | return rspData; |
| | | } |
| | | |
| | | /** |
| | | * è¿åæå |
| | | */ |
| | | public AjaxResult success() |
| | | { |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * è¿å失败æ¶æ¯ |
| | | */ |
| | | public AjaxResult error() |
| | | { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ¶æ¯ |
| | | */ |
| | | public AjaxResult success(String message) |
| | | { |
| | | return AjaxResult.success(message); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ¶æ¯ |
| | | */ |
| | | public AjaxResult success(Object data) |
| | | { |
| | | return AjaxResult.success(data); |
| | | } |
| | | |
| | | /** |
| | | * è¿å失败æ¶æ¯ |
| | | */ |
| | | public AjaxResult error(String message) |
| | | { |
| | | return AjaxResult.error(message); |
| | | } |
| | | |
| | | /** |
| | | * è¿åè¦åæ¶æ¯ |
| | | */ |
| | | public AjaxResult warn(String message) |
| | | { |
| | | return AjaxResult.warn(message); |
| | | } |
| | | |
| | | /** |
| | | * ååºè¿åç»æ |
| | | * |
| | | * @param rows å½±åè¡æ° |
| | | * @return æä½ç»æ |
| | | */ |
| | | protected AjaxResult toAjax(int rows) |
| | | { |
| | | return rows > 0 ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | /** |
| | | * ååºè¿åç»æ |
| | | * |
| | | * @param result ç»æ |
| | | * @return æä½ç»æ |
| | | */ |
| | | protected AjaxResult toAjax(boolean result) |
| | | { |
| | | return result ? success() : error(); |
| | | } |
| | | |
| | | /** |
| | | * 页é¢è·³è½¬ |
| | | */ |
| | | public String redirect(String url) |
| | | { |
| | | return StringUtils.format("redirect:{}", url); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·ç¼åä¿¡æ¯ |
| | | */ |
| | | public LoginUser getLoginUser() |
| | | { |
| | | return SecurityUtils.getLoginUser(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½ç¨æ·id |
| | | */ |
| | | public Long getUserId() |
| | | { |
| | | return getLoginUser().getUserId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½é¨é¨id |
| | | */ |
| | | public Long getDeptId() |
| | | { |
| | | return getLoginUser().getDeptId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½ç¨æ·å |
| | | */ |
| | | public String getUsername() |
| | | { |
| | | return getLoginUser().getUsername(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Objects; |
| | | import com.jcdm.common.constant.HttpStatus; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * æä½æ¶æ¯æé |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class AjaxResult extends HashMap<String, Object> |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ç¶æç */ |
| | | public static final String CODE_TAG = "code"; |
| | | |
| | | /** è¿åå
容 */ |
| | | public static final String MSG_TAG = "msg"; |
| | | |
| | | /** æ°æ®å¯¹è±¡ */ |
| | | public static final String DATA_TAG = "data"; |
| | | |
| | | /** |
| | | * åå§åä¸ä¸ªæ°å建ç AjaxResult 对象ï¼ä½¿å
¶è¡¨ç¤ºä¸ä¸ªç©ºæ¶æ¯ã |
| | | */ |
| | | public AjaxResult() |
| | | { |
| | | } |
| | | |
| | | /** |
| | | * åå§åä¸ä¸ªæ°å建ç AjaxResult 对象 |
| | | * |
| | | * @param code ç¶æç |
| | | * @param msg è¿åå
容 |
| | | */ |
| | | public AjaxResult(int code, String msg) |
| | | { |
| | | super.put(CODE_TAG, code); |
| | | super.put(MSG_TAG, msg); |
| | | } |
| | | |
| | | /** |
| | | * åå§åä¸ä¸ªæ°å建ç AjaxResult 对象 |
| | | * |
| | | * @param code ç¶æç |
| | | * @param msg è¿åå
容 |
| | | * @param data æ°æ®å¯¹è±¡ |
| | | */ |
| | | public AjaxResult(int code, String msg, Object data) |
| | | { |
| | | super.put(CODE_TAG, code); |
| | | super.put(MSG_TAG, msg); |
| | | if (StringUtils.isNotNull(data)) |
| | | { |
| | | super.put(DATA_TAG, data); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ¶æ¯ |
| | | * |
| | | * @return æåæ¶æ¯ |
| | | */ |
| | | public static AjaxResult success() |
| | | { |
| | | return AjaxResult.success("æä½æå"); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ°æ® |
| | | * |
| | | * @return æåæ¶æ¯ |
| | | */ |
| | | public static AjaxResult success(Object data) |
| | | { |
| | | return AjaxResult.success("æä½æå", data); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @return æåæ¶æ¯ |
| | | */ |
| | | public static AjaxResult success(String msg) |
| | | { |
| | | return AjaxResult.success(msg, null); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæåæ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @param data æ°æ®å¯¹è±¡ |
| | | * @return æåæ¶æ¯ |
| | | */ |
| | | public static AjaxResult success(String msg, Object data) |
| | | { |
| | | return new AjaxResult(HttpStatus.SUCCESS, msg, data); |
| | | } |
| | | |
| | | /** |
| | | * è¿åè¦åæ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @return è¦åæ¶æ¯ |
| | | */ |
| | | public static AjaxResult warn(String msg) |
| | | { |
| | | return AjaxResult.warn(msg, null); |
| | | } |
| | | |
| | | /** |
| | | * è¿åè¦åæ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @param data æ°æ®å¯¹è±¡ |
| | | * @return è¦åæ¶æ¯ |
| | | */ |
| | | public static AjaxResult warn(String msg, Object data) |
| | | { |
| | | return new AjaxResult(HttpStatus.WARN, msg, data); |
| | | } |
| | | |
| | | /** |
| | | * è¿åé误æ¶æ¯ |
| | | * |
| | | * @return é误æ¶æ¯ |
| | | */ |
| | | public static AjaxResult error() |
| | | { |
| | | return AjaxResult.error("æä½å¤±è´¥"); |
| | | } |
| | | |
| | | /** |
| | | * è¿åé误æ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @return é误æ¶æ¯ |
| | | */ |
| | | public static AjaxResult error(String msg) |
| | | { |
| | | return AjaxResult.error(msg, null); |
| | | } |
| | | |
| | | /** |
| | | * è¿åé误æ¶æ¯ |
| | | * |
| | | * @param msg è¿åå
容 |
| | | * @param data æ°æ®å¯¹è±¡ |
| | | * @return é误æ¶æ¯ |
| | | */ |
| | | public static AjaxResult error(String msg, Object data) |
| | | { |
| | | return new AjaxResult(HttpStatus.ERROR, msg, data); |
| | | } |
| | | |
| | | /** |
| | | * è¿åé误æ¶æ¯ |
| | | * |
| | | * @param code ç¶æç |
| | | * @param msg è¿åå
容 |
| | | * @return é误æ¶æ¯ |
| | | */ |
| | | public static AjaxResult error(int code, String msg) |
| | | { |
| | | return new AjaxResult(code, msg, null); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºæåæ¶æ¯ |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isSuccess() |
| | | { |
| | | return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG)); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºè¦åæ¶æ¯ |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isWarn() |
| | | { |
| | | return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG)); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºé误æ¶æ¯ |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isError() |
| | | { |
| | | return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹ä¾¿é¾å¼è°ç¨ |
| | | * |
| | | * @param key é® |
| | | * @param value å¼ |
| | | * @return æ°æ®å¯¹è±¡ |
| | | */ |
| | | @Override |
| | | public AjaxResult put(String key, Object value) |
| | | { |
| | | super.put(key, value); |
| | | return this; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | |
| | | /** |
| | | * Entityåºç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BaseEntity implements Serializable |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** æç´¢å¼ */ |
| | | @JsonIgnore |
| | | private String searchValue; |
| | | |
| | | /** å建è
*/ |
| | | private String createBy; |
| | | |
| | | /** å建æ¶é´ */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | /** æ´æ°è
*/ |
| | | private String updateBy; |
| | | |
| | | /** æ´æ°æ¶é´ */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date updateTime; |
| | | |
| | | /** å¤æ³¨ */ |
| | | private String remark; |
| | | |
| | | /** 请æ±åæ° */ |
| | | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| | | private Map<String, Object> params; |
| | | |
| | | public String getSearchValue() |
| | | { |
| | | return searchValue; |
| | | } |
| | | |
| | | public void setSearchValue(String searchValue) |
| | | { |
| | | this.searchValue = searchValue; |
| | | } |
| | | |
| | | public String getCreateBy() |
| | | { |
| | | return createBy; |
| | | } |
| | | |
| | | public void setCreateBy(String createBy) |
| | | { |
| | | this.createBy = createBy; |
| | | } |
| | | |
| | | public Date getCreateTime() |
| | | { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) |
| | | { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public String getUpdateBy() |
| | | { |
| | | return updateBy; |
| | | } |
| | | |
| | | public void setUpdateBy(String updateBy) |
| | | { |
| | | this.updateBy = updateBy; |
| | | } |
| | | |
| | | public Date getUpdateTime() |
| | | { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Date updateTime) |
| | | { |
| | | this.updateTime = updateTime; |
| | | } |
| | | |
| | | public String getRemark() |
| | | { |
| | | return remark; |
| | | } |
| | | |
| | | public void setRemark(String remark) |
| | | { |
| | | this.remark = remark; |
| | | } |
| | | |
| | | public Map<String, Object> getParams() |
| | | { |
| | | if (params == null) |
| | | { |
| | | params = new HashMap<>(); |
| | | } |
| | | return params; |
| | | } |
| | | |
| | | public void setParams(Map<String, Object> params) |
| | | { |
| | | this.params = params; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain; |
| | | |
| | | import java.io.Serializable; |
| | | import com.jcdm.common.constant.HttpStatus; |
| | | |
| | | /** |
| | | * ååºä¿¡æ¯ä¸»ä½ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class R<T> implements Serializable |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** æå */ |
| | | public static final int SUCCESS = HttpStatus.SUCCESS; |
| | | |
| | | /** 失败 */ |
| | | public static final int FAIL = HttpStatus.ERROR; |
| | | |
| | | private int code; |
| | | |
| | | private String msg; |
| | | |
| | | private T data; |
| | | |
| | | public static <T> R<T> ok() |
| | | { |
| | | return restResult(null, SUCCESS, "æä½æå"); |
| | | } |
| | | |
| | | public static <T> R<T> ok(T data) |
| | | { |
| | | return restResult(data, SUCCESS, "æä½æå"); |
| | | } |
| | | |
| | | public static <T> R<T> ok(T data, String msg) |
| | | { |
| | | return restResult(data, SUCCESS, msg); |
| | | } |
| | | |
| | | public static <T> R<T> fail() |
| | | { |
| | | return restResult(null, FAIL, "æä½å¤±è´¥"); |
| | | } |
| | | |
| | | public static <T> R<T> fail(String msg) |
| | | { |
| | | return restResult(null, FAIL, msg); |
| | | } |
| | | |
| | | public static <T> R<T> fail(T data) |
| | | { |
| | | return restResult(data, FAIL, "æä½å¤±è´¥"); |
| | | } |
| | | |
| | | public static <T> R<T> fail(T data, String msg) |
| | | { |
| | | return restResult(data, FAIL, msg); |
| | | } |
| | | |
| | | public static <T> R<T> fail(int code, String msg) |
| | | { |
| | | return restResult(null, code, msg); |
| | | } |
| | | |
| | | private static <T> R<T> restResult(T data, int code, String msg) |
| | | { |
| | | R<T> apiResult = new R<>(); |
| | | apiResult.setCode(code); |
| | | apiResult.setData(data); |
| | | apiResult.setMsg(msg); |
| | | return apiResult; |
| | | } |
| | | |
| | | public int getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(int code) |
| | | { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() |
| | | { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) |
| | | { |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public T getData() |
| | | { |
| | | return data; |
| | | } |
| | | |
| | | public void setData(T data) |
| | | { |
| | | this.data = data; |
| | | } |
| | | |
| | | public static <T> Boolean isError(R<T> ret) |
| | | { |
| | | return !isSuccess(ret); |
| | | } |
| | | |
| | | public static <T> Boolean isSuccess(R<T> ret) |
| | | { |
| | | return R.SUCCESS == ret.getCode(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Treeåºç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class TreeEntity extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ç¶èåå称 */ |
| | | private String parentName; |
| | | |
| | | /** ç¶èåID */ |
| | | private Long parentId; |
| | | |
| | | /** æ¾ç¤ºé¡ºåº */ |
| | | private Integer orderNum; |
| | | |
| | | /** ç¥çº§å表 */ |
| | | private String ancestors; |
| | | |
| | | /** åé¨é¨ */ |
| | | private List<?> children = new ArrayList<>(); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public Integer getOrderNum() |
| | | { |
| | | return orderNum; |
| | | } |
| | | |
| | | public void setOrderNum(Integer orderNum) |
| | | { |
| | | this.orderNum = orderNum; |
| | | } |
| | | |
| | | public String getAncestors() |
| | | { |
| | | return ancestors; |
| | | } |
| | | |
| | | public void setAncestors(String ancestors) |
| | | { |
| | | this.ancestors = ancestors; |
| | | } |
| | | |
| | | public List<?> getChildren() |
| | | { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<?> children) |
| | | { |
| | | this.children = children; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | import com.jcdm.common.core.domain.entity.SysDept; |
| | | import com.jcdm.common.core.domain.entity.SysMenu; |
| | | |
| | | /** |
| | | * Treeselectæ ç»æå®ä½ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | 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.jcdm.common.core.domain.entity; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.validation.constraints.Email; |
| | | 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.jcdm.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * é¨é¨è¡¨ sys_dept |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SysDept extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** é¨é¨ID */ |
| | | private Long deptId; |
| | | |
| | | /** ç¶é¨é¨ID */ |
| | | private Long parentId; |
| | | |
| | | /** ç¥çº§å表 */ |
| | | private String ancestors; |
| | | |
| | | /** é¨é¨å称 */ |
| | | private String deptName; |
| | | |
| | | /** æ¾ç¤ºé¡ºåº */ |
| | | private Integer orderNum; |
| | | |
| | | /** è´è´£äºº */ |
| | | private String leader; |
| | | |
| | | /** èç³»çµè¯ */ |
| | | private String phone; |
| | | |
| | | /** é®ç®± */ |
| | | private String email; |
| | | |
| | | /** é¨é¨ç¶æ:0æ£å¸¸,1åç¨ */ |
| | | private String status; |
| | | |
| | | /** å é¤æ å¿ï¼0代表åå¨ 2代表å é¤ï¼ */ |
| | | private String delFlag; |
| | | |
| | | /** ç¶é¨é¨å称 */ |
| | | private String parentName; |
| | | |
| | | /** åé¨é¨ */ |
| | | private List<SysDept> children = new ArrayList<SysDept>(); |
| | | |
| | | public Long getDeptId() |
| | | { |
| | | return deptId; |
| | | } |
| | | |
| | | public void setDeptId(Long deptId) |
| | | { |
| | | this.deptId = deptId; |
| | | } |
| | | |
| | | public Long getParentId() |
| | | { |
| | | return parentId; |
| | | } |
| | | |
| | | public void setParentId(Long parentId) |
| | | { |
| | | this.parentId = parentId; |
| | | } |
| | | |
| | | public String getAncestors() |
| | | { |
| | | return ancestors; |
| | | } |
| | | |
| | | public void setAncestors(String ancestors) |
| | | { |
| | | this.ancestors = ancestors; |
| | | } |
| | | |
| | | @NotBlank(message = "é¨é¨å称ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 30, message = "é¨é¨å称é¿åº¦ä¸è½è¶
è¿30个å符") |
| | | public String getDeptName() |
| | | { |
| | | return deptName; |
| | | } |
| | | |
| | | public void setDeptName(String deptName) |
| | | { |
| | | this.deptName = deptName; |
| | | } |
| | | |
| | | @NotNull(message = "æ¾ç¤ºé¡ºåºä¸è½ä¸ºç©º") |
| | | public Integer getOrderNum() |
| | | { |
| | | return orderNum; |
| | | } |
| | | |
| | | public void setOrderNum(Integer orderNum) |
| | | { |
| | | this.orderNum = orderNum; |
| | | } |
| | | |
| | | public String getLeader() |
| | | { |
| | | return leader; |
| | | } |
| | | |
| | | public void setLeader(String leader) |
| | | { |
| | | this.leader = leader; |
| | | } |
| | | |
| | | @Size(min = 0, max = 11, message = "èç³»çµè¯é¿åº¦ä¸è½è¶
è¿11个å符") |
| | | public String getPhone() |
| | | { |
| | | return phone; |
| | | } |
| | | |
| | | public void setPhone(String phone) |
| | | { |
| | | this.phone = phone; |
| | | } |
| | | |
| | | @Email(message = "é®ç®±æ ¼å¼ä¸æ£ç¡®") |
| | | @Size(min = 0, max = 50, message = "é®ç®±é¿åº¦ä¸è½è¶
è¿50个å符") |
| | | public String getEmail() |
| | | { |
| | | return email; |
| | | } |
| | | |
| | | public void setEmail(String email) |
| | | { |
| | | this.email = email; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getDelFlag() |
| | | { |
| | | return delFlag; |
| | | } |
| | | |
| | | public void setDelFlag(String delFlag) |
| | | { |
| | | this.delFlag = delFlag; |
| | | } |
| | | |
| | | public String getParentName() |
| | | { |
| | | return parentName; |
| | | } |
| | | |
| | | public void setParentName(String parentName) |
| | | { |
| | | this.parentName = parentName; |
| | | } |
| | | |
| | | public List<SysDept> getChildren() |
| | | { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<SysDept> children) |
| | | { |
| | | this.children = children; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("deptId", getDeptId()) |
| | | .append("parentId", getParentId()) |
| | | .append("ancestors", getAncestors()) |
| | | .append("deptName", getDeptName()) |
| | | .append("orderNum", getOrderNum()) |
| | | .append("leader", getLeader()) |
| | | .append("phone", getPhone()) |
| | | .append("email", getEmail()) |
| | | .append("status", getStatus()) |
| | | .append("delFlag", getDelFlag()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.entity; |
| | | |
| | | 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.jcdm.common.annotation.Excel; |
| | | import com.jcdm.common.annotation.Excel.ColumnType; |
| | | import com.jcdm.common.constant.UserConstants; |
| | | import com.jcdm.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * åå
¸æ°æ®è¡¨ sys_dict_data |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SysDictData extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** åå
¸ç¼ç */ |
| | | @Excel(name = "åå
¸ç¼ç ", cellType = ColumnType.NUMERIC) |
| | | private Long dictCode; |
| | | |
| | | /** åå
¸æåº */ |
| | | @Excel(name = "åå
¸æåº", cellType = ColumnType.NUMERIC) |
| | | private Long dictSort; |
| | | |
| | | /** åå
¸æ ç¾ */ |
| | | @Excel(name = "åå
¸æ ç¾") |
| | | private String dictLabel; |
| | | |
| | | /** åå
¸é®å¼ */ |
| | | @Excel(name = "åå
¸é®å¼") |
| | | private String dictValue; |
| | | |
| | | /** åå
¸ç±»å */ |
| | | @Excel(name = "åå
¸ç±»å") |
| | | private String dictType; |
| | | |
| | | /** æ ·å¼å±æ§ï¼å
¶ä»æ ·å¼æ©å±ï¼ */ |
| | | private String cssClass; |
| | | |
| | | /** è¡¨æ ¼åå
¸æ ·å¼ */ |
| | | private String listClass; |
| | | |
| | | /** æ¯å¦é»è®¤ï¼Yæ¯ Nå¦ï¼ */ |
| | | @Excel(name = "æ¯å¦é»è®¤", readConverterExp = "Y=æ¯,N=å¦") |
| | | private String isDefault; |
| | | |
| | | /** ç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | @Excel(name = "ç¶æ", readConverterExp = "0=æ£å¸¸,1=åç¨") |
| | | private String status; |
| | | |
| | | public Long getDictCode() |
| | | { |
| | | return dictCode; |
| | | } |
| | | |
| | | public void setDictCode(Long dictCode) |
| | | { |
| | | this.dictCode = dictCode; |
| | | } |
| | | |
| | | public Long getDictSort() |
| | | { |
| | | return dictSort; |
| | | } |
| | | |
| | | public void setDictSort(Long dictSort) |
| | | { |
| | | this.dictSort = dictSort; |
| | | } |
| | | |
| | | @NotBlank(message = "åå
¸æ ç¾ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åå
¸æ ç¾é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getDictLabel() |
| | | { |
| | | return dictLabel; |
| | | } |
| | | |
| | | public void setDictLabel(String dictLabel) |
| | | { |
| | | this.dictLabel = dictLabel; |
| | | } |
| | | |
| | | @NotBlank(message = "åå
¸é®å¼ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åå
¸é®å¼é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getDictValue() |
| | | { |
| | | return dictValue; |
| | | } |
| | | |
| | | public void setDictValue(String dictValue) |
| | | { |
| | | this.dictValue = dictValue; |
| | | } |
| | | |
| | | @NotBlank(message = "åå
¸ç±»åä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åå
¸ç±»åé¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getDictType() |
| | | { |
| | | return dictType; |
| | | } |
| | | |
| | | public void setDictType(String dictType) |
| | | { |
| | | this.dictType = dictType; |
| | | } |
| | | |
| | | @Size(min = 0, max = 100, message = "æ ·å¼å±æ§é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getCssClass() |
| | | { |
| | | return cssClass; |
| | | } |
| | | |
| | | public void setCssClass(String cssClass) |
| | | { |
| | | this.cssClass = cssClass; |
| | | } |
| | | |
| | | public String getListClass() |
| | | { |
| | | return listClass; |
| | | } |
| | | |
| | | public void setListClass(String listClass) |
| | | { |
| | | this.listClass = listClass; |
| | | } |
| | | |
| | | public boolean getDefault() |
| | | { |
| | | return UserConstants.YES.equals(this.isDefault); |
| | | } |
| | | |
| | | public String getIsDefault() |
| | | { |
| | | return isDefault; |
| | | } |
| | | |
| | | public void setIsDefault(String isDefault) |
| | | { |
| | | this.isDefault = isDefault; |
| | | } |
| | | |
| | | 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("dictCode", getDictCode()) |
| | | .append("dictSort", getDictSort()) |
| | | .append("dictLabel", getDictLabel()) |
| | | .append("dictValue", getDictValue()) |
| | | .append("dictType", getDictType()) |
| | | .append("cssClass", getCssClass()) |
| | | .append("listClass", getListClass()) |
| | | .append("isDefault", getIsDefault()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.entity; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.Pattern; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.jcdm.common.annotation.Excel; |
| | | import com.jcdm.common.annotation.Excel.ColumnType; |
| | | import com.jcdm.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * åå
¸ç±»å表 sys_dict_type |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SysDictType extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** åå
¸ä¸»é® */ |
| | | @Excel(name = "åå
¸ä¸»é®", cellType = ColumnType.NUMERIC) |
| | | private Long dictId; |
| | | |
| | | /** åå
¸å称 */ |
| | | @Excel(name = "åå
¸å称") |
| | | private String dictName; |
| | | |
| | | /** åå
¸ç±»å */ |
| | | @Excel(name = "åå
¸ç±»å") |
| | | private String dictType; |
| | | |
| | | /** ç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | @Excel(name = "ç¶æ", readConverterExp = "0=æ£å¸¸,1=åç¨") |
| | | private String status; |
| | | |
| | | public Long getDictId() |
| | | { |
| | | return dictId; |
| | | } |
| | | |
| | | public void setDictId(Long dictId) |
| | | { |
| | | this.dictId = dictId; |
| | | } |
| | | |
| | | @NotBlank(message = "åå
¸å称ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åå
¸ç±»åå称é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getDictName() |
| | | { |
| | | return dictName; |
| | | } |
| | | |
| | | public void setDictName(String dictName) |
| | | { |
| | | this.dictName = dictName; |
| | | } |
| | | |
| | | @NotBlank(message = "åå
¸ç±»åä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "åå
¸ç±»åç±»åé¿åº¦ä¸è½è¶
è¿100个å符") |
| | | @Pattern(regexp = "^[a-z][a-z0-9_]*$", message = "åå
¸ç±»åå¿
须以åæ¯å¼å¤´ï¼ä¸åªè½ä¸ºï¼å°ååæ¯ï¼æ°åï¼ä¸æ»çº¿ï¼") |
| | | public String getDictType() |
| | | { |
| | | return dictType; |
| | | } |
| | | |
| | | public void setDictType(String dictType) |
| | | { |
| | | this.dictType = dictType; |
| | | } |
| | | |
| | | 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("dictId", getDictId()) |
| | | .append("dictName", getDictName()) |
| | | .append("dictType", getDictType()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.entity; |
| | | |
| | | 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.jcdm.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * èåæé表 sys_menu |
| | | * |
| | | * @author jc |
| | | */ |
| | | 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; |
| | | |
| | | /** æ¯å¦ä¸ºå¤é¾ï¼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 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("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.jcdm.common.core.domain.entity; |
| | | |
| | | import java.util.Set; |
| | | 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.jcdm.common.annotation.Excel; |
| | | import com.jcdm.common.annotation.Excel.ColumnType; |
| | | import com.jcdm.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * è§è²è¡¨ sys_role |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SysRole extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** è§è²ID */ |
| | | @Excel(name = "è§è²åºå·", cellType = ColumnType.NUMERIC) |
| | | private Long roleId; |
| | | |
| | | /** è§è²å称 */ |
| | | @Excel(name = "è§è²å称") |
| | | private String roleName; |
| | | |
| | | /** è§è²æé */ |
| | | @Excel(name = "è§è²æé") |
| | | private String roleKey; |
| | | |
| | | /** è§è²æåº */ |
| | | @Excel(name = "è§è²æåº") |
| | | private Integer roleSort; |
| | | |
| | | /** æ°æ®èå´ï¼1ï¼æææ°æ®æéï¼2ï¼èªå®ä¹æ°æ®æéï¼3ï¼æ¬é¨é¨æ°æ®æéï¼4ï¼æ¬é¨é¨å以ä¸æ°æ®æéï¼5ï¼ä»
æ¬äººæ°æ®æéï¼ */ |
| | | @Excel(name = "æ°æ®èå´", readConverterExp = "1=æææ°æ®æé,2=èªå®ä¹æ°æ®æé,3=æ¬é¨é¨æ°æ®æé,4=æ¬é¨é¨å以ä¸æ°æ®æé,5=ä»
æ¬äººæ°æ®æé") |
| | | private String dataScope; |
| | | |
| | | /** èåæ éæ©é¡¹æ¯å¦å
³èæ¾ç¤ºï¼ 0ï¼ç¶åä¸äºç¸å
³èæ¾ç¤º 1ï¼ç¶åäºç¸å
³èæ¾ç¤ºï¼ */ |
| | | private boolean menuCheckStrictly; |
| | | |
| | | /** é¨é¨æ éæ©é¡¹æ¯å¦å
³èæ¾ç¤ºï¼0ï¼ç¶åä¸äºç¸å
³èæ¾ç¤º 1ï¼ç¶åäºç¸å
³èæ¾ç¤º ï¼ */ |
| | | private boolean deptCheckStrictly; |
| | | |
| | | /** è§è²ç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | @Excel(name = "è§è²ç¶æ", readConverterExp = "0=æ£å¸¸,1=åç¨") |
| | | private String status; |
| | | |
| | | /** å é¤æ å¿ï¼0代表åå¨ 2代表å é¤ï¼ */ |
| | | private String delFlag; |
| | | |
| | | /** ç¨æ·æ¯å¦åå¨æ¤è§è²æ è¯ é»è®¤ä¸åå¨ */ |
| | | private boolean flag = false; |
| | | |
| | | /** èåç» */ |
| | | private Long[] menuIds; |
| | | |
| | | /** é¨é¨ç»ï¼æ°æ®æéï¼ */ |
| | | private Long[] deptIds; |
| | | |
| | | /** è§è²èåæé */ |
| | | private Set<String> permissions; |
| | | |
| | | public SysRole() |
| | | { |
| | | |
| | | } |
| | | |
| | | public SysRole(Long roleId) |
| | | { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | public Long getRoleId() |
| | | { |
| | | return roleId; |
| | | } |
| | | |
| | | public void setRoleId(Long roleId) |
| | | { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | public boolean isAdmin() |
| | | { |
| | | return isAdmin(this.roleId); |
| | | } |
| | | |
| | | public static boolean isAdmin(Long roleId) |
| | | { |
| | | return roleId != null && 1L == roleId; |
| | | } |
| | | |
| | | @NotBlank(message = "è§è²å称ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 30, message = "è§è²å称é¿åº¦ä¸è½è¶
è¿30个å符") |
| | | public String getRoleName() |
| | | { |
| | | return roleName; |
| | | } |
| | | |
| | | public void setRoleName(String roleName) |
| | | { |
| | | this.roleName = roleName; |
| | | } |
| | | |
| | | @NotBlank(message = "æéå符ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 100, message = "æéå符é¿åº¦ä¸è½è¶
è¿100个å符") |
| | | public String getRoleKey() |
| | | { |
| | | return roleKey; |
| | | } |
| | | |
| | | public void setRoleKey(String roleKey) |
| | | { |
| | | this.roleKey = roleKey; |
| | | } |
| | | |
| | | @NotNull(message = "æ¾ç¤ºé¡ºåºä¸è½ä¸ºç©º") |
| | | public Integer getRoleSort() |
| | | { |
| | | return roleSort; |
| | | } |
| | | |
| | | public void setRoleSort(Integer roleSort) |
| | | { |
| | | this.roleSort = roleSort; |
| | | } |
| | | |
| | | public String getDataScope() |
| | | { |
| | | return dataScope; |
| | | } |
| | | |
| | | public void setDataScope(String dataScope) |
| | | { |
| | | this.dataScope = dataScope; |
| | | } |
| | | |
| | | public boolean isMenuCheckStrictly() |
| | | { |
| | | return menuCheckStrictly; |
| | | } |
| | | |
| | | public void setMenuCheckStrictly(boolean menuCheckStrictly) |
| | | { |
| | | this.menuCheckStrictly = menuCheckStrictly; |
| | | } |
| | | |
| | | public boolean isDeptCheckStrictly() |
| | | { |
| | | return deptCheckStrictly; |
| | | } |
| | | |
| | | public void setDeptCheckStrictly(boolean deptCheckStrictly) |
| | | { |
| | | this.deptCheckStrictly = deptCheckStrictly; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getDelFlag() |
| | | { |
| | | return delFlag; |
| | | } |
| | | |
| | | public void setDelFlag(String delFlag) |
| | | { |
| | | this.delFlag = delFlag; |
| | | } |
| | | |
| | | public boolean isFlag() |
| | | { |
| | | return flag; |
| | | } |
| | | |
| | | public void setFlag(boolean flag) |
| | | { |
| | | this.flag = flag; |
| | | } |
| | | |
| | | public Long[] getMenuIds() |
| | | { |
| | | return menuIds; |
| | | } |
| | | |
| | | public void setMenuIds(Long[] menuIds) |
| | | { |
| | | this.menuIds = menuIds; |
| | | } |
| | | |
| | | public Long[] getDeptIds() |
| | | { |
| | | return deptIds; |
| | | } |
| | | |
| | | public void setDeptIds(Long[] deptIds) |
| | | { |
| | | this.deptIds = deptIds; |
| | | } |
| | | |
| | | public Set<String> getPermissions() |
| | | { |
| | | return permissions; |
| | | } |
| | | |
| | | public void setPermissions(Set<String> permissions) |
| | | { |
| | | this.permissions = permissions; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("roleId", getRoleId()) |
| | | .append("roleName", getRoleName()) |
| | | .append("roleKey", getRoleKey()) |
| | | .append("roleSort", getRoleSort()) |
| | | .append("dataScope", getDataScope()) |
| | | .append("menuCheckStrictly", isMenuCheckStrictly()) |
| | | .append("deptCheckStrictly", isDeptCheckStrictly()) |
| | | .append("status", getStatus()) |
| | | .append("delFlag", getDelFlag()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.entity; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.validation.constraints.*; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.jcdm.common.annotation.Excel; |
| | | import com.jcdm.common.annotation.Excel.ColumnType; |
| | | import com.jcdm.common.annotation.Excel.Type; |
| | | import com.jcdm.common.annotation.Excels; |
| | | import com.jcdm.common.core.domain.BaseEntity; |
| | | import com.jcdm.common.xss.Xss; |
| | | |
| | | /** |
| | | * ç¨æ·å¯¹è±¡ sys_user |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SysUser extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ç¨æ·ID */ |
| | | @Excel(name = "ç¨æ·åºå·", cellType = ColumnType.NUMERIC, prompt = "ç¨æ·ç¼å·") |
| | | private Long userId; |
| | | |
| | | /** é¨é¨ID */ |
| | | @Excel(name = "é¨é¨ç¼å·", type = Type.IMPORT) |
| | | private Long deptId; |
| | | |
| | | /** ç¨æ·è´¦å· */ |
| | | @Excel(name = "ç»å½å称") |
| | | private String userName; |
| | | |
| | | /** ç¨æ·æµç§° */ |
| | | @Excel(name = "ç¨æ·å称") |
| | | private String nickName; |
| | | |
| | | /** ç¨æ·é®ç®± */ |
| | | @Excel(name = "ç¨æ·é®ç®±") |
| | | private String email; |
| | | |
| | | /** ææºå·ç */ |
| | | @Excel(name = "ææºå·ç ") |
| | | private String phonenumber; |
| | | |
| | | /** ç¨æ·æ§å« */ |
| | | @Excel(name = "ç¨æ·æ§å«", readConverterExp = "0=ç·,1=女,2=æªç¥") |
| | | private String sex; |
| | | |
| | | /** ç¨æ·å¤´å */ |
| | | private String avatar; |
| | | |
| | | /** å¯ç */ |
| | | private String password; |
| | | |
| | | /** å¸å·ç¶æï¼0æ£å¸¸ 1åç¨ï¼ */ |
| | | @Excel(name = "å¸å·ç¶æ", readConverterExp = "0=æ£å¸¸,1=åç¨") |
| | | private String status; |
| | | |
| | | /** å é¤æ å¿ï¼0代表åå¨ 2代表å é¤ï¼ */ |
| | | private String delFlag; |
| | | |
| | | /** æåç»å½IP */ |
| | | @Excel(name = "æåç»å½IP", type = Type.EXPORT) |
| | | private String loginIp; |
| | | |
| | | /** æåç»å½æ¶é´ */ |
| | | @Excel(name = "æåç»å½æ¶é´", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) |
| | | private Date loginDate; |
| | | |
| | | /** é¨é¨å¯¹è±¡ */ |
| | | @Excels({ |
| | | @Excel(name = "é¨é¨å称", targetAttr = "deptName", type = Type.EXPORT), |
| | | @Excel(name = "é¨é¨è´è´£äºº", targetAttr = "leader", type = Type.EXPORT) |
| | | }) |
| | | private SysDept dept; |
| | | |
| | | /** è§è²å¯¹è±¡ */ |
| | | private List<SysRole> roles; |
| | | |
| | | /** è§è²ç» */ |
| | | private Long[] roleIds; |
| | | |
| | | /** å²ä½ç» */ |
| | | private Long[] postIds; |
| | | |
| | | /** è§è²ID */ |
| | | private Long roleId; |
| | | |
| | | public SysUser() |
| | | { |
| | | |
| | | } |
| | | |
| | | public SysUser(Long userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public Long getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Long userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public boolean isAdmin() |
| | | { |
| | | return isAdmin(this.userId); |
| | | } |
| | | |
| | | public static boolean isAdmin(Long userId) |
| | | { |
| | | return userId != null && 1L == userId; |
| | | } |
| | | |
| | | public Long getDeptId() |
| | | { |
| | | return deptId; |
| | | } |
| | | |
| | | public void setDeptId(Long deptId) |
| | | { |
| | | this.deptId = deptId; |
| | | } |
| | | |
| | | @Xss(message = "ç¨æ·æµç§°ä¸è½å
å«èæ¬å符") |
| | | @Size(min = 0, max = 30, message = "ç¨æ·æµç§°é¿åº¦ä¸è½è¶
è¿30个å符") |
| | | public String getNickName() |
| | | { |
| | | return nickName; |
| | | } |
| | | |
| | | public void setNickName(String nickName) |
| | | { |
| | | this.nickName = nickName; |
| | | } |
| | | |
| | | @Xss(message = "ç¨æ·è´¦å·ä¸è½å
å«èæ¬å符") |
| | | @NotBlank(message = "ç¨æ·è´¦å·ä¸è½ä¸ºç©º") |
| | | @Size(min = 0, max = 30, message = "ç¨æ·è´¦å·é¿åº¦ä¸è½è¶
è¿30个å符") |
| | | public String getUserName() |
| | | { |
| | | return userName; |
| | | } |
| | | |
| | | public void setUserName(String userName) |
| | | { |
| | | this.userName = userName; |
| | | } |
| | | |
| | | @Email(message = "é®ç®±æ ¼å¼ä¸æ£ç¡®") |
| | | @Size(min = 0, max = 50, message = "é®ç®±é¿åº¦ä¸è½è¶
è¿50个å符") |
| | | public String getEmail() |
| | | { |
| | | return email; |
| | | } |
| | | |
| | | public void setEmail(String email) |
| | | { |
| | | this.email = email; |
| | | } |
| | | |
| | | @Size(min = 0, max = 11, message = "ææºå·ç é¿åº¦ä¸è½è¶
è¿11个å符") |
| | | public String getPhonenumber() |
| | | { |
| | | return phonenumber; |
| | | } |
| | | |
| | | public void setPhonenumber(String phonenumber) |
| | | { |
| | | this.phonenumber = phonenumber; |
| | | } |
| | | |
| | | public String getSex() |
| | | { |
| | | return sex; |
| | | } |
| | | |
| | | public void setSex(String sex) |
| | | { |
| | | this.sex = sex; |
| | | } |
| | | |
| | | public String getAvatar() |
| | | { |
| | | return avatar; |
| | | } |
| | | |
| | | public void setAvatar(String avatar) |
| | | { |
| | | this.avatar = avatar; |
| | | } |
| | | |
| | | public String getPassword() |
| | | { |
| | | return password; |
| | | } |
| | | |
| | | public void setPassword(String password) |
| | | { |
| | | this.password = password; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getDelFlag() |
| | | { |
| | | return delFlag; |
| | | } |
| | | |
| | | public void setDelFlag(String delFlag) |
| | | { |
| | | this.delFlag = delFlag; |
| | | } |
| | | |
| | | public String getLoginIp() |
| | | { |
| | | return loginIp; |
| | | } |
| | | |
| | | public void setLoginIp(String loginIp) |
| | | { |
| | | this.loginIp = loginIp; |
| | | } |
| | | |
| | | public Date getLoginDate() |
| | | { |
| | | return loginDate; |
| | | } |
| | | |
| | | public void setLoginDate(Date loginDate) |
| | | { |
| | | this.loginDate = loginDate; |
| | | } |
| | | |
| | | public SysDept getDept() |
| | | { |
| | | return dept; |
| | | } |
| | | |
| | | public void setDept(SysDept dept) |
| | | { |
| | | this.dept = dept; |
| | | } |
| | | |
| | | public List<SysRole> getRoles() |
| | | { |
| | | return roles; |
| | | } |
| | | |
| | | public void setRoles(List<SysRole> roles) |
| | | { |
| | | this.roles = roles; |
| | | } |
| | | |
| | | public Long[] getRoleIds() |
| | | { |
| | | return roleIds; |
| | | } |
| | | |
| | | public void setRoleIds(Long[] roleIds) |
| | | { |
| | | this.roleIds = roleIds; |
| | | } |
| | | |
| | | public Long[] getPostIds() |
| | | { |
| | | return postIds; |
| | | } |
| | | |
| | | public void setPostIds(Long[] postIds) |
| | | { |
| | | this.postIds = postIds; |
| | | } |
| | | |
| | | 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("deptId", getDeptId()) |
| | | .append("userName", getUserName()) |
| | | .append("nickName", getNickName()) |
| | | .append("email", getEmail()) |
| | | .append("phonenumber", getPhonenumber()) |
| | | .append("sex", getSex()) |
| | | .append("avatar", getAvatar()) |
| | | .append("password", getPassword()) |
| | | .append("status", getStatus()) |
| | | .append("delFlag", getDelFlag()) |
| | | .append("loginIp", getLoginIp()) |
| | | .append("loginDate", getLoginDate()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .append("dept", getDept()) |
| | | .toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.model; |
| | | |
| | | /** |
| | | * ç¨æ·ç»å½å¯¹è±¡ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class LoginBody |
| | | { |
| | | /** |
| | | * ç¨æ·å |
| | | */ |
| | | private String username; |
| | | |
| | | /** |
| | | * ç¨æ·å¯ç |
| | | */ |
| | | private String password; |
| | | |
| | | /** |
| | | * éªè¯ç |
| | | */ |
| | | private String code; |
| | | |
| | | /** |
| | | * å¯ä¸æ è¯ |
| | | */ |
| | | private String uuid; |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public String getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) |
| | | { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getUuid() |
| | | { |
| | | return uuid; |
| | | } |
| | | |
| | | public void setUuid(String uuid) |
| | | { |
| | | this.uuid = uuid; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.model; |
| | | |
| | | import com.alibaba.fastjson2.annotation.JSONField; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | | import org.springframework.security.core.userdetails.UserDetails; |
| | | import java.util.Collection; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * ç»å½ç¨æ·èº«ä»½æé |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class LoginUser implements UserDetails |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * ç¨æ·ID |
| | | */ |
| | | private Long userId; |
| | | |
| | | /** |
| | | * é¨é¨ID |
| | | */ |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * ç¨æ·å¯ä¸æ è¯ |
| | | */ |
| | | private String token; |
| | | |
| | | /** |
| | | * ç»å½æ¶é´ |
| | | */ |
| | | private Long loginTime; |
| | | |
| | | /** |
| | | * è¿ææ¶é´ |
| | | */ |
| | | private Long expireTime; |
| | | |
| | | /** |
| | | * ç»å½IPå°å |
| | | */ |
| | | private String ipaddr; |
| | | |
| | | /** |
| | | * ç»å½å°ç¹ |
| | | */ |
| | | private String loginLocation; |
| | | |
| | | /** |
| | | * æµè§å¨ç±»å |
| | | */ |
| | | private String browser; |
| | | |
| | | /** |
| | | * æä½ç³»ç» |
| | | */ |
| | | private String os; |
| | | |
| | | /** |
| | | * æéå表 |
| | | */ |
| | | private Set<String> permissions; |
| | | |
| | | /** |
| | | * ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | private SysUser user; |
| | | |
| | | public LoginUser() |
| | | { |
| | | } |
| | | |
| | | public LoginUser(SysUser user, Set<String> permissions) |
| | | { |
| | | this.user = user; |
| | | this.permissions = permissions; |
| | | } |
| | | |
| | | public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions) |
| | | { |
| | | this.userId = userId; |
| | | this.deptId = deptId; |
| | | this.user = user; |
| | | this.permissions = permissions; |
| | | } |
| | | |
| | | public Long getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Long userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public Long getDeptId() |
| | | { |
| | | return deptId; |
| | | } |
| | | |
| | | public void setDeptId(Long deptId) |
| | | { |
| | | this.deptId = deptId; |
| | | } |
| | | |
| | | public String getToken() |
| | | { |
| | | return token; |
| | | } |
| | | |
| | | public void setToken(String token) |
| | | { |
| | | this.token = token; |
| | | } |
| | | |
| | | @JSONField(serialize = false) |
| | | @Override |
| | | public String getPassword() |
| | | { |
| | | return user.getPassword(); |
| | | } |
| | | |
| | | @Override |
| | | public String getUsername() |
| | | { |
| | | return user.getUserName(); |
| | | } |
| | | |
| | | /** |
| | | * è´¦æ·æ¯å¦æªè¿æ,è¿ææ æ³éªè¯ |
| | | */ |
| | | @JSONField(serialize = false) |
| | | @Override |
| | | public boolean isAccountNonExpired() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æå®ç¨æ·æ¯å¦è§£é,éå®çç¨æ·æ æ³è¿è¡èº«ä»½éªè¯ |
| | | * |
| | | * @return |
| | | */ |
| | | @JSONField(serialize = false) |
| | | @Override |
| | | public boolean isAccountNonLocked() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æ示æ¯å¦å·²è¿æçç¨æ·çåæ®(å¯ç ),è¿æçåæ®é²æ¢è®¤è¯ |
| | | * |
| | | * @return |
| | | */ |
| | | @JSONField(serialize = false) |
| | | @Override |
| | | public boolean isCredentialsNonExpired() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦å¯ç¨ ,ç¦ç¨çç¨æ·ä¸è½èº«ä»½éªè¯ |
| | | * |
| | | * @return |
| | | */ |
| | | @JSONField(serialize = false) |
| | | @Override |
| | | public boolean isEnabled() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public Long getLoginTime() |
| | | { |
| | | return loginTime; |
| | | } |
| | | |
| | | public void setLoginTime(Long loginTime) |
| | | { |
| | | this.loginTime = loginTime; |
| | | } |
| | | |
| | | 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 getExpireTime() |
| | | { |
| | | return expireTime; |
| | | } |
| | | |
| | | public void setExpireTime(Long expireTime) |
| | | { |
| | | this.expireTime = expireTime; |
| | | } |
| | | |
| | | public Set<String> getPermissions() |
| | | { |
| | | return permissions; |
| | | } |
| | | |
| | | public void setPermissions(Set<String> permissions) |
| | | { |
| | | this.permissions = permissions; |
| | | } |
| | | |
| | | public SysUser getUser() |
| | | { |
| | | return user; |
| | | } |
| | | |
| | | public void setUser(SysUser user) |
| | | { |
| | | this.user = user; |
| | | } |
| | | |
| | | @Override |
| | | public Collection<? extends GrantedAuthority> getAuthorities() |
| | | { |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.domain.model; |
| | | |
| | | /** |
| | | * ç¨æ·æ³¨å对象 |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class RegisterBody extends LoginBody |
| | | { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.page; |
| | | |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * å页æ°æ® |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class PageDomain |
| | | { |
| | | /** å½åè®°å½èµ·å§ç´¢å¼ */ |
| | | private Integer pageNum; |
| | | |
| | | /** æ¯é¡µæ¾ç¤ºè®°å½æ° */ |
| | | private Integer pageSize; |
| | | |
| | | /** æåºå */ |
| | | private String orderByColumn; |
| | | |
| | | /** æåºçæ¹ådescæè
asc */ |
| | | private String isAsc = "asc"; |
| | | |
| | | /** å页åæ°åçå */ |
| | | private Boolean reasonable = true; |
| | | |
| | | public String getOrderBy() |
| | | { |
| | | if (StringUtils.isEmpty(orderByColumn)) |
| | | { |
| | | return ""; |
| | | } |
| | | return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc; |
| | | } |
| | | |
| | | public Integer getPageNum() |
| | | { |
| | | return pageNum; |
| | | } |
| | | |
| | | public void setPageNum(Integer pageNum) |
| | | { |
| | | this.pageNum = pageNum; |
| | | } |
| | | |
| | | public Integer getPageSize() |
| | | { |
| | | return pageSize; |
| | | } |
| | | |
| | | public void setPageSize(Integer pageSize) |
| | | { |
| | | this.pageSize = pageSize; |
| | | } |
| | | |
| | | public String getOrderByColumn() |
| | | { |
| | | return orderByColumn; |
| | | } |
| | | |
| | | public void setOrderByColumn(String orderByColumn) |
| | | { |
| | | this.orderByColumn = orderByColumn; |
| | | } |
| | | |
| | | public String getIsAsc() |
| | | { |
| | | return isAsc; |
| | | } |
| | | |
| | | public void setIsAsc(String isAsc) |
| | | { |
| | | if (StringUtils.isNotEmpty(isAsc)) |
| | | { |
| | | // å
¼å®¹å端æåºç±»å |
| | | if ("ascending".equals(isAsc)) |
| | | { |
| | | isAsc = "asc"; |
| | | } |
| | | else if ("descending".equals(isAsc)) |
| | | { |
| | | isAsc = "desc"; |
| | | } |
| | | this.isAsc = isAsc; |
| | | } |
| | | } |
| | | |
| | | public Boolean getReasonable() |
| | | { |
| | | if (StringUtils.isNull(reasonable)) |
| | | { |
| | | return Boolean.TRUE; |
| | | } |
| | | return reasonable; |
| | | } |
| | | |
| | | public void setReasonable(Boolean reasonable) |
| | | { |
| | | this.reasonable = reasonable; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.page; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è¡¨æ ¼å页æ°æ®å¯¹è±¡ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class TableDataInfo implements Serializable |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** æ»è®°å½æ° */ |
| | | private long total; |
| | | |
| | | /** å表æ°æ® */ |
| | | private List<?> rows; |
| | | |
| | | /** æ¶æ¯ç¶æç */ |
| | | private int code; |
| | | |
| | | /** æ¶æ¯å
容 */ |
| | | private String msg; |
| | | |
| | | /** |
| | | * è¡¨æ ¼æ°æ®å¯¹è±¡ |
| | | */ |
| | | public TableDataInfo() |
| | | { |
| | | } |
| | | |
| | | /** |
| | | * å页 |
| | | * |
| | | * @param list å表æ°æ® |
| | | * @param total æ»è®°å½æ° |
| | | */ |
| | | public TableDataInfo(List<?> list, int total) |
| | | { |
| | | this.rows = list; |
| | | this.total = total; |
| | | } |
| | | |
| | | public long getTotal() |
| | | { |
| | | return total; |
| | | } |
| | | |
| | | public void setTotal(long total) |
| | | { |
| | | this.total = total; |
| | | } |
| | | |
| | | public List<?> getRows() |
| | | { |
| | | return rows; |
| | | } |
| | | |
| | | public void setRows(List<?> rows) |
| | | { |
| | | this.rows = rows; |
| | | } |
| | | |
| | | public int getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(int code) |
| | | { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() |
| | | { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) |
| | | { |
| | | this.msg = msg; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.page; |
| | | |
| | | import com.jcdm.common.core.text.Convert; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | |
| | | /** |
| | | * è¡¨æ ¼æ°æ®å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class TableSupport |
| | | { |
| | | /** |
| | | * å½åè®°å½èµ·å§ç´¢å¼ |
| | | */ |
| | | public static final String PAGE_NUM = "pageNum"; |
| | | |
| | | /** |
| | | * æ¯é¡µæ¾ç¤ºè®°å½æ° |
| | | */ |
| | | public static final String PAGE_SIZE = "pageSize"; |
| | | |
| | | /** |
| | | * æåºå |
| | | */ |
| | | public static final String ORDER_BY_COLUMN = "orderByColumn"; |
| | | |
| | | /** |
| | | * æåºçæ¹å "desc" æè
"asc". |
| | | */ |
| | | public static final String IS_ASC = "isAsc"; |
| | | |
| | | /** |
| | | * å页åæ°åçå |
| | | */ |
| | | public static final String REASONABLE = "reasonable"; |
| | | |
| | | /** |
| | | * å°è£
å页对象 |
| | | */ |
| | | public static PageDomain getPageDomain() |
| | | { |
| | | PageDomain pageDomain = new PageDomain(); |
| | | pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1)); |
| | | pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10)); |
| | | pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN)); |
| | | pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC)); |
| | | pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE)); |
| | | return pageDomain; |
| | | } |
| | | |
| | | public static PageDomain buildPageRequest() |
| | | { |
| | | return getPageDomain(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.redis; |
| | | |
| | | import org.springframework.cache.Cache; |
| | | import org.springframework.cache.support.SimpleValueWrapper; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Component |
| | | public class MyCache implements Cache { |
| | | |
| | | // 使ç¨ConcurrentHashMapä½ä¸ºæ°æ®çåå¨ |
| | | private Map<String, Object> storage = new ConcurrentHashMap<>(); |
| | | |
| | | // getNameè·åcacheçå称ï¼ååæ°æ®çæ¶åç¨æ¥åºåæ¯é对åªä¸ªcacheæä½ |
| | | @Override |
| | | public String getName() { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Object getNativeCache() { |
| | | return null; |
| | | } |
| | | |
| | | public boolean hasKey(String key){ |
| | | return storage.containsKey(key); |
| | | } |
| | | |
| | | @Override |
| | | public ValueWrapper get(Object key) { |
| | | String k = key.toString(); |
| | | Object value = storage.get(k); |
| | | |
| | | // 注æè¿åçæ°æ®ï¼è¦ååæ¾æ¶æ¥æ¶å°æ°æ®ä¿æä¸è´ï¼è¦å°æ°æ®ååºåååæ¥ã |
| | | return Objects.isNull(value) ? null : new SimpleValueWrapper(value); |
| | | } |
| | | |
| | | @Override |
| | | public <T> T get(Object key, Class<T> type) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public <T> T get(Object key, Callable<T> valueLoader) { |
| | | return null; |
| | | } |
| | | |
| | | // putæ¹æ³ï¼å°±æ¯æ§è¡å°æ°æ®è¿è¡ç¼å |
| | | @Override |
| | | public void put(Object key, Object value) { |
| | | if (Objects.isNull(value)) { |
| | | return; |
| | | } |
| | | //åå¼ |
| | | storage.put(key.toString(), value); |
| | | } |
| | | |
| | | // evictæ¹æ³ï¼æ¯ç¨æ¥æ¸
é¤æ个ç¼å项 |
| | | @Override |
| | | public void evict(Object key) { |
| | | storage.remove(key.toString()); |
| | | } |
| | | |
| | | // å é¤éå |
| | | public boolean deleteObject(final Collection collection){ |
| | | collection.forEach(o -> { |
| | | storage.remove(o.toString()); |
| | | } ); |
| | | return true; |
| | | } |
| | | |
| | | // è·åææçkeys |
| | | public Collection<String> keys(final String pattern){ |
| | | return storage.keySet(); |
| | | } |
| | | |
| | | @Override |
| | | public void clear() { |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.redis; |
| | | |
| | | import org.springframework.cache.Cache; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Collection; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * spring redis å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | **/ |
| | | @SuppressWarnings(value = { "unchecked", "rawtypes" }) |
| | | @Component |
| | | public class RedisCache |
| | | { |
| | | // @Autowired |
| | | // public RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | public MyCache myCache; |
| | | |
| | | /** |
| | | * ç¼ååºæ¬ç对象ï¼IntegerãStringãå®ä½ç±»ç |
| | | * |
| | | * @param key ç¼åçé®å¼ |
| | | * @param value ç¼åçå¼ |
| | | */ |
| | | public <T> void setCacheObject(final String key, final T value) |
| | | { |
| | | myCache.put(key,value); |
| | | // redisTemplate.opsForValue().set(key, value); |
| | | } |
| | | |
| | | /** |
| | | * ç¼ååºæ¬ç对象ï¼IntegerãStringãå®ä½ç±»ç |
| | | * |
| | | * @param key ç¼åçé®å¼ |
| | | * @param value ç¼åçå¼ |
| | | * @param timeout æ¶é´ |
| | | * @param timeUnit æ¶é´é¢ç²åº¦ |
| | | */ |
| | | public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) |
| | | { |
| | | myCache.put(key,value); |
| | | // redisTemplate.opsForValue().set(key, value, timeout, timeUnit); |
| | | } |
| | | |
| | | /** |
| | | * 设置æææ¶é´ |
| | | * |
| | | * @param key Redisé® |
| | | * @param timeout è¶
æ¶æ¶é´ |
| | | * @return true=设置æåï¼false=设置失败 |
| | | */ |
| | | public boolean expire(final String key, final long timeout) |
| | | { |
| | | return expire(key, timeout, TimeUnit.SECONDS); |
| | | } |
| | | |
| | | /** |
| | | * 设置æææ¶é´ |
| | | * |
| | | * @param key Redisé® |
| | | * @param timeout è¶
æ¶æ¶é´ |
| | | * @param unit æ¶é´åä½ |
| | | * @return true=设置æåï¼false=设置失败 |
| | | */ |
| | | public boolean expire(final String key, final long timeout, final TimeUnit unit) |
| | | { |
| | | return true; |
| | | // return redisTemplate.expire(key, timeout, unit); |
| | | } |
| | | |
| | | /** |
| | | * è·åæææ¶é´ |
| | | * |
| | | * @param key Redisé® |
| | | * @return æææ¶é´ |
| | | */ |
| | | // public long getExpire(final String key) |
| | | // { |
| | | // return redisTemplate.getExpire(key); |
| | | // } |
| | | |
| | | /** |
| | | * å¤æ keyæ¯å¦åå¨ |
| | | * |
| | | * @param key é® |
| | | * @return true åå¨ falseä¸åå¨ |
| | | */ |
| | | public Boolean hasKey(String key) |
| | | { |
| | | return myCache.hasKey(key); |
| | | // return redisTemplate.hasKey(key); |
| | | } |
| | | |
| | | /** |
| | | * è·å¾ç¼åçåºæ¬å¯¹è±¡ã |
| | | * |
| | | * @param key ç¼åé®å¼ |
| | | * @return ç¼åé®å¼å¯¹åºçæ°æ® |
| | | */ |
| | | public <T> T getCacheObject(final String key) |
| | | { |
| | | Cache.ValueWrapper valueWrapper = myCache.get(key); |
| | | if (valueWrapper == null){ |
| | | return null; |
| | | }else { |
| | | return (T) valueWrapper.get(); |
| | | } |
| | | // ValueOperations<String, T> operation = redisTemplate.opsForValue(); |
| | | // return operation.get(key); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å个对象 |
| | | * |
| | | * @param key |
| | | */ |
| | | public boolean deleteObject(final String key) |
| | | { |
| | | myCache.evict(key); |
| | | return true; |
| | | // return redisTemplate.delete(key); |
| | | } |
| | | |
| | | /** |
| | | * å é¤éå对象 |
| | | * |
| | | * @param collection å¤ä¸ªå¯¹è±¡ |
| | | * @return |
| | | */ |
| | | public boolean deleteObject(final Collection collection) |
| | | { |
| | | return myCache.deleteObject(collection); |
| | | // return redisTemplate.delete(collection) > 0; |
| | | } |
| | | |
| | | /** |
| | | * ç¼åListæ°æ® |
| | | * |
| | | * @param key ç¼åçé®å¼ |
| | | * @param dataList å¾
ç¼åçListæ°æ® |
| | | * @return ç¼åç对象 |
| | | */ |
| | | // public <T> long setCacheList(final String key, final List<T> dataList) |
| | | // { |
| | | // Long count = redisTemplate.opsForList().rightPushAll(key, dataList); |
| | | // return count == null ? 0 : count; |
| | | // } |
| | | |
| | | /** |
| | | * è·å¾ç¼åçlist对象 |
| | | * |
| | | * @param key ç¼åçé®å¼ |
| | | * @return ç¼åé®å¼å¯¹åºçæ°æ® |
| | | */ |
| | | // public <T> List<T> getCacheList(final String key) |
| | | // { |
| | | // return redisTemplate.opsForList().range(key, 0, -1); |
| | | // } |
| | | |
| | | /** |
| | | * ç¼åSet |
| | | * |
| | | * @param key ç¼åé®å¼ |
| | | * @param dataSet ç¼åçæ°æ® |
| | | * @return ç¼åæ°æ®ç对象 |
| | | */ |
| | | // public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) |
| | | // { |
| | | // BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key); |
| | | // Iterator<T> it = dataSet.iterator(); |
| | | // while (it.hasNext()) |
| | | // { |
| | | // setOperation.add(it.next()); |
| | | // } |
| | | // return setOperation; |
| | | // } |
| | | |
| | | /** |
| | | * è·å¾ç¼åçset |
| | | * |
| | | * @param key |
| | | * @return |
| | | */ |
| | | // public <T> Set<T> getCacheSet(final String key) |
| | | // { |
| | | // return redisTemplate.opsForSet().members(key); |
| | | // } |
| | | |
| | | /** |
| | | * ç¼åMap |
| | | * |
| | | * @param key |
| | | * @param dataMap |
| | | */ |
| | | // public <T> void setCacheMap(final String key, final Map<String, T> dataMap) |
| | | // { |
| | | // if (dataMap != null) { |
| | | // redisTemplate.opsForHash().putAll(key, dataMap); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * è·å¾ç¼åçMap |
| | | * |
| | | * @param key |
| | | * @return |
| | | */ |
| | | // public <T> Map<String, T> getCacheMap(final String key) |
| | | // { |
| | | // return redisTemplate.opsForHash().entries(key); |
| | | // } |
| | | |
| | | /** |
| | | * å¾Hashä¸åå
¥æ°æ® |
| | | * |
| | | * @param key Redisé® |
| | | * @param hKey Hashé® |
| | | * @param value å¼ |
| | | */ |
| | | // public <T> void setCacheMapValue(final String key, final String hKey, final T value) |
| | | // { |
| | | // redisTemplate.opsForHash().put(key, hKey, value); |
| | | // } |
| | | |
| | | /** |
| | | * è·åHashä¸çæ°æ® |
| | | * |
| | | * @param key Redisé® |
| | | * @param hKey Hashé® |
| | | * @return Hashä¸ç对象 |
| | | */ |
| | | // public <T> T getCacheMapValue(final String key, final String hKey) |
| | | // { |
| | | // HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash(); |
| | | // return opsForHash.get(key, hKey); |
| | | // } |
| | | |
| | | /** |
| | | * è·åå¤ä¸ªHashä¸çæ°æ® |
| | | * |
| | | * @param key Redisé® |
| | | * @param hKeys Hashé®éå |
| | | * @return Hash对象éå |
| | | */ |
| | | // public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) |
| | | // { |
| | | // return redisTemplate.opsForHash().multiGet(key, hKeys); |
| | | // } |
| | | |
| | | /** |
| | | * å é¤Hashä¸çææ¡æ°æ® |
| | | * |
| | | * @param key Redisé® |
| | | * @param hKey Hashé® |
| | | * @return æ¯å¦æå |
| | | */ |
| | | // public boolean deleteCacheMapValue(final String key, final String hKey) |
| | | // { |
| | | // return redisTemplate.opsForHash().delete(key, hKey) > 0; |
| | | // } |
| | | |
| | | /** |
| | | * è·å¾ç¼åçåºæ¬å¯¹è±¡å表 |
| | | * |
| | | * @param pattern å符串åç¼ |
| | | * @return 对象å表 |
| | | */ |
| | | public Collection<String> keys(final String pattern) |
| | | { |
| | | return myCache.keys(pattern); |
| | | // return redisTemplate.keys(pattern); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.text; |
| | | |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * å符éå·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class CharsetKit |
| | | { |
| | | /** ISO-8859-1 */ |
| | | public static final String ISO_8859_1 = "ISO-8859-1"; |
| | | /** UTF-8 */ |
| | | public static final String UTF_8 = "UTF-8"; |
| | | /** GBK */ |
| | | public static final String GBK = "GBK"; |
| | | |
| | | /** ISO-8859-1 */ |
| | | public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); |
| | | /** UTF-8 */ |
| | | public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); |
| | | /** GBK */ |
| | | public static final Charset CHARSET_GBK = Charset.forName(GBK); |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºCharset对象 |
| | | * |
| | | * @param charset å符éï¼ä¸ºç©ºåè¿åé»è®¤å符é |
| | | * @return Charset |
| | | */ |
| | | public static Charset charset(String charset) |
| | | { |
| | | return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢å符串çå符éç¼ç |
| | | * |
| | | * @param source å符串 |
| | | * @param srcCharset æºå符éï¼é»è®¤ISO-8859-1 |
| | | * @param destCharset ç®æ å符éï¼é»è®¤UTF-8 |
| | | * @return 转æ¢åçå符é |
| | | */ |
| | | public static String convert(String source, String srcCharset, String destCharset) |
| | | { |
| | | return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢å符串çå符éç¼ç |
| | | * |
| | | * @param source å符串 |
| | | * @param srcCharset æºå符éï¼é»è®¤ISO-8859-1 |
| | | * @param destCharset ç®æ å符éï¼é»è®¤UTF-8 |
| | | * @return 转æ¢åçå符é |
| | | */ |
| | | public static String convert(String source, Charset srcCharset, Charset destCharset) |
| | | { |
| | | if (null == srcCharset) |
| | | { |
| | | srcCharset = StandardCharsets.ISO_8859_1; |
| | | } |
| | | |
| | | if (null == destCharset) |
| | | { |
| | | destCharset = StandardCharsets.UTF_8; |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) |
| | | { |
| | | return source; |
| | | } |
| | | return new String(source.getBytes(srcCharset), destCharset); |
| | | } |
| | | |
| | | /** |
| | | * @return ç³»ç»å符éç¼ç |
| | | */ |
| | | public static String systemCharset() |
| | | { |
| | | return Charset.defaultCharset().name(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.text; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.charset.Charset; |
| | | import java.text.NumberFormat; |
| | | import java.util.Set; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | |
| | | /** |
| | | * ç±»å转æ¢å¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class Convert |
| | | { |
| | | /** |
| | | * 转æ¢ä¸ºå符串<br> |
| | | * å¦æç»å®çå¼ä¸ºnullï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String toStr(Object value, String defaultValue) |
| | | { |
| | | if (null == value) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof String) |
| | | { |
| | | return (String) value; |
| | | } |
| | | return value.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºå符串<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String toStr(Object value) |
| | | { |
| | | return toStr(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºå符<br> |
| | | * å¦æç»å®çå¼ä¸ºnullï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Character toChar(Object value, Character defaultValue) |
| | | { |
| | | if (null == value) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Character) |
| | | { |
| | | return (Character) value; |
| | | } |
| | | |
| | | final String valueStr = toStr(value, null); |
| | | return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºå符<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Character toChar(Object value) |
| | | { |
| | | return toChar(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºbyte<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Byte toByte(Object value, Byte defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Byte) |
| | | { |
| | | return (Byte) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).byteValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return Byte.parseByte(valueStr); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºbyte<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Byte toByte(Object value) |
| | | { |
| | | return toByte(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºShort<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Short toShort(Object value, Short defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Short) |
| | | { |
| | | return (Short) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).shortValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return Short.parseShort(valueStr.trim()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºShort<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Short toShort(Object value) |
| | | { |
| | | return toShort(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºNumber<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Number toNumber(Object value, Number defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return (Number) value; |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return NumberFormat.getInstance().parse(valueStr); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºNumber<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Number toNumber(Object value) |
| | | { |
| | | return toNumber(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºint<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer toInt(Object value, Integer defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Integer) |
| | | { |
| | | return (Integer) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).intValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return Integer.parseInt(valueStr.trim()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºint<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer toInt(Object value) |
| | | { |
| | | return toInt(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeræ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer[] toIntArray(String str) |
| | | { |
| | | return toIntArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongæ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long[] toLongArray(String str) |
| | | { |
| | | return toLongArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeræ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param split 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer[] toIntArray(String split, String str) |
| | | { |
| | | if (StringUtils.isEmpty(str)) |
| | | { |
| | | return new Integer[] {}; |
| | | } |
| | | String[] arr = str.split(split); |
| | | final Integer[] ints = new Integer[arr.length]; |
| | | for (int i = 0; i < arr.length; i++) |
| | | { |
| | | final Integer v = toInt(arr[i], 0); |
| | | ints[i] = v; |
| | | } |
| | | return ints; |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongæ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long[] toLongArray(String split, String str) |
| | | { |
| | | if (StringUtils.isEmpty(str)) |
| | | { |
| | | return new Long[] {}; |
| | | } |
| | | String[] arr = str.split(split); |
| | | final Long[] longs = new Long[arr.length]; |
| | | for (int i = 0; i < arr.length; i++) |
| | | { |
| | | final Long v = toLong(arr[i], null); |
| | | longs[i] = v; |
| | | } |
| | | return longs; |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringæ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String[] toStrArray(String str) |
| | | { |
| | | return toStrArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringæ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param split 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String[] toStrArray(String split, String str) |
| | | { |
| | | return str.split(split); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºlong<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long toLong(Object value, Long defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Long) |
| | | { |
| | | return (Long) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).longValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | // æ¯æç§å¦è®¡æ°æ³ |
| | | return new BigDecimal(valueStr.trim()).longValue(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºlong<br> |
| | | * å¦æç»å®çå¼ä¸º<code>null</code>ï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long toLong(Object value) |
| | | { |
| | | return toLong(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºdouble<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Double toDouble(Object value, Double defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Double) |
| | | { |
| | | return (Double) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).doubleValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | // æ¯æç§å¦è®¡æ°æ³ |
| | | return new BigDecimal(valueStr.trim()).doubleValue(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºdouble<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Double toDouble(Object value) |
| | | { |
| | | return toDouble(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºFloat<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Float toFloat(Object value, Float defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Float) |
| | | { |
| | | return (Float) value; |
| | | } |
| | | if (value instanceof Number) |
| | | { |
| | | return ((Number) value).floatValue(); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return Float.parseFloat(valueStr.trim()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºFloat<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Float toFloat(Object value) |
| | | { |
| | | return toFloat(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºboolean<br> |
| | | * Stringæ¯æçå¼ä¸ºï¼trueãfalseãyesãokãnoï¼1,0 å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Boolean toBool(Object value, Boolean defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof Boolean) |
| | | { |
| | | return (Boolean) value; |
| | | } |
| | | String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | valueStr = valueStr.trim().toLowerCase(); |
| | | switch (valueStr) |
| | | { |
| | | case "true": |
| | | case "yes": |
| | | case "ok": |
| | | case "1": |
| | | return true; |
| | | case "false": |
| | | case "no": |
| | | case "0": |
| | | return false; |
| | | default: |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºboolean<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Boolean toBool(Object value) |
| | | { |
| | | return toBool(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºEnum对象<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * |
| | | * @param clazz EnumçClass |
| | | * @param value å¼ |
| | | * @param defaultValue é»è®¤å¼ |
| | | * @return Enum |
| | | */ |
| | | public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (clazz.isAssignableFrom(value.getClass())) |
| | | { |
| | | @SuppressWarnings("unchecked") |
| | | E myE = (E) value; |
| | | return myE; |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return Enum.valueOf(clazz, valueStr); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºEnum对象<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * |
| | | * @param clazz EnumçClass |
| | | * @param value å¼ |
| | | * @return Enum |
| | | */ |
| | | public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) |
| | | { |
| | | return toEnum(clazz, value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºBigInteger<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static BigInteger toBigInteger(Object value, BigInteger defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof BigInteger) |
| | | { |
| | | return (BigInteger) value; |
| | | } |
| | | if (value instanceof Long) |
| | | { |
| | | return BigInteger.valueOf((Long) value); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return new BigInteger(valueStr); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºBigInteger<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<code>null</code><br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static BigInteger toBigInteger(Object value) |
| | | { |
| | | return toBigInteger(value, null); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºBigDecimal<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @param defaultValue 转æ¢é误æ¶çé»è®¤å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) |
| | | { |
| | | if (value == null) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | if (value instanceof BigDecimal) |
| | | { |
| | | return (BigDecimal) value; |
| | | } |
| | | if (value instanceof Long) |
| | | { |
| | | return new BigDecimal((Long) value); |
| | | } |
| | | if (value instanceof Double) |
| | | { |
| | | return BigDecimal.valueOf((Double) value); |
| | | } |
| | | if (value instanceof Integer) |
| | | { |
| | | return new BigDecimal((Integer) value); |
| | | } |
| | | final String valueStr = toStr(value, null); |
| | | if (StringUtils.isEmpty(valueStr)) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | try |
| | | { |
| | | return new BigDecimal(valueStr); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return defaultValue; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºBigDecimal<br> |
| | | * å¦æç»å®çå¼ä¸ºç©ºï¼æè
转æ¢å¤±è´¥ï¼è¿åé»è®¤å¼<br> |
| | | * 转æ¢å¤±è´¥ä¸ä¼æ¥é |
| | | * |
| | | * @param value 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static BigDecimal toBigDecimal(Object value) |
| | | { |
| | | return toBigDecimal(value, null); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡è½¬ä¸ºå符串<br> |
| | | * 1ãByteæ°ç»åByteBufferä¼è¢«è½¬æ¢ä¸ºå¯¹åºå符串çæ°ç» 2ã对象æ°ç»ä¼è°ç¨Arrays.toStringæ¹æ³ |
| | | * |
| | | * @param obj 对象 |
| | | * @return å符串 |
| | | */ |
| | | public static String utf8Str(Object obj) |
| | | { |
| | | return str(obj, CharsetKit.CHARSET_UTF_8); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡è½¬ä¸ºå符串<br> |
| | | * 1ãByteæ°ç»åByteBufferä¼è¢«è½¬æ¢ä¸ºå¯¹åºå符串çæ°ç» 2ã对象æ°ç»ä¼è°ç¨Arrays.toStringæ¹æ³ |
| | | * |
| | | * @param obj 对象 |
| | | * @param charsetName å符é |
| | | * @return å符串 |
| | | */ |
| | | public static String str(Object obj, String charsetName) |
| | | { |
| | | return str(obj, Charset.forName(charsetName)); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡è½¬ä¸ºå符串<br> |
| | | * 1ãByteæ°ç»åByteBufferä¼è¢«è½¬æ¢ä¸ºå¯¹åºå符串çæ°ç» 2ã对象æ°ç»ä¼è°ç¨Arrays.toStringæ¹æ³ |
| | | * |
| | | * @param obj 对象 |
| | | * @param charset å符é |
| | | * @return å符串 |
| | | */ |
| | | public static String str(Object obj, Charset charset) |
| | | { |
| | | if (null == obj) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if (obj instanceof String) |
| | | { |
| | | return (String) obj; |
| | | } |
| | | else if (obj instanceof byte[]) |
| | | { |
| | | return str((byte[]) obj, charset); |
| | | } |
| | | else if (obj instanceof Byte[]) |
| | | { |
| | | byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); |
| | | return str(bytes, charset); |
| | | } |
| | | else if (obj instanceof ByteBuffer) |
| | | { |
| | | return str((ByteBuffer) obj, charset); |
| | | } |
| | | return obj.toString(); |
| | | } |
| | | |
| | | /** |
| | | * å°byteæ°ç»è½¬ä¸ºå符串 |
| | | * |
| | | * @param bytes byteæ°ç» |
| | | * @param charset å符é |
| | | * @return å符串 |
| | | */ |
| | | public static String str(byte[] bytes, String charset) |
| | | { |
| | | return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); |
| | | } |
| | | |
| | | /** |
| | | * 解ç åèç |
| | | * |
| | | * @param data å符串 |
| | | * @param charset å符éï¼å¦ææ¤å段为空ï¼å解ç çç»æåå³äºå¹³å° |
| | | * @return 解ç åçå符串 |
| | | */ |
| | | public static String str(byte[] data, Charset charset) |
| | | { |
| | | if (data == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | if (null == charset) |
| | | { |
| | | return new String(data); |
| | | } |
| | | return new String(data, charset); |
| | | } |
| | | |
| | | /** |
| | | * å°ç¼ç çbyteBufferæ°æ®è½¬æ¢ä¸ºå符串 |
| | | * |
| | | * @param data æ°æ® |
| | | * @param charset å符éï¼å¦æ为空使ç¨å½åç³»ç»å符é |
| | | * @return å符串 |
| | | */ |
| | | public static String str(ByteBuffer data, String charset) |
| | | { |
| | | if (data == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return str(data, Charset.forName(charset)); |
| | | } |
| | | |
| | | /** |
| | | * å°ç¼ç çbyteBufferæ°æ®è½¬æ¢ä¸ºå符串 |
| | | * |
| | | * @param data æ°æ® |
| | | * @param charset å符éï¼å¦æ为空使ç¨å½åç³»ç»å符é |
| | | * @return å符串 |
| | | */ |
| | | public static String str(ByteBuffer data, Charset charset) |
| | | { |
| | | if (null == charset) |
| | | { |
| | | charset = Charset.defaultCharset(); |
| | | } |
| | | return charset.decode(data).toString(); |
| | | } |
| | | |
| | | // ----------------------------------------------------------------------- å
¨è§åè§è½¬æ¢ |
| | | /** |
| | | * åè§è½¬å
¨è§ |
| | | * |
| | | * @param input String. |
| | | * @return å
¨è§å符串. |
| | | */ |
| | | public static String toSBC(String input) |
| | | { |
| | | return toSBC(input, null); |
| | | } |
| | | |
| | | /** |
| | | * åè§è½¬å
¨è§ |
| | | * |
| | | * @param input String |
| | | * @param notConvertSet ä¸æ¿æ¢çå符éå |
| | | * @return å
¨è§å符串. |
| | | */ |
| | | public static String toSBC(String input, Set<Character> notConvertSet) |
| | | { |
| | | char[] c = input.toCharArray(); |
| | | for (int i = 0; i < c.length; i++) |
| | | { |
| | | if (null != notConvertSet && notConvertSet.contains(c[i])) |
| | | { |
| | | // è·³è¿ä¸æ¿æ¢çå符 |
| | | continue; |
| | | } |
| | | |
| | | if (c[i] == ' ') |
| | | { |
| | | c[i] = '\u3000'; |
| | | } |
| | | else if (c[i] < '\177') |
| | | { |
| | | c[i] = (char) (c[i] + 65248); |
| | | |
| | | } |
| | | } |
| | | return new String(c); |
| | | } |
| | | |
| | | /** |
| | | * å
¨è§è½¬åè§ |
| | | * |
| | | * @param input String. |
| | | * @return åè§å符串 |
| | | */ |
| | | public static String toDBC(String input) |
| | | { |
| | | return toDBC(input, null); |
| | | } |
| | | |
| | | /** |
| | | * æ¿æ¢å
¨è§ä¸ºåè§ |
| | | * |
| | | * @param text ææ¬ |
| | | * @param notConvertSet ä¸æ¿æ¢çå符éå |
| | | * @return æ¿æ¢åçå符 |
| | | */ |
| | | public static String toDBC(String text, Set<Character> notConvertSet) |
| | | { |
| | | char[] c = text.toCharArray(); |
| | | for (int i = 0; i < c.length; i++) |
| | | { |
| | | if (null != notConvertSet && notConvertSet.contains(c[i])) |
| | | { |
| | | // è·³è¿ä¸æ¿æ¢çå符 |
| | | continue; |
| | | } |
| | | |
| | | if (c[i] == '\u3000') |
| | | { |
| | | c[i] = ' '; |
| | | } |
| | | else if (c[i] > '\uFF00' && c[i] < '\uFF5F') |
| | | { |
| | | c[i] = (char) (c[i] - 65248); |
| | | } |
| | | } |
| | | String returnString = new String(c); |
| | | |
| | | return returnString; |
| | | } |
| | | |
| | | /** |
| | | * æ°åéé¢å¤§åè½¬æ¢ å
å个å®æ´çç¶åå°å¦é¶æ¾æ¿æ¢æé¶ |
| | | * |
| | | * @param n æ°å |
| | | * @return ä¸æ大åæ°å |
| | | */ |
| | | public static String digitUppercase(double n) |
| | | { |
| | | String[] fraction = { "è§", "å" }; |
| | | String[] digit = { "é¶", "壹", "è´°", "å", "è", "ä¼", "é", "æ", "æ", "ç" }; |
| | | String[][] unit = { { "å
", "ä¸", "亿" }, { "", "æ¾", "ä½°", "ä»" } }; |
| | | |
| | | String head = n < 0 ? "è´" : ""; |
| | | n = Math.abs(n); |
| | | |
| | | String s = ""; |
| | | for (int i = 0; i < fraction.length; i++) |
| | | { |
| | | // ä¼ådouble计ç®ç²¾åº¦ä¸¢å¤±é®é¢ |
| | | BigDecimal nNum = new BigDecimal(n); |
| | | BigDecimal decimal = new BigDecimal(10); |
| | | BigDecimal scale = nNum.multiply(decimal).setScale(2, RoundingMode.HALF_EVEN); |
| | | double d = scale.doubleValue(); |
| | | s += (digit[(int) (Math.floor(d * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(é¶.)+", ""); |
| | | } |
| | | if (s.length() < 1) |
| | | { |
| | | s = "æ´"; |
| | | } |
| | | int integerPart = (int) Math.floor(n); |
| | | |
| | | for (int i = 0; i < unit[0].length && integerPart > 0; i++) |
| | | { |
| | | String p = ""; |
| | | for (int j = 0; j < unit[1].length && n > 0; j++) |
| | | { |
| | | p = digit[integerPart % 10] + unit[1][j] + p; |
| | | integerPart = integerPart / 10; |
| | | } |
| | | s = p.replaceAll("(é¶.)*é¶$", "").replaceAll("^$", "é¶") + unit[0][i] + s; |
| | | } |
| | | return head + s.replaceAll("(é¶.)*é¶å
", "å
").replaceFirst("(é¶.)+", "").replaceAll("(é¶.)+", "é¶").replaceAll("^æ´$", "é¶å
æ´"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.core.text; |
| | | |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * åç¬¦ä¸²æ ¼å¼å |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class StrFormatter |
| | | { |
| | | public static final String EMPTY_JSON = "{}"; |
| | | public static final char C_BACKSLASH = '\\'; |
| | | public static final char C_DELIM_START = '{'; |
| | | public static final char C_DELIM_END = '}'; |
| | | |
| | | /** |
| | | * æ ¼å¼åå符串<br> |
| | | * æ¤æ¹æ³åªæ¯ç®åå°å ä½ç¬¦ {} æç
§é¡ºåºæ¿æ¢ä¸ºåæ°<br> |
| | | * å¦ææ³è¾åº {} ä½¿ç¨ \\è½¬ä¹ { å³å¯ï¼å¦ææ³è¾åº {} ä¹åç \ 使ç¨å转ä¹ç¬¦ \\\\ å³å¯<br> |
| | | * ä¾ï¼<br> |
| | | * é常使ç¨ï¼format("this is {} for {}", "a", "b") -> this is a for b<br> |
| | | * 转ä¹{}ï¼ format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
| | | * 转ä¹\ï¼ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
| | | * |
| | | * @param strPattern åç¬¦ä¸²æ¨¡æ¿ |
| | | * @param argArray åæ°å表 |
| | | * @return ç»æ |
| | | */ |
| | | public static String format(final String strPattern, final Object... argArray) |
| | | { |
| | | if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) |
| | | { |
| | | return strPattern; |
| | | } |
| | | final int strPatternLength = strPattern.length(); |
| | | |
| | | // åå§åå®ä¹å¥½çé¿åº¦ä»¥è·å¾æ´å¥½çæ§è½ |
| | | StringBuilder sbuf = new StringBuilder(strPatternLength + 50); |
| | | |
| | | int handledPosition = 0; |
| | | int delimIndex;// å ä½ç¬¦æå¨ä½ç½® |
| | | for (int argIndex = 0; argIndex < argArray.length; argIndex++) |
| | | { |
| | | delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); |
| | | if (delimIndex == -1) |
| | | { |
| | | if (handledPosition == 0) |
| | | { |
| | | return strPattern; |
| | | } |
| | | else |
| | | { // å符串模æ¿å©ä½é¨åä¸åå
å«å ä½ç¬¦ï¼å å
¥å©ä½é¨ååè¿åç»æ |
| | | sbuf.append(strPattern, handledPosition, strPatternLength); |
| | | return sbuf.toString(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) |
| | | { |
| | | if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) |
| | | { |
| | | // 转ä¹ç¬¦ä¹åè¿æä¸ä¸ªè½¬ä¹ç¬¦ï¼å ä½ç¬¦ä¾æ§ææ |
| | | sbuf.append(strPattern, handledPosition, delimIndex - 1); |
| | | sbuf.append(Convert.utf8Str(argArray[argIndex])); |
| | | handledPosition = delimIndex + 2; |
| | | } |
| | | else |
| | | { |
| | | // å ä½ç¬¦è¢«è½¬ä¹ |
| | | argIndex--; |
| | | sbuf.append(strPattern, handledPosition, delimIndex - 1); |
| | | sbuf.append(C_DELIM_START); |
| | | handledPosition = delimIndex + 1; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // æ£å¸¸å ä½ç¬¦ |
| | | sbuf.append(strPattern, handledPosition, delimIndex); |
| | | sbuf.append(Convert.utf8Str(argArray[argIndex])); |
| | | handledPosition = delimIndex + 2; |
| | | } |
| | | } |
| | | } |
| | | // å å
¥æåä¸ä¸ªå ä½ç¬¦åææçå符 |
| | | sbuf.append(strPattern, handledPosition, strPattern.length()); |
| | | |
| | | return sbuf.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * æä½ç¶æ |
| | | * |
| | | * @author jc |
| | | * |
| | | */ |
| | | public enum BusinessStatus |
| | | { |
| | | /** |
| | | * æå |
| | | */ |
| | | SUCCESS, |
| | | |
| | | /** |
| | | * 失败 |
| | | */ |
| | | FAIL, |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * ä¸å¡æä½ç±»å |
| | | * |
| | | * @author jc |
| | | */ |
| | | public enum BusinessType |
| | | { |
| | | /** |
| | | * å
¶å® |
| | | */ |
| | | OTHER, |
| | | |
| | | /** |
| | | * æ°å¢ |
| | | */ |
| | | INSERT, |
| | | |
| | | /** |
| | | * ä¿®æ¹ |
| | | */ |
| | | UPDATE, |
| | | |
| | | /** |
| | | * å é¤ |
| | | */ |
| | | DELETE, |
| | | |
| | | /** |
| | | * ææ |
| | | */ |
| | | GRANT, |
| | | |
| | | /** |
| | | * å¯¼åº |
| | | */ |
| | | EXPORT, |
| | | |
| | | /** |
| | | * 导å
¥ |
| | | */ |
| | | IMPORT, |
| | | |
| | | /** |
| | | * 强é |
| | | */ |
| | | FORCE, |
| | | |
| | | /** |
| | | * çæ代ç |
| | | */ |
| | | GENCODE, |
| | | |
| | | /** |
| | | * æ¸
空æ°æ® |
| | | */ |
| | | CLEAN, |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * æ°æ®æº |
| | | * |
| | | * @author jc |
| | | */ |
| | | public enum DataSourceType |
| | | { |
| | | /** |
| | | * ä¸»åº |
| | | */ |
| | | MASTER, |
| | | |
| | | /** |
| | | * ä»åº |
| | | */ |
| | | SLAVE |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import org.springframework.lang.Nullable; |
| | | |
| | | /** |
| | | * 请æ±æ¹å¼ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public enum HttpMethod |
| | | { |
| | | GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; |
| | | |
| | | private static final Map<String, HttpMethod> mappings = new HashMap<>(16); |
| | | |
| | | static |
| | | { |
| | | for (HttpMethod httpMethod : values()) |
| | | { |
| | | mappings.put(httpMethod.name(), httpMethod); |
| | | } |
| | | } |
| | | |
| | | @Nullable |
| | | public static HttpMethod resolve(@Nullable String method) |
| | | { |
| | | return (method != null ? mappings.get(method) : null); |
| | | } |
| | | |
| | | public boolean matches(String method) |
| | | { |
| | | return (this == resolve(method)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * éæµç±»å |
| | | * |
| | | * @author jc |
| | | */ |
| | | |
| | | public enum LimitType |
| | | { |
| | | /** |
| | | * é»è®¤çç¥å
¨å±éæµ |
| | | */ |
| | | DEFAULT, |
| | | |
| | | /** |
| | | * æ ¹æ®è¯·æ±è
IPè¿è¡éæµ |
| | | */ |
| | | IP |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * æä½äººç±»å« |
| | | * |
| | | * @author jc |
| | | */ |
| | | public enum OperatorType |
| | | { |
| | | /** |
| | | * å
¶å® |
| | | */ |
| | | OTHER, |
| | | |
| | | /** |
| | | * åå°ç¨æ· |
| | | */ |
| | | MANAGE, |
| | | |
| | | /** |
| | | * ææºç«¯ç¨æ· |
| | | */ |
| | | MOBILE |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.enums; |
| | | |
| | | /** |
| | | * ç¨æ·ç¶æ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public enum UserStatus |
| | | { |
| | | OK("0", "æ£å¸¸"), DISABLE("1", "åç¨"), DELETED("2", "å é¤"); |
| | | |
| | | private final String code; |
| | | private final String info; |
| | | |
| | | UserStatus(String code, String info) |
| | | { |
| | | this.code = code; |
| | | this.info = info; |
| | | } |
| | | |
| | | public String getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public String getInfo() |
| | | { |
| | | return info; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception; |
| | | |
| | | /** |
| | | * æ¼ç¤ºæ¨¡å¼å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class DemoModeException extends RuntimeException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public DemoModeException() |
| | | { |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception; |
| | | |
| | | /** |
| | | * å
¨å±å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class GlobalException extends RuntimeException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * é误æ示 |
| | | */ |
| | | private String message; |
| | | |
| | | /** |
| | | * é误æç»ï¼å
é¨è°è¯é误 |
| | | * |
| | | * å {@link CommonResult#getDetailMessage()} ä¸è´ç设计 |
| | | */ |
| | | private String detailMessage; |
| | | |
| | | /** |
| | | * 空æé æ¹æ³ï¼é¿å
ååºååé®é¢ |
| | | */ |
| | | public GlobalException() |
| | | { |
| | | } |
| | | |
| | | public GlobalException(String message) |
| | | { |
| | | this.message = message; |
| | | } |
| | | |
| | | public String getDetailMessage() |
| | | { |
| | | return detailMessage; |
| | | } |
| | | |
| | | public GlobalException setDetailMessage(String detailMessage) |
| | | { |
| | | this.detailMessage = detailMessage; |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public String getMessage() |
| | | { |
| | | return message; |
| | | } |
| | | |
| | | public GlobalException setMessage(String message) |
| | | { |
| | | this.message = message; |
| | | return this; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception; |
| | | |
| | | /** |
| | | * ä¸å¡å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public final class ServiceException extends RuntimeException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * é误ç |
| | | */ |
| | | private Integer code; |
| | | |
| | | /** |
| | | * é误æ示 |
| | | */ |
| | | private String message; |
| | | |
| | | /** |
| | | * é误æç»ï¼å
é¨è°è¯é误 |
| | | * |
| | | * å {@link CommonResult#getDetailMessage()} ä¸è´ç设计 |
| | | */ |
| | | private String detailMessage; |
| | | |
| | | /** |
| | | * 空æé æ¹æ³ï¼é¿å
ååºååé®é¢ |
| | | */ |
| | | public ServiceException() |
| | | { |
| | | } |
| | | |
| | | public ServiceException(String message) |
| | | { |
| | | this.message = message; |
| | | } |
| | | |
| | | public ServiceException(String message, Integer code) |
| | | { |
| | | this.message = message; |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getDetailMessage() |
| | | { |
| | | return detailMessage; |
| | | } |
| | | |
| | | @Override |
| | | public String getMessage() |
| | | { |
| | | return message; |
| | | } |
| | | |
| | | public Integer getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public ServiceException setMessage(String message) |
| | | { |
| | | this.message = message; |
| | | return this; |
| | | } |
| | | |
| | | public ServiceException setDetailMessage(String detailMessage) |
| | | { |
| | | this.detailMessage = detailMessage; |
| | | return this; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception; |
| | | |
| | | /** |
| | | * å·¥å
·ç±»å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UtilException extends RuntimeException |
| | | { |
| | | private static final long serialVersionUID = 8247610319171014183L; |
| | | |
| | | public UtilException(Throwable e) |
| | | { |
| | | super(e.getMessage(), e); |
| | | } |
| | | |
| | | public UtilException(String message) |
| | | { |
| | | super(message); |
| | | } |
| | | |
| | | public UtilException(String message, Throwable throwable) |
| | | { |
| | | super(message, throwable); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.base; |
| | | |
| | | import com.jcdm.common.utils.MessageUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * åºç¡å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BaseException extends RuntimeException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * æå±æ¨¡å |
| | | */ |
| | | private String module; |
| | | |
| | | /** |
| | | * é误ç |
| | | */ |
| | | private String code; |
| | | |
| | | /** |
| | | * é误ç 对åºçåæ° |
| | | */ |
| | | private Object[] args; |
| | | |
| | | /** |
| | | * é误æ¶æ¯ |
| | | */ |
| | | private String defaultMessage; |
| | | |
| | | public BaseException(String module, String code, Object[] args, String defaultMessage) |
| | | { |
| | | this.module = module; |
| | | this.code = code; |
| | | this.args = args; |
| | | this.defaultMessage = defaultMessage; |
| | | } |
| | | |
| | | public BaseException(String module, String code, Object[] args) |
| | | { |
| | | this(module, code, args, null); |
| | | } |
| | | |
| | | public BaseException(String module, String defaultMessage) |
| | | { |
| | | this(module, null, null, defaultMessage); |
| | | } |
| | | |
| | | public BaseException(String code, Object[] args) |
| | | { |
| | | this(null, code, args, null); |
| | | } |
| | | |
| | | public BaseException(String defaultMessage) |
| | | { |
| | | this(null, null, null, defaultMessage); |
| | | } |
| | | |
| | | @Override |
| | | public String getMessage() |
| | | { |
| | | String message = null; |
| | | if (!StringUtils.isEmpty(code)) |
| | | { |
| | | message = MessageUtils.message(code, args); |
| | | } |
| | | if (message == null) |
| | | { |
| | | message = defaultMessage; |
| | | } |
| | | return message; |
| | | } |
| | | |
| | | public String getModule() |
| | | { |
| | | return module; |
| | | } |
| | | |
| | | public String getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public Object[] getArgs() |
| | | { |
| | | return args; |
| | | } |
| | | |
| | | public String getDefaultMessage() |
| | | { |
| | | return defaultMessage; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.file; |
| | | |
| | | import com.jcdm.common.exception.base.BaseException; |
| | | |
| | | /** |
| | | * æ件信æ¯å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileException extends BaseException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public FileException(String code, Object[] args) |
| | | { |
| | | super("file", code, args, null); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.file; |
| | | |
| | | /** |
| | | * æ件å称è¶
é¿éå¶å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileNameLengthLimitExceededException extends FileException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public FileNameLengthLimitExceededException(int defaultFileNameLength) |
| | | { |
| | | super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.file; |
| | | |
| | | /** |
| | | * æ件å大å°éå¶å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileSizeLimitExceededException extends FileException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public FileSizeLimitExceededException(long defaultMaxSize) |
| | | { |
| | | super("upload.exceed.maxSize", new Object[] { defaultMaxSize }); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.file; |
| | | |
| | | import java.io.PrintStream; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * æ件ä¸ä¼ å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileUploadException extends Exception |
| | | { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private final Throwable cause; |
| | | |
| | | public FileUploadException() |
| | | { |
| | | this(null, null); |
| | | } |
| | | |
| | | public FileUploadException(final String msg) |
| | | { |
| | | this(msg, null); |
| | | } |
| | | |
| | | public FileUploadException(String msg, Throwable cause) |
| | | { |
| | | super(msg); |
| | | this.cause = cause; |
| | | } |
| | | |
| | | @Override |
| | | public void printStackTrace(PrintStream stream) |
| | | { |
| | | super.printStackTrace(stream); |
| | | if (cause != null) |
| | | { |
| | | stream.println("Caused by:"); |
| | | cause.printStackTrace(stream); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void printStackTrace(PrintWriter writer) |
| | | { |
| | | super.printStackTrace(writer); |
| | | if (cause != null) |
| | | { |
| | | writer.println("Caused by:"); |
| | | cause.printStackTrace(writer); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Throwable getCause() |
| | | { |
| | | return cause; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.file; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * æ件ä¸ä¼ 误å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class InvalidExtensionException extends FileUploadException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String[] allowedExtension; |
| | | private String extension; |
| | | private String filename; |
| | | |
| | | public InvalidExtensionException(String[] allowedExtension, String extension, String filename) |
| | | { |
| | | super("æ件[" + filename + "]åç¼[" + extension + "]ä¸æ£ç¡®ï¼è¯·ä¸ä¼ " + Arrays.toString(allowedExtension) + "æ ¼å¼"); |
| | | this.allowedExtension = allowedExtension; |
| | | this.extension = extension; |
| | | this.filename = filename; |
| | | } |
| | | |
| | | public String[] getAllowedExtension() |
| | | { |
| | | return allowedExtension; |
| | | } |
| | | |
| | | public String getExtension() |
| | | { |
| | | return extension; |
| | | } |
| | | |
| | | public String getFilename() |
| | | { |
| | | return filename; |
| | | } |
| | | |
| | | public static class InvalidImageExtensionException extends InvalidExtensionException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) |
| | | { |
| | | super(allowedExtension, extension, filename); |
| | | } |
| | | } |
| | | |
| | | public static class InvalidFlashExtensionException extends InvalidExtensionException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) |
| | | { |
| | | super(allowedExtension, extension, filename); |
| | | } |
| | | } |
| | | |
| | | public static class InvalidMediaExtensionException extends InvalidExtensionException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) |
| | | { |
| | | super(allowedExtension, extension, filename); |
| | | } |
| | | } |
| | | |
| | | public static class InvalidVideoExtensionException extends InvalidExtensionException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) |
| | | { |
| | | super(allowedExtension, extension, filename); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.job; |
| | | |
| | | /** |
| | | * 计åçç¥å¼å¸¸ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class TaskException extends Exception |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Code code; |
| | | |
| | | public TaskException(String msg, Code code) |
| | | { |
| | | this(msg, code, null); |
| | | } |
| | | |
| | | public TaskException(String msg, Code code, Exception nestedEx) |
| | | { |
| | | super(msg, nestedEx); |
| | | this.code = code; |
| | | } |
| | | |
| | | public Code getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public enum Code |
| | | { |
| | | TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * é»ååIPå¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BlackListException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public BlackListException() |
| | | { |
| | | super("login.blocked", null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * éªè¯ç é误å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class CaptchaException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public CaptchaException() |
| | | { |
| | | super("user.jcaptcha.error", null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * éªè¯ç 失æå¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class CaptchaExpireException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public CaptchaExpireException() |
| | | { |
| | | super("user.jcaptcha.expire", null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | import com.jcdm.common.exception.base.BaseException; |
| | | |
| | | /** |
| | | * ç¨æ·ä¿¡æ¯å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UserException extends BaseException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public UserException(String code, Object[] args) |
| | | { |
| | | super("user", code, args, null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * ç¨æ·ä¸åå¨å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UserNotExistsException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public UserNotExistsException() |
| | | { |
| | | super("user.not.exists", null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * ç¨æ·å¯ç ä¸æ£ç¡®æä¸ç¬¦åè§èå¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UserPasswordNotMatchException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public UserPasswordNotMatchException() |
| | | { |
| | | super("user.password.not.match", null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.exception.user; |
| | | |
| | | /** |
| | | * ç¨æ·é误æ大次æ°å¼å¸¸ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class UserPasswordRetryLimitExceedException extends UserException |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime) |
| | | { |
| | | super("user.password.retry.limit.exceed", new Object[] { retryLimitCount, lockTime }); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.filter; |
| | | |
| | | import com.alibaba.fastjson2.filter.SimplePropertyPreFilter; |
| | | |
| | | /** |
| | | * æé¤JSONææå±æ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class PropertyPreExcludeFilter extends SimplePropertyPreFilter |
| | | { |
| | | public PropertyPreExcludeFilter() |
| | | { |
| | | } |
| | | |
| | | public PropertyPreExcludeFilter addExcludes(String... filters) |
| | | { |
| | | for (int i = 0; i < filters.length; i++) |
| | | { |
| | | this.getExcludes().add(filters[i]); |
| | | } |
| | | return this; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.filter; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.Filter; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.FilterConfig; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.http.MediaType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * Repeatable è¿æ»¤å¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class RepeatableFilter implements Filter |
| | | { |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | ServletRequest requestWrapper = null; |
| | | if (request instanceof HttpServletRequest |
| | | && StringUtils.startsWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) |
| | | { |
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); |
| | | } |
| | | if (null == requestWrapper) |
| | | { |
| | | chain.doFilter(request, response); |
| | | } |
| | | else |
| | | { |
| | | chain.doFilter(requestWrapper, response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.filter; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import javax.servlet.ReadListener; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import com.jcdm.common.utils.http.HttpHelper; |
| | | import com.jcdm.common.constant.Constants; |
| | | |
| | | /** |
| | | * æ建å¯éå¤è¯»åinputStreamçrequest |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper |
| | | { |
| | | private final byte[] body; |
| | | |
| | | public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException |
| | | { |
| | | super(request); |
| | | request.setCharacterEncoding(Constants.UTF8); |
| | | response.setCharacterEncoding(Constants.UTF8); |
| | | |
| | | body = HttpHelper.getBodyString(request).getBytes(Constants.UTF8); |
| | | } |
| | | |
| | | @Override |
| | | public BufferedReader getReader() throws IOException |
| | | { |
| | | return new BufferedReader(new InputStreamReader(getInputStream())); |
| | | } |
| | | |
| | | @Override |
| | | public ServletInputStream getInputStream() throws IOException |
| | | { |
| | | final ByteArrayInputStream bais = new ByteArrayInputStream(body); |
| | | return new ServletInputStream() |
| | | { |
| | | @Override |
| | | public int read() throws IOException |
| | | { |
| | | return bais.read(); |
| | | } |
| | | |
| | | @Override |
| | | public int available() throws IOException |
| | | { |
| | | return body.length; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isFinished() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isReady() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public void setReadListener(ReadListener readListener) |
| | | { |
| | | |
| | | } |
| | | }; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.filter; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import javax.servlet.Filter; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.FilterConfig; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.enums.HttpMethod; |
| | | |
| | | /** |
| | | * é²æ¢XSSæ»å»çè¿æ»¤å¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class XssFilter implements Filter |
| | | { |
| | | /** |
| | | * æé¤é¾æ¥ |
| | | */ |
| | | public List<String> excludes = new ArrayList<>(); |
| | | |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | String tempExcludes = filterConfig.getInitParameter("excludes"); |
| | | if (StringUtils.isNotEmpty(tempExcludes)) |
| | | { |
| | | String[] url = tempExcludes.split(","); |
| | | for (int i = 0; url != null && i < url.length; i++) |
| | | { |
| | | excludes.add(url[i]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | HttpServletRequest req = (HttpServletRequest) request; |
| | | HttpServletResponse resp = (HttpServletResponse) response; |
| | | if (handleExcludeURL(req, resp)) |
| | | { |
| | | chain.doFilter(request, response); |
| | | return; |
| | | } |
| | | XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request); |
| | | chain.doFilter(xssRequest, response); |
| | | } |
| | | |
| | | private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) |
| | | { |
| | | String url = request.getServletPath(); |
| | | String method = request.getMethod(); |
| | | // GET DELETE ä¸è¿æ»¤ |
| | | if (method == null || HttpMethod.GET.matches(method) || HttpMethod.DELETE.matches(method)) |
| | | { |
| | | return true; |
| | | } |
| | | return StringUtils.matches(url, excludes); |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.filter; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import javax.servlet.ReadListener; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.html.EscapeUtil; |
| | | |
| | | /** |
| | | * XSSè¿æ»¤å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper |
| | | { |
| | | /** |
| | | * @param request |
| | | */ |
| | | public XssHttpServletRequestWrapper(HttpServletRequest request) |
| | | { |
| | | super(request); |
| | | } |
| | | |
| | | @Override |
| | | public String[] getParameterValues(String name) |
| | | { |
| | | String[] values = super.getParameterValues(name); |
| | | if (values != null) |
| | | { |
| | | int length = values.length; |
| | | String[] escapesValues = new String[length]; |
| | | for (int i = 0; i < length; i++) |
| | | { |
| | | // é²xssæ»å»åè¿æ»¤ååç©ºæ ¼ |
| | | escapesValues[i] = EscapeUtil.clean(values[i]).trim(); |
| | | } |
| | | return escapesValues; |
| | | } |
| | | return super.getParameterValues(name); |
| | | } |
| | | |
| | | @Override |
| | | public ServletInputStream getInputStream() throws IOException |
| | | { |
| | | // éjsonç±»åï¼ç´æ¥è¿å |
| | | if (!isJsonRequest()) |
| | | { |
| | | return super.getInputStream(); |
| | | } |
| | | |
| | | // 为空ï¼ç´æ¥è¿å |
| | | String json = IOUtils.toString(super.getInputStream(), "utf-8"); |
| | | if (StringUtils.isEmpty(json)) |
| | | { |
| | | return super.getInputStream(); |
| | | } |
| | | |
| | | // xssè¿æ»¤ |
| | | json = EscapeUtil.clean(json).trim(); |
| | | byte[] jsonBytes = json.getBytes("utf-8"); |
| | | final ByteArrayInputStream bis = new ByteArrayInputStream(jsonBytes); |
| | | return new ServletInputStream() |
| | | { |
| | | @Override |
| | | public boolean isFinished() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isReady() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public int available() throws IOException |
| | | { |
| | | return jsonBytes.length; |
| | | } |
| | | |
| | | @Override |
| | | public void setReadListener(ReadListener readListener) |
| | | { |
| | | } |
| | | |
| | | @Override |
| | | public int read() throws IOException |
| | | { |
| | | return bis.read(); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ¯Jsonè¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public boolean isJsonRequest() |
| | | { |
| | | String header = super.getHeader(HttpHeaders.CONTENT_TYPE); |
| | | return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | /** |
| | | * 精确çæµ®ç¹æ°è¿ç® |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class Arith |
| | | { |
| | | |
| | | /** é»è®¤é¤æ³è¿ç®ç²¾åº¦ */ |
| | | private static final int DEF_DIV_SCALE = 10; |
| | | |
| | | /** è¿ä¸ªç±»ä¸è½å®ä¾å */ |
| | | private Arith() |
| | | { |
| | | } |
| | | |
| | | /** |
| | | * æä¾ç²¾ç¡®çå æ³è¿ç®ã |
| | | * @param v1 被å æ° |
| | | * @param v2 å æ° |
| | | * @return 两个åæ°çå |
| | | */ |
| | | public static double add(double v1, double v2) |
| | | { |
| | | BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
| | | BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
| | | return b1.add(b2).doubleValue(); |
| | | } |
| | | |
| | | /** |
| | | * æä¾ç²¾ç¡®çåæ³è¿ç®ã |
| | | * @param v1 被åæ° |
| | | * @param v2 åæ° |
| | | * @return 两个åæ°çå·® |
| | | */ |
| | | public static double sub(double v1, double v2) |
| | | { |
| | | BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
| | | BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
| | | return b1.subtract(b2).doubleValue(); |
| | | } |
| | | |
| | | /** |
| | | * æä¾ç²¾ç¡®çä¹æ³è¿ç®ã |
| | | * @param v1 被ä¹æ° |
| | | * @param v2 ä¹æ° |
| | | * @return 两个åæ°ç积 |
| | | */ |
| | | public static double mul(double v1, double v2) |
| | | { |
| | | BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
| | | BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
| | | return b1.multiply(b2).doubleValue(); |
| | | } |
| | | |
| | | /** |
| | | * æä¾ï¼ç¸å¯¹ï¼ç²¾ç¡®çé¤æ³è¿ç®ï¼å½åçé¤ä¸å°½çæ
åµæ¶ï¼ç²¾ç¡®å° |
| | | * å°æ°ç¹ä»¥å10ä½ï¼ä»¥åçæ°ååèäºå
¥ã |
| | | * @param v1 被é¤æ° |
| | | * @param v2 é¤æ° |
| | | * @return 两个åæ°çå |
| | | */ |
| | | public static double div(double v1, double v2) |
| | | { |
| | | return div(v1, v2, DEF_DIV_SCALE); |
| | | } |
| | | |
| | | /** |
| | | * æä¾ï¼ç¸å¯¹ï¼ç²¾ç¡®çé¤æ³è¿ç®ãå½åçé¤ä¸å°½çæ
åµæ¶ï¼ç±scaleåæ°æ |
| | | * å®ç²¾åº¦ï¼ä»¥åçæ°ååèäºå
¥ã |
| | | * @param v1 被é¤æ° |
| | | * @param v2 é¤æ° |
| | | * @param scale 表示表示éè¦ç²¾ç¡®å°å°æ°ç¹ä»¥åå ä½ã |
| | | * @return 两个åæ°çå |
| | | */ |
| | | public static double div(double v1, double v2, int scale) |
| | | { |
| | | if (scale < 0) |
| | | { |
| | | throw new IllegalArgumentException( |
| | | "The scale must be a positive integer or zero"); |
| | | } |
| | | BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
| | | BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
| | | if (b1.compareTo(BigDecimal.ZERO) == 0) |
| | | { |
| | | return BigDecimal.ZERO.doubleValue(); |
| | | } |
| | | return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | |
| | | /** |
| | | * æä¾ç²¾ç¡®çå°æ°ä½åèäºå
¥å¤çã |
| | | * @param v éè¦åèäºå
¥çæ°å |
| | | * @param scale å°æ°ç¹åä¿çå ä½ |
| | | * @return åèäºå
¥åçç»æ |
| | | */ |
| | | public static double round(double v, int scale) |
| | | { |
| | | if (scale < 0) |
| | | { |
| | | throw new IllegalArgumentException( |
| | | "The scale must be a positive integer or zero"); |
| | | } |
| | | BigDecimal b = new BigDecimal(Double.toString(v)); |
| | | BigDecimal one = BigDecimal.ONE; |
| | | return b.divide(one, scale, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.lang.management.ManagementFactory; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | |
| | | /** |
| | | * æ¶é´å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class DateUtils extends org.apache.commons.lang3.time.DateUtils |
| | | { |
| | | public static String YYYY = "yyyy"; |
| | | |
| | | public static String YYYY_MM = "yyyy-MM"; |
| | | |
| | | public static String YYYY_MM_DD = "yyyy-MM-dd"; |
| | | |
| | | public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; |
| | | |
| | | public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; |
| | | |
| | | private static String[] parsePatterns = { |
| | | "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", |
| | | "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", |
| | | "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; |
| | | |
| | | /** |
| | | * è·åå½åDateåæ¥æ |
| | | * |
| | | * @return Date() å½åæ¥æ |
| | | */ |
| | | public static Date getNowDate() |
| | | { |
| | | return new Date(); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åæ¥æ, é»è®¤æ ¼å¼ä¸ºyyyy-MM-dd |
| | | * |
| | | * @return String |
| | | */ |
| | | public static String getDate() |
| | | { |
| | | return dateTimeNow(YYYY_MM_DD); |
| | | } |
| | | |
| | | public static final String getTime() |
| | | { |
| | | return dateTimeNow(YYYY_MM_DD_HH_MM_SS); |
| | | } |
| | | |
| | | public static final String dateTimeNow() |
| | | { |
| | | return dateTimeNow(YYYYMMDDHHMMSS); |
| | | } |
| | | |
| | | public static final String dateTimeNow(final String format) |
| | | { |
| | | return parseDateToStr(format, new Date()); |
| | | } |
| | | |
| | | public static final String dateTime(final Date date) |
| | | { |
| | | return parseDateToStr(YYYY_MM_DD, date); |
| | | } |
| | | |
| | | public static final String parseDateToStr(final String format, final Date date) |
| | | { |
| | | return new SimpleDateFormat(format).format(date); |
| | | } |
| | | |
| | | public static final Date dateTime(final String format, final String ts) |
| | | { |
| | | try |
| | | { |
| | | return new SimpleDateFormat(format).parse(ts); |
| | | } |
| | | catch (ParseException e) |
| | | { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥æè·¯å¾ å³å¹´/æ/æ¥ å¦2018/08/08 |
| | | */ |
| | | public static final String datePath() |
| | | { |
| | | Date now = new Date(); |
| | | return DateFormatUtils.format(now, "yyyy/MM/dd"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æè·¯å¾ å³å¹´/æ/æ¥ å¦20180808 |
| | | */ |
| | | public static final String dateTime() |
| | | { |
| | | Date now = new Date(); |
| | | return DateFormatUtils.format(now, "yyyyMMdd"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æåå符串转å为æ¥æ æ ¼å¼ |
| | | */ |
| | | public static Date parseDate(Object str) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return null; |
| | | } |
| | | try |
| | | { |
| | | return parseDate(str.toString(), parsePatterns); |
| | | } |
| | | catch (ParseException e) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæå¡å¨å¯å¨æ¶é´ |
| | | */ |
| | | public static Date getServerStartDate() |
| | | { |
| | | long time = ManagementFactory.getRuntimeMXBean().getStartTime(); |
| | | return new Date(time); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ç¸å·®å¤©æ° |
| | | */ |
| | | public static int differentDaysByMillisecond(Date date1, Date date2) |
| | | { |
| | | return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®æ¶é´å·® |
| | | * |
| | | * @param endDate æåæ¶é´ |
| | | * @param startTime å¼å§æ¶é´ |
| | | * @return æ¶é´å·®ï¼å¤©/å°æ¶/åéï¼ |
| | | */ |
| | | public static String timeDistance(Date endDate, Date startTime) |
| | | { |
| | | long nd = 1000 * 24 * 60 * 60; |
| | | long nh = 1000 * 60 * 60; |
| | | long nm = 1000 * 60; |
| | | // long ns = 1000; |
| | | // è·å¾ä¸¤ä¸ªæ¶é´ç毫ç§æ¶é´å·®å¼ |
| | | long diff = endDate.getTime() - startTime.getTime(); |
| | | // 计ç®å·®å¤å°å¤© |
| | | long day = diff / nd; |
| | | // 计ç®å·®å¤å°å°æ¶ |
| | | long hour = diff % nd / nh; |
| | | // 计ç®å·®å¤å°åé |
| | | long min = diff % nd % nh / nm; |
| | | // 计ç®å·®å¤å°ç§//è¾åºç»æ |
| | | // long sec = diff % nd % nh % nm / ns; |
| | | return day + "天" + hour + "å°æ¶" + min + "åé"; |
| | | } |
| | | |
| | | /** |
| | | * å¢å LocalDateTime ==> Date |
| | | */ |
| | | public static Date toDate(LocalDateTime temporalAccessor) |
| | | { |
| | | ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault()); |
| | | return Date.from(zdt.toInstant()); |
| | | } |
| | | |
| | | /** |
| | | * å¢å LocalDate ==> Date |
| | | */ |
| | | public static Date toDate(LocalDate temporalAccessor) |
| | | { |
| | | LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0)); |
| | | ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); |
| | | return Date.from(zdt.toInstant()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.core.domain.entity.SysDictData; |
| | | import com.jcdm.common.core.redis.RedisCache; |
| | | import com.jcdm.common.utils.spring.SpringUtils; |
| | | |
| | | /** |
| | | * åå
¸å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class DictUtils |
| | | { |
| | | /** |
| | | * åé符 |
| | | */ |
| | | public static final String SEPARATOR = ","; |
| | | |
| | | /** |
| | | * 设置åå
¸ç¼å |
| | | * |
| | | * @param key åæ°é® |
| | | * @param dictDatas åå
¸æ°æ®å表 |
| | | */ |
| | | public static void setDictCache(String key, List<SysDictData> dictDatas) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); |
| | | } |
| | | |
| | | // /** |
| | | // * è·ååå
¸ç¼å |
| | | // * |
| | | // * @param key åæ°é® |
| | | // * @return dictDatas åå
¸æ°æ®å表 |
| | | // */ |
| | | // public static List<SysDictData> getDictCache(String key) |
| | | // { |
| | | // JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); |
| | | // if (StringUtils.isNotNull(arrayCache)) |
| | | // { |
| | | // return arrayCache.toList(SysDictData.class); |
| | | // } |
| | | // return null; |
| | | // } |
| | | /** |
| | | * è·ååå
¸ç¼å |
| | | * |
| | | * @param key åæ°é® |
| | | * @return dictDatas åå
¸æ°æ®å表 |
| | | */ |
| | | public static List<SysDictData> getDictCache(String key) |
| | | { |
| | | JSONArray arrayCache = JSONArray.parseArray(JSON.toJSONString(SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)))); |
| | | // JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); |
| | | if (StringUtils.isNotNull(arrayCache)) |
| | | { |
| | | return arrayCache.toList(SysDictData.class); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸å¼ |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public static String getDictLabel(String dictType, String dictValue) |
| | | { |
| | | return getDictLabel(dictType, dictValue, SEPARATOR); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictLabel åå
¸æ ç¾ |
| | | * @return åå
¸å¼ |
| | | */ |
| | | public static String getDictValue(String dictType, String dictLabel) |
| | | { |
| | | return getDictValue(dictType, dictLabel, SEPARATOR); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸å¼ |
| | | * @param separator åé符 |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public static String getDictLabel(String dictType, String dictValue, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | List<SysDictData> datas = getDictCache(dictType); |
| | | |
| | | if (StringUtils.isNotNull(datas)) |
| | | { |
| | | if (StringUtils.containsAny(separator, dictValue)) |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | for (String value : dictValue.split(separator)) |
| | | { |
| | | if (value.equals(dict.getDictValue())) |
| | | { |
| | | propertyString.append(dict.getDictLabel()).append(separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | if (dictValue.equals(dict.getDictValue())) |
| | | { |
| | | return dict.getDictLabel(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.stripEnd(propertyString.toString(), separator); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictLabel åå
¸æ ç¾ |
| | | * @param separator åé符 |
| | | * @return åå
¸å¼ |
| | | */ |
| | | public static String getDictValue(String dictType, String dictLabel, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | List<SysDictData> datas = getDictCache(dictType); |
| | | |
| | | if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)) |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | for (String label : dictLabel.split(separator)) |
| | | { |
| | | if (label.equals(dict.getDictLabel())) |
| | | { |
| | | propertyString.append(dict.getDictValue()).append(separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | if (dictLabel.equals(dict.getDictLabel())) |
| | | { |
| | | return dict.getDictValue(); |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.stripEnd(propertyString.toString(), separator); |
| | | } |
| | | |
| | | /** |
| | | * å é¤æå®åå
¸ç¼å |
| | | * |
| | | * @param key åå
¸é® |
| | | */ |
| | | public static void removeDictCache(String key) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空åå
¸ç¼å |
| | | */ |
| | | public static void clearDictCache() |
| | | { |
| | | Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(keys); |
| | | } |
| | | |
| | | /** |
| | | * 设置cache key |
| | | * |
| | | * @param configKey åæ°é® |
| | | * @return ç¼åé®key |
| | | */ |
| | | public static String getCacheKey(String configKey) |
| | | { |
| | | return CacheConstants.SYS_DICT_KEY + configKey; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.io.StringWriter; |
| | | import org.apache.commons.lang3.exception.ExceptionUtils; |
| | | |
| | | /** |
| | | * é误信æ¯å¤çç±»ã |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class ExceptionUtil |
| | | { |
| | | /** |
| | | * è·åexceptionç详ç»é误信æ¯ã |
| | | */ |
| | | public static String getExceptionMessage(Throwable e) |
| | | { |
| | | StringWriter sw = new StringWriter(); |
| | | e.printStackTrace(new PrintWriter(sw, true)); |
| | | return sw.toString(); |
| | | } |
| | | |
| | | public static String getRootErrorMessage(Exception e) |
| | | { |
| | | Throwable root = ExceptionUtils.getRootCause(e); |
| | | root = (root == null ? e : root); |
| | | if (root == null) |
| | | { |
| | | return ""; |
| | | } |
| | | String msg = root.getMessage(); |
| | | if (msg == null) |
| | | { |
| | | return "null"; |
| | | } |
| | | return StringUtils.defaultString(msg); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | /** |
| | | * å¤ç并记å½æ¥å¿æ件 |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class LogUtils |
| | | { |
| | | public static String getBlock(Object msg) |
| | | { |
| | | if (msg == null) |
| | | { |
| | | msg = ""; |
| | | } |
| | | return "[" + msg.toString() + "]"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import org.springframework.context.MessageSource; |
| | | import org.springframework.context.i18n.LocaleContextHolder; |
| | | import com.jcdm.common.utils.spring.SpringUtils; |
| | | |
| | | /** |
| | | * è·åi18nèµæºæ件 |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class MessageUtils |
| | | { |
| | | /** |
| | | * æ ¹æ®æ¶æ¯é®ååæ° è·åæ¶æ¯ å§æç»spring messageSource |
| | | * |
| | | * @param code æ¶æ¯é® |
| | | * @param args åæ° |
| | | * @return è·åå½é
åç¿»è¯å¼ |
| | | */ |
| | | public static String message(String code, Object... args) |
| | | { |
| | | MessageSource messageSource = SpringUtils.getBean(MessageSource.class); |
| | | return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.jcdm.common.core.page.PageDomain; |
| | | import com.jcdm.common.core.page.TableSupport; |
| | | import com.jcdm.common.utils.sql.SqlUtil; |
| | | |
| | | /** |
| | | * å页工å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class PageUtils extends PageHelper |
| | | { |
| | | /** |
| | | * 设置请æ±å页æ°æ® |
| | | */ |
| | | public static void startPage() |
| | | { |
| | | PageDomain pageDomain = TableSupport.buildPageRequest(); |
| | | Integer pageNum = pageDomain.getPageNum(); |
| | | Integer pageSize = pageDomain.getPageSize(); |
| | | String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); |
| | | Boolean reasonable = pageDomain.getReasonable(); |
| | | PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
çå页ç线ç¨åé |
| | | */ |
| | | public static void clearPage() |
| | | { |
| | | PageHelper.clearPage(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import org.springframework.util.PatternMatchUtils; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.constant.HttpStatus; |
| | | import com.jcdm.common.core.domain.entity.SysRole; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.exception.ServiceException; |
| | | |
| | | /** |
| | | * å®å
¨æå¡å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SecurityUtils |
| | | { |
| | | |
| | | /** |
| | | * ç¨æ·ID |
| | | **/ |
| | | public static Long getUserId() |
| | | { |
| | | try |
| | | { |
| | | return getLoginUser().getUserId(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("è·åç¨æ·IDå¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åé¨é¨ID |
| | | **/ |
| | | public static Long getDeptId() |
| | | { |
| | | try |
| | | { |
| | | return getLoginUser().getDeptId(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("è·åé¨é¨IDå¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·è´¦æ· |
| | | **/ |
| | | public static String getUsername() |
| | | { |
| | | try |
| | | { |
| | | return getLoginUser().getUsername(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("è·åç¨æ·è´¦æ·å¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ· |
| | | **/ |
| | | public static LoginUser getLoginUser() |
| | | { |
| | | try |
| | | { |
| | | return (LoginUser) getAuthentication().getPrincipal(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("è·åç¨æ·ä¿¡æ¯å¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åAuthentication |
| | | */ |
| | | public static Authentication getAuthentication() |
| | | { |
| | | return SecurityContextHolder.getContext().getAuthentication(); |
| | | } |
| | | |
| | | /** |
| | | * çæBCryptPasswordEncoderå¯ç |
| | | * |
| | | * @param password å¯ç |
| | | * @return å å¯å符串 |
| | | */ |
| | | public static String encryptPassword(String password) |
| | | { |
| | | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); |
| | | return passwordEncoder.encode(password); |
| | | } |
| | | |
| | | /** |
| | | * å¤æå¯ç æ¯å¦ç¸å |
| | | * |
| | | * @param rawPassword çå®å¯ç |
| | | * @param encodedPassword å å¯åå符 |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean matchesPassword(String rawPassword, String encodedPassword) |
| | | { |
| | | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); |
| | | return passwordEncoder.matches(rawPassword, encodedPassword); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºç®¡çå |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean isAdmin(Long userId) |
| | | { |
| | | return userId != null && 1L == userId; |
| | | } |
| | | |
| | | /** |
| | | * éªè¯ç¨æ·æ¯å¦å
·å¤ææé |
| | | * |
| | | * @param permission æéå符串 |
| | | * @return ç¨æ·æ¯å¦å
·å¤ææé |
| | | */ |
| | | public static boolean hasPermi(String permission) |
| | | { |
| | | return hasPermi(getLoginUser().getPermissions(), permission); |
| | | } |
| | | |
| | | /** |
| | | * å¤ææ¯å¦å
å«æé |
| | | * |
| | | * @param authorities æéå表 |
| | | * @param permission æéå符串 |
| | | * @return ç¨æ·æ¯å¦å
·å¤ææé |
| | | */ |
| | | public static boolean hasPermi(Collection<String> authorities, String permission) |
| | | { |
| | | return authorities.stream().filter(StringUtils::hasText) |
| | | .anyMatch(x -> Constants.ALL_PERMISSION.equals(x) || PatternMatchUtils.simpleMatch(x, permission)); |
| | | } |
| | | |
| | | /** |
| | | * éªè¯ç¨æ·æ¯å¦æ¥ææ个è§è² |
| | | * |
| | | * @param role è§è²æ è¯ |
| | | * @return ç¨æ·æ¯å¦å
·å¤æè§è² |
| | | */ |
| | | public static boolean hasRole(String role) |
| | | { |
| | | List<SysRole> roleList = getLoginUser().getUser().getRoles(); |
| | | Collection<String> roles = roleList.stream().map(SysRole::getRoleKey).collect(Collectors.toSet()); |
| | | return hasRole(roles, role); |
| | | } |
| | | |
| | | /** |
| | | * å¤ææ¯å¦å
å«è§è² |
| | | * |
| | | * @param roles è§è²å表 |
| | | * @param role è§è² |
| | | * @return ç¨æ·æ¯å¦å
·å¤æè§è²æé |
| | | */ |
| | | public static boolean hasRole(Collection<String> roles, String role) |
| | | { |
| | | return roles.stream().filter(StringUtils::hasText) |
| | | .anyMatch(x -> Constants.SUPER_ADMIN.equals(x) || PatternMatchUtils.simpleMatch(x, role)); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLDecoder; |
| | | import java.net.URLEncoder; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import org.springframework.web.context.request.RequestAttributes; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.core.text.Convert; |
| | | |
| | | /** |
| | | * 客æ·ç«¯å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class ServletUtils |
| | | { |
| | | /** |
| | | * è·åStringåæ° |
| | | */ |
| | | public static String getParameter(String name) |
| | | { |
| | | return getRequest().getParameter(name); |
| | | } |
| | | |
| | | /** |
| | | * è·åStringåæ° |
| | | */ |
| | | public static String getParameter(String name, String defaultValue) |
| | | { |
| | | return Convert.toStr(getRequest().getParameter(name), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * è·åIntegeråæ° |
| | | */ |
| | | public static Integer getParameterToInt(String name) |
| | | { |
| | | return Convert.toInt(getRequest().getParameter(name)); |
| | | } |
| | | |
| | | /** |
| | | * è·åIntegeråæ° |
| | | */ |
| | | public static Integer getParameterToInt(String name, Integer defaultValue) |
| | | { |
| | | return Convert.toInt(getRequest().getParameter(name), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * è·åBooleanåæ° |
| | | */ |
| | | public static Boolean getParameterToBool(String name) |
| | | { |
| | | return Convert.toBool(getRequest().getParameter(name)); |
| | | } |
| | | |
| | | /** |
| | | * è·åBooleanåæ° |
| | | */ |
| | | public static Boolean getParameterToBool(String name, Boolean defaultValue) |
| | | { |
| | | return Convert.toBool(getRequest().getParameter(name), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * è·å¾ææ请æ±åæ° |
| | | * |
| | | * @param request 请æ±å¯¹è±¡{@link ServletRequest} |
| | | * @return Map |
| | | */ |
| | | public static Map<String, String[]> getParams(ServletRequest request) |
| | | { |
| | | final Map<String, String[]> map = request.getParameterMap(); |
| | | return Collections.unmodifiableMap(map); |
| | | } |
| | | |
| | | /** |
| | | * è·å¾ææ请æ±åæ° |
| | | * |
| | | * @param request 请æ±å¯¹è±¡{@link ServletRequest} |
| | | * @return Map |
| | | */ |
| | | public static Map<String, String> getParamMap(ServletRequest request) |
| | | { |
| | | Map<String, String> params = new HashMap<>(); |
| | | for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) |
| | | { |
| | | params.put(entry.getKey(), StringUtils.join(entry.getValue(), ",")); |
| | | } |
| | | return params; |
| | | } |
| | | |
| | | /** |
| | | * è·årequest |
| | | */ |
| | | public static HttpServletRequest getRequest() |
| | | { |
| | | return getRequestAttributes().getRequest(); |
| | | } |
| | | |
| | | /** |
| | | * è·åresponse |
| | | */ |
| | | public static HttpServletResponse getResponse() |
| | | { |
| | | return getRequestAttributes().getResponse(); |
| | | } |
| | | |
| | | /** |
| | | * è·åsession |
| | | */ |
| | | public static HttpSession getSession() |
| | | { |
| | | return getRequest().getSession(); |
| | | } |
| | | |
| | | public static ServletRequestAttributes getRequestAttributes() |
| | | { |
| | | RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); |
| | | return (ServletRequestAttributes) attributes; |
| | | } |
| | | |
| | | /** |
| | | * å°å符串渲æå°å®¢æ·ç«¯ |
| | | * |
| | | * @param response 渲æ对象 |
| | | * @param string å¾
渲æçå符串 |
| | | */ |
| | | public static void renderString(HttpServletResponse response, String string) |
| | | { |
| | | try |
| | | { |
| | | response.setStatus(200); |
| | | response.setContentType("application/json"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.getWriter().print(string); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ¯Ajaxå¼æ¥è¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public static boolean isAjaxRequest(HttpServletRequest request) |
| | | { |
| | | String accept = request.getHeader("accept"); |
| | | if (accept != null && accept.contains("application/json")) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | String xRequestedWith = request.getHeader("X-Requested-With"); |
| | | if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | String uri = request.getRequestURI(); |
| | | if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | String ajax = request.getParameter("__ajax"); |
| | | return StringUtils.inStringIgnoreCase(ajax, "json", "xml"); |
| | | } |
| | | |
| | | /** |
| | | * å
容ç¼ç |
| | | * |
| | | * @param str å
容 |
| | | * @return ç¼ç åçå
容 |
| | | */ |
| | | public static String urlEncode(String str) |
| | | { |
| | | try |
| | | { |
| | | return URLEncoder.encode(str, Constants.UTF8); |
| | | } |
| | | catch (UnsupportedEncodingException e) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å
容解ç |
| | | * |
| | | * @param str å
容 |
| | | * @return 解ç åçå
容 |
| | | */ |
| | | public static String urlDecode(String str) |
| | | { |
| | | try |
| | | { |
| | | return URLDecoder.decode(str, Constants.UTF8); |
| | | } |
| | | catch (UnsupportedEncodingException e) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import org.springframework.util.AntPathMatcher; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.core.text.StrFormatter; |
| | | |
| | | /** |
| | | * å符串工å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class StringUtils extends org.apache.commons.lang3.StringUtils |
| | | { |
| | | /** 空å符串 */ |
| | | private static final String NULLSTR = ""; |
| | | |
| | | /** ä¸å线 */ |
| | | private static final char SEPARATOR = '_'; |
| | | |
| | | /** |
| | | * è·ååæ°ä¸ä¸ºç©ºå¼ |
| | | * |
| | | * @param value defaultValue è¦å¤æçvalue |
| | | * @return value è¿åå¼ |
| | | */ |
| | | public static <T> T nvl(T value, T defaultValue) |
| | | { |
| | | return value != null ? value : defaultValue; |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªCollectionæ¯å¦ä¸ºç©ºï¼ å
å«Listï¼Setï¼Queue |
| | | * |
| | | * @param coll è¦å¤æçCollection |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Collection<?> coll) |
| | | { |
| | | return isNull(coll) || coll.isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªCollectionæ¯å¦é空ï¼å
å«Listï¼Setï¼Queue |
| | | * |
| | | * @param coll è¦å¤æçCollection |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Collection<?> coll) |
| | | { |
| | | return !isEmpty(coll); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå¯¹è±¡æ°ç»æ¯å¦ä¸ºç©º |
| | | * |
| | | * @param objects è¦å¤æç对象æ°ç» |
| | | ** @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Object[] objects) |
| | | { |
| | | return isNull(objects) || (objects.length == 0); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå¯¹è±¡æ°ç»æ¯å¦é空 |
| | | * |
| | | * @param objects è¦å¤æç对象æ°ç» |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Object[] objects) |
| | | { |
| | | return !isEmpty(objects); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªMapæ¯å¦ä¸ºç©º |
| | | * |
| | | * @param map è¦å¤æçMap |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Map<?, ?> map) |
| | | { |
| | | return isNull(map) || map.isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªMapæ¯å¦ä¸ºç©º |
| | | * |
| | | * @param map è¦å¤æçMap |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Map<?, ?> map) |
| | | { |
| | | return !isEmpty(map); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå符串æ¯å¦ä¸ºç©ºä¸² |
| | | * |
| | | * @param str String |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(String str) |
| | | { |
| | | return isNull(str) || NULLSTR.equals(str.trim()); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå符串æ¯å¦ä¸ºé空串 |
| | | * |
| | | * @param str String |
| | | * @return trueï¼é空串 falseï¼ç©ºä¸² |
| | | */ |
| | | public static boolean isNotEmpty(String str) |
| | | { |
| | | return !isEmpty(str); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå¯¹è±¡æ¯å¦ä¸ºç©º |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isNull(Object object) |
| | | { |
| | | return object == null; |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå¯¹è±¡æ¯å¦é空 |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotNull(Object object) |
| | | { |
| | | return !isNull(object); |
| | | } |
| | | |
| | | /** |
| | | * * å¤æä¸ä¸ªå¯¹è±¡æ¯å¦æ¯æ°ç»ç±»åï¼Javaåºæ¬åå«çæ°ç»ï¼ |
| | | * |
| | | * @param object 对象 |
| | | * @return trueï¼æ¯æ°ç» falseï¼ä¸æ¯æ°ç» |
| | | */ |
| | | public static boolean isArray(Object object) |
| | | { |
| | | return isNotNull(object) && object.getClass().isArray(); |
| | | } |
| | | |
| | | /** |
| | | * å»ç©ºæ ¼ |
| | | */ |
| | | public static String trim(String str) |
| | | { |
| | | return (str == null ? "" : str.trim()); |
| | | } |
| | | |
| | | /** |
| | | * æªåå符串 |
| | | * |
| | | * @param str å符串 |
| | | * @param start å¼å§ |
| | | * @return ç»æ |
| | | */ |
| | | public static String substring(final String str, int start) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = str.length() + start; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = 0; |
| | | } |
| | | if (start > str.length()) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | return str.substring(start); |
| | | } |
| | | |
| | | /** |
| | | * æªåå符串 |
| | | * |
| | | * @param str å符串 |
| | | * @param start å¼å§ |
| | | * @param end ç»æ |
| | | * @return ç»æ |
| | | */ |
| | | public static String substring(final String str, int start, int end) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (end < 0) |
| | | { |
| | | end = str.length() + end; |
| | | } |
| | | if (start < 0) |
| | | { |
| | | start = str.length() + start; |
| | | } |
| | | |
| | | if (end > str.length()) |
| | | { |
| | | end = str.length(); |
| | | } |
| | | |
| | | if (start > end) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = 0; |
| | | } |
| | | if (end < 0) |
| | | { |
| | | end = 0; |
| | | } |
| | | |
| | | return str.substring(start, end); |
| | | } |
| | | |
| | | /** |
| | | * å¤ææ¯å¦ä¸ºç©ºï¼å¹¶ä¸ä¸æ¯ç©ºç½å符 |
| | | * |
| | | * @param str è¦å¤æçvalue |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean hasText(String str) |
| | | { |
| | | return (str != null && !str.isEmpty() && containsText(str)); |
| | | } |
| | | |
| | | private static boolean containsText(CharSequence str) |
| | | { |
| | | int strLen = str.length(); |
| | | for (int i = 0; i < strLen; i++) |
| | | { |
| | | if (!Character.isWhitespace(str.charAt(i))) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * æ ¼å¼åææ¬, {} 表示å ä½ç¬¦<br> |
| | | * æ¤æ¹æ³åªæ¯ç®åå°å ä½ç¬¦ {} æç
§é¡ºåºæ¿æ¢ä¸ºåæ°<br> |
| | | * å¦ææ³è¾åº {} ä½¿ç¨ \\è½¬ä¹ { å³å¯ï¼å¦ææ³è¾åº {} ä¹åç \ 使ç¨å转ä¹ç¬¦ \\\\ å³å¯<br> |
| | | * ä¾ï¼<br> |
| | | * é常使ç¨ï¼format("this is {} for {}", "a", "b") -> this is a for b<br> |
| | | * 转ä¹{}ï¼ format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
| | | * 转ä¹\ï¼ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
| | | * |
| | | * @param template ææ¬æ¨¡æ¿ï¼è¢«æ¿æ¢çé¨åç¨ {} 表示 |
| | | * @param params åæ°å¼ |
| | | * @return æ ¼å¼ååçææ¬ |
| | | */ |
| | | public static String format(String template, Object... params) |
| | | { |
| | | if (isEmpty(params) || isEmpty(template)) |
| | | { |
| | | return template; |
| | | } |
| | | return StrFormatter.format(template, params); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºhttp(s)://å¼å¤´ |
| | | * |
| | | * @param link é¾æ¥ |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean ishttp(String link) |
| | | { |
| | | return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); |
| | | } |
| | | |
| | | /** |
| | | * å符串转set |
| | | * |
| | | * @param str å符串 |
| | | * @param sep åé符 |
| | | * @return setéå |
| | | */ |
| | | public static final Set<String> str2Set(String str, String sep) |
| | | { |
| | | return new HashSet<String>(str2List(str, sep, true, false)); |
| | | } |
| | | |
| | | /** |
| | | * å符串转list |
| | | * |
| | | * @param str å符串 |
| | | * @param sep åé符 |
| | | * @param filterBlank è¿æ»¤çº¯ç©ºç½ |
| | | * @param trim å»æé¦å°¾ç©ºç½ |
| | | * @return listéå |
| | | */ |
| | | public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) |
| | | { |
| | | List<String> list = new ArrayList<String>(); |
| | | if (StringUtils.isEmpty(str)) |
| | | { |
| | | return list; |
| | | } |
| | | |
| | | // è¿æ»¤ç©ºç½å符串 |
| | | if (filterBlank && StringUtils.isBlank(str)) |
| | | { |
| | | return list; |
| | | } |
| | | String[] split = str.split(sep); |
| | | for (String string : split) |
| | | { |
| | | if (filterBlank && StringUtils.isBlank(string)) |
| | | { |
| | | continue; |
| | | } |
| | | if (trim) |
| | | { |
| | | string = string.trim(); |
| | | } |
| | | list.add(string); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * å¤æç»å®çcollectionå表ä¸æ¯å¦å
å«æ°ç»array å¤æç»å®çæ°ç»arrayä¸æ¯å¦å
å«ç»å®çå
ç´ value |
| | | * |
| | | * @param collection ç»å®çéå |
| | | * @param array ç»å®çæ°ç» |
| | | * @return boolean ç»æ |
| | | */ |
| | | public static boolean containsAny(Collection<String> collection, String... array) |
| | | { |
| | | if (isEmpty(collection) || isEmpty(array)) |
| | | { |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | for (String str : array) |
| | | { |
| | | if (collection.contains(str)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾æå®å符串æ¯å¦å
å«æå®å符串å表ä¸çä»»æä¸ä¸ªå符串åæ¶ä¸²å¿½ç¥å¤§å°å |
| | | * |
| | | * @param cs æå®å符串 |
| | | * @param searchCharSequences éè¦æ£æ¥çå符串æ°ç» |
| | | * @return æ¯å¦å
å«ä»»æä¸ä¸ªå符串 |
| | | */ |
| | | public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) |
| | | { |
| | | if (isEmpty(cs) || isEmpty(searchCharSequences)) |
| | | { |
| | | return false; |
| | | } |
| | | for (CharSequence testStr : searchCharSequences) |
| | | { |
| | | if (containsIgnoreCase(cs, testStr)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 驼峰转ä¸å线å½å |
| | | */ |
| | | public static String toUnderScoreCase(String str) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return null; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | // åç½®å符æ¯å¦å¤§å |
| | | boolean preCharIsUpperCase = true; |
| | | // å½åå符æ¯å¦å¤§å |
| | | boolean curreCharIsUpperCase = true; |
| | | // ä¸ä¸å符æ¯å¦å¤§å |
| | | boolean nexteCharIsUpperCase = true; |
| | | for (int i = 0; i < str.length(); i++) |
| | | { |
| | | char c = str.charAt(i); |
| | | if (i > 0) |
| | | { |
| | | preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); |
| | | } |
| | | else |
| | | { |
| | | preCharIsUpperCase = false; |
| | | } |
| | | |
| | | curreCharIsUpperCase = Character.isUpperCase(c); |
| | | |
| | | if (i < (str.length() - 1)) |
| | | { |
| | | nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); |
| | | } |
| | | |
| | | if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) |
| | | { |
| | | sb.append(SEPARATOR); |
| | | } |
| | | else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) |
| | | { |
| | | sb.append(SEPARATOR); |
| | | } |
| | | sb.append(Character.toLowerCase(c)); |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦å
å«å符串 |
| | | * |
| | | * @param str éªè¯å符串 |
| | | * @param strs åç¬¦ä¸²ç» |
| | | * @return å
å«è¿åtrue |
| | | */ |
| | | public static boolean inStringIgnoreCase(String str, String... strs) |
| | | { |
| | | if (str != null && strs != null) |
| | | { |
| | | for (String s : strs) |
| | | { |
| | | if (str.equalsIgnoreCase(trim(s))) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * å°ä¸å线大åæ¹å¼å½åçå符串转æ¢ä¸ºé©¼å³°å¼ãå¦æ转æ¢åçä¸å线大åæ¹å¼å½åçå符串为空ï¼åè¿å空å符串ã ä¾å¦ï¼HELLO_WORLD->HelloWorld |
| | | * |
| | | * @param name 转æ¢åçä¸å线大åæ¹å¼å½åçå符串 |
| | | * @return 转æ¢åç驼峰å¼å½åçå符串 |
| | | */ |
| | | public static String convertToCamelCase(String name) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | // å¿«éæ£æ¥ |
| | | if (name == null || name.isEmpty()) |
| | | { |
| | | // 没å¿
è¦è½¬æ¢ |
| | | return ""; |
| | | } |
| | | else if (!name.contains("_")) |
| | | { |
| | | // ä¸å«ä¸å线ï¼ä»
å°é¦åæ¯å¤§å |
| | | return name.substring(0, 1).toUpperCase() + name.substring(1); |
| | | } |
| | | // ç¨ä¸å线å°åå§å符串åå² |
| | | String[] camels = name.split("_"); |
| | | for (String camel : camels) |
| | | { |
| | | // è·³è¿åå§å符串ä¸å¼å¤´ãç»å°¾çä¸æ¢çº¿æåéä¸å线 |
| | | if (camel.isEmpty()) |
| | | { |
| | | continue; |
| | | } |
| | | // é¦åæ¯å¤§å |
| | | result.append(camel.substring(0, 1).toUpperCase()); |
| | | result.append(camel.substring(1).toLowerCase()); |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 驼峰å¼å½åæ³ |
| | | * ä¾å¦ï¼user_name->userName |
| | | */ |
| | | public static String toCamelCase(String s) |
| | | { |
| | | if (s == null) |
| | | { |
| | | return null; |
| | | } |
| | | if (s.indexOf(SEPARATOR) == -1) |
| | | { |
| | | return s; |
| | | } |
| | | s = s.toLowerCase(); |
| | | StringBuilder sb = new StringBuilder(s.length()); |
| | | boolean upperCase = false; |
| | | for (int i = 0; i < s.length(); i++) |
| | | { |
| | | char c = s.charAt(i); |
| | | |
| | | if (c == SEPARATOR) |
| | | { |
| | | upperCase = true; |
| | | } |
| | | else if (upperCase) |
| | | { |
| | | sb.append(Character.toUpperCase(c)); |
| | | upperCase = false; |
| | | } |
| | | else |
| | | { |
| | | sb.append(c); |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾æå®å符串æ¯å¦å¹é
æå®å符串å表ä¸çä»»æä¸ä¸ªå符串 |
| | | * |
| | | * @param str æå®å符串 |
| | | * @param strs éè¦æ£æ¥çå符串æ°ç» |
| | | * @return æ¯å¦å¹é
|
| | | */ |
| | | public static boolean matches(String str, List<String> strs) |
| | | { |
| | | if (isEmpty(str) || isEmpty(strs)) |
| | | { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) |
| | | { |
| | | if (isMatch(pattern, str)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * å¤æurlæ¯å¦ä¸è§åé
ç½®: |
| | | * ? 表示å个å符; |
| | | * * 表示ä¸å±è·¯å¾å
çä»»æå符串ï¼ä¸å¯è·¨å±çº§; |
| | | * ** 表示任æå±è·¯å¾; |
| | | * |
| | | * @param pattern å¹é
è§å |
| | | * @param url éè¦å¹é
çurl |
| | | * @return |
| | | */ |
| | | public static boolean isMatch(String pattern, String url) |
| | | { |
| | | AntPathMatcher matcher = new AntPathMatcher(); |
| | | return matcher.match(pattern, url); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T cast(Object obj) |
| | | { |
| | | return (T) obj; |
| | | } |
| | | |
| | | /** |
| | | * æ°å左边补é½0ï¼ä½¿ä¹è¾¾å°æå®é¿åº¦ã注æï¼å¦ææ°å转æ¢ä¸ºå符串åï¼é¿åº¦å¤§äºsizeï¼ååªä¿ç æåsize个å符ã |
| | | * |
| | | * @param num æ°å对象 |
| | | * @param size å符串æå®é¿åº¦ |
| | | * @return è¿åæ°åçåç¬¦ä¸²æ ¼å¼ï¼è¯¥å符串为æå®é¿åº¦ã |
| | | */ |
| | | public static final String padl(final Number num, final int size) |
| | | { |
| | | return padl(num.toString(), size, '0'); |
| | | } |
| | | |
| | | /** |
| | | * å符串左补é½ãå¦æåå§å符串sé¿åº¦å¤§äºsizeï¼ååªä¿çæåsize个å符ã |
| | | * |
| | | * @param s åå§å符串 |
| | | * @param size å符串æå®é¿åº¦ |
| | | * @param c ç¨äºè¡¥é½çå符 |
| | | * @return è¿åæå®é¿åº¦çå符串ï¼ç±åå符串左补é½ææªåå¾å°ã |
| | | */ |
| | | public static final String padl(final String s, final int size, final char c) |
| | | { |
| | | final StringBuilder sb = new StringBuilder(size); |
| | | if (s != null) |
| | | { |
| | | final int len = s.length(); |
| | | if (s.length() <= size) |
| | | { |
| | | for (int i = size - len; i > 0; i--) |
| | | { |
| | | sb.append(c); |
| | | } |
| | | sb.append(s); |
| | | } |
| | | else |
| | | { |
| | | return s.substring(len - size, len); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int i = size; i > 0; i--) |
| | | { |
| | | sb.append(c); |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils; |
| | | |
| | | import java.util.concurrent.CancellationException; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Future; |
| | | import java.util.concurrent.TimeUnit; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * 线ç¨ç¸å
³å·¥å
·ç±». |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class Threads |
| | | { |
| | | private static final Logger logger = LoggerFactory.getLogger(Threads.class); |
| | | |
| | | /** |
| | | * sleepçå¾
,åä½ä¸ºæ¯«ç§ |
| | | */ |
| | | public static void sleep(long milliseconds) |
| | | { |
| | | try |
| | | { |
| | | Thread.sleep(milliseconds); |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åæ¢çº¿ç¨æ± |
| | | * å
使ç¨shutdown, åæ¢æ¥æ¶æ°ä»»å¡å¹¶å°è¯å®æææå·²åå¨ä»»å¡. |
| | | * å¦æè¶
æ¶, åè°ç¨shutdownNow, åæ¶å¨workQueueä¸Pendingçä»»å¡,并ä¸æææé»å¡å½æ°. |
| | | * å¦æä»ç¶è¶
æï¼åå¼·å¶éåº. |
| | | * å¦å¯¹å¨shutdownæ¶çº¿ç¨æ¬èº«è¢«è°ç¨ä¸æåäºå¤ç. |
| | | */ |
| | | public static void shutdownAndAwaitTermination(ExecutorService pool) |
| | | { |
| | | if (pool != null && !pool.isShutdown()) |
| | | { |
| | | pool.shutdown(); |
| | | try |
| | | { |
| | | if (!pool.awaitTermination(120, TimeUnit.SECONDS)) |
| | | { |
| | | pool.shutdownNow(); |
| | | if (!pool.awaitTermination(120, TimeUnit.SECONDS)) |
| | | { |
| | | logger.info("Pool did not terminate"); |
| | | } |
| | | } |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | pool.shutdownNow(); |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æå°çº¿ç¨å¼å¸¸ä¿¡æ¯ |
| | | */ |
| | | public static void printException(Runnable r, Throwable t) |
| | | { |
| | | if (t == null && r instanceof Future<?>) |
| | | { |
| | | try |
| | | { |
| | | Future<?> future = (Future<?>) r; |
| | | if (future.isDone()) |
| | | { |
| | | future.get(); |
| | | } |
| | | } |
| | | catch (CancellationException ce) |
| | | { |
| | | t = ce; |
| | | } |
| | | catch (ExecutionException ee) |
| | | { |
| | | t = ee.getCause(); |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | | if (t != null) |
| | | { |
| | | logger.error(t.getMessage(), t); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.bean; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * Bean å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BeanUtils extends org.springframework.beans.BeanUtils |
| | | { |
| | | /** Beanæ¹æ³åä¸å±æ§åå¼å§çä¸æ */ |
| | | private static final int BEAN_METHOD_PROP_INDEX = 3; |
| | | |
| | | /** * å¹é
getteræ¹æ³çæ£åè¡¨è¾¾å¼ */ |
| | | private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)"); |
| | | |
| | | /** * å¹é
setteræ¹æ³çæ£åè¡¨è¾¾å¼ */ |
| | | private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)"); |
| | | |
| | | /** |
| | | * Beanå±æ§å¤å¶å·¥å
·æ¹æ³ã |
| | | * |
| | | * @param dest ç®æ 对象 |
| | | * @param src æºå¯¹è±¡ |
| | | */ |
| | | public static void copyBeanProp(Object dest, Object src) |
| | | { |
| | | try |
| | | { |
| | | copyProperties(src, dest); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å对象çsetteræ¹æ³ã |
| | | * |
| | | * @param obj 对象 |
| | | * @return 对象çsetteræ¹æ³å表 |
| | | */ |
| | | public static List<Method> getSetterMethods(Object obj) |
| | | { |
| | | // setteræ¹æ³å表 |
| | | List<Method> setterMethods = new ArrayList<Method>(); |
| | | |
| | | // è·åæææ¹æ³ |
| | | Method[] methods = obj.getClass().getMethods(); |
| | | |
| | | // æ¥æ¾setteræ¹æ³ |
| | | |
| | | for (Method method : methods) |
| | | { |
| | | Matcher m = SET_PATTERN.matcher(method.getName()); |
| | | if (m.matches() && (method.getParameterTypes().length == 1)) |
| | | { |
| | | setterMethods.add(method); |
| | | } |
| | | } |
| | | // è¿åsetteræ¹æ³å表 |
| | | return setterMethods; |
| | | } |
| | | |
| | | /** |
| | | * è·å对象çgetteræ¹æ³ã |
| | | * |
| | | * @param obj 对象 |
| | | * @return 对象çgetteræ¹æ³å表 |
| | | */ |
| | | |
| | | public static List<Method> getGetterMethods(Object obj) |
| | | { |
| | | // getteræ¹æ³å表 |
| | | List<Method> getterMethods = new ArrayList<Method>(); |
| | | // è·åæææ¹æ³ |
| | | Method[] methods = obj.getClass().getMethods(); |
| | | // æ¥æ¾getteræ¹æ³ |
| | | for (Method method : methods) |
| | | { |
| | | Matcher m = GET_PATTERN.matcher(method.getName()); |
| | | if (m.matches() && (method.getParameterTypes().length == 0)) |
| | | { |
| | | getterMethods.add(method); |
| | | } |
| | | } |
| | | // è¿ågetteræ¹æ³å表 |
| | | return getterMethods; |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥Beanæ¹æ³åä¸çå±æ§åæ¯å¦ç¸çã<br> |
| | | * å¦getName()åsetName()å±æ§åä¸æ ·ï¼getName()åsetAge()å±æ§åä¸ä¸æ ·ã |
| | | * |
| | | * @param m1 æ¹æ³å1 |
| | | * @param m2 æ¹æ³å2 |
| | | * @return å±æ§åä¸æ ·è¿åtrueï¼å¦åè¿åfalse |
| | | */ |
| | | |
| | | public static boolean isMethodPropEquals(String m1, String m2) |
| | | { |
| | | return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.bean; |
| | | |
| | | import java.util.Set; |
| | | import javax.validation.ConstraintViolation; |
| | | import javax.validation.ConstraintViolationException; |
| | | import javax.validation.Validator; |
| | | |
| | | /** |
| | | * bean对象å±æ§éªè¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class BeanValidators |
| | | { |
| | | public static void validateWithException(Validator validator, Object object, Class<?>... groups) |
| | | throws ConstraintViolationException |
| | | { |
| | | Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); |
| | | if (!constraintViolations.isEmpty()) |
| | | { |
| | | throw new ConstraintViolationException(constraintViolations); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.file; |
| | | |
| | | import java.io.File; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | /** |
| | | * æ件类åå·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileTypeUtils |
| | | { |
| | | /** |
| | | * è·åæ件类å |
| | | * <p> |
| | | * ä¾å¦: jcdm.txt, è¿å: txt |
| | | * |
| | | * @param file æ件å |
| | | * @return åç¼ï¼ä¸å«".") |
| | | */ |
| | | public static String getFileType(File file) |
| | | { |
| | | if (null == file) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | return getFileType(file.getName()); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ件类å |
| | | * <p> |
| | | * ä¾å¦: jcdm.txt, è¿å: txt |
| | | * |
| | | * @param fileName æ件å |
| | | * @return åç¼ï¼ä¸å«".") |
| | | */ |
| | | public static String getFileType(String fileName) |
| | | { |
| | | int separatorIndex = fileName.lastIndexOf("."); |
| | | if (separatorIndex < 0) |
| | | { |
| | | return ""; |
| | | } |
| | | return fileName.substring(separatorIndex + 1).toLowerCase(); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ件类å |
| | | * |
| | | * @param photoByte æ件åèç |
| | | * @return åç¼ï¼ä¸å«".") |
| | | */ |
| | | public static String getFileExtendName(byte[] photoByte) |
| | | { |
| | | String strFileExtendName = "JPG"; |
| | | if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) |
| | | && ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) |
| | | { |
| | | strFileExtendName = "GIF"; |
| | | } |
| | | else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) |
| | | { |
| | | strFileExtendName = "JPG"; |
| | | } |
| | | else if ((photoByte[0] == 66) && (photoByte[1] == 77)) |
| | | { |
| | | strFileExtendName = "BMP"; |
| | | } |
| | | else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) |
| | | { |
| | | strFileExtendName = "PNG"; |
| | | } |
| | | return strFileExtendName; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.file; |
| | | |
| | | 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.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.exception.file.FileNameLengthLimitExceededException; |
| | | import com.jcdm.common.exception.file.FileSizeLimitExceededException; |
| | | import com.jcdm.common.exception.file.InvalidExtensionException; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.uuid.Seq; |
| | | |
| | | /** |
| | | * æ件ä¸ä¼ å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileUploadUtils |
| | | { |
| | | /** |
| | | * é»è®¤å¤§å° 50M |
| | | */ |
| | | public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024; |
| | | |
| | | /** |
| | | * é»è®¤çæ件åæ大é¿åº¦ 100 |
| | | */ |
| | | public static final int DEFAULT_FILE_NAME_LENGTH = 100; |
| | | |
| | | /** |
| | | * é»è®¤ä¸ä¼ çå°å |
| | | */ |
| | | private static String defaultBaseDir = MesConfig.getProfile(); |
| | | |
| | | public static void setDefaultBaseDir(String defaultBaseDir) |
| | | { |
| | | FileUploadUtils.defaultBaseDir = defaultBaseDir; |
| | | } |
| | | |
| | | public static String getDefaultBaseDir() |
| | | { |
| | | return defaultBaseDir; |
| | | } |
| | | |
| | | /** |
| | | * 以é»è®¤é
ç½®è¿è¡æ件ä¸ä¼ |
| | | * |
| | | * @param file ä¸ä¼ çæ件 |
| | | * @return æ件å称 |
| | | * @throws Exception |
| | | */ |
| | | public static final String upload(MultipartFile file) throws IOException |
| | | { |
| | | try |
| | | { |
| | | return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new IOException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ件路å¾ä¸ä¼ |
| | | * |
| | | * @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 (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(baseDir, fileName); |
| | | } |
| | | |
| | | /** |
| | | * ç¼ç æ件å |
| | | */ |
| | | public static final String extractFilename(MultipartFile file) |
| | | { |
| | | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| | | FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); |
| | | } |
| | | |
| | | public 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; |
| | | } |
| | | |
| | | public static final String getPathFileName(String uploadDir, String fileName) throws IOException |
| | | { |
| | | int dirLastIndex = MesConfig.getProfile().length() + 1; |
| | | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
| | | return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| | | } |
| | | |
| | | /** |
| | | * æ件大å°æ ¡éª |
| | | * |
| | | * @param file ä¸ä¼ çæ件 |
| | | * @return |
| | | * @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 = 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 |
| | | */ |
| | | public static final boolean isAllowedExtension(String extension, String[] allowedExtension) |
| | | { |
| | | for (String str : allowedExtension) |
| | | { |
| | | if (str.equalsIgnoreCase(extension)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ件åçåç¼ |
| | | * |
| | | * @param file 表åæ件 |
| | | * @return åç¼å |
| | | */ |
| | | public static final String getExtension(MultipartFile file) |
| | | { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | if (StringUtils.isEmpty(extension)) |
| | | { |
| | | extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType())); |
| | | } |
| | | return extension; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.file; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.uuid.IdUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | |
| | | /** |
| | | * æ件å¤çå·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FileUtils |
| | | { |
| | | public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; |
| | | |
| | | /** |
| | | * è¾åºæå®æ件çbyteæ°ç» |
| | | * |
| | | * @param filePath æä»¶è·¯å¾ |
| | | * @param os è¾åºæµ |
| | | * @return |
| | | */ |
| | | public static void writeBytes(String filePath, OutputStream os) throws IOException |
| | | { |
| | | FileInputStream fis = null; |
| | | try |
| | | { |
| | | File file = new File(filePath); |
| | | if (!file.exists()) |
| | | { |
| | | throw new FileNotFoundException(filePath); |
| | | } |
| | | fis = new FileInputStream(file); |
| | | byte[] b = new byte[1024]; |
| | | int length; |
| | | while ((length = fis.read(b)) > 0) |
| | | { |
| | | os.write(b, 0, length); |
| | | } |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | throw e; |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.close(os); |
| | | IOUtils.close(fis); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åæ°æ®å°æä»¶ä¸ |
| | | * |
| | | * @param data æ°æ® |
| | | * @return ç®æ æ件 |
| | | * @throws IOException IOå¼å¸¸ |
| | | */ |
| | | public static String writeImportBytes(byte[] data) throws IOException |
| | | { |
| | | return writeBytes(data, MesConfig.getImportPath()); |
| | | } |
| | | |
| | | /** |
| | | * åæ°æ®å°æä»¶ä¸ |
| | | * |
| | | * @param data æ°æ® |
| | | * @param uploadDir ç®æ æ件 |
| | | * @return ç®æ æ件 |
| | | * @throws IOException IOå¼å¸¸ |
| | | */ |
| | | public static String writeBytes(byte[] data, String uploadDir) throws IOException |
| | | { |
| | | FileOutputStream fos = null; |
| | | String pathName = ""; |
| | | try |
| | | { |
| | | String extension = getFileExtendName(data); |
| | | pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; |
| | | File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName); |
| | | fos = new FileOutputStream(file); |
| | | fos.write(data); |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.close(fos); |
| | | } |
| | | return FileUploadUtils.getPathFileName(uploadDir, pathName); |
| | | } |
| | | |
| | | /** |
| | | * å é¤æ件 |
| | | * |
| | | * @param filePath æ件 |
| | | * @return |
| | | */ |
| | | public static boolean deleteFile(String filePath) |
| | | { |
| | | boolean flag = false; |
| | | File file = new File(filePath); |
| | | // è·¯å¾ä¸ºæ件ä¸ä¸ä¸ºç©ºåè¿è¡å é¤ |
| | | if (file.isFile() && file.exists()) |
| | | { |
| | | flag = file.delete(); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * æ件å称éªè¯ |
| | | * |
| | | * @param filename æ件å称 |
| | | * @return true æ£å¸¸ false éæ³ |
| | | */ |
| | | public static boolean isValidFilename(String filename) |
| | | { |
| | | return filename.matches(FILENAME_PATTERN); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ件æ¯å¦å¯ä¸è½½ |
| | | * |
| | | * @param resource éè¦ä¸è½½çæ件 |
| | | * @return true æ£å¸¸ false éæ³ |
| | | */ |
| | | public static boolean checkAllowDownload(String resource) |
| | | { |
| | | // ç¦æ¢ç®å½ä¸è·³çº§å« |
| | | if (StringUtils.contains(resource, "..")) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // æ£æ¥å
许ä¸è½½çæ件è§å |
| | | if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | // ä¸å¨å
许ä¸è½½çæ件è§å |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * ä¸è½½æ件åéæ°ç¼ç |
| | | * |
| | | * @param request 请æ±å¯¹è±¡ |
| | | * @param fileName æ件å |
| | | * @return ç¼ç åçæ件å |
| | | */ |
| | | public static String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException |
| | | { |
| | | final String agent = request.getHeader("USER-AGENT"); |
| | | String filename = fileName; |
| | | if (agent.contains("MSIE")) |
| | | { |
| | | // IEæµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | filename = filename.replace("+", " "); |
| | | } |
| | | else if (agent.contains("Firefox")) |
| | | { |
| | | // ç«çæµè§å¨ |
| | | filename = new String(fileName.getBytes(), "ISO8859-1"); |
| | | } |
| | | else if (agent.contains("Chrome")) |
| | | { |
| | | // googleæµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | } |
| | | else |
| | | { |
| | | // å
¶å®æµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | } |
| | | return filename; |
| | | } |
| | | |
| | | /** |
| | | * ä¸è½½æ件åéæ°ç¼ç |
| | | * |
| | | * @param response ååºå¯¹è±¡ |
| | | * @param realFileName çå®æ件å |
| | | */ |
| | | public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException |
| | | { |
| | | String percentEncodedFileName = percentEncode(realFileName); |
| | | |
| | | StringBuilder contentDispositionValue = new StringBuilder(); |
| | | contentDispositionValue.append("attachment; filename=") |
| | | .append(percentEncodedFileName) |
| | | .append(";") |
| | | .append("filename*=") |
| | | .append("utf-8''") |
| | | .append(percentEncodedFileName); |
| | | |
| | | response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename"); |
| | | response.setHeader("Content-disposition", contentDispositionValue.toString()); |
| | | response.setHeader("download-filename", percentEncodedFileName); |
| | | } |
| | | |
| | | /** |
| | | * ç¾åå·ç¼ç å·¥å
·æ¹æ³ |
| | | * |
| | | * @param s éè¦ç¾åå·ç¼ç çå符串 |
| | | * @return ç¾åå·ç¼ç åçå符串 |
| | | */ |
| | | public static String percentEncode(String s) throws UnsupportedEncodingException |
| | | { |
| | | String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString()); |
| | | return encode.replaceAll("\\+", "%20"); |
| | | } |
| | | |
| | | /** |
| | | * è·åå¾ååç¼ |
| | | * |
| | | * @param photoByte å¾åæ°æ® |
| | | * @return åç¼å |
| | | */ |
| | | public static String getFileExtendName(byte[] photoByte) |
| | | { |
| | | String strFileExtendName = "jpg"; |
| | | if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) |
| | | && ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) |
| | | { |
| | | strFileExtendName = "gif"; |
| | | } |
| | | else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) |
| | | { |
| | | strFileExtendName = "jpg"; |
| | | } |
| | | else if ((photoByte[0] == 66) && (photoByte[1] == 77)) |
| | | { |
| | | strFileExtendName = "bmp"; |
| | | } |
| | | else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) |
| | | { |
| | | strFileExtendName = "png"; |
| | | } |
| | | return strFileExtendName; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ件å称 /profile/upload/2022/04/16/jcdm.png |
| | | * |
| | | * @param fileName è·¯å¾å称 |
| | | * @return 没ææ件路å¾çå称 |
| | | */ |
| | | public static String getName(String fileName) |
| | | { |
| | | if (fileName == null) |
| | | { |
| | | return null; |
| | | } |
| | | int lastUnixPos = fileName.lastIndexOf('/'); |
| | | int lastWindowsPos = fileName.lastIndexOf('\\'); |
| | | int index = Math.max(lastUnixPos, lastWindowsPos); |
| | | return fileName.substring(index + 1); |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸å¸¦åç¼æ件å称 /profile/upload/2022/04/16/jcdm.png |
| | | * |
| | | * @param fileName è·¯å¾å称 |
| | | * @return 没ææ件路å¾ååç¼çå称 |
| | | */ |
| | | public static String getNameNotSuffix(String fileName) |
| | | { |
| | | if (fileName == null) |
| | | { |
| | | return null; |
| | | } |
| | | String baseName = FilenameUtils.getBaseName(fileName); |
| | | return baseName; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.file; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.util.Arrays; |
| | | import org.apache.poi.util.IOUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * å¾çå¤çå·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class ImageUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(ImageUtils.class); |
| | | |
| | | public static byte[] getImage(String imagePath) |
| | | { |
| | | InputStream is = getFile(imagePath); |
| | | try |
| | | { |
| | | return IOUtils.toByteArray(is); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("å¾çå è½½å¼å¸¸ {}", e); |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(is); |
| | | } |
| | | } |
| | | |
| | | public static InputStream getFile(String imagePath) |
| | | { |
| | | try |
| | | { |
| | | byte[] result = readFile(imagePath); |
| | | result = Arrays.copyOf(result, result.length); |
| | | return new ByteArrayInputStream(result); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·åå¾çå¼å¸¸ {}", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 读åæ件为åèæ°æ® |
| | | * |
| | | * @param url å°å |
| | | * @return åèæ°æ® |
| | | */ |
| | | public static byte[] readFile(String url) |
| | | { |
| | | InputStream in = null; |
| | | try |
| | | { |
| | | if (url.startsWith("http")) |
| | | { |
| | | // ç½ç»å°å |
| | | URL urlObj = new URL(url); |
| | | URLConnection urlConnection = urlObj.openConnection(); |
| | | urlConnection.setConnectTimeout(30 * 1000); |
| | | urlConnection.setReadTimeout(60 * 1000); |
| | | urlConnection.setDoInput(true); |
| | | in = urlConnection.getInputStream(); |
| | | } |
| | | else |
| | | { |
| | | // æ¬æºå°å |
| | | String localPath = MesConfig.getProfile(); |
| | | String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); |
| | | in = new FileInputStream(downloadPath); |
| | | } |
| | | return IOUtils.toByteArray(in); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·åæ件路å¾å¼å¸¸ {}", e); |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(in); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.file; |
| | | |
| | | /** |
| | | * åªä½ç±»åå·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class MimeTypeUtils |
| | | { |
| | | public static final String IMAGE_PNG = "image/png"; |
| | | |
| | | public static final String IMAGE_JPG = "image/jpg"; |
| | | |
| | | public static final String IMAGE_JPEG = "image/jpeg"; |
| | | |
| | | public static final String IMAGE_BMP = "image/bmp"; |
| | | |
| | | public static final String IMAGE_GIF = "image/gif"; |
| | | |
| | | public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" }; |
| | | |
| | | public static final String[] FLASH_EXTENSION = { "swf", "flv" }; |
| | | |
| | | public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", |
| | | "asf", "rm", "rmvb" }; |
| | | |
| | | public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" }; |
| | | |
| | | public static final String[] DEFAULT_ALLOWED_EXTENSION = { |
| | | // å¾ç |
| | | "bmp", "gif", "jpg", "jpeg", "png", |
| | | // word excel powerpoint |
| | | "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", |
| | | // å缩æ件 |
| | | "rar", "zip", "gz", "bz2", |
| | | // è§é¢æ ¼å¼ |
| | | "mp4", "avi", "rmvb", |
| | | // pdf |
| | | "pdf" }; |
| | | |
| | | public static String getExtension(String prefix) |
| | | { |
| | | switch (prefix) |
| | | { |
| | | case IMAGE_PNG: |
| | | return "png"; |
| | | case IMAGE_JPG: |
| | | return "jpg"; |
| | | case IMAGE_JPEG: |
| | | return "jpeg"; |
| | | case IMAGE_BMP: |
| | | return "bmp"; |
| | | case IMAGE_GIF: |
| | | return "gif"; |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.html; |
| | | |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * 转ä¹åå转ä¹å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class EscapeUtil |
| | | { |
| | | public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)"; |
| | | |
| | | private static final char[][] TEXT = new char[64][]; |
| | | |
| | | static |
| | | { |
| | | for (int i = 0; i < 64; i++) |
| | | { |
| | | TEXT[i] = new char[] { (char) i }; |
| | | } |
| | | |
| | | // special HTML characters |
| | | TEXT['\''] = "'".toCharArray(); // åå¼å· |
| | | TEXT['"'] = """.toCharArray(); // åå¼å· |
| | | TEXT['&'] = "&".toCharArray(); // &符 |
| | | TEXT['<'] = "<".toCharArray(); // å°äºå· |
| | | TEXT['>'] = ">".toCharArray(); // 大äºå· |
| | | } |
| | | |
| | | /** |
| | | * 转ä¹ææ¬ä¸çHTMLå符为å®å
¨çå符 |
| | | * |
| | | * @param text 被转ä¹çææ¬ |
| | | * @return 转ä¹åçææ¬ |
| | | */ |
| | | public static String escape(String text) |
| | | { |
| | | return encode(text); |
| | | } |
| | | |
| | | /** |
| | | * è¿å被转ä¹çHTMLç¹æ®å符 |
| | | * |
| | | * @param content å
å«è½¬ä¹ç¬¦çHTMLå
容 |
| | | * @return 转æ¢åçå符串 |
| | | */ |
| | | public static String unescape(String content) |
| | | { |
| | | return decode(content); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
é¤ææHTMLæ ç¾ï¼ä½æ¯ä¸å é¤æ ç¾å
çå
容 |
| | | * |
| | | * @param content ææ¬ |
| | | * @return æ¸
é¤æ ç¾åçææ¬ |
| | | */ |
| | | public static String clean(String content) |
| | | { |
| | | return new HTMLFilter().filter(content); |
| | | } |
| | | |
| | | /** |
| | | * Escapeç¼ç |
| | | * |
| | | * @param text 被ç¼ç çææ¬ |
| | | * @return ç¼ç åçå符 |
| | | */ |
| | | private static String encode(String text) |
| | | { |
| | | if (StringUtils.isEmpty(text)) |
| | | { |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | final StringBuilder tmp = new StringBuilder(text.length() * 6); |
| | | char c; |
| | | for (int i = 0; i < text.length(); i++) |
| | | { |
| | | c = text.charAt(i); |
| | | if (c < 256) |
| | | { |
| | | tmp.append("%"); |
| | | if (c < 16) |
| | | { |
| | | tmp.append("0"); |
| | | } |
| | | tmp.append(Integer.toString(c, 16)); |
| | | } |
| | | else |
| | | { |
| | | tmp.append("%u"); |
| | | if (c <= 0xfff) |
| | | { |
| | | // issue#I49JU8@Gitee |
| | | tmp.append("0"); |
| | | } |
| | | tmp.append(Integer.toString(c, 16)); |
| | | } |
| | | } |
| | | return tmp.toString(); |
| | | } |
| | | |
| | | /** |
| | | * Escape解ç |
| | | * |
| | | * @param content 被转ä¹çå
容 |
| | | * @return 解ç åçå符串 |
| | | */ |
| | | public static String decode(String content) |
| | | { |
| | | if (StringUtils.isEmpty(content)) |
| | | { |
| | | return content; |
| | | } |
| | | |
| | | StringBuilder tmp = new StringBuilder(content.length()); |
| | | int lastPos = 0, pos = 0; |
| | | char ch; |
| | | while (lastPos < content.length()) |
| | | { |
| | | pos = content.indexOf("%", lastPos); |
| | | if (pos == lastPos) |
| | | { |
| | | if (content.charAt(pos + 1) == 'u') |
| | | { |
| | | ch = (char) Integer.parseInt(content.substring(pos + 2, pos + 6), 16); |
| | | tmp.append(ch); |
| | | lastPos = pos + 6; |
| | | } |
| | | else |
| | | { |
| | | ch = (char) Integer.parseInt(content.substring(pos + 1, pos + 3), 16); |
| | | tmp.append(ch); |
| | | lastPos = pos + 3; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (pos == -1) |
| | | { |
| | | tmp.append(content.substring(lastPos)); |
| | | lastPos = content.length(); |
| | | } |
| | | else |
| | | { |
| | | tmp.append(content.substring(lastPos, pos)); |
| | | lastPos = pos; |
| | | } |
| | | } |
| | | } |
| | | return tmp.toString(); |
| | | } |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | String html = "<script>alert(1);</script>"; |
| | | String escape = EscapeUtil.escape(html); |
| | | // String html = "<scr<script>ipt>alert(\"XSS\")</scr<script>ipt>"; |
| | | // String html = "<123"; |
| | | // String html = "123>"; |
| | | System.out.println("clean: " + EscapeUtil.clean(html)); |
| | | System.out.println("escape: " + escape); |
| | | System.out.println("unescape: " + EscapeUtil.unescape(escape)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.html; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentMap; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * HTMLè¿æ»¤å¨ï¼ç¨äºå»é¤XSSæ¼æ´éæ£ã |
| | | * |
| | | * @author jc |
| | | */ |
| | | public final class HTMLFilter |
| | | { |
| | | /** |
| | | * regex flag union representing /si modifiers in php |
| | | **/ |
| | | private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL; |
| | | private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL); |
| | | private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI); |
| | | private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL); |
| | | private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI); |
| | | private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI); |
| | | private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI); |
| | | private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI); |
| | | private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI); |
| | | private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?"); |
| | | private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?"); |
| | | private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?"); |
| | | private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))"); |
| | | private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL); |
| | | private static final Pattern P_END_ARROW = Pattern.compile("^>"); |
| | | private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)"); |
| | | private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)"); |
| | | private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)"); |
| | | private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)"); |
| | | private static final Pattern P_AMP = Pattern.compile("&"); |
| | | private static final Pattern P_QUOTE = Pattern.compile("\""); |
| | | private static final Pattern P_LEFT_ARROW = Pattern.compile("<"); |
| | | private static final Pattern P_RIGHT_ARROW = Pattern.compile(">"); |
| | | private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>"); |
| | | |
| | | // @xxx could grow large... maybe use sesat's ReferenceMap |
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>(); |
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * set of allowed html elements, along with allowed attributes for each element |
| | | **/ |
| | | private final Map<String, List<String>> vAllowed; |
| | | /** |
| | | * counts of open tags for each (allowable) html element |
| | | **/ |
| | | private final Map<String, Integer> vTagCounts = new HashMap<>(); |
| | | |
| | | /** |
| | | * html elements which must always be self-closing (e.g. "<img />") |
| | | **/ |
| | | private final String[] vSelfClosingTags; |
| | | /** |
| | | * html elements which must always have separate opening and closing tags (e.g. "<b></b>") |
| | | **/ |
| | | private final String[] vNeedClosingTags; |
| | | /** |
| | | * set of disallowed html elements |
| | | **/ |
| | | private final String[] vDisallowed; |
| | | /** |
| | | * attributes which should be checked for valid protocols |
| | | **/ |
| | | private final String[] vProtocolAtts; |
| | | /** |
| | | * allowed protocols |
| | | **/ |
| | | private final String[] vAllowedProtocols; |
| | | /** |
| | | * tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />") |
| | | **/ |
| | | private final String[] vRemoveBlanks; |
| | | /** |
| | | * entities allowed within html markup |
| | | **/ |
| | | private final String[] vAllowedEntities; |
| | | /** |
| | | * flag determining whether comments are allowed in input String. |
| | | */ |
| | | private final boolean stripComment; |
| | | private final boolean encodeQuotes; |
| | | /** |
| | | * flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>" |
| | | * becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped. |
| | | */ |
| | | private final boolean alwaysMakeTags; |
| | | |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | public HTMLFilter() |
| | | { |
| | | vAllowed = new HashMap<>(); |
| | | |
| | | final ArrayList<String> a_atts = new ArrayList<>(); |
| | | a_atts.add("href"); |
| | | a_atts.add("target"); |
| | | vAllowed.put("a", a_atts); |
| | | |
| | | final ArrayList<String> img_atts = new ArrayList<>(); |
| | | img_atts.add("src"); |
| | | img_atts.add("width"); |
| | | img_atts.add("height"); |
| | | img_atts.add("alt"); |
| | | vAllowed.put("img", img_atts); |
| | | |
| | | final ArrayList<String> no_atts = new ArrayList<>(); |
| | | vAllowed.put("b", no_atts); |
| | | vAllowed.put("strong", no_atts); |
| | | vAllowed.put("i", no_atts); |
| | | vAllowed.put("em", no_atts); |
| | | |
| | | vSelfClosingTags = new String[] { "img" }; |
| | | vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" }; |
| | | vDisallowed = new String[] {}; |
| | | vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp. |
| | | vProtocolAtts = new String[] { "src", "href" }; |
| | | vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" }; |
| | | vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" }; |
| | | stripComment = true; |
| | | encodeQuotes = true; |
| | | alwaysMakeTags = false; |
| | | } |
| | | |
| | | /** |
| | | * Map-parameter configurable constructor. |
| | | * |
| | | * @param conf map containing configuration. keys match field names. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public HTMLFilter(final Map<String, Object> conf) |
| | | { |
| | | |
| | | assert conf.containsKey("vAllowed") : "configuration requires vAllowed"; |
| | | assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags"; |
| | | assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags"; |
| | | assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed"; |
| | | assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols"; |
| | | assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts"; |
| | | assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks"; |
| | | assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities"; |
| | | |
| | | vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) conf.get("vAllowed")); |
| | | vSelfClosingTags = (String[]) conf.get("vSelfClosingTags"); |
| | | vNeedClosingTags = (String[]) conf.get("vNeedClosingTags"); |
| | | vDisallowed = (String[]) conf.get("vDisallowed"); |
| | | vAllowedProtocols = (String[]) conf.get("vAllowedProtocols"); |
| | | vProtocolAtts = (String[]) conf.get("vProtocolAtts"); |
| | | vRemoveBlanks = (String[]) conf.get("vRemoveBlanks"); |
| | | vAllowedEntities = (String[]) conf.get("vAllowedEntities"); |
| | | stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true; |
| | | encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true; |
| | | alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true; |
| | | } |
| | | |
| | | private void reset() |
| | | { |
| | | vTagCounts.clear(); |
| | | } |
| | | |
| | | // --------------------------------------------------------------- |
| | | // my versions of some PHP library functions |
| | | public static String chr(final int decimal) |
| | | { |
| | | return String.valueOf((char) decimal); |
| | | } |
| | | |
| | | public static String htmlSpecialChars(final String s) |
| | | { |
| | | String result = s; |
| | | result = regexReplace(P_AMP, "&", result); |
| | | result = regexReplace(P_QUOTE, """, result); |
| | | result = regexReplace(P_LEFT_ARROW, "<", result); |
| | | result = regexReplace(P_RIGHT_ARROW, ">", result); |
| | | return result; |
| | | } |
| | | |
| | | // --------------------------------------------------------------- |
| | | |
| | | /** |
| | | * given a user submitted input String, filter out any invalid or restricted html. |
| | | * |
| | | * @param input text (i.e. submitted by a user) than may contain html |
| | | * @return "clean" version of input, with only valid, whitelisted html elements allowed |
| | | */ |
| | | public String filter(final String input) |
| | | { |
| | | reset(); |
| | | String s = input; |
| | | |
| | | s = escapeComments(s); |
| | | |
| | | s = balanceHTML(s); |
| | | |
| | | s = checkTags(s); |
| | | |
| | | s = processRemoveBlanks(s); |
| | | |
| | | // s = validateEntities(s); |
| | | |
| | | return s; |
| | | } |
| | | |
| | | public boolean isAlwaysMakeTags() |
| | | { |
| | | return alwaysMakeTags; |
| | | } |
| | | |
| | | public boolean isStripComments() |
| | | { |
| | | return stripComment; |
| | | } |
| | | |
| | | private String escapeComments(final String s) |
| | | { |
| | | final Matcher m = P_COMMENTS.matcher(s); |
| | | final StringBuffer buf = new StringBuffer(); |
| | | if (m.find()) |
| | | { |
| | | final String match = m.group(1); // (.*?) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->")); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | return buf.toString(); |
| | | } |
| | | |
| | | private String balanceHTML(String s) |
| | | { |
| | | if (alwaysMakeTags) |
| | | { |
| | | // |
| | | // try and form html |
| | | // |
| | | s = regexReplace(P_END_ARROW, "", s); |
| | | // ä¸è¿½å ç»ææ ç¾ |
| | | s = regexReplace(P_BODY_TO_END, "<$1>", s); |
| | | s = regexReplace(P_XML_CONTENT, "$1<$2", s); |
| | | |
| | | } |
| | | else |
| | | { |
| | | // |
| | | // escape stray brackets |
| | | // |
| | | s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s); |
| | | s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s); |
| | | |
| | | // |
| | | // the last regexp causes '<>' entities to appear |
| | | // (we need to do a lookahead assertion so that the last bracket can |
| | | // be used in the next pass of the regexp) |
| | | // |
| | | s = regexReplace(P_BOTH_ARROWS, "", s); |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String checkTags(String s) |
| | | { |
| | | Matcher m = P_TAGS.matcher(s); |
| | | |
| | | final StringBuffer buf = new StringBuffer(); |
| | | while (m.find()) |
| | | { |
| | | String replaceStr = m.group(1); |
| | | replaceStr = processTag(replaceStr); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr)); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | // these get tallied in processTag |
| | | // (remember to reset before subsequent calls to filter method) |
| | | final StringBuilder sBuilder = new StringBuilder(buf.toString()); |
| | | for (String key : vTagCounts.keySet()) |
| | | { |
| | | for (int ii = 0; ii < vTagCounts.get(key); ii++) |
| | | { |
| | | sBuilder.append("</").append(key).append(">"); |
| | | } |
| | | } |
| | | s = sBuilder.toString(); |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String processRemoveBlanks(final String s) |
| | | { |
| | | String result = s; |
| | | for (String tag : vRemoveBlanks) |
| | | { |
| | | if (!P_REMOVE_PAIR_BLANKS.containsKey(tag)) |
| | | { |
| | | P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">")); |
| | | } |
| | | result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result); |
| | | if (!P_REMOVE_SELF_BLANKS.containsKey(tag)) |
| | | { |
| | | P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>")); |
| | | } |
| | | result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) |
| | | { |
| | | Matcher m = regex_pattern.matcher(s); |
| | | return m.replaceAll(replacement); |
| | | } |
| | | |
| | | private String processTag(final String s) |
| | | { |
| | | // ending tags |
| | | Matcher m = P_END_TAG.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String name = m.group(1).toLowerCase(); |
| | | if (allowed(name)) |
| | | { |
| | | if (!inArray(name, vSelfClosingTags)) |
| | | { |
| | | if (vTagCounts.containsKey(name)) |
| | | { |
| | | vTagCounts.put(name, vTagCounts.get(name) - 1); |
| | | return "</" + name + ">"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // starting tags |
| | | m = P_START_TAG.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String name = m.group(1).toLowerCase(); |
| | | final String body = m.group(2); |
| | | String ending = m.group(3); |
| | | |
| | | // debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" ); |
| | | if (allowed(name)) |
| | | { |
| | | final StringBuilder params = new StringBuilder(); |
| | | |
| | | final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body); |
| | | final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body); |
| | | final List<String> paramNames = new ArrayList<>(); |
| | | final List<String> paramValues = new ArrayList<>(); |
| | | while (m2.find()) |
| | | { |
| | | paramNames.add(m2.group(1)); // ([a-z0-9]+) |
| | | paramValues.add(m2.group(3)); // (.*?) |
| | | } |
| | | while (m3.find()) |
| | | { |
| | | paramNames.add(m3.group(1)); // ([a-z0-9]+) |
| | | paramValues.add(m3.group(3)); // ([^\"\\s']+) |
| | | } |
| | | |
| | | String paramName, paramValue; |
| | | for (int ii = 0; ii < paramNames.size(); ii++) |
| | | { |
| | | paramName = paramNames.get(ii).toLowerCase(); |
| | | paramValue = paramValues.get(ii); |
| | | |
| | | // debug( "paramName='" + paramName + "'" ); |
| | | // debug( "paramValue='" + paramValue + "'" ); |
| | | // debug( "allowed? " + vAllowed.get( name ).contains( paramName ) ); |
| | | |
| | | if (allowedAttribute(name, paramName)) |
| | | { |
| | | if (inArray(paramName, vProtocolAtts)) |
| | | { |
| | | paramValue = processParamProtocol(paramValue); |
| | | } |
| | | params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\\\""); |
| | | } |
| | | } |
| | | |
| | | if (inArray(name, vSelfClosingTags)) |
| | | { |
| | | ending = " /"; |
| | | } |
| | | |
| | | if (inArray(name, vNeedClosingTags)) |
| | | { |
| | | ending = ""; |
| | | } |
| | | |
| | | if (ending == null || ending.length() < 1) |
| | | { |
| | | if (vTagCounts.containsKey(name)) |
| | | { |
| | | vTagCounts.put(name, vTagCounts.get(name) + 1); |
| | | } |
| | | else |
| | | { |
| | | vTagCounts.put(name, 1); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ending = " /"; |
| | | } |
| | | return "<" + name + params + ending + ">"; |
| | | } |
| | | else |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | // comments |
| | | m = P_COMMENT.matcher(s); |
| | | if (!stripComment && m.find()) |
| | | { |
| | | return "<" + m.group() + ">"; |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | private String processParamProtocol(String s) |
| | | { |
| | | s = decodeEntities(s); |
| | | final Matcher m = P_PROTOCOL.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String protocol = m.group(1); |
| | | if (!inArray(protocol, vAllowedProtocols)) |
| | | { |
| | | // bad protocol, turn into local anchor link instead |
| | | s = "#" + s.substring(protocol.length() + 1); |
| | | if (s.startsWith("#//")) |
| | | { |
| | | s = "#" + s.substring(3); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String decodeEntities(String s) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | |
| | | Matcher m = P_ENTITY.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.decode(match).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | buf = new StringBuffer(); |
| | | m = P_ENTITY_UNICODE.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.valueOf(match, 16).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | buf = new StringBuffer(); |
| | | m = P_ENCODE.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.valueOf(match, 16).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | s = validateEntities(s); |
| | | return s; |
| | | } |
| | | |
| | | private String validateEntities(final String s) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | |
| | | // validate entities throughout the string |
| | | Matcher m = P_VALID_ENTITIES.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String one = m.group(1); // ([^&;]*) |
| | | final String two = m.group(2); // (?=(;|&|$)) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | return encodeQuotes(buf.toString()); |
| | | } |
| | | |
| | | private String encodeQuotes(final String s) |
| | | { |
| | | if (encodeQuotes) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | Matcher m = P_VALID_QUOTES.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String one = m.group(1); // (>|^) |
| | | final String two = m.group(2); // ([^<]+?) |
| | | final String three = m.group(3); // (<|$) |
| | | // ä¸æ¿æ¢åå¼å·ä¸º"ï¼é²æ¢jsonæ ¼å¼æ æ regexReplace(P_QUOTE, """, two) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three)); |
| | | } |
| | | m.appendTail(buf); |
| | | return buf.toString(); |
| | | } |
| | | else |
| | | { |
| | | return s; |
| | | } |
| | | } |
| | | |
| | | private String checkEntity(final String preamble, final String term) |
| | | { |
| | | |
| | | return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble; |
| | | } |
| | | |
| | | private boolean isValidEntity(final String entity) |
| | | { |
| | | return inArray(entity, vAllowedEntities); |
| | | } |
| | | |
| | | private static boolean inArray(final String s, final String[] array) |
| | | { |
| | | for (String item : array) |
| | | { |
| | | if (item != null && item.equals(s)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private boolean allowed(final String name) |
| | | { |
| | | return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed); |
| | | } |
| | | |
| | | private boolean allowedAttribute(final String name, final String paramName) |
| | | { |
| | | return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.http; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | import javax.servlet.ServletRequest; |
| | | import org.apache.commons.lang3.exception.ExceptionUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * éç¨httpå·¥å
·å°è£
|
| | | * |
| | | * @author jc |
| | | */ |
| | | public class HttpHelper |
| | | { |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class); |
| | | |
| | | public static String getBodyString(ServletRequest request) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | BufferedReader reader = null; |
| | | try (InputStream inputStream = request.getInputStream()) |
| | | { |
| | | reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); |
| | | String line = ""; |
| | | while ((line = reader.readLine()) != null) |
| | | { |
| | | sb.append(line); |
| | | } |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | LOGGER.warn("getBodyStringåºç°é®é¢ï¼"); |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | LOGGER.error(ExceptionUtils.getMessage(e)); |
| | | } |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.http; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.PrintWriter; |
| | | import java.net.ConnectException; |
| | | import java.net.SocketTimeoutException; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.cert.X509Certificate; |
| | | import javax.net.ssl.HostnameVerifier; |
| | | import javax.net.ssl.HttpsURLConnection; |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.SSLSession; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * éç¨httpåéæ¹æ³ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class HttpUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(HttpUtils.class); |
| | | |
| | | /** |
| | | * åæå® URL åéGETæ¹æ³çè¯·æ± |
| | | * |
| | | * @param url åé请æ±ç URL |
| | | * @return æ代表è¿ç¨èµæºçååºç»æ |
| | | */ |
| | | public static String sendGet(String url) |
| | | { |
| | | return sendGet(url, StringUtils.EMPTY); |
| | | } |
| | | |
| | | /** |
| | | * åæå® URL åéGETæ¹æ³çè¯·æ± |
| | | * |
| | | * @param url åé请æ±ç URL |
| | | * @param param 请æ±åæ°ï¼è¯·æ±åæ°åºè¯¥æ¯ name1=value1&name2=value2 çå½¢å¼ã |
| | | * @return æ代表è¿ç¨èµæºçååºç»æ |
| | | */ |
| | | public static String sendGet(String url, String param) |
| | | { |
| | | return sendGet(url, param, Constants.UTF8); |
| | | } |
| | | |
| | | /** |
| | | * åæå® URL åéGETæ¹æ³çè¯·æ± |
| | | * |
| | | * @param url åé请æ±ç URL |
| | | * @param param 请æ±åæ°ï¼è¯·æ±åæ°åºè¯¥æ¯ name1=value1&name2=value2 çå½¢å¼ã |
| | | * @param contentType ç¼ç ç±»å |
| | | * @return æ代表è¿ç¨èµæºçååºç»æ |
| | | */ |
| | | public static String sendGet(String url, String param, String contentType) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | BufferedReader in = null; |
| | | try |
| | | { |
| | | String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url; |
| | | log.info("sendGet - {}", urlNameString); |
| | | URL realUrl = new URL(urlNameString); |
| | | URLConnection connection = realUrl.openConnection(); |
| | | connection.setRequestProperty("accept", "*/*"); |
| | | connection.setRequestProperty("connection", "Keep-Alive"); |
| | | connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | connection.connect(); |
| | | in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType)); |
| | | String line; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | result.append(line); |
| | | } |
| | | log.info("recv - {}", result); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è°ç¨HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (in != null) |
| | | { |
| | | in.close(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.error("è°ç¨in.close Exception, url=" + url + ",param=" + param, ex); |
| | | } |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | /** |
| | | * åæå® URL åéPOSTæ¹æ³çè¯·æ± |
| | | * |
| | | * @param url åé请æ±ç URL |
| | | * @param param 请æ±åæ°ï¼è¯·æ±åæ°åºè¯¥æ¯ name1=value1&name2=value2 çå½¢å¼ã |
| | | * @return æ代表è¿ç¨èµæºçååºç»æ |
| | | */ |
| | | public static String sendPost(String url, String param) |
| | | { |
| | | PrintWriter out = null; |
| | | BufferedReader in = null; |
| | | StringBuilder result = new StringBuilder(); |
| | | try |
| | | { |
| | | log.info("sendPost - {}", url); |
| | | URL realUrl = new URL(url); |
| | | URLConnection conn = realUrl.openConnection(); |
| | | conn.setRequestProperty("accept", "*/*"); |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("contentType", "utf-8"); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | out = new PrintWriter(conn.getOutputStream()); |
| | | out.print(param); |
| | | out.flush(); |
| | | in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); |
| | | String line; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | result.append(line); |
| | | } |
| | | log.info("recv - {}", result); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è°ç¨HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (out != null) |
| | | { |
| | | out.close(); |
| | | } |
| | | if (in != null) |
| | | { |
| | | in.close(); |
| | | } |
| | | } |
| | | catch (IOException ex) |
| | | { |
| | | log.error("è°ç¨in.close Exception, url=" + url + ",param=" + param, ex); |
| | | } |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | public static String sendSSLPost(String url, String param) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | String urlNameString = url + "?" + param; |
| | | try |
| | | { |
| | | log.info("sendSSLPost - {}", urlNameString); |
| | | SSLContext sc = SSLContext.getInstance("SSL"); |
| | | sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom()); |
| | | URL console = new URL(urlNameString); |
| | | HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(); |
| | | conn.setRequestProperty("accept", "*/*"); |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("contentType", "utf-8"); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | |
| | | conn.setSSLSocketFactory(sc.getSocketFactory()); |
| | | conn.setHostnameVerifier(new TrustAnyHostnameVerifier()); |
| | | conn.connect(); |
| | | InputStream is = conn.getInputStream(); |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
| | | String ret = ""; |
| | | while ((ret = br.readLine()) != null) |
| | | { |
| | | if (ret != null && !"".equals(ret.trim())) |
| | | { |
| | | result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); |
| | | } |
| | | } |
| | | log.info("recv - {}", result); |
| | | conn.disconnect(); |
| | | br.close(); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("è°ç¨HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è°ç¨HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | private static class TrustAnyTrustManager implements X509TrustManager |
| | | { |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] chain, String authType) |
| | | { |
| | | } |
| | | |
| | | @Override |
| | | public void checkServerTrusted(X509Certificate[] chain, String authType) |
| | | { |
| | | } |
| | | |
| | | @Override |
| | | public X509Certificate[] getAcceptedIssuers() |
| | | { |
| | | return new X509Certificate[] {}; |
| | | } |
| | | } |
| | | |
| | | private static class TrustAnyHostnameVerifier implements HostnameVerifier |
| | | { |
| | | @Override |
| | | public boolean verify(String hostname, SSLSession session) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.ip; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.http.HttpUtils; |
| | | |
| | | /** |
| | | * è·åå°åç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class AddressUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AddressUtils.class); |
| | | |
| | | // IPå°åæ¥è¯¢ |
| | | public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; |
| | | |
| | | // æªç¥å°å |
| | | public static final String UNKNOWN = "XX XX"; |
| | | |
| | | public static String getRealAddressByIP(String ip) |
| | | { |
| | | // å
ç½ä¸æ¥è¯¢ |
| | | if (IpUtils.internalIp(ip)) |
| | | { |
| | | return "å
ç½IP"; |
| | | } |
| | | if (MesConfig.isAddressEnabled()) |
| | | { |
| | | try |
| | | { |
| | | String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK); |
| | | if (StringUtils.isEmpty(rspStr)) |
| | | { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | return UNKNOWN; |
| | | } |
| | | JSONObject obj = JSON.parseObject(rspStr); |
| | | String region = obj.getString("pro"); |
| | | String city = obj.getString("city"); |
| | | return String.format("%s %s", region, city); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | } |
| | | } |
| | | return UNKNOWN; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.ip; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * è·åIPæ¹æ³ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class IpUtils |
| | | { |
| | | public final static String REGX_0_255 = "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)"; |
| | | // å¹é
ip |
| | | public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")"; |
| | | public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))"; |
| | | // å¹é
ç½æ®µ |
| | | public final static String REGX_IP_SEG = "(" + REGX_IP + "\\-" + REGX_IP + ")"; |
| | | |
| | | /** |
| | | * è·å客æ·ç«¯IP |
| | | * |
| | | * @return IPå°å |
| | | */ |
| | | public static String getIpAddr() |
| | | { |
| | | return getIpAddr(ServletUtils.getRequest()); |
| | | } |
| | | |
| | | /** |
| | | * è·å客æ·ç«¯IP |
| | | * |
| | | * @param request 请æ±å¯¹è±¡ |
| | | * @return IPå°å |
| | | */ |
| | | public static String getIpAddr(HttpServletRequest request) |
| | | { |
| | | if (request == null) |
| | | { |
| | | return "unknown"; |
| | | } |
| | | String ip = request.getHeader("x-forwarded-for"); |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) |
| | | { |
| | | ip = request.getHeader("Proxy-Client-IP"); |
| | | } |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) |
| | | { |
| | | ip = request.getHeader("X-Forwarded-For"); |
| | | } |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) |
| | | { |
| | | ip = request.getHeader("WL-Proxy-Client-IP"); |
| | | } |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) |
| | | { |
| | | ip = request.getHeader("X-Real-IP"); |
| | | } |
| | | |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) |
| | | { |
| | | ip = request.getRemoteAddr(); |
| | | } |
| | | |
| | | return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ¯å¦ä¸ºå
é¨IPå°å |
| | | * |
| | | * @param ip IPå°å |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean internalIp(String ip) |
| | | { |
| | | byte[] addr = textToNumericFormatV4(ip); |
| | | return internalIp(addr) || "127.0.0.1".equals(ip); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ¯å¦ä¸ºå
é¨IPå°å |
| | | * |
| | | * @param addr byteå°å |
| | | * @return ç»æ |
| | | */ |
| | | private static boolean internalIp(byte[] addr) |
| | | { |
| | | if (StringUtils.isNull(addr) || addr.length < 2) |
| | | { |
| | | return true; |
| | | } |
| | | final byte b0 = addr[0]; |
| | | final byte b1 = addr[1]; |
| | | // 10.x.x.x/8 |
| | | final byte SECTION_1 = 0x0A; |
| | | // 172.16.x.x/12 |
| | | final byte SECTION_2 = (byte) 0xAC; |
| | | final byte SECTION_3 = (byte) 0x10; |
| | | final byte SECTION_4 = (byte) 0x1F; |
| | | // 192.168.x.x/16 |
| | | final byte SECTION_5 = (byte) 0xC0; |
| | | final byte SECTION_6 = (byte) 0xA8; |
| | | switch (b0) |
| | | { |
| | | case SECTION_1: |
| | | return true; |
| | | case SECTION_2: |
| | | if (b1 >= SECTION_3 && b1 <= SECTION_4) |
| | | { |
| | | return true; |
| | | } |
| | | case SECTION_5: |
| | | switch (b1) |
| | | { |
| | | case SECTION_6: |
| | | return true; |
| | | } |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°IPv4å°å转æ¢æåè |
| | | * |
| | | * @param text IPv4å°å |
| | | * @return byte åè |
| | | */ |
| | | public static byte[] textToNumericFormatV4(String text) |
| | | { |
| | | if (text.length() == 0) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | byte[] bytes = new byte[4]; |
| | | String[] elements = text.split("\\.", -1); |
| | | try |
| | | { |
| | | long l; |
| | | int i; |
| | | switch (elements.length) |
| | | { |
| | | case 1: |
| | | l = Long.parseLong(elements[0]); |
| | | if ((l < 0L) || (l > 4294967295L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[0] = (byte) (int) (l >> 24 & 0xFF); |
| | | bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF); |
| | | bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); |
| | | bytes[3] = (byte) (int) (l & 0xFF); |
| | | break; |
| | | case 2: |
| | | l = Integer.parseInt(elements[0]); |
| | | if ((l < 0L) || (l > 255L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[0] = (byte) (int) (l & 0xFF); |
| | | l = Integer.parseInt(elements[1]); |
| | | if ((l < 0L) || (l > 16777215L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[1] = (byte) (int) (l >> 16 & 0xFF); |
| | | bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF); |
| | | bytes[3] = (byte) (int) (l & 0xFF); |
| | | break; |
| | | case 3: |
| | | for (i = 0; i < 2; ++i) |
| | | { |
| | | l = Integer.parseInt(elements[i]); |
| | | if ((l < 0L) || (l > 255L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[i] = (byte) (int) (l & 0xFF); |
| | | } |
| | | l = Integer.parseInt(elements[2]); |
| | | if ((l < 0L) || (l > 65535L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[2] = (byte) (int) (l >> 8 & 0xFF); |
| | | bytes[3] = (byte) (int) (l & 0xFF); |
| | | break; |
| | | case 4: |
| | | for (i = 0; i < 4; ++i) |
| | | { |
| | | l = Integer.parseInt(elements[i]); |
| | | if ((l < 0L) || (l > 255L)) |
| | | { |
| | | return null; |
| | | } |
| | | bytes[i] = (byte) (int) (l & 0xFF); |
| | | } |
| | | break; |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | catch (NumberFormatException e) |
| | | { |
| | | return null; |
| | | } |
| | | return bytes; |
| | | } |
| | | |
| | | /** |
| | | * è·åIPå°å |
| | | * |
| | | * @return æ¬å°IPå°å |
| | | */ |
| | | public static String getHostIp() |
| | | { |
| | | try |
| | | { |
| | | return InetAddress.getLocalHost().getHostAddress(); |
| | | } |
| | | catch (UnknownHostException e) |
| | | { |
| | | } |
| | | return "127.0.0.1"; |
| | | } |
| | | |
| | | /** |
| | | * è·å主æºå |
| | | * |
| | | * @return æ¬å°ä¸»æºå |
| | | */ |
| | | public static String getHostName() |
| | | { |
| | | try |
| | | { |
| | | return InetAddress.getLocalHost().getHostName(); |
| | | } |
| | | catch (UnknownHostException e) |
| | | { |
| | | } |
| | | return "æªç¥"; |
| | | } |
| | | |
| | | /** |
| | | * ä»å¤çº§åå代çä¸è·å¾ç¬¬ä¸ä¸ªéunknown IPå°å |
| | | * |
| | | * @param ip è·å¾çIPå°å |
| | | * @return 第ä¸ä¸ªéunknown IPå°å |
| | | */ |
| | | public static String getMultistageReverseProxyIp(String ip) |
| | | { |
| | | // å¤çº§åå代çæ£æµ |
| | | if (ip != null && ip.indexOf(",") > 0) |
| | | { |
| | | final String[] ips = ip.trim().split(","); |
| | | for (String subIp : ips) |
| | | { |
| | | if (false == isUnknown(subIp)) |
| | | { |
| | | ip = subIp; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.substring(ip, 0, 255); |
| | | } |
| | | |
| | | /** |
| | | * æ£æµç»å®å符串æ¯å¦ä¸ºæªç¥ï¼å¤ç¨äºæ£æµHTTP请æ±ç¸å
³ |
| | | * |
| | | * @param checkString 被æ£æµçå符串 |
| | | * @return æ¯å¦æªç¥ |
| | | */ |
| | | public static boolean isUnknown(String checkString) |
| | | { |
| | | return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºIP |
| | | */ |
| | | public static boolean isIP(String ip) |
| | | { |
| | | return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºIPï¼æ *为é´éçéé
符å°å |
| | | */ |
| | | public static boolean isIpWildCard(String ip) |
| | | { |
| | | return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP_WILDCARD); |
| | | } |
| | | |
| | | /** |
| | | * æ£æµåæ°æ¯å¦å¨ipéé
符é |
| | | */ |
| | | public static boolean ipIsInWildCardNoCheck(String ipWildCard, String ip) |
| | | { |
| | | String[] s1 = ipWildCard.split("\\."); |
| | | String[] s2 = ip.split("\\."); |
| | | boolean isMatchedSeg = true; |
| | | for (int i = 0; i < s1.length && !s1[i].equals("*"); i++) |
| | | { |
| | | if (!s1[i].equals(s2[i])) |
| | | { |
| | | isMatchedSeg = false; |
| | | break; |
| | | } |
| | | } |
| | | return isMatchedSeg; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºç¹å®æ ¼å¼å¦:â10.10.10.1-10.10.10.99âçip段å符串 |
| | | */ |
| | | public static boolean isIPSegment(String ipSeg) |
| | | { |
| | | return StringUtils.isNotBlank(ipSeg) && ipSeg.matches(REGX_IP_SEG); |
| | | } |
| | | |
| | | /** |
| | | * å¤æipæ¯å¦å¨æå®ç½æ®µä¸ |
| | | */ |
| | | public static boolean ipIsInNetNoCheck(String iparea, String ip) |
| | | { |
| | | int idx = iparea.indexOf('-'); |
| | | String[] sips = iparea.substring(0, idx).split("\\."); |
| | | String[] sipe = iparea.substring(idx + 1).split("\\."); |
| | | String[] sipt = ip.split("\\."); |
| | | long ips = 0L, ipe = 0L, ipt = 0L; |
| | | for (int i = 0; i < 4; ++i) |
| | | { |
| | | ips = ips << 8 | Integer.parseInt(sips[i]); |
| | | ipe = ipe << 8 | Integer.parseInt(sipe[i]); |
| | | ipt = ipt << 8 | Integer.parseInt(sipt[i]); |
| | | } |
| | | if (ips > ipe) |
| | | { |
| | | long t = ips; |
| | | ips = ipe; |
| | | ipe = t; |
| | | } |
| | | return ips <= ipt && ipt <= ipe; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªipæ¯å¦ç¬¦åè¿æ»¤ä¸²è§å |
| | | * |
| | | * @param filter è¿æ»¤IPå表,æ¯æåç¼'*'éé
,æ¯æç½æ®µå¦:`10.10.10.1-10.10.10.99` |
| | | * @param ip æ ¡éªIPå°å |
| | | * @return boolean ç»æ |
| | | */ |
| | | public static boolean isMatchedIp(String filter, String ip) |
| | | { |
| | | if (StringUtils.isEmpty(filter) || StringUtils.isEmpty(ip)) |
| | | { |
| | | return false; |
| | | } |
| | | String[] ips = filter.split(";"); |
| | | for (String iStr : ips) |
| | | { |
| | | if (isIP(iStr) && iStr.equals(ip)) |
| | | { |
| | | return true; |
| | | } |
| | | else if (isIpWildCard(iStr) && ipIsInWildCardNoCheck(iStr, ip)) |
| | | { |
| | | return true; |
| | | } |
| | | else if (isIPSegment(iStr) && ipIsInNetNoCheck(iStr, ip)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.poi; |
| | | |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | |
| | | /** |
| | | * Excelæ°æ®æ ¼å¼å¤çéé
å¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public interface ExcelHandlerAdapter |
| | | { |
| | | /** |
| | | * æ ¼å¼å |
| | | * |
| | | * @param value åå
æ ¼æ°æ®å¼ |
| | | * @param args excel注解argsåæ°ç» |
| | | * @param cell åå
æ ¼å¯¹è±¡ |
| | | * @param wb å·¥ä½ç°¿å¯¹è±¡ |
| | | * |
| | | * @return å¤çåçå¼ |
| | | */ |
| | | Object format(Object value, String[] args, Cell cell, Workbook wb); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.poi; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.ParameterizedType; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.apache.commons.lang3.RegExUtils; |
| | | import org.apache.commons.lang3.reflect.FieldUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFPicture; |
| | | import org.apache.poi.hssf.usermodel.HSSFPictureData; |
| | | import org.apache.poi.hssf.usermodel.HSSFShape; |
| | | import org.apache.poi.hssf.usermodel.HSSFSheet; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ooxml.POIXMLDocumentPart; |
| | | import org.apache.poi.ss.usermodel.BorderStyle; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.CellStyle; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DataValidationHelper; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.apache.poi.ss.usermodel.Drawing; |
| | | import org.apache.poi.ss.usermodel.FillPatternType; |
| | | import org.apache.poi.ss.usermodel.Font; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import org.apache.poi.ss.usermodel.Name; |
| | | import org.apache.poi.ss.usermodel.PictureData; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.VerticalAlignment; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.util.IOUtils; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.apache.poi.xssf.usermodel.XSSFDrawing; |
| | | import org.apache.poi.xssf.usermodel.XSSFPicture; |
| | | import org.apache.poi.xssf.usermodel.XSSFShape; |
| | | import org.apache.poi.xssf.usermodel.XSSFSheet; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.jcdm.common.annotation.Excel; |
| | | import com.jcdm.common.annotation.Excel.ColumnType; |
| | | import com.jcdm.common.annotation.Excel.Type; |
| | | import com.jcdm.common.annotation.Excels; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.core.text.Convert; |
| | | import com.jcdm.common.exception.UtilException; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | import com.jcdm.common.utils.DictUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.file.FileTypeUtils; |
| | | import com.jcdm.common.utils.file.FileUtils; |
| | | import com.jcdm.common.utils.file.ImageUtils; |
| | | import com.jcdm.common.utils.reflect.ReflectUtils; |
| | | |
| | | /** |
| | | * Excelç¸å
³å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class ExcelUtil<T> |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); |
| | | |
| | | public static final String FORMULA_REGEX_STR = "=|-|\\+|@"; |
| | | |
| | | public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; |
| | | |
| | | /** |
| | | * ç¨äºdictTypeå±æ§æ°æ®åå¨ï¼é¿å
éå¤æ¥ç¼å |
| | | */ |
| | | public Map<String, String> sysDictMap = new HashMap<String, String>(); |
| | | |
| | | /** |
| | | * Excel sheetæ大è¡æ°ï¼é»è®¤65536 |
| | | */ |
| | | public static final int sheetSize = 65536; |
| | | |
| | | /** |
| | | * å·¥ä½è¡¨å称 |
| | | */ |
| | | private String sheetName; |
| | | |
| | | /** |
| | | * 导åºç±»åï¼EXPORT:导åºæ°æ®ï¼IMPORTï¼å¯¼å
¥æ¨¡æ¿ï¼ |
| | | */ |
| | | private Type type; |
| | | |
| | | /** |
| | | * å·¥ä½è对象 |
| | | */ |
| | | private Workbook wb; |
| | | |
| | | /** |
| | | * å·¥ä½è¡¨å¯¹è±¡ |
| | | */ |
| | | private Sheet sheet; |
| | | |
| | | /** |
| | | * æ ·å¼å表 |
| | | */ |
| | | private Map<String, CellStyle> styles; |
| | | |
| | | /** |
| | | * 导å
¥å¯¼åºæ°æ®å表 |
| | | */ |
| | | private List<T> list; |
| | | |
| | | /** |
| | | * 注解å表 |
| | | */ |
| | | private List<Object[]> fields; |
| | | |
| | | /** |
| | | * å½åè¡å· |
| | | */ |
| | | private int rownum; |
| | | |
| | | /** |
| | | * æ é¢ |
| | | */ |
| | | private String title; |
| | | |
| | | /** |
| | | * æ大é«åº¦ |
| | | */ |
| | | private short maxHeight; |
| | | |
| | | /** |
| | | * å并åæåè¡æ° |
| | | */ |
| | | private int subMergedLastRowNum = 0; |
| | | |
| | | /** |
| | | * å并åå¼å§è¡æ° |
| | | */ |
| | | private int subMergedFirstRowNum = 1; |
| | | |
| | | /** |
| | | * 对象çåå表æ¹æ³ |
| | | */ |
| | | private Method subMethod; |
| | | |
| | | /** |
| | | * 对象çåå表å±æ§ |
| | | */ |
| | | private List<Field> subFields; |
| | | |
| | | /** |
| | | * ç»è®¡å表 |
| | | */ |
| | | private Map<Integer, Double> statistics = new HashMap<Integer, Double>(); |
| | | |
| | | /** |
| | | * æ°åæ ¼å¼ |
| | | */ |
| | | private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); |
| | | |
| | | /** |
| | | * å®ä½å¯¹è±¡ |
| | | */ |
| | | public Class<T> clazz; |
| | | |
| | | /** |
| | | * éè¦æé¤åå±æ§ |
| | | */ |
| | | public String[] excludeFields; |
| | | |
| | | public ExcelUtil(Class<T> clazz) |
| | | { |
| | | this.clazz = clazz; |
| | | } |
| | | |
| | | /** |
| | | * éèExcelä¸åå±æ§ |
| | | * |
| | | * @param fields åå±æ§å 示ä¾[å个"name"/å¤ä¸ª"id","name"] |
| | | * @throws Exception |
| | | */ |
| | | public void hideColumn(String... fields) |
| | | { |
| | | this.excludeFields = fields; |
| | | } |
| | | |
| | | public void init(List<T> list, String sheetName, String title, Type type) |
| | | { |
| | | if (list == null) |
| | | { |
| | | list = new ArrayList<T>(); |
| | | } |
| | | this.list = list; |
| | | this.sheetName = sheetName; |
| | | this.type = type; |
| | | this.title = title; |
| | | createExcelField(); |
| | | createWorkbook(); |
| | | createTitle(); |
| | | createSubHead(); |
| | | } |
| | | |
| | | /** |
| | | * å建excel第ä¸è¡æ é¢ |
| | | */ |
| | | public void createTitle() |
| | | { |
| | | if (StringUtils.isNotEmpty(title)) |
| | | { |
| | | subMergedFirstRowNum++; |
| | | subMergedLastRowNum++; |
| | | int titleLastCol = this.fields.size() - 1; |
| | | if (isSubList()) |
| | | { |
| | | titleLastCol = titleLastCol + subFields.size() - 1; |
| | | } |
| | | Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0); |
| | | titleRow.setHeightInPoints(30); |
| | | Cell titleCell = titleRow.createCell(0); |
| | | titleCell.setCellStyle(styles.get("title")); |
| | | titleCell.setCellValue(title); |
| | | sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å建对象çåå表å称 |
| | | */ |
| | | public void createSubHead() |
| | | { |
| | | if (isSubList()) |
| | | { |
| | | subMergedFirstRowNum++; |
| | | subMergedLastRowNum++; |
| | | Row subRow = sheet.createRow(rownum); |
| | | int excelNum = 0; |
| | | for (Object[] objects : fields) |
| | | { |
| | | Excel attr = (Excel) objects[1]; |
| | | Cell headCell1 = subRow.createCell(excelNum); |
| | | headCell1.setCellValue(attr.name()); |
| | | headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); |
| | | excelNum++; |
| | | } |
| | | int headFirstRow = excelNum - 1; |
| | | int headLastRow = headFirstRow + subFields.size() - 1; |
| | | if (headLastRow > headFirstRow) |
| | | { |
| | | sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow)); |
| | | } |
| | | rownum++; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对excel表åé»è®¤ç¬¬ä¸ä¸ªç´¢å¼å转æ¢ælist |
| | | * |
| | | * @param is è¾å
¥æµ |
| | | * @return 转æ¢åéå |
| | | */ |
| | | public List<T> importExcel(InputStream is) |
| | | { |
| | | List<T> list = null; |
| | | try |
| | | { |
| | | list = importExcel(is, 0); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导å
¥Excelå¼å¸¸{}", e.getMessage()); |
| | | throw new UtilException(e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(is); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 对excel表åé»è®¤ç¬¬ä¸ä¸ªç´¢å¼å转æ¢ælist |
| | | * |
| | | * @param is è¾å
¥æµ |
| | | * @param titleNum æ é¢å ç¨è¡æ° |
| | | * @return 转æ¢åéå |
| | | */ |
| | | public List<T> importExcel(InputStream is, int titleNum) throws Exception |
| | | { |
| | | return importExcel(StringUtils.EMPTY, is, titleNum); |
| | | } |
| | | |
| | | /** |
| | | * 对excel表åæå®è¡¨æ ¼ç´¢å¼å转æ¢ælist |
| | | * |
| | | * @param sheetName è¡¨æ ¼ç´¢å¼å |
| | | * @param titleNum æ é¢å ç¨è¡æ° |
| | | * @param is è¾å
¥æµ |
| | | * @return 转æ¢åéå |
| | | */ |
| | | public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception |
| | | { |
| | | this.type = Type.IMPORT; |
| | | this.wb = WorkbookFactory.create(is); |
| | | List<T> list = new ArrayList<T>(); |
| | | // å¦ææå®sheetå,ååæå®sheetä¸çå
容 å¦åé»è®¤æå第1个sheet |
| | | Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0); |
| | | if (sheet == null) |
| | | { |
| | | throw new IOException("æ件sheetä¸åå¨"); |
| | | } |
| | | boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook); |
| | | Map<String, PictureData> pictures; |
| | | if (isXSSFWorkbook) |
| | | { |
| | | pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb); |
| | | } |
| | | else |
| | | { |
| | | pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb); |
| | | } |
| | | // è·åæåä¸ä¸ªé空è¡çè¡ä¸æ ï¼æ¯å¦æ»è¡æ°ä¸ºnï¼åè¿åç为n-1 |
| | | int rows = sheet.getLastRowNum(); |
| | | if (rows > 0) |
| | | { |
| | | // å®ä¹ä¸ä¸ªmapç¨äºåæ¾excelåçåºå·åfield. |
| | | Map<String, Integer> cellMap = new HashMap<String, Integer>(); |
| | | // è·å表头 |
| | | Row heard = sheet.getRow(titleNum); |
| | | for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) |
| | | { |
| | | Cell cell = heard.getCell(i); |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | String value = this.getCellValue(heard, i).toString(); |
| | | cellMap.put(value, i); |
| | | } |
| | | else |
| | | { |
| | | cellMap.put(null, i); |
| | | } |
| | | } |
| | | // ææ°æ®æ¶æå¤ç å¾å°ç±»çææfield. |
| | | List<Object[]> fields = this.getFields(); |
| | | Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>(); |
| | | for (Object[] objects : fields) |
| | | { |
| | | Excel attr = (Excel) objects[1]; |
| | | Integer column = cellMap.get(attr.name()); |
| | | if (column != null) |
| | | { |
| | | fieldsMap.put(column, objects); |
| | | } |
| | | } |
| | | for (int i = titleNum + 1; i <= rows; i++) |
| | | { |
| | | // ä»ç¬¬2è¡å¼å§åæ°æ®,é»è®¤ç¬¬ä¸è¡æ¯è¡¨å¤´. |
| | | Row row = sheet.getRow(i); |
| | | // å¤æå½åè¡æ¯å¦æ¯ç©ºè¡ |
| | | if (isRowEmpty(row)) |
| | | { |
| | | continue; |
| | | } |
| | | T entity = null; |
| | | for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet()) |
| | | { |
| | | Object val = this.getCellValue(row, entry.getKey()); |
| | | |
| | | // å¦æä¸åå¨å®ä¾åæ°å»º. |
| | | entity = (entity == null ? clazz.newInstance() : entity); |
| | | // ä»mapä¸å¾å°å¯¹åºåçfield. |
| | | Field field = (Field) entry.getValue()[0]; |
| | | Excel attr = (Excel) entry.getValue()[1]; |
| | | // åå¾ç±»å,å¹¶æ ¹æ®å¯¹è±¡ç±»å设置å¼. |
| | | Class<?> fieldType = field.getType(); |
| | | if (String.class == fieldType) |
| | | { |
| | | String s = Convert.toStr(val); |
| | | if (StringUtils.endsWith(s, ".0")) |
| | | { |
| | | val = StringUtils.substringBefore(s, ".0"); |
| | | } |
| | | else |
| | | { |
| | | String dateFormat = field.getAnnotation(Excel.class).dateFormat(); |
| | | if (StringUtils.isNotEmpty(dateFormat)) |
| | | { |
| | | val = parseDateToStr(dateFormat, val); |
| | | } |
| | | else |
| | | { |
| | | val = Convert.toStr(val); |
| | | } |
| | | } |
| | | } |
| | | else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) |
| | | { |
| | | val = Convert.toInt(val); |
| | | } |
| | | else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) |
| | | { |
| | | val = Convert.toLong(val); |
| | | } |
| | | else if (Double.TYPE == fieldType || Double.class == fieldType) |
| | | { |
| | | val = Convert.toDouble(val); |
| | | } |
| | | else if (Float.TYPE == fieldType || Float.class == fieldType) |
| | | { |
| | | val = Convert.toFloat(val); |
| | | } |
| | | else if (BigDecimal.class == fieldType) |
| | | { |
| | | val = Convert.toBigDecimal(val); |
| | | } |
| | | else if (Date.class == fieldType) |
| | | { |
| | | if (val instanceof String) |
| | | { |
| | | val = DateUtils.parseDate(val); |
| | | } |
| | | else if (val instanceof Double) |
| | | { |
| | | val = DateUtil.getJavaDate((Double) val); |
| | | } |
| | | } |
| | | else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) |
| | | { |
| | | val = Convert.toBool(val, false); |
| | | } |
| | | if (StringUtils.isNotNull(fieldType)) |
| | | { |
| | | String propertyName = field.getName(); |
| | | if (StringUtils.isNotEmpty(attr.targetAttr())) |
| | | { |
| | | propertyName = field.getName() + "." + attr.targetAttr(); |
| | | } |
| | | if (StringUtils.isNotEmpty(attr.readConverterExp())) |
| | | { |
| | | val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); |
| | | } |
| | | else if (StringUtils.isNotEmpty(attr.dictType())) |
| | | { |
| | | val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator()); |
| | | } |
| | | else if (!attr.handler().equals(ExcelHandlerAdapter.class)) |
| | | { |
| | | val = dataFormatHandlerAdapter(val, attr, null); |
| | | } |
| | | else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures)) |
| | | { |
| | | PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey()); |
| | | if (image == null) |
| | | { |
| | | val = ""; |
| | | } |
| | | else |
| | | { |
| | | byte[] data = image.getData(); |
| | | val = FileUtils.writeImportBytes(data); |
| | | } |
| | | } |
| | | ReflectUtils.invokeSetter(entity, propertyName, val); |
| | | } |
| | | } |
| | | list.add(entity); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param list 导åºæ°æ®éå |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @return ç»æ |
| | | */ |
| | | public AjaxResult exportExcel(List<T> list, String sheetName) |
| | | { |
| | | return exportExcel(list, sheetName, StringUtils.EMPTY); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param list 导åºæ°æ®éå |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @param title æ é¢ |
| | | * @return ç»æ |
| | | */ |
| | | public AjaxResult exportExcel(List<T> list, String sheetName, String title) |
| | | { |
| | | this.init(list, sheetName, title, Type.EXPORT); |
| | | return exportExcel(); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param response è¿åæ°æ® |
| | | * @param list 导åºæ°æ®éå |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @return ç»æ |
| | | */ |
| | | public void exportExcel(HttpServletResponse response, List<T> list, String sheetName) |
| | | { |
| | | exportExcel(response, list, sheetName, StringUtils.EMPTY); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param response è¿åæ°æ® |
| | | * @param list 导åºæ°æ®éå |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @param title æ é¢ |
| | | * @return ç»æ |
| | | */ |
| | | public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title) |
| | | { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | this.init(list, sheetName, title, Type.EXPORT); |
| | | exportExcel(response); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @return ç»æ |
| | | */ |
| | | public AjaxResult importTemplateExcel(String sheetName) |
| | | { |
| | | return importTemplateExcel(sheetName, StringUtils.EMPTY); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @param title æ é¢ |
| | | * @return ç»æ |
| | | */ |
| | | public AjaxResult importTemplateExcel(String sheetName, String title) |
| | | { |
| | | this.init(null, sheetName, title, Type.IMPORT); |
| | | return exportExcel(); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @return ç»æ |
| | | */ |
| | | public void importTemplateExcel(HttpServletResponse response, String sheetName) |
| | | { |
| | | importTemplateExcel(response, sheetName, StringUtils.EMPTY); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @param sheetName å·¥ä½è¡¨çå称 |
| | | * @param title æ é¢ |
| | | * @return ç»æ |
| | | */ |
| | | public void importTemplateExcel(HttpServletResponse response, String sheetName, String title) |
| | | { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | this.init(null, sheetName, title, Type.IMPORT); |
| | | exportExcel(response); |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public void exportExcel(HttpServletResponse response) |
| | | { |
| | | try |
| | | { |
| | | writeSheet(); |
| | | wb.write(response.getOutputStream()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导åºExcelå¼å¸¸{}", e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(wb); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对listæ°æ®æºå°å
¶éé¢çæ°æ®å¯¼å
¥å°excel表å |
| | | * |
| | | * @return ç»æ |
| | | */ |
| | | public AjaxResult exportExcel() |
| | | { |
| | | OutputStream out = null; |
| | | try |
| | | { |
| | | writeSheet(); |
| | | String filename = encodingFilename(sheetName); |
| | | out = new FileOutputStream(getAbsoluteFile(filename)); |
| | | wb.write(out); |
| | | return AjaxResult.success(filename); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导åºExcelå¼å¸¸{}", e.getMessage()); |
| | | throw new UtilException("导åºExcel失败ï¼è¯·èç³»ç½ç«ç®¡çåï¼"); |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(wb); |
| | | IOUtils.closeQuietly(out); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å建åå
¥æ°æ®å°Sheet |
| | | */ |
| | | public void writeSheet() |
| | | { |
| | | // ååºä¸å
±æå¤å°ä¸ªsheet. |
| | | int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize)); |
| | | for (int index = 0; index < sheetNo; index++) |
| | | { |
| | | createSheet(sheetNo, index); |
| | | |
| | | // 产çä¸è¡ |
| | | Row row = sheet.createRow(rownum); |
| | | int column = 0; |
| | | // åå
¥å个å段çå头å称 |
| | | for (Object[] os : fields) |
| | | { |
| | | Field field = (Field) os[0]; |
| | | Excel excel = (Excel) os[1]; |
| | | if (Collection.class.isAssignableFrom(field.getType())) |
| | | { |
| | | for (Field subField : subFields) |
| | | { |
| | | Excel subExcel = subField.getAnnotation(Excel.class); |
| | | this.createHeadCell(subExcel, row, column++); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | this.createHeadCell(excel, row, column++); |
| | | } |
| | | } |
| | | if (Type.EXPORT.equals(type)) |
| | | { |
| | | fillExcelData(index, row); |
| | | addStatisticsRow(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¡«å
excelæ°æ® |
| | | * |
| | | * @param index åºå· |
| | | * @param row åå
æ ¼è¡ |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public void fillExcelData(int index, Row row) |
| | | { |
| | | int startNo = index * sheetSize; |
| | | int endNo = Math.min(startNo + sheetSize, list.size()); |
| | | int rowNo = (1 + rownum) - startNo; |
| | | for (int i = startNo; i < endNo; i++) |
| | | { |
| | | rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo; |
| | | row = sheet.createRow(rowNo); |
| | | // å¾å°å¯¼åºå¯¹è±¡. |
| | | T vo = (T) list.get(i); |
| | | Collection<?> subList = null; |
| | | if (isSubList()) |
| | | { |
| | | if (isSubListValue(vo)) |
| | | { |
| | | subList = getListCellValue(vo); |
| | | subMergedLastRowNum = subMergedLastRowNum + subList.size(); |
| | | } |
| | | else |
| | | { |
| | | subMergedFirstRowNum++; |
| | | subMergedLastRowNum++; |
| | | } |
| | | } |
| | | int column = 0; |
| | | for (Object[] os : fields) |
| | | { |
| | | Field field = (Field) os[0]; |
| | | Excel excel = (Excel) os[1]; |
| | | if (Collection.class.isAssignableFrom(field.getType()) && StringUtils.isNotNull(subList)) |
| | | { |
| | | boolean subFirst = false; |
| | | for (Object obj : subList) |
| | | { |
| | | if (subFirst) |
| | | { |
| | | rowNo++; |
| | | row = sheet.createRow(rowNo); |
| | | } |
| | | List<Field> subFields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), Excel.class); |
| | | int subIndex = 0; |
| | | for (Field subField : subFields) |
| | | { |
| | | if (subField.isAnnotationPresent(Excel.class)) |
| | | { |
| | | subField.setAccessible(true); |
| | | Excel attr = subField.getAnnotation(Excel.class); |
| | | this.addCell(attr, row, (T) obj, subField, column + subIndex); |
| | | } |
| | | subIndex++; |
| | | } |
| | | subFirst = true; |
| | | } |
| | | this.subMergedFirstRowNum = this.subMergedFirstRowNum + subList.size(); |
| | | } |
| | | else |
| | | { |
| | | this.addCell(excel, row, vo, field, column++); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå»ºè¡¨æ ¼æ ·å¼ |
| | | * |
| | | * @param wb å·¥ä½è对象 |
| | | * @return æ ·å¼å表 |
| | | */ |
| | | private Map<String, CellStyle> createStyles(Workbook wb) |
| | | { |
| | | // åå
¥åæ¡è®°å½,æ¯æ¡è®°å½å¯¹åºexcel表ä¸çä¸è¡ |
| | | Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | Font titleFont = wb.createFont(); |
| | | titleFont.setFontName("Arial"); |
| | | titleFont.setFontHeightInPoints((short) 16); |
| | | titleFont.setBold(true); |
| | | style.setFont(titleFont); |
| | | styles.put("title", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderTop(BorderStyle.THIN); |
| | | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderBottom(BorderStyle.THIN); |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | Font dataFont = wb.createFont(); |
| | | dataFont.setFontName("Arial"); |
| | | dataFont.setFontHeightInPoints((short) 10); |
| | | style.setFont(dataFont); |
| | | styles.put("data", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | Font totalFont = wb.createFont(); |
| | | totalFont.setFontName("Arial"); |
| | | totalFont.setFontHeightInPoints((short) 10); |
| | | style.setFont(totalFont); |
| | | styles.put("total", style); |
| | | |
| | | styles.putAll(annotationHeaderStyles(wb, styles)); |
| | | |
| | | styles.putAll(annotationDataStyles(wb)); |
| | | |
| | | return styles; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®Excel注解åå»ºè¡¨æ ¼å¤´æ ·å¼ |
| | | * |
| | | * @param wb å·¥ä½è对象 |
| | | * @return èªå®ä¹æ ·å¼å表 |
| | | */ |
| | | private Map<String, CellStyle> annotationHeaderStyles(Workbook wb, Map<String, CellStyle> styles) |
| | | { |
| | | Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>(); |
| | | for (Object[] os : fields) |
| | | { |
| | | Excel excel = (Excel) os[1]; |
| | | String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor()); |
| | | if (!headerStyles.containsKey(key)) |
| | | { |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setFillForegroundColor(excel.headerBackgroundColor().index); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font headerFont = wb.createFont(); |
| | | headerFont.setFontName("Arial"); |
| | | headerFont.setFontHeightInPoints((short) 10); |
| | | headerFont.setBold(true); |
| | | headerFont.setColor(excel.headerColor().index); |
| | | style.setFont(headerFont); |
| | | headerStyles.put(key, style); |
| | | } |
| | | } |
| | | return headerStyles; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®Excel注解åå»ºè¡¨æ ¼åæ ·å¼ |
| | | * |
| | | * @param wb å·¥ä½è对象 |
| | | * @return èªå®ä¹æ ·å¼å表 |
| | | */ |
| | | private Map<String, CellStyle> annotationDataStyles(Workbook wb) |
| | | { |
| | | Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); |
| | | for (Object[] os : fields) |
| | | { |
| | | Excel excel = (Excel) os[1]; |
| | | String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor()); |
| | | if (!styles.containsKey(key)) |
| | | { |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(excel.align()); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderTop(BorderStyle.THIN); |
| | | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderBottom(BorderStyle.THIN); |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | style.setFillForegroundColor(excel.backgroundColor().getIndex()); |
| | | Font dataFont = wb.createFont(); |
| | | dataFont.setFontName("Arial"); |
| | | dataFont.setFontHeightInPoints((short) 10); |
| | | dataFont.setColor(excel.color().index); |
| | | style.setFont(dataFont); |
| | | styles.put(key, style); |
| | | } |
| | | } |
| | | return styles; |
| | | } |
| | | |
| | | /** |
| | | * å建åå
æ ¼ |
| | | */ |
| | | public Cell createHeadCell(Excel attr, Row row, int column) |
| | | { |
| | | // å建å |
| | | Cell cell = row.createCell(column); |
| | | // åå
¥åä¿¡æ¯ |
| | | cell.setCellValue(attr.name()); |
| | | setDataValidation(attr, row, column); |
| | | cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); |
| | | if (isSubList()) |
| | | { |
| | | // å¡«å
é»è®¤æ ·å¼ï¼é²æ¢å并åå
æ ¼æ ·å¼å¤±æ |
| | | sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); |
| | | if (attr.needMerge()) |
| | | { |
| | | sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column)); |
| | | } |
| | | } |
| | | return cell; |
| | | } |
| | | |
| | | /** |
| | | * 设置åå
æ ¼ä¿¡æ¯ |
| | | * |
| | | * @param value åå
æ ¼å¼ |
| | | * @param attr 注解ç¸å
³ |
| | | * @param cell åå
æ ¼ä¿¡æ¯ |
| | | */ |
| | | public void setCellVo(Object value, Excel attr, Cell cell) |
| | | { |
| | | if (ColumnType.STRING == attr.cellType()) |
| | | { |
| | | String cellValue = Convert.toStr(value); |
| | | // 对äºä»»ä½ä»¥è¡¨è¾¾å¼è§¦åå符 =-+@å¼å¤´çåå
æ ¼ï¼ç´æ¥ä½¿ç¨tabå符ä½ä¸ºåç¼ï¼é²æ¢CSV注å
¥ã |
| | | if (StringUtils.startsWithAny(cellValue, FORMULA_STR)) |
| | | { |
| | | cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0"); |
| | | } |
| | | if (value instanceof Collection && StringUtils.equals("[]", cellValue)) |
| | | { |
| | | cellValue = StringUtils.EMPTY; |
| | | } |
| | | cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix()); |
| | | } |
| | | else if (ColumnType.NUMERIC == attr.cellType()) |
| | | { |
| | | if (StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } |
| | | } |
| | | else if (ColumnType.IMAGE == attr.cellType()) |
| | | { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(imagePath)) |
| | | { |
| | | byte[] data = ImageUtils.getImage(imagePath); |
| | | getDrawingPatriarch(cell.getSheet()).createPicture(anchor, |
| | | cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å¸ |
| | | */ |
| | | public static Drawing<?> getDrawingPatriarch(Sheet sheet) |
| | | { |
| | | if (sheet.getDrawingPatriarch() == null) |
| | | { |
| | | sheet.createDrawingPatriarch(); |
| | | } |
| | | return sheet.getDrawingPatriarch(); |
| | | } |
| | | |
| | | /** |
| | | * è·åå¾çç±»å,设置å¾çæå
¥ç±»å |
| | | */ |
| | | public int getImageType(byte[] value) |
| | | { |
| | | String type = FileTypeUtils.getFileExtendName(value); |
| | | if ("JPG".equalsIgnoreCase(type)) |
| | | { |
| | | return Workbook.PICTURE_TYPE_JPEG; |
| | | } |
| | | else if ("PNG".equalsIgnoreCase(type)) |
| | | { |
| | | return Workbook.PICTURE_TYPE_PNG; |
| | | } |
| | | return Workbook.PICTURE_TYPE_JPEG; |
| | | } |
| | | |
| | | /** |
| | | * åå»ºè¡¨æ ¼æ ·å¼ |
| | | */ |
| | | public void setDataValidation(Excel attr, Row row, int column) |
| | | { |
| | | if (attr.name().indexOf("注ï¼") >= 0) |
| | | { |
| | | sheet.setColumnWidth(column, 6000); |
| | | } |
| | | else |
| | | { |
| | | // 设置å宽 |
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); |
| | | } |
| | | if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0) |
| | | { |
| | | if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255) |
| | | { |
| | | // å¦æä¸ææ°å¤§äº15æå符串é¿åº¦å¤§äº255ï¼å使ç¨ä¸ä¸ªæ°sheetåå¨ï¼é¿å
çæç模æ¿ä¸æå¼è·åä¸å° |
| | | setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column); |
| | | } |
| | | else |
| | | { |
| | | // æ示信æ¯æåªè½éæ©ä¸è½è¾å
¥çåå
容. |
| | | setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å åå
æ ¼ |
| | | */ |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) |
| | | { |
| | | Cell cell = null; |
| | | try |
| | | { |
| | | // 设置è¡é« |
| | | row.setHeight(maxHeight); |
| | | // æ ¹æ®Excelä¸è®¾ç½®æ
åµå³å®æ¯å¦å¯¼åº,æäºæ
åµéè¦ä¿æ为空,å¸æç¨æ·å¡«åè¿ä¸å. |
| | | if (attr.isExport()) |
| | | { |
| | | // å建cell |
| | | cell = row.createCell(column); |
| | | if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge()) |
| | | { |
| | | CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column); |
| | | sheet.addMergedRegion(cellAddress); |
| | | } |
| | | cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); |
| | | |
| | | // ç¨äºè¯»å对象ä¸çå±æ§ |
| | | Object value = getTargetValue(vo, field, attr); |
| | | String dateFormat = attr.dateFormat(); |
| | | String readConverterExp = attr.readConverterExp(); |
| | | String separator = attr.separator(); |
| | | String dictType = attr.dictType(); |
| | | if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(parseDateToStr(dateFormat, value)); |
| | | } |
| | | else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); |
| | | } |
| | | else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) |
| | | { |
| | | if (!sysDictMap.containsKey(dictType + value)) |
| | | { |
| | | String lable = convertDictByExp(Convert.toStr(value), dictType, separator); |
| | | sysDictMap.put(dictType + value, lable); |
| | | } |
| | | cell.setCellValue(sysDictMap.get(dictType + value)); |
| | | } |
| | | else if (value instanceof BigDecimal && -1 != attr.scale()) |
| | | { |
| | | cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); |
| | | } |
| | | else if (!attr.handler().equals(ExcelHandlerAdapter.class)) |
| | | { |
| | | cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell)); |
| | | } |
| | | else |
| | | { |
| | | // 设置åç±»å |
| | | setCellVo(value, attr, cell); |
| | | } |
| | | addStatisticsData(column, Convert.toStr(value), attr); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导åºExcel失败{}", e); |
| | | } |
| | | return cell; |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet åå
æ ¼æ示æéæ©æ¡ |
| | | * |
| | | * @param sheet 表å |
| | | * @param textlist ä¸ææ¡æ¾ç¤ºçå
容 |
| | | * @param promptContent æ示å
容 |
| | | * @param firstRow å¼å§è¡ |
| | | * @param endRow ç»æè¡ |
| | | * @param firstCol å¼å§å |
| | | * @param endCol ç»æå |
| | | */ |
| | | public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) |
| | | { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); |
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | if (StringUtils.isNotEmpty(promptContent)) |
| | | { |
| | | // å¦æ设置äºæ示信æ¯åé¼ æ æ¾ä¸å»æ示 |
| | | dataValidation.createPromptBox("", promptContent); |
| | | dataValidation.setShowPromptBox(true); |
| | | } |
| | | // å¤çExcelå
¼å®¹æ§é®é¢ |
| | | if (dataValidation instanceof XSSFDataValidation) |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | else |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | } |
| | | sheet.addValidationData(dataValidation); |
| | | } |
| | | |
| | | /** |
| | | * 设置æäºåçå¼åªè½è¾å
¥é¢å¶çæ°æ®,æ¾ç¤ºä¸ææ¡ï¼å
¼å®¹è¶
åºä¸å®æ°éçä¸ææ¡ï¼. |
| | | * |
| | | * @param sheet è¦è®¾ç½®çsheet. |
| | | * @param textlist ä¸ææ¡æ¾ç¤ºçå
容 |
| | | * @param promptContent æ示å
容 |
| | | * @param firstRow å¼å§è¡ |
| | | * @param endRow ç»æè¡ |
| | | * @param firstCol å¼å§å |
| | | * @param endCol ç»æå |
| | | */ |
| | | public void setXSSFValidationWithHidden(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol) |
| | | { |
| | | String hideSheetName = "combo_" + firstCol + "_" + endCol; |
| | | Sheet hideSheet = wb.createSheet(hideSheetName); // ç¨äºåå¨ ä¸æèåæ°æ® |
| | | for (int i = 0; i < textlist.length; i++) |
| | | { |
| | | hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]); |
| | | } |
| | | // å建å称ï¼å¯è¢«å
¶ä»åå
æ ¼å¼ç¨ |
| | | Name name = wb.createName(); |
| | | name.setNameName(hideSheetName + "_data"); |
| | | name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length); |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // å è½½ä¸æå表å
容 |
| | | DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data"); |
| | | // 设置æ°æ®æææ§å è½½å¨åªä¸ªåå
æ ¼ä¸,å个åæ°åå«æ¯ï¼èµ·å§è¡ãç»æ¢è¡ãèµ·å§åãç»æ¢å |
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); |
| | | // æ°æ®æææ§å¯¹è±¡ |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | if (StringUtils.isNotEmpty(promptContent)) |
| | | { |
| | | // å¦æ设置äºæ示信æ¯åé¼ æ æ¾ä¸å»æ示 |
| | | dataValidation.createPromptBox("", promptContent); |
| | | dataValidation.setShowPromptBox(true); |
| | | } |
| | | // å¤çExcelå
¼å®¹æ§é®é¢ |
| | | if (dataValidation instanceof XSSFDataValidation) |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | else |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | | // 设置hiddenSheetéè |
| | | wb.setSheetHidden(wb.getSheetIndex(hideSheet), true); |
| | | } |
| | | |
| | | /** |
| | | * 解æ导åºå¼ 0=ç·,1=女,2=æªç¥ |
| | | * |
| | | * @param propertyValue åæ°å¼ |
| | | * @param converterExp ç¿»è¯æ³¨è§£ |
| | | * @param separator åé符 |
| | | * @return 解æåå¼ |
| | | */ |
| | | public static String convertByExp(String propertyValue, String converterExp, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | String[] convertSource = converterExp.split(","); |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (StringUtils.containsAny(propertyValue, separator)) |
| | | { |
| | | for (String value : propertyValue.split(separator)) |
| | | { |
| | | if (itemArray[0].equals(value)) |
| | | { |
| | | propertyString.append(itemArray[1] + separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (itemArray[0].equals(propertyValue)) |
| | | { |
| | | return itemArray[1]; |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.stripEnd(propertyString.toString(), separator); |
| | | } |
| | | |
| | | /** |
| | | * åå解æå¼ ç·=0,女=1,æªç¥=2 |
| | | * |
| | | * @param propertyValue åæ°å¼ |
| | | * @param converterExp ç¿»è¯æ³¨è§£ |
| | | * @param separator åé符 |
| | | * @return 解æåå¼ |
| | | */ |
| | | public static String reverseByExp(String propertyValue, String converterExp, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | String[] convertSource = converterExp.split(","); |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (StringUtils.containsAny(propertyValue, separator)) |
| | | { |
| | | for (String value : propertyValue.split(separator)) |
| | | { |
| | | if (itemArray[1].equals(value)) |
| | | { |
| | | propertyString.append(itemArray[0] + separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (itemArray[1].equals(propertyValue)) |
| | | { |
| | | return itemArray[0]; |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.stripEnd(propertyString.toString(), separator); |
| | | } |
| | | |
| | | /** |
| | | * 解æåå
¸å¼ |
| | | * |
| | | * @param dictValue åå
¸å¼ |
| | | * @param dictType åå
¸ç±»å |
| | | * @param separator åé符 |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public static String convertDictByExp(String dictValue, String dictType, String separator) |
| | | { |
| | | return DictUtils.getDictLabel(dictType, dictValue, separator); |
| | | } |
| | | |
| | | /** |
| | | * åå解æå¼åå
¸å¼ |
| | | * |
| | | * @param dictLabel åå
¸æ ç¾ |
| | | * @param dictType åå
¸ç±»å |
| | | * @param separator åé符 |
| | | * @return åå
¸å¼ |
| | | */ |
| | | public static String reverseDictByExp(String dictLabel, String dictType, String separator) |
| | | { |
| | | return DictUtils.getDictValue(dictType, dictLabel, separator); |
| | | } |
| | | |
| | | /** |
| | | * æ°æ®å¤çå¨ |
| | | * |
| | | * @param value æ°æ®å¼ |
| | | * @param excel æ°æ®æ³¨è§£ |
| | | * @return |
| | | */ |
| | | public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell) |
| | | { |
| | | try |
| | | { |
| | | Object instance = excel.handler().newInstance(); |
| | | Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class }); |
| | | value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("ä¸è½æ ¼å¼åæ°æ® " + excel.handler(), e.getMessage()); |
| | | } |
| | | return Convert.toStr(value); |
| | | } |
| | | |
| | | /** |
| | | * å计ç»è®¡ä¿¡æ¯ |
| | | */ |
| | | private void addStatisticsData(Integer index, String text, Excel entity) |
| | | { |
| | | if (entity != null && entity.isStatistics()) |
| | | { |
| | | Double temp = 0D; |
| | | if (!statistics.containsKey(index)) |
| | | { |
| | | statistics.put(index, temp); |
| | | } |
| | | try |
| | | { |
| | | temp = Double.valueOf(text); |
| | | } |
| | | catch (NumberFormatException e) |
| | | { |
| | | } |
| | | statistics.put(index, statistics.get(index) + temp); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å建ç»è®¡è¡ |
| | | */ |
| | | public void addStatisticsRow() |
| | | { |
| | | if (statistics.size() > 0) |
| | | { |
| | | Row row = sheet.createRow(sheet.getLastRowNum() + 1); |
| | | Set<Integer> keys = statistics.keySet(); |
| | | Cell cell = row.createCell(0); |
| | | cell.setCellStyle(styles.get("total")); |
| | | cell.setCellValue("å计"); |
| | | |
| | | for (Integer key : keys) |
| | | { |
| | | cell = row.createCell(key); |
| | | cell.setCellStyle(styles.get("total")); |
| | | cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key))); |
| | | } |
| | | statistics.clear(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç¼ç æ件å |
| | | */ |
| | | public String encodingFilename(String filename) |
| | | { |
| | | filename = UUID.randomUUID() + "_" + filename + ".xlsx"; |
| | | return filename; |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸è½½è·¯å¾ |
| | | * |
| | | * @param filename æ件å称 |
| | | */ |
| | | public String getAbsoluteFile(String filename) |
| | | { |
| | | String downloadPath = MesConfig.getDownloadPath() + filename; |
| | | File desc = new File(downloadPath); |
| | | if (!desc.getParentFile().exists()) |
| | | { |
| | | desc.getParentFile().mkdirs(); |
| | | } |
| | | return downloadPath; |
| | | } |
| | | |
| | | /** |
| | | * è·åbeanä¸çå±æ§å¼ |
| | | * |
| | | * @param vo å®ä½å¯¹è±¡ |
| | | * @param field å段 |
| | | * @param excel 注解 |
| | | * @return æç»çå±æ§å¼ |
| | | * @throws Exception |
| | | */ |
| | | private Object getTargetValue(T vo, Field field, Excel excel) throws Exception |
| | | { |
| | | Object o = field.get(vo); |
| | | if (StringUtils.isNotEmpty(excel.targetAttr())) |
| | | { |
| | | String target = excel.targetAttr(); |
| | | if (target.contains(".")) |
| | | { |
| | | String[] targets = target.split("[.]"); |
| | | for (String name : targets) |
| | | { |
| | | o = getValue(o, name); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | o = getValue(o, target); |
| | | } |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | /** |
| | | * 以类çå±æ§çgetæ¹æ³æ¹æ³å½¢å¼è·åå¼ |
| | | * |
| | | * @param o |
| | | * @param name |
| | | * @return value |
| | | * @throws Exception |
| | | */ |
| | | private Object getValue(Object o, String name) throws Exception |
| | | { |
| | | if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name)) |
| | | { |
| | | Class<?> clazz = o.getClass(); |
| | | Field field = clazz.getDeclaredField(name); |
| | | field.setAccessible(true); |
| | | o = field.get(o); |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ææå®ä¹å段 |
| | | */ |
| | | private void createExcelField() |
| | | { |
| | | this.fields = getFields(); |
| | | this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); |
| | | this.maxHeight = getRowHeight(); |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ®µæ³¨è§£ä¿¡æ¯ |
| | | */ |
| | | public List<Object[]> getFields() |
| | | { |
| | | List<Object[]> fields = new ArrayList<Object[]>(); |
| | | List<Field> tempFields = new ArrayList<>(); |
| | | tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); |
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); |
| | | for (Field field : tempFields) |
| | | { |
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName())) |
| | | { |
| | | // å注解 |
| | | if (field.isAnnotationPresent(Excel.class)) |
| | | { |
| | | Excel attr = field.getAnnotation(Excel.class); |
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) |
| | | { |
| | | field.setAccessible(true); |
| | | fields.add(new Object[] { field, attr }); |
| | | } |
| | | if (Collection.class.isAssignableFrom(field.getType())) |
| | | { |
| | | subMethod = getSubMethod(field.getName(), clazz); |
| | | ParameterizedType pt = (ParameterizedType) field.getGenericType(); |
| | | Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0]; |
| | | this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class); |
| | | } |
| | | } |
| | | |
| | | // å¤æ³¨è§£ |
| | | if (field.isAnnotationPresent(Excels.class)) |
| | | { |
| | | Excels attrs = field.getAnnotation(Excels.class); |
| | | Excel[] excels = attrs.value(); |
| | | for (Excel attr : excels) |
| | | { |
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr()) |
| | | && (attr != null && (attr.type() == Type.ALL || attr.type() == type))) |
| | | { |
| | | field.setAccessible(true); |
| | | fields.add(new Object[] { field, attr }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return fields; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ³¨è§£è·åæ大è¡é« |
| | | */ |
| | | public short getRowHeight() |
| | | { |
| | | double maxHeight = 0; |
| | | for (Object[] os : this.fields) |
| | | { |
| | | Excel excel = (Excel) os[1]; |
| | | maxHeight = Math.max(maxHeight, excel.height()); |
| | | } |
| | | return (short) (maxHeight * 20); |
| | | } |
| | | |
| | | /** |
| | | * å建ä¸ä¸ªå·¥ä½ç°¿ |
| | | */ |
| | | public void createWorkbook() |
| | | { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.sheet = wb.createSheet(); |
| | | wb.setSheetName(0, sheetName); |
| | | this.styles = createStyles(wb); |
| | | } |
| | | |
| | | /** |
| | | * å建工ä½è¡¨ |
| | | * |
| | | * @param sheetNo sheetæ°é |
| | | * @param index åºå· |
| | | */ |
| | | public void createSheet(int sheetNo, int index) |
| | | { |
| | | // 设置工ä½è¡¨çå称. |
| | | if (sheetNo > 1 && index > 0) |
| | | { |
| | | this.sheet = wb.createSheet(); |
| | | this.createTitle(); |
| | | wb.setSheetName(index, sheetName + index); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
æ ¼å¼ |
| | | * |
| | | * @param row è·åçè¡ |
| | | * @param column è·ååå
æ ¼åå· |
| | | * @return åå
æ ¼å¼ |
| | | */ |
| | | public Object getCellValue(Row row, int column) |
| | | { |
| | | if (row == null) |
| | | { |
| | | return row; |
| | | } |
| | | Object val = ""; |
| | | try |
| | | { |
| | | Cell cell = row.getCell(column); |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA) |
| | | { |
| | | val = cell.getNumericCellValue(); |
| | | if (DateUtil.isCellDateFormatted(cell)) |
| | | { |
| | | val = DateUtil.getJavaDate((Double) val); // POI Excel æ¥ææ ¼å¼è½¬æ¢ |
| | | } |
| | | else |
| | | { |
| | | if ((Double) val % 1 != 0) |
| | | { |
| | | val = new BigDecimal(val.toString()); |
| | | } |
| | | else |
| | | { |
| | | val = new DecimalFormat("0").format(val); |
| | | } |
| | | } |
| | | } |
| | | else if (cell.getCellType() == CellType.STRING) |
| | | { |
| | | val = cell.getStringCellValue(); |
| | | } |
| | | else if (cell.getCellType() == CellType.BOOLEAN) |
| | | { |
| | | val = cell.getBooleanCellValue(); |
| | | } |
| | | else if (cell.getCellType() == CellType.ERROR) |
| | | { |
| | | val = cell.getErrorCellValue(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return val; |
| | | } |
| | | return val; |
| | | } |
| | | |
| | | /** |
| | | * å¤ææ¯å¦æ¯ç©ºè¡ |
| | | * |
| | | * @param row å¤æçè¡ |
| | | * @return |
| | | */ |
| | | private boolean isRowEmpty(Row row) |
| | | { |
| | | if (row == null) |
| | | { |
| | | return true; |
| | | } |
| | | for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) |
| | | { |
| | | Cell cell = row.getCell(i); |
| | | if (cell != null && cell.getCellType() != CellType.BLANK) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * è·åExcel2003å¾ç |
| | | * |
| | | * @param sheet å½åsheet对象 |
| | | * @param workbook å·¥ä½ç°¿å¯¹è±¡ |
| | | * @return Map key:å¾çåå
æ ¼ç´¢å¼ï¼1_1ï¼Stringï¼value:å¾çæµPictureData |
| | | */ |
| | | public static Map<String, PictureData> getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) |
| | | { |
| | | Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); |
| | | List<HSSFPictureData> pictures = workbook.getAllPictures(); |
| | | if (!pictures.isEmpty()) |
| | | { |
| | | for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) |
| | | { |
| | | HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor(); |
| | | if (shape instanceof HSSFPicture) |
| | | { |
| | | HSSFPicture pic = (HSSFPicture) shape; |
| | | int pictureIndex = pic.getPictureIndex() - 1; |
| | | HSSFPictureData picData = pictures.get(pictureIndex); |
| | | String picIndex = anchor.getRow1() + "_" + anchor.getCol1(); |
| | | sheetIndexPicMap.put(picIndex, picData); |
| | | } |
| | | } |
| | | return sheetIndexPicMap; |
| | | } |
| | | else |
| | | { |
| | | return sheetIndexPicMap; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åExcel2007å¾ç |
| | | * |
| | | * @param sheet å½åsheet对象 |
| | | * @param workbook å·¥ä½ç°¿å¯¹è±¡ |
| | | * @return Map key:å¾çåå
æ ¼ç´¢å¼ï¼1_1ï¼Stringï¼value:å¾çæµPictureData |
| | | */ |
| | | public static Map<String, PictureData> getSheetPictures07(XSSFSheet sheet, XSSFWorkbook workbook) |
| | | { |
| | | Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); |
| | | for (POIXMLDocumentPart dr : sheet.getRelations()) |
| | | { |
| | | if (dr instanceof XSSFDrawing) |
| | | { |
| | | XSSFDrawing drawing = (XSSFDrawing) dr; |
| | | List<XSSFShape> shapes = drawing.getShapes(); |
| | | for (XSSFShape shape : shapes) |
| | | { |
| | | if (shape instanceof XSSFPicture) |
| | | { |
| | | XSSFPicture pic = (XSSFPicture) shape; |
| | | XSSFClientAnchor anchor = pic.getPreferredSize(); |
| | | CTMarker ctMarker = anchor.getFrom(); |
| | | String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); |
| | | sheetIndexPicMap.put(picIndex, pic.getPictureData()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return sheetIndexPicMap; |
| | | } |
| | | |
| | | /** |
| | | * æ ¼å¼åä¸åç±»åçæ¥æ对象 |
| | | * |
| | | * @param dateFormat æ¥ææ ¼å¼ |
| | | * @param val è¢«æ ¼å¼åçæ¥æ对象 |
| | | * @return æ ¼å¼ååçæ¥æå符 |
| | | */ |
| | | public String parseDateToStr(String dateFormat, Object val) |
| | | { |
| | | if (val == null) |
| | | { |
| | | return ""; |
| | | } |
| | | String str; |
| | | if (val instanceof Date) |
| | | { |
| | | str = DateUtils.parseDateToStr(dateFormat, (Date) val); |
| | | } |
| | | else if (val instanceof LocalDateTime) |
| | | { |
| | | str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val)); |
| | | } |
| | | else if (val instanceof LocalDate) |
| | | { |
| | | str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val)); |
| | | } |
| | | else |
| | | { |
| | | str = val.toString(); |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ对象çåå表 |
| | | */ |
| | | public boolean isSubList() |
| | | { |
| | | return StringUtils.isNotNull(subFields) && subFields.size() > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ对象çåå表ï¼éåä¸ä¸ºç©º |
| | | */ |
| | | public boolean isSubListValue(T vo) |
| | | { |
| | | return StringUtils.isNotNull(subFields) && subFields.size() > 0 && StringUtils.isNotNull(getListCellValue(vo)) && getListCellValue(vo).size() > 0; |
| | | } |
| | | |
| | | /** |
| | | * è·åéåçå¼ |
| | | */ |
| | | public Collection<?> getListCellValue(Object obj) |
| | | { |
| | | Object value; |
| | | try |
| | | { |
| | | value = subMethod.invoke(obj, new Object[] {}); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return new ArrayList<Object>(); |
| | | } |
| | | return (Collection<?>) value; |
| | | } |
| | | |
| | | /** |
| | | * è·å对象çåå表æ¹æ³ |
| | | * |
| | | * @param name å称 |
| | | * @param pojoClass 类对象 |
| | | * @return åå表æ¹æ³ |
| | | */ |
| | | public Method getSubMethod(String name, Class<?> pojoClass) |
| | | { |
| | | StringBuffer getMethodName = new StringBuffer("get"); |
| | | getMethodName.append(name.substring(0, 1).toUpperCase()); |
| | | getMethodName.append(name.substring(1)); |
| | | Method method = null; |
| | | try |
| | | { |
| | | method = pojoClass.getMethod(getMethodName.toString(), new Class[] {}); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·å对象å¼å¸¸{}", e.getMessage()); |
| | | } |
| | | return method; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.reflect; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Modifier; |
| | | import java.lang.reflect.ParameterizedType; |
| | | import java.lang.reflect.Type; |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.lang3.Validate; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.jcdm.common.core.text.Convert; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | |
| | | /** |
| | | * åå°å·¥å
·ç±». æä¾è°ç¨getter/setteræ¹æ³, 访é®ç§æåé, è°ç¨ç§ææ¹æ³, è·åæ³åç±»åClass, 被AOPè¿ççå®ç±»çå·¥å
·å½æ°. |
| | | * |
| | | * @author jc |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public class ReflectUtils |
| | | { |
| | | private static final String SETTER_PREFIX = "set"; |
| | | |
| | | private static final String GETTER_PREFIX = "get"; |
| | | |
| | | private static final String CGLIB_CLASS_SEPARATOR = "$$"; |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); |
| | | |
| | | /** |
| | | * è°ç¨Getteræ¹æ³. |
| | | * æ¯æå¤çº§ï¼å¦ï¼å¯¹è±¡å.对象å.æ¹æ³ |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeGetter(Object obj, String propertyName) |
| | | { |
| | | Object object = obj; |
| | | for (String name : StringUtils.split(propertyName, ".")) |
| | | { |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); |
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); |
| | | } |
| | | return (E) object; |
| | | } |
| | | |
| | | /** |
| | | * è°ç¨Setteræ¹æ³, ä»
å¹é
æ¹æ³åã |
| | | * æ¯æå¤çº§ï¼å¦ï¼å¯¹è±¡å.对象å.æ¹æ³ |
| | | */ |
| | | public static <E> void invokeSetter(Object obj, String propertyName, E value) |
| | | { |
| | | Object object = obj; |
| | | String[] names = StringUtils.split(propertyName, "."); |
| | | for (int i = 0; i < names.length; i++) |
| | | { |
| | | if (i < names.length - 1) |
| | | { |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); |
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); |
| | | } |
| | | else |
| | | { |
| | | String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); |
| | | invokeMethodByName(object, setterMethodName, new Object[] { value }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç´æ¥è¯»å对象å±æ§å¼, æ è§private/protected修饰符, ä¸ç»è¿getterå½æ°. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E getFieldValue(final Object obj, final String fieldName) |
| | | { |
| | | Field field = getAccessibleField(obj, fieldName); |
| | | if (field == null) |
| | | { |
| | | logger.debug("å¨ [" + obj.getClass() + "] ä¸ï¼æ²¡ææ¾å° [" + fieldName + "] å段 "); |
| | | return null; |
| | | } |
| | | E result = null; |
| | | try |
| | | { |
| | | result = (E) field.get(obj); |
| | | } |
| | | catch (IllegalAccessException e) |
| | | { |
| | | logger.error("ä¸å¯è½æåºçå¼å¸¸{}", e.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * ç´æ¥è®¾ç½®å¯¹è±¡å±æ§å¼, æ è§private/protected修饰符, ä¸ç»è¿setterå½æ°. |
| | | */ |
| | | public static <E> void setFieldValue(final Object obj, final String fieldName, final E value) |
| | | { |
| | | Field field = getAccessibleField(obj, fieldName); |
| | | if (field == null) |
| | | { |
| | | // throw new IllegalArgumentException("å¨ [" + obj.getClass() + "] ä¸ï¼æ²¡ææ¾å° [" + fieldName + "] å段 "); |
| | | logger.debug("å¨ [" + obj.getClass() + "] ä¸ï¼æ²¡ææ¾å° [" + fieldName + "] å段 "); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | field.set(obj, value); |
| | | } |
| | | catch (IllegalAccessException e) |
| | | { |
| | | logger.error("ä¸å¯è½æåºçå¼å¸¸: {}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç´æ¥è°ç¨å¯¹è±¡æ¹æ³, æ è§private/protected修饰符. |
| | | * ç¨äºä¸æ¬¡æ§è°ç¨çæ
åµï¼å¦ååºä½¿ç¨getAccessibleMethod()å½æ°è·å¾Methodååå¤è°ç¨. |
| | | * åæ¶å¹é
æ¹æ³å+åæ°ç±»åï¼ |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes, |
| | | final Object[] args) |
| | | { |
| | | if (obj == null || methodName == null) |
| | | { |
| | | return null; |
| | | } |
| | | Method method = getAccessibleMethod(obj, methodName, parameterTypes); |
| | | if (method == null) |
| | | { |
| | | logger.debug("å¨ [" + obj.getClass() + "] ä¸ï¼æ²¡ææ¾å° [" + methodName + "] æ¹æ³ "); |
| | | return null; |
| | | } |
| | | try |
| | | { |
| | | return (E) method.invoke(obj, args); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; |
| | | throw convertReflectionExceptionToUnchecked(msg, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç´æ¥è°ç¨å¯¹è±¡æ¹æ³, æ è§private/protectedä¿®é¥°ç¬¦ï¼ |
| | | * ç¨äºä¸æ¬¡æ§è°ç¨çæ
åµï¼å¦ååºä½¿ç¨getAccessibleMethodByName()å½æ°è·å¾Methodååå¤è°ç¨. |
| | | * åªå¹é
å½æ°åï¼å¦ææå¤ä¸ªååå½æ°è°ç¨ç¬¬ä¸ä¸ªã |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) |
| | | { |
| | | Method method = getAccessibleMethodByName(obj, methodName, args.length); |
| | | if (method == null) |
| | | { |
| | | // å¦æ为空ä¸æ¥éï¼ç´æ¥è¿å空ã |
| | | logger.debug("å¨ [" + obj.getClass() + "] ä¸ï¼æ²¡ææ¾å° [" + methodName + "] æ¹æ³ "); |
| | | return null; |
| | | } |
| | | try |
| | | { |
| | | // ç±»å转æ¢ï¼å°åæ°æ°æ®ç±»å转æ¢ä¸ºç®æ æ¹æ³åæ°ç±»åï¼ |
| | | Class<?>[] cs = method.getParameterTypes(); |
| | | for (int i = 0; i < cs.length; i++) |
| | | { |
| | | if (args[i] != null && !args[i].getClass().equals(cs[i])) |
| | | { |
| | | if (cs[i] == String.class) |
| | | { |
| | | args[i] = Convert.toStr(args[i]); |
| | | if (StringUtils.endsWith((String) args[i], ".0")) |
| | | { |
| | | args[i] = StringUtils.substringBefore((String) args[i], ".0"); |
| | | } |
| | | } |
| | | else if (cs[i] == Integer.class) |
| | | { |
| | | args[i] = Convert.toInt(args[i]); |
| | | } |
| | | else if (cs[i] == Long.class) |
| | | { |
| | | args[i] = Convert.toLong(args[i]); |
| | | } |
| | | else if (cs[i] == Double.class) |
| | | { |
| | | args[i] = Convert.toDouble(args[i]); |
| | | } |
| | | else if (cs[i] == Float.class) |
| | | { |
| | | args[i] = Convert.toFloat(args[i]); |
| | | } |
| | | else if (cs[i] == Date.class) |
| | | { |
| | | if (args[i] instanceof String) |
| | | { |
| | | args[i] = DateUtils.parseDate(args[i]); |
| | | } |
| | | else |
| | | { |
| | | args[i] = DateUtil.getJavaDate((Double) args[i]); |
| | | } |
| | | } |
| | | else if (cs[i] == boolean.class || cs[i] == Boolean.class) |
| | | { |
| | | args[i] = Convert.toBool(args[i]); |
| | | } |
| | | } |
| | | } |
| | | return (E) method.invoke(obj, args); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; |
| | | throw convertReflectionExceptionToUnchecked(msg, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 循ç¯åä¸è½¬å, è·å对象çDeclaredField, 并强å¶è®¾ç½®ä¸ºå¯è®¿é®. |
| | | * å¦åä¸è½¬åå°Objectä»æ æ³æ¾å°, è¿ånull. |
| | | */ |
| | | public static Field getAccessibleField(final Object obj, final String fieldName) |
| | | { |
| | | // 为空ä¸æ¥éãç´æ¥è¿å null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(fieldName, "fieldName can't be blank"); |
| | | for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) |
| | | { |
| | | try |
| | | { |
| | | Field field = superClass.getDeclaredField(fieldName); |
| | | makeAccessible(field); |
| | | return field; |
| | | } |
| | | catch (NoSuchFieldException e) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 循ç¯åä¸è½¬å, è·å对象çDeclaredMethod,并强å¶è®¾ç½®ä¸ºå¯è®¿é®. |
| | | * å¦åä¸è½¬åå°Objectä»æ æ³æ¾å°, è¿ånull. |
| | | * å¹é
å½æ°å+åæ°ç±»åã |
| | | * ç¨äºæ¹æ³éè¦è¢«å¤æ¬¡è°ç¨çæ
åµ. å
使ç¨æ¬å½æ°å
åå¾Method,ç¶åè°ç¨Method.invoke(Object obj, Object... args) |
| | | */ |
| | | public static Method getAccessibleMethod(final Object obj, final String methodName, |
| | | final Class<?>... parameterTypes) |
| | | { |
| | | // 为空ä¸æ¥éãç´æ¥è¿å null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(methodName, "methodName can't be blank"); |
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) |
| | | { |
| | | try |
| | | { |
| | | Method method = searchType.getDeclaredMethod(methodName, parameterTypes); |
| | | makeAccessible(method); |
| | | return method; |
| | | } |
| | | catch (NoSuchMethodException e) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 循ç¯åä¸è½¬å, è·å对象çDeclaredMethod,并强å¶è®¾ç½®ä¸ºå¯è®¿é®. |
| | | * å¦åä¸è½¬åå°Objectä»æ æ³æ¾å°, è¿ånull. |
| | | * åªå¹é
å½æ°åã |
| | | * ç¨äºæ¹æ³éè¦è¢«å¤æ¬¡è°ç¨çæ
åµ. å
使ç¨æ¬å½æ°å
åå¾Method,ç¶åè°ç¨Method.invoke(Object obj, Object... args) |
| | | */ |
| | | public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum) |
| | | { |
| | | // 为空ä¸æ¥éãç´æ¥è¿å null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(methodName, "methodName can't be blank"); |
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) |
| | | { |
| | | Method[] methods = searchType.getDeclaredMethods(); |
| | | for (Method method : methods) |
| | | { |
| | | if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum) |
| | | { |
| | | makeAccessible(method); |
| | | return method; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ¹åprivate/protectedçæ¹æ³ä¸ºpublicï¼å°½éä¸è°ç¨å®é
æ¹å¨çè¯å¥ï¼é¿å
JDKçSecurityManageræ±æ¨ã |
| | | */ |
| | | public static void makeAccessible(Method method) |
| | | { |
| | | if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) |
| | | && !method.isAccessible()) |
| | | { |
| | | method.setAccessible(true); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¹åprivate/protectedçæååé为publicï¼å°½éä¸è°ç¨å®é
æ¹å¨çè¯å¥ï¼é¿å
JDKçSecurityManageræ±æ¨ã |
| | | */ |
| | | public static void makeAccessible(Field field) |
| | | { |
| | | if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) |
| | | || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) |
| | | { |
| | | field.setAccessible(true); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éè¿åå°, è·å¾Classå®ä¹ä¸å£°æçæ³ååæ°çç±»å, 注ææ³åå¿
é¡»å®ä¹å¨ç¶ç±»å¤ |
| | | * å¦æ æ³æ¾å°, è¿åObject.class. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> Class<T> getClassGenricType(final Class clazz) |
| | | { |
| | | return getClassGenricType(clazz, 0); |
| | | } |
| | | |
| | | /** |
| | | * éè¿åå°, è·å¾Classå®ä¹ä¸å£°æçç¶ç±»çæ³ååæ°çç±»å. |
| | | * å¦æ æ³æ¾å°, è¿åObject.class. |
| | | */ |
| | | public static Class getClassGenricType(final Class clazz, final int index) |
| | | { |
| | | Type genType = clazz.getGenericSuperclass(); |
| | | |
| | | if (!(genType instanceof ParameterizedType)) |
| | | { |
| | | logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); |
| | | return Object.class; |
| | | } |
| | | |
| | | Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); |
| | | |
| | | if (index >= params.length || index < 0) |
| | | { |
| | | logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " |
| | | + params.length); |
| | | return Object.class; |
| | | } |
| | | if (!(params[index] instanceof Class)) |
| | | { |
| | | logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); |
| | | return Object.class; |
| | | } |
| | | |
| | | return (Class) params[index]; |
| | | } |
| | | |
| | | public static Class<?> getUserClass(Object instance) |
| | | { |
| | | if (instance == null) |
| | | { |
| | | throw new RuntimeException("Instance must not be null"); |
| | | } |
| | | Class clazz = instance.getClass(); |
| | | if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) |
| | | { |
| | | Class<?> superClass = clazz.getSuperclass(); |
| | | if (superClass != null && !Object.class.equals(superClass)) |
| | | { |
| | | return superClass; |
| | | } |
| | | } |
| | | return clazz; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * å°åå°æ¶çchecked exception转æ¢ä¸ºunchecked exception. |
| | | */ |
| | | public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e) |
| | | { |
| | | if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException |
| | | || e instanceof NoSuchMethodException) |
| | | { |
| | | return new IllegalArgumentException(msg, e); |
| | | } |
| | | else if (e instanceof InvocationTargetException) |
| | | { |
| | | return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException()); |
| | | } |
| | | return new RuntimeException(msg, e); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.sign; |
| | | |
| | | /** |
| | | * Base64å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public final class Base64 |
| | | { |
| | | static private final int BASELENGTH = 128; |
| | | static private final int LOOKUPLENGTH = 64; |
| | | static private final int TWENTYFOURBITGROUP = 24; |
| | | static private final int EIGHTBIT = 8; |
| | | static private final int SIXTEENBIT = 16; |
| | | static private final int FOURBYTE = 4; |
| | | static private final int SIGN = -128; |
| | | static private final char PAD = '='; |
| | | static final private byte[] base64Alphabet = new byte[BASELENGTH]; |
| | | static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; |
| | | |
| | | static |
| | | { |
| | | for (int i = 0; i < BASELENGTH; ++i) |
| | | { |
| | | base64Alphabet[i] = -1; |
| | | } |
| | | for (int i = 'Z'; i >= 'A'; i--) |
| | | { |
| | | base64Alphabet[i] = (byte) (i - 'A'); |
| | | } |
| | | for (int i = 'z'; i >= 'a'; i--) |
| | | { |
| | | base64Alphabet[i] = (byte) (i - 'a' + 26); |
| | | } |
| | | |
| | | for (int i = '9'; i >= '0'; i--) |
| | | { |
| | | base64Alphabet[i] = (byte) (i - '0' + 52); |
| | | } |
| | | |
| | | base64Alphabet['+'] = 62; |
| | | base64Alphabet['/'] = 63; |
| | | |
| | | for (int i = 0; i <= 25; i++) |
| | | { |
| | | lookUpBase64Alphabet[i] = (char) ('A' + i); |
| | | } |
| | | |
| | | for (int i = 26, j = 0; i <= 51; i++, j++) |
| | | { |
| | | lookUpBase64Alphabet[i] = (char) ('a' + j); |
| | | } |
| | | |
| | | for (int i = 52, j = 0; i <= 61; i++, j++) |
| | | { |
| | | lookUpBase64Alphabet[i] = (char) ('0' + j); |
| | | } |
| | | lookUpBase64Alphabet[62] = (char) '+'; |
| | | lookUpBase64Alphabet[63] = (char) '/'; |
| | | } |
| | | |
| | | private static boolean isWhiteSpace(char octect) |
| | | { |
| | | return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); |
| | | } |
| | | |
| | | private static boolean isPad(char octect) |
| | | { |
| | | return (octect == PAD); |
| | | } |
| | | |
| | | private static boolean isData(char octect) |
| | | { |
| | | return (octect < BASELENGTH && base64Alphabet[octect] != -1); |
| | | } |
| | | |
| | | /** |
| | | * Encodes hex octects into Base64 |
| | | * |
| | | * @param binaryData Array containing binaryData |
| | | * @return Encoded Base64 array |
| | | */ |
| | | public static String encode(byte[] binaryData) |
| | | { |
| | | if (binaryData == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | int lengthDataBits = binaryData.length * EIGHTBIT; |
| | | if (lengthDataBits == 0) |
| | | { |
| | | return ""; |
| | | } |
| | | |
| | | int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; |
| | | int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; |
| | | int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets; |
| | | char encodedData[] = null; |
| | | |
| | | encodedData = new char[numberQuartet * 4]; |
| | | |
| | | byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; |
| | | |
| | | int encodedIndex = 0; |
| | | int dataIndex = 0; |
| | | |
| | | for (int i = 0; i < numberTriplets; i++) |
| | | { |
| | | b1 = binaryData[dataIndex++]; |
| | | b2 = binaryData[dataIndex++]; |
| | | b3 = binaryData[dataIndex++]; |
| | | |
| | | l = (byte) (b2 & 0x0f); |
| | | k = (byte) (b1 & 0x03); |
| | | |
| | | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); |
| | | byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); |
| | | byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); |
| | | |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; |
| | | } |
| | | |
| | | // form integral number of 6-bit groups |
| | | if (fewerThan24bits == EIGHTBIT) |
| | | { |
| | | b1 = binaryData[dataIndex]; |
| | | k = (byte) (b1 & 0x03); |
| | | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; |
| | | encodedData[encodedIndex++] = PAD; |
| | | encodedData[encodedIndex++] = PAD; |
| | | } |
| | | else if (fewerThan24bits == SIXTEENBIT) |
| | | { |
| | | b1 = binaryData[dataIndex]; |
| | | b2 = binaryData[dataIndex + 1]; |
| | | l = (byte) (b2 & 0x0f); |
| | | k = (byte) (b1 & 0x03); |
| | | |
| | | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); |
| | | byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); |
| | | |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; |
| | | encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; |
| | | encodedData[encodedIndex++] = PAD; |
| | | } |
| | | return new String(encodedData); |
| | | } |
| | | |
| | | /** |
| | | * Decodes Base64 data into octects |
| | | * |
| | | * @param encoded string containing Base64 data |
| | | * @return Array containind decoded data. |
| | | */ |
| | | public static byte[] decode(String encoded) |
| | | { |
| | | if (encoded == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | char[] base64Data = encoded.toCharArray(); |
| | | // remove white spaces |
| | | int len = removeWhiteSpace(base64Data); |
| | | |
| | | if (len % FOURBYTE != 0) |
| | | { |
| | | return null;// should be divisible by four |
| | | } |
| | | |
| | | int numberQuadruple = (len / FOURBYTE); |
| | | |
| | | if (numberQuadruple == 0) |
| | | { |
| | | return new byte[0]; |
| | | } |
| | | |
| | | byte decodedData[] = null; |
| | | byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
| | | char d1 = 0, d2 = 0, d3 = 0, d4 = 0; |
| | | |
| | | int i = 0; |
| | | int encodedIndex = 0; |
| | | int dataIndex = 0; |
| | | decodedData = new byte[(numberQuadruple) * 3]; |
| | | |
| | | for (; i < numberQuadruple - 1; i++) |
| | | { |
| | | |
| | | if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) |
| | | || !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) |
| | | { |
| | | return null; |
| | | } // if found "no data" just return null |
| | | |
| | | b1 = base64Alphabet[d1]; |
| | | b2 = base64Alphabet[d2]; |
| | | b3 = base64Alphabet[d3]; |
| | | b4 = base64Alphabet[d4]; |
| | | |
| | | decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); |
| | | decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); |
| | | decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); |
| | | } |
| | | |
| | | if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) |
| | | { |
| | | return null;// if found "no data" just return null |
| | | } |
| | | |
| | | b1 = base64Alphabet[d1]; |
| | | b2 = base64Alphabet[d2]; |
| | | |
| | | d3 = base64Data[dataIndex++]; |
| | | d4 = base64Data[dataIndex++]; |
| | | if (!isData((d3)) || !isData((d4))) |
| | | {// Check if they are PAD characters |
| | | if (isPad(d3) && isPad(d4)) |
| | | { |
| | | if ((b2 & 0xf) != 0)// last 4 bits should be zero |
| | | { |
| | | return null; |
| | | } |
| | | byte[] tmp = new byte[i * 3 + 1]; |
| | | System.arraycopy(decodedData, 0, tmp, 0, i * 3); |
| | | tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); |
| | | return tmp; |
| | | } |
| | | else if (!isPad(d3) && isPad(d4)) |
| | | { |
| | | b3 = base64Alphabet[d3]; |
| | | if ((b3 & 0x3) != 0)// last 2 bits should be zero |
| | | { |
| | | return null; |
| | | } |
| | | byte[] tmp = new byte[i * 3 + 2]; |
| | | System.arraycopy(decodedData, 0, tmp, 0, i * 3); |
| | | tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); |
| | | tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); |
| | | return tmp; |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | else |
| | | { // No PAD e.g 3cQl |
| | | b3 = base64Alphabet[d3]; |
| | | b4 = base64Alphabet[d4]; |
| | | decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); |
| | | decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); |
| | | decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); |
| | | |
| | | } |
| | | return decodedData; |
| | | } |
| | | |
| | | /** |
| | | * remove WhiteSpace from MIME containing encoded Base64 data. |
| | | * |
| | | * @param data the byte array of base64 data (with WS) |
| | | * @return the new length |
| | | */ |
| | | private static int removeWhiteSpace(char[] data) |
| | | { |
| | | if (data == null) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | // count characters that's not whitespace |
| | | int newSize = 0; |
| | | int len = data.length; |
| | | for (int i = 0; i < len; i++) |
| | | { |
| | | if (!isWhiteSpace(data[i])) |
| | | { |
| | | data[newSize++] = data[i]; |
| | | } |
| | | } |
| | | return newSize; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.sign; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.MessageDigest; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * Md5å å¯æ¹æ³ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class Md5Utils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(Md5Utils.class); |
| | | |
| | | private static byte[] md5(String s) |
| | | { |
| | | MessageDigest algorithm; |
| | | try |
| | | { |
| | | algorithm = MessageDigest.getInstance("MD5"); |
| | | algorithm.reset(); |
| | | algorithm.update(s.getBytes("UTF-8")); |
| | | byte[] messageDigest = algorithm.digest(); |
| | | return messageDigest; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("MD5 Error...", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static final String toHex(byte hash[]) |
| | | { |
| | | if (hash == null) |
| | | { |
| | | return null; |
| | | } |
| | | StringBuffer buf = new StringBuffer(hash.length * 2); |
| | | int i; |
| | | |
| | | for (i = 0; i < hash.length; i++) |
| | | { |
| | | if ((hash[i] & 0xff) < 0x10) |
| | | { |
| | | buf.append("0"); |
| | | } |
| | | buf.append(Long.toString(hash[i] & 0xff, 16)); |
| | | } |
| | | return buf.toString(); |
| | | } |
| | | |
| | | public static String hash(String s) |
| | | { |
| | | try |
| | | { |
| | | return new String(toHex(md5(s)).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("not supported charset...{}", e); |
| | | return s; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.spring; |
| | | |
| | | import org.springframework.aop.framework.AopContext; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
| | | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
| | | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.stereotype.Component; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * springå·¥å
·ç±» æ¹ä¾¿å¨éspring管çç¯å¢ä¸è·åbean |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware |
| | | { |
| | | /** Springåºç¨ä¸ä¸æç¯å¢ */ |
| | | private static ConfigurableListableBeanFactory beanFactory; |
| | | |
| | | private static ApplicationContext applicationContext; |
| | | |
| | | @Override |
| | | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException |
| | | { |
| | | SpringUtils.beanFactory = beanFactory; |
| | | } |
| | | |
| | | @Override |
| | | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException |
| | | { |
| | | SpringUtils.applicationContext = applicationContext; |
| | | } |
| | | |
| | | /** |
| | | * è·å对象 |
| | | * |
| | | * @param name |
| | | * @return Object ä¸ä¸ªä»¥æç»åå注åçbeançå®ä¾ |
| | | * @throws org.springframework.beans.BeansException |
| | | * |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T getBean(String name) throws BeansException |
| | | { |
| | | return (T) beanFactory.getBean(name); |
| | | } |
| | | |
| | | /** |
| | | * è·åç±»å为requiredTypeç对象 |
| | | * |
| | | * @param clz |
| | | * @return |
| | | * @throws org.springframework.beans.BeansException |
| | | * |
| | | */ |
| | | public static <T> T getBean(Class<T> clz) throws BeansException |
| | | { |
| | | T result = (T) beanFactory.getBean(clz); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * å¦æBeanFactoryå
å«ä¸ä¸ªä¸æç»å称å¹é
çbeanå®ä¹ï¼åè¿åtrue |
| | | * |
| | | * @param name |
| | | * @return boolean |
| | | */ |
| | | public static boolean containsBean(String name) |
| | | { |
| | | return beanFactory.containsBean(name); |
| | | } |
| | | |
| | | /** |
| | | * å¤æ以ç»å®åå注åçbeanå®ä¹æ¯ä¸ä¸ªsingletonè¿æ¯ä¸ä¸ªprototypeã å¦æä¸ç»å®ååç¸åºçbeanå®ä¹æ²¡æ被æ¾å°ï¼å°ä¼æåºä¸ä¸ªå¼å¸¸ï¼NoSuchBeanDefinitionExceptionï¼ |
| | | * |
| | | * @param name |
| | | * @return boolean |
| | | * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException |
| | | * |
| | | */ |
| | | public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException |
| | | { |
| | | return beanFactory.isSingleton(name); |
| | | } |
| | | |
| | | /** |
| | | * @param name |
| | | * @return Class 注å对象çç±»å |
| | | * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException |
| | | * |
| | | */ |
| | | public static Class<?> getType(String name) throws NoSuchBeanDefinitionException |
| | | { |
| | | return beanFactory.getType(name); |
| | | } |
| | | |
| | | /** |
| | | * å¦æç»å®çbeanååå¨beanå®ä¹ä¸æå«åï¼åè¿åè¿äºå«å |
| | | * |
| | | * @param name |
| | | * @return |
| | | * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException |
| | | * |
| | | */ |
| | | public static String[] getAliases(String name) throws NoSuchBeanDefinitionException |
| | | { |
| | | return beanFactory.getAliases(name); |
| | | } |
| | | |
| | | /** |
| | | * è·åaop代ç对象 |
| | | * |
| | | * @param invoker |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T getAopProxy(T invoker) |
| | | { |
| | | return (T) AopContext.currentProxy(); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åçç¯å¢é
ç½®ï¼æ é
ç½®è¿ånull |
| | | * |
| | | * @return å½åçç¯å¢é
ç½® |
| | | */ |
| | | public static String[] getActiveProfiles() |
| | | { |
| | | return applicationContext.getEnvironment().getActiveProfiles(); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åçç¯å¢é
ç½®ï¼å½æå¤ä¸ªç¯å¢é
ç½®æ¶ï¼åªè·å第ä¸ä¸ª |
| | | * |
| | | * @return å½åçç¯å¢é
ç½® |
| | | */ |
| | | public static String getActiveProfile() |
| | | { |
| | | final String[] activeProfiles = getActiveProfiles(); |
| | | return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; |
| | | } |
| | | |
| | | /** |
| | | * è·åé
ç½®æ件ä¸çå¼ |
| | | * |
| | | * @param key é
ç½®æ件çkey |
| | | * @return å½åçé
ç½®æ件çå¼ |
| | | * |
| | | */ |
| | | public static String getRequiredProperty(String key) |
| | | { |
| | | return applicationContext.getEnvironment().getRequiredProperty(key); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.sql; |
| | | |
| | | import com.jcdm.common.exception.UtilException; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * sqlæä½å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class SqlUtil |
| | | { |
| | | /** |
| | | * å®ä¹å¸¸ç¨ç sqlå
³é®å |
| | | */ |
| | | public static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()"; |
| | | |
| | | /** |
| | | * ä»
æ¯æåæ¯ãæ°åãä¸å线ãç©ºæ ¼ãéå·ãå°æ°ç¹ï¼æ¯æå¤ä¸ªå段æåºï¼ |
| | | */ |
| | | public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+"; |
| | | |
| | | /** |
| | | * éå¶orderByæ大é¿åº¦ |
| | | */ |
| | | private static final int ORDER_BY_MAX_LENGTH = 500; |
| | | |
| | | /** |
| | | * æ£æ¥å符ï¼é²æ¢æ³¨å
¥ç»è¿ |
| | | */ |
| | | public static String escapeOrderBySql(String value) |
| | | { |
| | | if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) |
| | | { |
| | | throw new UtilException("åæ°ä¸ç¬¦åè§èï¼ä¸è½è¿è¡æ¥è¯¢"); |
| | | } |
| | | if (StringUtils.length(value) > ORDER_BY_MAX_LENGTH) |
| | | { |
| | | throw new UtilException("åæ°å·²è¶
è¿æ大éå¶ï¼ä¸è½è¿è¡æ¥è¯¢"); |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | /** |
| | | * éªè¯ order by è¯æ³æ¯å¦ç¬¦åè§è |
| | | */ |
| | | public static boolean isValidOrderBySql(String value) |
| | | { |
| | | return value.matches(SQL_PATTERN); |
| | | } |
| | | |
| | | /** |
| | | * SQLå
³é®åæ£æ¥ |
| | | */ |
| | | public static void filterKeyword(String value) |
| | | { |
| | | if (StringUtils.isEmpty(value)) |
| | | { |
| | | return; |
| | | } |
| | | String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|"); |
| | | for (String sqlKeyword : sqlKeywords) |
| | | { |
| | | if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1) |
| | | { |
| | | throw new UtilException("åæ°åå¨SQL注å
¥é£é©"); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.uuid; |
| | | |
| | | /** |
| | | * IDçæå¨å·¥å
·ç±» |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class IdUtils |
| | | { |
| | | /** |
| | | * è·åéæºUUID |
| | | * |
| | | * @return éæºUUID |
| | | */ |
| | | public static String randomUUID() |
| | | { |
| | | return UUID.randomUUID().toString(); |
| | | } |
| | | |
| | | /** |
| | | * ç®åçUUIDï¼å»æäºæ¨ªçº¿ |
| | | * |
| | | * @return ç®åçUUIDï¼å»æäºæ¨ªçº¿ |
| | | */ |
| | | public static String simpleUUID() |
| | | { |
| | | return UUID.randomUUID().toString(true); |
| | | } |
| | | |
| | | /** |
| | | * è·åéæºUUIDï¼ä½¿ç¨æ§è½æ´å¥½çThreadLocalRandomçæUUID |
| | | * |
| | | * @return éæºUUID |
| | | */ |
| | | public static String fastUUID() |
| | | { |
| | | return UUID.fastUUID().toString(); |
| | | } |
| | | |
| | | /** |
| | | * ç®åçUUIDï¼å»æäºæ¨ªçº¿ï¼ä½¿ç¨æ§è½æ´å¥½çThreadLocalRandomçæUUID |
| | | * |
| | | * @return ç®åçUUIDï¼å»æäºæ¨ªçº¿ |
| | | */ |
| | | public static String fastSimpleUUID() |
| | | { |
| | | return UUID.fastUUID().toString(true); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.uuid; |
| | | |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import com.jcdm.common.utils.DateUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * @author jc åºåçæç±» |
| | | */ |
| | | public class Seq |
| | | { |
| | | // éç¨åºåç±»å |
| | | public static final String commSeqType = "COMMON"; |
| | | |
| | | // ä¸ä¼ åºåç±»å |
| | | public static final String uploadSeqType = "UPLOAD"; |
| | | |
| | | // éç¨æ¥å£åºåæ° |
| | | private static AtomicInteger commSeq = new AtomicInteger(1); |
| | | |
| | | // ä¸ä¼ æ¥å£åºåæ° |
| | | private static AtomicInteger uploadSeq = new AtomicInteger(1); |
| | | |
| | | // æºå¨æ è¯ |
| | | private static final String machineCode = "A"; |
| | | |
| | | /** |
| | | * è·åéç¨åºåå· |
| | | * |
| | | * @return åºåå¼ |
| | | */ |
| | | public static String getId() |
| | | { |
| | | return getId(commSeqType); |
| | | } |
| | | |
| | | /** |
| | | * é»è®¤16ä½åºåå· yyMMddHHmmss + ä¸ä½æºå¨æ è¯ + 3é¿åº¦å¾ªç¯éå¢å符串 |
| | | * |
| | | * @return åºåå¼ |
| | | */ |
| | | public static String getId(String type) |
| | | { |
| | | AtomicInteger atomicInt = commSeq; |
| | | if (uploadSeqType.equals(type)) |
| | | { |
| | | atomicInt = uploadSeq; |
| | | } |
| | | return getId(atomicInt, 3); |
| | | } |
| | | |
| | | /** |
| | | * éç¨æ¥å£åºåå· yyMMddHHmmss + ä¸ä½æºå¨æ è¯ + lengthé¿åº¦å¾ªç¯éå¢å符串 |
| | | * |
| | | * @param atomicInt åºåæ° |
| | | * @param length æ°å¼é¿åº¦ |
| | | * @return åºåå¼ |
| | | */ |
| | | public static String getId(AtomicInteger atomicInt, int length) |
| | | { |
| | | String result = DateUtils.dateTimeNow(); |
| | | result += machineCode; |
| | | result += getSeq(atomicInt, length); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * åºå循ç¯éå¢å符串[1, 10 ç (length)å¹æ¬¡æ¹), ç¨0左补é½lengthä½æ° |
| | | * |
| | | * @return åºåå¼ |
| | | */ |
| | | private synchronized static String getSeq(AtomicInteger atomicInt, int length) |
| | | { |
| | | // å
åå¼å+1 |
| | | int value = atomicInt.getAndIncrement(); |
| | | |
| | | // å¦ææ´æ°åå¼>=10 ç (length)å¹æ¬¡æ¹åé置为1 |
| | | int maxSeq = (int) Math.pow(10, length); |
| | | if (atomicInt.get() >= maxSeq) |
| | | { |
| | | atomicInt.set(1); |
| | | } |
| | | // 转å符串ï¼ç¨0å·¦è¡¥é½ |
| | | return StringUtils.padl(value, length); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.utils.uuid; |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.SecureRandom; |
| | | import java.util.Random; |
| | | import java.util.concurrent.ThreadLocalRandom; |
| | | import com.jcdm.common.exception.UtilException; |
| | | |
| | | /** |
| | | * æä¾éç¨å¯ä¸è¯å«ç ï¼universally unique identifierï¼ï¼UUIDï¼å®ç° |
| | | * |
| | | * @author jc |
| | | */ |
| | | public final class UUID implements java.io.Serializable, Comparable<UUID> |
| | | { |
| | | private static final long serialVersionUID = -1185015143654744140L; |
| | | |
| | | /** |
| | | * SecureRandom çåä¾ |
| | | * |
| | | */ |
| | | private static class Holder |
| | | { |
| | | static final SecureRandom numberGenerator = getSecureRandom(); |
| | | } |
| | | |
| | | /** æ¤UUIDçæé«64ææä½ */ |
| | | private final long mostSigBits; |
| | | |
| | | /** æ¤UUIDçæä½64ææä½ */ |
| | | private final long leastSigBits; |
| | | |
| | | /** |
| | | * ç§ææé |
| | | * |
| | | * @param data æ°æ® |
| | | */ |
| | | private UUID(byte[] data) |
| | | { |
| | | long msb = 0; |
| | | long lsb = 0; |
| | | assert data.length == 16 : "data must be 16 bytes in length"; |
| | | for (int i = 0; i < 8; i++) |
| | | { |
| | | msb = (msb << 8) | (data[i] & 0xff); |
| | | } |
| | | for (int i = 8; i < 16; i++) |
| | | { |
| | | lsb = (lsb << 8) | (data[i] & 0xff); |
| | | } |
| | | this.mostSigBits = msb; |
| | | this.leastSigBits = lsb; |
| | | } |
| | | |
| | | /** |
| | | * 使ç¨æå®çæ°æ®æé æ°ç UUIDã |
| | | * |
| | | * @param mostSigBits ç¨äº {@code UUID} çæé«ææ 64 ä½ |
| | | * @param leastSigBits ç¨äº {@code UUID} çæä½ææ 64 ä½ |
| | | */ |
| | | public UUID(long mostSigBits, long leastSigBits) |
| | | { |
| | | this.mostSigBits = mostSigBits; |
| | | this.leastSigBits = leastSigBits; |
| | | } |
| | | |
| | | /** |
| | | * è·åç±»å 4ï¼ä¼ªéæºçæçï¼UUID çéæå·¥åã |
| | | * |
| | | * @return éæºçæç {@code UUID} |
| | | */ |
| | | public static UUID fastUUID() |
| | | { |
| | | return randomUUID(false); |
| | | } |
| | | |
| | | /** |
| | | * è·åç±»å 4ï¼ä¼ªéæºçæçï¼UUID çéæå·¥åã 使ç¨å å¯ç强伪éæºæ°çæå¨çæ该 UUIDã |
| | | * |
| | | * @return éæºçæç {@code UUID} |
| | | */ |
| | | public static UUID randomUUID() |
| | | { |
| | | return randomUUID(true); |
| | | } |
| | | |
| | | /** |
| | | * è·åç±»å 4ï¼ä¼ªéæºçæçï¼UUID çéæå·¥åã 使ç¨å å¯ç强伪éæºæ°çæå¨çæ该 UUIDã |
| | | * |
| | | * @param isSecure æ¯å¦ä½¿ç¨{@link SecureRandom}å¦ææ¯å¯ä»¥è·å¾æ´å®å
¨çéæºç ï¼å¦åå¯ä»¥å¾å°æ´å¥½çæ§è½ |
| | | * @return éæºçæç {@code UUID} |
| | | */ |
| | | public static UUID randomUUID(boolean isSecure) |
| | | { |
| | | final Random ng = isSecure ? Holder.numberGenerator : getRandom(); |
| | | |
| | | byte[] randomBytes = new byte[16]; |
| | | ng.nextBytes(randomBytes); |
| | | randomBytes[6] &= 0x0f; /* clear version */ |
| | | randomBytes[6] |= 0x40; /* set to version 4 */ |
| | | randomBytes[8] &= 0x3f; /* clear variant */ |
| | | randomBytes[8] |= 0x80; /* set to IETF variant */ |
| | | return new UUID(randomBytes); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æå®çåèæ°ç»è·åç±»å 3ï¼åºäºå称çï¼UUID çéæå·¥åã |
| | | * |
| | | * @param name ç¨äºæé UUID çåèæ°ç»ã |
| | | * |
| | | * @return æ ¹æ®æå®æ°ç»çæç {@code UUID} |
| | | */ |
| | | public static UUID nameUUIDFromBytes(byte[] name) |
| | | { |
| | | MessageDigest md; |
| | | try |
| | | { |
| | | md = MessageDigest.getInstance("MD5"); |
| | | } |
| | | catch (NoSuchAlgorithmException nsae) |
| | | { |
| | | throw new InternalError("MD5 not supported"); |
| | | } |
| | | byte[] md5Bytes = md.digest(name); |
| | | md5Bytes[6] &= 0x0f; /* clear version */ |
| | | md5Bytes[6] |= 0x30; /* set to version 3 */ |
| | | md5Bytes[8] &= 0x3f; /* clear variant */ |
| | | md5Bytes[8] |= 0x80; /* set to IETF variant */ |
| | | return new UUID(md5Bytes); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ® {@link #toString()} æ¹æ³ä¸æè¿°çå符串æ å表示形å¼å建{@code UUID}ã |
| | | * |
| | | * @param name æå® {@code UUID} å符串 |
| | | * @return å
·ææå®å¼ç {@code UUID} |
| | | * @throws IllegalArgumentException å¦æ name ä¸ {@link #toString} ä¸æè¿°çå符串表示形å¼ä¸ç¬¦æåºæ¤å¼å¸¸ |
| | | * |
| | | */ |
| | | public static UUID fromString(String name) |
| | | { |
| | | String[] components = name.split("-"); |
| | | if (components.length != 5) |
| | | { |
| | | throw new IllegalArgumentException("Invalid UUID string: " + name); |
| | | } |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | components[i] = "0x" + components[i]; |
| | | } |
| | | |
| | | long mostSigBits = Long.decode(components[0]).longValue(); |
| | | mostSigBits <<= 16; |
| | | mostSigBits |= Long.decode(components[1]).longValue(); |
| | | mostSigBits <<= 16; |
| | | mostSigBits |= Long.decode(components[2]).longValue(); |
| | | |
| | | long leastSigBits = Long.decode(components[3]).longValue(); |
| | | leastSigBits <<= 48; |
| | | leastSigBits |= Long.decode(components[4]).longValue(); |
| | | |
| | | return new UUID(mostSigBits, leastSigBits); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæ¤ UUID ç 128 ä½å¼ä¸çæä½ææ 64 ä½ã |
| | | * |
| | | * @return æ¤ UUID ç 128 ä½å¼ä¸çæä½ææ 64 ä½ã |
| | | */ |
| | | public long getLeastSignificantBits() |
| | | { |
| | | return leastSigBits; |
| | | } |
| | | |
| | | /** |
| | | * è¿åæ¤ UUID ç 128 ä½å¼ä¸çæé«ææ 64 ä½ã |
| | | * |
| | | * @return æ¤ UUID ç 128 ä½å¼ä¸æé«ææ 64 ä½ã |
| | | */ |
| | | public long getMostSignificantBits() |
| | | { |
| | | return mostSigBits; |
| | | } |
| | | |
| | | /** |
| | | * ä¸æ¤ {@code UUID} ç¸å
³èççæ¬å·. çæ¬å·æè¿°æ¤ {@code UUID} æ¯å¦ä½çæçã |
| | | * <p> |
| | | * çæ¬å·å
·æ以ä¸å«æ: |
| | | * <ul> |
| | | * <li>1 åºäºæ¶é´ç UUID |
| | | * <li>2 DCE å®å
¨ UUID |
| | | * <li>3 åºäºå称ç UUID |
| | | * <li>4 éæºçæç UUID |
| | | * </ul> |
| | | * |
| | | * @return æ¤ {@code UUID} ççæ¬å· |
| | | */ |
| | | public int version() |
| | | { |
| | | // Version is bits masked by 0x000000000000F000 in MS long |
| | | return (int) ((mostSigBits >> 12) & 0x0f); |
| | | } |
| | | |
| | | /** |
| | | * ä¸æ¤ {@code UUID} ç¸å
³èçåä½å·ãåä½å·æè¿° {@code UUID} çå¸å±ã |
| | | * <p> |
| | | * åä½å·å
·æ以ä¸å«æï¼ |
| | | * <ul> |
| | | * <li>0 为 NCS ååå
¼å®¹ä¿ç |
| | | * <li>2 <a href="http://www.ietf.org/rfc/rfc4122.txt">IETF RFC 4122</a>(Leach-Salz), ç¨äºæ¤ç±» |
| | | * <li>6 ä¿çï¼å¾®è½¯ååå
¼å®¹ |
| | | * <li>7 ä¿çä¾ä»¥åå®ä¹ä½¿ç¨ |
| | | * </ul> |
| | | * |
| | | * @return æ¤ {@code UUID} ç¸å
³èçåä½å· |
| | | */ |
| | | public int variant() |
| | | { |
| | | // This field is composed of a varying number of bits. |
| | | // 0 - - Reserved for NCS backward compatibility |
| | | // 1 0 - The IETF aka Leach-Salz variant (used by this class) |
| | | // 1 1 0 Reserved, Microsoft backward compatibility |
| | | // 1 1 1 Reserved for future definition. |
| | | return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63)); |
| | | } |
| | | |
| | | /** |
| | | * ä¸æ¤ UUID ç¸å
³èçæ¶é´æ³å¼ã |
| | | * |
| | | * <p> |
| | | * 60 ä½çæ¶é´æ³å¼æ ¹æ®æ¤ {@code UUID} ç time_lowãtime_mid å time_hi å段æé ã<br> |
| | | * æå¾å°çæ¶é´æ³ä»¥ 100 毫微ç§ä¸ºåä½ï¼ä» UTCï¼éç¨åè°æ¶é´ï¼ 1582 å¹´ 10 æ 15 æ¥é¶æ¶å¼å§ã |
| | | * |
| | | * <p> |
| | | * æ¶é´æ³å¼ä»
å¨å¨åºäºæ¶é´ç UUIDï¼å
¶ version ç±»å为 1ï¼ä¸æææä¹ã<br> |
| | | * å¦ææ¤ {@code UUID} ä¸æ¯åºäºæ¶é´ç UUIDï¼åæ¤æ¹æ³æåº UnsupportedOperationExceptionã |
| | | * |
| | | * @throws UnsupportedOperationException å¦ææ¤ {@code UUID} ä¸æ¯ version 为 1 ç UUIDã |
| | | */ |
| | | public long timestamp() throws UnsupportedOperationException |
| | | { |
| | | checkTimeBase(); |
| | | return (mostSigBits & 0x0FFFL) << 48// |
| | | | ((mostSigBits >> 16) & 0x0FFFFL) << 32// |
| | | | mostSigBits >>> 32; |
| | | } |
| | | |
| | | /** |
| | | * ä¸æ¤ UUID ç¸å
³èçæ¶éåºåå¼ã |
| | | * |
| | | * <p> |
| | | * 14 ä½çæ¶éåºåå¼æ ¹æ®æ¤ UUID ç clock_seq å段æé ãclock_seq å段ç¨äºä¿è¯å¨åºäºæ¶é´ç UUID ä¸çæ¶é´å¯ä¸æ§ã |
| | | * <p> |
| | | * {@code clockSequence} å¼ä»
å¨åºäºæ¶é´ç UUIDï¼å
¶ version ç±»å为 1ï¼ä¸æææä¹ã å¦ææ¤ UUID ä¸æ¯åºäºæ¶é´ç UUIDï¼åæ¤æ¹æ³æåº |
| | | * UnsupportedOperationExceptionã |
| | | * |
| | | * @return æ¤ {@code UUID} çæ¶éåºå |
| | | * |
| | | * @throws UnsupportedOperationException å¦ææ¤ UUID ç version ä¸ä¸º 1 |
| | | */ |
| | | public int clockSequence() throws UnsupportedOperationException |
| | | { |
| | | checkTimeBase(); |
| | | return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48); |
| | | } |
| | | |
| | | /** |
| | | * ä¸æ¤ UUID ç¸å
³çèç¹å¼ã |
| | | * |
| | | * <p> |
| | | * 48 ä½çèç¹å¼æ ¹æ®æ¤ UUID ç node å段æé ãæ¤å段æ¨å¨ç¨äºä¿åæºå¨ç IEEE 802 å°åï¼è¯¥å°åç¨äºçææ¤ UUID 以ä¿è¯ç©ºé´å¯ä¸æ§ã |
| | | * <p> |
| | | * èç¹å¼ä»
å¨åºäºæ¶é´ç UUIDï¼å
¶ version ç±»å为 1ï¼ä¸æææä¹ã<br> |
| | | * å¦ææ¤ UUID ä¸æ¯åºäºæ¶é´ç UUIDï¼åæ¤æ¹æ³æåº UnsupportedOperationExceptionã |
| | | * |
| | | * @return æ¤ {@code UUID} çèç¹å¼ |
| | | * |
| | | * @throws UnsupportedOperationException å¦ææ¤ UUID ç version ä¸ä¸º 1 |
| | | */ |
| | | public long node() throws UnsupportedOperationException |
| | | { |
| | | checkTimeBase(); |
| | | return leastSigBits & 0x0000FFFFFFFFFFFFL; |
| | | } |
| | | |
| | | /** |
| | | * è¿åæ¤{@code UUID} çå符串表ç°å½¢å¼ã |
| | | * |
| | | * <p> |
| | | * UUID çå符串表示形å¼ç±æ¤ BNF æè¿°ï¼ |
| | | * |
| | | * <pre> |
| | | * {@code |
| | | * UUID = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node> |
| | | * time_low = 4*<hexOctet> |
| | | * time_mid = 2*<hexOctet> |
| | | * time_high_and_version = 2*<hexOctet> |
| | | * variant_and_sequence = 2*<hexOctet> |
| | | * node = 6*<hexOctet> |
| | | * hexOctet = <hexDigit><hexDigit> |
| | | * hexDigit = [0-9a-fA-F] |
| | | * } |
| | | * </pre> |
| | | * |
| | | * </blockquote> |
| | | * |
| | | * @return æ¤{@code UUID} çå符串表ç°å½¢å¼ |
| | | * @see #toString(boolean) |
| | | */ |
| | | @Override |
| | | public String toString() |
| | | { |
| | | return toString(false); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæ¤{@code UUID} çå符串表ç°å½¢å¼ã |
| | | * |
| | | * <p> |
| | | * UUID çå符串表示形å¼ç±æ¤ BNF æè¿°ï¼ |
| | | * |
| | | * <pre> |
| | | * {@code |
| | | * UUID = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node> |
| | | * time_low = 4*<hexOctet> |
| | | * time_mid = 2*<hexOctet> |
| | | * time_high_and_version = 2*<hexOctet> |
| | | * variant_and_sequence = 2*<hexOctet> |
| | | * node = 6*<hexOctet> |
| | | * hexOctet = <hexDigit><hexDigit> |
| | | * hexDigit = [0-9a-fA-F] |
| | | * } |
| | | * </pre> |
| | | * |
| | | * </blockquote> |
| | | * |
| | | * @param isSimple æ¯å¦ç®å模å¼ï¼ç®å模å¼ä¸ºä¸å¸¦'-'çUUIDå符串 |
| | | * @return æ¤{@code UUID} çå符串表ç°å½¢å¼ |
| | | */ |
| | | public String toString(boolean isSimple) |
| | | { |
| | | final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36); |
| | | // time_low |
| | | builder.append(digits(mostSigBits >> 32, 8)); |
| | | if (!isSimple) |
| | | { |
| | | builder.append('-'); |
| | | } |
| | | // time_mid |
| | | builder.append(digits(mostSigBits >> 16, 4)); |
| | | if (!isSimple) |
| | | { |
| | | builder.append('-'); |
| | | } |
| | | // time_high_and_version |
| | | builder.append(digits(mostSigBits, 4)); |
| | | if (!isSimple) |
| | | { |
| | | builder.append('-'); |
| | | } |
| | | // variant_and_sequence |
| | | builder.append(digits(leastSigBits >> 48, 4)); |
| | | if (!isSimple) |
| | | { |
| | | builder.append('-'); |
| | | } |
| | | // node |
| | | builder.append(digits(leastSigBits, 12)); |
| | | |
| | | return builder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * è¿åæ¤ UUID çåå¸ç ã |
| | | * |
| | | * @return UUID çåå¸ç å¼ã |
| | | */ |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | | long hilo = mostSigBits ^ leastSigBits; |
| | | return ((int) (hilo >> 32)) ^ (int) hilo; |
| | | } |
| | | |
| | | /** |
| | | * å°æ¤å¯¹è±¡ä¸æå®å¯¹è±¡æ¯è¾ã |
| | | * <p> |
| | | * å½ä¸ä»
å½åæ°ä¸ä¸º {@code null}ãèæ¯ä¸ä¸ª UUID 对象ãå
·æä¸æ¤ UUID ç¸åç varriantãå
å«ç¸åçå¼ï¼æ¯ä¸ä½åç¸åï¼æ¶ï¼ç»ææ为 {@code true}ã |
| | | * |
| | | * @param obj è¦ä¸ä¹æ¯è¾ç对象 |
| | | * |
| | | * @return å¦æ对象ç¸åï¼åè¿å {@code true}ï¼å¦åè¿å {@code false} |
| | | */ |
| | | @Override |
| | | public boolean equals(Object obj) |
| | | { |
| | | if ((null == obj) || (obj.getClass() != UUID.class)) |
| | | { |
| | | return false; |
| | | } |
| | | UUID id = (UUID) obj; |
| | | return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits); |
| | | } |
| | | |
| | | // Comparison Operations |
| | | |
| | | /** |
| | | * å°æ¤ UUID ä¸æå®ç UUID æ¯è¾ã |
| | | * |
| | | * <p> |
| | | * å¦æ两个 UUID ä¸åï¼ä¸ç¬¬ä¸ä¸ª UUID çæé«ææå段大äºç¬¬äºä¸ª UUID ç对åºå段ï¼å第ä¸ä¸ª UUID 大äºç¬¬äºä¸ª UUIDã |
| | | * |
| | | * @param val ä¸æ¤ UUID æ¯è¾ç UUID |
| | | * |
| | | * @return å¨æ¤ UUID å°äºãçäºæå¤§äº val æ¶ï¼åå«è¿å -1ã0 æ 1ã |
| | | * |
| | | */ |
| | | @Override |
| | | public int compareTo(UUID val) |
| | | { |
| | | // The ordering is intentionally set up so that the UUIDs |
| | | // can simply be numerically compared as two numbers |
| | | return (this.mostSigBits < val.mostSigBits ? -1 : // |
| | | (this.mostSigBits > val.mostSigBits ? 1 : // |
| | | (this.leastSigBits < val.leastSigBits ? -1 : // |
| | | (this.leastSigBits > val.leastSigBits ? 1 : // |
| | | 0)))); |
| | | } |
| | | |
| | | // ------------------------------------------------------------------------------------------------------------------- |
| | | // Private method start |
| | | /** |
| | | * è¿åæå®æ°å对åºçhexå¼ |
| | | * |
| | | * @param val å¼ |
| | | * @param digits ä½ |
| | | * @return å¼ |
| | | */ |
| | | private static String digits(long val, int digits) |
| | | { |
| | | long hi = 1L << (digits * 4); |
| | | return Long.toHexString(hi | (val & (hi - 1))).substring(1); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ¯å¦ä¸ºtime-basedçæ¬UUID |
| | | */ |
| | | private void checkTimeBase() |
| | | { |
| | | if (version() != 1) |
| | | { |
| | | throw new UnsupportedOperationException("Not a time-based UUID"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å{@link SecureRandom}ï¼ç±»æä¾å å¯ç强éæºæ°çæå¨ (RNG) |
| | | * |
| | | * @return {@link SecureRandom} |
| | | */ |
| | | public static SecureRandom getSecureRandom() |
| | | { |
| | | try |
| | | { |
| | | return SecureRandom.getInstance("SHA1PRNG"); |
| | | } |
| | | catch (NoSuchAlgorithmException e) |
| | | { |
| | | throw new UtilException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åéæºæ°çæå¨å¯¹è±¡<br> |
| | | * ThreadLocalRandomæ¯JDK 7ä¹åæä¾å¹¶å产çéæºæ°ï¼è½å¤è§£å³å¤ä¸ªçº¿ç¨åççç«äºäºå¤ºã |
| | | * |
| | | * @return {@link ThreadLocalRandom} |
| | | */ |
| | | public static ThreadLocalRandom getRandom() |
| | | { |
| | | return ThreadLocalRandom.current(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.xss; |
| | | |
| | | import javax.validation.Constraint; |
| | | import javax.validation.Payload; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * èªå®ä¹xssæ ¡éªæ³¨è§£ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Target(value = { ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER }) |
| | | @Constraint(validatedBy = { XssValidator.class }) |
| | | public @interface Xss |
| | | { |
| | | String message() |
| | | |
| | | default "ä¸å
许任ä½èæ¬è¿è¡"; |
| | | |
| | | Class<?>[] groups() default {}; |
| | | |
| | | Class<? extends Payload>[] payload() default {}; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.common.xss; |
| | | |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import javax.validation.ConstraintValidator; |
| | | import javax.validation.ConstraintValidatorContext; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * èªå®ä¹xssæ ¡éªæ³¨è§£å®ç° |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class XssValidator implements ConstraintValidator<Xss, String> |
| | | { |
| | | private static final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />"; |
| | | |
| | | @Override |
| | | public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) |
| | | { |
| | | if (StringUtils.isBlank(value)) |
| | | { |
| | | return true; |
| | | } |
| | | return !containsHtml(value); |
| | | } |
| | | |
| | | public static boolean containsHtml(String value) |
| | | { |
| | | Pattern pattern = Pattern.compile(HTML_PATTERN); |
| | | Matcher matcher = pattern.matcher(value); |
| | | return matcher.matches(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <parent> |
| | | <artifactId>jcdm</artifactId> |
| | | <groupId>com.jcdm</groupId> |
| | | <version>3.8.6</version> |
| | | </parent> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <artifactId>jcdm-framework</artifactId> |
| | | |
| | | <description> |
| | | frameworkæ¡æ¶æ ¸å¿ |
| | | </description> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- SpringBoot Webå®¹å¨ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringBoot æ¦æªå¨ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-aop</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- é¿éæ°æ®åºè¿æ¥æ± --> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>druid-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- éªè¯ç --> |
| | | <dependency> |
| | | <groupId>pro.fessional</groupId> |
| | | <artifactId>kaptcha</artifactId> |
| | | <exclusions> |
| | | <exclusion> |
| | | <artifactId>servlet-api</artifactId> |
| | | <groupId>javax.servlet</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- è·åç³»ç»ä¿¡æ¯ --> |
| | | <dependency> |
| | | <groupId>com.github.oshi</groupId> |
| | | <artifactId>oshi-core</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- ç³»ç»æ¨¡å--> |
| | | <dependency> |
| | | <groupId>com.jcdm</groupId> |
| | | <artifactId>jcdm-system</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringBoot Websocket --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-websocket</artifactId> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.aspectj; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.springframework.stereotype.Component; |
| | | import com.jcdm.common.annotation.DataScope; |
| | | import com.jcdm.common.core.domain.BaseEntity; |
| | | import com.jcdm.common.core.domain.entity.SysRole; |
| | | import com.jcdm.common.core.domain.entity.SysUser; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.core.text.Convert; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.framework.security.context.PermissionContextHolder; |
| | | |
| | | /** |
| | | * æ°æ®è¿æ»¤å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Aspect |
| | | @Component |
| | | public class DataScopeAspect |
| | | { |
| | | /** |
| | | * å
¨é¨æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_ALL = "1"; |
| | | |
| | | /** |
| | | * èªå®æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_CUSTOM = "2"; |
| | | |
| | | /** |
| | | * é¨é¨æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_DEPT = "3"; |
| | | |
| | | /** |
| | | * é¨é¨å以ä¸æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; |
| | | |
| | | /** |
| | | * ä»
æ¬äººæ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_SELF = "5"; |
| | | |
| | | /** |
| | | * æ°æ®æéè¿æ»¤å
³é®å |
| | | */ |
| | | public static final String DATA_SCOPE = "dataScope"; |
| | | |
| | | @Before("@annotation(controllerDataScope)") |
| | | public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable |
| | | { |
| | | clearDataScope(point); |
| | | handleDataScope(point, controllerDataScope); |
| | | } |
| | | |
| | | protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) |
| | | { |
| | | // è·åå½åçç¨æ· |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | { |
| | | SysUser currentUser = loginUser.getUser(); |
| | | // å¦ææ¯è¶
级管çåï¼åä¸è¿æ»¤æ°æ® |
| | | if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) |
| | | { |
| | | String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext()); |
| | | dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), |
| | | controllerDataScope.userAlias(), permission); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°æ®èå´è¿æ»¤ |
| | | * |
| | | * @param joinPoint åç¹ |
| | | * @param user ç¨æ· |
| | | * @param deptAlias é¨é¨å«å |
| | | * @param userAlias ç¨æ·å«å |
| | | * @param permission æéå符 |
| | | */ |
| | | public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission) |
| | | { |
| | | StringBuilder sqlString = new StringBuilder(); |
| | | List<String> conditions = new ArrayList<String>(); |
| | | |
| | | for (SysRole role : user.getRoles()) |
| | | { |
| | | String dataScope = role.getDataScope(); |
| | | if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope)) |
| | | { |
| | | continue; |
| | | } |
| | | if (StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions()) |
| | | && !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission))) |
| | | { |
| | | continue; |
| | | } |
| | | if (DATA_SCOPE_ALL.equals(dataScope)) |
| | | { |
| | | sqlString = new StringBuilder(); |
| | | conditions.add(dataScope); |
| | | break; |
| | | } |
| | | else if (DATA_SCOPE_CUSTOM.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, |
| | | role.getRoleId())); |
| | | } |
| | | else if (DATA_SCOPE_DEPT.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); |
| | | } |
| | | else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
| | | deptAlias, user.getDeptId(), user.getDeptId())); |
| | | } |
| | | else if (DATA_SCOPE_SELF.equals(dataScope)) |
| | | { |
| | | if (StringUtils.isNotBlank(userAlias)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); |
| | | } |
| | | else |
| | | { |
| | | // æ°æ®æé为ä»
æ¬äººä¸æ²¡æuserAliaså«åä¸æ¥è¯¢ä»»ä½æ°æ® |
| | | sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); |
| | | } |
| | | } |
| | | conditions.add(dataScope); |
| | | } |
| | | |
| | | // å¤è§è²æ
åµä¸ï¼ææè§è²é½ä¸å
å«ä¼ éè¿æ¥çæéå符ï¼è¿ä¸ªæ¶åsqlStringä¹ä¼ä¸ºç©ºï¼æ以è¦éå¶ä¸ä¸,ä¸æ¥è¯¢ä»»ä½æ°æ® |
| | | if (StringUtils.isEmpty(conditions)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(sqlString.toString())) |
| | | { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (StringUtils.isNotNull(params) && params instanceof BaseEntity) |
| | | { |
| | | BaseEntity baseEntity = (BaseEntity) params; |
| | | baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¼æ¥æésqlåå
æ¸
空params.dataScopeåæ°é²æ¢æ³¨å
¥ |
| | | */ |
| | | private void clearDataScope(final JoinPoint joinPoint) |
| | | { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (StringUtils.isNotNull(params) && params instanceof BaseEntity) |
| | | { |
| | | BaseEntity baseEntity = (BaseEntity) params; |
| | | baseEntity.getParams().put(DATA_SCOPE, ""); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.aspectj; |
| | | |
| | | import java.util.Objects; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.core.annotation.AnnotationUtils; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | import com.jcdm.common.annotation.DataSource; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.framework.datasource.DynamicDataSourceContextHolder; |
| | | |
| | | /** |
| | | * å¤æ°æ®æºå¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Aspect |
| | | @Order(1) |
| | | @Component |
| | | public class DataSourceAspect |
| | | { |
| | | protected Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | @Pointcut("@annotation(com.jcdm.common.annotation.DataSource)" |
| | | + "|| @within(com.jcdm.common.annotation.DataSource)") |
| | | public void dsPointCut() |
| | | { |
| | | |
| | | } |
| | | |
| | | @Around("dsPointCut()") |
| | | public Object around(ProceedingJoinPoint point) throws Throwable |
| | | { |
| | | DataSource dataSource = getDataSource(point); |
| | | |
| | | if (StringUtils.isNotNull(dataSource)) |
| | | { |
| | | DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); |
| | | } |
| | | |
| | | try |
| | | { |
| | | return point.proceed(); |
| | | } |
| | | finally |
| | | { |
| | | // éæ¯æ°æ®æº å¨æ§è¡æ¹æ³ä¹å |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åéè¦åæ¢çæ°æ®æº |
| | | */ |
| | | public DataSource getDataSource(ProceedingJoinPoint point) |
| | | { |
| | | MethodSignature signature = (MethodSignature) point.getSignature(); |
| | | DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); |
| | | if (Objects.nonNull(dataSource)) |
| | | { |
| | | return dataSource; |
| | | } |
| | | |
| | | return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.aspectj; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.AfterReturning; |
| | | import org.aspectj.lang.annotation.AfterThrowing; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.core.NamedThreadLocal; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.jcdm.common.annotation.Log; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.enums.BusinessStatus; |
| | | import com.jcdm.common.enums.HttpMethod; |
| | | import com.jcdm.common.filter.PropertyPreExcludeFilter; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.ip.IpUtils; |
| | | import com.jcdm.framework.manager.AsyncManager; |
| | | import com.jcdm.framework.manager.factory.AsyncFactory; |
| | | import com.jcdm.system.domain.SysOperLog; |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Aspect |
| | | @Component |
| | | public class LogAspect |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(LogAspect.class); |
| | | |
| | | /** æé¤ææå±æ§å段 */ |
| | | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" }; |
| | | |
| | | /** 计ç®æä½æ¶èæ¶é´ */ |
| | | private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time"); |
| | | |
| | | /** |
| | | * å¤ç请æ±åæ§è¡ |
| | | */ |
| | | @Before(value = "@annotation(controllerLog)") |
| | | public void boBefore(JoinPoint joinPoint, Log controllerLog) |
| | | { |
| | | TIME_THREADLOCAL.set(System.currentTimeMillis()); |
| | | } |
| | | |
| | | /** |
| | | * å¤çå®è¯·æ±åæ§è¡ |
| | | * |
| | | * @param joinPoint åç¹ |
| | | */ |
| | | @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") |
| | | public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) |
| | | { |
| | | handleLog(joinPoint, controllerLog, null, jsonResult); |
| | | } |
| | | |
| | | /** |
| | | * æ¦æªå¼å¸¸æä½ |
| | | * |
| | | * @param joinPoint åç¹ |
| | | * @param e å¼å¸¸ |
| | | */ |
| | | @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") |
| | | public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) |
| | | { |
| | | handleLog(joinPoint, controllerLog, e, null); |
| | | } |
| | | |
| | | protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) |
| | | { |
| | | try |
| | | { |
| | | // è·åå½åçç¨æ· |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | |
| | | // *========æ°æ®åºæ¥å¿=========*// |
| | | SysOperLog operLog = new SysOperLog(); |
| | | operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | | // 请æ±çå°å |
| | | String ip = IpUtils.getIpAddr(); |
| | | operLog.setOperIp(ip); |
| | | operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); |
| | | if (loginUser != null) |
| | | { |
| | | operLog.setOperName(loginUser.getUsername()); |
| | | } |
| | | |
| | | if (e != null) |
| | | { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | } |
| | | // 设置æ¹æ³å称 |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | | String methodName = joinPoint.getSignature().getName(); |
| | | operLog.setMethod(className + "." + methodName + "()"); |
| | | // 设置请æ±æ¹å¼ |
| | | operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); |
| | | // å¤ç设置注解ä¸çåæ° |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| | | // 设置æ¶èæ¶é´ |
| | | operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get()); |
| | | // ä¿åæ°æ®åº |
| | | AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); |
| | | } |
| | | catch (Exception exp) |
| | | { |
| | | // è®°å½æ¬å°å¼å¸¸æ¥å¿ |
| | | log.error("å¼å¸¸ä¿¡æ¯:{}", exp.getMessage()); |
| | | exp.printStackTrace(); |
| | | } |
| | | finally |
| | | { |
| | | TIME_THREADLOCAL.remove(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å注解ä¸å¯¹æ¹æ³çæè¿°ä¿¡æ¯ ç¨äºControllerå±æ³¨è§£ |
| | | * |
| | | * @param log æ¥å¿ |
| | | * @param operLog æä½æ¥å¿ |
| | | * @throws Exception |
| | | */ |
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception |
| | | { |
| | | // 设置actionå¨ä½ |
| | | operLog.setBusinessType(log.businessType().ordinal()); |
| | | // 设置æ é¢ |
| | | operLog.setTitle(log.title()); |
| | | // 设置æä½äººç±»å« |
| | | operLog.setOperatorType(log.operatorType().ordinal()); |
| | | // æ¯å¦éè¦ä¿årequestï¼åæ°åå¼ |
| | | if (log.isSaveRequestData()) |
| | | { |
| | | // è·ååæ°çä¿¡æ¯ï¼ä¼ å
¥å°æ°æ®åºä¸ã |
| | | setRequestValue(joinPoint, operLog, log.excludeParamNames()); |
| | | } |
| | | // æ¯å¦éè¦ä¿åresponseï¼åæ°åå¼ |
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) |
| | | { |
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å请æ±çåæ°ï¼æ¾å°logä¸ |
| | | * |
| | | * @param operLog æä½æ¥å¿ |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception |
| | | { |
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); |
| | | String requestMethod = operLog.getRequestMethod(); |
| | | if (StringUtils.isEmpty(paramsMap) |
| | | && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))) |
| | | { |
| | | String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames); |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000)); |
| | | } |
| | | else |
| | | { |
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åæ°æ¼è£
|
| | | */ |
| | | private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) |
| | | { |
| | | String params = ""; |
| | | if (paramsArray != null && paramsArray.length > 0) |
| | | { |
| | | for (Object o : paramsArray) |
| | | { |
| | | if (StringUtils.isNotNull(o) && !isFilterObject(o)) |
| | | { |
| | | try |
| | | { |
| | | String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter(excludeParamNames)); |
| | | params += jsonObj.toString() + " "; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return params.trim(); |
| | | } |
| | | |
| | | /** |
| | | * 忽ç¥ææå±æ§ |
| | | */ |
| | | public PropertyPreExcludeFilter excludePropertyPreFilter(String[] excludeParamNames) |
| | | { |
| | | return new PropertyPreExcludeFilter().addExcludes(ArrayUtils.addAll(EXCLUDE_PROPERTIES, excludeParamNames)); |
| | | } |
| | | |
| | | /** |
| | | * å¤ææ¯å¦éè¦è¿æ»¤ç对象ã |
| | | * |
| | | * @param o 对象信æ¯ã |
| | | * @return å¦ææ¯éè¦è¿æ»¤ç对象ï¼åè¿åtrueï¼å¦åè¿åfalseã |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public boolean isFilterObject(final Object o) |
| | | { |
| | | Class<?> clazz = o.getClass(); |
| | | if (clazz.isArray()) |
| | | { |
| | | return clazz.getComponentType().isAssignableFrom(MultipartFile.class); |
| | | } |
| | | else if (Collection.class.isAssignableFrom(clazz)) |
| | | { |
| | | Collection collection = (Collection) o; |
| | | for (Object value : collection) |
| | | { |
| | | return value instanceof MultipartFile; |
| | | } |
| | | } |
| | | else if (Map.class.isAssignableFrom(clazz)) |
| | | { |
| | | Map map = (Map) o; |
| | | for (Object value : map.entrySet()) |
| | | { |
| | | Map.Entry entry = (Map.Entry) value; |
| | | return entry.getValue() instanceof MultipartFile; |
| | | } |
| | | } |
| | | return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse |
| | | || o instanceof BindingResult; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.aspectj; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.script.RedisScript; |
| | | import org.springframework.stereotype.Component; |
| | | import com.jcdm.common.annotation.RateLimiter; |
| | | import com.jcdm.common.enums.LimitType; |
| | | import com.jcdm.common.exception.ServiceException; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.ip.IpUtils; |
| | | |
| | | /** |
| | | * éæµå¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | //@Aspect |
| | | //@Component |
| | | public class RateLimiterAspect |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class); |
| | | |
| | | private RedisTemplate<Object, Object> redisTemplate; |
| | | |
| | | private RedisScript<Long> limitScript; |
| | | |
| | | // @Autowired |
| | | public void setRedisTemplate1(RedisTemplate<Object, Object> redisTemplate) |
| | | { |
| | | this.redisTemplate = redisTemplate; |
| | | } |
| | | |
| | | // @Autowired |
| | | public void setLimitScript(RedisScript<Long> limitScript) |
| | | { |
| | | this.limitScript = limitScript; |
| | | } |
| | | |
| | | @Before("@annotation(rateLimiter)") |
| | | public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable |
| | | { |
| | | int time = rateLimiter.time(); |
| | | int count = rateLimiter.count(); |
| | | |
| | | String combineKey = getCombineKey(rateLimiter, point); |
| | | List<Object> keys = Collections.singletonList(combineKey); |
| | | try |
| | | { |
| | | Long number = redisTemplate.execute(limitScript, keys, count, time); |
| | | if (StringUtils.isNull(number) || number.intValue() > count) |
| | | { |
| | | throw new ServiceException("访é®è¿äºé¢ç¹ï¼è¯·ç¨ååè¯"); |
| | | } |
| | | log.info("éå¶è¯·æ±'{}',å½å请æ±'{}',ç¼åkey'{}'", count, number.intValue(), combineKey); |
| | | } |
| | | catch (ServiceException e) |
| | | { |
| | | throw e; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new RuntimeException("æå¡å¨éæµå¼å¸¸ï¼è¯·ç¨ååè¯"); |
| | | } |
| | | } |
| | | |
| | | public String getCombineKey(RateLimiter rateLimiter, JoinPoint point) |
| | | { |
| | | StringBuffer stringBuffer = new StringBuffer(rateLimiter.key()); |
| | | if (rateLimiter.limitType() == LimitType.IP) |
| | | { |
| | | stringBuffer.append(IpUtils.getIpAddr()).append("-"); |
| | | } |
| | | MethodSignature signature = (MethodSignature) point.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | Class<?> targetClass = method.getDeclaringClass(); |
| | | stringBuffer.append(targetClass.getName()).append("-").append(method.getName()); |
| | | return stringBuffer.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.util.TimeZone; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.EnableAspectJAutoProxy; |
| | | |
| | | /** |
| | | * ç¨åºæ³¨è§£é
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | // 表示éè¿aopæ¡æ¶æ´é²è¯¥ä»£ç对象,AopContextè½å¤è®¿é® |
| | | @EnableAspectJAutoProxy(exposeProxy = true) |
| | | // æå®è¦æ«æçMapperç±»çå
çè·¯å¾ |
| | | @MapperScan("com.jcdm.**.mapper") |
| | | public class ApplicationConfig |
| | | { |
| | | /** |
| | | * æ¶åºé
ç½® |
| | | */ |
| | | @Bean |
| | | public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() |
| | | { |
| | | return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.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 jc |
| | | */ |
| | | @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, "com.jcdm.framework.config.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.jcdm.framework.config; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.Filter; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.sql.DataSource; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; |
| | | import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; |
| | | import com.alibaba.druid.util.Utils; |
| | | import com.jcdm.common.enums.DataSourceType; |
| | | import com.jcdm.common.utils.spring.SpringUtils; |
| | | import com.jcdm.framework.config.properties.DruidProperties; |
| | | import com.jcdm.framework.datasource.DynamicDataSource; |
| | | |
| | | /** |
| | | * druid é
ç½®å¤æ°æ®æº |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class DruidConfig |
| | | { |
| | | @Bean |
| | | @ConfigurationProperties("spring.datasource.druid.master") |
| | | public DataSource masterDataSource(DruidProperties druidProperties) |
| | | { |
| | | DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); |
| | | return druidProperties.dataSource(dataSource); |
| | | } |
| | | |
| | | @Bean |
| | | @ConfigurationProperties("spring.datasource.druid.slave") |
| | | @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") |
| | | public DataSource slaveDataSource(DruidProperties druidProperties) |
| | | { |
| | | DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); |
| | | return druidProperties.dataSource(dataSource); |
| | | } |
| | | |
| | | @Bean(name = "dynamicDataSource") |
| | | @Primary |
| | | public DynamicDataSource dataSource(DataSource masterDataSource) |
| | | { |
| | | Map<Object, Object> targetDataSources = new HashMap<>(); |
| | | targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); |
| | | setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); |
| | | return new DynamicDataSource(masterDataSource, targetDataSources); |
| | | } |
| | | |
| | | /** |
| | | * 设置æ°æ®æº |
| | | * |
| | | * @param targetDataSources å¤éæ°æ®æºéå |
| | | * @param sourceName æ°æ®æºå称 |
| | | * @param beanName beanå称 |
| | | */ |
| | | public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) |
| | | { |
| | | try |
| | | { |
| | | DataSource dataSource = SpringUtils.getBean(beanName); |
| | | targetDataSources.put(sourceName, dataSource); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å»é¤çæ§é¡µé¢åºé¨ç广å |
| | | */ |
| | | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| | | @Bean |
| | | @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") |
| | | public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) |
| | | { |
| | | // è·åwebçæ§é¡µé¢çåæ° |
| | | DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); |
| | | // æåcommon.jsçé
ç½®è·¯å¾ |
| | | String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; |
| | | String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); |
| | | final String filePath = "support/http/resources/js/common.js"; |
| | | // å建filterè¿è¡è¿æ»¤ |
| | | Filter filter = new Filter() |
| | | { |
| | | @Override |
| | | public void init(javax.servlet.FilterConfig filterConfig) throws ServletException |
| | | { |
| | | } |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | chain.doFilter(request, response); |
| | | // éç½®ç¼å²åºï¼ååºå¤´ä¸ä¼è¢«éç½® |
| | | response.resetBuffer(); |
| | | // è·åcommon.js |
| | | String text = Utils.readFromResource(filePath); |
| | | // æ£åæ¿æ¢banner, é¤å»åºé¨ç广åä¿¡æ¯ |
| | | text = text.replaceAll("<a.*?banner\"></a><br/>", ""); |
| | | text = text.replaceAll("powered.*?shrek.wang</a>", ""); |
| | | response.getWriter().write(text); |
| | | } |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | } |
| | | }; |
| | | FilterRegistrationBean registrationBean = new FilterRegistrationBean(); |
| | | registrationBean.setFilter(filter); |
| | | registrationBean.addUrlPatterns(commonJsPattern); |
| | | return registrationBean; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.nio.charset.Charset; |
| | | import org.springframework.data.redis.serializer.RedisSerializer; |
| | | import org.springframework.data.redis.serializer.SerializationException; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONReader; |
| | | import com.alibaba.fastjson2.JSONWriter; |
| | | import com.alibaba.fastjson2.filter.Filter; |
| | | import com.jcdm.common.constant.Constants; |
| | | |
| | | /** |
| | | * Redis使ç¨FastJsonåºåå |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> |
| | | { |
| | | public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); |
| | | |
| | | static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR); |
| | | |
| | | private Class<T> clazz; |
| | | |
| | | public FastJson2JsonRedisSerializer(Class<T> clazz) |
| | | { |
| | | super(); |
| | | this.clazz = clazz; |
| | | } |
| | | |
| | | @Override |
| | | public byte[] serialize(T t) throws SerializationException |
| | | { |
| | | if (t == null) |
| | | { |
| | | return new byte[0]; |
| | | } |
| | | return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET); |
| | | } |
| | | |
| | | @Override |
| | | public T deserialize(byte[] bytes) throws SerializationException |
| | | { |
| | | if (bytes == null || bytes.length <= 0) |
| | | { |
| | | return null; |
| | | } |
| | | String str = new String(bytes, DEFAULT_CHARSET); |
| | | |
| | | return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.DispatcherType; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import com.jcdm.common.filter.RepeatableFilter; |
| | | import com.jcdm.common.filter.XssFilter; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * Filteré
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class FilterConfig |
| | | { |
| | | @Value("${xss.excludes}") |
| | | private String excludes; |
| | | |
| | | @Value("${xss.urlPatterns}") |
| | | private String urlPatterns; |
| | | |
| | | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| | | @Bean |
| | | @ConditionalOnProperty(value = "xss.enabled", havingValue = "true") |
| | | public FilterRegistrationBean xssFilterRegistration() |
| | | { |
| | | FilterRegistrationBean registration = new FilterRegistrationBean(); |
| | | registration.setDispatcherTypes(DispatcherType.REQUEST); |
| | | registration.setFilter(new XssFilter()); |
| | | registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); |
| | | registration.setName("xssFilter"); |
| | | registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); |
| | | Map<String, String> initParameters = new HashMap<String, String>(); |
| | | initParameters.put("excludes", excludes); |
| | | registration.setInitParameters(initParameters); |
| | | return registration; |
| | | } |
| | | |
| | | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| | | @Bean |
| | | public FilterRegistrationBean someFilterRegistration() |
| | | { |
| | | FilterRegistrationBean registration = new FilterRegistrationBean(); |
| | | registration.setFilter(new RepeatableFilter()); |
| | | registration.addUrlPatterns("/*"); |
| | | registration.setName("repeatableFilter"); |
| | | registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE); |
| | | return registration; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.util.Random; |
| | | import com.google.code.kaptcha.text.impl.DefaultTextCreator; |
| | | |
| | | /** |
| | | * éªè¯ç ææ¬çæå¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | 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 (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]); |
| | | } |
| | | } |
| | | suChinese.append("=?@" + result); |
| | | return suChinese.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import javax.sql.DataSource; |
| | | import org.apache.ibatis.io.VFS; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.mybatis.spring.SqlSessionFactoryBean; |
| | | import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.core.io.DefaultResourceLoader; |
| | | import org.springframework.core.io.Resource; |
| | | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
| | | import org.springframework.core.io.support.ResourcePatternResolver; |
| | | import org.springframework.core.type.classreading.CachingMetadataReaderFactory; |
| | | import org.springframework.core.type.classreading.MetadataReader; |
| | | import org.springframework.core.type.classreading.MetadataReaderFactory; |
| | | import org.springframework.util.ClassUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * Mybatisæ¯æ*å¹é
æ«æå
|
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class MyBatisConfig |
| | | { |
| | | @Autowired |
| | | private Environment env; |
| | | |
| | | static final String DEFAULT_RESOURCE_PATTERN = "**/*.class"; |
| | | |
| | | public static String setTypeAliasesPackage(String typeAliasesPackage) |
| | | { |
| | | ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); |
| | | MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); |
| | | List<String> allResult = new ArrayList<String>(); |
| | | try |
| | | { |
| | | for (String aliasesPackage : typeAliasesPackage.split(",")) |
| | | { |
| | | List<String> result = new ArrayList<String>(); |
| | | aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX |
| | | + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN; |
| | | Resource[] resources = resolver.getResources(aliasesPackage); |
| | | if (resources != null && resources.length > 0) |
| | | { |
| | | MetadataReader metadataReader = null; |
| | | for (Resource resource : resources) |
| | | { |
| | | if (resource.isReadable()) |
| | | { |
| | | metadataReader = metadataReaderFactory.getMetadataReader(resource); |
| | | try |
| | | { |
| | | result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); |
| | | } |
| | | catch (ClassNotFoundException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (result.size() > 0) |
| | | { |
| | | HashSet<String> hashResult = new HashSet<String>(result); |
| | | allResult.addAll(hashResult); |
| | | } |
| | | } |
| | | if (allResult.size() > 0) |
| | | { |
| | | typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0])); |
| | | } |
| | | else |
| | | { |
| | | throw new RuntimeException("mybatis typeAliasesPackage è·¯å¾æ«æé误,åæ°typeAliasesPackage:" + typeAliasesPackage + "æªæ¾å°ä»»ä½å
"); |
| | | } |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | return typeAliasesPackage; |
| | | } |
| | | |
| | | public Resource[] resolveMapperLocations(String[] mapperLocations) |
| | | { |
| | | ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); |
| | | List<Resource> resources = new ArrayList<Resource>(); |
| | | if (mapperLocations != null) |
| | | { |
| | | for (String mapperLocation : mapperLocations) |
| | | { |
| | | try |
| | | { |
| | | Resource[] mappers = resourceResolver.getResources(mapperLocation); |
| | | resources.addAll(Arrays.asList(mappers)); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | // ignore |
| | | } |
| | | } |
| | | } |
| | | return resources.toArray(new Resource[resources.size()]); |
| | | } |
| | | |
| | | @Bean |
| | | public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception |
| | | { |
| | | String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage"); |
| | | String mapperLocations = env.getProperty("mybatis.mapperLocations"); |
| | | String configLocation = env.getProperty("mybatis.configLocation"); |
| | | typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage); |
| | | VFS.addImplClass(SpringBootVFS.class); |
| | | |
| | | final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
| | | sessionFactory.setDataSource(dataSource); |
| | | sessionFactory.setTypeAliasesPackage(typeAliasesPackage); |
| | | sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); |
| | | sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); |
| | | return sessionFactory.getObject(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | | import org.springframework.cache.annotation.EnableCaching; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.script.DefaultRedisScript; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | /** |
| | | * redisé
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | //@Configuration |
| | | //@EnableCaching |
| | | public class RedisConfig extends CachingConfigurerSupport |
| | | { |
| | | // @Bean |
| | | @SuppressWarnings(value = { "unchecked", "rawtypes" }) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) |
| | | { |
| | | RedisTemplate<Object, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(connectionFactory); |
| | | |
| | | FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); |
| | | |
| | | // 使ç¨StringRedisSerializeræ¥åºåååååºååredisçkeyå¼ |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setValueSerializer(serializer); |
| | | |
| | | // Hashçkeyä¹éç¨StringRedisSerializerçåºååæ¹å¼ |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | // @Bean |
| | | public DefaultRedisScript<Long> limitScript() |
| | | { |
| | | DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>(); |
| | | redisScript.setScriptText(limitScriptText()); |
| | | redisScript.setResultType(Long.class); |
| | | return redisScript; |
| | | } |
| | | |
| | | /** |
| | | * éæµèæ¬ |
| | | */ |
| | | private String limitScriptText() |
| | | { |
| | | return "local key = KEYS[1]\n" + |
| | | "local count = tonumber(ARGV[1])\n" + |
| | | "local time = tonumber(ARGV[2])\n" + |
| | | "local current = redis.call('get', key);\n" + |
| | | "if current and tonumber(current) > count then\n" + |
| | | " return tonumber(current);\n" + |
| | | "end\n" + |
| | | "current = redis.call('incr', key)\n" + |
| | | "if tonumber(current) == 1 then\n" + |
| | | " redis.call('expire', key, time)\n" + |
| | | "end\n" + |
| | | "return tonumber(current);"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.CacheControl; |
| | | import org.springframework.web.cors.CorsConfiguration; |
| | | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| | | import org.springframework.web.filter.CorsFilter; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | import com.jcdm.common.config.MesConfig; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.framework.interceptor.RepeatSubmitInterceptor; |
| | | |
| | | /** |
| | | * éç¨é
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class ResourcesConfig implements WebMvcConfigurer |
| | | { |
| | | @Autowired |
| | | private RepeatSubmitInterceptor repeatSubmitInterceptor; |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) |
| | | { |
| | | /** æ¬å°æ件ä¸ä¼ è·¯å¾ */ |
| | | registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") |
| | | .addResourceLocations("file:" + MesConfig.getProfile() + "/"); |
| | | |
| | | /** swaggeré
ç½® */ |
| | | registry.addResourceHandler("/swagger-ui/**") |
| | | .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") |
| | | .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic());; |
| | | } |
| | | |
| | | /** |
| | | * èªå®ä¹æ¦æªè§å |
| | | */ |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) |
| | | { |
| | | registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); |
| | | } |
| | | |
| | | /** |
| | | * è·¨åé
ç½® |
| | | */ |
| | | @Bean |
| | | public CorsFilter corsFilter() |
| | | { |
| | | CorsConfiguration config = new CorsConfiguration(); |
| | | config.setAllowCredentials(true); |
| | | // 设置访é®æºå°å |
| | | config.addAllowedOriginPattern("*"); |
| | | // 设置访é®æºè¯·æ±å¤´ |
| | | config.addAllowedHeader("*"); |
| | | // 设置访é®æºè¯·æ±æ¹æ³ |
| | | config.addAllowedMethod("*"); |
| | | // æææ 1800ç§ |
| | | config.setMaxAge(1800L); |
| | | // æ·»å æ å°è·¯å¾ï¼æ¦æªä¸åè¯·æ± |
| | | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| | | source.registerCorsConfiguration("/**", config); |
| | | // è¿åæ°çCorsFilter |
| | | return new CorsFilter(source); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
| | | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
| | | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| | | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| | | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; |
| | | import org.springframework.security.config.http.SessionCreationPolicy; |
| | | import org.springframework.security.core.userdetails.UserDetailsService; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
| | | import org.springframework.security.web.authentication.logout.LogoutFilter; |
| | | import org.springframework.web.filter.CorsFilter; |
| | | import com.jcdm.framework.config.properties.PermitAllUrlProperties; |
| | | import com.jcdm.framework.security.filter.JwtAuthenticationTokenFilter; |
| | | import com.jcdm.framework.security.handle.AuthenticationEntryPointImpl; |
| | | import com.jcdm.framework.security.handle.LogoutSuccessHandlerImpl; |
| | | |
| | | /** |
| | | * spring securityé
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) |
| | | public class SecurityConfig extends WebSecurityConfigurerAdapter |
| | | { |
| | | /** |
| | | * èªå®ä¹ç¨æ·è®¤è¯é»è¾ |
| | | */ |
| | | @Autowired |
| | | private UserDetailsService userDetailsService; |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥å¤çç±» |
| | | */ |
| | | @Autowired |
| | | private AuthenticationEntryPointImpl unauthorizedHandler; |
| | | |
| | | /** |
| | | * éåºå¤çç±» |
| | | */ |
| | | @Autowired |
| | | private LogoutSuccessHandlerImpl logoutSuccessHandler; |
| | | |
| | | /** |
| | | * token认è¯è¿æ»¤å¨ |
| | | */ |
| | | @Autowired |
| | | private JwtAuthenticationTokenFilter authenticationTokenFilter; |
| | | |
| | | /** |
| | | * è·¨åè¿æ»¤å¨ |
| | | */ |
| | | @Autowired |
| | | private CorsFilter corsFilter; |
| | | |
| | | /** |
| | | * å
许å¿å访é®çå°å |
| | | */ |
| | | @Autowired |
| | | private PermitAllUrlProperties permitAllUrl; |
| | | |
| | | /** |
| | | * è§£å³ æ æ³ç´æ¥æ³¨å
¥ AuthenticationManager |
| | | * |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Bean |
| | | @Override |
| | | public AuthenticationManager authenticationManagerBean() throws Exception |
| | | { |
| | | return super.authenticationManagerBean(); |
| | | } |
| | | |
| | | /** |
| | | * anyRequest | å¹é
ææ请æ±è·¯å¾ |
| | | * access | SpringEl表达å¼ç»æ为trueæ¶å¯ä»¥è®¿é® |
| | | * anonymous | å¿åå¯ä»¥è®¿é® |
| | | * denyAll | ç¨æ·ä¸è½è®¿é® |
| | | * fullyAuthenticated | ç¨æ·å®å
¨è®¤è¯å¯ä»¥è®¿é®ï¼éremember-meä¸èªå¨ç»å½ï¼ |
| | | * hasAnyAuthority | å¦ææåæ°ï¼åæ°è¡¨ç¤ºæéï¼åå
¶ä¸ä»»ä½ä¸ä¸ªæéå¯ä»¥è®¿é® |
| | | * hasAnyRole | å¦ææåæ°ï¼åæ°è¡¨ç¤ºè§è²ï¼åå
¶ä¸ä»»ä½ä¸ä¸ªè§è²å¯ä»¥è®¿é® |
| | | * hasAuthority | å¦ææåæ°ï¼åæ°è¡¨ç¤ºæéï¼åå
¶æéå¯ä»¥è®¿é® |
| | | * hasIpAddress | å¦ææåæ°ï¼åæ°è¡¨ç¤ºIPå°åï¼å¦æç¨æ·IPååæ°å¹é
ï¼åå¯ä»¥è®¿é® |
| | | * hasRole | å¦ææåæ°ï¼åæ°è¡¨ç¤ºè§è²ï¼åå
¶è§è²å¯ä»¥è®¿é® |
| | | * permitAll | ç¨æ·å¯ä»¥ä»»æè®¿é® |
| | | * rememberMe | å
许éè¿remember-meç»å½çç¨æ·è®¿é® |
| | | * authenticated | ç¨æ·ç»å½åå¯è®¿é® |
| | | */ |
| | | @Override |
| | | protected void configure(HttpSecurity httpSecurity) throws Exception |
| | | { |
| | | // 注解æ è®°å
许å¿å访é®çurl |
| | | ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests(); |
| | | permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll()); |
| | | |
| | | httpSecurity |
| | | // CSRFç¦ç¨ï¼å 为ä¸ä½¿ç¨session |
| | | .csrf().disable() |
| | | // ç¦ç¨HTTPååºæ 头 |
| | | .headers().cacheControl().disable().and() |
| | | // 认è¯å¤±è´¥å¤çç±» |
| | | .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() |
| | | // åºäºtokenï¼æ以ä¸éè¦session |
| | | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() |
| | | // è¿æ»¤è¯·æ± |
| | | .authorizeRequests() |
| | | // 对äºç»å½login 注åregister éªè¯ç captchaImage å
许å¿åè®¿é® |
| | | .antMatchers("/login", "/register", "/captchaImage","/websocket/**","/postWebsocket/**").permitAll() |
| | | // éæèµæºï¼å¯å¿åè®¿é® |
| | | .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() |
| | | .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() |
| | | // é¤ä¸é¢å¤çææ请æ±å
¨é¨éè¦é´æè®¤è¯ |
| | | .anyRequest().authenticated() |
| | | .and() |
| | | .headers().frameOptions().disable(); |
| | | // æ·»å Logout filter |
| | | httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); |
| | | // æ·»å JWT filter |
| | | httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); |
| | | // æ·»å CORS filter |
| | | httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class); |
| | | httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); |
| | | } |
| | | |
| | | /** |
| | | * 强æ£ååå¸å å¯å®ç° |
| | | */ |
| | | @Bean |
| | | public BCryptPasswordEncoder bCryptPasswordEncoder() |
| | | { |
| | | return new BCryptPasswordEncoder(); |
| | | } |
| | | |
| | | /** |
| | | * 身份认è¯æ¥å£ |
| | | */ |
| | | @Override |
| | | protected void configure(AuthenticationManagerBuilder auth) throws Exception |
| | | { |
| | | auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.stereotype.Component; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | |
| | | /** |
| | | * æå¡ç¸å
³é
ç½® |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public class ServerConfig |
| | | { |
| | | /** |
| | | * è·åå®æ´ç请æ±è·¯å¾ï¼å
æ¬ï¼ååï¼ç«¯å£ï¼ä¸ä¸æ访é®è·¯å¾ |
| | | * |
| | | * @return æå¡å°å |
| | | */ |
| | | public String getUrl() |
| | | { |
| | | HttpServletRequest request = ServletUtils.getRequest(); |
| | | return getDomain(request); |
| | | } |
| | | |
| | | public static String getDomain(HttpServletRequest request) |
| | | { |
| | | StringBuffer url = request.getRequestURL(); |
| | | String contextPath = request.getServletContext().getContextPath(); |
| | | return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config; |
| | | |
| | | import com.jcdm.common.utils.Threads; |
| | | import org.apache.commons.lang3.concurrent.BasicThreadFactory; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ScheduledThreadPoolExecutor; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | |
| | | /** |
| | | * 线ç¨æ± é
ç½® |
| | | * |
| | | * @author jc |
| | | **/ |
| | | @Configuration |
| | | public class ThreadPoolConfig |
| | | { |
| | | // æ ¸å¿çº¿ç¨æ± å¤§å° |
| | | private int corePoolSize = 50; |
| | | |
| | | // æ大å¯å建ç线ç¨æ° |
| | | private int maxPoolSize = 200; |
| | | |
| | | // éåæ大é¿åº¦ |
| | | private int queueCapacity = 1000; |
| | | |
| | | // 线ç¨æ± ç»´æ¤çº¿ç¨æå
许ç空é²æ¶é´ |
| | | private int keepAliveSeconds = 300; |
| | | |
| | | @Bean(name = "threadPoolTaskExecutor") |
| | | public ThreadPoolTaskExecutor threadPoolTaskExecutor() |
| | | { |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | executor.setMaxPoolSize(maxPoolSize); |
| | | executor.setCorePoolSize(corePoolSize); |
| | | executor.setQueueCapacity(queueCapacity); |
| | | executor.setKeepAliveSeconds(keepAliveSeconds); |
| | | // 线ç¨æ± 对æç»ä»»å¡(æ 线ç¨å¯ç¨)çå¤ççç¥ |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | return executor; |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å¨ææ§æå®æ¶ä»»å¡ |
| | | */ |
| | | @Bean(name = "scheduledExecutorService") |
| | | protected ScheduledExecutorService scheduledExecutorService() |
| | | { |
| | | return new ScheduledThreadPoolExecutor(corePoolSize, |
| | | new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(), |
| | | new ThreadPoolExecutor.CallerRunsPolicy()) |
| | | { |
| | | @Override |
| | | protected void afterExecute(Runnable r, Throwable t) |
| | | { |
| | | super.afterExecute(r, t); |
| | | Threads.printException(r, t); |
| | | } |
| | | }; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config.properties; |
| | | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | |
| | | /** |
| | | * druid é
ç½®å±æ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class DruidProperties |
| | | { |
| | | @Value("${spring.datasource.druid.initialSize}") |
| | | private int initialSize; |
| | | |
| | | @Value("${spring.datasource.druid.minIdle}") |
| | | private int minIdle; |
| | | |
| | | @Value("${spring.datasource.druid.maxActive}") |
| | | private int maxActive; |
| | | |
| | | @Value("${spring.datasource.druid.maxWait}") |
| | | private int maxWait; |
| | | |
| | | @Value("${spring.datasource.druid.connectTimeout}") |
| | | private int connectTimeout; |
| | | |
| | | @Value("${spring.datasource.druid.socketTimeout}") |
| | | private int socketTimeout; |
| | | |
| | | @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}") |
| | | private int timeBetweenEvictionRunsMillis; |
| | | |
| | | @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}") |
| | | private int minEvictableIdleTimeMillis; |
| | | |
| | | @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}") |
| | | private int maxEvictableIdleTimeMillis; |
| | | |
| | | @Value("${spring.datasource.druid.validationQuery}") |
| | | private String validationQuery; |
| | | |
| | | @Value("${spring.datasource.druid.testWhileIdle}") |
| | | private boolean testWhileIdle; |
| | | |
| | | @Value("${spring.datasource.druid.testOnBorrow}") |
| | | private boolean testOnBorrow; |
| | | |
| | | @Value("${spring.datasource.druid.testOnReturn}") |
| | | private boolean testOnReturn; |
| | | |
| | | public DruidDataSource dataSource(DruidDataSource datasource) |
| | | { |
| | | /** é
ç½®åå§å大å°ãæå°ãæ大 */ |
| | | datasource.setInitialSize(initialSize); |
| | | datasource.setMaxActive(maxActive); |
| | | datasource.setMinIdle(minIdle); |
| | | |
| | | /** é
ç½®è·åè¿æ¥çå¾
è¶
æ¶çæ¶é´ */ |
| | | datasource.setMaxWait(maxWait); |
| | | |
| | | /** é
置驱å¨è¿æ¥è¶
æ¶æ¶é´ï¼æ£æµæ°æ®åºå»ºç«è¿æ¥çè¶
æ¶æ¶é´ï¼åä½æ¯æ¯«ç§ */ |
| | | datasource.setConnectTimeout(connectTimeout); |
| | | |
| | | /** é
ç½®ç½ç»è¶
æ¶æ¶é´ï¼çå¾
æ°æ®åºæä½å®æçç½ç»è¶
æ¶æ¶é´ï¼åä½æ¯æ¯«ç§ */ |
| | | datasource.setSocketTimeout(socketTimeout); |
| | | |
| | | /** é
ç½®é´éå¤ä¹
æè¿è¡ä¸æ¬¡æ£æµï¼æ£æµéè¦å
³éç空é²è¿æ¥ï¼åä½æ¯æ¯«ç§ */ |
| | | datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
| | | |
| | | /** é
ç½®ä¸ä¸ªè¿æ¥å¨æ± ä¸æå°ãæ大çåçæ¶é´ï¼åä½æ¯æ¯«ç§ */ |
| | | datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
| | | datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); |
| | | |
| | | /** |
| | | * ç¨æ¥æ£æµè¿æ¥æ¯å¦ææçsqlï¼è¦æ±æ¯ä¸ä¸ªæ¥è¯¢è¯å¥ï¼å¸¸ç¨select 'x'ãå¦ævalidationQuery为nullï¼testOnBorrowãtestOnReturnãtestWhileIdleé½ä¸ä¼èµ·ä½ç¨ã |
| | | */ |
| | | datasource.setValidationQuery(validationQuery); |
| | | /** 建议é
置为trueï¼ä¸å½±åæ§è½ï¼å¹¶ä¸ä¿è¯å®å
¨æ§ãç³è¯·è¿æ¥çæ¶åæ£æµï¼å¦æ空é²æ¶é´å¤§äºtimeBetweenEvictionRunsMillisï¼æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææã */ |
| | | datasource.setTestWhileIdle(testWhileIdle); |
| | | /** ç³è¯·è¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼åäºè¿ä¸ªé
ç½®ä¼éä½æ§è½ã */ |
| | | datasource.setTestOnBorrow(testOnBorrow); |
| | | /** å½è¿è¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼åäºè¿ä¸ªé
ç½®ä¼éä½æ§è½ã */ |
| | | datasource.setTestOnReturn(testOnReturn); |
| | | return datasource; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.config.properties; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.regex.Pattern; |
| | | import org.apache.commons.lang3.RegExUtils; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.annotation.AnnotationUtils; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
| | | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
| | | import com.jcdm.common.annotation.Anonymous; |
| | | |
| | | /** |
| | | * 设置Anonymous注解å
许å¿å访é®çurl |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Configuration |
| | | public class PermitAllUrlProperties implements InitializingBean, ApplicationContextAware |
| | | { |
| | | private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}"); |
| | | |
| | | private ApplicationContext applicationContext; |
| | | |
| | | private List<String> urls = new ArrayList<>(); |
| | | |
| | | public String ASTERISK = "*"; |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() |
| | | { |
| | | RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); |
| | | Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); |
| | | |
| | | map.keySet().forEach(info -> { |
| | | HandlerMethod handlerMethod = map.get(info); |
| | | |
| | | // è·åæ¹æ³ä¸è¾¹ç注解 æ¿ä»£path variable 为 * |
| | | Anonymous method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Anonymous.class); |
| | | Optional.ofNullable(method).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns()) |
| | | .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); |
| | | |
| | | // è·åç±»ä¸è¾¹ç注解, æ¿ä»£path variable 为 * |
| | | Anonymous controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Anonymous.class); |
| | | Optional.ofNullable(controller).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns()) |
| | | .forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void setApplicationContext(ApplicationContext context) throws BeansException |
| | | { |
| | | this.applicationContext = context; |
| | | } |
| | | |
| | | public List<String> getUrls() |
| | | { |
| | | return urls; |
| | | } |
| | | |
| | | public void setUrls(List<String> urls) |
| | | { |
| | | this.urls = urls; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.datasource; |
| | | |
| | | import java.util.Map; |
| | | import javax.sql.DataSource; |
| | | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; |
| | | |
| | | /** |
| | | * å¨ææ°æ®æº |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class DynamicDataSource extends AbstractRoutingDataSource |
| | | { |
| | | public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) |
| | | { |
| | | super.setDefaultTargetDataSource(defaultTargetDataSource); |
| | | super.setTargetDataSources(targetDataSources); |
| | | super.afterPropertiesSet(); |
| | | } |
| | | |
| | | @Override |
| | | protected Object determineCurrentLookupKey() |
| | | { |
| | | return DynamicDataSourceContextHolder.getDataSourceType(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.datasource; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * æ°æ®æºåæ¢å¤ç |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class DynamicDataSourceContextHolder |
| | | { |
| | | public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class); |
| | | |
| | | /** |
| | | * 使ç¨ThreadLocalç»´æ¤åéï¼ThreadLocal为æ¯ä¸ªä½¿ç¨è¯¥åéç线ç¨æä¾ç¬ç«çåéå¯æ¬ï¼ |
| | | * æ以æ¯ä¸ä¸ªçº¿ç¨é½å¯ä»¥ç¬ç«å°æ¹åèªå·±çå¯æ¬ï¼èä¸ä¼å½±åå
¶å®çº¿ç¨æ对åºçå¯æ¬ã |
| | | */ |
| | | private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>(); |
| | | |
| | | /** |
| | | * 设置æ°æ®æºçåé |
| | | */ |
| | | public static void setDataSourceType(String dsType) |
| | | { |
| | | log.info("åæ¢å°{}æ°æ®æº", dsType); |
| | | CONTEXT_HOLDER.set(dsType); |
| | | } |
| | | |
| | | /** |
| | | * è·å¾æ°æ®æºçåé |
| | | */ |
| | | public static String getDataSourceType() |
| | | { |
| | | return CONTEXT_HOLDER.get(); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空æ°æ®æºåé |
| | | */ |
| | | public static void clearDataSourceType() |
| | | { |
| | | CONTEXT_HOLDER.remove(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.interceptor; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.jcdm.common.annotation.RepeatSubmit; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | |
| | | /** |
| | | * é²æ¢éå¤æ交æ¦æªå¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public abstract class RepeatSubmitInterceptor implements HandlerInterceptor |
| | | { |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception |
| | | { |
| | | if (handler instanceof HandlerMethod) |
| | | { |
| | | HandlerMethod handlerMethod = (HandlerMethod) handler; |
| | | Method method = handlerMethod.getMethod(); |
| | | RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); |
| | | if (annotation != null) |
| | | { |
| | | if (this.isRepeatSubmit(request, annotation)) |
| | | { |
| | | AjaxResult ajaxResult = AjaxResult.error(annotation.message()); |
| | | ServletUtils.renderString(response, JSON.toJSONString(ajaxResult)); |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éªè¯æ¯å¦éå¤æ交ç±åç±»å®ç°å
·ä½çé²éå¤æ交çè§å |
| | | * |
| | | * @param request 请æ±ä¿¡æ¯ |
| | | * @param annotation é²éå¤æ³¨è§£åæ° |
| | | * @return ç»æ |
| | | * @throws Exception |
| | | */ |
| | | public abstract boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.interceptor.impl; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.jcdm.common.annotation.RepeatSubmit; |
| | | import com.jcdm.common.constant.CacheConstants; |
| | | import com.jcdm.common.core.redis.RedisCache; |
| | | import com.jcdm.common.filter.RepeatedlyRequestWrapper; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.http.HttpHelper; |
| | | import com.jcdm.framework.interceptor.RepeatSubmitInterceptor; |
| | | |
| | | /** |
| | | * å¤æ请æ±urlåæ°æ®æ¯å¦åä¸ä¸æ¬¡ç¸åï¼ |
| | | * å¦æåä¸æ¬¡ç¸åï¼åæ¯éå¤æ交表åã æææ¶é´ä¸º10ç§å
ã |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
| | | { |
| | | public final String REPEAT_PARAMS = "repeatParams"; |
| | | |
| | | public final String REPEAT_TIME = "repeatTime"; |
| | | |
| | | // 令çèªå®ä¹æ è¯ |
| | | @Value("${token.header}") |
| | | private String header; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation) |
| | | { |
| | | String nowParams = ""; |
| | | if (request instanceof RepeatedlyRequestWrapper) |
| | | { |
| | | RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; |
| | | nowParams = HttpHelper.getBodyString(repeatedlyRequest); |
| | | } |
| | | |
| | | // bodyåæ°ä¸ºç©ºï¼è·åParameterçæ°æ® |
| | | if (StringUtils.isEmpty(nowParams)) |
| | | { |
| | | nowParams = JSON.toJSONString(request.getParameterMap()); |
| | | } |
| | | Map<String, Object> nowDataMap = new HashMap<String, Object>(); |
| | | nowDataMap.put(REPEAT_PARAMS, nowParams); |
| | | nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); |
| | | |
| | | // 请æ±å°åï¼ä½ä¸ºåæ¾cacheçkeyå¼ï¼ |
| | | String url = request.getRequestURI(); |
| | | |
| | | // å¯ä¸å¼ï¼æ²¡ææ¶æ¯å¤´å使ç¨è¯·æ±å°åï¼ |
| | | String submitKey = StringUtils.trimToEmpty(request.getHeader(header)); |
| | | |
| | | // å¯ä¸æ è¯ï¼æå®key + url + æ¶æ¯å¤´ï¼ |
| | | String cacheRepeatKey = CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey; |
| | | |
| | | Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); |
| | | if (sessionObj != null) |
| | | { |
| | | Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; |
| | | if (sessionMap.containsKey(url)) |
| | | { |
| | | Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url); |
| | | if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap, annotation.interval())) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> cacheMap = new HashMap<String, Object>(); |
| | | cacheMap.put(url, nowDataMap); |
| | | redisCache.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * å¤æåæ°æ¯å¦ç¸å |
| | | */ |
| | | private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) |
| | | { |
| | | String nowParams = (String) nowMap.get(REPEAT_PARAMS); |
| | | String preParams = (String) preMap.get(REPEAT_PARAMS); |
| | | return nowParams.equals(preParams); |
| | | } |
| | | |
| | | /** |
| | | * å¤æ两次é´éæ¶é´ |
| | | */ |
| | | private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap, int interval) |
| | | { |
| | | long time1 = (Long) nowMap.get(REPEAT_TIME); |
| | | long time2 = (Long) preMap.get(REPEAT_TIME); |
| | | if ((time1 - time2) < interval) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.manager; |
| | | |
| | | import java.util.TimerTask; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.TimeUnit; |
| | | import com.jcdm.common.utils.Threads; |
| | | import com.jcdm.common.utils.spring.SpringUtils; |
| | | |
| | | /** |
| | | * å¼æ¥ä»»å¡ç®¡çå¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class AsyncManager |
| | | { |
| | | /** |
| | | * æä½å»¶è¿10æ¯«ç§ |
| | | */ |
| | | private final int OPERATE_DELAY_TIME = 10; |
| | | |
| | | /** |
| | | * å¼æ¥æä½ä»»å¡è°åº¦çº¿ç¨æ± |
| | | */ |
| | | private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService"); |
| | | |
| | | /** |
| | | * åä¾æ¨¡å¼ |
| | | */ |
| | | private AsyncManager(){} |
| | | |
| | | private static AsyncManager me = new AsyncManager(); |
| | | |
| | | public static AsyncManager me() |
| | | { |
| | | return me; |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡ä»»å¡ |
| | | * |
| | | * @param task ä»»å¡ |
| | | */ |
| | | public void execute(TimerTask task) |
| | | { |
| | | executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | /** |
| | | * åæ¢ä»»å¡çº¿ç¨æ± |
| | | */ |
| | | public void shutdown() |
| | | { |
| | | Threads.shutdownAndAwaitTermination(executor); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.manager; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import javax.annotation.PreDestroy; |
| | | |
| | | /** |
| | | * ç¡®ä¿åºç¨éåºæ¶è½å
³éåå°çº¿ç¨ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public class ShutdownManager |
| | | { |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | |
| | | @PreDestroy |
| | | public void destroy() |
| | | { |
| | | shutdownAsyncManager(); |
| | | } |
| | | |
| | | /** |
| | | * åæ¢å¼æ¥æ§è¡ä»»å¡ |
| | | */ |
| | | private void shutdownAsyncManager() |
| | | { |
| | | try |
| | | { |
| | | logger.info("====å
³éåå°ä»»å¡ä»»å¡çº¿ç¨æ± ===="); |
| | | AsyncManager.me().shutdown(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.manager.factory; |
| | | |
| | | import java.util.TimerTask; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.jcdm.common.constant.Constants; |
| | | import com.jcdm.common.utils.LogUtils; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.common.utils.ip.AddressUtils; |
| | | import com.jcdm.common.utils.ip.IpUtils; |
| | | import com.jcdm.common.utils.spring.SpringUtils; |
| | | import com.jcdm.system.domain.SysLogininfor; |
| | | import com.jcdm.system.domain.SysOperLog; |
| | | import com.jcdm.system.service.ISysLogininforService; |
| | | import com.jcdm.system.service.ISysOperLogService; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | |
| | | /** |
| | | * å¼æ¥å·¥åï¼äº§çä»»å¡ç¨ï¼ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class AsyncFactory |
| | | { |
| | | private static final Logger sys_user_logger = LoggerFactory.getLogger("sys-user"); |
| | | |
| | | /** |
| | | * è®°å½ç»å½ä¿¡æ¯ |
| | | * |
| | | * @param username ç¨æ·å |
| | | * @param status ç¶æ |
| | | * @param message æ¶æ¯ |
| | | * @param args å表 |
| | | * @return ä»»å¡task |
| | | */ |
| | | public static TimerTask recordLogininfor(final String username, final String status, final String message, |
| | | final Object... args) |
| | | { |
| | | final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); |
| | | final String ip = IpUtils.getIpAddr(); |
| | | return new TimerTask() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | String address = AddressUtils.getRealAddressByIP(ip); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(LogUtils.getBlock(ip)); |
| | | s.append(address); |
| | | s.append(LogUtils.getBlock(username)); |
| | | s.append(LogUtils.getBlock(status)); |
| | | s.append(LogUtils.getBlock(message)); |
| | | // æå°ä¿¡æ¯å°æ¥å¿ |
| | | sys_user_logger.info(s.toString(), args); |
| | | // è·å客æ·ç«¯æä½ç³»ç» |
| | | String os = userAgent.getOperatingSystem().getName(); |
| | | // è·å客æ·ç«¯æµè§å¨ |
| | | String browser = userAgent.getBrowser().getName(); |
| | | // å°è£
对象 |
| | | SysLogininfor logininfor = new SysLogininfor(); |
| | | logininfor.setUserName(username); |
| | | logininfor.setIpaddr(ip); |
| | | logininfor.setLoginLocation(address); |
| | | logininfor.setBrowser(browser); |
| | | logininfor.setOs(os); |
| | | logininfor.setMsg(message); |
| | | // æ¥å¿ç¶æ |
| | | if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) |
| | | { |
| | | logininfor.setStatus(Constants.SUCCESS); |
| | | } |
| | | else if (Constants.LOGIN_FAIL.equals(status)) |
| | | { |
| | | logininfor.setStatus(Constants.FAIL); |
| | | } |
| | | // æå
¥æ°æ® |
| | | SpringUtils.getBean(ISysLogininforService.class).insertLogininfor(logininfor); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½ |
| | | * |
| | | * @param operLog æä½æ¥å¿ä¿¡æ¯ |
| | | * @return ä»»å¡task |
| | | */ |
| | | public static TimerTask recordOper(final SysOperLog operLog) |
| | | { |
| | | return new TimerTask() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | // è¿ç¨æ¥è¯¢æä½å°ç¹ |
| | | operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); |
| | | SpringUtils.getBean(ISysOperLogService.class).insertOperlog(operLog); |
| | | } |
| | | }; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.security.context; |
| | | |
| | | import org.springframework.security.core.Authentication; |
| | | |
| | | /** |
| | | * 身份éªè¯ä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class AuthenticationContextHolder |
| | | { |
| | | private static final ThreadLocal<Authentication> contextHolder = new ThreadLocal<>(); |
| | | |
| | | public static Authentication getContext() |
| | | { |
| | | return contextHolder.get(); |
| | | } |
| | | |
| | | public static void setContext(Authentication context) |
| | | { |
| | | contextHolder.set(context); |
| | | } |
| | | |
| | | public static void clearContext() |
| | | { |
| | | contextHolder.remove(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.security.context; |
| | | |
| | | import org.springframework.web.context.request.RequestAttributes; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import com.jcdm.common.core.text.Convert; |
| | | |
| | | /** |
| | | * æéä¿¡æ¯ |
| | | * |
| | | * @author jc |
| | | */ |
| | | public class PermissionContextHolder |
| | | { |
| | | private static final String PERMISSION_CONTEXT_ATTRIBUTES = "PERMISSION_CONTEXT"; |
| | | |
| | | public static void setContext(String permission) |
| | | { |
| | | RequestContextHolder.currentRequestAttributes().setAttribute(PERMISSION_CONTEXT_ATTRIBUTES, permission, |
| | | RequestAttributes.SCOPE_REQUEST); |
| | | } |
| | | |
| | | public static String getContext() |
| | | { |
| | | return Convert.toStr(RequestContextHolder.currentRequestAttributes().getAttribute(PERMISSION_CONTEXT_ATTRIBUTES, |
| | | RequestAttributes.SCOPE_REQUEST)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.security.filter; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.filter.OncePerRequestFilter; |
| | | import com.jcdm.common.core.domain.model.LoginUser; |
| | | import com.jcdm.common.utils.SecurityUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | import com.jcdm.framework.web.service.TokenService; |
| | | |
| | | /** |
| | | * tokenè¿æ»¤å¨ éªè¯tokenæææ§ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public class JwtAuthenticationTokenFilter extends OncePerRequestFilter |
| | | { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| | | throws ServletException, IOException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) |
| | | { |
| | | tokenService.verifyToken(loginUser); |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); |
| | | authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); |
| | | SecurityContextHolder.getContext().setAuthentication(authenticationToken); |
| | | } |
| | | chain.doFilter(request, response); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.framework.security.handle; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.security.core.AuthenticationException; |
| | | import org.springframework.security.web.AuthenticationEntryPoint; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.jcdm.common.constant.HttpStatus; |
| | | import com.jcdm.common.core.domain.AjaxResult; |
| | | import com.jcdm.common.utils.ServletUtils; |
| | | import com.jcdm.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥å¤çç±» è¿åæªææ |
| | | * |
| | | * @author jc |
| | | */ |
| | | @Component |
| | | public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable |
| | | { |
| | | private static final long serialVersionUID = -8970718410437077606L; |
| | | |
| | | @Override |
| | | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) |
| | | throws IOException |
| | | { |
| | | int code = HttpStatus.UNAUTHORIZED; |
| | | String msg = StringUtils.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); |
| | | } |
| | | } |
jcdm-framework/src/main/java/com/jcdm/framework/security/handle/LogoutSuccessHandlerImpl.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/Server.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/server/Cpu.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/server/Jvm.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/server/Mem.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/server/Sys.java
jcdm-framework/src/main/java/com/jcdm/framework/web/domain/server/SysFile.java
jcdm-framework/src/main/java/com/jcdm/framework/web/exception/GlobalExceptionHandler.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/PermissionService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/SysLoginService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/SysPasswordService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/SysPermissionService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/SysRegisterService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/TokenService.java
jcdm-framework/src/main/java/com/jcdm/framework/web/service/UserDetailsServiceImpl.java
jcdm-framework/src/main/java/com/jcdm/framework/websocket/PostController.java
jcdm-framework/src/main/java/com/jcdm/framework/websocket/SemaphoreUtils.java
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketConfig.java
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketServer.java
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketUsers.java
jcdm-generator/pom.xml
jcdm-generator/src/main/java/com/jcdm/generator/config/GenConfig.java
jcdm-generator/src/main/java/com/jcdm/generator/controller/GenController.java
jcdm-generator/src/main/java/com/jcdm/generator/domain/GenTable.java
jcdm-generator/src/main/java/com/jcdm/generator/domain/GenTableColumn.java
jcdm-generator/src/main/java/com/jcdm/generator/mapper/GenTableColumnMapper.java
jcdm-generator/src/main/java/com/jcdm/generator/mapper/GenTableMapper.java
jcdm-generator/src/main/java/com/jcdm/generator/service/GenTableColumnServiceImpl.java
jcdm-generator/src/main/java/com/jcdm/generator/service/GenTableServiceImpl.java
jcdm-generator/src/main/java/com/jcdm/generator/service/IGenTableColumnService.java
jcdm-generator/src/main/java/com/jcdm/generator/service/IGenTableService.java
jcdm-generator/src/main/java/com/jcdm/generator/util/GenUtils.java
jcdm-generator/src/main/java/com/jcdm/generator/util/VelocityInitializer.java
jcdm-generator/src/main/java/com/jcdm/generator/util/VelocityUtils.java
jcdm-generator/src/main/resources/generator.yml
jcdm-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
jcdm-generator/src/main/resources/mapper/generator/GenTableMapper.xml
jcdm-generator/src/main/resources/vm/java/controller.java.vm
jcdm-generator/src/main/resources/vm/java/domain.java.vm
jcdm-generator/src/main/resources/vm/java/mapper.java.vm
jcdm-generator/src/main/resources/vm/java/service.java.vm
jcdm-generator/src/main/resources/vm/java/serviceImpl.java.vm
jcdm-generator/src/main/resources/vm/java/sub-domain.java.vm
jcdm-generator/src/main/resources/vm/js/api.js.vm
jcdm-generator/src/main/resources/vm/sql/sql.vm
jcdm-generator/src/main/resources/vm/vue/index-tree.vue.vm
jcdm-generator/src/main/resources/vm/vue/index.vue.vm
jcdm-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm
jcdm-generator/src/main/resources/vm/vue/v3/index.vue.vm
jcdm-generator/src/main/resources/vm/xml/mapper.xml.vm
jcdm-main/pom.xml
jcdm-main/src/main/java/com/jcdm/main/bs/beatSetting/controller/BsBeatSettingController.java
jcdm-main/src/main/java/com/jcdm/main/bs/beatSetting/domain/BsBeatSetting.java
jcdm-main/src/main/java/com/jcdm/main/bs/beatSetting/mapper/BsBeatSettingMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/beatSetting/service/IBsBeatSettingService.java
jcdm-main/src/main/java/com/jcdm/main/bs/beatSetting/service/impl/BsBeatSettingServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/formula/controller/BsFormulaInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/formula/domain/BsFormulaInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/formula/mapper/BsFormulaInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/formula/service/IBsFormulaInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/formula/service/impl/BsFormulaInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/controller/BsFormulaChildInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/domain/BsFormulaChildInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/mapper/BsFormulaChildInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/IBsFormulaChildInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/lineInfo/controller/BsLineInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/lineInfo/domain/BsLineInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/lineInfo/mapper/BsLineInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/lineInfo/service/IBsLineInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/lineInfo/service/impl/BsLineInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/material/controller/BsMaterialInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/material/domain/BsMaterialInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/material/mapper/BsMaterialInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/material/service/IBsMaterialInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/material/service/impl/BsMaterialInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/processFile/controller/BsProcessFileController.java
jcdm-main/src/main/java/com/jcdm/main/bs/processFile/domain/BsProcessFile.java
jcdm-main/src/main/java/com/jcdm/main/bs/processFile/mapper/BsProcessFileMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/processFile/service/IBsProcessFileService.java
jcdm-main/src/main/java/com/jcdm/main/bs/processFile/service/impl/BsProcessFileServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/processes/controller/BsProcessesInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/processes/domain/BsProcessesInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/processes/mapper/BsProcessesInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/processes/service/IBsProcessesInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/processes/service/impl/BsProcessesInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBom/controller/BsProductBomInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBom/domain/BsProductBomInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBom/mapper/BsProductBomInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBom/service/IBsProductBomInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBom/service/impl/BsProductBomInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBomChild/controller/BsProductBomChildInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBomChild/domain/BsProductBomChildInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBomChild/mapper/BsProductBomChildInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBomChild/service/IBsProductBomChildInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/productBomChild/service/impl/BsProductBomChildInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRoute/controller/BsTechnologyRouteInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRoute/domain/BsTechnologyRouteInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRoute/mapper/BsTechnologyRouteInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRoute/service/IBsTechnologyRouteInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRoute/service/impl/BsTechnologyRouteInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRouteChild/controller/BsTechnologyRouteChildInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRouteChild/domain/BsTechnologyRouteChildInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRouteChild/mapper/BsTechnologyRouteChildInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRouteChild/service/IBsTechnologyRouteChildInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/technologyRouteChild/service/impl/BsTechnologyRouteChildInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/bs/workshop/controller/BsWorkshopInfoController.java
jcdm-main/src/main/java/com/jcdm/main/bs/workshop/domain/BsWorkshopInfo.java
jcdm-main/src/main/java/com/jcdm/main/bs/workshop/mapper/BsWorkshopInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/bs/workshop/service/IBsWorkshopInfoService.java
jcdm-main/src/main/java/com/jcdm/main/bs/workshop/service/impl/BsWorkshopInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/da/collectionParamConf/controller/DaCollectionParamConfController.java
jcdm-main/src/main/java/com/jcdm/main/da/collectionParamConf/domain/DaCollectionParamConf.java
jcdm-main/src/main/java/com/jcdm/main/da/collectionParamConf/mapper/DaCollectionParamConfMapper.java
jcdm-main/src/main/java/com/jcdm/main/da/collectionParamConf/service/IDaCollectionParamConfService.java
jcdm-main/src/main/java/com/jcdm/main/da/collectionParamConf/service/impl/DaCollectionParamConfServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/domain/DaOpcuaConfig.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/domain/NodeEntity.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/BeanUtils.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/Properties.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/mapper/DaOpcuaConfigMapper.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/service/IDaOpcuaConfigService.java
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/service/impl/DaOpcuaConfigServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/controller/DaParamCollectionController.java
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/domain/DaParamCollection.java
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/mapper/DaParamCollectionMapper.java
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/IDaParamCollectionService.java
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/common/Constants.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/controller/DaPassingStationCollectionController.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/domain/DaPassingStationCollection.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/mapper/DaPassingStationCollectionMapper.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/service/IDaPassingStationCollectionService.java
jcdm-main/src/main/java/com/jcdm/main/da/passingStationCollection/service/impl/DaPassingStationCollectionServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentAlarm/controller/EmEquipmentAlarmController.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentAlarm/domain/EmEquipmentAlarm.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentAlarm/mapper/EmEquipmentAlarmMapper.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentAlarm/service/IEmEquipmentAlarmService.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentAlarm/service/impl/EmEquipmentAlarmServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentArchives/controller/EmEquipmentArchivesController.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentArchives/domain/EmEquipmentArchives.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentArchives/mapper/EmEquipmentArchivesMapper.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentArchives/service/IEmEquipmentArchivesService.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentArchives/service/impl/EmEquipmentArchivesServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentStatus/controller/EmEquipmentStatusController.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentStatus/domain/EmEquipmentStatus.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentStatus/mapper/EmEquipmentStatusMapper.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentStatus/service/IEmEquipmentStatusService.java
jcdm-main/src/main/java/com/jcdm/main/em/equipmentStatus/service/impl/EmEquipmentStatusServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java
jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/domain/OmProductionOrdeInfo.java
jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/mapper/OmProductionOrdeInfoMapper.java
jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/service/IOmProductionOrdeInfoService.java
jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/service/impl/OmProductionOrdeInfoServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/om/workReport/controller/OmWorkReportController.java
jcdm-main/src/main/java/com/jcdm/main/om/workReport/domain/OmWorkReport.java
jcdm-main/src/main/java/com/jcdm/main/om/workReport/mapper/OmWorkReportMapper.java
jcdm-main/src/main/java/com/jcdm/main/om/workReport/service/IOmWorkReportService.java
jcdm-main/src/main/java/com/jcdm/main/om/workReport/service/impl/OmWorkReportServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairData/controller/RmRepairDataController.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairData/domain/RmRepairData.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairData/mapper/RmRepairDataMapper.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairData/service/IRmRepairDataService.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairData/service/impl/RmRepairDataServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairRecord/controller/RmRepairRecordController.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairRecord/domain/RmRepairRecord.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairRecord/mapper/RmRepairRecordMapper.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairRecord/service/IRmRepairRecordService.java
jcdm-main/src/main/java/com/jcdm/main/rm/repairRecord/service/impl/RmRepairRecordServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/sc/stationConf/controller/ScStationConfController.java
jcdm-main/src/main/java/com/jcdm/main/sc/stationConf/domain/ScStationConf.java
jcdm-main/src/main/java/com/jcdm/main/sc/stationConf/mapper/ScStationConfMapper.java
jcdm-main/src/main/java/com/jcdm/main/sc/stationConf/service/IScStationConfService.java
jcdm-main/src/main/java/com/jcdm/main/sc/stationConf/service/impl/ScStationConfServiceImpl.java
jcdm-main/src/main/java/com/jcdm/main/util/IpInfoUtils.java
jcdm-main/src/main/java/com/jcdm/main/webservice/Item.java
jcdm-main/src/main/java/com/jcdm/main/webservice/ItemList.java
jcdm-main/src/main/java/com/jcdm/main/webservice/test.java
jcdm-main/src/main/resources/mapper/bs/beatSetting/BsBeatSettingMapper.xml
jcdm-main/src/main/resources/mapper/bs/formula/BsFormulaInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/formulaChild/BsFormulaChildInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/lineInfo/BsLineInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/material/BsMaterialInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/processFile/BsProcessFileMapper.xml
jcdm-main/src/main/resources/mapper/bs/processes/BsProcessesInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/productBom/BsProductBomInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/productBomChild/BsProductBomChildInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/technologyRoute/BsTechnologyRouteInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/technologyRouteChild/BsTechnologyRouteChildInfoMapper.xml
jcdm-main/src/main/resources/mapper/bs/workshop/BsWorkshopInfoMapper.xml
jcdm-main/src/main/resources/mapper/da/collectionParamConf/DaCollectionParamConfMapper.xml
jcdm-main/src/main/resources/mapper/da/opcuaconfig/DaOpcuaConfigMapper.xml
jcdm-main/src/main/resources/mapper/da/paramCollection/DaParamCollectionMapper.xml
jcdm-main/src/main/resources/mapper/da/passingStationCollection/DaPassingStationCollectionMapper.xml
jcdm-main/src/main/resources/mapper/em/equipmentAlarm/EmEquipmentAlarmMapper.xml
jcdm-main/src/main/resources/mapper/em/equipmentArchives/EmEquipmentArchivesMapper.xml
jcdm-main/src/main/resources/mapper/em/equipmentStatus/EmEquipmentStatusMapper.xml
jcdm-main/src/main/resources/mapper/om/productionOrde/OmProductionOrdeInfoMapper.xml
jcdm-main/src/main/resources/mapper/om/workReport/OmWorkReportMapper.xml
jcdm-main/src/main/resources/mapper/rm/repairData/RmRepairDataMapper.xml
jcdm-main/src/main/resources/mapper/rm/repairRecord/RmRepairRecordMapper.xml
jcdm-main/src/main/resources/mapper/sc/stationConf/ScStationConfMapper.xml
jcdm-main/src/main/resources/opcua.properties
jcdm-quartz/pom.xml
jcdm-quartz/src/main/java/com/jcdm/quartz/config/ScheduleConfig.java
jcdm-quartz/src/main/java/com/jcdm/quartz/controller/SysJobController.java
jcdm-quartz/src/main/java/com/jcdm/quartz/controller/SysJobLogController.java
jcdm-quartz/src/main/java/com/jcdm/quartz/domain/SysJob.java
jcdm-quartz/src/main/java/com/jcdm/quartz/domain/SysJobLog.java
jcdm-quartz/src/main/java/com/jcdm/quartz/mapper/SysJobLogMapper.java
jcdm-quartz/src/main/java/com/jcdm/quartz/mapper/SysJobMapper.java
jcdm-quartz/src/main/java/com/jcdm/quartz/service/ISysJobLogService.java
jcdm-quartz/src/main/java/com/jcdm/quartz/service/ISysJobService.java
jcdm-quartz/src/main/java/com/jcdm/quartz/service/impl/SysJobLogServiceImpl.java
jcdm-quartz/src/main/java/com/jcdm/quartz/service/impl/SysJobServiceImpl.java
jcdm-quartz/src/main/java/com/jcdm/quartz/task/RyTask.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/AbstractQuartzJob.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/CronUtils.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/JobInvokeUtil.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/QuartzDisallowConcurrentExecution.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/QuartzJobExecution.java
jcdm-quartz/src/main/java/com/jcdm/quartz/util/ScheduleUtils.java
jcdm-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml
jcdm-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml
jcdm-system/pom.xml
jcdm-system/src/main/java/com/jcdm/system/domain/SysCache.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysConfig.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysLogininfor.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysNotice.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysOperLog.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysPost.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysRoleDept.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysRoleMenu.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysUserOnline.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysUserPost.java
jcdm-system/src/main/java/com/jcdm/system/domain/SysUserRole.java
jcdm-system/src/main/java/com/jcdm/system/domain/vo/MetaVo.java
jcdm-system/src/main/java/com/jcdm/system/domain/vo/RouterVo.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysConfigMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysDeptMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysDictDataMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysDictTypeMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysLogininforMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysMenuMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysNoticeMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysOperLogMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysPostMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysRoleDeptMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysRoleMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysRoleMenuMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysUserMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysUserPostMapper.java
jcdm-system/src/main/java/com/jcdm/system/mapper/SysUserRoleMapper.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysConfigService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysDeptService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysDictDataService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysDictTypeService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysLogininforService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysMenuService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysNoticeService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysOperLogService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysPostService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysRoleService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysUserOnlineService.java
jcdm-system/src/main/java/com/jcdm/system/service/ISysUserService.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysConfigServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysDeptServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysDictDataServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysDictTypeServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysLogininforServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysMenuServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysNoticeServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysOperLogServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysPostServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysRoleServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysUserOnlineServiceImpl.java
jcdm-system/src/main/java/com/jcdm/system/service/impl/SysUserServiceImpl.java
jcdm-system/src/main/resources/mapper/system/SysConfigMapper.xml
jcdm-system/src/main/resources/mapper/system/SysDeptMapper.xml
jcdm-system/src/main/resources/mapper/system/SysDictDataMapper.xml
jcdm-system/src/main/resources/mapper/system/SysDictTypeMapper.xml
jcdm-system/src/main/resources/mapper/system/SysLogininforMapper.xml
jcdm-system/src/main/resources/mapper/system/SysMenuMapper.xml
jcdm-system/src/main/resources/mapper/system/SysNoticeMapper.xml
jcdm-system/src/main/resources/mapper/system/SysOperLogMapper.xml
jcdm-system/src/main/resources/mapper/system/SysPostMapper.xml
jcdm-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml
jcdm-system/src/main/resources/mapper/system/SysRoleMapper.xml
jcdm-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml
jcdm-system/src/main/resources/mapper/system/SysUserMapper.xml
jcdm-system/src/main/resources/mapper/system/SysUserPostMapper.xml
jcdm-system/src/main/resources/mapper/system/SysUserRoleMapper.xml
jcdm-ui/.editorconfig
jcdm-ui/.env.development
jcdm-ui/.env.production
jcdm-ui/.env.staging
jcdm-ui/.eslintignore
jcdm-ui/.eslintrc.js
jcdm-ui/.gitignore
jcdm-ui/README.md
jcdm-ui/babel.config.js
jcdm-ui/bin/build.bat
jcdm-ui/bin/package.bat
jcdm-ui/bin/run-web.bat
jcdm-ui/build/index.js
jcdm-ui/dist.rar
jcdm-ui/package.json
jcdm-ui/public/favicon.ico
jcdm-ui/public/html/ie.html
jcdm-ui/public/index.html
jcdm-ui/public/robots.txt
jcdm-ui/src/App.vue
jcdm-ui/src/api/login.js
jcdm-ui/src/api/main/bs/ProductBom/ProductBom.js
jcdm-ui/src/api/main/bs/ProductBomChild/ProductBomChild.js
jcdm-ui/src/api/main/bs/beatSetting/beatSetting.js
jcdm-ui/src/api/main/bs/formula/formula.js
jcdm-ui/src/api/main/bs/formulaChild/formulaChild.js
jcdm-ui/src/api/main/bs/lineInfo/lineInfo.js
jcdm-ui/src/api/main/bs/material/material.js
jcdm-ui/src/api/main/bs/processFile/processFile.js
jcdm-ui/src/api/main/bs/processes/processes.js
jcdm-ui/src/api/main/bs/technologyRoute/technologyRoute.js
jcdm-ui/src/api/main/bs/technologyRouteChild/technologyRouteChild.js
jcdm-ui/src/api/main/bs/workshop/workshop.js
jcdm-ui/src/api/main/da/collectionParamConf/collectionParamConf.js
jcdm-ui/src/api/main/da/opcuaconfig/opcuaconfig.js
jcdm-ui/src/api/main/da/paramCollection/paramCollection.js
jcdm-ui/src/api/main/da/passingStationCollection/passingStationCollection.js
jcdm-ui/src/api/main/em/equipmentAlarm/equipmentAlarm.js
jcdm-ui/src/api/main/em/equipmentArchives/equipmentArchives.js
jcdm-ui/src/api/main/em/equipmentStatus/equipmentStatus.js
jcdm-ui/src/api/main/om/productionOrde/productionOrde.js
jcdm-ui/src/api/main/om/workReport/workReport.js
jcdm-ui/src/api/main/rm/repairData/repairData.js
jcdm-ui/src/api/main/rm/repairRecord/repairRecord.js
jcdm-ui/src/api/main/sc/stationConf.js
jcdm-ui/src/api/menu.js
jcdm-ui/src/api/monitor/cache.js
jcdm-ui/src/api/monitor/job.js
jcdm-ui/src/api/monitor/jobLog.js
jcdm-ui/src/api/monitor/logininfor.js
jcdm-ui/src/api/monitor/online.js
jcdm-ui/src/api/monitor/operlog.js
jcdm-ui/src/api/monitor/server.js
jcdm-ui/src/api/system/config.js
jcdm-ui/src/api/system/dept.js
jcdm-ui/src/api/system/dict/data.js
jcdm-ui/src/api/system/dict/type.js
jcdm-ui/src/api/system/menu.js
jcdm-ui/src/api/system/notice.js
jcdm-ui/src/api/system/post.js
jcdm-ui/src/api/system/role.js
jcdm-ui/src/api/system/user.js
jcdm-ui/src/api/tool/gen.js
jcdm-ui/src/assets/401_images/401.gif
jcdm-ui/src/assets/404_images/404.png
jcdm-ui/src/assets/404_images/404_cloud.png
jcdm-ui/src/assets/icons/index.js
jcdm-ui/src/assets/icons/svg/404.svg
jcdm-ui/src/assets/icons/svg/bug.svg
jcdm-ui/src/assets/icons/svg/build.svg
jcdm-ui/src/assets/icons/svg/button.svg
jcdm-ui/src/assets/icons/svg/cascader.svg
jcdm-ui/src/assets/icons/svg/chart.svg
jcdm-ui/src/assets/icons/svg/checkbox.svg
jcdm-ui/src/assets/icons/svg/clipboard.svg
jcdm-ui/src/assets/icons/svg/code.svg
jcdm-ui/src/assets/icons/svg/color.svg
jcdm-ui/src/assets/icons/svg/component.svg
jcdm-ui/src/assets/icons/svg/dashboard.svg
jcdm-ui/src/assets/icons/svg/date-range.svg
jcdm-ui/src/assets/icons/svg/date.svg
jcdm-ui/src/assets/icons/svg/dict.svg
jcdm-ui/src/assets/icons/svg/documentation.svg
jcdm-ui/src/assets/icons/svg/download.svg
jcdm-ui/src/assets/icons/svg/drag.svg
jcdm-ui/src/assets/icons/svg/druid.svg
jcdm-ui/src/assets/icons/svg/edit.svg
jcdm-ui/src/assets/icons/svg/education.svg
jcdm-ui/src/assets/icons/svg/email.svg
jcdm-ui/src/assets/icons/svg/example.svg
jcdm-ui/src/assets/icons/svg/excel.svg
jcdm-ui/src/assets/icons/svg/exit-fullscreen.svg
jcdm-ui/src/assets/icons/svg/eye-open.svg
jcdm-ui/src/assets/icons/svg/eye.svg
jcdm-ui/src/assets/icons/svg/form.svg
jcdm-ui/src/assets/icons/svg/fullscreen.svg
jcdm-ui/src/assets/icons/svg/github.svg
jcdm-ui/src/assets/icons/svg/guide.svg
jcdm-ui/src/assets/icons/svg/icon.svg
jcdm-ui/src/assets/icons/svg/input.svg
jcdm-ui/src/assets/icons/svg/international.svg
jcdm-ui/src/assets/icons/svg/job.svg
jcdm-ui/src/assets/icons/svg/language.svg
jcdm-ui/src/assets/icons/svg/link.svg
jcdm-ui/src/assets/icons/svg/list.svg
jcdm-ui/src/assets/icons/svg/lock.svg
jcdm-ui/src/assets/icons/svg/log.svg
jcdm-ui/src/assets/icons/svg/logininfor.svg
jcdm-ui/src/assets/icons/svg/message.svg
jcdm-ui/src/assets/icons/svg/money.svg
jcdm-ui/src/assets/icons/svg/monitor.svg
jcdm-ui/src/assets/icons/svg/nested.svg
jcdm-ui/src/assets/icons/svg/number.svg
jcdm-ui/src/assets/icons/svg/online.svg
jcdm-ui/src/assets/icons/svg/password.svg
jcdm-ui/src/assets/icons/svg/pdf.svg
jcdm-ui/src/assets/icons/svg/people.svg
jcdm-ui/src/assets/icons/svg/peoples.svg
jcdm-ui/src/assets/icons/svg/phone.svg
jcdm-ui/src/assets/icons/svg/post.svg
jcdm-ui/src/assets/icons/svg/qq.svg
jcdm-ui/src/assets/icons/svg/question.svg
jcdm-ui/src/assets/icons/svg/radio.svg
jcdm-ui/src/assets/icons/svg/rate.svg
jcdm-ui/src/assets/icons/svg/redis-list.svg
jcdm-ui/src/assets/icons/svg/redis.svg
jcdm-ui/src/assets/icons/svg/row.svg
jcdm-ui/src/assets/icons/svg/search.svg
jcdm-ui/src/assets/icons/svg/select.svg
jcdm-ui/src/assets/icons/svg/server.svg
jcdm-ui/src/assets/icons/svg/shopping.svg
jcdm-ui/src/assets/icons/svg/size.svg
jcdm-ui/src/assets/icons/svg/skill.svg
jcdm-ui/src/assets/icons/svg/slider.svg
jcdm-ui/src/assets/icons/svg/star.svg
jcdm-ui/src/assets/icons/svg/swagger.svg
jcdm-ui/src/assets/icons/svg/switch.svg
jcdm-ui/src/assets/icons/svg/system.svg
jcdm-ui/src/assets/icons/svg/tab.svg
jcdm-ui/src/assets/icons/svg/table.svg
jcdm-ui/src/assets/icons/svg/textarea.svg
jcdm-ui/src/assets/icons/svg/theme.svg
jcdm-ui/src/assets/icons/svg/time-range.svg
jcdm-ui/src/assets/icons/svg/time.svg
jcdm-ui/src/assets/icons/svg/tool.svg
jcdm-ui/src/assets/icons/svg/tree-table.svg
jcdm-ui/src/assets/icons/svg/tree.svg
jcdm-ui/src/assets/icons/svg/upload.svg
jcdm-ui/src/assets/icons/svg/user.svg
jcdm-ui/src/assets/icons/svg/validCode.svg
jcdm-ui/src/assets/icons/svg/wechat.svg
jcdm-ui/src/assets/icons/svg/zip.svg
jcdm-ui/src/assets/icons/svgo.yml
jcdm-ui/src/assets/images/dark.svg
jcdm-ui/src/assets/images/light.svg
jcdm-ui/src/assets/images/login-background.jpg
jcdm-ui/src/assets/images/login-background.png
jcdm-ui/src/assets/images/login-background1.png
jcdm-ui/src/assets/images/pay.png
jcdm-ui/src/assets/images/profile.jpg
jcdm-ui/src/assets/logo/logo.png
jcdm-ui/src/assets/styles/btn.scss
jcdm-ui/src/assets/styles/element-ui.scss
jcdm-ui/src/assets/styles/element-variables.scss
jcdm-ui/src/assets/styles/index.scss
jcdm-ui/src/assets/styles/mixin.scss
jcdm-ui/src/assets/styles/ruoyi.scss
jcdm-ui/src/assets/styles/sidebar.scss
jcdm-ui/src/assets/styles/transition.scss
jcdm-ui/src/assets/styles/variables.scss
jcdm-ui/src/components/Breadcrumb/index.vue
jcdm-ui/src/components/Crontab/day.vue
jcdm-ui/src/components/Crontab/hour.vue
jcdm-ui/src/components/Crontab/index.vue
jcdm-ui/src/components/Crontab/min.vue
jcdm-ui/src/components/Crontab/month.vue
jcdm-ui/src/components/Crontab/result.vue
jcdm-ui/src/components/Crontab/second.vue
jcdm-ui/src/components/Crontab/week.vue
jcdm-ui/src/components/Crontab/year.vue
jcdm-ui/src/components/DictData/index.js
jcdm-ui/src/components/DictTag/index.vue
jcdm-ui/src/components/Editor/index.vue
jcdm-ui/src/components/FileUpload/index.vue
jcdm-ui/src/components/Hamburger/index.vue
jcdm-ui/src/components/HeaderSearch/index.vue
jcdm-ui/src/components/IconSelect/index.vue
jcdm-ui/src/components/IconSelect/requireIcons.js
jcdm-ui/src/components/ImagePreview/index.vue
jcdm-ui/src/components/ImageUpload/index.vue
jcdm-ui/src/components/Pagination/index.vue
jcdm-ui/src/components/PanThumb/index.vue
jcdm-ui/src/components/ParentView/index.vue
jcdm-ui/src/components/RightPanel/index.vue
jcdm-ui/src/components/RightToolbar/index.vue
jcdm-ui/src/components/RuoYi/Doc/index.vue
jcdm-ui/src/components/RuoYi/Git/index.vue
jcdm-ui/src/components/Screenfull/index.vue
jcdm-ui/src/components/SizeSelect/index.vue
jcdm-ui/src/components/SvgIcon/index.vue
jcdm-ui/src/components/ThemePicker/index.vue
jcdm-ui/src/components/TopNav/index.vue
jcdm-ui/src/components/iFrame/index.vue
jcdm-ui/src/components/itemSelect/index.vue
jcdm-ui/src/components/itemSelect/single.vue
jcdm-ui/src/directive/dialog/drag.js
jcdm-ui/src/directive/dialog/dragHeight.js
jcdm-ui/src/directive/dialog/dragWidth.js
jcdm-ui/src/directive/index.js
jcdm-ui/src/directive/module/clipboard.js
jcdm-ui/src/directive/permission/hasPermi.js
jcdm-ui/src/directive/permission/hasRole.js
jcdm-ui/src/layout/components/AppMain.vue
jcdm-ui/src/layout/components/IframeToggle/index.vue
jcdm-ui/src/layout/components/InnerLink/index.vue
jcdm-ui/src/layout/components/Navbar.vue
jcdm-ui/src/layout/components/Settings/index.vue
jcdm-ui/src/layout/components/Sidebar/FixiOSBug.js
jcdm-ui/src/layout/components/Sidebar/Item.vue
jcdm-ui/src/layout/components/Sidebar/Link.vue
jcdm-ui/src/layout/components/Sidebar/Logo.vue
jcdm-ui/src/layout/components/Sidebar/SidebarItem.vue
jcdm-ui/src/layout/components/Sidebar/index.vue
jcdm-ui/src/layout/components/TagsView/ScrollPane.vue
jcdm-ui/src/layout/components/TagsView/index.vue
jcdm-ui/src/layout/components/index.js
jcdm-ui/src/layout/index.vue
jcdm-ui/src/layout/mixin/ResizeHandler.js
jcdm-ui/src/main.js
jcdm-ui/src/permission.js
jcdm-ui/src/plugins/auth.js
jcdm-ui/src/plugins/cache.js
jcdm-ui/src/plugins/download.js
jcdm-ui/src/plugins/index.js
jcdm-ui/src/plugins/modal.js
jcdm-ui/src/plugins/tab.js
jcdm-ui/src/router/directives.js
jcdm-ui/src/router/index.js
jcdm-ui/src/settings.js
jcdm-ui/src/store/getters.js
jcdm-ui/src/store/index.js
jcdm-ui/src/store/modules/app.js
jcdm-ui/src/store/modules/dict.js
jcdm-ui/src/store/modules/permission.js
jcdm-ui/src/store/modules/settings.js
jcdm-ui/src/store/modules/tagsView.js
jcdm-ui/src/store/modules/user.js
jcdm-ui/src/utils/auth.js
jcdm-ui/src/utils/dict/Dict.js
jcdm-ui/src/utils/dict/DictConverter.js
jcdm-ui/src/utils/dict/DictData.js
jcdm-ui/src/utils/dict/DictMeta.js
jcdm-ui/src/utils/dict/DictOptions.js
jcdm-ui/src/utils/dict/index.js
jcdm-ui/src/utils/errorCode.js
jcdm-ui/src/utils/generator/config.js
jcdm-ui/src/utils/generator/css.js
jcdm-ui/src/utils/generator/drawingDefault.js
jcdm-ui/src/utils/generator/html.js
jcdm-ui/src/utils/generator/icon.json
jcdm-ui/src/utils/generator/js.js
jcdm-ui/src/utils/generator/render.js
jcdm-ui/src/utils/index.js
jcdm-ui/src/utils/jsencrypt.js
jcdm-ui/src/utils/permission.js
jcdm-ui/src/utils/request.js
jcdm-ui/src/utils/ruoyi.js
jcdm-ui/src/utils/scroll-to.js
jcdm-ui/src/utils/validate.js
jcdm-ui/src/views/components/icons/element-icons.js
jcdm-ui/src/views/components/icons/index.vue
jcdm-ui/src/views/components/icons/svg-icons.js
jcdm-ui/src/views/dashboard/BarChart.vue
jcdm-ui/src/views/dashboard/LineChart.vue
jcdm-ui/src/views/dashboard/PanelGroup.vue
jcdm-ui/src/views/dashboard/PieChart.vue
jcdm-ui/src/views/dashboard/RaddarChart.vue
jcdm-ui/src/views/dashboard/mixins/resize.js
jcdm-ui/src/views/error/401.vue
jcdm-ui/src/views/error/404.vue
jcdm-ui/src/views/index.vue
jcdm-ui/src/views/index_v1.vue
jcdm-ui/src/views/login.vue
jcdm-ui/src/views/main/bs/ProductBom/index.vue
jcdm-ui/src/views/main/bs/ProductBomChild/index.vue
jcdm-ui/src/views/main/bs/beatSetting/index.vue
jcdm-ui/src/views/main/bs/formula/index.vue
jcdm-ui/src/views/main/bs/formulaChild/index.vue
jcdm-ui/src/views/main/bs/lineInfo/index.vue
jcdm-ui/src/views/main/bs/material/index.vue
jcdm-ui/src/views/main/bs/processFile/index.vue
jcdm-ui/src/views/main/bs/processes/index.vue
jcdm-ui/src/views/main/bs/technologyRoute/index.vue
jcdm-ui/src/views/main/bs/technologyRouteChild/index.vue
jcdm-ui/src/views/main/bs/workshop/index.vue
jcdm-ui/src/views/main/cfkb/Instructions/index.vue
jcdm-ui/src/views/main/da/collectionParamConf/index.vue
jcdm-ui/src/views/main/da/opcuaconfig/index.vue
jcdm-ui/src/views/main/da/paramCollection/index.vue
jcdm-ui/src/views/main/da/passingStationCollection/index.vue
jcdm-ui/src/views/main/em/equipmentAlarm/index.vue
jcdm-ui/src/views/main/em/equipmentArchives/index.vue
jcdm-ui/src/views/main/em/equipmentStatus/index.vue
jcdm-ui/src/views/main/kb/stationTerminal/index.vue
jcdm-ui/src/views/main/om/productionOrde/index.vue
jcdm-ui/src/views/main/om/workReport/index.vue
jcdm-ui/src/views/main/rm/repairData/index.vue
jcdm-ui/src/views/main/rm/repairRecord/index.vue
jcdm-ui/src/views/main/sc/stationConf/index.vue
jcdm-ui/src/views/monitor/cache/index.vue
jcdm-ui/src/views/monitor/cache/list.vue
jcdm-ui/src/views/monitor/druid/index.vue
jcdm-ui/src/views/monitor/job/index.vue
jcdm-ui/src/views/monitor/job/log.vue
jcdm-ui/src/views/monitor/logininfor/index.vue
jcdm-ui/src/views/monitor/online/index.vue
jcdm-ui/src/views/monitor/operlog/index.vue
jcdm-ui/src/views/monitor/server/index.vue
jcdm-ui/src/views/redirect.vue
jcdm-ui/src/views/register.vue
jcdm-ui/src/views/system/config/index.vue
jcdm-ui/src/views/system/dept/index.vue
jcdm-ui/src/views/system/dict/data.vue
jcdm-ui/src/views/system/dict/index.vue
jcdm-ui/src/views/system/menu/index.vue
jcdm-ui/src/views/system/notice/index.vue
jcdm-ui/src/views/system/post/index.vue
jcdm-ui/src/views/system/role/authUser.vue
jcdm-ui/src/views/system/role/index.vue
jcdm-ui/src/views/system/role/selectUser.vue
jcdm-ui/src/views/system/user/authRole.vue
jcdm-ui/src/views/system/user/index.vue
jcdm-ui/src/views/system/user/profile/index.vue
jcdm-ui/src/views/system/user/profile/resetPwd.vue
jcdm-ui/src/views/system/user/profile/userAvatar.vue
jcdm-ui/src/views/system/user/profile/userInfo.vue
jcdm-ui/src/views/tool/build/CodeTypeDialog.vue
jcdm-ui/src/views/tool/build/DraggableItem.vue
jcdm-ui/src/views/tool/build/IconsDialog.vue
jcdm-ui/src/views/tool/build/RightPanel.vue
jcdm-ui/src/views/tool/build/TreeNodeDialog.vue
jcdm-ui/src/views/tool/build/index.vue
jcdm-ui/src/views/tool/gen/basicInfoForm.vue
jcdm-ui/src/views/tool/gen/editTable.vue
jcdm-ui/src/views/tool/gen/genInfoForm.vue
jcdm-ui/src/views/tool/gen/importTable.vue
jcdm-ui/src/views/tool/gen/index.vue
jcdm-ui/src/views/tool/swagger/index.vue
jcdm-ui/vue.config.js
package-lock.json
pom.xml
sql/quartz.sql
sql/ry_20231130.sql |