Merge remote-tracking branch 'origin/dev'
# Conflicts:
# ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RedisLockAspect.java
已修改143个文件
已添加9个文件
已重命名2个文件
已删除12个文件
| | |
| | | [](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus) |
| | | [](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus/blob/master/LICENSE) |
| | | [](https://www.jetbrains.com/?from=RuoYi-Vue-Plus) |
| | | []() |
| | | []() |
| | | |
| | | åºäº RuoYi-Vue éæ Mybatis-Plus Lombok Hutool ç便æ·å¼åå·¥å
· éé
éåç¸å
³ä¸å¡ 便äºå¼å å®æä¸ RuoYi-Vue 忥 |
| | | * å端å¼åæ¡æ¶ VueãElement UI |
| | |
| | | * çæ§æ¡æ¶ spring-boot-admin å
¨æ¹ä½æå¡çæ§ |
| | | * æ ¡éªæ¡æ¶ validation å¢å¼ºæ¥å£å®å
¨æ§ ä¸¥è°¨æ§ |
| | | * ææ¡£æ¡æ¶ knife4j ç¾åæ¥å£ææ¡£ |
| | | * åºååæ¡æ¶ ç»ä¸ä½¿ç¨ jackson 髿å¯é |
| | | * 代ç çæå¨ ä¸é®çæåå端代ç |
| | | * 夿°æ®æºæ¡æ¶ dynamic-datasource æ¯æä¸»ä»ä¸å¤ç§ç±»æ°æ®åºå¼æ |
| | | * Redis客æ·ç«¯ éç¨ Redisson æ§è½æ´å¼º |
| | | * åå¸å¼é Lock4j 注解éãå·¥å
·é å¤ç§å¤æ · |
| | | |
| | | ## åèææ¡£ |
| | | |
| | | ä½¿ç¨æ¡æ¶å请ä»ç»é
è¯»ææ¡£éç¹æ³¨æäºé¡¹ |
| | | [åèææ¡£ Wiki](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus/wikis/pages) |
| | | |
| | | ## ä¿®æ¹RuoYiåè½ |
| | |
| | | * éæ Feign æ¥å£å管ç Http 请æ±(å¦ä¸æ¹è¯·æ± æ¯ä»,çä¿¡,æ¨éç) |
| | | * ç§»é¤ èªå¸¦æå¡çæ§ æ¹ä¸º spring-boot-admin å
¨æ¹ä½çæ§ |
| | | * å¢å demo 模å示ä¾(ç»ä¸ä¼å¢å 模åçå°ä¼ä¼´ååè) |
| | | * å¢å redisson æ¯æåå¸å¼é åè½æ´å¼ºå¤§ |
| | | * å¢å redisson 髿§è½ Redis 客æ·ç«¯ |
| | | * ç§»é¤ fastjson ç»ä¸ä½¿ç¨ jackson åºåå |
| | | * éæ dynamic-datasource 夿°æ®æº(é»è®¤æ¯æMySQL,å
¶ä»ç§ç±»éèªè¡éé
) |
| | | * éæ Lock4j å®ç°åå¸å¼ 注解éãå·¥å
·é å¤ç§å¤æ · |
| | | |
| | | ### ä»£ç æ¹å¨ |
| | | |
| | |
| | | * 项ç®ä¿®æ¹ä¸º mavenå¤ç¯å¢é
ç½® |
| | | * 项ç®é
置修æ¹ä¸º application.yml ç»ä¸ç®¡ç |
| | | * æ°æ®æéä¿®æ¹ä¸º éé
æ¯æå表ãå¤è¡¨ |
| | | * ä½¿ç¨ redisson å®ç°åå¸å¼é注解ä¸å·¥å
·ç±» |
| | | * ä½¿ç¨ redisson å®ç° spring-cache æ´å |
| | | * å¢å mybatis-plus äºçº§ç¼å redis åå¨ |
| | | |
| | |
| | | |
| | | <properties> |
| | | <ruoyi-vue-plus.version>2.3.2</ruoyi-vue-plus.version> |
| | | <spring-boot.version>2.3.11.RELEASE</spring-boot.version> |
| | | <spring-boot.version>2.4.7</spring-boot.version> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| | | <java.version>1.8</java.version> |
| | | <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version> |
| | | <druid.version>1.2.6</druid.version> |
| | | <knife4j.version>3.0.2</knife4j.version> |
| | | <fastjson.version>1.2.76</fastjson.version> |
| | | <poi.version>4.1.2</poi.version> |
| | | <velocity.version>1.7</velocity.version> |
| | | <jwt.version>0.9.1</jwt.version> |
| | | <mybatis-plus.version>3.4.3</mybatis-plus.version> |
| | | <hutool.version>5.6.5</hutool.version> |
| | | <feign.version>2.2.6.RELEASE</feign.version> |
| | | <hutool.version>5.7.2</hutool.version> |
| | | <feign.version>3.0.3</feign.version> |
| | | <feign-okhttp.version>11.0</feign-okhttp.version> |
| | | <spring-boot-admin.version>2.3.1</spring-boot-admin.version> |
| | | <spring-boot-admin.version>2.4.1</spring-boot-admin.version> |
| | | <redisson.version>3.15.2</redisson.version> |
| | | <lock4j.version>2.2.1</lock4j.version> |
| | | <datasource.version>3.4.0</datasource.version> |
| | | </properties> |
| | | |
| | | <!-- ä¾èµå£°æ --> |
| | |
| | | <version>${velocity.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- é¿éJSONè§£æå¨ --> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>fastjson</artifactId> |
| | | <version>${fastjson.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- Tokençæä¸è§£æ--> |
| | | <dependency> |
| | | <groupId>io.jsonwebtoken</groupId> |
| | | <artifactId>jjwt</artifactId> |
| | | <version>${jwt.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- dynamic-datasource 夿°æ®æº--> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
| | | <version>${datasource.version}</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | |
| | | <artifactId>mybatis-plus-extension</artifactId> |
| | | <version>${mybatis-plus.version}</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>cn.hutool</groupId> |
| | | <artifactId>hutool-all</artifactId> |
| | |
| | | <artifactId>redisson-spring-boot-starter</artifactId> |
| | | <version>${redisson.version}</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>lock4j-redisson-spring-boot-starter</artifactId> |
| | | <version>${lock4j.version}</version> |
| | | </dependency> |
| | | <!-- 宿¶ä»»å¡--> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | |
| | | <logging.level>warn</logging.level> |
| | | </properties> |
| | | </profile> |
| | | |
| | | <!-- jdkå¤çæ¬é
ç½® --> |
| | | <profile> |
| | | <id>jdk8</id> |
| | | <activation> |
| | | <activeByDefault>true</activeByDefault> |
| | | <jdk>1.8</jdk> |
| | | </activation> |
| | | <properties> |
| | | <java.version>1.8</java.version> |
| | | </properties> |
| | | </profile> |
| | | <profile> |
| | | <id>jdk11</id> |
| | | <activation> |
| | | <jdk>11</jdk> |
| | | </activation> |
| | | <properties> |
| | | <java.version>11</java.version> |
| | | <jaxb.version>3.0.1</jaxb.version> |
| | | </properties> |
| | | <dependencyManagement> |
| | | <dependencies> |
| | | <!-- jdk11 缺失ä¾èµ jaxb--> |
| | | <dependency> |
| | | <groupId>com.sun.xml.bind</groupId> |
| | | <artifactId>jaxb-impl</artifactId> |
| | | <version>${jaxb.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | </dependencyManagement> |
| | | <dependencies> |
| | | <!--jaxb--> |
| | | <dependency> |
| | | <groupId>com.sun.xml.bind</groupId> |
| | | <artifactId>jaxb-impl</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | </profile> |
| | | </profiles> |
| | | |
| | | </project> |
| | |
| | | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| | | |
| | | /** |
| | | * å¯å¨ç¨åº |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | |
| | | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) |
| | | @SpringBootApplication |
| | | public class RuoYiApplication |
| | | { |
| | | public static void main(String[] args) |
| | |
| | | |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |
| | | FileUtils.writeToStream(filePath, response.getOutputStream()); |
| | | if (delete) |
| | | { |
| | | FileUtils.deleteFile(filePath); |
| | | FileUtils.del(filePath); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | |
| | | String downloadName = StrUtil.subAfter(downloadPath, "/",true); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, downloadName); |
| | | FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
| | | FileUtils.writeToStream(downloadPath, response.getOutputStream()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | { |
| | | SysDept d = (SysDept) it.next(); |
| | | if (d.getDeptId().intValue() == deptId |
| | | || ArrayUtils.contains(StrUtil.split(d.getAncestors(), ","), deptId + "")) |
| | | || ArrayUtils.contains(StrUtil.splitToArray(d.getAncestors(), ","), deptId + "")) |
| | | { |
| | | it.remove(); |
| | | } |
| | |
| | | # æ°æ®æºé
ç½® |
| | | spring: |
| | | autoconfigure: |
| | | exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | # å¨ææ°æ®æºææ¡£ https://www.kancloud.cn/tracy5546/dynamic-datasource/content |
| | | dynamic: |
| | | #设置é»è®¤çæ°æ®æºæè
æ°æ®æºç»,é»è®¤å¼å³ä¸º master |
| | | primary: master |
| | | datasource: |
| | | # ä¸»åºæ°æ®æº |
| | | master: |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true |
| | | username: root |
| | | password: root |
| | | # ä»åºæ°æ®æº |
| | | slave: |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | url: |
| | | username: |
| | | password: |
| | | druid: |
| | | # ä¸»åºæ°æ®æº |
| | | master: |
| | | url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true |
| | | username: root |
| | | password: root |
| | | # ä»åºæ°æ®æº |
| | | slave: |
| | | # 仿°æ®æºå¼å
³/é»è®¤å
³é |
| | | enabled: false |
| | | url: |
| | | username: |
| | | password: |
| | | # åå§è¿æ¥æ° |
| | | initialSize: 5 |
| | | # æå°è¿æ¥æ± æ°é |
| | |
| | | testWhileIdle: true |
| | | testOnBorrow: false |
| | | testOnReturn: false |
| | | # 注æè¿ä¸ªå¼ådruidåçä¸ä¸è´ï¼é»è®¤å¯å¨äºstat |
| | | filters: stat |
| | | webStatFilter: |
| | | enabled: true |
| | | statViewServlet: |
| | |
| | | # æ°æ®æºé
ç½® |
| | | spring: |
| | | autoconfigure: |
| | | exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | # å¨ææ°æ®æºææ¡£ https://www.kancloud.cn/tracy5546/dynamic-datasource/content |
| | | dynamic: |
| | | #设置é»è®¤çæ°æ®æºæè
æ°æ®æºç»,é»è®¤å¼å³ä¸º master |
| | | primary: master |
| | | datasource: |
| | | # ä¸»åºæ°æ®æº |
| | | master: |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true |
| | | username: root |
| | | password: root |
| | | # ä»åºæ°æ®æº |
| | | slave: |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | url: |
| | | username: |
| | | password: |
| | | druid: |
| | | # ä¸»åºæ°æ®æº |
| | | master: |
| | | url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true |
| | | username: root |
| | | password: root |
| | | # ä»åºæ°æ®æº |
| | | slave: |
| | | # 仿°æ®æºå¼å
³/é»è®¤å
³é |
| | | enabled: false |
| | | url: |
| | | username: |
| | | password: |
| | | # åå§è¿æ¥æ° |
| | | initialSize: 5 |
| | | # æå°è¿æ¥æ± æ°é |
| | |
| | | testWhileIdle: true |
| | | testOnBorrow: false |
| | | testOnReturn: false |
| | | # 注æè¿ä¸ªå¼ådruidåçä¸ä¸è´ï¼é»è®¤å¯å¨äºstat |
| | | filters: stat |
| | | webStatFilter: |
| | | enabled: true |
| | | statViewServlet: |
| | |
| | | # redis é
ç½® |
| | | redis: |
| | | # å°å |
| | | host: 192.168.0.222 |
| | | host: localhost |
| | | # 端å£ï¼é»è®¤ä¸º6379 |
| | | port: 6379 |
| | | # æ°æ®åºç´¢å¼ |
| | |
| | | # æä»¶è·¯å¾ |
| | | profile: ./ruoyi/uploadPath |
| | | # è·åipå°åå¼å
³ |
| | | addressEnabled: false |
| | | addressEnabled: true |
| | | |
| | | captcha: |
| | | # éªè¯ç å¼å
³ |
| | |
| | | thymeleaf: |
| | | # å°ç³»ç»æ¨¡æ¿æ¾ç½®å°æåé¢ å¦åä¼ä¸ springboot-admin 页é¢å²çª |
| | | template-resolver-order: 1 |
| | | jackson: |
| | | # æ¥ææ ¼å¼å |
| | | date-format: yyyy-MM-dd HH:mm:ss |
| | | serialization: |
| | | # æ ¼å¼åè¾åº |
| | | indent_output: false |
| | | # å¿½ç¥æ æ³è½¬æ¢ç对象 |
| | | fail_on_empty_beans: false |
| | | deserialization: |
| | | # å
许对象忽ç¥jsonä¸ä¸åå¨ç屿§ |
| | | fail_on_unknown_properties: false |
| | | |
| | | # tokené
ç½® |
| | | token: |
| | |
| | | enabled: true |
| | | okhttp: |
| | | enabled: true |
| | | hystrix: |
| | | circuitbreaker: |
| | | enabled: true |
| | | |
| | | --- # åå¸å¼é lock4j å
¨å±é
ç½® |
| | | lock4j: |
| | | # è·ååå¸å¼éè¶
æ¶æ¶é´ï¼é»è®¤ä¸º 3000 æ¯«ç§ |
| | | acquire-timeout: 3000 |
| | | # åå¸å¼éçè¶
æ¶æ¶é´ï¼é»è®¤ä¸º 30 æ¯«ç§ |
| | | expire: 30000 |
| | | |
| | | --- # 宿¶ä»»å¡é
ç½® |
| | | spring: |
| | | quartz: |
| | |
| | | <artifactId>jackson-databind</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- é¿éJSONè§£æå¨ --> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>fastjson</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- excelå·¥å
· --> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | |
| | | <artifactId>redisson-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- dynamic-datasource 夿°æ®æº--> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>lock4j-redisson-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | </project> |
| | |
| | | public static final String RESOURCE_PREFIX = "/profile"; |
| | | |
| | | /** |
| | | * RMI è¿ç¨æ¹æ³è°ç¨ |
| | | */ |
| | | public static final String LOOKUP_RMI = "rmi://"; |
| | | |
| | | /** |
| | | * èµæºæ å°è·¯å¾ åç¼ |
| | | */ |
| | | public static final String REDIS_LOCK_KEY = "redis_lock:"; |
| | |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.web.bind.annotation.InitBinder; |
| | | |
| | | import java.beans.PropertyEditorSupport; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * webå±éç¨æ°æ®å¤ç |
| | |
| | | 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)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * ååºè¿åç»æ |
| | |
| | | package com.ruoyi.common.core.domain; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | |
| | | |
| | | /** |
| | | * Entityåºç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | |
| | |
| | | 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; |
| | | |
| | | /** 夿³¨ */ |
ÎļþÃû´Ó ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/MybatisPlusRedisCache.java ÐÞ¸Ä |
| | |
| | | package com.ruoyi.common.core.mybatisplus; |
| | | package com.ruoyi.common.core.mybatisplus.cache; |
| | | |
| | | import cn.hutool.extra.spring.SpringUtil; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.core.mybatisplus.core; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Collection; |
| | | |
| | | /** |
| | | * èªå®ä¹ Mapper æ¥å£, å®ç° èªå®ä¹æ©å± |
| | | * |
| | | * @author Lion Li |
| | | * @since 2021-05-13 |
| | | */ |
| | | public interface BaseMapperPlus<T> extends BaseMapper<T> { |
| | | |
| | | int insertAll(@Param("list") Collection<T> batchList); |
| | | |
| | | } |
ÎļþÃû´Ó ruoyi-common/src/main/java/com/ruoyi/common/core/page/IServicePlus.java ÐÞ¸Ä |
| | |
| | | package com.ruoyi.common.core.page; |
| | | package com.ruoyi.common.core.mybatisplus.core; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.common.core.page.PagePlus; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Collection; |
| | |
| | | * |
| | | * @param page 翻页对象 |
| | | * @param queryWrapper å®ä½å¯¹è±¡å°è£
æä½ç±» |
| | | * @param kClass voç±»å |
| | | */ |
| | | default <K> PagePlus<T, K> pageVo(PagePlus<T, K> page, Wrapper<T> queryWrapper, Class<K> kClass) { |
| | | PagePlus<T, K> result = getBaseMapper().selectPage(page, queryWrapper); |
| | |
| | | * æ æ¡ä»¶ç¿»é¡µæ¥è¯¢ |
| | | * |
| | | * @param page 翻页对象 |
| | | * @param kClass voç±»å |
| | | */ |
| | | default <K> PagePlus<T, K> pageVo(PagePlus<T, K> page, Class<K> kClass) { |
| | | return pageVo(page, Wrappers.emptyWrapper(), kClass); |
| | |
| | | return pageVo(page, Wrappers.emptyWrapper(), convertor); |
| | | } |
| | | |
| | | @Override |
| | | default boolean saveBatch(Collection<T> entityList) { |
| | | return saveBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | default boolean saveOrUpdateBatch(Collection<T> entityList) { |
| | | return saveOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | default boolean updateBatchById(Collection<T> entityList) { |
| | | return updateBatchById(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | boolean saveAll(Collection<T> entityList); |
| | | } |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.core.mybatisplus.core; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.ClassUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.ResolvableType; |
| | | |
| | | import java.util.Collection; |
| | | |
| | | /** |
| | | * IServicePlus å®ç°ç±» |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @SuppressWarnings("unchecked") |
| | | public class ServicePlusImpl<M extends BaseMapperPlus<T>, T> extends ServiceImpl<M, T> implements IServicePlus<T> { |
| | | |
| | | @Autowired |
| | | protected M baseMapper; |
| | | |
| | | @Override |
| | | public M getBaseMapper() { |
| | | return baseMapper; |
| | | } |
| | | |
| | | |
| | | protected Class<T> entityClass = currentModelClass(); |
| | | |
| | | @Override |
| | | public Class<T> getEntityClass() { |
| | | return entityClass; |
| | | } |
| | | |
| | | protected Class<T> mapperClass = currentMapperClass(); |
| | | |
| | | @Override |
| | | protected Class<T> currentMapperClass() { |
| | | return (Class<T>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(0).getType(); |
| | | } |
| | | |
| | | @Override |
| | | protected Class<T> currentModelClass() { |
| | | return (Class<T>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(1).getType(); |
| | | } |
| | | |
| | | @Override |
| | | protected ResolvableType getResolvableType() { |
| | | return ResolvableType.forClass(ClassUtils.getUserClass(getClass())); |
| | | } |
| | | |
| | | /** |
| | | * åæ¡æ§è¡æ§è½å·® |
| | | * |
| | | * {@link #saveAll(Collection)} |
| | | */ |
| | | @Deprecated |
| | | @Override |
| | | public boolean saveBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveBatch(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveOrUpdate(T entity) { |
| | | return super.saveOrUpdate(entity); |
| | | } |
| | | |
| | | /** |
| | | * åæ¡æ§è¡æ§è½å·® |
| | | * |
| | | * {@link #saveAll(Collection)} |
| | | */ |
| | | @Deprecated |
| | | @Override |
| | | public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveOrUpdateBatch(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateBatchById(Collection<T> entityList, int batchSize) { |
| | | return super.updateBatchById(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveAll(Collection<T> entityList) { |
| | | return baseMapper.insertAll(entityList) == entityList.size(); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.core.mybatisplus.methods; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import org.apache.ibatis.executor.keygen.NoKeyGenerator; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlSource; |
| | | |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | |
| | | /** |
| | | * åsqlæ¹éæå
¥ |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | public class InsertAll extends AbstractMethod { |
| | | |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | final String sql = "<script>insert into %s %s values %s</script>"; |
| | | final String fieldSql = prepareFieldSql(tableInfo); |
| | | final String valueSql = prepareValuesSqlForMysqlBatch(tableInfo); |
| | | final String sqlResult = String.format(sql, tableInfo.getTableName(), fieldSql, valueSql); |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | return this.addInsertMappedStatement(mapperClass, modelClass, "insertAll", sqlSource, new NoKeyGenerator(), null, null); |
| | | } |
| | | |
| | | private String prepareFieldSql(TableInfo tableInfo) { |
| | | StringBuilder fieldSql = new StringBuilder(); |
| | | if (StrUtil.isNotBlank(tableInfo.getKeyColumn())) { |
| | | fieldSql.append(tableInfo.getKeyColumn()).append(","); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> fieldSql.append(x.getColumn()).append(",")); |
| | | fieldSql.delete(fieldSql.length() - 1, fieldSql.length()); |
| | | fieldSql.insert(0, "("); |
| | | fieldSql.append(")"); |
| | | return fieldSql.toString(); |
| | | } |
| | | |
| | | private String prepareValuesSqlForMysqlBatch(TableInfo tableInfo) { |
| | | final StringBuilder valueSql = new StringBuilder(); |
| | | valueSql.append("<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"(\" separator=\"),(\" close=\")\">"); |
| | | if (StrUtil.isNotBlank(tableInfo.getKeyColumn())) { |
| | | valueSql.append("#{item.").append(tableInfo.getKeyProperty()).append("},"); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> valueSql.append("#{item.").append(x.getProperty()).append("},")); |
| | | valueSql.delete(valueSql.length() - 1, valueSql.length()); |
| | | valueSql.append("</foreach>"); |
| | | return valueSql.toString(); |
| | | } |
| | | } |
| | | |
| | |
| | | package com.ruoyi.common.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * æ°æ®æº |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | public enum DataSourceType |
| | | { |
| | | /** |
| | | * ä¸»åº |
| | | */ |
| | | MASTER, |
| | | @AllArgsConstructor |
| | | public enum DataSourceType { |
| | | /** |
| | | * ä¸»åº |
| | | */ |
| | | MASTER("master"), |
| | | |
| | | /** |
| | | * ä»åº |
| | | */ |
| | | SLAVE |
| | | /** |
| | | * ä»åº |
| | | */ |
| | | SLAVE("slave"); |
| | | |
| | | @Getter |
| | | private final String source; |
| | | } |
| | |
| | | package com.ruoyi.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.ruoyi.common.utils.http.HttpHelper;
|
| | |
|
| | | /**
|
| | | * æå»ºå¯éå¤è¯»åinputStreamçrequest
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
| | | {
|
| | | private final byte[] body;
|
| | |
|
| | | public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException
|
| | | {
|
| | | super(request);
|
| | | request.setCharacterEncoding("UTF-8");
|
| | | response.setCharacterEncoding("UTF-8");
|
| | |
|
| | | body = HttpHelper.getBodyString(request).getBytes("UTF-8");
|
| | | }
|
| | |
|
| | | @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.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | |
| | | import javax.servlet.ReadListener; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * æå»ºå¯éå¤è¯»åinputStreamçrequest |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper |
| | | { |
| | | private final byte[] body; |
| | | |
| | | public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException |
| | | { |
| | | super(request); |
| | | request.setCharacterEncoding("UTF-8"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | |
| | | body = IoUtil.readUtf8(request.getInputStream()).getBytes(StandardCharsets.UTF_8); |
| | | } |
| | | |
| | | @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.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | |
| | |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * XSSè¿æ»¤å¤ç |
| | |
| | | } |
| | | |
| | | // 为空ï¼ç´æ¥è¿å |
| | | String json = IOUtils.toString(super.getInputStream(), "utf-8"); |
| | | String json = IoUtil.read(super.getInputStream(), StandardCharsets.UTF_8); |
| | | if (Validator.isEmpty(json)) |
| | | { |
| | | return super.getInputStream(); |
| | |
| | | |
| | | // xssè¿æ»¤ |
| | | json = HtmlUtil.cleanHtmlTag(json).trim(); |
| | | final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); |
| | | |
| | | final ByteArrayInputStream bis = IoUtil.toStream(json, StandardCharsets.UTF_8); |
| | | return new ServletInputStream() |
| | | { |
| | | @Override |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * JSON å·¥å
·ç±» |
| | | * |
| | | * @author èéæºç |
| | | */ |
| | | public class JsonUtils { |
| | | |
| | | private static ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | /** |
| | | * åå§å objectMapper 屿§ |
| | | * <p> |
| | | * éè¿è¿æ ·çæ¹å¼ï¼ä½¿ç¨ Spring å建ç ObjectMapper Bean |
| | | * |
| | | * @param objectMapper ObjectMapper 对象 |
| | | */ |
| | | public static void init(ObjectMapper objectMapper) { |
| | | JsonUtils.objectMapper = objectMapper; |
| | | } |
| | | |
| | | public static String toJsonString(Object object) { |
| | | if (Validator.isEmpty(object)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return objectMapper.writeValueAsString(object); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static <T> T parseObject(String text, Class<T> clazz) { |
| | | if (StrUtil.isEmpty(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return objectMapper.readValue(text, clazz); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static <T> T parseObject(byte[] bytes, Class<T> clazz) { |
| | | if (ArrayUtil.isEmpty(bytes)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return objectMapper.readValue(bytes, clazz); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static <T> T parseObject(String text, TypeReference<T> typeReference) { |
| | | if (StrUtil.isBlank(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return objectMapper.readValue(text, typeReference); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static <T> Map<String, T> parseMap(String text) { |
| | | if (StrUtil.isBlank(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return objectMapper.readValue(text, new TypeReference<Map<String, T>>() {}); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static <T> List<T> parseArray(String text, Class<T> clazz) { |
| | | if (StrUtil.isEmpty(text)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | try { |
| | | return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | return page; |
| | | } |
| | | |
| | | public static <T> Page<T> buildPage() { |
| | | return buildPage(null, null); |
| | | } |
| | | |
| | | /** |
| | | * æå»º MP æ®éå页对象 |
| | | * @param <T> domain å®ä½ |
| | | * @return å页对象 |
| | | */ |
| | | public static <T> Page<T> buildPage() { |
| | | public static <T> Page<T> buildPage(String defaultOrderByColumn, String defaultIsAsc) { |
| | | Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, DEFAULT_PAGE_NUM); |
| | | Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); |
| | | String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN); |
| | | String isAsc = ServletUtils.getParameter(IS_ASC); |
| | | String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN, defaultOrderByColumn); |
| | | String isAsc = ServletUtils.getParameter(IS_ASC, defaultIsAsc); |
| | | // å
¼å®¹å端æåºç±»å |
| | | if ("ascending".equals(isAsc)) { |
| | | isAsc = "asc"; |
| | | } else if ("descending".equals(isAsc)) { |
| | | isAsc = "desc"; |
| | | } |
| | | Page<T> page = new Page<>(pageNum, pageSize); |
| | | if (StrUtil.isNotBlank(orderByColumn)) { |
| | | String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); |
| | | if ("asc".equals(isAsc)) { |
| | | orderBy = StrUtil.toUnderlineCase(orderBy); |
| | | if ("asc".equals(isAsc)) { |
| | | page.addOrder(OrderItem.asc(orderBy)); |
| | | } else if ("desc".equals(isAsc)) { |
| | | page.addOrder(OrderItem.desc(orderBy)); |
| | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.servlet.ServletUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.context.request.RequestAttributes; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * 客æ·ç«¯å·¥å
·ç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class ServletUtils |
| | | { |
| | | /** |
| | | * è·åStringåæ° |
| | | */ |
| | | public static String getParameter(String name) |
| | | { |
| | | return getRequest().getParameter(name); |
| | | } |
| | | public class ServletUtils extends ServletUtil { |
| | | /** |
| | | * è·å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); |
| | | } |
| | | /** |
| | | * è·å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) { |
| | | return Convert.toInt(getRequest().getParameter(name)); |
| | | } |
| | | |
| | | /** |
| | | * è·åIntegeråæ° |
| | | */ |
| | | public static Integer getParameterToInt(String name, Integer defaultValue) |
| | | { |
| | | return Convert.toInt(getRequest().getParameter(name), defaultValue); |
| | | } |
| | | /** |
| | | * è·åIntegeråæ° |
| | | */ |
| | | public static Integer getParameterToInt(String name, Integer defaultValue) { |
| | | return Convert.toInt(getRequest().getParameter(name), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * è·årequest |
| | | */ |
| | | public static HttpServletRequest getRequest() |
| | | { |
| | | return getRequestAttributes().getRequest(); |
| | | } |
| | | /** |
| | | * è·årequest |
| | | */ |
| | | public static HttpServletRequest getRequest() { |
| | | return getRequestAttributes().getRequest(); |
| | | } |
| | | |
| | | /** |
| | | * è·åresponse |
| | | */ |
| | | public static HttpServletResponse getResponse() |
| | | { |
| | | return getRequestAttributes().getResponse(); |
| | | } |
| | | /** |
| | | * è·åresponse |
| | | */ |
| | | public static HttpServletResponse getResponse() { |
| | | return getRequestAttributes().getResponse(); |
| | | } |
| | | |
| | | /** |
| | | * è·åsession |
| | | */ |
| | | public static HttpSession getSession() |
| | | { |
| | | return getRequest().getSession(); |
| | | } |
| | | /** |
| | | * è·åsession |
| | | */ |
| | | public static HttpSession getSession() { |
| | | return getRequest().getSession(); |
| | | } |
| | | |
| | | public static ServletRequestAttributes getRequestAttributes() |
| | | { |
| | | RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); |
| | | return (ServletRequestAttributes) attributes; |
| | | } |
| | | public static ServletRequestAttributes getRequestAttributes() { |
| | | RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); |
| | | return (ServletRequestAttributes) attributes; |
| | | } |
| | | |
| | | /** |
| | | * å°å符串渲æå°å®¢æ·ç«¯ |
| | | * |
| | | * @param response 渲æå¯¹è±¡ |
| | | * @param string å¾
渲æçå符串 |
| | | * @return null |
| | | */ |
| | | public static String 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(); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * å°å符串渲æå°å®¢æ·ç«¯ |
| | | * |
| | | * @param response 渲æå¯¹è±¡ |
| | | * @param string å¾
渲æçå符串 |
| | | * @return null |
| | | */ |
| | | public static String renderString(HttpServletResponse response, String string) { |
| | | try { |
| | | response.setStatus(HttpStatus.HTTP_OK); |
| | | response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
| | | response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); |
| | | response.getWriter().print(string); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦æ¯Ajax弿¥è¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public static boolean isAjaxRequest(HttpServletRequest request) |
| | | { |
| | | String accept = request.getHeader("accept"); |
| | | if (accept != null && accept.indexOf("application/json") != -1) |
| | | { |
| | | return true; |
| | | } |
| | | /** |
| | | * æ¯å¦æ¯Ajax弿¥è¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public static boolean isAjaxRequest(HttpServletRequest request) { |
| | | |
| | | String xRequestedWith = request.getHeader("X-Requested-With"); |
| | | if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) |
| | | { |
| | | return true; |
| | | } |
| | | String accept = request.getHeader("accept"); |
| | | if (accept != null && accept.indexOf("application/json") != -1) { |
| | | return true; |
| | | } |
| | | |
| | | String uri = request.getRequestURI(); |
| | | if (StrUtil.equalsAnyIgnoreCase(uri, ".json", ".xml")) |
| | | { |
| | | return true; |
| | | } |
| | | String xRequestedWith = request.getHeader("X-Requested-With"); |
| | | if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) { |
| | | return true; |
| | | } |
| | | |
| | | String ajax = request.getParameter("__ajax"); |
| | | if (StrUtil.equalsAnyIgnoreCase(ajax, "json", "xml")) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | String uri = request.getRequestURI(); |
| | | if (StrUtil.equalsAnyIgnoreCase(uri, ".json", ".xml")) { |
| | | return true; |
| | | } |
| | | |
| | | String ajax = request.getParameter("__ajax"); |
| | | if (StrUtil.equalsAnyIgnoreCase(ajax, "json", "xml")) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static String getClientIP() { |
| | | return getClientIP(getRequest()); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | |
| | | |
| | | /** |
| | | * æä»¶å¤çå·¥å
·ç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class FileUtils extends org.apache.commons.io.FileUtils |
| | | public class FileUtils extends FileUtil |
| | | { |
| | | 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 |
| | | { |
| | | if (os != null) |
| | | { |
| | | try |
| | | { |
| | | os.close(); |
| | | } |
| | | catch (IOException e1) |
| | | { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | if (fis != null) |
| | | { |
| | | try |
| | | { |
| | | fis.close(); |
| | | } |
| | | catch (IOException e1) |
| | | { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å 餿件 |
| | | * |
| | | * @param filePath æä»¶ |
| | | * @return |
| | | */ |
| | | public static boolean deleteFile(String filePath) |
| | | { |
| | | boolean flag = false; |
| | | File file = new File(filePath); |
| | | // è·¯å¾ä¸ºæä»¶ä¸ä¸ä¸ºç©ºåè¿è¡å é¤ |
| | | if (file.isFile() && file.exists()) |
| | | { |
| | | file.delete(); |
| | | flag = true; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶åç§°éªè¯ |
| | | * |
| | | * |
| | | * @param filename æä»¶åç§° |
| | | * @return true æ£å¸¸ false éæ³ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * ä¸è½½æä»¶åéæ°ç¼ç |
| | | * |
| | | * |
| | | * @param request 请æ±å¯¹è±¡ |
| | | * @param fileName æä»¶å |
| | | * @return ç¼ç åçæä»¶å |
| | |
| | | if (agent.contains("MSIE")) |
| | | { |
| | | // IEæµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | filename = URLEncoder.encode(filename, StandardCharsets.UTF_8.toString()); |
| | | filename = filename.replace("+", " "); |
| | | } |
| | | else if (agent.contains("Firefox")) |
| | |
| | | else if (agent.contains("Chrome")) |
| | | { |
| | | // googleæµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | filename = URLEncoder.encode(filename, StandardCharsets.UTF_8.toString()); |
| | | } |
| | | else |
| | | { |
| | | // å
¶å®æµè§å¨ |
| | | filename = URLEncoder.encode(filename, "utf-8"); |
| | | filename = URLEncoder.encode(filename, StandardCharsets.UTF_8.toString()); |
| | | } |
| | | return filename; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.ip; |
| | | |
| | | import cn.hutool.core.net.NetUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * è·åå°åç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class AddressUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AddressUtils.class); |
| | | @Slf4j |
| | | public class AddressUtils { |
| | | |
| | | // IPå°åæ¥è¯¢ |
| | | public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; |
| | | // IPå°åæ¥è¯¢ |
| | | public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; |
| | | |
| | | // æªç¥å°å |
| | | public static final String UNKNOWN = "XX XX"; |
| | | // æªç¥å°å |
| | | public static final String UNKNOWN = "XX XX"; |
| | | |
| | | public static String getRealAddressByIP(String ip) |
| | | { |
| | | String address = UNKNOWN; |
| | | // å
ç½ä¸æ¥è¯¢ |
| | | if (IpUtils.internalIp(ip)) |
| | | { |
| | | return "å
ç½IP"; |
| | | } |
| | | if (RuoYiConfig.isAddressEnabled()) |
| | | { |
| | | try |
| | | { |
| | | String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK); |
| | | if (StrUtil.isEmpty(rspStr)) |
| | | { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | return UNKNOWN; |
| | | } |
| | | JSONObject obj = JSONObject.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 address; |
| | | } |
| | | public static String getRealAddressByIP(String ip) { |
| | | String address = UNKNOWN; |
| | | // å
ç½ä¸æ¥è¯¢ |
| | | ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); |
| | | if (NetUtil.isInnerIP(ip)) { |
| | | return "å
ç½IP"; |
| | | } |
| | | if (RuoYiConfig.isAddressEnabled()) { |
| | | try { |
| | | String rspStr = HttpUtil.createGet(IP_URL) |
| | | .body("ip=" + ip + "&json=true", Constants.GBK) |
| | | .execute() |
| | | .body(); |
| | | if (StrUtil.isEmpty(rspStr)) { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | return UNKNOWN; |
| | | } |
| | | Map<String, String> obj = JsonUtils.parseMap(rspStr); |
| | | String region = obj.get("pro"); |
| | | String city = obj.get("city"); |
| | | return String.format("%s %s", region, city); |
| | | } catch (Exception e) { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | } |
| | | } |
| | | return address; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.utils.reflect;
|
| | |
|
| | | import cn.hutool.core.convert.Convert;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | 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 java.lang.reflect.*;
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * åå°å·¥å
·ç±». æä¾è°ç¨getter/setteræ¹æ³, 访é®ç§æåé, è°ç¨ç§ææ¹æ³, è·åæ³åç±»åClass, 被AOPè¿ççå®ç±»çå·¥å
·å½æ°.
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @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.ruoyi.common.utils.reflect; |
| | | |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * åå°å·¥å
·ç±». æä¾è°ç¨getter/setteræ¹æ³, 访é®ç§æåé, è°ç¨ç§ææ¹æ³, è·åæ³åç±»åClass, 被AOPè¿ççå®ç±»çå·¥å
·å½æ°. |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public class ReflectUtils extends ReflectUtil { |
| | | |
| | | private static final String SETTER_PREFIX = "set"; |
| | | |
| | | private static final String GETTER_PREFIX = "get"; |
| | | |
| | | /** |
| | | * è°ç¨Getteræ¹æ³. |
| | | * æ¯æå¤çº§ï¼å¦ï¼å¯¹è±¡å.对象å.æ¹æ³ |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeGetter(Object obj, String propertyName) { |
| | | Object object = obj; |
| | | for (String name : StrUtil.split(propertyName, ".")) { |
| | | String getterMethodName = GETTER_PREFIX + StrUtil.upperFirst(name); |
| | | object = invoke(object, getterMethodName); |
| | | } |
| | | return (E) object; |
| | | } |
| | | |
| | | /** |
| | | * è°ç¨Setteræ¹æ³, ä»
å¹é
æ¹æ³åã |
| | | * æ¯æå¤çº§ï¼å¦ï¼å¯¹è±¡å.对象å.æ¹æ³ |
| | | */ |
| | | public static <E> void invokeSetter(Object obj, String propertyName, E value) { |
| | | Object object = obj; |
| | | List<String> names = StrUtil.split(propertyName, "."); |
| | | for (int i = 0; i < names.size(); i++) { |
| | | if (i < names.size() - 1) { |
| | | String getterMethodName = GETTER_PREFIX + StrUtil.upperFirst(names.get(i)); |
| | | object = invoke(object, getterMethodName); |
| | | } else { |
| | | String setterMethodName = SETTER_PREFIX + StrUtil.upperFirst(names.get(i)); |
| | | Method method = getMethodByName(object.getClass(), setterMethodName); |
| | | invoke(object, method, value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.common.utils.spring; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.extra.spring.SpringUtil; |
| | | 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; |
| | | |
| | | /** |
| | | * springå·¥å
·ç±» æ¹ä¾¿å¨éspring管çç¯å¢ä¸è·åbean |
| | | * |
| | | * @author ruoyi |
| | | * springå·¥å
·ç±» |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware |
| | | { |
| | | /** Springåºç¨ä¸ä¸æç¯å¢ */ |
| | | private static ConfigurableListableBeanFactory beanFactory; |
| | | public final class SpringUtils extends SpringUtil { |
| | | |
| | | private static ApplicationContext applicationContext; |
| | | /** |
| | | * 妿BeanFactoryå
å«ä¸ä¸ªä¸æç»åç§°å¹é
çbeanå®ä¹ï¼åè¿åtrue |
| | | * |
| | | * @param name |
| | | * @return boolean |
| | | */ |
| | | public static boolean containsBean(String name) { |
| | | return getBeanFactory().containsBean(name); |
| | | } |
| | | |
| | | @Override |
| | | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException |
| | | { |
| | | SpringUtils.beanFactory = beanFactory; |
| | | } |
| | | /** |
| | | * 夿以ç»å®ååæ³¨åçbeanå®ä¹æ¯ä¸ä¸ªsingletonè¿æ¯ä¸ä¸ªprototypeã |
| | | * 妿ä¸ç»å®ååç¸åºçbeanå®ä¹æ²¡æè¢«æ¾å°ï¼å°ä¼æåºä¸ä¸ªå¼å¸¸ï¼NoSuchBeanDefinitionExceptionï¼ |
| | | * |
| | | * @param name |
| | | * @return boolean |
| | | */ |
| | | public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { |
| | | return getBeanFactory().isSingleton(name); |
| | | } |
| | | |
| | | @Override |
| | | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException |
| | | { |
| | | SpringUtils.applicationContext = applicationContext; |
| | | } |
| | | /** |
| | | * @param name |
| | | * @return Class 注å对象çç±»å |
| | | */ |
| | | public static Class<?> getType(String name) throws NoSuchBeanDefinitionException { |
| | | return getBeanFactory().getType(name); |
| | | } |
| | | |
| | | /** |
| | | * è·å对象 |
| | | * |
| | | * @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); |
| | | } |
| | | /** |
| | | * 妿ç»å®çbeanååå¨beanå®ä¹ä¸æå«åï¼åè¿åè¿äºå«å |
| | | * |
| | | * @param name |
| | | */ |
| | | public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { |
| | | return getBeanFactory().getAliases(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; |
| | | } |
| | | /** |
| | | * è·åaop代ç对象 |
| | | * |
| | | * @param invoker |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T getAopProxy(T invoker) { |
| | | return (T) AopContext.currentProxy(); |
| | | } |
| | | |
| | | /** |
| | | * 妿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 Validator.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; |
| | | } |
| | | } |
| | |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | |
| | | import java.util.Date; |
| | | |
| | | |
| | | /** |
| | |
| | | @NotBlank(message = "å¼ä¸è½ä¸ºç©º") |
| | | private String value; |
| | | |
| | | /** å建æ¶é´ */ |
| | | @ApiModelProperty("å建æ¶é´") |
| | | private Date createTime; |
| | | |
| | | } |
| | |
| | | package com.ruoyi.demo.controller; |
| | | |
| | | import com.ruoyi.common.annotation.RedisLock; |
| | | import com.baomidou.lock.LockInfo; |
| | | import com.baomidou.lock.LockTemplate; |
| | | import com.baomidou.lock.annotation.Lock4j; |
| | | import com.baomidou.lock.executor.RedissonLockExecutor; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.redis.RedisLockManager; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.time.LocalTime; |
| | | |
| | | |
| | | /** |
| | |
| | | public class RedisLockController { |
| | | |
| | | @Autowired |
| | | private RedisLockManager redisLockManager; |
| | | private LockTemplate lockTemplate; |
| | | |
| | | /** |
| | | * #p0 æ è¯å第ä¸ä¸ªåæ°ä¸ºrediséçkey |
| | | * æµè¯lock4j 注解 |
| | | */ |
| | | @GetMapping("/testLock1") |
| | | @RedisLock(expireTime = 10, key = "#p0") |
| | | public AjaxResult<String> testLock1(String key, String value) { |
| | | @Lock4j(keys = {"#key"}) |
| | | @GetMapping("/testLock4j") |
| | | public AjaxResult<String> testLock4j(String key,String value){ |
| | | System.out.println("start:"+key+",time:"+ LocalTime.now().toString()); |
| | | try { |
| | | // åæ¶è¯·æ±æé |
| | | // Thread.sleep(5000); |
| | | // éè¶
æ¶æµè¯ |
| | | Thread.sleep(11000); |
| | | Thread.sleep(10000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | System.out.println("end :"+key+",time:"+LocalTime.now().toString()); |
| | | return AjaxResult.success("æä½æå",value); |
| | | } |
| | | |
| | | /** |
| | | * æµè¯éå·¥å
·ç±» |
| | | * æµè¯lock4j å·¥å
· |
| | | */ |
| | | @GetMapping("/testLock2") |
| | | public AjaxResult<Void> testLock(String key, Long time) { |
| | | try { |
| | | boolean flag = redisLockManager.getLock(key, time, TimeUnit.SECONDS); |
| | | if (flag) { |
| | | log.info("è·åéæå: " + key); |
| | | Thread.sleep(3000); |
| | | redisLockManager.unLock(key); |
| | | log.info("éæ¾éæå: " + key); |
| | | } else { |
| | | log.error("è·åé失败: " + key); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | log.error(e.getMessage()); |
| | | @GetMapping("/testLock4jLockTemaplate") |
| | | public AjaxResult<String> testLock4jLockTemaplate(String key,String value){ |
| | | final LockInfo lockInfo = lockTemplate.lock(key, 30000L, 5000L, RedissonLockExecutor.class); |
| | | if (null == lockInfo) { |
| | | throw new RuntimeException("ä¸å¡å¤çä¸,请ç¨ååè¯"); |
| | | } |
| | | return AjaxResult.success(); |
| | | // è·åéæåï¼å¤çä¸å¡ |
| | | try { |
| | | try { |
| | | Thread.sleep(8000); |
| | | } catch (InterruptedException e) { |
| | | // |
| | | } |
| | | System.out.println("æ§è¡ç®åæ¹æ³1 , å½å线ç¨:" + Thread.currentThread().getName()); |
| | | } finally { |
| | | //éæ¾é |
| | | lockTemplate.releaseLock(lockInfo); |
| | | } |
| | | //ç»æ |
| | | return AjaxResult.success("æä½æå",value); |
| | | } |
| | | |
| | | /** |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.demo.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.demo.domain.TestDemo; |
| | | import com.ruoyi.demo.service.ITestDemoService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æµè¯æ¹éæ¹æ³ |
| | | * |
| | | * @author Lion Li |
| | | * @date 2021-05-30 |
| | | */ |
| | | @RequiredArgsConstructor(onConstructor_ = @Autowired) |
| | | @RestController |
| | | @RequestMapping("/demo/batch") |
| | | public class TestBatchController extends BaseController { |
| | | |
| | | private final ITestDemoService iTestDemoService; |
| | | |
| | | /** |
| | | * æ°å¢æ¹éæ¹æ³ |
| | | */ |
| | | @PostMapping() |
| | | public AjaxResult<Void> add() { |
| | | List<TestDemo> list = new ArrayList<>(); |
| | | for (int i = 0; i < 1000; i++) { |
| | | list.add(new TestDemo().setOrderNum(-1L).setTestKey("æ¹éæ°å¢").setValue("æµè¯æ°å¢")); |
| | | } |
| | | return toAjax(iTestDemoService.saveAll(list) ? 1 : 0); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹æ¹éæ¹æ³ |
| | | */ |
| | | @DeleteMapping() |
| | | public AjaxResult<Void> edit() { |
| | | return toAjax(iTestDemoService.remove(new LambdaQueryWrapper<TestDemo>() |
| | | .eq(TestDemo::getOrderNum, -1L)) ? 1 : 0); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.demo.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | |
| | | private static final long serialVersionUID=1L; |
| | | |
| | | |
| | | /** ä¸»é® */ |
| | | /** |
| | | * ä¸»é® |
| | | */ |
| | | @TableId(value = "id") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | private Long id; |
| | | |
| | | /** é¨é¨id */ |
| | |
| | | private String updateBy; |
| | | |
| | | /** å 餿 å¿ */ |
| | | @TableLogic |
| | | private Long delFlag; |
| | | |
| | | } |
| | |
| | | package com.ruoyi.demo.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.math.BigDecimal; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | |
| | | /** |
| | | * æµè¯æ 表对象 test_tree |
| | |
| | | |
| | | /** ä¸»é® */ |
| | | @TableId(value = "id") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | private Long id; |
| | | |
| | | /** ç¶id */ |
| | |
| | | package com.ruoyi.demo.feign; |
| | | |
| | | import com.ruoyi.demo.feign.constant.FeignTestConstant; |
| | | import com.ruoyi.demo.feign.fallback.FeignTestFallback; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | |
| | | /** |
| | | * feignæµè¯service |
| | | * |
| | | * è§èæ¥å£ Service æ æè°ç¨ |
| | | * 常é管ç请æ±è·¯å¾ æ´å è§è |
| | | * èªå®ä¹å®¹éå¤ç å®å
¨å¯é |
| | | * @author Lion Li |
| | | */ |
| | | @FeignClient(name = "baidu",url = "http://www.baidu.com",fallback = FeignTestFallback.class) |
| | | @FeignClient( |
| | | name = FeignTestConstant.BAIDU_NAME, |
| | | url = FeignTestConstant.BAIDU_URL, |
| | | fallback = FeignTestFallback.class) |
| | | public interface FeignTestService { |
| | | |
| | | @GetMapping("/s") |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.demo.feign.constant; |
| | | |
| | | public class FeignTestConstant { |
| | | |
| | | public static final String BAIDU_NAME = "baidu"; |
| | | |
| | | public static final String BAIDU_URL = "http://www.baidu.com"; |
| | | |
| | | } |
| | |
| | | package com.ruoyi.demo.mapper; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.MybatisPlusRedisCache; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.cache.MybatisPlusRedisCache; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.demo.domain.TestDemo; |
| | | import org.apache.ibatis.annotations.CacheNamespace; |
| | | |
| | |
| | | * @author Lion Li |
| | | * @date 2021-05-30 |
| | | */ |
| | | // å¦ä½¿éåæ¢æ°æ®æº 请å¿ä½¿ç¨ç¼å ä¼é ææ°æ®ä¸ä¸è´ç°è±¡ |
| | | @CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class) |
| | | public interface TestDemoMapper extends BaseMapperPlus<TestDemo> { |
| | | |
| | |
| | | package com.ruoyi.demo.mapper; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.MybatisPlusRedisCache; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.demo.domain.TestTree; |
| | | import org.apache.ibatis.annotations.CacheNamespace; |
| | | |
| | | /** |
| | | * æµè¯æ 表Mapperæ¥å£ |
| | |
| | | * @author Lion Li |
| | | * @date 2021-05-30 |
| | | */ |
| | | @CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class) |
| | | //@CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class) |
| | | public interface TestTreeMapper extends BaseMapperPlus<TestTree> { |
| | | |
| | | } |
| | |
| | | import com.ruoyi.demo.bo.TestDemoQueryBo; |
| | | import com.ruoyi.demo.bo.TestDemoAddBo; |
| | | import com.ruoyi.demo.bo.TestDemoEditBo; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | import java.util.Collection; |
| | |
| | | * @date 2021-05-30 |
| | | */ |
| | | public interface ITestDemoService extends IServicePlus<TestDemo> { |
| | | |
| | | /** |
| | | * æ¥è¯¢å个 |
| | | * @return |
| | |
| | | package com.ruoyi.demo.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.demo.bo.TestTreeAddBo; |
| | | import com.ruoyi.demo.bo.TestTreeEditBo; |
| | | import com.ruoyi.demo.bo.TestTreeQueryBo; |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.PagePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | * @date 2021-05-30 |
| | | */ |
| | | @Service |
| | | public class TestDemoServiceImpl extends ServiceImpl<TestDemoMapper, TestDemo> implements ITestDemoService { |
| | | public class TestDemoServiceImpl extends ServicePlusImpl<TestDemoMapper, TestDemo> implements ITestDemoService { |
| | | |
| | | @Override |
| | | public TestDemoVo queryById(Long id) { |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.demo.bo.TestTreeAddBo; |
| | | import com.ruoyi.demo.bo.TestTreeEditBo; |
| | | import com.ruoyi.demo.bo.TestTreeQueryBo; |
| | |
| | | * @date 2021-05-30 |
| | | */ |
| | | @Service |
| | | public class TestTreeServiceImpl extends ServiceImpl<TestTreeMapper, TestTree> implements ITestTreeService { |
| | | public class TestTreeServiceImpl extends ServicePlusImpl<TestTreeMapper, TestTree> implements ITestTreeService { |
| | | |
| | | @Override |
| | | public TestTreeVo queryById(Long id) { |
| | | return getVoById(id, TestTreeVo.class); |
| | | } |
| | | |
| | | // @DataSource(DataSourceType.SLAVE) // 忢ä»åºæ¥è¯¢ |
| | | @DataScope(isUser = true) |
| | | @Override |
| | | public List<TestTreeVo> queryList(TestTreeQueryBo bo) { |
| | |
| | | package com.ruoyi.demo.vo; |
| | | |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | |
| | |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ä¸»é® */ |
| | | /** |
| | | * ä¸»é® |
| | | * 妿æ¯èªå®ä¹id æè
éªè±id |
| | | * éè¦å¢å åºåå为å符串注解 å 为Longå°å端ä¼å¤±ç |
| | | */ |
| | | @ApiModelProperty("主é®") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | private Long id; |
| | | |
| | | /** é¨é¨id */ |
| | |
| | | |
| | | /** å建æ¶é´ */ |
| | | @Excel(name = "å建æ¶é´" , width = 30, dateFormat = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("å建æ¶é´") |
| | | private Date createTime; |
| | | |
| | |
| | | |
| | | /** æ´æ°æ¶é´ */ |
| | | @Excel(name = "æ´æ°æ¶é´" , width = 30, dateFormat = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | private Date updateTime; |
| | | |
| | |
| | | package com.ruoyi.demo.vo; |
| | | |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | |
| | |
| | | |
| | | /** ä¸»é® */ |
| | | @ApiModelProperty("主é®") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | private Long id; |
| | | |
| | | /** ç¶id */ |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder; |
| | | 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; |
| | |
| | | |
| | | /** |
| | | * 夿°æ®æºå¤ç |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Aspect |
| | | @Order(1) |
| | | @Order(-500) |
| | | @Component |
| | | public class DataSourceAspect |
| | | { |
| | | protected Logger logger = LoggerFactory.getLogger(getClass()); |
| | | public class DataSourceAspect { |
| | | |
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" |
| | | + "|| @within(com.ruoyi.common.annotation.DataSource)") |
| | | public void dsPointCut() |
| | | { |
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" |
| | | + "|| @within(com.ruoyi.common.annotation.DataSource)") |
| | | public void dsPointCut() { |
| | | } |
| | | |
| | | } |
| | | @Around("dsPointCut()") |
| | | public Object around(ProceedingJoinPoint point) throws Throwable { |
| | | DataSource dataSource = getDataSource(point); |
| | | |
| | | @Around("dsPointCut()") |
| | | public Object around(ProceedingJoinPoint point) throws Throwable |
| | | { |
| | | DataSource dataSource = getDataSource(point); |
| | | if (Validator.isNotNull(dataSource)) { |
| | | DynamicDataSourceContextHolder.poll(); |
| | | String source = dataSource.value().getSource(); |
| | | DynamicDataSourceContextHolder.push(source); |
| | | } |
| | | |
| | | if (Validator.isNotNull(dataSource)) |
| | | { |
| | | DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); |
| | | } |
| | | try { |
| | | return point.proceed(); |
| | | } finally { |
| | | // éæ¯æ°æ®æº 卿§è¡æ¹æ³ä¹å |
| | | DynamicDataSourceContextHolder.clear(); |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * è·åéè¦åæ¢çæ°æ®æº |
| | | */ |
| | | 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); |
| | | } |
| | | return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | | import com.ruoyi.common.enums.HttpMethod; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.AsyncService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | import org.aspectj.lang.JoinPoint; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | SysOperLog operLog = new SysOperLog(); |
| | | operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | | // 请æ±çå°å |
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); |
| | | String ip = ServletUtils.getClientIP(); |
| | | operLog.setOperIp(ip); |
| | | // è¿ååæ° |
| | | operLog.setJsonResult(JSON.toJSONString(jsonResult)); |
| | | operLog.setJsonResult(JsonUtils.toJsonString(jsonResult)); |
| | | |
| | | operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); |
| | | if (loginUser != null) |
| | |
| | | // å¤ç设置注解ä¸çåæ° |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog); |
| | | // ä¿åæ°æ®åº |
| | | AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); |
| | | SpringUtils.getBean(AsyncService.class).recordOper(operLog); |
| | | } |
| | | catch (Exception exp) |
| | | { |
| | |
| | | */ |
| | | private String argsArrayToString(Object[] paramsArray) |
| | | { |
| | | String params = ""; |
| | | StringBuilder params = new StringBuilder(); |
| | | if (paramsArray != null && paramsArray.length > 0) |
| | | { |
| | | for (int i = 0; i < paramsArray.length; i++) |
| | | { |
| | | if (Validator.isNotNull(paramsArray[i]) && !isFilterObject(paramsArray[i])) |
| | | { |
| | | Object jsonObj = JSON.toJSON(paramsArray[i]); |
| | | params += jsonObj.toString() + " "; |
| | | } |
| | | } |
| | | for (Object o : paramsArray) { |
| | | if (Validator.isNotNull(o) && !isFilterObject(o)) { |
| | | params.append(JsonUtils.toJsonString(o)).append(" "); |
| | | } |
| | | } |
| | | } |
| | | return params.trim(); |
| | | return params.toString().trim(); |
| | | } |
| | | |
| | | /** |
| | |
| | | else if (Collection.class.isAssignableFrom(clazz)) |
| | | { |
| | | Collection collection = (Collection) o; |
| | | for (Iterator iter = collection.iterator(); iter.hasNext();) |
| | | { |
| | | return iter.next() instanceof MultipartFile; |
| | | } |
| | | for (Object value : collection) { |
| | | return value instanceof MultipartFile; |
| | | } |
| | | } |
| | | else if (Map.class.isAssignableFrom(clazz)) |
| | | { |
| | | Map map = (Map) o; |
| | | for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) |
| | | { |
| | | Map.Entry entry = (Map.Entry) iter.next(); |
| | | return entry.getValue() instanceof MultipartFile; |
| | | } |
| | | 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; |
| | |
| | | |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.AsyncConfigurerSupport; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | |
| | | /** |
| | | * 弿¥é
ç½® |
| | |
| | | @Configuration |
| | | public class AsyncConfig extends AsyncConfigurerSupport { |
| | | |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | |
| | | /** |
| | | * 弿¥æ§è¡éè¦ä½¿ç¨æéæ¡æ¶èªå¸¦çå
è£
çº¿ç¨æ± ä¿è¯æéä¿¡æ¯çä¼ é |
| | | */ |
| | | @Override |
| | | public Executor getAsyncExecutor() { |
| | | return new DelegatingSecurityContextExecutorService( |
| | | Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); |
| | | return new DelegatingSecurityContextExecutorService(scheduledExecutorService); |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.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 com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; |
| | | import com.alibaba.druid.util.Utils; |
| | | 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.ruoyi.common.enums.DataSourceType; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.config.properties.DruidProperties; |
| | | import com.ruoyi.framework.datasource.DynamicDataSource; |
| | | |
| | | import javax.servlet.*; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * druid é
ç½®å¤æ°æ®æº |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @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) |
| | | { |
| | | } |
| | | } |
| | | public class DruidConfig { |
| | | |
| | | /** |
| | | * å»é¤çæ§é¡µé¢åºé¨ç广å |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import feign.*; |
| | | import feign.hystrix.HystrixFeign; |
| | | import okhttp3.ConnectionPool; |
| | | import okhttp3.OkHttpClient; |
| | | import org.springframework.boot.autoconfigure.AutoConfigureBefore; |
| | |
| | | } |
| | | |
| | | @Bean |
| | | public Feign.Builder feignBuilder() { |
| | | return HystrixFeign.builder(); |
| | | } |
| | | |
| | | @Bean |
| | | public Contract feignContract() { |
| | | return new SpringMvcContract(); |
| | | } |
| | |
| | | return new Retryer.Default(); |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | FilterRegistrationBean registration = new FilterRegistrationBean(); |
| | | registration.setDispatcherTypes(DispatcherType.REQUEST); |
| | | registration.setFilter(new XssFilter()); |
| | | registration.addUrlPatterns(StrUtil.split(xssProperties.getUrlPatterns(), ",")); |
| | | registration.addUrlPatterns(StrUtil.splitToArray(xssProperties.getUrlPatterns(), ",")); |
| | | registration.setName("xssFilter"); |
| | | registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); |
| | | Map<String, String> initParameters = new HashMap<String, String>(); |
| | |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.module.SimpleModule; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; |
| | | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.beans.factory.config.BeanPostProcessor; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.TimeZone; |
| | | |
| | | /** |
| | | * å½Mybatis plus设置为éªè±IDæ¶ |
| | | * ä½¿ç¨æ¤ç±»ï¼ä¼ææææ°åè¿åå为å符串è¿åéé
å端Longå失çé®é¢ |
| | | * jackson é
ç½® |
| | | * |
| | | * @author Ming LI |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @Configuration |
| | | public class JacksonConfig { |
| | | |
| | | @Bean |
| | | @Primary |
| | | @ConditionalOnMissingBean(ObjectMapper.class) |
| | | @ConditionalOnProperty(value = "mybatis-plus.global-config.dbConfig.idType", havingValue = "ASSIGN_ID") |
| | | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // å
¨å±é
ç½®åºååè¿å JSON å¤ç |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | //JSON Long ==> String |
| | | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
| | | objectMapper.registerModule(simpleModule); |
| | | return objectMapper; |
| | | public BeanPostProcessor objectMapperBeanPostProcessor() { |
| | | return new BeanPostProcessor() { |
| | | @Override |
| | | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| | | if (!(bean instanceof ObjectMapper)) { |
| | | return bean; |
| | | } |
| | | ObjectMapper objectMapper = (ObjectMapper) bean; |
| | | // å
¨å±é
ç½®åºååè¿å JSON å¤ç |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | simpleModule.addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE); |
| | | simpleModule.addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); |
| | | objectMapper.registerModule(simpleModule); |
| | | objectMapper.setTimeZone(TimeZone.getDefault()); |
| | | JsonUtils.init(objectMapper); |
| | | log.info("åå§å jackson é
ç½®"); |
| | | return bean; |
| | | } |
| | | }; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.annotation.DbType; |
| | | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; |
| | | import com.baomidou.mybatisplus.core.injector.ISqlInjector; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
| | | import com.ruoyi.common.core.mybatisplus.methods.InsertAll; |
| | | import com.ruoyi.framework.mybatisplus.CreateAndUpdateMetaObjectHandler; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * mybatis-plusé
置类 |
| | |
| | | * sql注å
¥å¨é
ç½® |
| | | * https://baomidou.com/guide/sql-injector.html |
| | | */ |
| | | // @Bean |
| | | // public ISqlInjector sqlInjector() { |
| | | // return new DefaultSqlInjector(); |
| | | // } |
| | | @Bean |
| | | public ISqlInjector sqlInjector() { |
| | | return new DefaultSqlInjector() { |
| | | @Override |
| | | public List<AbstractMethod> getMethodList(Class<?> mapperClass) { |
| | | List<AbstractMethod> methodList = super.getMethodList(mapperClass); |
| | | methodList.add(new InsertAll()); |
| | | return methodList; |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * TenantLineInnerInterceptor å¤ç§æ·æä»¶ |
| | |
| | | { |
| | | /** æ¬å°æä»¶ä¸ä¼ è·¯å¾ */ |
| | | registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); |
| | | |
| | | /** swaggeré
ç½® */ |
| | | registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); |
| | | } |
| | | |
| | | /** |
| | |
| | | CorsConfiguration config = new CorsConfiguration(); |
| | | config.setAllowCredentials(true); |
| | | // è®¾ç½®è®¿é®æºå°å |
| | | config.addAllowedOrigin("*"); |
| | | config.addAllowedOriginPattern("*"); |
| | | // è®¾ç½®è®¿é®æºè¯·æ±å¤´ |
| | | config.addAllowedHeader("*"); |
| | | // è®¾ç½®è®¿é®æºè¯·æ±æ¹æ³ |
| | |
| | | |
| | | /** |
| | | * spring securityé
ç½® |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) |
| | |
| | | */ |
| | | @Autowired |
| | | private UserDetailsService userDetailsService; |
| | | |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥å¤çç±» |
| | | */ |
| | |
| | | |
| | | @Autowired |
| | | private AdminServerProperties adminServerProperties; |
| | | |
| | | |
| | | /** |
| | | * è§£å³ æ æ³ç´æ¥æ³¨å
¥ AuthenticationManager |
| | | * |
| | |
| | | .antMatchers("/profile/**").anonymous() |
| | | .antMatchers("/common/download**").anonymous() |
| | | .antMatchers("/common/download/resource**").anonymous() |
| | | .antMatchers("/swagger-ui.html").anonymous() |
| | | .antMatchers("/doc.html").anonymous() |
| | | .antMatchers("/swagger-resources/**").anonymous() |
| | | .antMatchers("/webjars/**").anonymous() |
| | | .antMatchers("/*/api-docs").anonymous() |
| | |
| | | httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 强æ£ååå¸å å¯å®ç° |
| | | */ |
| | |
| | | package com.ruoyi.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.handler.HandlerInterceptorAdapter;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.annotation.RepeatSubmit;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | |
|
| | | /**
|
| | | * 鲿¢éå¤æäº¤æ¦æªå¨
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
|
| | | {
|
| | | @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))
|
| | | {
|
| | | AjaxResult ajaxResult = AjaxResult.error("ä¸å
许éå¤æäº¤ï¼è¯·ç¨ååè¯");
|
| | | ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult));
|
| | | return false;
|
| | | }
|
| | | }
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | return super.preHandle(request, response, handler);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * éªè¯æ¯å¦éå¤æäº¤ç±åç±»å®ç°å
·ä½çé²éå¤æäº¤çè§å
|
| | | *
|
| | | * @param request
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public abstract boolean isRepeatSubmit(HttpServletRequest request);
|
| | | }
|
| | | package com.ruoyi.framework.interceptor; |
| | | |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | |
| | | /** |
| | | * 鲿¢éå¤æäº¤æ¦æªå¨ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter |
| | | { |
| | | @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)) |
| | | { |
| | | AjaxResult ajaxResult = AjaxResult.error("ä¸å
许éå¤æäº¤ï¼è¯·ç¨ååè¯"); |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(ajaxResult)); |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return super.preHandle(request, response, handler); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éªè¯æ¯å¦éå¤æäº¤ç±åç±»å®ç°å
·ä½çé²éå¤æäº¤çè§å |
| | | * |
| | | * @param request |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public abstract boolean isRepeatSubmit(HttpServletRequest request); |
| | | } |
| | |
| | | package com.ruoyi.framework.interceptor.impl;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
|
| | | import com.ruoyi.common.utils.http.HttpHelper;
|
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
|
| | | /**
|
| | | * å¤æè¯·æ±urlåæ°æ®æ¯å¦åä¸ä¸æ¬¡ç¸åï¼
|
| | | * 妿å䏿¬¡ç¸åï¼åæ¯éå¤æäº¤è¡¨åã æææ¶é´ä¸º10ç§å
ã
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @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;
|
| | |
|
| | | /**
|
| | | * é´éæ¶é´ï¼åä½:ç§ é»è®¤10ç§
|
| | | * |
| | | * 两次ç¸ååæ°ç请æ±ï¼å¦æé´éæ¶é´å¤§äºè¯¥åæ°ï¼ç³»ç»ä¸ä¼è®¤å®ä¸ºéå¤æäº¤çæ°æ®
|
| | | */
|
| | | private int intervalTime = 10;
|
| | |
|
| | | public void setIntervalTime(int intervalTime)
|
| | | {
|
| | | this.intervalTime = intervalTime;
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public boolean isRepeatSubmit(HttpServletRequest request)
|
| | | {
|
| | | String nowParams = "";
|
| | | if (request instanceof RepeatedlyRequestWrapper)
|
| | | {
|
| | | RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request;
|
| | | nowParams = HttpHelper.getBodyString(repeatedlyRequest);
|
| | | }
|
| | |
|
| | | // bodyåæ°ä¸ºç©ºï¼è·åParameterçæ°æ®
|
| | | if (Validator.isEmpty(nowParams))
|
| | | {
|
| | | nowParams = JSONObject.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 = request.getHeader(header);
|
| | | if (Validator.isEmpty(submitKey))
|
| | | {
|
| | | submitKey = url;
|
| | | }
|
| | |
|
| | | // å¯ä¸æ è¯ï¼æå®key + æ¶æ¯å¤´ï¼
|
| | | String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + 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))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | }
|
| | | Map<String, Object> cacheMap = new HashMap<String, Object>();
|
| | | cacheMap.put(url, nowDataMap);
|
| | | redisCache.setCacheObject(cacheRepeatKey, cacheMap, intervalTime, TimeUnit.SECONDS);
|
| | | 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)
|
| | | {
|
| | | long time1 = (Long) nowMap.get(REPEAT_TIME);
|
| | | long time2 = (Long) preMap.get(REPEAT_TIME);
|
| | | if ((time1 - time2) < (this.intervalTime * 1000))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|
| | | package com.ruoyi.framework.interceptor.impl; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.filter.RepeatedlyRequestWrapper; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * å¤æè¯·æ±urlåæ°æ®æ¯å¦åä¸ä¸æ¬¡ç¸åï¼ |
| | | * 妿å䏿¬¡ç¸åï¼åæ¯éå¤æäº¤è¡¨åã æææ¶é´ä¸º10ç§å
ã |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | @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; |
| | | |
| | | /** |
| | | * é´éæ¶é´ï¼åä½:ç§ é»è®¤10ç§ |
| | | * |
| | | * 两次ç¸ååæ°ç请æ±ï¼å¦æé´éæ¶é´å¤§äºè¯¥åæ°ï¼ç³»ç»ä¸ä¼è®¤å®ä¸ºéå¤æäº¤çæ°æ® |
| | | */ |
| | | private int intervalTime = 10; |
| | | |
| | | public void setIntervalTime(int intervalTime) |
| | | { |
| | | this.intervalTime = intervalTime; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public boolean isRepeatSubmit(HttpServletRequest request) |
| | | { |
| | | String nowParams = ""; |
| | | if (request instanceof RepeatedlyRequestWrapper) |
| | | { |
| | | RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; |
| | | try { |
| | | nowParams = IoUtil.readUtf8(repeatedlyRequest.getInputStream()); |
| | | } catch (IOException e) { |
| | | log.warn("è¯»åæµåºç°é®é¢ï¼"); |
| | | } |
| | | } |
| | | |
| | | // bodyåæ°ä¸ºç©ºï¼è·åParameterçæ°æ® |
| | | if (Validator.isEmpty(nowParams)) |
| | | { |
| | | nowParams = JsonUtils.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 = request.getHeader(header); |
| | | if (Validator.isEmpty(submitKey)) |
| | | { |
| | | submitKey = url; |
| | | } |
| | | |
| | | // å¯ä¸æ è¯ï¼æå®key + æ¶æ¯å¤´ï¼ |
| | | String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + 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)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> cacheMap = new HashMap<String, Object>(); |
| | | cacheMap.put(url, nowDataMap); |
| | | redisCache.setCacheObject(cacheRepeatKey, cacheMap, intervalTime, TimeUnit.SECONDS); |
| | | 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) |
| | | { |
| | | long time1 = (Long) nowMap.get(REPEAT_TIME); |
| | | long time2 = (Long) preMap.get(REPEAT_TIME); |
| | | if ((time1 - time2) < (this.intervalTime * 1000)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.manager; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.utils.Threads; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | |
| | | /** |
| | | * ç¡®ä¿åºç¨éåºæ¶è½å
³éåå°çº¿ç¨ |
| | | * |
| | | * @author ruoyi |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j(topic = "sys-user") |
| | | @Component |
| | | public class ShutdownManager |
| | | { |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | public class ShutdownManager { |
| | | |
| | | @PreDestroy |
| | | public void destroy() |
| | | { |
| | | shutdownAsyncManager(); |
| | | } |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | |
| | | /** |
| | | * 忢弿¥æ§è¡ä»»å¡ |
| | | */ |
| | | private void shutdownAsyncManager() |
| | | { |
| | | try |
| | | { |
| | | logger.info("====å
³éåå°ä»»å¡ä»»å¡çº¿ç¨æ± ===="); |
| | | AsyncManager.me().shutdown(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | @PreDestroy |
| | | public void destroy() { |
| | | shutdownAsyncManager(); |
| | | } |
| | | |
| | | /** |
| | | * 忢弿¥æ§è¡ä»»å¡ |
| | | */ |
| | | private void shutdownAsyncManager() { |
| | | try { |
| | | log.info("====å
³éåå°ä»»å¡ä»»å¡çº¿ç¨æ± ===="); |
| | | Threads.shutdownAndAwaitTermination(scheduledExecutorService); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import org.springframework.security.core.AuthenticationException; |
| | | import org.springframework.security.web.AuthenticationEntryPoint; |
| | |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥å¤çç±» è¿åæªææ |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | |
| | | { |
| | | int code = HttpStatus.HTTP_UNAUTHORIZED; |
| | | String msg = StrUtil.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(code, msg))); |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.AsyncService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | |
| | | /** |
| | | * èªå®ä¹éåºå¤çç±» è¿åæå |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Configuration |
| | | public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler |
| | | { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { |
| | | |
| | | /** |
| | | * éåºå¤ç |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
| | | throws IOException, ServletException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (Validator.isNotNull(loginUser)) |
| | | { |
| | | String userName = loginUser.getUsername(); |
| | | // å é¤ç¨æ·ç¼åè®°å½ |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // è®°å½ç¨æ·éåºæ¥å¿ |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "éåºæå")); |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.HTTP_OK, "éåºæå"))); |
| | | } |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private AsyncService asyncService; |
| | | |
| | | /** |
| | | * éåºå¤ç |
| | | */ |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
| | | throws IOException, ServletException { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (Validator.isNotNull(loginUser)) { |
| | | String userName = loginUser.getUsername(); |
| | | // å é¤ç¨æ·ç¼åè®°å½ |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // è®°å½ç¨æ·éåºæ¥å¿ |
| | | asyncService.recordLogininfor(userName, Constants.LOGOUT, "éåºæå", request); |
| | | } |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(HttpStatus.HTTP_OK, "éåºæå"))); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import cn.hutool.http.useragent.UserAgent; |
| | | import cn.hutool.http.useragent.UserAgentUtil; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | import com.ruoyi.system.service.ISysLogininforService; |
| | | import com.ruoyi.system.service.ISysOperLogService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * 弿¥å·¥åï¼äº§çä»»å¡ç¨ï¼ |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j(topic = "sys-user") |
| | | @Async |
| | | @Component |
| | | public class AsyncService { |
| | | |
| | | @Autowired |
| | | private ISysLogininforService iSysLogininforService; |
| | | |
| | | @Autowired |
| | | private ISysOperLogService iSysOperLogService; |
| | | |
| | | /** |
| | | * è®°å½ç»å½ä¿¡æ¯ |
| | | * |
| | | * @param username ç¨æ·å |
| | | * @param status ç¶æ |
| | | * @param message æ¶æ¯ |
| | | * @param args å表 |
| | | */ |
| | | public void recordLogininfor(final String username, final String status, final String message, |
| | | HttpServletRequest request, final Object... args) { |
| | | final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); |
| | | final String ip = ServletUtils.getClientIP(request); |
| | | |
| | | String address = AddressUtils.getRealAddressByIP(ip); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(getBlock(ip)); |
| | | s.append(address); |
| | | s.append(getBlock(username)); |
| | | s.append(getBlock(status)); |
| | | s.append(getBlock(message)); |
| | | // æå°ä¿¡æ¯å°æ¥å¿ |
| | | log.info(s.toString(), args); |
| | | // è·å客æ·ç«¯æä½ç³»ç» |
| | | String os = userAgent.getOs().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 (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) { |
| | | logininfor.setStatus(Constants.SUCCESS); |
| | | } else if (Constants.LOGIN_FAIL.equals(status)) { |
| | | logininfor.setStatus(Constants.FAIL); |
| | | } |
| | | // æå
¥æ°æ® |
| | | iSysLogininforService.insertLogininfor(logininfor); |
| | | } |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½ |
| | | * |
| | | * @param operLog æä½æ¥å¿ä¿¡æ¯ |
| | | */ |
| | | public void recordOper(final SysOperLog operLog) { |
| | | // è¿ç¨æ¥è¯¢æä½å°ç¹ |
| | | operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); |
| | | iSysOperLogService.insertOperlog(operLog); |
| | | } |
| | | |
| | | private String getBlock(Object msg) { |
| | | if (msg == null) { |
| | | msg = ""; |
| | | } |
| | | return "[" + msg.toString() + "]"; |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.framework.config.properties.CaptchaProperties; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * ç»å½æ ¡éªæ¹æ³ |
| | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private AsyncService asyncService; |
| | | |
| | | /** |
| | | * ç»å½éªè¯ |
| | | * |
| | |
| | | */ |
| | | public String login(String username, String password, String code, String uuid) |
| | | { |
| | | HttpServletRequest request = ServletUtils.getRequest(); |
| | | if(captchaProperties.getEnabled()) { |
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request); |
| | | throw new CaptchaException(); |
| | | } |
| | | } |
| | |
| | | { |
| | | if (e instanceof BadCredentialsException) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request); |
| | | throw new UserPasswordNotMatchException(); |
| | | } |
| | | else |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request); |
| | | throw new CustomException(e.getMessage()); |
| | | } |
| | | } |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request); |
| | | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| | | recordLoginInfo(loginUser.getUser()); |
| | | // çætoken |
| | |
| | | */ |
| | | public void recordLoginInfo(SysUser user) |
| | | { |
| | | user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); |
| | | user.setLoginIp(ServletUtils.getClientIP()); |
| | | user.setLoginDate(DateUtils.getNowDate()); |
| | | user.setUpdateBy(user.getUserName()); |
| | | userService.updateUserProfile(user); |
| | |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.framework.config.properties.TokenProperties; |
| | | import io.jsonwebtoken.Claims; |
| | | import io.jsonwebtoken.Jwts; |
| | |
| | | */ |
| | | public void setUserAgent(LoginUser loginUser) { |
| | | UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); |
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); |
| | | String ip = ServletUtils.getClientIP(); |
| | | loginUser.setIpaddr(ip); |
| | | loginUser.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); |
| | | loginUser.setBrowser(userAgent.getBrowser().getName()); |
| | |
| | | package com.ruoyi.generator.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.generator.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService { |
| | | public class GenTableColumnServiceImpl extends ServicePlusImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService { |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¸å¡å段å表 |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService { |
| | | public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTable> implements IGenTableService { |
| | | |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | |
| | | @Override |
| | | @Transactional |
| | | public void updateGenTable(GenTable genTable) { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | String options = JsonUtils.toJsonString(genTable.getParams()); |
| | | genTable.setOptions(options); |
| | | int row = baseMapper.updateById(genTable); |
| | | if (row > 0) { |
| | |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8); |
| | | } catch (IOException e) { |
| | | throw new CustomException("æ¸²ææ¨¡æ¿å¤±è´¥ï¼è¡¨åï¼" + table.getTableName()); |
| | | } |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeUtf8String(sw.toString(), path); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public void validateEdit(GenTable genTable) { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { |
| | | Map<String, Object> paramsObj = genTable.getParams(); |
| | | if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { |
| | | throw new CustomException("æ ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { |
| | | } else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) { |
| | | throw new CustomException("æ ç¶ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { |
| | | } else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) { |
| | | throw new CustomException("æ åç§°åæ®µä¸è½ä¸ºç©º"); |
| | | } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { |
| | | if (Validator.isEmpty(genTable.getSubTableName())) { |
| | |
| | | * @param genTable 设置åççæå¯¹è±¡ |
| | | */ |
| | | public void setTableFromOptions(GenTable genTable) { |
| | | JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions()); |
| | | if (Validator.isNotNull(paramsObj)) { |
| | | String treeCode = paramsObj.getString(GenConstants.TREE_CODE); |
| | | String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); |
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME); |
| | | String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); |
| | | String treeCode = Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)); |
| | | String treeParentCode = Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)); |
| | | String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); |
| | | String parentMenuId = Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); |
| | | String parentMenuName = Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_NAME)); |
| | | |
| | | genTable.setTreeCode(treeCode); |
| | | genTable.setTreeParentCode(treeParentCode); |
| | |
| | | /** |
| | | * è·å代ç çæå°å |
| | | * |
| | | * @param table ä¸å¡è¡¨ä¿¡æ¯ |
| | | * @param table ä¸å¡è¡¨ä¿¡æ¯ |
| | | * @param template æ¨¡æ¿æä»¶è·¯å¾ |
| | | * @return çæå°å |
| | | */ |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | |
| | |
| | | |
| | | /** |
| | | * 代ç çæå¨ å·¥å
·ç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class GenUtils |
| | |
| | | column.setHtmlType(GenConstants.HTML_INPUT); |
| | | |
| | | // å¦ææ¯æµ®ç¹å ç»ä¸ç¨BigDecimal |
| | | String[] str = StrUtil.split(StrUtil.subBetween(column.getColumnType(), "(", ")"), ","); |
| | | String[] str = StrUtil.splitToArray(StrUtil.subBetween(column.getColumnType(), "(", ")"), ","); |
| | | if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_BIGDECIMAL); |
| | |
| | | |
| | | /** |
| | | * æ ¡éªæ°ç»æ¯å¦å
嫿å®å¼ |
| | | * |
| | | * |
| | | * @param arr æ°ç» |
| | | * @param targetValue å¼ |
| | | * @return æ¯å¦å
å« |
| | |
| | | |
| | | /** |
| | | * è·å模åå |
| | | * |
| | | * |
| | | * @param packageName å
å |
| | | * @return 模åå |
| | | */ |
| | |
| | | |
| | | /** |
| | | * è·åä¸å¡å |
| | | * |
| | | * |
| | | * @param tableName 表å |
| | | * @return ä¸å¡å |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 表åè½¬æ¢æJavaç±»å |
| | | * |
| | | * |
| | | * @param tableName 表åç§° |
| | | * @return ç±»å |
| | | */ |
| | |
| | | String tablePrefix = GenConfig.getTablePrefix(); |
| | | if (autoRemovePre && StrUtil.isNotEmpty(tablePrefix)) |
| | | { |
| | | String[] searchList = StrUtil.split(tablePrefix, ","); |
| | | String[] searchList = StrUtil.splitToArray(tablePrefix, ","); |
| | | tableName = replaceFirst(tableName, searchList); |
| | | } |
| | | return StrUtil.upperFirst(StrUtil.toCamelCase(tableName)); |
| | |
| | | |
| | | /** |
| | | * æ¹éæ¿æ¢åç¼ |
| | | * |
| | | * |
| | | * @param replacementm æ¿æ¢å¼ |
| | | * @param searchList æ¿æ¢å表 |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * å
³é®åæ¿æ¢ |
| | | * |
| | | * |
| | | * @param text éè¦è¢«æ¿æ¢çåå |
| | | * @return æ¿æ¢åçåå |
| | | */ |
| | |
| | | |
| | | /** |
| | | * è·åæ°æ®åºç±»ååæ®µ |
| | | * |
| | | * |
| | | * @param columnType åç±»å |
| | | * @return æªååçåç±»å |
| | | */ |
| | |
| | | |
| | | /** |
| | | * è·ååæ®µé¿åº¦ |
| | | * |
| | | * |
| | | * @param columnType åç±»å |
| | | * @return æªååçåç±»å |
| | | */ |
| | |
| | | package com.ruoyi.generator.util; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import org.apache.velocity.VelocityContext; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 模æ¿å¤çå·¥å
·ç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class VelocityUtils |
| | |
| | | public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | String parentMenuId = getParentMenuId(paramsObj); |
| | | context.put("parentMenuId", parentMenuId); |
| | | } |
| | |
| | | public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | String treeCode = getTreecode(paramsObj); |
| | | String treeParentCode = getTreeParentCode(paramsObj); |
| | | String treeName = getTreeName(paramsObj); |
| | |
| | | context.put("expandColumn", getExpandColumn(genTable)); |
| | | if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE)); |
| | | } |
| | | if (paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); |
| | | context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME)); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return ä¸çº§èåIDåæ®µ |
| | | */ |
| | | public static String getParentMenuId(JSONObject paramsObj) |
| | | public static String getParentMenuId(Map<String, Object> paramsObj) |
| | | { |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) |
| | | { |
| | | return paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); |
| | | } |
| | | return DEFAULT_PARENT_MENU_ID; |
| | | } |
| | |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ ç¼ç |
| | | */ |
| | | public static String getTreecode(JSONObject paramsObj) |
| | | public static String getTreecode(Map<String, Object> paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_CODE)) |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) |
| | | { |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | } |
| | |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ ç¶ç¼ç |
| | | */ |
| | | public static String getTreeParentCode(JSONObject paramsObj) |
| | | public static String getTreeParentCode(Map<String, Object> paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | } |
| | |
| | | * @param paramsObj çæå
¶ä»é项 |
| | | * @return æ åç§° |
| | | */ |
| | | public static String getTreeName(JSONObject paramsObj) |
| | | public static String getTreeName(Map<String, Object> paramsObj) |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | } |
| | |
| | | public static int getExpandColumn(GenTable genTable) |
| | | { |
| | | String options = genTable.getOptions(); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); |
| | | int num = 0; |
| | | for (GenTableColumn column : genTable.getColumns()) |
| | | { |
| | |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import java.util.Date; |
| | | import javax.validation.constraints.*; |
| | |
| | | |
| | | /** $column.columnComment */ |
| | | @ApiModelProperty("$column.columnComment") |
| | | #if($column.javaType == 'Date') |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | #end |
| | | #if($column.isRequired==1) |
| | | #if($column.javaType == 'String') |
| | | @NotBlank(message = "$column.columnCommentä¸è½ä¸ºç©º") |
| | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.math.BigDecimal; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | |
| | | /** |
| | | * ${functionName}对象 ${tableName} |
| | |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import java.util.Date; |
| | | import javax.validation.constraints.*; |
| | |
| | | |
| | | /** $column.columnComment */ |
| | | @ApiModelProperty("$column.columnComment") |
| | | #if($column.javaType == 'Date') |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | #end |
| | | #if($column.isRequired==1) |
| | | #if($column.javaType == 'String') |
| | | @NotBlank(message = "$column.columnCommentä¸è½ä¸ºç©º") |
| | |
| | | package ${packageName}.mapper; |
| | | |
| | | import ${packageName}.domain.${ClassName}; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.MybatisPlusRedisCache; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.cache.MybatisPlusRedisCache; |
| | | import org.apache.ibatis.annotations.CacheNamespace; |
| | | |
| | | /** |
| | |
| | | * @author ${author} |
| | | * @date ${datetime} |
| | | */ |
| | | // å¦ä½¿éåæ¢æ°æ®æº 请å¿ä½¿ç¨ç¼å ä¼é ææ°æ®ä¸ä¸è´ç°è±¡ |
| | | @CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class) |
| | | public interface ${ClassName}Mapper extends BaseMapperPlus<${ClassName}> { |
| | | |
| | |
| | | #foreach ($column in $columns) |
| | | #if(!$table.isSuperColumn($column.javaField) && $column.query) |
| | | /** $column.columnComment */ |
| | | #if($column.javaType == 'Date') |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | #end |
| | | @ApiModelProperty("$column.columnComment") |
| | | private $column.javaType $column.javaField; |
| | | #end |
| | |
| | | import ${packageName}.bo.${ClassName}QueryBo; |
| | | import ${packageName}.bo.${ClassName}AddBo; |
| | | import ${packageName}.bo.${ClassName}EditBo; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | #if($table.crud || $table.sub) |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | #end |
| | |
| | | * @param isValid æ¯å¦æ ¡éª,true-å é¤åæ ¡éª,false-䏿 ¡éª |
| | | * @return |
| | | */ |
| | | Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); |
| | | Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid); |
| | | } |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | #end |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import ${packageName}.bo.${ClassName}AddBo; |
| | |
| | | * @date ${datetime} |
| | | */ |
| | | @Service |
| | | public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { |
| | | public class ${ClassName}ServiceImpl extends ServicePlusImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { |
| | | |
| | | @Override |
| | | public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | //TODO åä¸äºä¸å¡ä¸çæ ¡éª,夿æ¯å¦éè¦æ ¡éª |
| | | } |
| | |
| | | package ${packageName}.vo; |
| | | |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | #foreach ($import in $importList) |
| | | import ${import}; |
| | | #end |
| | |
| | | @Excel(name = "${comment}" , readConverterExp = "$column.readConverterExp()") |
| | | #elseif($column.javaType == 'Date') |
| | | @Excel(name = "${comment}" , width = 30, dateFormat = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | #else |
| | | @Excel(name = "${comment}") |
| | | #end |
| | |
| | | <template>
|
| | | <div class="app-container">
|
| | | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
| | | #foreach($column in $columns)
|
| | | #if($column.query)
|
| | | #set($dictType=$column.dictType)
|
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | #if($column.htmlType == "input")
|
| | | <el-form-item label="${comment}" prop="${column.javaField}">
|
| | | <el-input
|
| | | v-model="queryParams.${column.javaField}"
|
| | | placeholder="请è¾å
¥${comment}"
|
| | | clearable
|
| | | size="small"
|
| | | @keyup.enter.native="handleQuery"
|
| | | />
|
| | | </el-form-item>
|
| | | #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
| | | <el-form-item label="${comment}" prop="${column.javaField}">
|
| | | <el-select v-model="queryParams.${column.javaField}" placeholder="è¯·éæ©${comment}" clearable size="small">
|
| | | <el-option
|
| | | v-for="dict in ${column.javaField}Options"
|
| | | :key="dict.dictValue"
|
| | | :label="dict.dictLabel"
|
| | | :value="dict.dictValue"
|
| | | />
|
| | | </el-select>
|
| | | </el-form-item>
|
| | | #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
| | | <el-form-item label="${comment}" prop="${column.javaField}">
|
| | | <el-select v-model="queryParams.${column.javaField}" placeholder="è¯·éæ©${comment}" clearable size="small">
|
| | | <el-option label="è¯·éæ©åå
¸çæ" value="" />
|
| | | </el-select>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
| | | <el-form-item label="${comment}" prop="${column.javaField}">
|
| | | <el-date-picker clearable size="small"
|
| | | v-model="queryParams.${column.javaField}"
|
| | | type="date"
|
| | | value-format="yyyy-MM-dd"
|
| | | placeholder="éæ©${comment}">
|
| | | </el-date-picker>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
| | | <el-form-item label="${comment}">
|
| | | <el-date-picker
|
| | | v-model="daterange${AttrName}"
|
| | | size="small"
|
| | | style="width: 240px"
|
| | | value-format="yyyy-MM-dd"
|
| | | type="daterange"
|
| | | range-separator="-"
|
| | | start-placeholder="å¼å§æ¥æ"
|
| | | end-placeholder="ç»ææ¥æ"
|
| | | ></el-date-picker>
|
| | | </el-form-item>
|
| | | #end
|
| | | #end
|
| | | #end
|
| | | <el-form-item>
|
| | | <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">æç´¢</el-button>
|
| | | <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">éç½®</el-button>
|
| | | </el-form-item>
|
| | | </el-form>
|
| | |
|
| | | <el-row :gutter="10" class="mb8">
|
| | | <el-col :span="1.5">
|
| | | <el-button
|
| | | type="primary"
|
| | | plain
|
| | | icon="el-icon-plus"
|
| | | size="mini"
|
| | | @click="handleAdd"
|
| | | v-hasPermi="['${moduleName}:${businessName}:add']"
|
| | | >æ°å¢</el-button>
|
| | | </el-col>
|
| | | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
| | | </el-row>
|
| | |
|
| | | <el-table
|
| | | v-loading="loading"
|
| | | :data="${businessName}List"
|
| | | row-key="${treeCode}"
|
| | | default-expand-all
|
| | | :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
| | | >
|
| | | #foreach($column in $columns)
|
| | | #set($javaField=$column.javaField)
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | #if($column.pk)
|
| | | #elseif($column.list && $column.htmlType == "datetime")
|
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
| | | <template slot-scope="scope">
|
| | | <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
|
| | | </template>
|
| | | </el-table-column>
|
| | | #elseif($column.list && "" != $column.dictType)
|
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
|
| | | #elseif($column.list && "" != $javaField)
|
| | | #if(${foreach.index} == 1)
|
| | | <el-table-column label="${comment}" prop="${javaField}" />
|
| | | #else
|
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" />
|
| | | #end
|
| | | #end
|
| | | #end
|
| | | <el-table-column label="æä½" align="center" class-name="small-padding fixed-width">
|
| | | <template slot-scope="scope">
|
| | | <el-button
|
| | | size="mini"
|
| | | type="text"
|
| | | icon="el-icon-edit"
|
| | | @click="handleUpdate(scope.row)"
|
| | | v-hasPermi="['${moduleName}:${businessName}:edit']"
|
| | | >ä¿®æ¹</el-button>
|
| | | <el-button
|
| | | size="mini"
|
| | | type="text"
|
| | | icon="el-icon-plus"
|
| | | @click="handleAdd(scope.row)"
|
| | | v-hasPermi="['${moduleName}:${businessName}:add']"
|
| | | >æ°å¢</el-button>
|
| | | <el-button
|
| | | size="mini"
|
| | | type="text"
|
| | | icon="el-icon-delete"
|
| | | @click="handleDelete(scope.row)"
|
| | | v-hasPermi="['${moduleName}:${businessName}:remove']"
|
| | | >å é¤</el-button>
|
| | | </template>
|
| | | </el-table-column>
|
| | | </el-table>
|
| | |
|
| | | <!-- æ·»å æä¿®æ¹${functionName}å¯¹è¯æ¡ -->
|
| | | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
| | | <el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
| | | #foreach($column in $columns)
|
| | | #set($field=$column.javaField)
|
| | | #if($column.insert && !$column.pk)
|
| | | #if(($column.usableColumn) || (!$column.superColumn))
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | #set($dictType=$column.dictType)
|
| | | #if("" != $treeParentCode && $column.javaField == $treeParentCode)
|
| | | <el-form-item label="${comment}" prop="${treeParentCode}">
|
| | | <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="è¯·éæ©${comment}" />
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "input")
|
| | | <el-form-item label="${comment}" prop="${field}">
|
| | | <el-input v-model="form.${field}" placeholder="请è¾å
¥${comment}" />
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "imageUpload")
|
| | | <el-form-item label="${comment}">
|
| | | <imageUpload v-model="form.${field}"/>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "fileUpload")
|
| | | <el-form-item label="${comment}">
|
| | | <fileUpload v-model="form.${field}"/>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "editor")
|
| | | <el-form-item label="${comment}">
|
| | | <editor v-model="form.${field}" :min-height="192"/>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "select" && "" != $dictType)
|
| | | <el-form-item label="${comment}" prop="${field}">
|
| | | <el-select v-model="form.${field}" placeholder="è¯·éæ©${comment}">
|
| | | <el-option
|
| | | v-for="dict in ${field}Options"
|
| | | :key="dict.dictValue"
|
| | | :label="dict.dictLabel"
|
| | | #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
|
| | |
|
| | | ></el-option>
|
| | | </el-select>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "select" && $dictType)
|
| | | <el-form-item label="${comment}" prop="${field}">
|
| | | <el-select v-model="form.${field}" placeholder="è¯·éæ©${comment}">
|
| | | <el-option label="è¯·éæ©åå
¸çæ" value="" />
|
| | | </el-select>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "checkbox" && "" != $dictType)
|
| | | <el-form-item label="${comment}">
|
| | | <el-checkbox-group v-model="form.${field}">
|
| | | <el-checkbox
|
| | | v-for="dict in ${field}Options"
|
| | | :key="dict.dictValue"
|
| | | :label="dict.dictValue">
|
| | | {{dict.dictLabel}}
|
| | | </el-checkbox>
|
| | | </el-checkbox-group>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "checkbox" && $dictType)
|
| | | <el-form-item label="${comment}">
|
| | | <el-checkbox-group v-model="form.${field}">
|
| | | <el-checkbox>è¯·éæ©åå
¸çæ</el-checkbox>
|
| | | </el-checkbox-group>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "radio" && "" != $dictType)
|
| | | <el-form-item label="${comment}">
|
| | | <el-radio-group v-model="form.${field}">
|
| | | <el-radio
|
| | | v-for="dict in ${field}Options"
|
| | | :key="dict.dictValue"
|
| | | #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
|
| | |
|
| | | >{{dict.dictLabel}}</el-radio>
|
| | | </el-radio-group>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "radio" && $dictType)
|
| | | <el-form-item label="${comment}">
|
| | | <el-radio-group v-model="form.${field}">
|
| | | <el-radio label="1">è¯·éæ©åå
¸çæ</el-radio>
|
| | | </el-radio-group>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "datetime")
|
| | | <el-form-item label="${comment}" prop="${field}">
|
| | | <el-date-picker clearable size="small"
|
| | | v-model="form.${field}"
|
| | | type="datetime"
|
| | | value-format="yyyy-MM-dd HH:mm:ss"
|
| | | placeholder="éæ©${comment}">
|
| | | </el-date-picker>
|
| | | </el-form-item>
|
| | | #elseif($column.htmlType == "textarea")
|
| | | <el-form-item label="${comment}" prop="${field}">
|
| | | <el-input v-model="form.${field}" type="textarea" placeholder="请è¾å
¥å
容" />
|
| | | </el-form-item>
|
| | | #end
|
| | | #end
|
| | | #end
|
| | | #end
|
| | | </el-form>
|
| | | <div slot="footer" class="dialog-footer">
|
| | | <el-button :loading="buttonLoading" type="primary" @click="submitForm">ç¡® å®</el-button>
|
| | | <el-button @click="cancel">å æ¶</el-button>
|
| | | </div>
|
| | | </el-dialog>
|
| | | </div>
|
| | | </template>
|
| | |
|
| | | <script>
|
| | | import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
|
| | | import Treeselect from "@riophae/vue-treeselect";
|
| | | import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
|
| | | import ImageUpload from '@/components/ImageUpload';
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
|
| | | import FileUpload from '@/components/FileUpload';
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
|
| | | import Editor from '@/components/Editor';
|
| | | #break
|
| | | #end
|
| | | #end
|
| | |
|
| | | export default {
|
| | | name: "${BusinessName}",
|
| | | components: {
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
|
| | | ImageUpload,
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
|
| | | FileUpload,
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | #foreach($column in $columns)
|
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
|
| | | Editor,
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | Treeselect
|
| | | },
|
| | | data() {
|
| | | return {
|
| | | //æé®loading
|
| | | buttonLoading: false,
|
| | | // é®ç½©å±
|
| | | loading: true,
|
| | | // æ¾ç¤ºæç´¢æ¡ä»¶
|
| | | showSearch: true,
|
| | | // ${functionName}è¡¨æ ¼æ°æ®
|
| | | ${businessName}List: [],
|
| | | // ${functionName}æ é项
|
| | | ${businessName}Options: [],
|
| | | // å¼¹åºå±æ é¢
|
| | | title: "",
|
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå±
|
| | | open: false,
|
| | | #foreach ($column in $columns)
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | #if(${column.dictType} != '')
|
| | | // $commentåå
¸
|
| | | ${column.javaField}Options: [],
|
| | | #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
| | | // $commentæ¶é´èå´
|
| | | daterange${AttrName}: [],
|
| | | #end
|
| | | #end
|
| | | // æ¥è¯¢åæ°
|
| | | queryParams: {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.query)
|
| | | $column.javaField: null#if($velocityCount != $columns.size()),#end
|
| | |
|
| | | #end
|
| | | #end
|
| | | },
|
| | | // 表ååæ°
|
| | | form: {},
|
| | | // è¡¨åæ ¡éª
|
| | | rules: {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.required)
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | $column.javaField: [
|
| | | { required: true, message: "$commentä¸è½ä¸ºç©º", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
|
| | | ]#if($velocityCount != $columns.size()),#end
|
| | |
|
| | | #end
|
| | | #end
|
| | | }
|
| | | };
|
| | | },
|
| | | created() {
|
| | | this.getList();
|
| | | #foreach ($column in $columns)
|
| | | #if(${column.dictType} != '')
|
| | | this.getDicts("${column.dictType}").then(response => {
|
| | | this.${column.javaField}Options = response.data;
|
| | | });
|
| | | #end
|
| | | #end
|
| | | },
|
| | | methods: {
|
| | | /** æ¥è¯¢${functionName}å表 */
|
| | | getList() {
|
| | | this.loading = true;
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
| | | this.queryParams.params = {};
|
| | | #break
|
| | | #end
|
| | | #end
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
| | | if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
|
| | | this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
|
| | | this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
|
| | | }
|
| | | #end
|
| | | #end
|
| | | list${BusinessName}(this.queryParams).then(response => {
|
| | | this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
|
| | | this.loading = false;
|
| | | });
|
| | | },
|
| | | /** 转æ¢${functionName}æ°æ®ç»æ */
|
| | | normalizer(node) {
|
| | | if (node.children && !node.children.length) {
|
| | | delete node.children;
|
| | | }
|
| | | return {
|
| | | id: node.${treeCode},
|
| | | label: node.${treeName},
|
| | | children: node.children
|
| | | };
|
| | | },
|
| | | /** æ¥è¯¢${functionName}䏿æ ç»æ */
|
| | | getTreeselect() {
|
| | | list${BusinessName}().then(response => {
|
| | | this.${businessName}Options = [];
|
| | | const data = { ${treeCode}: 0, ${treeName}: '顶级èç¹', children: [] };
|
| | | data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
|
| | | this.${businessName}Options.push(data);
|
| | | });
|
| | | },
|
| | | #foreach ($column in $columns)
|
| | | #if(${column.dictType} != '')
|
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼"))
|
| | | #if($parentheseIndex != -1)
|
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
| | | #else
|
| | | #set($comment=$column.columnComment)
|
| | | #end
|
| | | // $commentåå
¸ç¿»è¯
|
| | | ${column.javaField}Format(row, column) {
|
| | | return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
|
| | | },
|
| | | #end
|
| | | #end
|
| | | // åæ¶æé®
|
| | | cancel() {
|
| | | this.open = false;
|
| | | this.reset();
|
| | | },
|
| | | // 表åéç½®
|
| | | reset() {
|
| | | this.form = {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "radio")
|
| | | $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
|
| | |
|
| | | #elseif($column.htmlType == "checkbox")
|
| | | $column.javaField: []#if($velocityCount != $columns.size()),#end
|
| | |
|
| | | #else
|
| | | $column.javaField: null#if($velocityCount != $columns.size()),#end
|
| | |
|
| | | #end
|
| | | #end
|
| | | };
|
| | | this.resetForm("form");
|
| | | },
|
| | | /** æç´¢æé®æä½ */
|
| | | handleQuery() {
|
| | | this.getList();
|
| | | },
|
| | | /** éç½®æé®æä½ */
|
| | | resetQuery() {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
| | | this.daterange${AttrName} = [];
|
| | | #end
|
| | | #end
|
| | | this.resetForm("queryForm");
|
| | | this.handleQuery();
|
| | | },
|
| | | /** æ°å¢æé®æä½ */
|
| | | handleAdd(row) {
|
| | | this.reset();
|
| | | this.getTreeselect();
|
| | | if (row != null && row.${treeCode}) {
|
| | | this.form.${treeParentCode} = row.${treeCode};
|
| | | } else {
|
| | | this.form.${treeParentCode} = 0;
|
| | | }
|
| | | this.open = true;
|
| | | this.title = "æ·»å ${functionName}";
|
| | | },
|
| | | /** ä¿®æ¹æé®æä½ */
|
| | | handleUpdate(row) {
|
| | | this.loading = true;
|
| | | this.reset();
|
| | | this.getTreeselect();
|
| | | if (row != null) {
|
| | | this.form.${treeParentCode} = row.${treeCode};
|
| | | }
|
| | | get${BusinessName}(row.${pkColumn.javaField}).then(response => {
|
| | | this.loading = false;
|
| | | this.form = response.data;
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "checkbox")
|
| | | this.form.$column.javaField = this.form.${column.javaField}.split(",");
|
| | | #end
|
| | | #end
|
| | | this.open = true;
|
| | | this.title = "ä¿®æ¹${functionName}";
|
| | | });
|
| | | },
|
| | | /** æäº¤æé® */
|
| | | submitForm() {
|
| | | this.#[[$]]#refs["form"].validate(valid => {
|
| | | if (valid) {
|
| | | this.buttonLoading = true;
|
| | | #foreach ($column in $columns)
|
| | | #if($column.htmlType == "checkbox")
|
| | | this.form.$column.javaField = this.form.${column.javaField}.join(",");
|
| | | #end
|
| | | #end
|
| | | if (this.form.${pkColumn.javaField} != null) {
|
| | | update${BusinessName}(this.form).then(response => {
|
| | | this.buttonLoading = false;
|
| | | this.msgSuccess("ä¿®æ¹æå");
|
| | | this.open = false;
|
| | | this.getList();
|
| | | });
|
| | | } else {
|
| | | add${BusinessName}(this.form).then(response => {
|
| | | this.buttonLoading = false;
|
| | | this.msgSuccess("æ°å¢æå");
|
| | | this.open = false;
|
| | | this.getList();
|
| | | });
|
| | | }
|
| | | }
|
| | | });
|
| | | },
|
| | | /** å é¤æé®æä½ */
|
| | | handleDelete(row) {
|
| | | this.$confirm('æ¯å¦ç¡®è®¤å é¤${functionName}ç¼å·ä¸º"' + row.${pkColumn.javaField} + '"çæ°æ®é¡¹?', "è¦å", {
|
| | | confirmButtonText: "ç¡®å®",
|
| | | cancelButtonText: "åæ¶",
|
| | | type: "warning"
|
| | | }).then(() => {
|
| | | this.loading = true;
|
| | | return del${BusinessName}(row.${pkColumn.javaField});
|
| | | }).then(() => {
|
| | | this.loading = false;
|
| | | this.getList();
|
| | | this.msgSuccess("å 餿å");
|
| | | }).catch(() => {});
|
| | | }
|
| | | }
|
| | | };
|
| | | </script>
|
| | | <template> |
| | | <div class="app-container"> |
| | | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> |
| | | #foreach($column in $columns) |
| | | #if($column.query) |
| | | #set($dictType=$column.dictType) |
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | #if($column.htmlType == "input") |
| | | <el-form-item label="${comment}" prop="${column.javaField}"> |
| | | <el-input |
| | | v-model="queryParams.${column.javaField}" |
| | | placeholder="请è¾å
¥${comment}" |
| | | clearable |
| | | size="small" |
| | | @keyup.enter.native="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType) |
| | | <el-form-item label="${comment}" prop="${column.javaField}"> |
| | | <el-select v-model="queryParams.${column.javaField}" placeholder="è¯·éæ©${comment}" clearable size="small"> |
| | | <el-option |
| | | v-for="dict in ${column.javaField}Options" |
| | | :key="dict.dictValue" |
| | | :label="dict.dictLabel" |
| | | :value="dict.dictValue" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType) |
| | | <el-form-item label="${comment}" prop="${column.javaField}"> |
| | | <el-select v-model="queryParams.${column.javaField}" placeholder="è¯·éæ©${comment}" clearable size="small"> |
| | | <el-option label="è¯·éæ©åå
¸çæ" value="" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN") |
| | | <el-form-item label="${comment}" prop="${column.javaField}"> |
| | | <el-date-picker clearable size="small" |
| | | v-model="queryParams.${column.javaField}" |
| | | type="date" |
| | | value-format="yyyy-MM-dd" |
| | | placeholder="éæ©${comment}"> |
| | | </el-date-picker> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") |
| | | <el-form-item label="${comment}"> |
| | | <el-date-picker |
| | | v-model="daterange${AttrName}" |
| | | size="small" |
| | | style="width: 240px" |
| | | value-format="yyyy-MM-dd" |
| | | type="daterange" |
| | | range-separator="-" |
| | | start-placeholder="å¼å§æ¥æ" |
| | | end-placeholder="ç»ææ¥æ" |
| | | ></el-date-picker> |
| | | </el-form-item> |
| | | #end |
| | | #end |
| | | #end |
| | | <el-form-item> |
| | | <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">æç´¢</el-button> |
| | | <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">éç½®</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <el-row :gutter="10" class="mb8"> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="primary" |
| | | plain |
| | | icon="el-icon-plus" |
| | | size="mini" |
| | | @click="handleAdd" |
| | | v-hasPermi="['${moduleName}:${businessName}:add']" |
| | | >æ°å¢</el-button> |
| | | </el-col> |
| | | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | |
| | | <el-table |
| | | v-loading="loading" |
| | | :data="${businessName}List" |
| | | row-key="${treeCode}" |
| | | default-expand-all |
| | | :tree-props="{children: 'children', hasChildren: 'hasChildren'}" |
| | | > |
| | | #foreach($column in $columns) |
| | | #set($javaField=$column.javaField) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | #if($column.pk) |
| | | #elseif($column.list && $column.htmlType == "datetime") |
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | #elseif($column.list && "" != $column.dictType) |
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" /> |
| | | #elseif($column.list && "" != $javaField) |
| | | #if(${foreach.index} == 1) |
| | | <el-table-column label="${comment}" prop="${javaField}" /> |
| | | #else |
| | | <el-table-column label="${comment}" align="center" prop="${javaField}" /> |
| | | #end |
| | | #end |
| | | #end |
| | | <el-table-column label="æä½" align="center" class-name="small-padding fixed-width"> |
| | | <template slot-scope="scope"> |
| | | <el-button |
| | | size="mini" |
| | | type="text" |
| | | icon="el-icon-edit" |
| | | @click="handleUpdate(scope.row)" |
| | | v-hasPermi="['${moduleName}:${businessName}:edit']" |
| | | >ä¿®æ¹</el-button> |
| | | <el-button |
| | | size="mini" |
| | | type="text" |
| | | icon="el-icon-plus" |
| | | @click="handleAdd(scope.row)" |
| | | v-hasPermi="['${moduleName}:${businessName}:add']" |
| | | >æ°å¢</el-button> |
| | | <el-button |
| | | size="mini" |
| | | type="text" |
| | | icon="el-icon-delete" |
| | | @click="handleDelete(scope.row)" |
| | | v-hasPermi="['${moduleName}:${businessName}:remove']" |
| | | >å é¤</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | |
| | | <!-- æ·»å æä¿®æ¹${functionName}å¯¹è¯æ¡ --> |
| | | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| | | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| | | #foreach($column in $columns) |
| | | #set($field=$column.javaField) |
| | | #if($column.insert && !$column.pk) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | #set($dictType=$column.dictType) |
| | | #if("" != $treeParentCode && $column.javaField == $treeParentCode) |
| | | <el-form-item label="${comment}" prop="${treeParentCode}"> |
| | | <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="è¯·éæ©${comment}" /> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "input") |
| | | <el-form-item label="${comment}" prop="${field}"> |
| | | <el-input v-model="form.${field}" placeholder="请è¾å
¥${comment}" /> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "imageUpload") |
| | | <el-form-item label="${comment}"> |
| | | <imageUpload v-model="form.${field}"/> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "fileUpload") |
| | | <el-form-item label="${comment}"> |
| | | <fileUpload v-model="form.${field}"/> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "editor") |
| | | <el-form-item label="${comment}"> |
| | | <editor v-model="form.${field}" :min-height="192"/> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "select" && "" != $dictType) |
| | | <el-form-item label="${comment}" prop="${field}"> |
| | | <el-select v-model="form.${field}" placeholder="è¯·éæ©${comment}"> |
| | | <el-option |
| | | v-for="dict in ${field}Options" |
| | | :key="dict.dictValue" |
| | | :label="dict.dictLabel" |
| | | #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end |
| | | |
| | | ></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "select" && $dictType) |
| | | <el-form-item label="${comment}" prop="${field}"> |
| | | <el-select v-model="form.${field}" placeholder="è¯·éæ©${comment}"> |
| | | <el-option label="è¯·éæ©åå
¸çæ" value="" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "checkbox" && "" != $dictType) |
| | | <el-form-item label="${comment}"> |
| | | <el-checkbox-group v-model="form.${field}"> |
| | | <el-checkbox |
| | | v-for="dict in ${field}Options" |
| | | :key="dict.dictValue" |
| | | :label="dict.dictValue"> |
| | | {{dict.dictLabel}} |
| | | </el-checkbox> |
| | | </el-checkbox-group> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "checkbox" && $dictType) |
| | | <el-form-item label="${comment}"> |
| | | <el-checkbox-group v-model="form.${field}"> |
| | | <el-checkbox>è¯·éæ©åå
¸çæ</el-checkbox> |
| | | </el-checkbox-group> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "radio" && "" != $dictType) |
| | | <el-form-item label="${comment}"> |
| | | <el-radio-group v-model="form.${field}"> |
| | | <el-radio |
| | | v-for="dict in ${field}Options" |
| | | :key="dict.dictValue" |
| | | #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end |
| | | |
| | | >{{dict.dictLabel}}</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "radio" && $dictType) |
| | | <el-form-item label="${comment}"> |
| | | <el-radio-group v-model="form.${field}"> |
| | | <el-radio label="1">è¯·éæ©åå
¸çæ</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "datetime") |
| | | <el-form-item label="${comment}" prop="${field}"> |
| | | <el-date-picker clearable size="small" |
| | | v-model="form.${field}" |
| | | type="datetime" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | placeholder="éæ©${comment}"> |
| | | </el-date-picker> |
| | | </el-form-item> |
| | | #elseif($column.htmlType == "textarea") |
| | | <el-form-item label="${comment}" prop="${field}"> |
| | | <el-input v-model="form.${field}" type="textarea" placeholder="请è¾å
¥å
容" /> |
| | | </el-form-item> |
| | | #end |
| | | #end |
| | | #end |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button :loading="buttonLoading" type="primary" @click="submitForm">ç¡® å®</el-button> |
| | | <el-button @click="cancel">å æ¶</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; |
| | | import Treeselect from "@riophae/vue-treeselect"; |
| | | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "imageUpload") |
| | | import ImageUpload from '@/components/ImageUpload'; |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "fileUpload") |
| | | import FileUpload from '@/components/FileUpload'; |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "editor") |
| | | import Editor from '@/components/Editor'; |
| | | #break |
| | | #end |
| | | #end |
| | | |
| | | export default { |
| | | name: "${BusinessName}", |
| | | components: { |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "imageUpload") |
| | | ImageUpload, |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "fileUpload") |
| | | FileUpload, |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.pk && $column.htmlType == "editor") |
| | | Editor, |
| | | #break |
| | | #end |
| | | #end |
| | | Treeselect |
| | | }, |
| | | data() { |
| | | return { |
| | | //æé®loading |
| | | buttonLoading: false, |
| | | // é®ç½©å± |
| | | loading: true, |
| | | // æ¾ç¤ºæç´¢æ¡ä»¶ |
| | | showSearch: true, |
| | | // ${functionName}è¡¨æ ¼æ°æ® |
| | | ${businessName}List: [], |
| | | // ${functionName}æ é项 |
| | | ${businessName}Options: [], |
| | | // å¼¹åºå±æ é¢ |
| | | title: "", |
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå± |
| | | open: false, |
| | | #foreach ($column in $columns) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | #if(${column.dictType} != '') |
| | | // $commentåå
¸ |
| | | ${column.javaField}Options: [], |
| | | #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") |
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| | | // $commentæ¶é´èå´ |
| | | daterange${AttrName}: [], |
| | | #end |
| | | #end |
| | | // æ¥è¯¢åæ° |
| | | queryParams: { |
| | | #foreach ($column in $columns) |
| | | #if($column.query) |
| | | $column.javaField: null#if($velocityCount != $columns.size()),#end |
| | | |
| | | #end |
| | | #end |
| | | }, |
| | | // 表ååæ° |
| | | form: {}, |
| | | // è¡¨åæ ¡éª |
| | | rules: { |
| | | #foreach ($column in $columns) |
| | | #if($column.required) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | $column.javaField: [ |
| | | { required: true, message: "$commentä¸è½ä¸ºç©º", trigger: #if($column.htmlType == "select")"change"#else"blur"#end } |
| | | ]#if($velocityCount != $columns.size()),#end |
| | | |
| | | #end |
| | | #end |
| | | } |
| | | }; |
| | | }, |
| | | created() { |
| | | this.getList(); |
| | | #foreach ($column in $columns) |
| | | #if(${column.dictType} != '') |
| | | this.getDicts("${column.dictType}").then(response => { |
| | | this.${column.javaField}Options = response.data; |
| | | }); |
| | | #end |
| | | #end |
| | | }, |
| | | methods: { |
| | | /** æ¥è¯¢${functionName}å表 */ |
| | | getList() { |
| | | this.loading = true; |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") |
| | | this.queryParams.params = {}; |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") |
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| | | if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) { |
| | | this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0]; |
| | | this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1]; |
| | | } |
| | | #end |
| | | #end |
| | | list${BusinessName}(this.queryParams).then(response => { |
| | | this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}"); |
| | | this.loading = false; |
| | | }); |
| | | }, |
| | | /** 转æ¢${functionName}æ°æ®ç»æ */ |
| | | normalizer(node) { |
| | | if (node.children && !node.children.length) { |
| | | delete node.children; |
| | | } |
| | | return { |
| | | id: node.${treeCode}, |
| | | label: node.${treeName}, |
| | | children: node.children |
| | | }; |
| | | }, |
| | | /** æ¥è¯¢${functionName}䏿æ ç»æ */ |
| | | getTreeselect() { |
| | | list${BusinessName}().then(response => { |
| | | this.${businessName}Options = []; |
| | | const data = { ${treeCode}: 0, ${treeName}: '顶级èç¹', children: [] }; |
| | | data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}"); |
| | | this.${businessName}Options.push(data); |
| | | }); |
| | | }, |
| | | #foreach ($column in $columns) |
| | | #if(${column.dictType} != '') |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | | #else |
| | | #set($comment=$column.columnComment) |
| | | #end |
| | | // $commentåå
¸ç¿»è¯ |
| | | ${column.javaField}Format(row, column) { |
| | | return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); |
| | | }, |
| | | #end |
| | | #end |
| | | // åæ¶æé® |
| | | cancel() { |
| | | this.open = false; |
| | | this.reset(); |
| | | }, |
| | | // 表åéç½® |
| | | reset() { |
| | | this.form = { |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "radio") |
| | | $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end |
| | | |
| | | #elseif($column.htmlType == "checkbox") |
| | | $column.javaField: []#if($velocityCount != $columns.size()),#end |
| | | |
| | | #else |
| | | $column.javaField: null#if($velocityCount != $columns.size()),#end |
| | | |
| | | #end |
| | | #end |
| | | }; |
| | | this.resetForm("form"); |
| | | }, |
| | | /** æç´¢æé®æä½ */ |
| | | handleQuery() { |
| | | this.getList(); |
| | | }, |
| | | /** éç½®æé®æä½ */ |
| | | resetQuery() { |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") |
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| | | this.daterange${AttrName} = []; |
| | | #end |
| | | #end |
| | | this.resetForm("queryForm"); |
| | | this.handleQuery(); |
| | | }, |
| | | /** æ°å¢æé®æä½ */ |
| | | handleAdd(row) { |
| | | this.reset(); |
| | | this.getTreeselect(); |
| | | if (row != null && row.${treeCode}) { |
| | | this.form.${treeParentCode} = row.${treeCode}; |
| | | } else { |
| | | this.form.${treeParentCode} = 0; |
| | | } |
| | | this.open = true; |
| | | this.title = "æ·»å ${functionName}"; |
| | | }, |
| | | /** ä¿®æ¹æé®æä½ */ |
| | | handleUpdate(row) { |
| | | this.loading = true; |
| | | this.reset(); |
| | | this.getTreeselect(); |
| | | if (row != null) { |
| | | this.form.${treeParentCode} = row.${treeCode}; |
| | | } |
| | | get${BusinessName}(row.${pkColumn.javaField}).then(response => { |
| | | this.loading = false; |
| | | this.form = response.data; |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "checkbox") |
| | | this.form.$column.javaField = this.form.${column.javaField}.split(","); |
| | | #end |
| | | #end |
| | | this.open = true; |
| | | this.title = "ä¿®æ¹${functionName}"; |
| | | }); |
| | | }, |
| | | /** æäº¤æé® */ |
| | | submitForm() { |
| | | this.#[[$]]#refs["form"].validate(valid => { |
| | | if (valid) { |
| | | this.buttonLoading = true; |
| | | #foreach ($column in $columns) |
| | | #if($column.htmlType == "checkbox") |
| | | this.form.$column.javaField = this.form.${column.javaField}.join(","); |
| | | #end |
| | | #end |
| | | if (this.form.${pkColumn.javaField} != null) { |
| | | update${BusinessName}(this.form).then(response => { |
| | | this.buttonLoading = false; |
| | | this.msgSuccess("ä¿®æ¹æå"); |
| | | this.open = false; |
| | | this.getList(); |
| | | }); |
| | | } else { |
| | | add${BusinessName}(this.form).then(response => { |
| | | this.buttonLoading = false; |
| | | this.msgSuccess("æ°å¢æå"); |
| | | this.open = false; |
| | | this.getList(); |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | /** å é¤æé®æä½ */ |
| | | handleDelete(row) { |
| | | this.$confirm('æ¯å¦ç¡®è®¤å é¤${functionName}ç¼å·ä¸º"' + row.${pkColumn.javaField} + '"çæ°æ®é¡¹?', "è¦å", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning" |
| | | }).then(() => { |
| | | this.loading = true; |
| | | return del${BusinessName}(row.${pkColumn.javaField}); |
| | | }).then(() => { |
| | | this.loading = false; |
| | | this.getList(); |
| | | this.msgSuccess("å 餿å"); |
| | | }).catch(() => {}); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | |
| | | #foreach($column in $columns) |
| | | #set($field=$column.javaField) |
| | | #if($column.insert && !$column.pk) |
| | | #if(($column.usableColumn) || (!$column.superColumn)) |
| | | #set($parentheseIndex=$column.columnComment.indexOf("ï¼")) |
| | | #if($parentheseIndex != -1) |
| | | #set($comment=$column.columnComment.substring(0, $parentheseIndex)) |
| | |
| | | #end |
| | | #end |
| | | #end |
| | | #end |
| | | #if($table.sub) |
| | | <el-divider content-position="center">${subTable.functionName}ä¿¡æ¯</el-divider> |
| | | <el-row :gutter="10" class="mb8"> |
| | |
| | | <script> |
| | | import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "imageUpload") |
| | | import ImageUpload from '@/components/ImageUpload'; |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "fileUpload") |
| | | import FileUpload from '@/components/FileUpload'; |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "editor") |
| | | import Editor from '@/components/Editor'; |
| | | #break |
| | | #end |
| | |
| | | name: "${BusinessName}", |
| | | components: { |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "imageUpload") |
| | | ImageUpload, |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "fileUpload") |
| | | FileUpload, |
| | | #break |
| | | #end |
| | | #end |
| | | #foreach($column in $columns) |
| | | #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") |
| | | #if($column.insert && !$column.pk && $column.htmlType == "editor") |
| | | Editor, |
| | | #break |
| | | #end |
| | |
| | | package com.ruoyi.quartz.controller;
|
| | |
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.service.ISysJobService;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * è°åº¦ä»»å¡ä¿¡æ¯æä½å¤ç
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping("/monitor/job")
|
| | | public class SysJobController extends BaseController
|
| | | {
|
| | | @Autowired
|
| | | private ISysJobService jobService;
|
| | |
|
| | | /**
|
| | | * æ¥è¯¢å®æ¶ä»»å¡å表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')")
|
| | | @GetMapping("/list")
|
| | | public TableDataInfo list(SysJob sysJob)
|
| | | {
|
| | | return jobService.selectPageJobList(sysJob);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 导åºå®æ¶ä»»å¡å表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.EXPORT)
|
| | | @GetMapping("/export")
|
| | | public AjaxResult export(SysJob sysJob)
|
| | | {
|
| | | List<SysJob> list = jobService.selectJobList(sysJob);
|
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
|
| | | return util.exportExcel(list, "宿¶ä»»å¡");
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·å宿¶ä»»å¡è¯¦ç»ä¿¡æ¯
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')")
|
| | | @GetMapping(value = "/{jobId}")
|
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
| | | {
|
| | | return AjaxResult.success(jobService.selectJobById(jobId));
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ°å¢å®æ¶ä»»å¡
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:add')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
| | | {
|
| | | if (!CronUtils.isValid(sysJob.getCronExpression()))
|
| | | {
|
| | | return AjaxResult.error("cron表达å¼ä¸æ£ç¡®");
|
| | | }
|
| | | sysJob.setCreateBy(SecurityUtils.getUsername());
|
| | | return toAjax(jobService.insertJob(sysJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * ä¿®æ¹å®æ¶ä»»å¡
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
| | | {
|
| | | if (!CronUtils.isValid(sysJob.getCronExpression()))
|
| | | {
|
| | | return AjaxResult.error("cron表达å¼ä¸æ£ç¡®");
|
| | | }
|
| | | sysJob.setUpdateBy(SecurityUtils.getUsername());
|
| | | return toAjax(jobService.updateJob(sysJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡ç¶æä¿®æ¹
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/changeStatus")
|
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
|
| | | {
|
| | | SysJob newJob = jobService.selectJobById(job.getJobId());
|
| | | newJob.setStatus(job.getStatus());
|
| | | return toAjax(jobService.changeStatus(newJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡ç«å³æ§è¡ä¸æ¬¡
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/run")
|
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
| | | {
|
| | | jobService.run(job);
|
| | | return AjaxResult.success();
|
| | | }
|
| | |
|
| | | /**
|
| | | * å é¤å®æ¶ä»»å¡
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
|
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{jobIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
| | | {
|
| | | jobService.deleteJobByIds(jobIds);
|
| | | return AjaxResult.success();
|
| | | }
|
| | | }
|
| | | package com.ruoyi.quartz.controller; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | import com.ruoyi.quartz.service.ISysJobService; |
| | | import com.ruoyi.quartz.util.CronUtils; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡ä¿¡æ¯æä½å¤ç |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/job") |
| | | public class SysJobController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysJobService jobService; |
| | | |
| | | /** |
| | | * æ¥è¯¢å®æ¶ä»»å¡å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysJob sysJob) |
| | | { |
| | | return jobService.selectPageJobList(sysJob); |
| | | } |
| | | |
| | | /** |
| | | * 导åºå®æ¶ä»»å¡å表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/export") |
| | | public AjaxResult export(SysJob sysJob) |
| | | { |
| | | List<SysJob> list = jobService.selectJobList(sysJob); |
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); |
| | | return util.exportExcel(list, "宿¶ä»»å¡"); |
| | | } |
| | | |
| | | /** |
| | | * è·å宿¶ä»»å¡è¯¦ç»ä¿¡æ¯ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')") |
| | | @GetMapping(value = "/{jobId}") |
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId) |
| | | { |
| | | return AjaxResult.success(jobService.selectJobById(jobId)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å®æ¶ä»»å¡ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:add')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(sysJob.getCronExpression())) |
| | | { |
| | | return AjaxResult.error("æ°å¢ä»»å¡'" + sysJob.getJobName() + "'失败ï¼Cron表达å¼ä¸æ£ç¡®"); |
| | | } |
| | | else if (StrUtil.containsIgnoreCase(sysJob.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | { |
| | | return AjaxResult.error("æ°å¢ä»»å¡'" + sysJob.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi://'è°ç¨"); |
| | | } |
| | | sysJob.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.insertJob(sysJob)); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹å®æ¶ä»»å¡ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:edit')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(sysJob.getCronExpression())) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ä»»å¡'" + sysJob.getJobName() + "'失败ï¼Cron表达å¼ä¸æ£ç¡®"); |
| | | } |
| | | else if (StrUtil.containsIgnoreCase(sysJob.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ä»»å¡'" + sysJob.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi://'è°ç¨"); |
| | | } |
| | | sysJob.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.updateJob(sysJob)); |
| | | } |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡ç¶æä¿®æ¹ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | SysJob newJob = jobService.selectJobById(job.getJobId()); |
| | | newJob.setStatus(job.getStatus()); |
| | | return toAjax(jobService.changeStatus(newJob)); |
| | | } |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡ç«å³æ§è¡ä¸æ¬¡ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/run") |
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | jobService.run(job); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * å é¤å®æ¶ä»»å¡ |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| | | @Log(title = "宿¶ä»»å¡", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{jobIds}") |
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException |
| | | { |
| | | jobService.deleteJobByIds(jobIds); |
| | | return AjaxResult.success(); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.quartz.mapper;
|
| | |
|
| | | import com.ruoyi.common.core.page.BaseMapperPlus;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | |
|
| | | /**
|
| | | * è°åº¦ä»»å¡æ¥å¿ä¿¡æ¯ æ°æ®å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobLogMapper extends BaseMapperPlus<SysJobLog> {
|
| | |
|
| | | }
|
| | | package com.ruoyi.quartz.mapper; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.quartz.domain.SysJobLog; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡æ¥å¿ä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysJobLogMapper extends BaseMapperPlus<SysJobLog> { |
| | | |
| | | } |
| | |
| | | package com.ruoyi.quartz.mapper;
|
| | |
|
| | | import com.ruoyi.common.core.page.BaseMapperPlus;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * è°åº¦ä»»å¡ä¿¡æ¯ æ°æ®å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobMapper extends BaseMapperPlus<SysJob> {
|
| | |
|
| | | }
|
| | | package com.ruoyi.quartz.mapper; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | |
| | | /** |
| | | * è°åº¦ä»»å¡ä¿¡æ¯ æ°æ®å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysJobMapper extends BaseMapperPlus<SysJob> { |
| | | |
| | | } |
| | |
| | | package com.ruoyi.quartz.service;
|
| | |
|
| | | import com.ruoyi.common.core.page.IServicePlus;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ä¿¡æ¯ æå¡å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobLogService extends IServicePlus<SysJobLog> {
|
| | |
|
| | |
|
| | | TableDataInfo<SysJobLog> selectPageJobLogList(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡
|
| | | *
|
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯
|
| | | * @return è°åº¦ä»»å¡æ¥å¿éå
|
| | | */
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID
|
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯
|
| | | */
|
| | | public SysJobLog selectJobLogById(Long jobLogId);
|
| | |
|
| | | /**
|
| | | * æ°å¢ä»»å¡æ¥å¿
|
| | | *
|
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯
|
| | | */
|
| | | public void addJobLog(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯
|
| | | *
|
| | | * @param logIds éè¦å é¤çæ¥å¿ID
|
| | | * @return ç»æ
|
| | | */
|
| | | public int deleteJobLogByIds(Long[] logIds);
|
| | |
|
| | | /**
|
| | | * å é¤ä»»å¡æ¥å¿
|
| | | *
|
| | | * @param jobId è°åº¦æ¥å¿ID
|
| | | * @return ç»æ
|
| | | */
|
| | | public int deleteJobLogById(Long jobId);
|
| | |
|
| | | /**
|
| | | * æ¸
ç©ºä»»å¡æ¥å¿
|
| | | */
|
| | | public void cleanJobLog();
|
| | | }
|
| | | package com.ruoyi.quartz.service; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.quartz.domain.SysJobLog; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface ISysJobLogService extends IServicePlus<SysJobLog> { |
| | | |
| | | |
| | | TableDataInfo<SysJobLog> selectPageJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡æ¥å¿éå |
| | | */ |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID |
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJobLog selectJobLogById(Long jobLogId); |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | */ |
| | | public void addJobLog(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * |
| | | * @param logIds éè¦å é¤çæ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogByIds(Long[] logIds); |
| | | |
| | | /** |
| | | * å é¤ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobId è°åº¦æ¥å¿ID |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJobLogById(Long jobId); |
| | | |
| | | /** |
| | | * æ¸
ç©ºä»»å¡æ¥å¿ |
| | | */ |
| | | public void cleanJobLog(); |
| | | } |
| | |
| | | package com.ruoyi.quartz.service;
|
| | |
|
| | | import com.ruoyi.common.core.page.IServicePlus;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import org.quartz.SchedulerException;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ä¿¡æ¯ æå¡å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobService extends IServicePlus<SysJob> {
|
| | | /**
|
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return è°åº¦ä»»å¡éå
|
| | | */
|
| | | public TableDataInfo<SysJob> selectPageJobList(SysJob job);
|
| | |
|
| | | public List<SysJob> selectJobList(SysJob job);
|
| | |
|
| | | /**
|
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobId è°åº¦ä»»å¡ID
|
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯
|
| | | */
|
| | | public SysJob selectJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * æåä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int pauseJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * æ¢å¤ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int resumeJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int deleteJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobIds éè¦å é¤çä»»å¡ID
|
| | | * @return ç»æ
|
| | | */
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int changeStatus(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * ç«å³è¿è¡ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public void run(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * æ°å¢ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException;
|
| | |
|
| | | /**
|
| | | * æ´æ°ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException;
|
| | |
|
| | | /**
|
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ
|
| | | *
|
| | | * @param cronExpression 表达å¼
|
| | | * @return ç»æ
|
| | | */
|
| | | public boolean checkCronExpressionIsValid(String cronExpression);
|
| | | }
|
| | | package com.ruoyi.quartz.service; |
| | | |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | import org.quartz.SchedulerException; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface ISysJobService extends IServicePlus<SysJob> { |
| | | /** |
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡éå |
| | | */ |
| | | public TableDataInfo<SysJob> selectPageJobList(SysJob job); |
| | | |
| | | public List<SysJob> selectJobList(SysJob job); |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ä»»å¡ID |
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | public SysJob selectJobById(Long jobId); |
| | | |
| | | /** |
| | | * æåä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int pauseJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ¢å¤ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int resumeJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int deleteJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobIds éè¦å é¤çä»»å¡ID |
| | | * @return ç»æ |
| | | */ |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException; |
| | | |
| | | /** |
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int changeStatus(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * ç«å³è¿è¡ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public void run(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ |
| | | * |
| | | * @param cronExpression è¡¨è¾¾å¼ |
| | | * @return ç»æ |
| | | */ |
| | | public boolean checkCronExpressionIsValid(String cronExpression); |
| | | } |
| | |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.utils.PageUtils;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.mapper.SysJobLogMapper;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import java.util.Arrays;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ æå¡å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService {
|
| | |
|
| | | @Override
|
| | | public TableDataInfo<SysJobLog> selectPageJobLogList(SysJobLog jobLog) {
|
| | | Map<String, Object> params = jobLog.getParams();
|
| | | LambdaQueryWrapper<SysJobLog> lqw = new LambdaQueryWrapper<SysJobLog>()
|
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus())
|
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget())
|
| | | .apply(Validator.isNotEmpty(params.get("beginTime")),
|
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
|
| | | params.get("beginTime"))
|
| | | .apply(Validator.isNotEmpty(params.get("endTime")),
|
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
|
| | | params.get("endTime"));
|
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw));
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡
|
| | | *
|
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯
|
| | | * @return è°åº¦ä»»å¡æ¥å¿éå
|
| | | */
|
| | | @Override
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) {
|
| | | Map<String, Object> params = jobLog.getParams();
|
| | | return list(new LambdaQueryWrapper<SysJobLog>()
|
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus())
|
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget())
|
| | | .apply(Validator.isNotEmpty(params.get("beginTime")),
|
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
|
| | | params.get("beginTime"))
|
| | | .apply(Validator.isNotEmpty(params.get("endTime")),
|
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
|
| | | params.get("endTime")));
|
| | | }
|
| | |
|
| | | /**
|
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID
|
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | public SysJobLog selectJobLogById(Long jobLogId) {
|
| | | return getById(jobLogId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ°å¢ä»»å¡æ¥å¿
|
| | | *
|
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | public void addJobLog(SysJobLog jobLog) {
|
| | | baseMapper.insert(jobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯
|
| | | *
|
| | | * @param logIds éè¦å é¤çæ°æ®ID
|
| | | * @return ç»æ
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogByIds(Long[] logIds) {
|
| | | return baseMapper.deleteBatchIds(Arrays.asList(logIds));
|
| | | }
|
| | |
|
| | | /**
|
| | | * å é¤ä»»å¡æ¥å¿
|
| | | *
|
| | | * @param jobId è°åº¦æ¥å¿ID
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogById(Long jobId) {
|
| | | return baseMapper.deleteById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ¸
ç©ºä»»å¡æ¥å¿
|
| | | */
|
| | | @Override
|
| | | public void cleanJobLog() {
|
| | | remove(new LambdaQueryWrapper<>());
|
| | | }
|
| | | }
|
| | | package com.ruoyi.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.quartz.domain.SysJobLog; |
| | | import com.ruoyi.quartz.mapper.SysJobLogMapper; |
| | | import com.ruoyi.quartz.service.ISysJobLogService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æ¥å¿ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysJobLogServiceImpl extends ServicePlusImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService { |
| | | |
| | | @Override |
| | | public TableDataInfo<SysJobLog> selectPageJobLogList(SysJobLog jobLog) { |
| | | Map<String, Object> params = jobLog.getParams(); |
| | | LambdaQueryWrapper<SysJobLog> lqw = new LambdaQueryWrapper<SysJobLog>() |
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | | .apply(Validator.isNotEmpty(params.get("endTime")), |
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')", |
| | | params.get("endTime")); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | } |
| | | |
| | | /** |
| | | * è·åquartzè°åº¦å¨æ¥å¿ç计åä»»å¡ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * @return è°åº¦ä»»å¡æ¥å¿éå |
| | | */ |
| | | @Override |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) { |
| | | Map<String, Object> params = jobLog.getParams(); |
| | | return list(new LambdaQueryWrapper<SysJobLog>() |
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | | .apply(Validator.isNotEmpty(params.get("endTime")), |
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')", |
| | | params.get("endTime"))); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡æ¥å¿IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobLogId è°åº¦ä»»å¡æ¥å¿ID |
| | | * @return è°åº¦ä»»å¡æ¥å¿å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysJobLog selectJobLogById(Long jobLogId) { |
| | | return getById(jobLogId); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobLog è°åº¦æ¥å¿ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public void addJobLog(SysJobLog jobLog) { |
| | | baseMapper.insert(jobLog); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦æ¥å¿ä¿¡æ¯ |
| | | * |
| | | * @param logIds éè¦å é¤çæ°æ®ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteJobLogByIds(Long[] logIds) { |
| | | return baseMapper.deleteBatchIds(Arrays.asList(logIds)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä»»å¡æ¥å¿ |
| | | * |
| | | * @param jobId è°åº¦æ¥å¿ID |
| | | */ |
| | | @Override |
| | | public int deleteJobLogById(Long jobId) { |
| | | return baseMapper.deleteById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
ç©ºä»»å¡æ¥å¿ |
| | | */ |
| | | @Override |
| | | public void cleanJobLog() { |
| | | remove(new LambdaQueryWrapper<>()); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.common.utils.PageUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.mapper.SysJobMapper;
|
| | | import com.ruoyi.quartz.service.ISysJobService;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | | import com.ruoyi.quartz.util.ScheduleUtils;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobKey;
|
| | | import org.quartz.Scheduler;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import javax.annotation.PostConstruct;
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ æå¡å±
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService {
|
| | | @Autowired
|
| | | private Scheduler scheduler;
|
| | |
|
| | | /**
|
| | | * 项ç®å¯å¨æ¶ï¼åå§å宿¶å¨ ä¸»è¦æ¯é²æ¢æå¨ä¿®æ¹æ°æ®åºå¯¼è´æªåæ¥å°å®æ¶ä»»å¡å¤çï¼æ³¨ï¼ä¸è½æå¨ä¿®æ¹æ°æ®åºIDåä»»å¡ç»åï¼å¦åä¼å¯¼è´èæ°æ®ï¼
|
| | | */
|
| | | @PostConstruct
|
| | | public void init() throws SchedulerException, TaskException {
|
| | | scheduler.clear();
|
| | | List<SysJob> jobList = list();
|
| | | for (SysJob job : jobList) {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TableDataInfo<SysJob> selectPageJobList(SysJob job) {
|
| | | LambdaQueryWrapper<SysJob> lqw = new LambdaQueryWrapper<SysJob>()
|
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName())
|
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus())
|
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget());
|
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw));
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡å表
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<SysJob> selectJobList(SysJob job) {
|
| | | return list(new LambdaQueryWrapper<SysJob>()
|
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName())
|
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus())
|
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget()));
|
| | | }
|
| | |
|
| | | /**
|
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobId è°åº¦ä»»å¡ID
|
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | public SysJob selectJobById(Long jobId) {
|
| | | return getById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æåä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int pauseJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ¢å¤ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int resumeJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | int rows = baseMapper.deleteById(jobId);
|
| | | if (rows > 0) {
|
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯
|
| | | *
|
| | | * @param jobIds éè¦å é¤çä»»å¡ID
|
| | | * @return ç»æ
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException {
|
| | | for (Long jobId : jobIds) {
|
| | | SysJob job = getById(jobId);
|
| | | deleteJob(job);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int changeStatus(SysJob job) throws SchedulerException {
|
| | | int rows = 0;
|
| | | String status = job.getStatus();
|
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
|
| | | rows = resumeJob(job);
|
| | | } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
|
| | | rows = pauseJob(job);
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * ç«å³è¿è¡ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void run(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | | // åæ°
|
| | | JobDataMap dataMap = new JobDataMap();
|
| | | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
|
| | | scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ°å¢ä»»å¡
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯ è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException {
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = baseMapper.insert(job);
|
| | | if (rows > 0) {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ´æ°ä»»å¡çæ¶é´è¡¨è¾¾å¼
|
| | | *
|
| | | * @param job è°åº¦ä¿¡æ¯
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException {
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | updateSchedulerJob(job, properties.getJobGroup());
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ´æ°ä»»å¡
|
| | | *
|
| | | * @param job ä»»å¡å¯¹è±¡
|
| | | * @param jobGroup ä»»å¡ç»å
|
| | | */
|
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException {
|
| | | Long jobId = job.getJobId();
|
| | | // 夿æ¯å¦åå¨
|
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
| | | if (scheduler.checkExists(jobKey)) {
|
| | | // 鲿¢å建æ¶å卿°æ®é®é¢ å
ç§»é¤ï¼ç¶å卿§è¡å建æä½
|
| | | scheduler.deleteJob(jobKey);
|
| | | }
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ
|
| | | *
|
| | | * @param cronExpression 表达å¼
|
| | | * @return ç»æ
|
| | | */
|
| | | @Override
|
| | | public boolean checkCronExpressionIsValid(String cronExpression) {
|
| | | return CronUtils.isValid(cronExpression);
|
| | | }
|
| | | }
|
| | | package com.ruoyi.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | import com.ruoyi.quartz.mapper.SysJobMapper; |
| | | import com.ruoyi.quartz.service.ISysJobService; |
| | | import com.ruoyi.quartz.util.CronUtils; |
| | | import com.ruoyi.quartz.util.ScheduleUtils; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦ä¿¡æ¯ æå¡å± |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysJobServiceImpl extends ServicePlusImpl<SysJobMapper, SysJob> implements ISysJobService { |
| | | @Autowired |
| | | private Scheduler scheduler; |
| | | |
| | | /** |
| | | * 项ç®å¯å¨æ¶ï¼åå§å宿¶å¨ ä¸»è¦æ¯é²æ¢æå¨ä¿®æ¹æ°æ®åºå¯¼è´æªåæ¥å°å®æ¶ä»»å¡å¤çï¼æ³¨ï¼ä¸è½æå¨ä¿®æ¹æ°æ®åºIDåä»»å¡ç»åï¼å¦åä¼å¯¼è´èæ°æ®ï¼ |
| | | */ |
| | | @PostConstruct |
| | | public void init() throws SchedulerException, TaskException { |
| | | scheduler.clear(); |
| | | List<SysJob> jobList = list(); |
| | | for (SysJob job : jobList) { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public TableDataInfo<SysJob> selectPageJobList(SysJob job) { |
| | | LambdaQueryWrapper<SysJob> lqw = new LambdaQueryWrapper<SysJob>() |
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget()); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | } |
| | | |
| | | /** |
| | | * è·åquartzè°åº¦å¨ç计åä»»å¡å表 |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SysJob> selectJobList(SysJob job) { |
| | | return list(new LambdaQueryWrapper<SysJob>() |
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget())); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è°åº¦ä»»å¡IDæ¥è¯¢è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobId è°åº¦ä»»å¡ID |
| | | * @return è°åº¦ä»»å¡å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public SysJob selectJobById(Long jobId) { |
| | | return getById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * æåä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int pauseJob(SysJob job) throws SchedulerException { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = baseMapper.updateById(job); |
| | | if (rows > 0) { |
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ¢å¤ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int resumeJob(SysJob job) throws SchedulerException { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); |
| | | int rows = baseMapper.updateById(job); |
| | | if (rows > 0) { |
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * å é¤ä»»å¡åï¼æå¯¹åºçtriggerä¹å°è¢«å é¤ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int deleteJob(SysJob job) throws SchedulerException { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | int rows = baseMapper.deleteById(jobId); |
| | | if (rows > 0) { |
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è°åº¦ä¿¡æ¯ |
| | | * |
| | | * @param jobIds éè¦å é¤çä»»å¡ID |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException { |
| | | for (Long jobId : jobIds) { |
| | | SysJob job = getById(jobId); |
| | | deleteJob(job); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä»»å¡è°åº¦ç¶æä¿®æ¹ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int changeStatus(SysJob job) throws SchedulerException { |
| | | int rows = 0; |
| | | String status = job.getStatus(); |
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) { |
| | | rows = resumeJob(job); |
| | | } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) { |
| | | rows = pauseJob(job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * ç«å³è¿è¡ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void run(SysJob job) throws SchedulerException { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | // åæ° |
| | | JobDataMap dataMap = new JobDataMap(); |
| | | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); |
| | | scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä»»å¡ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException { |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = baseMapper.insert(job); |
| | | if (rows > 0) { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡çæ¶é´è¡¨è¾¾å¼ |
| | | * |
| | | * @param job è°åº¦ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException { |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | int rows = baseMapper.updateById(job); |
| | | if (rows > 0) { |
| | | updateSchedulerJob(job, properties.getJobGroup()); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°ä»»å¡ |
| | | * |
| | | * @param job ä»»å¡å¯¹è±¡ |
| | | * @param jobGroup ä»»å¡ç»å |
| | | */ |
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException { |
| | | Long jobId = job.getJobId(); |
| | | // 夿æ¯å¦åå¨ |
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| | | if (scheduler.checkExists(jobKey)) { |
| | | // 鲿¢å建æ¶å卿°æ®é®é¢ å
ç§»é¤ï¼ç¶å卿§è¡å建æä½ |
| | | scheduler.deleteJob(jobKey); |
| | | } |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªcronè¡¨è¾¾å¼æ¯å¦ææ |
| | | * |
| | | * @param cronExpression è¡¨è¾¾å¼ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public boolean checkCronExpressionIsValid(String cronExpression) { |
| | | return CronUtils.isValid(cronExpression); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | |
| | | /** |
| | | * æ ¹æ®è§è²IDæ¥è¯¢é¨é¨æ ä¿¡æ¯ |
| | | * |
| | | * @param roleId è§è²ID |
| | | * @param roleId è§è²ID |
| | | * @param deptCheckStrictly é¨é¨æ 鿩项æ¯å¦å
³èæ¾ç¤º |
| | | * @return éä¸é¨é¨å表 |
| | | */ |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDictType; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | |
| | | /** |
| | | * åå
¸è¡¨ æ°æ®å± |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysNotice; |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysPost; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysRoleDept; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è§è²ä¸é¨é¨å
³è表 æ°æ®å± |
| | |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysRoleDeptMapper extends BaseMapperPlus<SysRoleDept> { |
| | | |
| | | /** |
| | | * æ¹éæ°å¢è§è²é¨é¨ä¿¡æ¯ |
| | | * |
| | | * @param roleDeptList è§è²é¨é¨å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchRoleDept(List<SysRoleDept> roleDeptList); |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è§è²ä¸èåå
³è表 æ°æ®å± |
| | |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysRoleMenuMapper extends BaseMapperPlus<SysRoleMenu> { |
| | | |
| | | /** |
| | | * æ¹éæ°å¢è§è²èåä¿¡æ¯ |
| | | * |
| | | * @param roleMenuList è§è²èåå表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchRoleMenu(List<SysRoleMenu> roleMenuList); |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysUserPost; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç¨æ·ä¸å²ä½å
³è表 æ°æ®å± |
| | |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysUserPostMapper extends BaseMapperPlus<SysUserPost> { |
| | | |
| | | /** |
| | | * æ¹éæ°å¢ç¨æ·å²ä½ä¿¡æ¯ |
| | | * |
| | | * @param userPostList ç¨æ·è§è²å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchUserPost(List<SysUserPost> userPostList); |
| | | |
| | | } |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.common.core.page.BaseMapperPlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç¨æ·ä¸è§è²å
³è表 æ°æ®å± |
| | |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysUserRoleMapper extends BaseMapperPlus<SysUserRole> { |
| | | |
| | | /** |
| | | * æ¹éæ°å¢ç¨æ·è§è²ä¿¡æ¯ |
| | | * |
| | | * @param userRoleList ç¨æ·è§è²å表 |
| | | * @return ç»æ |
| | | */ |
| | | public int batchUserRole(List<SysUserRole> userRoleList); |
| | | |
| | | } |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | |
| | |
| | | |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | import java.util.List; |
| | |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.domain.entity.SysDictType; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | | |
| | |
| | | |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.system.domain.SysNotice; |
| | | |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.system.domain.SysPost; |
| | | |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | import java.util.List; |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.page.IServicePlus; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | import java.util.List; |
| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.enums.DataSourceType; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService { |
| | | public class SysConfigServiceImpl extends ServicePlusImpl<SysConfigMapper, SysConfig> implements ISysConfigService { |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService { |
| | | public class SysDeptServiceImpl extends ServicePlusImpl<SysDeptMapper, SysDept> implements ISysDeptService { |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | |
| | | for (SysDept dept : depts) { |
| | | tempList.add(dept.getDeptId()); |
| | | } |
| | | for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext(); ) { |
| | | SysDept dept = (SysDept) iterator.next(); |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(dept.getParentId())) { |
| | | recursionFn(depts, dept); |
| | | returnList.add(dept); |
| | | } |
| | | } |
| | | for (SysDept dept : depts) { |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(dept.getParentId())) { |
| | | recursionFn(depts, dept); |
| | | returnList.add(dept); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) { |
| | | returnList = depts; |
| | | } |
| | |
| | | int result = count(new LambdaQueryWrapper<SysDept>() |
| | | .eq(SysDept::getParentId, deptId) |
| | | .last("limit 1")); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean checkDeptExistUser(Long deptId) { |
| | | int result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>() |
| | | .eq(SysUser::getDeptId, deptId)); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | int result = baseMapper.updateById(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) { |
| | | // å¦æè¯¥é¨é¨æ¯å¯ç¨ç¶æï¼åå¯ç¨è¯¥é¨é¨çææä¸çº§é¨é¨ |
| | | updateParentDeptStatus(dept); |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | * |
| | | * @param dept å½åé¨é¨ |
| | | */ |
| | | private void updateParentDeptStatus(SysDept dept) { |
| | | String updateBy = dept.getUpdateBy(); |
| | | dept = getById(dept.getDeptId()); |
| | | dept.setUpdateBy(updateBy); |
| | | update(null,new LambdaUpdateWrapper<SysDept>() |
| | | .set(StrUtil.isNotBlank(dept.getStatus()), |
| | | SysDept::getStatus,dept.getStatus()) |
| | | .set(StrUtil.isNotBlank(dept.getUpdateBy()), |
| | | SysDept::getUpdateBy,dept.getUpdateBy()) |
| | | .in(SysDept::getDeptId, Arrays.asList(dept.getAncestors().split(",")))); |
| | | private void updateParentDeptStatusNormal(SysDept dept) { |
| | | String ancestors = dept.getAncestors(); |
| | | Long[] deptIds = Convert.toLongArray(ancestors); |
| | | update(null, new LambdaUpdateWrapper<SysDept>() |
| | | .set(SysDept::getStatus, "0") |
| | | .in(SysDept::getDeptId, Arrays.asList(deptIds))); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹åå
ç´ å
³ç³» |
| | | * |
| | | * @param deptId 被修æ¹çé¨é¨ID |
| | | * @param deptId 被修æ¹çé¨é¨ID |
| | | * @param newAncestors æ°çç¶IDéå |
| | | * @param oldAncestors æ§çç¶IDéå |
| | | */ |
| | |
| | | */ |
| | | private List<SysDept> getChildList(List<SysDept> list, SysDept t) { |
| | | List<SysDept> tlist = new ArrayList<SysDept>(); |
| | | Iterator<SysDept> it = list.iterator(); |
| | | while (it.hasNext()) { |
| | | SysDept n = (SysDept) it.next(); |
| | | if (Validator.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | for (SysDept n : list) { |
| | | if (Validator.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | |
| | | * 夿æ¯å¦æåèç¹ |
| | | */ |
| | | private boolean hasChild(List<SysDept> list, SysDept t) { |
| | | return getChildList(list, t).size() > 0 ? true : false; |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService { |
| | | public class SysDictDataServiceImpl extends ServicePlusImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService { |
| | | |
| | | @Override |
| | | public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData) { |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.domain.entity.SysDictType; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService { |
| | | public class SysDictTypeServiceImpl extends ServicePlusImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService { |
| | | |
| | | @Autowired |
| | | private SysDictDataMapper dictDataMapper; |
| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforMapper, SysLogininfor> implements ISysLogininforService { |
| | | public class SysLogininforServiceImpl extends ServicePlusImpl<SysLogininforMapper, SysLogininfor> implements ISysLogininforService { |
| | | |
| | | @Override |
| | | public TableDataInfo<SysLogininfor> selectPageLogininforList(SysLogininfor logininfor) { |
| | |
| | | params.get("beginTime")) |
| | | .apply(Validator.isNotEmpty(params.get("endTime")), |
| | | "date_format(login_time,'%y%m%d') <= date_format({0},'%y%m%d')", |
| | | params.get("endTime")) |
| | | .orderByDesc(SysLogininfor::getInfoId); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | params.get("endTime")); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage("info_id","desc"), lqw)); |
| | | } |
| | | |
| | | /** |
| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | |
| | | |
| | | /** |
| | | * èå ä¸å¡å±å¤ç |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService { |
| | | public class SysMenuServiceImpl extends ServicePlusImpl<SysMenuMapper, SysMenu> implements ISysMenuService { |
| | | public static final String PREMISSION_STRING = "perms[\"{0}\"]"; |
| | | |
| | | @Autowired |
| | |
| | | router.setComponent(getComponent(menu)); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()))); |
| | | List<SysMenu> cMenus = menu.getChildren(); |
| | | if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | if (!cMenus.isEmpty() && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | router.setAlwaysShow(true); |
| | | router.setRedirect("noRedirect"); |
| | | router.setChildren(buildMenus(cMenus)); |
| | |
| | | for (SysMenu dept : menus) { |
| | | tempList.add(dept.getMenuId()); |
| | | } |
| | | for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext(); ) { |
| | | SysMenu menu = (SysMenu) iterator.next(); |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(menu.getParentId())) { |
| | | recursionFn(menus, menu); |
| | | returnList.add(menu); |
| | | } |
| | | } |
| | | for (SysMenu menu : menus) { |
| | | // 妿æ¯é¡¶çº§èç¹, éå该ç¶èç¹çææåèç¹ |
| | | if (!tempList.contains(menu.getParentId())) { |
| | | recursionFn(menus, menu); |
| | | returnList.add(menu); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) { |
| | | returnList = menus; |
| | | } |
| | |
| | | @Override |
| | | public boolean hasChildByMenuId(Long menuId) { |
| | | int result = count(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getParentId,menuId)); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean checkMenuExistRole(Long menuId) { |
| | | int result = roleMenuMapper.selectCount(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getMenuId,menuId)); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) { |
| | | List<SysMenu> returnList = new ArrayList<SysMenu>(); |
| | | for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext(); ) { |
| | | SysMenu t = (SysMenu) iterator.next(); |
| | | // ä¸ãæ ¹æ®ä¼ å
¥çæä¸ªç¶èç¹ID,éå该ç¶èç¹çææåèç¹ |
| | | if (t.getParentId() == parentId) { |
| | | recursionFn(list, t); |
| | | returnList.add(t); |
| | | } |
| | | } |
| | | for (SysMenu t : list) { |
| | | // ä¸ãæ ¹æ®ä¼ å
¥çæä¸ªç¶èç¹ID,éå该ç¶èç¹çææåèç¹ |
| | | if (t.getParentId() == parentId) { |
| | | recursionFn(list, t); |
| | | returnList.add(t); |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | |
| | | */ |
| | | private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) { |
| | | List<SysMenu> tlist = new ArrayList<SysMenu>(); |
| | | Iterator<SysMenu> it = list.iterator(); |
| | | while (it.hasNext()) { |
| | | SysMenu n = (SysMenu) it.next(); |
| | | if (n.getParentId().longValue() == t.getMenuId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | for (SysMenu n : list) { |
| | | if (n.getParentId().longValue() == t.getMenuId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | |
| | | * 夿æ¯å¦æåèç¹ |
| | | */ |
| | | private boolean hasChild(List<SysMenu> list, SysMenu t) { |
| | | return getChildList(list, t).size() > 0 ? true : false; |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.system.domain.SysNotice; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService { |
| | | public class SysNoticeServiceImpl extends ServicePlusImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService { |
| | | |
| | | @Override |
| | | public TableDataInfo<SysNotice> selectPageNoticeList(SysNotice notice) { |
| | |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService { |
| | | public class SysOperLogServiceImpl extends ServicePlusImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService { |
| | | |
| | | @Override |
| | | public TableDataInfo<SysOperLog> selectPageOperLogList(SysOperLog operLog) { |
| | |
| | | params.get("beginTime")) |
| | | .apply(Validator.isNotEmpty(params.get("endTime")), |
| | | "date_format(oper_time,'%y%m%d') <= date_format({0},'%y%m%d')", |
| | | params.get("endTime")) |
| | | .orderByDesc(SysOperLog::getOperId); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | params.get("endTime")); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage("oper_id","desc"), lqw)); |
| | | } |
| | | |
| | | /** |
| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements ISysPostService { |
| | | public class SysPostServiceImpl extends ServicePlusImpl<SysPostMapper, SysPost> implements ISysPostService { |
| | | |
| | | @Autowired |
| | | private SysUserPostMapper userPostMapper; |
| | |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService { |
| | | public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole> implements ISysRoleService { |
| | | |
| | | @Autowired |
| | | private SysRoleMenuMapper roleMenuMapper; |
| | |
| | | list.add(rm); |
| | | } |
| | | if (list.size() > 0) { |
| | | rows = roleMenuMapper.batchRoleMenu(list); |
| | | rows = roleMenuMapper.insertAll(list); |
| | | } |
| | | return rows; |
| | | } |
| | |
| | | list.add(rd); |
| | | } |
| | | if (list.size() > 0) { |
| | | rows = roleDeptMapper.batchRoleDept(list); |
| | | rows = roleDeptMapper.insertAll(list); |
| | | } |
| | | return rows; |
| | | } |
| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | |
| | | list.add(ur); |
| | | } |
| | | if (list.size() > 0) { |
| | | userRoleMapper.batchUserRole(list); |
| | | userRoleMapper.insertAll(list); |
| | | } |
| | | } |
| | | } |
| | |
| | | list.add(up); |
| | | } |
| | | if (list.size() > 0) { |
| | | userPostMapper.batchUserPost(list); |
| | | userPostMapper.insertAll(list); |
| | | } |
| | | } |
| | | } |
| | |
| | | <result property="deptId" column="dept_id"/> |
| | | </resultMap> |
| | | |
| | | <insert id="batchRoleDept"> |
| | | insert into sys_role_dept(role_id, dept_id) values |
| | | <foreach item="item" index="index" collection="list" separator=","> |
| | | (#{item.roleId},#{item.deptId}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result property="menuId" column="menu_id"/> |
| | | </resultMap> |
| | | |
| | | <insert id="batchRoleMenu"> |
| | | insert into sys_role_menu(role_id, menu_id) values |
| | | <foreach item="item" index="index" collection="list" separator=","> |
| | | (#{item.roleId},#{item.menuId}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result property="postId" column="post_id"/> |
| | | </resultMap> |
| | | |
| | | <insert id="batchUserPost"> |
| | | insert into sys_user_post(user_id, post_id) values |
| | | <foreach item="item" index="index" collection="list" separator=","> |
| | | (#{item.userId},#{item.postId}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result property="roleId" column="role_id"/> |
| | | </resultMap> |
| | | |
| | | <insert id="batchUserRole"> |
| | | insert into sys_user_role(user_id, role_id) values |
| | | <foreach item="item" index="index" collection="list" separator=","> |
| | | (#{item.userId},#{item.roleId}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | # 页颿 é¢ |
| | | VUE_APP_TITLE = RuoYi-Vue-Plusåå°ç®¡çç³»ç» |
| | | |
| | | # å¼åç¯å¢é
ç½® |
| | | ENV = 'development' |
| | | |
| | |
| | | # 页颿 é¢ |
| | | VUE_APP_TITLE = RuoYi-Vue-Plusåå°ç®¡çç³»ç» |
| | | |
| | | # ç产ç¯å¢é
ç½® |
| | | ENV = 'production' |
| | | |
| | |
| | | # 页颿 é¢ |
| | | VUE_APP_TITLE = RuoYi-Vue-Plusåå°ç®¡çç³»ç» |
| | | |
| | | NODE_ENV = production |
| | | |
| | | # æµè¯ç¯å¢é
ç½® |
| | |
| | | "clipboard": "2.0.6", |
| | | "core-js": "3.8.1", |
| | | "echarts": "4.9.0", |
| | | "element-ui": "2.15.0", |
| | | "element-ui": "2.15.2", |
| | | "file-saver": "2.0.4", |
| | | "fuse.js": "6.4.3", |
| | | "highlight.js": "9.18.5", |
| | |
| | | "vue": "2.6.12", |
| | | "vue-count-to": "1.0.13", |
| | | "vue-cropper": "0.5.5", |
| | | "vue-meta": "^2.4.0", |
| | | "vue-router": "3.4.9", |
| | | "vuedraggable": "2.24.3", |
| | | "vuex": "3.6.0" |
| | |
| | | |
| | | <script> |
| | | export default { |
| | | name: 'App' |
| | | name: 'App', |
| | | metaInfo() { |
| | | return { |
| | | title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title, |
| | | titleTemplate: title => { |
| | | return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | |
| | | position: absolute; |
| | | } |
| | | |
| | | @media ( max-width : 768px) { |
| | | .pagination-container .el-pagination > .el-pagination__jump { |
| | | display: none !important; |
| | | } |
| | | .pagination-container .el-pagination > .el-pagination__sizes { |
| | | display: none !important; |
| | | } |
| | | } |
| | | |
| | | .el-table .fixed-width .el-button--mini { |
| | | padding-left: 0; |
| | | padding-right: 0; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template>
|
| | | <div>
|
| | | <template v-for="(item, index) in options">
|
| | | <template v-if="values.includes(item.dictValue)">
|
| | | <span
|
| | | v-if="item.listClass == 'default' || item.listClass == ''"
|
| | | :key="item.dictValue"
|
| | | :index="index"
|
| | | :class="item.cssClass"
|
| | | >{{ item.dictLabel }}</span
|
| | | >
|
| | | <el-tag
|
| | | v-else
|
| | | :key="item.dictValue"
|
| | | :index="index"
|
| | | :type="item.listClass == 'primary' ? '' : item.listClass"
|
| | | :class="item.cssClass"
|
| | | >
|
| | | {{ item.dictLabel }}
|
| | | </el-tag>
|
| | | </template>
|
| | | </template>
|
| | | </div>
|
| | | </template>
|
| | |
|
| | | <script>
|
| | | export default {
|
| | | name: "DictTag",
|
| | | props: {
|
| | | options: {
|
| | | type: Array,
|
| | | default: null,
|
| | | },
|
| | | value: [String, Array],
|
| | | },
|
| | | computed: {
|
| | | values() {
|
| | | if (this.value) {
|
| | | return Array.isArray(this.value) ? this.value : [this.value];
|
| | | } else {
|
| | | return [];
|
| | | }
|
| | | },
|
| | | },
|
| | | };
|
| | | </script>
|
| | | <style scoped>
|
| | | .el-tag + .el-tag {
|
| | | margin-left: 10px;
|
| | | }
|
| | | </style> |
| | |
| | | :page-size.sync="pageSize" |
| | | :layout="layout" |
| | | :page-sizes="pageSizes" |
| | | :pager-count="pagerCount" |
| | | :total="total" |
| | | v-bind="$attrs" |
| | | @size-change="handleSizeChange" |
| | |
| | | return [10, 20, 30, 50] |
| | | } |
| | | }, |
| | | // ç§»å¨ç«¯é¡µç æé®çæ°é端é»è®¤å¼5 |
| | | pagerCount: { |
| | | type: Number, |
| | | default: document.body.clientWidth < 992 ? 5 : 7 |
| | | }, |
| | | layout: { |
| | | type: String, |
| | | default: 'total, sizes, prev, pager, next, jumper' |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template>
|
| | | <div v-loading="loading" :style="'height:' + height">
|
| | | <iframe
|
| | | :src="src"
|
| | | frameborder="no"
|
| | | style="width: 100%; height: 100%"
|
| | | scrolling="auto"
|
| | | />
|
| | | </div>
|
| | | </template>
|
| | | <script>
|
| | | export default {
|
| | | props: {
|
| | | src: {
|
| | | type: String,
|
| | | required: true
|
| | | },
|
| | | },
|
| | | data() {
|
| | | return {
|
| | | height: document.documentElement.clientHeight - 94.5 + "px;",
|
| | | loading: true,
|
| | | url: this.src
|
| | | };
|
| | | },
|
| | | mounted: function () {
|
| | | setTimeout(() => {
|
| | | this.loading = false;
|
| | | }, 300);
|
| | | const that = this;
|
| | | window.onresize = function temp() {
|
| | | that.height = document.documentElement.clientHeight - 94.5 + "px;";
|
| | | };
|
| | | }
|
| | | };
|
| | | </script>
|
| | |
| | | <el-divider/> |
| | | |
| | | <h3 class="drawer-title">ç³»ç»å¸å±é
ç½®</h3> |
| | | |
| | | |
| | | <div class="drawer-item"> |
| | | <span>å¼å¯ TopNav</span> |
| | | <el-switch v-model="topNav" class="drawer-switch" /> |
| | |
| | | <div class="drawer-item"> |
| | | <span>æ¾ç¤º Logo</span> |
| | | <el-switch v-model="sidebarLogo" class="drawer-switch" /> |
| | | </div> |
| | | |
| | | <div class="drawer-item"> |
| | | <span>卿æ é¢</span> |
| | | <el-switch v-model="dynamicTitle" class="drawer-switch" /> |
| | | </div> |
| | | |
| | | <el-divider/> |
| | |
| | | }) |
| | | } |
| | | }, |
| | | dynamicTitle: { |
| | | get() { |
| | | return this.$store.state.settings.dynamicTitle |
| | | }, |
| | | set(val) { |
| | | this.$store.dispatch('settings/changeSetting', { |
| | | key: 'dynamicTitle', |
| | | value: val |
| | | }) |
| | | } |
| | | }, |
| | | }, |
| | | methods: { |
| | | themeChange(val) { |
| | |
| | | "tagsView":${this.tagsView}, |
| | | "fixedHeader":${this.fixedHeader}, |
| | | "sidebarLogo":${this.sidebarLogo}, |
| | | "dynamicTitle":${this.dynamicTitle}, |
| | | "sideTheme":"${this.sideTheme}", |
| | | "theme":"${this.theme}" |
| | | }` |
| | |
| | | <div class="sidebar-logo-container" :class="{'collapse':collapse}" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBg : variables.menuLightBg }"> |
| | | <transition name="sidebarLogoFade"> |
| | | <router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/"> |
| | | <img v-if="logo" :src="logo" class="sidebar-logo"> |
| | | <img v-if="logo" :src="logo" class="sidebar-logo" /> |
| | | <h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.sidebarTitle : variables.sidebarLightTitle }">{{ title }} </h1> |
| | | </router-link> |
| | | <router-link v-else key="expand" class="sidebar-logo-link" to="/"> |
| | | <img v-if="logo" :src="logo" class="sidebar-logo"> |
| | | <img v-if="logo" :src="logo" class="sidebar-logo" /> |
| | | <h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.sidebarTitle : variables.sidebarLightTitle }">{{ title }} </h1> |
| | | </router-link> |
| | | </transition> |
| | |
| | | import { getConfigKey } from "@/api/system/config"; |
| | | import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi"; |
| | | import Pagination from "@/components/Pagination"; |
| | | // èªå®ä¹è¡¨æ ¼å·¥å
·æ©å± |
| | | // èªå®ä¹è¡¨æ ¼å·¥å
·ç»ä»¶ |
| | | import RightToolbar from "@/components/RightToolbar" |
| | | // åå
¸æ ç¾ç»ä»¶ |
| | | import DictTag from '@/components/DictTag' |
| | | // 头鍿 ç¾ç»ä»¶ |
| | | import VueMeta from 'vue-meta' |
| | | |
| | | // å
¨å±æ¹æ³æè½½ |
| | | Vue.prototype.getDicts = getDicts |
| | |
| | | } |
| | | |
| | | // å
¨å±ç»ä»¶æè½½ |
| | | Vue.component('DictTag', DictTag) |
| | | Vue.component('Pagination', Pagination) |
| | | Vue.component('RightToolbar', RightToolbar) |
| | | |
| | | Vue.use(permission) |
| | | Vue.use(VueMeta) |
| | | |
| | | /** |
| | | * If you don't want to use mock-server |
| | |
| | | router.beforeEach((to, from, next) => { |
| | | NProgress.start() |
| | | if (getToken()) { |
| | | to.meta.title && store.dispatch('settings/setTitle', to.meta.title) |
| | | /* has token*/ |
| | | if (to.path === '/login') { |
| | | next({ path: '/' }) |
| | |
| | | module.exports = { |
| | | title: 'RuoYi-Vue-Plusåå°ç®¡çç³»ç»', |
| | | |
| | | /** |
| | | * ä¾§è¾¹æ ä¸»é¢ æ·±è²ä¸»é¢theme-darkï¼æµ
è²ä¸»é¢theme-light |
| | | */ |
| | |
| | | sidebarLogo: true, |
| | | |
| | | /** |
| | | * æ¯å¦æ¾ç¤ºå¨ææ é¢ |
| | | */ |
| | | dynamicTitle: false, |
| | | |
| | | /** |
| | | * @type {string | array} 'production' | ['production', 'development'] |
| | | * @description Need show err logs component. |
| | | * The default is only used in the production env |
| | |
| | | import variables from '@/assets/styles/element-variables.scss' |
| | | import defaultSettings from '@/settings' |
| | | |
| | | const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings |
| | | const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle } = defaultSettings |
| | | |
| | | const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || '' |
| | | const state = { |
| | | title: '', |
| | | theme: storageSetting.theme || variables.theme, |
| | | sideTheme: storageSetting.sideTheme || sideTheme, |
| | | showSettings: showSettings, |
| | | topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav, |
| | | tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView, |
| | | fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader, |
| | | sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo |
| | | sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo, |
| | | dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle |
| | | } |
| | | const mutations = { |
| | | CHANGE_SETTING: (state, { key, value }) => { |
| | |
| | | } |
| | | |
| | | const actions = { |
| | | // ä¿®æ¹å¸å±è®¾ç½® |
| | | changeSetting({ commit }, data) { |
| | | commit('CHANGE_SETTING', data) |
| | | }, |
| | | // 设置ç½é¡µæ é¢ |
| | | setTitle({ commit }, title) { |
| | | state.title = title |
| | | } |
| | | } |
| | | |
| | |
| | | <el-form-item label="å¼" prop="value"> |
| | | <el-input v-model="form.value" placeholder="请è¾å
¥å¼" /> |
| | | </el-form-item> |
| | | <el-form-item label="å建æ¶é´" prop="createTime"> |
| | | <el-date-picker clearable size="small" |
| | | v-model="form.createTime" |
| | | type="datetime" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | placeholder="éæ©å建æ¶é´"> |
| | | </el-date-picker> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button :loading="buttonLoading" type="primary" @click="submitForm">ç¡® å®</el-button> |
| | |
| | | <li>JWT</li> |
| | | <li>MyBatis</li> |
| | | <li>Druid</li> |
| | | <li>Fastjson</li> |
| | | <li>Jackson</li> |
| | | <li>...</li> |
| | | </ul> |
| | | </el-col> |
| | |
| | | <template> |
| | | <div v-loading="loading" :style="'height:'+ height"> |
| | | <iframe :src="src" frameborder="no" style="width: 100%;height: 100%" scrolling="auto" /> |
| | | </div> |
| | | <i-frame :src="url" /> |
| | | </template> |
| | | <script> |
| | | import iFrame from "@/components/iFrame/index"; |
| | | export default { |
| | | name: "Druid", |
| | | components: { iFrame }, |
| | | data() { |
| | | return { |
| | | src: process.env.VUE_APP_BASE_API + "/druid/login.html", |
| | | height: document.documentElement.clientHeight - 94.5 + "px;", |
| | | loading: true |
| | | url: process.env.VUE_APP_BASE_API + "/druid/login.html" |
| | | }; |
| | | }, |
| | | mounted: function() { |
| | | setTimeout(() => { |
| | | this.loading = false; |
| | | }, 230); |
| | | const that = this; |
| | | window.onresize = function temp() { |
| | | that.height = document.documentElement.clientHeight - 94.5 + "px;"; |
| | | }; |
| | | } |
| | | }; |
| | | </script> |
| | |
| | | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | |
| | | <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange"> |
| | | <el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="访é®ç¼å·" align="center" prop="infoId" /> |
| | | <el-table-column label="ç¨æ·åç§°" align="center" prop="userName" /> |
| | | <el-table-column label="ç¨æ·åç§°" align="center" prop="userName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" /> |
| | | <el-table-column label="ç»å½å°å" align="center" prop="ipaddr" width="130" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="ç»å½å°ç¹" align="center" prop="loginLocation" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="æµè§å¨" align="center" prop="browser" /> |
| | | <el-table-column label="æµè§å¨" align="center" prop="browser" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="æä½ç³»ç»" align="center" prop="os" /> |
| | | <el-table-column label="ç»å½ç¶æ" align="center" prop="status" :formatter="statusFormat" /> |
| | | <el-table-column label="æä½ä¿¡æ¯" align="center" prop="msg" /> |
| | | <el-table-column label="ç»å½æ¥æ" align="center" prop="loginTime" width="180"> |
| | | <el-table-column label="ç»å½æ¥æ" align="center" prop="loginTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="180"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ parseTime(scope.row.loginTime) }}</span> |
| | | </template> |
| | |
| | | statusOptions: [], |
| | | // æ¥æèå´ |
| | | dateRange: [], |
| | | // é»è®¤æåº |
| | | defaultSort: {prop: 'loginTime', order: 'descending'}, |
| | | // æ¥è¯¢åæ° |
| | | queryParams: { |
| | | pageNum: 1, |
| | |
| | | resetQuery() { |
| | | this.dateRange = []; |
| | | this.resetForm("queryForm"); |
| | | this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order) |
| | | this.handleQuery(); |
| | | }, |
| | | // å¤éæ¡é䏿°æ® |
| | | /** å¤éæ¡é䏿°æ® */ |
| | | handleSelectionChange(selection) { |
| | | this.ids = selection.map(item => item.infoId) |
| | | this.multiple = !selection.length |
| | | }, |
| | | /** æåºè§¦åäºä»¶ */ |
| | | handleSortChange(column, prop, order) { |
| | | this.queryParams.orderByColumn = column.prop; |
| | | this.queryParams.isAsc = column.order; |
| | | this.getList(); |
| | | }, |
| | | /** å é¤æé®æä½ */ |
| | | handleDelete(row) { |
| | | const infoIds = row.infoId || this.ids; |
| | |
| | | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | |
| | | <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange"> |
| | | <el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="æ¥å¿ç¼å·" align="center" prop="operId" /> |
| | | <el-table-column label="ç³»ç»æ¨¡å" align="center" prop="title" /> |
| | | <el-table-column label="æä½ç±»å" align="center" prop="businessType" :formatter="typeFormat" /> |
| | | <el-table-column label="è¯·æ±æ¹å¼" align="center" prop="requestMethod" /> |
| | | <el-table-column label="æä½äººå" align="center" prop="operName" /> |
| | | <el-table-column label="主æº" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="æä½äººå" align="center" prop="operName" width="100" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" /> |
| | | <el-table-column label="æä½å°å" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="æä½å°ç¹" align="center" prop="operLocation" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="æä½ç¶æ" align="center" prop="status" :formatter="statusFormat" /> |
| | | <el-table-column label="æä½æ¥æ" align="center" prop="operTime" width="180"> |
| | | <el-table-column label="æä½æ¥æ" align="center" prop="operTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="180"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ parseTime(scope.row.operTime) }}</span> |
| | | </template> |
| | |
| | | statusOptions: [], |
| | | // æ¥æèå´ |
| | | dateRange: [], |
| | | // é»è®¤æåº |
| | | defaultSort: {prop: 'operTime', order: 'descending'}, |
| | | // 表ååæ° |
| | | form: {}, |
| | | // æ¥è¯¢åæ° |
| | |
| | | resetQuery() { |
| | | this.dateRange = []; |
| | | this.resetForm("queryForm"); |
| | | this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order) |
| | | this.handleQuery(); |
| | | }, |
| | | // å¤éæ¡é䏿°æ® |
| | | /** å¤éæ¡é䏿°æ® */ |
| | | handleSelectionChange(selection) { |
| | | this.ids = selection.map(item => item.operId) |
| | | this.multiple = !selection.length |
| | | }, |
| | | /** æåºè§¦åäºä»¶ */ |
| | | handleSortChange(column, prop, order) { |
| | | this.queryParams.orderByColumn = column.prop; |
| | | this.queryParams.isAsc = column.order; |
| | | this.getList(); |
| | | }, |
| | | /** è¯¦ç»æé®æä½ */ |
| | | handleView(row) { |
| | | this.open = true; |
| | |
| | | <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="åå
¸ç¼ç " align="center" prop="dictCode" /> |
| | | <el-table-column label="åå
¸æ ç¾" align="center" prop="dictLabel" /> |
| | | <el-table-column label="åå
¸æ ç¾" align="center" prop="dictLabel"> |
| | | <template slot-scope="scope"> |
| | | <span v-if="scope.row.listClass == '' || scope.row.listClass == 'default'">{{scope.row.dictLabel}}</span> |
| | | <el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass">{{scope.row.dictLabel}}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="åå
¸é®å¼" align="center" prop="dictValue" /> |
| | | <el-table-column label="åå
¸æåº" align="center" prop="dictSort" /> |
| | | <el-table-column label="ç¶æ" align="center" prop="status" :formatter="statusFormat" /> |
| | | <el-table-column label="ç¶æ" align="center" prop="status"> |
| | | <template slot-scope="scope"> |
| | | <dict-tag :options="statusOptions" :value="scope.row.status"/> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="夿³¨" align="center" prop="remark" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="å建æ¶é´" align="center" prop="createTime" width="180"> |
| | | <template slot-scope="scope"> |
| | |
| | | <el-form-item label="æ°æ®é®å¼" prop="dictValue"> |
| | | <el-input v-model="form.dictValue" placeholder="请è¾å
¥æ°æ®é®å¼" /> |
| | | </el-form-item> |
| | | <el-form-item label="æ ·å¼å±æ§" prop="cssClass"> |
| | | <el-input v-model="form.cssClass" placeholder="请è¾å
¥æ ·å¼å±æ§" /> |
| | | </el-form-item> |
| | | <el-form-item label="æ¾ç¤ºæåº" prop="dictSort"> |
| | | <el-input-number v-model="form.dictSort" controls-position="right" :min="0" /> |
| | | </el-form-item> |
| | | <el-form-item label="åæ¾æ ·å¼" prop="listClass"> |
| | | <el-select v-model="form.listClass"> |
| | | <el-option |
| | | v-for="item in listClassOptions" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | ></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="ç¶æ" prop="status"> |
| | | <el-radio-group v-model="form.status"> |
| | |
| | | title: "", |
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå± |
| | | open: false, |
| | | // æ°æ®æ ç¾åæ¾æ ·å¼ |
| | | listClassOptions: [ |
| | | { |
| | | value: "default", |
| | | label: "é»è®¤" |
| | | }, |
| | | { |
| | | value: "primary", |
| | | label: "主è¦" |
| | | }, |
| | | { |
| | | value: "success", |
| | | label: "æå" |
| | | }, |
| | | { |
| | | value: "info", |
| | | label: "ä¿¡æ¯" |
| | | }, |
| | | { |
| | | value: "warning", |
| | | label: "è¦å" |
| | | }, |
| | | { |
| | | value: "danger", |
| | | label: "å±é©" |
| | | } |
| | | ], |
| | | // ç¶ææ°æ®åå
¸ |
| | | statusOptions: [], |
| | | // ç±»åæ°æ®åå
¸ |
| | |
| | | this.loading = false; |
| | | }); |
| | | }, |
| | | // æ°æ®ç¶æåå
¸ç¿»è¯ |
| | | statusFormat(row, column) { |
| | | return this.selectDictLabel(this.statusOptions, row.status); |
| | | }, |
| | | // åæ¶æé® |
| | | cancel() { |
| | | this.open = false; |
| | |
| | | dictCode: undefined, |
| | | dictLabel: undefined, |
| | | dictValue: undefined, |
| | | cssClass: undefined, |
| | | listClass: 'default', |
| | | dictSort: 0, |
| | | status: "0", |
| | | remark: undefined |
| | |
| | | </router-link> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="ç¶æ" align="center" prop="status" :formatter="statusFormat" /> |
| | | <el-table-column label="ç¶æ" align="center" prop="status"> |
| | | <template slot-scope="scope"> |
| | | <dict-tag :options="statusOptions" :value="scope.row.status"/> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="夿³¨" align="center" prop="remark" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="å建æ¶é´" align="center" prop="createTime" width="180"> |
| | | <template slot-scope="scope"> |
| | |
| | | this.loading = false; |
| | | } |
| | | ); |
| | | }, |
| | | // åå
¸ç¶æåå
¸ç¿»è¯ |
| | | statusFormat(row, column) { |
| | | return this.selectDictLabel(this.statusOptions, row.status); |
| | | }, |
| | | // åæ¶æé® |
| | | cancel() { |
| | |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ç¨æ·æµç§°" prop="nickName"> |
| | | <el-input v-model="form.nickName" placeholder="请è¾å
¥ç¨æ·æµç§°" /> |
| | | <el-input v-model="form.nickName" placeholder="请è¾å
¥ç¨æ·æµç§°" maxlength="30" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item v-if="form.userId == undefined" label="ç¨æ·åç§°" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="请è¾å
¥ç¨æ·åç§°" /> |
| | | <el-input v-model="form.userName" placeholder="请è¾å
¥ç¨æ·åç§°" maxlength="30" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item v-if="form.userId == undefined" label="ç¨æ·å¯ç " prop="password"> |
| | | <el-input v-model="form.password" placeholder="请è¾å
¥ç¨æ·å¯ç " type="password" /> |
| | | <el-input v-model="form.password" placeholder="请è¾å
¥ç¨æ·å¯ç " type="password" maxlength="20" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | { required: true, message: "ç¨æ·æµç§°ä¸è½ä¸ºç©º", trigger: "blur" } |
| | | ], |
| | | password: [ |
| | | { required: true, message: "ç¨æ·å¯ç ä¸è½ä¸ºç©º", trigger: "blur" } |
| | | { required: true, message: "ç¨æ·å¯ç ä¸è½ä¸ºç©º", trigger: "blur" }, |
| | | { min: 5, max: 20, message: 'ç¨æ·å¯ç é¿åº¦å¿
é¡»ä»äº 5 å 20 ä¹é´', trigger: 'blur' } |
| | | ], |
| | | email: [ |
| | | { |
| | |
| | | }, |
| | | /** æç´¢æé®æä½ */ |
| | | handleQuery() { |
| | | this.queryParams.page = 1; |
| | | this.queryParams.pageNum = 1; |
| | | this.getList(); |
| | | }, |
| | | /** éç½®æé®æä½ */ |
| | |
| | | handleResetPwd(row) { |
| | | this.$prompt('请è¾å
¥"' + row.userName + '"çæ°å¯ç ', "æç¤º", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶" |
| | | cancelButtonText: "åæ¶", |
| | | closeOnClickModal: false, |
| | | inputPattern: /^.{5,20}$/, |
| | | inputErrorMessage: "ç¨æ·å¯ç é¿åº¦å¿
é¡»ä»äº 5 å 20 ä¹é´", |
| | | }).then(({ value }) => { |
| | | resetUserPwd(row.userId, value).then(response => { |
| | | this.msgSuccess("ä¿®æ¹æåï¼æ°å¯ç æ¯ï¼" + value); |
| | |
| | | <template> |
| | | <el-form ref="form" :model="user" :rules="rules" label-width="80px"> |
| | | <el-form-item label="ç¨æ·æµç§°" prop="nickName"> |
| | | <el-input v-model="user.nickName" /> |
| | | <el-input v-model="user.nickName" maxlength="30" /> |
| | | </el-form-item> |
| | | <el-form-item label="ææºå·ç " prop="phonenumber"> |
| | | <el-input v-model="user.phonenumber" maxlength="11" /> |
| | |
| | | <el-select v-model="info.tplCategory" @change="tplSelectChange"> |
| | | <el-option label="å表ï¼å¢å æ¹æ¥ï¼" value="crud" /> |
| | | <el-option label="æ 表ï¼å¢å æ¹æ¥ï¼" value="tree" /> |
| | | <el-option label="主å表ï¼å¢å æ¹æ¥ï¼" value="sub" /> |
| | | <!-- <el-option label="主å表ï¼å¢å æ¹æ¥ï¼" value="sub" />--> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | <template> |
| | | <div v-loading="loading" :style="'height:'+ height"> |
| | | <iframe :src="src" frameborder="no" style="width: 100%;height: 100%" scrolling="auto" /> |
| | | </div> |
| | | <i-frame :src="url" /> |
| | | </template> |
| | | <script> |
| | | import iFrame from "@/components/iFrame/index"; |
| | | export default { |
| | | name: "Swagger", |
| | | components: { iFrame }, |
| | | data() { |
| | | return { |
| | | src: process.env.VUE_APP_BASE_API + "/doc.html", |
| | | height: document.documentElement.clientHeight - 94.5 + "px;", |
| | | loading: true |
| | | url: process.env.VUE_APP_BASE_API + "/doc.html" |
| | | }; |
| | | }, |
| | | mounted: function() { |
| | | setTimeout(() => { |
| | | this.loading = false; |
| | | }, 230); |
| | | const that = this; |
| | | window.onresize = function temp() { |
| | | that.height = document.documentElement.clientHeight - 94.5 + "px;"; |
| | | }; |
| | | } |
| | | }; |
| | | </script> |
| | |
| | | 'use strict' |
| | | const path = require('path') |
| | | const defaultSettings = require('./src/settings.js') |
| | | |
| | | function resolve(dir) { |
| | | return path.join(__dirname, dir) |
| | | } |
| | | |
| | | const name = defaultSettings.title || 'RuoYi-Vue-Plusåå°ç®¡çç³»ç»' // æ é¢ |
| | | const name = process.env.VUE_APP_TITLE || 'RuoYi-Vue-Plusåå°ç®¡çç³»ç»' // ç½é¡µæ é¢ |
| | | |
| | | const port = process.env.port || process.env.npm_config_port || 80 // ç«¯å£ |
| | | |
| | |
| | | # ./ry.sh start å¯å¨ |
| | | # ./ry.sh stop 忢 |
| | | # ./ry.sh restart éå¯ |
| | | # ./ry.sh start ç¶æ |
| | | # ./ry.sh status ç¶æ |
| | | AppName=ruoyi-admin.jar |
| | | |
| | | # JVMåæ° |