diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..fbcab77 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: http://doc.ruoyi.vip/ruoyi-vue/other/donate.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8368a --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +###################################################################### +# Build Tools + +.gradle +/build/ +!gradle/wrapper/gradle-wrapper.jar + +target/ +!.mvn/wrapper/maven-wrapper.jar + +###################################################################### +# IDE + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### JRebel ### +rebel.xml + +### NetBeans ### +nbproject/private/ +build/* +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +###################################################################### +# Others +*.log +*.xml.versionsBackup +*.swp + +!*/build/*.java +!*/build/*.html +!*/build/*.xml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8564f29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2018 RuoYi + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 1869635..e5a47b8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,96 @@ -# kaoshi_houduan +

+ logo +

+

RuoYi v3.8.8

+

基于SpringBoot+Vue前后端分离的Java快速开发框架

+

+ + + +

+## 平台简介 + +若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。 + +* 前端采用Vue、Element UI。 +* 后端采用Spring Boot、Spring Security、Redis & Jwt。 +* 权限认证使用Jwt,支持多终端认证系统。 +* 支持加载动态权限菜单,多方式轻松权限控制。 +* 高效率开发,使用代码生成器可以一键生成前后端代码。 +* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。 +* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。 +* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud) +* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)   +* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)   + +## 内置功能 + +1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。 +2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。 +3. 岗位管理:配置系统用户所属担任职务。 +4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。 +5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。 +6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 +7. 参数管理:对系统动态配置常用参数。 +8. 通知公告:系统通知公告信息发布维护。 +9. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。 +10. 登录日志:系统登录日志记录查询包含登录异常。 +11. 在线用户:当前系统中活跃用户状态监控。 +12. 定时任务:在线(添加、修改、删除)任务调度包含执行结果日志。 +13. 代码生成:前后端代码的生成(java、html、xml、sql)支持CRUD下载 。 +14. 系统接口:根据业务代码自动生成相关的api接口文档。 +15. 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。 +16. 缓存监控:对系统的缓存信息查询,命令统计等。 +17. 在线构建器:拖动表单元素生成相应的HTML代码。 +18. 连接池监视:监视当前系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。 + +## 在线体验 + +- admin/admin123 +- 陆陆续续收到一些打赏,为了更好的体验已用于演示服务器升级。谢谢各位小伙伴。 + +演示地址:http://vue.ruoyi.vip +文档地址:http://doc.ruoyi.vip + +## 演示图 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +## 若依前后端分离交流群 + +QQ群: [![加入QQ群](https://img.shields.io/badge/已满-937441-blue.svg)](https://jq.qq.com/?_wv=1027&k=5bVB1og) [![加入QQ群](https://img.shields.io/badge/已满-887144332-blue.svg)](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [![加入QQ群](https://img.shields.io/badge/已满-180251782-blue.svg)](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [![加入QQ群](https://img.shields.io/badge/已满-104180207-blue.svg)](https://jq.qq.com/?_wv=1027&k=51G72yr) [![加入QQ群](https://img.shields.io/badge/已满-186866453-blue.svg)](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [![加入QQ群](https://img.shields.io/badge/已满-201396349-blue.svg)](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [![加入QQ群](https://img.shields.io/badge/已满-101456076-blue.svg)](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [![加入QQ群](https://img.shields.io/badge/已满-101539465-blue.svg)](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) [![加入QQ群](https://img.shields.io/badge/已满-264312783-blue.svg)](https://jq.qq.com/?_wv=1027&k=EI9an8lJ) [![加入QQ群](https://img.shields.io/badge/已满-167385320-blue.svg)](https://jq.qq.com/?_wv=1027&k=SWCtLnMz) [![加入QQ群](https://img.shields.io/badge/已满-104748341-blue.svg)](https://jq.qq.com/?_wv=1027&k=96Dkdq0k) [![加入QQ群](https://img.shields.io/badge/已满-160110482-blue.svg)](https://jq.qq.com/?_wv=1027&k=0fsNiYZt) [![加入QQ群](https://img.shields.io/badge/已满-170801498-blue.svg)](https://jq.qq.com/?_wv=1027&k=7xw4xUG1) [![加入QQ群](https://img.shields.io/badge/已满-108482800-blue.svg)](https://jq.qq.com/?_wv=1027&k=eCx8eyoJ) [![加入QQ群](https://img.shields.io/badge/已满-101046199-blue.svg)](https://jq.qq.com/?_wv=1027&k=SpyH2875) [![加入QQ群](https://img.shields.io/badge/已满-136919097-blue.svg)](https://jq.qq.com/?_wv=1027&k=tKEt51dz) [![加入QQ群](https://img.shields.io/badge/已满-143961921-blue.svg)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=0vBbSb0ztbBgVtn3kJS-Q4HUNYwip89G&authKey=8irq5PhutrZmWIvsUsklBxhj57l%2F1nOZqjzigkXZVoZE451GG4JHPOqW7AW6cf0T&noverify=0&group_code=143961921) [![加入QQ群](https://img.shields.io/badge/已满-174951577-blue.svg)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=ZFAPAbp09S2ltvwrJzp7wGlbopsc0rwi&authKey=HB2cxpxP2yspk%2Bo3WKTBfktRCccVkU26cgi5B16u0KcAYrVu7sBaE7XSEqmMdFQp&noverify=0&group_code=174951577) [![加入QQ群](https://img.shields.io/badge/已满-161281055-blue.svg)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=Fn2aF5IHpwsy8j6VlalNJK6qbwFLFHat&authKey=uyIT%2B97x2AXj3odyXpsSpVaPMC%2Bidw0LxG5MAtEqlrcBcWJUA%2FeS43rsF1Tg7IRJ&noverify=0&group_code=161281055) [![加入QQ群](https://img.shields.io/badge/已满-138988063-blue.svg)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=XIzkm_mV2xTsUtFxo63bmicYoDBA6Ifm&authKey=dDW%2F4qsmw3x9govoZY9w%2FoWAoC4wbHqGal%2BbqLzoS6VBarU8EBptIgPKN%2FviyC8j&noverify=0&group_code=138988063) [![加入QQ群](https://img.shields.io/badge/151450850-blue.svg)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=DkugnCg68PevlycJSKSwjhFqfIgrWWwR&authKey=pR1Pa5lPIeGF%2FFtIk6d%2FGB5qFi0EdvyErtpQXULzo03zbhopBHLWcuqdpwY241R%2F&noverify=0&group_code=151450850) 点击按钮入群。 \ No newline at end of file diff --git a/bin/clean.bat b/bin/clean.bat new file mode 100644 index 0000000..24c0974 --- /dev/null +++ b/bin/clean.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [Ϣ] target· +echo. + +%~d0 +cd %~dp0 + +cd .. +call mvn clean + +pause \ No newline at end of file diff --git a/bin/package.bat b/bin/package.bat new file mode 100644 index 0000000..c693ec0 --- /dev/null +++ b/bin/package.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [Ϣ] Weḅwar/jarļ +echo. + +%~d0 +cd %~dp0 + +cd .. +call mvn clean package -Dmaven.test.skip=true + +pause \ No newline at end of file diff --git a/bin/run.bat b/bin/run.bat new file mode 100644 index 0000000..41efbd0 --- /dev/null +++ b/bin/run.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] ʹJarWeb̡ +echo. + +cd %~dp0 +cd ../ruoyi-admin/target + +set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -jar %JAVA_OPTS% ruoyi-admin.jar + +cd bin +pause \ No newline at end of file diff --git a/doc/若依环境使用手册.docx b/doc/若依环境使用手册.docx new file mode 100644 index 0000000..9e4daef Binary files /dev/null and b/doc/若依环境使用手册.docx differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e222f12 --- /dev/null +++ b/pom.xml @@ -0,0 +1,244 @@ + + + 4.0.0 + + com.ruoyi + ruoyi + 3.8.8 + + ruoyi + http://www.ruoyi.vip + 若依管理系统 + + + 3.8.8 + UTF-8 + UTF-8 + 8 + 3.1.1 + 5.3.33 + 5.7.12 + 1.2.23 + 1.21 + 3.0.0 + 2.3.3 + 1.4.7 + 2.0.53 + 6.6.3 + 2.13.0 + 4.1.2 + 2.3 + 0.9.1 + + + + + + + + + org.springframework + spring-framework-bom + ${spring-framework.version} + pom + import + + + + + org.springframework.security + spring-security-bom + ${spring-security.version} + pom + import + + + + + org.springframework.boot + spring-boot-dependencies + 2.5.15 + pom + import + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + + eu.bitwalker + UserAgentUtils + ${bitwalker.version} + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + ${pagehelper.boot.version} + + + + + com.github.oshi + oshi-core + ${oshi.version} + + + + + io.springfox + springfox-boot-starter + ${swagger.version} + + + io.swagger + swagger-models + + + + + + + commons-io + commons-io + ${commons.io.version} + + + + + org.apache.poi + poi-ooxml + ${poi.version} + + + + + org.apache.velocity + velocity-engine-core + ${velocity.version} + + + + + com.alibaba.fastjson2 + fastjson2 + ${fastjson.version} + + + + + io.jsonwebtoken + jjwt + ${jwt.version} + + + + + pro.fessional + kaptcha + ${kaptcha.version} + + + + + com.ruoyi + ruoyi-quartz + ${ruoyi.version} + + + + + com.ruoyi + ruoyi-generator + ${ruoyi.version} + + + + + com.ruoyi + ruoyi-framework + ${ruoyi.version} + + + + + com.ruoyi + ruoyi-system + ${ruoyi.version} + + + + + com.ruoyi + ruoyi-common + ${ruoyi.version} + + + + com.ruoyi + ruoyi-test + ${ruoyi.version} + + + + + + ruoyi-admin + ruoyi-framework + ruoyi-system + ruoyi-quartz + ruoyi-generator + ruoyi-common + ruoyi-test + + pom + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public + + true + + + false + + + + + \ No newline at end of file diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml new file mode 100644 index 0000000..46e8c16 --- /dev/null +++ b/ruoyi-admin/pom.xml @@ -0,0 +1,106 @@ + + + + ruoyi + com.ruoyi + 3.8.8 + + 4.0.0 + jar + ruoyi-admin + + + web服务入口 + + + + + + + org.springframework.boot + spring-boot-devtools + true + + + + + io.springfox + springfox-boot-starter + + + + + io.swagger + swagger-models + 1.6.2 + + + + + mysql + mysql-connector-java + + + + + com.ruoyi + ruoyi-framework + + + + + com.ruoyi + ruoyi-quartz + + + + + com.ruoyi + ruoyi-generator + + + + com.ruoyi + ruoyi-test + + + org.projectlombok + lombok + provided + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.5.15 + + true + + + + + repackage + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + ${project.artifactId} + + + + ${project.artifactId} + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java new file mode 100644 index 0000000..32eb6f1 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java @@ -0,0 +1,30 @@ +package com.ruoyi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +/** + * 启动程序 + * + * @author ruoyi + */ +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +public class RuoYiApplication +{ + public static void main(String[] args) + { + // System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(RuoYiApplication.class, args); + System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + + " .-------. ____ __ \n" + + " | _ _ \\ \\ \\ / / \n" + + " | ( ' ) | \\ _. / ' \n" + + " |(_ o _) / _( )_ .' \n" + + " | (_,_).' __ ___(_ o _)' \n" + + " | |\\ \\ | || |(_,_)' \n" + + " | | \\ `' /| `-' / \n" + + " | | \\ / \\ / \n" + + " ''-' `'-' `-..-' "); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiServletInitializer.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiServletInitializer.java new file mode 100644 index 0000000..6de67dc --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiServletInitializer.java @@ -0,0 +1,18 @@ +package com.ruoyi; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * web容器中进行部署 + * + * @author ruoyi + */ +public class RuoYiServletInitializer extends SpringBootServletInitializer +{ + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) + { + return application.sources(RuoYiApplication.class); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java new file mode 100644 index 0000000..d2d6e8c --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java @@ -0,0 +1,94 @@ +package com.ruoyi.web.controller.common; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Resource; +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.FastByteArrayOutputStream; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import com.google.code.kaptcha.Producer; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.sign.Base64; +import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.system.service.ISysConfigService; + +/** + * 验证码操作处理 + * + * @author ruoyi + */ +@RestController +public class CaptchaController +{ + @Resource(name = "captchaProducer") + private Producer captchaProducer; + + @Resource(name = "captchaProducerMath") + private Producer captchaProducerMath; + + @Autowired + private RedisCache redisCache; + + @Autowired + private ISysConfigService configService; + /** + * 生成验证码 + */ + @GetMapping("/captchaImage") + public AjaxResult getCode(HttpServletResponse response) throws IOException + { + AjaxResult ajax = AjaxResult.success(); + boolean captchaEnabled = configService.selectCaptchaEnabled(); + ajax.put("captchaEnabled", captchaEnabled); + if (!captchaEnabled) + { + return ajax; + } + + // 保存验证码信息 + String uuid = IdUtils.simpleUUID(); + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; + + String capStr = null, code = null; + BufferedImage image = null; + + // 生成验证码 + String captchaType = RuoYiConfig.getCaptchaType(); + if ("math".equals(captchaType)) + { + String capText = captchaProducerMath.createText(); + capStr = capText.substring(0, capText.lastIndexOf("@")); + code = capText.substring(capText.lastIndexOf("@") + 1); + image = captchaProducerMath.createImage(capStr); + } + else if ("char".equals(captchaType)) + { + capStr = code = captchaProducer.createText(); + image = captchaProducer.createImage(capStr); + } + + redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); + // 转换流信息写出 + FastByteArrayOutputStream os = new FastByteArrayOutputStream(); + try + { + ImageIO.write(image, "jpg", os); + } + catch (IOException e) + { + return AjaxResult.error(e.getMessage()); + } + + ajax.put("uuid", uuid); + ajax.put("img", Base64.encode(os.toByteArray())); + return ajax; + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java new file mode 100644 index 0000000..cec5006 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -0,0 +1,163 @@ +package com.ruoyi.web.controller.common; + +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.framework.config.ServerConfig; + +/** + * 通用请求处理 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/common") +public class CommonController +{ + private static final Logger log = LoggerFactory.getLogger(CommonController.class); + + @Autowired + private ServerConfig serverConfig; + + private static final String FILE_DELIMETER = ","; + + /** + * 通用下载请求 + * + * @param fileName 文件名称 + * @param delete 是否删除 + */ + @GetMapping("/download") + public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) + { + try + { + if (!FileUtils.checkAllowDownload(fileName)) + { + throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); + } + String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); + String filePath = RuoYiConfig.getDownloadPath() + fileName; + + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, realFileName); + FileUtils.writeBytes(filePath, response.getOutputStream()); + if (delete) + { + FileUtils.deleteFile(filePath); + } + } + catch (Exception e) + { + log.error("下载文件失败", e); + } + } + + /** + * 通用上传请求(单个) + */ + @PostMapping("/upload") + public AjaxResult uploadFile(MultipartFile file) throws Exception + { + try + { + // 上传文件路径 + String filePath = RuoYiConfig.getUploadPath(); + // 上传并返回新文件名称 + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + AjaxResult ajax = AjaxResult.success(); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); + return ajax; + } + catch (Exception e) + { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 通用上传请求(多个) + */ + @PostMapping("/uploads") + public AjaxResult uploadFiles(List files) throws Exception + { + try + { + // 上传文件路径 + String filePath = RuoYiConfig.getUploadPath(); + List urls = new ArrayList(); + List fileNames = new ArrayList(); + List newFileNames = new ArrayList(); + List originalFilenames = new ArrayList(); + for (MultipartFile file : files) + { + // 上传并返回新文件名称 + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + urls.add(url); + fileNames.add(fileName); + newFileNames.add(FileUtils.getName(fileName)); + originalFilenames.add(file.getOriginalFilename()); + } + AjaxResult ajax = AjaxResult.success(); + ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); + ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); + ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); + ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); + return ajax; + } + catch (Exception e) + { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 本地资源通用下载 + */ + @GetMapping("/download/resource") + public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) + throws Exception + { + try + { + if (!FileUtils.checkAllowDownload(resource)) + { + throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource)); + } + // 本地资源路径 + String localPath = RuoYiConfig.getProfile(); + // 数据库资源地址 + String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); + // 下载名称 + String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, downloadName); + FileUtils.writeBytes(downloadPath, response.getOutputStream()); + } + catch (Exception e) + { + log.error("下载文件失败", e); + } + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java new file mode 100644 index 0000000..c8c49c9 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java @@ -0,0 +1,121 @@ +package com.ruoyi.web.controller.monitor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.SysCache; + +/** + * 缓存监控 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/monitor/cache") +public class CacheController +{ + @Autowired + private RedisTemplate redisTemplate; + + private final static List caches = new ArrayList(); + { + caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息")); + caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息")); + caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典")); + caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码")); + caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交")); + caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理")); + caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数")); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping() + public AjaxResult getInfo() throws Exception + { + Properties info = (Properties) redisTemplate.execute((RedisCallback) connection -> connection.info()); + Properties commandStats = (Properties) redisTemplate.execute((RedisCallback) connection -> connection.info("commandstats")); + Object dbSize = redisTemplate.execute((RedisCallback) connection -> connection.dbSize()); + + Map result = new HashMap<>(3); + result.put("info", info); + result.put("dbSize", dbSize); + + List> pieList = new ArrayList<>(); + commandStats.stringPropertyNames().forEach(key -> { + Map data = new HashMap<>(2); + String property = commandStats.getProperty(key); + data.put("name", StringUtils.removeStart(key, "cmdstat_")); + data.put("value", StringUtils.substringBetween(property, "calls=", ",usec")); + pieList.add(data); + }); + result.put("commandStats", pieList); + return AjaxResult.success(result); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getNames") + public AjaxResult cache() + { + return AjaxResult.success(caches); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getKeys/{cacheName}") + public AjaxResult getCacheKeys(@PathVariable String cacheName) + { + Set cacheKeys = redisTemplate.keys(cacheName + "*"); + return AjaxResult.success(new TreeSet<>(cacheKeys)); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @GetMapping("/getValue/{cacheName}/{cacheKey}") + public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) + { + String cacheValue = redisTemplate.opsForValue().get(cacheKey); + SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue); + return AjaxResult.success(sysCache); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheName/{cacheName}") + public AjaxResult clearCacheName(@PathVariable String cacheName) + { + Collection cacheKeys = redisTemplate.keys(cacheName + "*"); + redisTemplate.delete(cacheKeys); + return AjaxResult.success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheKey/{cacheKey}") + public AjaxResult clearCacheKey(@PathVariable String cacheKey) + { + redisTemplate.delete(cacheKey); + return AjaxResult.success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:cache:list')") + @DeleteMapping("/clearCacheAll") + public AjaxResult clearCacheAll() + { + Collection cacheKeys = redisTemplate.keys("*"); + redisTemplate.delete(cacheKeys); + return AjaxResult.success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java new file mode 100644 index 0000000..cc805ad --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java @@ -0,0 +1,27 @@ +package com.ruoyi.web.controller.monitor; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.framework.web.domain.Server; + +/** + * 服务器监控 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/monitor/server") +public class ServerController +{ + @PreAuthorize("@ss.hasPermi('monitor:server:list')") + @GetMapping() + public AjaxResult getInfo() throws Exception + { + Server server = new Server(); + server.copyTo(); + return AjaxResult.success(server); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java new file mode 100644 index 0000000..e0175f4 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java @@ -0,0 +1,82 @@ +package com.ruoyi.web.controller.monitor; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.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.utils.poi.ExcelUtil; +import com.ruoyi.framework.web.service.SysPasswordService; +import com.ruoyi.system.domain.SysLogininfor; +import com.ruoyi.system.service.ISysLogininforService; + +/** + * 系统访问记录 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/monitor/logininfor") +public class SysLogininforController extends BaseController +{ + @Autowired + private ISysLogininforService logininforService; + + @Autowired + private SysPasswordService passwordService; + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')") + @GetMapping("/list") + public TableDataInfo list(SysLogininfor logininfor) + { + startPage(); + List list = logininforService.selectLogininforList(logininfor); + return getDataTable(list); + } + + @Log(title = "登录日志", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysLogininfor logininfor) + { + List list = logininforService.selectLogininforList(logininfor); + ExcelUtil util = new ExcelUtil(SysLogininfor.class); + util.exportExcel(response, list, "登录日志"); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") + @Log(title = "登录日志", businessType = BusinessType.DELETE) + @DeleteMapping("/{infoIds}") + public AjaxResult remove(@PathVariable Long[] infoIds) + { + return toAjax(logininforService.deleteLogininforByIds(infoIds)); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") + @Log(title = "登录日志", businessType = BusinessType.CLEAN) + @DeleteMapping("/clean") + public AjaxResult clean() + { + logininforService.cleanLogininfor(); + return success(); + } + + @PreAuthorize("@ss.hasPermi('monitor:logininfor:unlock')") + @Log(title = "账户解锁", businessType = BusinessType.OTHER) + @GetMapping("/unlock/{userName}") + public AjaxResult unlock(@PathVariable("userName") String userName) + { + passwordService.clearLoginRecordCache(userName); + return success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java new file mode 100644 index 0000000..6ca78cf --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java @@ -0,0 +1,69 @@ +package com.ruoyi.web.controller.monitor; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.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.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.SysOperLog; +import com.ruoyi.system.service.ISysOperLogService; + +/** + * 操作日志记录 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/monitor/operlog") +public class SysOperlogController extends BaseController +{ + @Autowired + private ISysOperLogService operLogService; + + @PreAuthorize("@ss.hasPermi('monitor:operlog:list')") + @GetMapping("/list") + public TableDataInfo list(SysOperLog operLog) + { + startPage(); + List list = operLogService.selectOperLogList(operLog); + return getDataTable(list); + } + + @Log(title = "操作日志", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('monitor:operlog:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysOperLog operLog) + { + List list = operLogService.selectOperLogList(operLog); + ExcelUtil util = new ExcelUtil(SysOperLog.class); + util.exportExcel(response, list, "操作日志"); + } + + @Log(title = "操作日志", businessType = BusinessType.DELETE) + @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") + @DeleteMapping("/{operIds}") + public AjaxResult remove(@PathVariable Long[] operIds) + { + return toAjax(operLogService.deleteOperLogByIds(operIds)); + } + + @Log(title = "操作日志", businessType = BusinessType.CLEAN) + @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") + @DeleteMapping("/clean") + public AjaxResult clean() + { + operLogService.cleanOperLog(); + return success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java new file mode 100644 index 0000000..a442863 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java @@ -0,0 +1,83 @@ +package com.ruoyi.web.controller.monitor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.SysUserOnline; +import com.ruoyi.system.service.ISysUserOnlineService; + +/** + * 在线用户监控 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/monitor/online") +public class SysUserOnlineController extends BaseController +{ + @Autowired + private ISysUserOnlineService userOnlineService; + + @Autowired + private RedisCache redisCache; + + @PreAuthorize("@ss.hasPermi('monitor:online:list')") + @GetMapping("/list") + public TableDataInfo list(String ipaddr, String userName) + { + Collection keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); + List userOnlineList = new ArrayList(); + for (String key : keys) + { + LoginUser user = redisCache.getCacheObject(key); + if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) + { + userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); + } + else if (StringUtils.isNotEmpty(ipaddr)) + { + userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); + } + else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) + { + userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); + } + else + { + userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); + } + } + Collections.reverse(userOnlineList); + userOnlineList.removeAll(Collections.singleton(null)); + return getDataTable(userOnlineList); + } + + /** + * 强退用户 + */ + @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") + @Log(title = "在线用户", businessType = BusinessType.FORCE) + @DeleteMapping("/{tokenId}") + public AjaxResult forceLogout(@PathVariable String tokenId) + { + redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId); + return success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java new file mode 100644 index 0000000..ab4653d --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java @@ -0,0 +1,133 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.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.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.SysConfig; +import com.ruoyi.system.service.ISysConfigService; + +/** + * 参数配置 信息操作处理 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/config") +public class SysConfigController extends BaseController +{ + @Autowired + private ISysConfigService configService; + + /** + * 获取参数配置列表 + */ + @PreAuthorize("@ss.hasPermi('system:config:list')") + @GetMapping("/list") + public TableDataInfo list(SysConfig config) + { + startPage(); + List list = configService.selectConfigList(config); + return getDataTable(list); + } + + @Log(title = "参数管理", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:config:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysConfig config) + { + List list = configService.selectConfigList(config); + ExcelUtil util = new ExcelUtil(SysConfig.class); + util.exportExcel(response, list, "参数数据"); + } + + /** + * 根据参数编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:config:query')") + @GetMapping(value = "/{configId}") + public AjaxResult getInfo(@PathVariable Long configId) + { + return success(configService.selectConfigById(configId)); + } + + /** + * 根据参数键名查询参数值 + */ + @GetMapping(value = "/configKey/{configKey}") + public AjaxResult getConfigKey(@PathVariable String configKey) + { + return success(configService.selectConfigByKey(configKey)); + } + + /** + * 新增参数配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:add')") + @Log(title = "参数管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysConfig config) + { + if (!configService.checkConfigKeyUnique(config)) + { + return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在"); + } + config.setCreateBy(getUsername()); + return toAjax(configService.insertConfig(config)); + } + + /** + * 修改参数配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:edit')") + @Log(title = "参数管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysConfig config) + { + if (!configService.checkConfigKeyUnique(config)) + { + return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在"); + } + config.setUpdateBy(getUsername()); + return toAjax(configService.updateConfig(config)); + } + + /** + * 删除参数配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:remove')") + @Log(title = "参数管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{configIds}") + public AjaxResult remove(@PathVariable Long[] configIds) + { + configService.deleteConfigByIds(configIds); + return success(); + } + + /** + * 刷新参数缓存 + */ + @PreAuthorize("@ss.hasPermi('system:config:remove')") + @Log(title = "参数管理", businessType = BusinessType.CLEAN) + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() + { + configService.resetConfigCache(); + return success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java new file mode 100644 index 0000000..59e7588 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -0,0 +1,132 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.service.ISysDeptService; + +/** + * 部门信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/dept") +public class SysDeptController extends BaseController +{ + @Autowired + private ISysDeptService deptService; + + /** + * 获取部门列表 + */ + @PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list") + public AjaxResult list(SysDept dept) + { + List depts = deptService.selectDeptList(dept); + return success(depts); + } + + /** + * 查询部门列表(排除节点) + */ + @PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list/exclude/{deptId}") + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) + { + List depts = deptService.selectDeptList(new SysDept()); + depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); + return success(depts); + } + + /** + * 根据部门编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:dept:query')") + @GetMapping(value = "/{deptId}") + public AjaxResult getInfo(@PathVariable Long deptId) + { + deptService.checkDeptDataScope(deptId); + return success(deptService.selectDeptById(deptId)); + } + + /** + * 新增部门 + */ + @PreAuthorize("@ss.hasPermi('system:dept:add')") + @Log(title = "部门管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDept dept) + { + if (!deptService.checkDeptNameUnique(dept)) + { + return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + } + dept.setCreateBy(getUsername()); + return toAjax(deptService.insertDept(dept)); + } + + /** + * 修改部门 + */ + @PreAuthorize("@ss.hasPermi('system:dept:edit')") + @Log(title = "部门管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDept dept) + { + Long deptId = dept.getDeptId(); + deptService.checkDeptDataScope(deptId); + if (!deptService.checkDeptNameUnique(dept)) + { + return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + } + else if (dept.getParentId().equals(deptId)) + { + return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); + } + else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) + { + return error("该部门包含未停用的子部门!"); + } + dept.setUpdateBy(getUsername()); + return toAjax(deptService.updateDept(dept)); + } + + /** + * 删除部门 + */ + @PreAuthorize("@ss.hasPermi('system:dept:remove')") + @Log(title = "部门管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{deptId}") + public AjaxResult remove(@PathVariable Long deptId) + { + if (deptService.hasChildByDeptId(deptId)) + { + return warn("存在下级部门,不允许删除"); + } + if (deptService.checkDeptExistUser(deptId)) + { + return warn("部门存在用户,不允许删除"); + } + deptService.checkDeptDataScope(deptId); + return toAjax(deptService.deleteDeptById(deptId)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java new file mode 100644 index 0000000..59becaf --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java @@ -0,0 +1,121 @@ +package com.ruoyi.web.controller.system; + +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.service.ISysDictDataService; +import com.ruoyi.system.service.ISysDictTypeService; + +/** + * 数据字典信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/dict/data") +public class SysDictDataController extends BaseController +{ + @Autowired + private ISysDictDataService dictDataService; + + @Autowired + private ISysDictTypeService dictTypeService; + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @GetMapping("/list") + public TableDataInfo list(SysDictData dictData) + { + startPage(); + List list = dictDataService.selectDictDataList(dictData); + return getDataTable(list); + } + + @Log(title = "字典数据", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:dict:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysDictData dictData) + { + List list = dictDataService.selectDictDataList(dictData); + ExcelUtil util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, list, "字典数据"); + } + + /** + * 查询字典数据详细 + */ + @PreAuthorize("@ss.hasPermi('system:dict:query')") + @GetMapping(value = "/{dictCode}") + public AjaxResult getInfo(@PathVariable Long dictCode) + { + return success(dictDataService.selectDictDataById(dictCode)); + } + + /** + * 根据字典类型查询字典数据信息 + */ + @GetMapping(value = "/type/{dictType}") + public AjaxResult dictType(@PathVariable String dictType) + { + List data = dictTypeService.selectDictDataByType(dictType); + if (StringUtils.isNull(data)) + { + data = new ArrayList(); + } + return success(data); + } + + /** + * 新增字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @Log(title = "字典数据", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDictData dict) + { + dict.setCreateBy(getUsername()); + return toAjax(dictDataService.insertDictData(dict)); + } + + /** + * 修改保存字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:edit')") + @Log(title = "字典数据", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDictData dict) + { + dict.setUpdateBy(getUsername()); + return toAjax(dictDataService.updateDictData(dict)); + } + + /** + * 删除字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "字典类型", businessType = BusinessType.DELETE) + @DeleteMapping("/{dictCodes}") + public AjaxResult remove(@PathVariable Long[] dictCodes) + { + dictDataService.deleteDictDataByIds(dictCodes); + return success(); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java new file mode 100644 index 0000000..c53867c --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java @@ -0,0 +1,131 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDictType; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.service.ISysDictTypeService; + +/** + * 数据字典信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/dict/type") +public class SysDictTypeController extends BaseController +{ + @Autowired + private ISysDictTypeService dictTypeService; + + @PreAuthorize("@ss.hasPermi('system:dict:list')") + @GetMapping("/list") + public TableDataInfo list(SysDictType dictType) + { + startPage(); + List list = dictTypeService.selectDictTypeList(dictType); + return getDataTable(list); + } + + @Log(title = "字典类型", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:dict:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysDictType dictType) + { + List list = dictTypeService.selectDictTypeList(dictType); + ExcelUtil util = new ExcelUtil(SysDictType.class); + util.exportExcel(response, list, "字典类型"); + } + + /** + * 查询字典类型详细 + */ + @PreAuthorize("@ss.hasPermi('system:dict:query')") + @GetMapping(value = "/{dictId}") + public AjaxResult getInfo(@PathVariable Long dictId) + { + return success(dictTypeService.selectDictTypeById(dictId)); + } + + /** + * 新增字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:add')") + @Log(title = "字典类型", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysDictType dict) + { + if (!dictTypeService.checkDictTypeUnique(dict)) + { + return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在"); + } + dict.setCreateBy(getUsername()); + return toAjax(dictTypeService.insertDictType(dict)); + } + + /** + * 修改字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:edit')") + @Log(title = "字典类型", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysDictType dict) + { + if (!dictTypeService.checkDictTypeUnique(dict)) + { + return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在"); + } + dict.setUpdateBy(getUsername()); + return toAjax(dictTypeService.updateDictType(dict)); + } + + /** + * 删除字典类型 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "字典类型", businessType = BusinessType.DELETE) + @DeleteMapping("/{dictIds}") + public AjaxResult remove(@PathVariable Long[] dictIds) + { + dictTypeService.deleteDictTypeByIds(dictIds); + return success(); + } + + /** + * 刷新字典缓存 + */ + @PreAuthorize("@ss.hasPermi('system:dict:remove')") + @Log(title = "字典类型", businessType = BusinessType.CLEAN) + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() + { + dictTypeService.resetDictCache(); + return success(); + } + + /** + * 获取字典选择框列表 + */ + @GetMapping("/optionselect") + public AjaxResult optionselect() + { + List dictTypes = dictTypeService.selectDictTypeAll(); + return success(dictTypes); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java new file mode 100644 index 0000000..13007eb --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java @@ -0,0 +1,29 @@ +package com.ruoyi.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.utils.StringUtils; + +/** + * 首页 + * + * @author ruoyi + */ +@RestController +public class SysIndexController +{ + /** 系统基础配置 */ + @Autowired + private RuoYiConfig ruoyiConfig; + + /** + * 访问首页,提示语 + */ + @RequestMapping("/") + public String index() + { + return StringUtils.format("欢迎使用{}后台管理框架,当前版本:v{},请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion()); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java new file mode 100644 index 0000000..c0d4981 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -0,0 +1,97 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysMenu; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginBody; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.web.service.SysLoginService; +import com.ruoyi.framework.web.service.SysPermissionService; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.service.ISysMenuService; + +/** + * 登录验证 + * + * @author ruoyi + */ +@RestController +public class SysLoginController +{ + @Autowired + private SysLoginService loginService; + + @Autowired + private ISysMenuService menuService; + + @Autowired + private SysPermissionService permissionService; + + @Autowired + private TokenService tokenService; + + /** + * 登录方法 + * + * @param loginBody 登录信息 + * @return 结果 + */ + @PostMapping("/login") + public AjaxResult login(@RequestBody LoginBody loginBody) + { + AjaxResult ajax = AjaxResult.success(); + // 生成令牌 + String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), + loginBody.getUuid()); + ajax.put(Constants.TOKEN, token); + return ajax; + } + + /** + * 获取用户信息 + * + * @return 用户信息 + */ + @GetMapping("getInfo") + public AjaxResult getInfo() + { + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUser user = loginUser.getUser(); + // 角色集合 + Set roles = permissionService.getRolePermission(user); + // 权限集合 + Set permissions = permissionService.getMenuPermission(user); + if (!loginUser.getPermissions().equals(permissions)) + { + loginUser.setPermissions(permissions); + tokenService.refreshToken(loginUser); + } + AjaxResult ajax = AjaxResult.success(); + ajax.put("user", user); + ajax.put("roles", roles); + ajax.put("permissions", permissions); + return ajax; + } + + /** + * 获取路由信息 + * + * @return 路由信息 + */ + @GetMapping("getRouters") + public AjaxResult getRouters() + { + Long userId = SecurityUtils.getUserId(); + List menus = menuService.selectMenuTreeByUserId(userId); + return AjaxResult.success(menuService.buildMenus(menus)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java new file mode 100644 index 0000000..03b6b65 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java @@ -0,0 +1,142 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysMenu; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.service.ISysMenuService; + +/** + * 菜单信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/menu") +public class SysMenuController extends BaseController +{ + @Autowired + private ISysMenuService menuService; + + /** + * 获取菜单列表 + */ + @PreAuthorize("@ss.hasPermi('system:menu:list')") + @GetMapping("/list") + public AjaxResult list(SysMenu menu) + { + List menus = menuService.selectMenuList(menu, getUserId()); + return success(menus); + } + + /** + * 根据菜单编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:menu:query')") + @GetMapping(value = "/{menuId}") + public AjaxResult getInfo(@PathVariable Long menuId) + { + return success(menuService.selectMenuById(menuId)); + } + + /** + * 获取菜单下拉树列表 + */ + @GetMapping("/treeselect") + public AjaxResult treeselect(SysMenu menu) + { + List menus = menuService.selectMenuList(menu, getUserId()); + return success(menuService.buildMenuTreeSelect(menus)); + } + + /** + * 加载对应角色菜单列表树 + */ + @GetMapping(value = "/roleMenuTreeselect/{roleId}") + public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) + { + List menus = menuService.selectMenuList(getUserId()); + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); + ajax.put("menus", menuService.buildMenuTreeSelect(menus)); + return ajax; + } + + /** + * 新增菜单 + */ + @PreAuthorize("@ss.hasPermi('system:menu:add')") + @Log(title = "菜单管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysMenu menu) + { + if (!menuService.checkMenuNameUnique(menu)) + { + return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); + } + else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) + { + return error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); + } + menu.setCreateBy(getUsername()); + return toAjax(menuService.insertMenu(menu)); + } + + /** + * 修改菜单 + */ + @PreAuthorize("@ss.hasPermi('system:menu:edit')") + @Log(title = "菜单管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysMenu menu) + { + if (!menuService.checkMenuNameUnique(menu)) + { + return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); + } + else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) + { + return error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); + } + else if (menu.getMenuId().equals(menu.getParentId())) + { + return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己"); + } + menu.setUpdateBy(getUsername()); + return toAjax(menuService.updateMenu(menu)); + } + + /** + * 删除菜单 + */ + @PreAuthorize("@ss.hasPermi('system:menu:remove')") + @Log(title = "菜单管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{menuId}") + public AjaxResult remove(@PathVariable("menuId") Long menuId) + { + if (menuService.hasChildByMenuId(menuId)) + { + return warn("存在子菜单,不允许删除"); + } + if (menuService.checkMenuExistRole(menuId)) + { + return warn("菜单已分配,不允许删除"); + } + return toAjax(menuService.deleteMenuById(menuId)); + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java new file mode 100644 index 0000000..8622828 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java @@ -0,0 +1,91 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.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.system.domain.SysNotice; +import com.ruoyi.system.service.ISysNoticeService; + +/** + * 公告 信息操作处理 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/notice") +public class SysNoticeController extends BaseController +{ + @Autowired + private ISysNoticeService noticeService; + + /** + * 获取通知公告列表 + */ + @PreAuthorize("@ss.hasPermi('system:notice:list')") + @GetMapping("/list") + public TableDataInfo list(SysNotice notice) + { + startPage(); + List list = noticeService.selectNoticeList(notice); + return getDataTable(list); + } + + /** + * 根据通知公告编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:notice:query')") + @GetMapping(value = "/{noticeId}") + public AjaxResult getInfo(@PathVariable Long noticeId) + { + return success(noticeService.selectNoticeById(noticeId)); + } + + /** + * 新增通知公告 + */ + @PreAuthorize("@ss.hasPermi('system:notice:add')") + @Log(title = "通知公告", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysNotice notice) + { + notice.setCreateBy(getUsername()); + return toAjax(noticeService.insertNotice(notice)); + } + + /** + * 修改通知公告 + */ + @PreAuthorize("@ss.hasPermi('system:notice:edit')") + @Log(title = "通知公告", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysNotice notice) + { + notice.setUpdateBy(getUsername()); + return toAjax(noticeService.updateNotice(notice)); + } + + /** + * 删除通知公告 + */ + @PreAuthorize("@ss.hasPermi('system:notice:remove')") + @Log(title = "通知公告", businessType = BusinessType.DELETE) + @DeleteMapping("/{noticeIds}") + public AjaxResult remove(@PathVariable Long[] noticeIds) + { + return toAjax(noticeService.deleteNoticeByIds(noticeIds)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java new file mode 100644 index 0000000..c37a543 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java @@ -0,0 +1,129 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.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.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.SysPost; +import com.ruoyi.system.service.ISysPostService; + +/** + * 岗位信息操作处理 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/post") +public class SysPostController extends BaseController +{ + @Autowired + private ISysPostService postService; + + /** + * 获取岗位列表 + */ + @PreAuthorize("@ss.hasPermi('system:post:list')") + @GetMapping("/list") + public TableDataInfo list(SysPost post) + { + startPage(); + List list = postService.selectPostList(post); + return getDataTable(list); + } + + @Log(title = "岗位管理", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:post:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysPost post) + { + List list = postService.selectPostList(post); + ExcelUtil util = new ExcelUtil(SysPost.class); + util.exportExcel(response, list, "岗位数据"); + } + + /** + * 根据岗位编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:post:query')") + @GetMapping(value = "/{postId}") + public AjaxResult getInfo(@PathVariable Long postId) + { + return success(postService.selectPostById(postId)); + } + + /** + * 新增岗位 + */ + @PreAuthorize("@ss.hasPermi('system:post:add')") + @Log(title = "岗位管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysPost post) + { + if (!postService.checkPostNameUnique(post)) + { + return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在"); + } + else if (!postService.checkPostCodeUnique(post)) + { + return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在"); + } + post.setCreateBy(getUsername()); + return toAjax(postService.insertPost(post)); + } + + /** + * 修改岗位 + */ + @PreAuthorize("@ss.hasPermi('system:post:edit')") + @Log(title = "岗位管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysPost post) + { + if (!postService.checkPostNameUnique(post)) + { + return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在"); + } + else if (!postService.checkPostCodeUnique(post)) + { + return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在"); + } + post.setUpdateBy(getUsername()); + return toAjax(postService.updatePost(post)); + } + + /** + * 删除岗位 + */ + @PreAuthorize("@ss.hasPermi('system:post:remove')") + @Log(title = "岗位管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{postIds}") + public AjaxResult remove(@PathVariable Long[] postIds) + { + return toAjax(postService.deletePostByIds(postIds)); + } + + /** + * 获取岗位选择框列表 + */ + @GetMapping("/optionselect") + public AjaxResult optionselect() + { + List posts = postService.selectPostAll(); + return success(posts); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java new file mode 100644 index 0000000..d5faedd --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java @@ -0,0 +1,137 @@ +package com.ruoyi.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.MimeTypeUtils; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.service.ISysUserService; + +/** + * 个人信息 业务处理 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/user/profile") +public class SysProfileController extends BaseController +{ + @Autowired + private ISysUserService userService; + + @Autowired + private TokenService tokenService; + + /** + * 个人信息 + */ + @GetMapping + public AjaxResult profile() + { + LoginUser loginUser = getLoginUser(); + SysUser user = loginUser.getUser(); + AjaxResult ajax = AjaxResult.success(user); + ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); + ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername())); + return ajax; + } + + /** + * 修改用户 + */ + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult updateProfile(@RequestBody SysUser user) + { + LoginUser loginUser = getLoginUser(); + SysUser currentUser = loginUser.getUser(); + currentUser.setNickName(user.getNickName()); + currentUser.setEmail(user.getEmail()); + currentUser.setPhonenumber(user.getPhonenumber()); + currentUser.setSex(user.getSex()); + if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) + { + return error("修改用户'" + loginUser.getUsername() + "'失败,手机号码已存在"); + } + if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) + { + return error("修改用户'" + loginUser.getUsername() + "'失败,邮箱账号已存在"); + } + if (userService.updateUserProfile(currentUser) > 0) + { + // 更新缓存用户信息 + tokenService.setLoginUser(loginUser); + return success(); + } + return error("修改个人信息异常,请联系管理员"); + } + + /** + * 重置密码 + */ + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PutMapping("/updatePwd") + public AjaxResult updatePwd(String oldPassword, String newPassword) + { + LoginUser loginUser = getLoginUser(); + String userName = loginUser.getUsername(); + String password = loginUser.getPassword(); + if (!SecurityUtils.matchesPassword(oldPassword, password)) + { + return error("修改密码失败,旧密码错误"); + } + if (SecurityUtils.matchesPassword(newPassword, password)) + { + return error("新密码不能与旧密码相同"); + } + newPassword = SecurityUtils.encryptPassword(newPassword); + if (userService.resetUserPwd(userName, newPassword) > 0) + { + // 更新缓存用户密码 + loginUser.getUser().setPassword(newPassword); + tokenService.setLoginUser(loginUser); + return success(); + } + return error("修改密码异常,请联系管理员"); + } + + /** + * 头像上传 + */ + @Log(title = "用户头像", businessType = BusinessType.UPDATE) + @PostMapping("/avatar") + public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception + { + if (!file.isEmpty()) + { + LoginUser loginUser = getLoginUser(); + String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); + if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) + { + AjaxResult ajax = AjaxResult.success(); + ajax.put("imgUrl", avatar); + // 更新缓存用户头像 + loginUser.getUser().setAvatar(avatar); + tokenService.setLoginUser(loginUser); + return ajax; + } + } + return error("上传图片异常,请联系管理员"); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java new file mode 100644 index 0000000..fe19249 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java @@ -0,0 +1,38 @@ +package com.ruoyi.web.controller.system; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.model.RegisterBody; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.framework.web.service.SysRegisterService; +import com.ruoyi.system.service.ISysConfigService; + +/** + * 注册验证 + * + * @author ruoyi + */ +@RestController +public class SysRegisterController extends BaseController +{ + @Autowired + private SysRegisterService registerService; + + @Autowired + private ISysConfigService configService; + + @PostMapping("/register") + public AjaxResult register(@RequestBody RegisterBody user) + { + if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) + { + return error("当前系统没有开启注册功能!"); + } + String msg = registerService.register(user); + return StringUtils.isEmpty(msg) ? success() : error(msg); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java new file mode 100644 index 0000000..42d9e8f --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -0,0 +1,262 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +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.domain.model.LoginUser; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.framework.web.service.SysPermissionService; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.system.service.ISysUserService; + +/** + * 角色信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/role") +public class SysRoleController extends BaseController +{ + @Autowired + private ISysRoleService roleService; + + @Autowired + private TokenService tokenService; + + @Autowired + private SysPermissionService permissionService; + + @Autowired + private ISysUserService userService; + + @Autowired + private ISysDeptService deptService; + + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/list") + public TableDataInfo list(SysRole role) + { + startPage(); + List list = roleService.selectRoleList(role); + return getDataTable(list); + } + + @Log(title = "角色管理", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:role:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysRole role) + { + List list = roleService.selectRoleList(role); + ExcelUtil util = new ExcelUtil(SysRole.class); + util.exportExcel(response, list, "角色数据"); + } + + /** + * 根据角色编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:role:query')") + @GetMapping(value = "/{roleId}") + public AjaxResult getInfo(@PathVariable Long roleId) + { + roleService.checkRoleDataScope(roleId); + return success(roleService.selectRoleById(roleId)); + } + + /** + * 新增角色 + */ + @PreAuthorize("@ss.hasPermi('system:role:add')") + @Log(title = "角色管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysRole role) + { + if (!roleService.checkRoleNameUnique(role)) + { + return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); + } + else if (!roleService.checkRoleKeyUnique(role)) + { + return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); + } + role.setCreateBy(getUsername()); + return toAjax(roleService.insertRole(role)); + + } + + /** + * 修改保存角色 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysRole role) + { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + if (!roleService.checkRoleNameUnique(role)) + { + return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); + } + else if (!roleService.checkRoleKeyUnique(role)) + { + return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); + } + role.setUpdateBy(getUsername()); + + if (roleService.updateRole(role) > 0) + { + // 更新缓存用户权限 + LoginUser loginUser = getLoginUser(); + if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) + { + loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); + loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); + tokenService.setLoginUser(loginUser); + } + return success(); + } + return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); + } + + /** + * 修改保存数据权限 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PutMapping("/dataScope") + public AjaxResult dataScope(@RequestBody SysRole role) + { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + return toAjax(roleService.authDataScope(role)); + } + + /** + * 状态修改 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult changeStatus(@RequestBody SysRole role) + { + roleService.checkRoleAllowed(role); + roleService.checkRoleDataScope(role.getRoleId()); + role.setUpdateBy(getUsername()); + return toAjax(roleService.updateRoleStatus(role)); + } + + /** + * 删除角色 + */ + @PreAuthorize("@ss.hasPermi('system:role:remove')") + @Log(title = "角色管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{roleIds}") + public AjaxResult remove(@PathVariable Long[] roleIds) + { + return toAjax(roleService.deleteRoleByIds(roleIds)); + } + + /** + * 获取角色选择框列表 + */ + @PreAuthorize("@ss.hasPermi('system:role:query')") + @GetMapping("/optionselect") + public AjaxResult optionselect() + { + return success(roleService.selectRoleAll()); + } + + /** + * 查询已分配用户角色列表 + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/allocatedList") + public TableDataInfo allocatedList(SysUser user) + { + startPage(); + List list = userService.selectAllocatedList(user); + return getDataTable(list); + } + + /** + * 查询未分配用户角色列表 + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo unallocatedList(SysUser user) + { + startPage(); + List list = userService.selectUnallocatedList(user); + return getDataTable(list); + } + + /** + * 取消授权用户 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancel") + public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) + { + return toAjax(roleService.deleteAuthUser(userRole)); + } + + /** + * 批量取消授权用户 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancelAll") + public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) + { + return toAjax(roleService.deleteAuthUsers(roleId, userIds)); + } + + /** + * 批量选择用户授权 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/selectAll") + public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) + { + roleService.checkRoleDataScope(roleId); + return toAjax(roleService.insertAuthUsers(roleId, userIds)); + } + + /** + * 获取对应角色部门树列表 + */ + @PreAuthorize("@ss.hasPermi('system:role:query')") + @GetMapping(value = "/deptTree/{roleId}") + public AjaxResult deptTree(@PathVariable("roleId") Long roleId) + { + AjaxResult ajax = AjaxResult.success(); + ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); + ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); + return ajax; + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java new file mode 100644 index 0000000..095c3cf --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java @@ -0,0 +1,256 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +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.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysPostService; +import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.system.service.ISysUserService; + +/** + * 用户信息 + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/user") +public class SysUserController extends BaseController +{ + @Autowired + private ISysUserService userService; + + @Autowired + private ISysRoleService roleService; + + @Autowired + private ISysDeptService deptService; + + @Autowired + private ISysPostService postService; + + /** + * 获取用户列表 + */ + @PreAuthorize("@ss.hasPermi('system:user:list')") + @GetMapping("/list") + public TableDataInfo list(SysUser user) + { + startPage(); + List list = userService.selectUserList(user); + return getDataTable(list); + } + + @Log(title = "用户管理", businessType = BusinessType.EXPORT) + @PreAuthorize("@ss.hasPermi('system:user:export')") + @PostMapping("/export") + public void export(HttpServletResponse response, SysUser user) + { + List list = userService.selectUserList(user); + ExcelUtil util = new ExcelUtil(SysUser.class); + util.exportExcel(response, list, "用户数据"); + } + + @Log(title = "用户管理", businessType = BusinessType.IMPORT) + @PreAuthorize("@ss.hasPermi('system:user:import')") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception + { + ExcelUtil util = new ExcelUtil(SysUser.class); + List userList = util.importExcel(file.getInputStream()); + String operName = getUsername(); + String message = userService.importUser(userList, updateSupport, operName); + return success(message); + } + + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) + { + ExcelUtil util = new ExcelUtil(SysUser.class); + util.importTemplateExcel(response, "用户数据"); + } + + /** + * 根据用户编号获取详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:user:query')") + @GetMapping(value = { "/", "/{userId}" }) + public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) + { + userService.checkUserDataScope(userId); + AjaxResult ajax = AjaxResult.success(); + List roles = roleService.selectRoleAll(); + ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); + ajax.put("posts", postService.selectPostAll()); + if (StringUtils.isNotNull(userId)) + { + SysUser sysUser = userService.selectUserById(userId); + ajax.put(AjaxResult.DATA_TAG, sysUser); + ajax.put("postIds", postService.selectPostListByUserId(userId)); + ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList())); + } + return ajax; + } + + /** + * 新增用户 + */ + @PreAuthorize("@ss.hasPermi('system:user:add')") + @Log(title = "用户管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody SysUser user) + { + deptService.checkDeptDataScope(user.getDeptId()); + roleService.checkRoleDataScope(user.getRoleIds()); + if (!userService.checkUserNameUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); + } + else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); + } + else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + user.setCreateBy(getUsername()); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + return toAjax(userService.insertUser(user)); + } + + /** + * 修改用户 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody SysUser user) + { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + deptService.checkDeptDataScope(user.getDeptId()); + roleService.checkRoleDataScope(user.getRoleIds()); + if (!userService.checkUserNameUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); + } + else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); + } + else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + user.setUpdateBy(getUsername()); + return toAjax(userService.updateUser(user)); + } + + /** + * 删除用户 + */ + @PreAuthorize("@ss.hasPermi('system:user:remove')") + @Log(title = "用户管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{userIds}") + public AjaxResult remove(@PathVariable Long[] userIds) + { + if (ArrayUtils.contains(userIds, getUserId())) + { + return error("当前用户不能删除"); + } + return toAjax(userService.deleteUserByIds(userIds)); + } + + /** + * 重置密码 + */ + @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PutMapping("/resetPwd") + public AjaxResult resetPwd(@RequestBody SysUser user) + { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + user.setUpdateBy(getUsername()); + return toAjax(userService.resetPwd(user)); + } + + /** + * 状态修改 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult changeStatus(@RequestBody SysUser user) + { + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getUserId()); + user.setUpdateBy(getUsername()); + return toAjax(userService.updateUserStatus(user)); + } + + /** + * 根据用户编号获取授权角色 + */ + @PreAuthorize("@ss.hasPermi('system:user:query')") + @GetMapping("/authRole/{userId}") + public AjaxResult authRole(@PathVariable("userId") Long userId) + { + AjaxResult ajax = AjaxResult.success(); + SysUser user = userService.selectUserById(userId); + List roles = roleService.selectRolesByUserId(userId); + ajax.put("user", user); + ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); + return ajax; + } + + /** + * 用户授权角色 + */ + @PreAuthorize("@ss.hasPermi('system:user:edit')") + @Log(title = "用户管理", businessType = BusinessType.GRANT) + @PutMapping("/authRole") + public AjaxResult insertAuthRole(Long userId, Long[] roleIds) + { + userService.checkUserDataScope(userId); + roleService.checkRoleDataScope(roleIds); + userService.insertUserAuth(userId, roleIds); + return success(); + } + + /** + * 获取部门树列表 + */ + @PreAuthorize("@ss.hasPermi('system:user:list')") + @GetMapping("/deptTree") + public AjaxResult deptTree(SysDept dept) + { + return success(deptService.selectDeptTreeList(dept)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/ExamDOController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/ExamDOController.java new file mode 100644 index 0000000..57ffa80 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/ExamDOController.java @@ -0,0 +1,210 @@ +package com.ruoyi.web.controller.test; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.google.gson.Gson; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.test.domain.DO.ExamCreateDO; +import com.ruoyi.test.domain.DO.ExamDO; +import com.ruoyi.test.domain.DO.OptionDO; +import com.ruoyi.test.domain.DO.SingleChoiceDO; +import com.ruoyi.test.domain.ExamCreate; +import com.ruoyi.test.domain.Questionbank; +import com.ruoyi.test.domain.Vo.ExamCreateVo; +import com.ruoyi.test.domain.Vo.QuestionbankVo; +import com.ruoyi.test.domain.Vo.QuestionbankVo1; +import com.ruoyi.test.seriver.IExamCreateService; +import com.ruoyi.test.seriver.IExamDOService; +import com.ruoyi.test.seriver.IExamPaperService; +import com.ruoyi.test.seriver.ISubjectService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "题库管理") +@RestController +@RequestMapping("/examcreate") +public class ExamDOController { + + @Autowired + private IExamDOService iExamDOService; + + @Autowired + private IExamCreateService iExamCreateService; + + @Autowired + private IExamPaperService iExamPaperService; + + @ApiOperation("题库列表") + @GetMapping("selectList") + public R> selectList(int pagenum,int pagesize){ + return R.ok(iExamDOService.selectExamDoList(pagenum,pagesize)); + } + + @ApiOperation("预览") + @GetMapping("preview") + public R preview(Long id){ + return R.ok(iExamDOService.preview(id)); + } + + @ApiOperation("题目创编") + @PostMapping("add") + public R add(@RequestBody SingleChoiceDO singleChoiceDO){ + String subject = singleChoiceDO.getSubject(); + String grade = singleChoiceDO.getGrade(); + + Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); + String chance = ""; + if(singleChoiceDO.getType()==1||singleChoiceDO.getType()==2){ + List optionDOS = singleChoiceDO.getList(); + Gson gson = new Gson(); + chance = gson.toJson(optionDOS); + } + Questionbank questionbank = new Questionbank(); + questionbank.setQuestiontype(singleChoiceDO.getType()); + questionbank.setContent(singleChoiceDO.getContent()); + questionbank.setAnswer(singleChoiceDO.getAnswer()); + questionbank.setChance(chance); + questionbank.setDifficulty(singleChoiceDO.getDifficulty()); + questionbank.setAnalysis(singleChoiceDO.getAnalysis()); + questionbank.setScore(singleChoiceDO.getScore()); + questionbank.setSubject(singleChoiceDO.getSubject()); + if(iExamDOService.addSingleChoice(questionbank)!=0){ + return R.ok("添加成功"); + } + return R.ok("添加失败"); + } + + +// +// @ApiOperation("单选创编") +// @PostMapping("addSingleChoice") +// public R addSingleChoice(@RequestBody SingleChoiceDO singleChoiceDO){ +// +// String subject = singleChoiceDO.getSubject(); +// String grade = singleChoiceDO.getGrade(); +// +// Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); +// +// List optionDOS = singleChoiceDO.getList(); +// Gson gson = new Gson(); +// String chance = gson.toJson(optionDOS); +// +// Questionbank questionbank = new Questionbank(); +// questionbank.setQuestiontype(1); +// questionbank.setContent(singleChoiceDO.getContent()); +// questionbank.setAnswer(singleChoiceDO.getAnswer()); +// questionbank.setChance(chance); +// questionbank.setDifficulty(singleChoiceDO.getDifficulty()); +// questionbank.setAnalysis(singleChoiceDO.getAnalysis()); +// questionbank.setScore(singleChoiceDO.getScore()); +// questionbank.setSubject(singleChoiceDO.getSubject()); +// if(iExamDOService.addSingleChoice(questionbank)!=0){ +// return R.ok("添加成功"); +// } +// return R.ok("添加失败"); +// } +// +// @ApiOperation("判断创编") +// @PostMapping("addtfQuestions") +// public R addtfQuestions(@RequestBody ExamCreateDO examCreateDO){ +// +// String subject = examCreateDO.getSubject(); +// String grade = examCreateDO.getGrade(); +// +// Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); +// +// Questionbank questionbank = new Questionbank(); +// questionbank.setQuestiontype(5); +// questionbank.setContent(examCreateDO.getContent()); +// questionbank.setAnswer(examCreateDO.getAnswer()); +// questionbank.setChance(examCreateDO.getChance()); +// questionbank.setDifficulty(examCreateDO.getDifficulty()); +// questionbank.setAnalysis(examCreateDO.getAnalysis()); +// questionbank.setScore(examCreateDO.getScore()); +// questionbank.setSubject(examCreateDO.getSubject()); +// if(iExamDOService.addtfQuestions(questionbank)!=0){ +// return R.ok("添加成功"); +// } +// return R.ok("添加失败"); +// } +// +// @ApiOperation("多选创编") +// @PostMapping("addMSingleChoice") +// public R addMSingleChoice(@RequestBody SingleChoiceDO singleChoiceDO){ +// +// String subject = singleChoiceDO.getSubject(); +// String grade = singleChoiceDO.getGrade(); +// +// Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); +// +// List optionDOS = singleChoiceDO.getList(); +// Gson gson = new Gson(); +// String chance = gson.toJson(optionDOS); +// +// Questionbank questionbank = new Questionbank(); +// questionbank.setQuestiontype(2); +// questionbank.setContent(singleChoiceDO.getContent()); +// questionbank.setAnswer(singleChoiceDO.getAnswer()); +// questionbank.setChance(chance); +// questionbank.setDifficulty(singleChoiceDO.getDifficulty()); +// questionbank.setAnalysis(singleChoiceDO.getAnalysis()); +// questionbank.setScore(singleChoiceDO.getScore()); +// questionbank.setSubject(singleChoiceDO.getSubject()); +// if(iExamDOService.addMSingleChoice(questionbank)!=0){ +// return R.ok("添加成功"); +// } +// return R.ok("添加失败"); +// } +// +// @ApiOperation("填空创编") +// @PostMapping("addGapFilling") +// public R addGapFilling(@RequestBody ExamCreateDO examCreateDO){ +// +// String subject = examCreateDO.getSubject(); +// String grade = examCreateDO.getGrade(); +// +// Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); +// +// Questionbank questionbank = new Questionbank(); +// questionbank.setQuestiontype(3); +// questionbank.setContent(examCreateDO.getContent()); +// questionbank.setAnswer(examCreateDO.getAnswer()); +// questionbank.setChance(examCreateDO.getChance()); +// questionbank.setDifficulty(examCreateDO.getDifficulty()); +// questionbank.setAnalysis(examCreateDO.getAnalysis()); +// questionbank.setScore(examCreateDO.getScore()); +// questionbank.setSubject(examCreateDO.getSubject()); +// if(iExamDOService.addGapFilling(questionbank)!=0){ +// return R.ok("添加成功"); +// } +// return R.ok("添加失败"); +// } +// +// @ApiOperation("解答创编") +// @PostMapping("addfrQuestions") +// public R addfrQuestions(@RequestBody ExamCreateDO examCreateDO){ +// +// String subject = examCreateDO.getSubject(); +// String grade = examCreateDO.getGrade(); +// +// Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade); +// +// Questionbank questionbank = new Questionbank(); +// questionbank.setQuestiontype(4); +// questionbank.setContent(examCreateDO.getContent()); +// questionbank.setAnswer(examCreateDO.getAnswer()); +// questionbank.setChance(examCreateDO.getChance()); +// questionbank.setDifficulty(examCreateDO.getDifficulty()); +// questionbank.setAnalysis(examCreateDO.getAnalysis()); +// questionbank.setScore(examCreateDO.getScore()); +// questionbank.setSubject(examCreateDO.getSubject()); +// if(iExamDOService.addfrQuestions(questionbank)!=0){ +// return R.ok("添加成功"); +// } +// return R.ok("添加失败"); +// } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/AnswerSheetController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/AnswerSheetController.java new file mode 100644 index 0000000..663d0f2 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/AnswerSheetController.java @@ -0,0 +1,125 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.google.gson.Gson; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.*; +import com.ruoyi.test.domain.DO.AnswerDO; +import com.ruoyi.test.domain.DO.AnswerSheetDO; +import com.ruoyi.test.domain.DO.QuestionAnswerDO; +import com.ruoyi.test.domain.Vo.AnswerVo; +import com.ruoyi.test.domain.Vo.QuestionanswerVo; +import com.ruoyi.test.seriver.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +@Api(tags = "管理端答卷管理") +@RestController +@RequestMapping("/gl/answerSheet") +public class AnswerSheetController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IAnswerSheetDOService iAnswerSheetDOService; + + @Autowired + private IAnswerService iAnswerService; + + @Autowired + private IExamCreateService iExamCreateService; + + @Autowired + private IQuestionanswerService iQuestionanswerService; + + @Autowired + private IMarkedtestService iMarkedtestService; + + @ApiOperation("试卷") + @GetMapping("testPaper") + public R testPaper(String subject, String grade, String name) { + return R.ok(iAnswerSheetDOService.testPaper(subject, grade, name)); + } + + @ApiOperation("答案") + @PostMapping("answer") + public R answer(@RequestBody AnswerDO answerDO) { + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + + List answerVos = answerDO.getList(); + Gson gson = new Gson(); + String answerVo = gson.toJson(answerVos); + + Answer answer = new Answer(); + answer.setSender(sender); + answer.setTestid(answerDO.getTestid()); + answer.setIdanswer(answerVo); + answer.setTime(answerDO.getTime()); + + if (iAnswerService.answer(answer) != 0) { + return R.ok("答案提交成功!"); + } + return R.fail("答案提交失败!"); + } + + //主观题自动更改 + @ApiOperation("主观题批改") + @GetMapping("answerDisplay") + public R answerDisplay(String sender, Long id) { + List list = iExamCreateService.selectListByPid(id); + Answer answer = iAnswerService.selectByTestId(sender, id); + QuestionAnswerDO questionAnswerDO = iQuestionanswerService.createTest(list, answer); + if (iQuestionanswerService.addTest(questionAnswerDO) != 0) { + return R.ok("该学生客观题已改完!"); + } + return R.fail("查不到该学生的考试记录!"); + } + + + @ApiOperation("查看学生的考试情况(最新)") + @GetMapping("selectQuestionanswer") + public R selectQuestionanswer(String sender, Long testid) { + return R.ok(iQuestionanswerService.selectQuestionanswer(sender,testid)); + } + + @ApiOperation("批改客观题") + @PostMapping("markObjectiveQuestions") + public R markObjectiveQuestions(@RequestBody QuestionAnswerDO questionAnswerDO) { + if(iQuestionanswerService.markObjectiveQuestions(questionAnswerDO)!=0){ + return R.ok("批改完成!"); + } + return R.fail("批改提交失败!"); + } + + + @ApiOperation("试卷批改完毕提交") + @PostMapping("addmarkedtest") + public R addmarkedtest(String sender,Long testid){ + if(iMarkedtestService.addmarkedtest(sender,testid)!=0){ + return R.ok("提交完成!"); + } + return R.fail("提交失败!"); + } + + @ApiOperation("学生成绩列表查询") + @GetMapping("selectmarkedtest") + public R> selectmarkedtest(int pagenum){ + return R.ok(iMarkedtestService.selectmarkedtest(pagenum)); + } + + @ApiOperation("通过学科查询学生成绩列表") + @GetMapping("selectmarkedtestBySubject") + public R> selectmarkedtestBySubject(int pagenum,String subject){ + return R.ok(iMarkedtestService.selectmarkedtestBySubject(pagenum,subject)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/ExamPaperController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/ExamPaperController.java new file mode 100644 index 0000000..286bbcb --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/ExamPaperController.java @@ -0,0 +1,122 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.test.domain.DO.PaperCreateDO; +import com.ruoyi.test.domain.DO.QuestionbankDO; +import com.ruoyi.test.domain.DO.QuestionbankDO1; +import com.ruoyi.test.domain.ExamPaper; +import com.ruoyi.test.domain.Questionbank; +import com.ruoyi.test.seriver.IExamCreateService; +import com.ruoyi.test.seriver.IExamPaperService; +import com.ruoyi.test.seriver.IQuestionbankService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "管理端卷库管理") +@RestController +@RequestMapping("/gl/exampaper") +public class ExamPaperController { + @Autowired + private IExamPaperService iExamPaperService; + + @Autowired + private IExamCreateService iExamCreateService; + + @Autowired + private IQuestionbankService iQuestionbankService; + + @ApiOperation("试卷列表") + @GetMapping("selectAll") + public R> selectAll(int pagenum,int pagesize){ + return R.ok(iExamPaperService.selectAll(pagenum,pagesize)); + } + + @ApiOperation("查询试卷列表") + @GetMapping("selectByGrateAndSubjectAndId") + public R> selectByGrateAndSubjectAndId(int pagenum,int pagesize,String grade,String subject,Long id){ + return R.ok(iExamPaperService.selectByGrateAndSubjectAndId(pagenum,pagesize,grade,subject,id)); + } + +// @ApiOperation("根据年级查试卷列表") +// @GetMapping("selectByGrate") +// public R> selectByGrate(int pagenum,String grade){ +// return R.ok(iExamPaperService.selectByGrate(pagenum,grade)); +// } +// +// @ApiOperation("根据学科查试卷列表") +// @GetMapping("selectBySubject") +// public R> selectBySubject(int pagenum,String subject){ +// return R.ok(iExamPaperService.selectBySubject(pagenum,subject)); +// } +// +// @ApiOperation("根据id查试卷列表") +// @GetMapping("selectById") +// public R> selectById(int pagenum,Long id){ +// return R.ok(iExamPaperService.selectById(pagenum,id)); +// } + + @ApiOperation("试卷创编(添加试卷)") + @PostMapping("addPaperExam") + public R addPaperExam(@RequestBody PaperCreateDO paperCreateDO){ + if(iExamPaperService.addPaperExam(paperCreateDO)!=0){ + return R.ok("试卷添加成功!"); + } + return R.fail("试卷添加失败!"); + } + + //自动返回 + @GetMapping("selectId") + public Long selectId(@RequestBody PaperCreateDO paperCreateDO){ + return iExamPaperService.selectId(paperCreateDO); + } + + @ApiOperation("试卷创编(添加题目)") + @GetMapping("addPaperCreate") + public R addPaperCreate(Long id,Long pid){ + if(pid!=-1){ + if(iExamCreateService.addPaperCreate(id,pid)!=0){ + return R.ok("添加成功!"); + } + return R.fail("添加失败!"); + } + return R.fail("找不到该试卷!"); + } + + @ApiOperation("试卷创编(删除题目)") + @DeleteMapping("deletePaperCreate") + public R deletePaperCreate(Long id,Long pid){ + if(iExamCreateService.deletePaperCreate(id,pid)!=0){ + return R.ok("删除成功!"); + } + return R.fail("删除失败!"); + } + + @ApiOperation("试卷创编(试卷显示)") + @GetMapping("selectPaperCreate") + public R> selectPaperCreate(Long pid){ + return R.ok(iExamCreateService.selectPaperCreate(pid)); + } + +// @ApiOperation("试卷创编(通过id查找题库)") +// @GetMapping("selectQuestionBankById") +// public R selectQuestionBankById(Long id){ +// return R.ok(iQuestionbankService.selectQuestionBankById(id)); +// } +// +// @ApiOperation("试卷创编(通过题目类型查找题库)") +// @GetMapping("selectQuestionBankByQuestionType") +// public R> selectQuestionBankByQuestionType(String type){ +// return R.ok(iQuestionbankService.selectQuestionBankByQuestionType(type)); +// } + + @ApiOperation("试卷创编(查找题库)") + @GetMapping("selectQuestionBankByIdAndQuestionType") + public R> selectQuestionBankByIdAndQuestionType(Long id,String type) { + return R.ok(iQuestionbankService.selectQuestionBankByIdAndQuestionType(id,type)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/KnowledgeTreeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/KnowledgeTreeController.java new file mode 100644 index 0000000..de06344 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/KnowledgeTreeController.java @@ -0,0 +1,78 @@ +package com.ruoyi.web.controller.test.gl; + +import com.ruoyi.common.core.domain.R; +import com.ruoyi.test.domain.DO.SubjectKnowledgeDO; +import com.ruoyi.test.domain.KnowledgeTree; +import com.ruoyi.test.domain.Vo.KnowledgeTreeVo; +import com.ruoyi.test.seriver.IKnowledgeTreeService; +import com.ruoyi.test.seriver.ISubjectKnowledgeDOService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.ibatis.annotations.Delete; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "管理端知识点管理") +@RestController +@RequestMapping("/gl/knowledgeTree") +public class KnowledgeTreeController { + @Autowired + private IKnowledgeTreeService iKnowledgeTreeService; + + @Autowired + private ISubjectKnowledgeDOService iSubjectKnowledgeDOService; + +// @ApiOperation("知识点列表") + @GetMapping("selectList") + public R> selectList(){ + return R.ok(iSubjectKnowledgeDOService.selectList()); + } + + @ApiOperation("知识点树") + @GetMapping("selectAll") + public R> selectAll(String grade,String subject){ + if(grade==null||subject==null){ + return R.fail("操作失败"); + } + return R.ok(iKnowledgeTreeService.selectAll(grade,subject)); + } + + @ApiOperation("添加知识点") + @PostMapping("addKnowledgeTree") + public R> addKnowledgeTree(@RequestBody KnowledgeTreeVo knowledgeTreeVo){ +// System.out.println(knowledgeTreeVo); + if(iKnowledgeTreeService.addKnowledgeTree(knowledgeTreeVo)>0){ + return R.ok(iKnowledgeTreeService.selectAll(knowledgeTreeVo.getGrade(),knowledgeTreeVo.getSubject())); + }else if(iKnowledgeTreeService.addKnowledgeTree(knowledgeTreeVo)==-1){ + return R.fail("无该父节点"); + } + return R.fail("添加失败"); + } + + @ApiOperation("重置知识点树") + @GetMapping("resetKnowledgeTree") + public R resetKnowledgeTree(String grade, String subject){ + if(iKnowledgeTreeService.resetKnowledgeTree(grade,subject)!=0){ + return R.ok("重置成功!"); + } + return R.fail("重置失败!"); + } + + //?如果删除父节点,则子节点无用,在数据库中可能造成冗余 + @ApiOperation("删除知识点树") + @DeleteMapping("deleteKnowledgeTree") + public R deleteKnowledgeTree(String grade, String subject,Long id){ + if(iKnowledgeTreeService.deleteKnowledgeTree(grade,subject,id)!=0){ + return R.ok("删除成功!"); + } + return R.fail("删除失败!"); + } + + @ApiOperation("修改知识点") + @GetMapping("update") + public R update(String grade,String subject,Long id,String content){ + return R.ok(iKnowledgeTreeService.update(grade,subject,id,content)); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/SubjectController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/SubjectController.java new file mode 100644 index 0000000..cdb5af3 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/SubjectController.java @@ -0,0 +1,45 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.test.domain.Subject; +import com.ruoyi.test.domain.Vo.SubjectVo; +import com.ruoyi.test.seriver.ISubjectService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "管理端学科管理") +@RestController +@RequestMapping("/gl/subject") +public class SubjectController { + + @Autowired + private ISubjectService iSubjectService; + + @ApiOperation("学科列表") + @GetMapping("selectAll") + public R> selectAll(int pagenum){ + return R.ok(iSubjectService.selectAll(pagenum)); + } + + @ApiOperation("根据年级查询学科") + @GetMapping("selectGrade") + public R> selectGrade(String Grade,int pagenum){ + return R.ok(iSubjectService.selectGrade(Grade,pagenum)); + } + + @ApiOperation("添加学科") + @PostMapping("addSubject") + public R addSubject(@RequestBody SubjectVo subjectVo){ + if(iSubjectService.addSubject(subjectVo)==2){ + return R.fail("该年级已有该学科!"); + }else if(iSubjectService.addSubject(subjectVo)!=0){ + return R.ok("添加成功!"); + } + return R.fail("添加失败!"); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/TaskController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/TaskController.java new file mode 100644 index 0000000..c7d384f --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/TaskController.java @@ -0,0 +1,76 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.Task; +import com.ruoyi.test.domain.Vo.TaskVo; +import com.ruoyi.test.seriver.ITaskService; +import com.ruoyi.test.seriver.IUserService; +import com.ruoyi.web.controller.tool.testTool.ResultVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.ibatis.annotations.Delete; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "管理端任务管理") +@RestController +@RequestMapping("/gl/tesk") +public class TaskController { + + @Autowired + private ITaskService iTaskService; + + @Autowired + private IUserService iUserService; + + @ApiOperation("任务列表") + @GetMapping("selectList") + public ResultVo> selectList(int pagenum,int pagesize){ +// return R.ok(iTaskService.selectList(pagenum,pagesize)); + return ResultVo.ok(iTaskService.selectList(pagenum,pagesize)); + } + +// @ApiOperation("根据年级获取任务列表") +// @GetMapping("selectListByGrade") +// public R> selectListByGrade(String grade,int pagenum){ +// return R.ok(iTaskService.selectListByGrade(grade,pagenum)); +// } + + @ApiOperation("根据年级或学科查询任务列表") + @GetMapping("selectListByGradeAndSubject") + public R> selectListByGradeAndSubject(String grade,String subject,int pagenum,int pagesize){ + return R.ok(iTaskService.selectListByGradeAndSubject(grade,subject,pagenum,pagesize)); + } + + @ApiOperation("任务创编") + @PostMapping("addTask") + public R addTask(@RequestBody TaskVo taskVo){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long userId = sysUser.getUserId(); + String tname = iUserService.user(iUserService.selectByzhid(userId)).getTname(); + if(iTaskService.addTask(taskVo,tname)!=0){ + return R.ok("任务添加成功!"); + } + return R.fail("任务添加失败"); + } + + @ApiOperation("删除任务") + @DeleteMapping("deleteTask") + public R deleteTask(Long id){ + if(iTaskService.deleteTask(id)!=0){ + return R.ok("删除成功!"); + } + return R.fail("删除失败!"); + } + +// @ApiOperation("根据学科获取任务列表") +// @GetMapping("selectListBySubject") +// public R> selectListBySubject(String subject,int pagenum){ +// return R.ok(iTaskService.selectListBySubject(subject,pagenum)); +// } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/UserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/UserController.java new file mode 100644 index 0000000..64ceafd --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/UserController.java @@ -0,0 +1,158 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.User; +import com.ruoyi.test.domain.Vo.UserVo; +import com.ruoyi.test.seriver.IUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "管理端用户管理") +@RestController +@RequestMapping("/gl/users") +public class UserController { + @Autowired + private IUserService iUserService; + + /* + 获取学生列表 + */ + @ApiOperation("学生列表") + @GetMapping("student") + public R> selectList(int pagenum){ + return R.ok(iUserService.selectStudentList(pagenum)); + } + /*获取学生用户名查询查询记录 + *@param name 用户名 + */ + @ApiOperation("学生用户名查询") + @GetMapping("/seleteStudentName") + public R> selectStudent(int pagenum,String name){ + return R.ok(iUserService.selectStudent(pagenum,name)); + } + + /*增加学生用户信息 + *@param name 用户名 + */ + @ApiOperation("学生添加用户") + @PostMapping("/insertStudent") + public R inserStudent(@RequestBody UserVo userVo){ + User user = new User(); + user.setAge(userVo.getAge()); + user.setBirthday(userVo.getBirthday()); + user.setGrade(userVo.getGrade()); + user.setSex(userVo.getSex()); + user.setName(userVo.getName()); + user.setTname(userVo.getTname()); + user.setTelephone(userVo.getTelephone()); + user.setRoleKey("2"); + user.setState(0L); + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long zhid = sysUser.getUserId(); + user.setZhId(zhid); + List list = iUserService.selectStudentByZhid(zhid); + if(list.size()==0){ + if(iUserService.insertUser(user)!=0){ + return R.ok("添加成功!"); + }else{ + return R.fail("添加失败!"); + } + } + return R.fail("该账号已绑定用户了!"); + } + + + + @ApiOperation("教师列表") + @GetMapping("/teacher") + public R> selectTeacher(int pagenum){ + return R.ok(iUserService.selectTeacherList(pagenum)); + } + /*获取教师用户名查询查询记录 + *@param name 用户名 + */ + @ApiOperation("教师用户名查询") + @GetMapping("/seleteTeacherName") + public R> selectTeacher(int pagenum,String name){ + return R.ok(iUserService.selectTeacher(pagenum,name)); + } + /*增加教师用户信息 + *@param name 用户名 + */ + @ApiOperation("老师添加用户") + @PostMapping("/insertTeacher") + public R insertTeacher(@RequestBody UserVo userVo){ + User user = new User(); + user.setAge(userVo.getAge()); + user.setBirthday(userVo.getBirthday()); + user.setGrade(userVo.getGrade()); + user.setSex(userVo.getSex()); + user.setName(userVo.getName()); + user.setTname(userVo.getTname()); + user.setTelephone(userVo.getTelephone()); + user.setRoleKey("3"); + user.setState(0L); + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long zhid = sysUser.getUserId(); + user.setZhId(zhid); + List list = iUserService.selectStudentByZhid(zhid); + if(list.size()==0){ + if(iUserService.insertUser(user)!=0){ + return R.ok("添加成功!"); + }else{ + return R.fail("添加失败!"); + } + } + return R.fail("该账号已绑定用户了!"); + } + + @ApiOperation("管理员列表") + @GetMapping("/Gl") + public R> selectGl(int pagenum){ + return R.ok(iUserService.selectGlList(pagenum)); + } + /*获取管理员用户名查询查询记录 + *@param name 用户名 + */ + @ApiOperation("管理员用户名查询") + @GetMapping("/seleteGlName") + public R> selectGl(int pagenum,String name){ + return R.ok(iUserService.selectGl(pagenum,name)); + } + /*增加管理员用户信息 + *@param name 用户名 + */ + @ApiOperation("管理员添加用户") + @PostMapping("/insertGl") + public R insertGl(@RequestBody UserVo userVo){ + User user = new User(); + user.setAge(userVo.getAge()); + user.setBirthday(userVo.getBirthday()); + user.setGrade(userVo.getGrade()); + user.setSex(userVo.getSex()); + user.setName(userVo.getName()); + user.setTname(userVo.getTname()); + user.setTelephone(userVo.getTelephone()); + user.setRoleKey("4"); + user.setState(0L); + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long zhid = sysUser.getUserId(); + user.setZhId(zhid); + List list = iUserService.selectStudentByZhid(zhid); + if(list.size()==0){ + if(iUserService.insertUser(user)!=0){ + return R.ok("添加成功!"); + }else{ + return R.fail("添加失败!"); + } + } + return R.fail("该账号已绑定用户了!"); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/VideoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/VideoController.java new file mode 100644 index 0000000..ed482fd --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/gl/VideoController.java @@ -0,0 +1,52 @@ +package com.ruoyi.web.controller.test.gl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.test.domain.Video; +import com.ruoyi.test.domain.Vo.VideoVo; +import com.ruoyi.test.seriver.IVideoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.ibatis.annotations.Delete; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Api(tags = "管理端视频管理") +@RestController +@RequestMapping("/gl/video") +public class VideoController { + @Autowired + private IVideoService iVideoService; + + @ApiOperation("视频列表") + @GetMapping("selectList") + public R> selectList(int pagenum){ + return R.ok(iVideoService.selectList(pagenum)); + } + + @ApiOperation("根据年级获取视频列表") + @GetMapping("selectListByGrate") + public R> selectListByGrate(String grade,int pagenum){ + return R.ok(iVideoService.selectListByGrate(grade,pagenum)); + } + + @ApiOperation("删除视频") + @DeleteMapping("deleteVideo") + public R deleteVideo(Long id){ + if(iVideoService.deleteVideo(id)!=0){ + return R.ok("删除成功!"); + } + return R.fail("删除失败!"); + } + + @ApiOperation("视频创编") + @PostMapping("addVideo") + public R addVideo(@RequestBody VideoVo videoVo){ + if(iVideoService.addVideo(videoVo)!=0){ + return R.ok("创建成功!"); + } + return R.fail("创建失败"); + } + + + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentErrorBookController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentErrorBookController.java new file mode 100644 index 0000000..b58a8f7 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentErrorBookController.java @@ -0,0 +1,80 @@ +package com.ruoyi.web.controller.test.student; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.Errorbook; +import com.ruoyi.test.domain.Questionbank; +import com.ruoyi.test.domain.Vo.ErrorbookVo; +import com.ruoyi.test.seriver.IErrorbookService; +import com.ruoyi.test.seriver.IMarkedtestService; +import com.ruoyi.test.seriver.IQuestionbankService; +import com.ruoyi.test.seriver.IUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "学生端错题管理") +@RestController +@RequestMapping("student/errorBook") +public class StudentErrorBookController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IMarkedtestService iMarkedtestService; + + @Autowired + private IErrorbookService iErrorbookService; + + @Autowired + private IQuestionbankService iQuestionbankService; + + @ApiOperation("新增错题") + @GetMapping("addErrorBook") + public R addErrorBook(Long qid){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + Questionbank questionbank = iQuestionbankService.selectById(qid); + Errorbook errorbook = new Errorbook(); + errorbook.setSender(sender); + errorbook.setContent(questionbank.getContent()); + errorbook.setChance(questionbank.getChance()); + errorbook.setDifficulty(questionbank.getDifficulty()); + errorbook.setAnalysis(questionbank.getAnalysis()); + errorbook.setAnswer(questionbank.getAnswer()); + errorbook.setSubject(questionbank.getSubject()); + errorbook.setType(questionbank.getQuestiontype()); + errorbook.setScore(questionbank.getScore()); + if(iErrorbookService.addErrorBook(errorbook)!=0){ + return R.ok("错题添加成功!"); + } + return R.fail("错题添加失败!"); + } + + @ApiOperation("查询错题") + @GetMapping("selectErrorBook") + public R> selectErrorBook(int pagenum){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + return R.ok(iErrorbookService.selectErrorBook(pagenum,sender)); + } + + @ApiOperation("查询错题(根据学科)") + @GetMapping("selectErrorBookBySubject") + public R> selectErrorBookBySubject(int pagenum,String subject){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + return R.ok(iErrorbookService.selectErrorBookBySubject(pagenum,sender,subject)); + } + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamPaperController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamPaperController.java new file mode 100644 index 0000000..26efb0d --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamPaperController.java @@ -0,0 +1,164 @@ +package com.ruoyi.web.controller.test.student; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.*; +import com.ruoyi.test.domain.DO.ExamPaperDO1; +import com.ruoyi.test.seriver.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Api(tags = "学生端试卷中心") +@RestController +@RequestMapping("/student/examPaper") +public class StudentExamPaperController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IStudentClassService iStudentClassService; + + @Autowired + private IClassExamPaperService iClassExamPaperService; + + @Autowired + private IExamPaperService iExamPaperService; + + @Autowired + private IExamCreateService iExamCreateService; + + @ApiOperation("试卷查询") + @GetMapping("examPaperByTypeAndSubject") + public R> examPaperByTypeAndSubject(int pagenum,int pagesize,String type,String subject){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + Long userid = iUserService.selectByzhid(id); + StudentClass studentClass = iStudentClassService.selectById(userid); + if(studentClass==null){ + return R.fail("你还没有班级或你不是学生"); + } + String grade = studentClass.getGrade(); + String Class1 = studentClass.getClass1(); + List list = iClassExamPaperService.selectByGradeAndClass(grade,Class1); + List list1 = new ArrayList<>(); + for(ClassExamPaper classExamPaper : list ){ + ExamPaper examPaper = iExamPaperService.selectById(classExamPaper.getId()); + if(type!=null&&!examPaper.getType().equals(type)){ + continue; + } + if(subject!=null&&!examPaper.getSubject().equals(subject)){ + continue; + } + ExamPaperDO1 examPaperDO1 = new ExamPaperDO1(); + examPaperDO1.setName(examPaper.getName()); + examPaperDO1.setTime(examPaper.getTime()); + examPaperDO1.setSubject(examPaper.getSubject()); + examPaperDO1.setStart_time(null); + examPaperDO1.setEnd_time(null); + Long testid = examPaper.getId(); + List list2 = iExamCreateService.selectListByPid(testid); + examPaperDO1.setTotalquestion(list2.size()); + Double total=0.0; + for(Questionbank questionbank : list2){ + total+=questionbank.getScore(); + } + examPaperDO1.setTotalscore(total); + list1.add(examPaperDO1); + } + Page page = new Page<>(pagenum,pagesize); + IPage iPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal()); + iPage.setRecords(list1); + return R.ok(iPage); + } + + +// @ApiOperation("试卷查询(试卷类型查询)") +// @GetMapping("examPaperByType") +// public R> examPaperByType(int pagenum,String type){ +// SysUser sysUser = SecurityUtils.getLoginUser().getUser(); +// Long id = sysUser.getUserId(); +// Long userid = iUserService.selectByzhid(id); +// StudentClass studentClass = iStudentClassService.selectById(userid); +// String grade = studentClass.getGrade(); +// String Class1 = studentClass.getClass1(); +// List list = iClassExamPaperService.selectByGradeAndClass(grade,Class1); +// List list1 = new ArrayList<>(); +// for(ClassExamPaper classExamPaper : list ){ +// ExamPaper examPaper = iExamPaperService.selectById(classExamPaper.getId()); +// if(!examPaper.getType().equals(type)){ +// continue; +// } +// ExamPaperDO1 examPaperDO1 = new ExamPaperDO1(); +// examPaperDO1.setName(examPaper.getName()); +// examPaperDO1.setTime(examPaper.getTime()); +// examPaperDO1.setSubject(examPaper.getSubject()); +// examPaperDO1.setStart_time(null); +// examPaperDO1.setEnd_time(null); +// Long testid = examPaper.getId(); +// List list2 = iExamCreateService.selectListByPid(testid); +// examPaperDO1.setTotalquestion(list2.size()); +// Double total=0.0; +// for(Questionbank questionbank : list2){ +// total+=questionbank.getScore(); +// } +// examPaperDO1.setTotalscore(total); +// list1.add(examPaperDO1); +// } +// Page page = new Page<>(pagenum,10); +// IPage iPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal()); +// iPage.setRecords(list1); +// return R.ok(iPage); +// } +// +// @ApiOperation("试卷查询(学科查询)") +// @GetMapping("examPaperBySubject") +// public R> examPaperBySubject(int pagenum,String subject){ +// SysUser sysUser = SecurityUtils.getLoginUser().getUser(); +// Long id = sysUser.getUserId(); +// Long userid = iUserService.selectByzhid(id); +// StudentClass studentClass = iStudentClassService.selectById(userid); +// String grade = studentClass.getGrade(); +// String Class1 = studentClass.getClass1(); +// List list = iClassExamPaperService.selectByGradeAndClass(grade,Class1); +// List list1 = new ArrayList<>(); +// for(ClassExamPaper classExamPaper : list ){ +// ExamPaper examPaper = iExamPaperService.selectById(classExamPaper.getId()); +// if(!examPaper.getSubject().equals(subject)){ +// continue; +// } +// ExamPaperDO1 examPaperDO1 = new ExamPaperDO1(); +// examPaperDO1.setName(examPaper.getName()); +// examPaperDO1.setTime(examPaper.getTime()); +// examPaperDO1.setSubject(examPaper.getSubject()); +// examPaperDO1.setStart_time(null); +// examPaperDO1.setEnd_time(null); +// Long testid = examPaper.getId(); +// List list2 = iExamCreateService.selectListByPid(testid); +// examPaperDO1.setTotalquestion(list2.size()); +// Double total=0.0; +// for(Questionbank questionbank : list2){ +// total+=questionbank.getScore(); +// } +// examPaperDO1.setTotalscore(total); +// list1.add(examPaperDO1); +// } +// Page page = new Page<>(pagenum,10); +// IPage iPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal()); +// iPage.setRecords(list1); +// return R.ok(iPage); +// } + + + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamRecordController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamRecordController.java new file mode 100644 index 0000000..0d4c602 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentExamRecordController.java @@ -0,0 +1,142 @@ +package com.ruoyi.web.controller.test.student; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.*; +import com.ruoyi.test.domain.DO.CorrectionDO; +import com.ruoyi.test.domain.DO.QuestionbankDO1; +import com.ruoyi.test.seriver.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Api(tags = "学生端考试记录管理") +@RestController +@RequestMapping("/student/examRecord") +public class StudentExamRecordController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IClassExamPaperService iClassExamPaperService; + + @Autowired + private IClass1Service iClass1Service; + + @Autowired + private IAnswerService iAnswerService; + + @Autowired + private IExamPaperService iExamPaperService; + + @Autowired + private IExamCreateService iExamCreateService; + + @Autowired + private IMarkedtestService iMarkedtestService; + + @Autowired + private IQuestionbankService iQuestionbankService; + + @ApiOperation("试卷批改情况") + @GetMapping("correction") + public R> correction(int pagenum,int pagesize){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + List list = iAnswerService.selectBySender(sender); + List list1 = new ArrayList<>(); + for(Answer answer : list){ + CorrectionDO correctionDO = new CorrectionDO(); + correctionDO.setFinishtime(answer.getFinishtime()); + correctionDO.setTime(answer.getTime()); + Long testid = answer.getTestid(); + ExamPaper examPaper = iExamPaperService.selectById(testid); + correctionDO.setSubject(examPaper.getSubject()); + correctionDO.setType(examPaper.getType()); + correctionDO.setName(examPaper.getName()); + if(iMarkedtestService.selectmarkedtestBySenderAndTestid(sender,testid)!=null){ + Markedtest markedtest = iMarkedtestService.selectmarkedtestBySenderAndTestid(sender,testid); + correctionDO.setTotalscore(markedtest.getTotalscore()); + correctionDO.setScore(markedtest.getScore()); + correctionDO.setTotalquestions(markedtest.getTotalquestions()); + correctionDO.setTquestions(markedtest.getTquestions()); + correctionDO.setState(0); + }else{ + List list2 = iExamCreateService.selectListByPid(testid); + correctionDO.setTotalquestions(list2.size()); + Double total = 0.0; + for(Questionbank questionbank : list2){ + total +=questionbank.getScore(); + } + correctionDO.setTotalscore(total); + correctionDO.setScore(null); + correctionDO.setTquestions(null); + correctionDO.setState(1); + } + list1.add(correctionDO); + } + Page page = new Page<>(pagenum,pagesize); + IPage iPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal()); + iPage.setRecords(list1); + return R.ok(iPage); + } + + @ApiOperation("试卷批改情况") + @GetMapping("correctionBySubject") + public R> correctionBySubject(int pagenum,String subject){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + List list = iAnswerService.selectBySender(sender); + List list1 = new ArrayList<>(); + for(Answer answer : list){ + Long testid = answer.getTestid(); + ExamPaper examPaper = iExamPaperService.selectById(testid); + if(!examPaper.getSubject().equals(subject)){ + continue; + } + CorrectionDO correctionDO = new CorrectionDO(); + correctionDO.setFinishtime(answer.getFinishtime()); + correctionDO.setTime(answer.getTime()); + correctionDO.setSubject(examPaper.getSubject()); + correctionDO.setType(examPaper.getType()); + correctionDO.setName(examPaper.getName()); + if(iMarkedtestService.selectmarkedtestBySenderAndTestid(sender,testid)!=null){ + Markedtest markedtest = iMarkedtestService.selectmarkedtestBySenderAndTestid(sender,testid); + correctionDO.setTotalscore(markedtest.getTotalscore()); + correctionDO.setScore(markedtest.getScore()); + correctionDO.setTotalquestions(markedtest.getTotalquestions()); + correctionDO.setTquestions(markedtest.getTquestions()); + correctionDO.setState(0); + }else{ + List list2 = iExamCreateService.selectListByPid(testid); + correctionDO.setTotalquestions(list2.size()); + Double total = 0.0; + for(Questionbank questionbank : list2){ + total +=questionbank.getScore(); + } + correctionDO.setTotalscore(total); + correctionDO.setScore(null); + correctionDO.setTquestions(null); + correctionDO.setState(1); + } + list1.add(correctionDO); + } + Page page = new Page<>(pagenum,10); + IPage iPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal()); + iPage.setRecords(list1); + return R.ok(iPage); + } + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentHomePageController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentHomePageController.java new file mode 100644 index 0000000..75077f6 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentHomePageController.java @@ -0,0 +1,117 @@ +package com.ruoyi.web.controller.test.student; + +import com.google.gson.Gson; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.Answer; +import com.ruoyi.test.domain.DO.AnswerDO; +import com.ruoyi.test.domain.DO.AnswerSheetDO; +import com.ruoyi.test.domain.DO.QuestionAnswerDO; +import com.ruoyi.test.domain.Markedtest; +import com.ruoyi.test.domain.Questionbank; +import com.ruoyi.test.domain.Vo.AnswerVo; +import com.ruoyi.test.seriver.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(tags = "学生端主页") +@RestController +@RequestMapping("/student/homepage") +public class StudentHomePageController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IAnswerService iAnswerService; + + @Autowired + private IMarkedtestService iMarkedtestService; + + @Autowired + private IAnswerSheetDOService iAnswerSheetDOService; + + @Autowired + private IQuestionanswerService iQuestionanswerService; + + @Autowired + private IExamCreateService iExamCreateService; + + + @ApiOperation("试卷") + @GetMapping("task_paper") + public R testPaper(String subject, String grade, String name) { + return R.ok(iAnswerSheetDOService.testPaper(subject, grade, name)); + } + + @ApiOperation("任务中心答题") + @PostMapping("task_answer") + public R taskAnswer(@RequestBody AnswerDO answerDO){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + List answerVos = answerDO.getList(); + Gson gson = new Gson(); + String answerVo = gson.toJson(answerVos); + + Answer answer = new Answer(); + answer.setSender(sender); + answer.setTestid(answerDO.getTestid()); + answer.setIdanswer(answerVo); + answer.setTime(answerDO.getTime()); + + if (iAnswerService.answer(answer) != 0) { + return R.ok("答案提交成功!"); + } + return R.fail("答案提交失败!"); + } + + @ApiOperation("任务中心分数") + @PostMapping("task_score") + public R taskScore(Long testid){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + return R.ok(iMarkedtestService.selectmarkedtestBySenderAndTestid(sender,testid).getScore()); + } + + @ApiOperation("查看学生的考试情况(最新)") + @GetMapping("selectQuestionanswer") + public R selectQuestionanswer(Long testid) { + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id)).getTname(); + return R.ok(iQuestionanswerService.selectQuestionanswer(sender,testid)); + } + + //主观题自动更改 + @ApiOperation("任务中心主观题批改") + @GetMapping("task_answerDisplay") + public R taskAnswerDisplay(Long id) { + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id1 = sysUser.getUserId(); + String sender = iUserService.user(iUserService.selectByzhid(id1)).getTname(); + List list = iExamCreateService.selectListByPid(id); + Answer answer = iAnswerService.selectByTestId(sender, id); + QuestionAnswerDO questionAnswerDO = iQuestionanswerService.createTest(list, answer); + if (iQuestionanswerService.addTest(questionAnswerDO) != 0) { + return R.ok("该学生客观题已改完!"); + } + return R.fail("查不到该学生的考试记录!"); + } + + @ApiOperation("任务中心批改客观题") + @PostMapping("task_markObjectiveQuestions") + public R taskMarkObjectiveQuestions(@RequestBody QuestionAnswerDO questionAnswerDO) { + if(iQuestionanswerService.markObjectiveQuestions(questionAnswerDO)!=0){ + return R.ok("批改完成!"); + } + return R.fail("批改提交失败!"); + } + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentIntellectualController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentIntellectualController.java new file mode 100644 index 0000000..a1d24b2 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentIntellectualController.java @@ -0,0 +1,17 @@ +package com.ruoyi.web.controller.test.student; + +import com.ruoyi.test.seriver.IClassExamPaperService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "学生端智慧训练") +@RestController +@RequestMapping("/student/intellectual") +public class StudentIntellectualController { + @Autowired + private IClassExamPaperService iClassExamPaperService ; + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentVideoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentVideoController.java new file mode 100644 index 0000000..265f5aa --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/test/student/StudentVideoController.java @@ -0,0 +1,89 @@ +package com.ruoyi.web.controller.test.student; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.test.domain.ClassVedio; +import com.ruoyi.test.domain.StudentClass; +import com.ruoyi.test.domain.Video; +import com.ruoyi.test.seriver.IClassVedioService; +import com.ruoyi.test.seriver.IStudentClassService; +import com.ruoyi.test.seriver.IUserService; +import com.ruoyi.test.seriver.IVideoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Api(tags = "学生端视频课堂") +@RestController +@RequestMapping("/student/video") +public class StudentVideoController { + + @Autowired + private IUserService iUserService; + + @Autowired + private IStudentClassService iStudentClassService; + + @Autowired + private IClassVedioService iClassVedioService; + + @Autowired + private IVideoService iVideoService; + + @ApiOperation("视频列表") + @GetMapping("vedioList") + public R> vedioList(int pagenum,int pagesize){ + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + Long id = sysUser.getUserId(); + Long userId = iUserService.user(iUserService.selectByzhid(id)).getUserId(); + StudentClass studentClass = iStudentClassService.selectById(userId); + String grade = studentClass.getGrade(); + String Class1 = studentClass.getClass1(); + List list= iClassVedioService.selectClassVideo(grade,Class1); + List