diff --git a/src/demo/pom.xml b/src/demo/pom.xml index 0200cfd..57e8046 100644 --- a/src/demo/pom.xml +++ b/src/demo/pom.xml @@ -63,7 +63,21 @@ - + + + org.apache.poi + poi + 3.17 + + + org.apache.poi + poi-ooxml + 3.17 + + + org.xmlunit + xmlunit-core + com.alibaba diff --git a/src/demo/src/main/java/com/example/demo/DemoApplication.java b/src/demo/src/main/java/com/example/demo/DemoApplication.java index ae4d683..325960d 100644 --- a/src/demo/src/main/java/com/example/demo/DemoApplication.java +++ b/src/demo/src/main/java/com/example/demo/DemoApplication.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan; @SpringBootApplication -@ComponentScan(basePackages = {"com.example.demo.controller", "com.example.demo.config", "com.example.demo.service.impl"}) +@ComponentScan(basePackages = {"com.example.demo.controller", "com.example.demo.config", "com.example.demo.service.impl","com.example.demo.mapper"}) @MapperScan("com.example.demo.mapper") public class DemoApplication { diff --git a/src/demo/src/main/java/com/example/demo/common/WechatUtil.java b/src/demo/src/main/java/com/example/demo/common/WechatUtil.java index 65e19b8..3271718 100644 --- a/src/demo/src/main/java/com/example/demo/common/WechatUtil.java +++ b/src/demo/src/main/java/com/example/demo/common/WechatUtil.java @@ -1,7 +1,4 @@ package com.example.demo.common; -;/** - * Create by eval on 2019/3/20 - */ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -17,13 +14,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -/** - * @ClassName WechatUtil - * @Description TODO - * @Author eval - * @Date 9:44 2019/3/20 - * @Version 1.0 - */ + public class WechatUtil { public static JSONObject getSessionKeyOrOpenId(String code) { String requestUrl = "https://api.weixin.qq.com/sns/jscode2session"; diff --git a/src/demo/src/main/java/com/example/demo/common/ZipUtils.java b/src/demo/src/main/java/com/example/demo/common/ZipUtils.java new file mode 100644 index 0000000..63e413e --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/common/ZipUtils.java @@ -0,0 +1,143 @@ +package com.example.demo.common; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class ZipUtils { + private static final int BUFFER_SIZE = 2 * 1024; + + /** + * 压缩成ZIP 方法1 + * + * @param srcDir 压缩文件夹路径 + * @param out 压缩文件输出流 + * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构; + * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败) + * @throws RuntimeException 压缩失败会抛出运行时异常 + */ + + public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure) + throws RuntimeException { + long start = System.currentTimeMillis(); + ZipOutputStream zos = null; + try { + zos = new ZipOutputStream(out); + File sourceFile = new File(srcDir); + compress(sourceFile, zos, sourceFile.getName(), KeepDirStructure); + long end = System.currentTimeMillis(); + System.out.println("压缩完成,耗时:" + (end - start) + " ms"); + } catch (Exception e) { + throw new RuntimeException("zip error from ZipUtils", e); + } finally { + if (zos != null) { + try { + zos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 压缩成ZIP 方法2 + * + * @param srcFiles 需要压缩的文件列表 + * @param out 压缩文件输出流 + * @throws RuntimeException 压缩失败会抛出运行时异常 + */ + + public static void toZip(List srcFiles, OutputStream out) throws RuntimeException { + long start = System.currentTimeMillis(); + ZipOutputStream zos = null; + try { + zos = new ZipOutputStream(out); + for (File srcFile : srcFiles) { + byte[] buf = new byte[BUFFER_SIZE]; + zos.putNextEntry(new ZipEntry(srcFile.getName())); + int len; + FileInputStream in = new FileInputStream(srcFile); + while ((len = in.read(buf)) != -1) { + zos.write(buf, 0, len); + } + zos.closeEntry(); + in.close(); + } + long end = System.currentTimeMillis(); + System.out.println("压缩完成,耗时:" + (end - start) + " ms"); + } catch (Exception e) { + throw new RuntimeException("zip error from ZipUtils", e); + } finally { + if (zos != null) { + try { + zos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + + /** + * 递归压缩方法 + * + * @param sourceFile 源文件 + * @param zos zip输出流 + * @param name 压缩后的名称 + * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构; + * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败) + * @throws Exception + */ + + private static void compress(File sourceFile, ZipOutputStream zos, String name, + boolean KeepDirStructure) throws Exception { + byte[] buf = new byte[BUFFER_SIZE]; + if (sourceFile.isFile()) { + // 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字 + zos.putNextEntry(new ZipEntry(name)); + // copy文件到zip输出流中 + int len; + FileInputStream in = new FileInputStream(sourceFile); + while ((len = in.read(buf)) != -1) { + zos.write(buf, 0, len); + } + // Complete the entry + zos.closeEntry(); + in.close(); + } else { + File[] listFiles = sourceFile.listFiles(); + if (listFiles == null || listFiles.length == 0) { + // 需要保留原来的文件结构时,需要对空文件夹进行处理 + if (KeepDirStructure) { + // 空文件夹的处理 + zos.putNextEntry(new ZipEntry(name + "/")); + // 没有文件,不需要文件的copy + zos.closeEntry(); + } + } else { + for (File file : listFiles) { + // 判断是否需要保留原来的文件结构 + if (KeepDirStructure) { + // 注意:file.getName()前面需要带上父文件夹的名字加一斜杠, + // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了 + compress(file, zos, name + "/" + file.getName(), KeepDirStructure); + } else { + compress(file, zos, file.getName(), KeepDirStructure); + } + } + } + } + } + + + public static void main(String[] args) throws Exception { + /** 测试压缩方法1 */ + FileOutputStream fos1 = new FileOutputStream(new File("./test.zip")); + ZipUtils.toZip("C:\\Users\\1\\OneDrive - sliverki\\学习", fos1, true); + + } +} diff --git a/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java b/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java new file mode 100644 index 0000000..1f9b48e --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/config/LoginHandleInterceptor.java @@ -0,0 +1,25 @@ +package com.example.demo.config; + +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class LoginHandleInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + /* + 登录成功后,取得用户的session + */ + Object loginUser= request.getSession().getAttribute("loginUser"); + + if(loginUser==null){//没登陆 + request.setAttribute("msg","没有权限,请先登录"); + request.getRequestDispatcher("/index.html").forward(request,response); + return false; + }else{ + return true; + } + + } +} diff --git a/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java b/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java index e7bf9fc..51cf113 100644 --- a/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java +++ b/src/demo/src/main/java/com/example/demo/config/MyMvcConfig.java @@ -1,6 +1,7 @@ package com.example.demo.config; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -11,4 +12,10 @@ public class MyMvcConfig implements WebMvcConfigurer { registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new LoginHandleInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","dashboard","/","/login","/css/**","/js/**","/img/**"); + + } } diff --git a/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java b/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java deleted file mode 100644 index 38b92f8..0000000 --- a/src/demo/src/main/java/com/example/demo/config/config/WebConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.example.demo.config.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * Web 配置类 - * - * @author huang - * @since 2022-03-18 - */ -@Configuration -public class WebConfig implements WebMvcConfigurer { - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("login/login"); - } -} diff --git a/src/demo/src/main/java/com/example/demo/controller/ControllerText.java b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java new file mode 100644 index 0000000..0b9de03 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java @@ -0,0 +1,67 @@ +package com.example.demo.controller; + + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.tags.Tags; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.jdbc.core.JdbcTemplate; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@SpringBootApplication +@Tag(name ="你的接口",description = "test") +public class ControllerText { + @Operation(summary = "获取用户列表",description = "test") + @RequestMapping("getUser") + + public Map getUser(){ + System.out.println("微信小程序正在调用。。。"); + Map map = new HashMap(); + List list = new ArrayList(); + list.add("zhangsan"); + list.add("lisi"); + list.add("wanger"); + list.add("mazi"); + map.put("list",list); + System.out.println("微信小程序调用完成。。。"); + return map; + } + @Operation(summary = "获取用户表",description = "test") + @RequestMapping("getWord") + public Map getText(String word){ + Map map = new HashMap(); + String message = "我能力有限,不要为难我"; + if ("后来".equals(word)) { + message="正在热映的后来的我们是刘若英的处女作。"; + }else if("微信小程序".equals(word)){ + message= "想获取更多微信小程序相关知识,请更多的阅读微信官方文档,还有其他更多微信开发相关的内容,学无止境。"; + }else if("cauc".equals(word)){ + message="yes"; + } + map.put("message", message); + return map; + } + + @Autowired + JdbcTemplate jct; + @Operation(summary = "取用户列表",description = "test") + @GetMapping("userslist") + public List> userlist(){ + String sql = "select * from user"; + List> map = jct.queryForList(sql); + System.out.println("调用sql"); + return map; + } + + + +} diff --git a/src/demo/src/main/java/com/example/demo/controller/DragonController.java b/src/demo/src/main/java/com/example/demo/controller/DragonController.java new file mode 100644 index 0000000..9a74fdd --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/controller/DragonController.java @@ -0,0 +1,42 @@ +package com.example.demo.controller; + +import com.example.demo.common.util.FormatResponseUtil; +import com.example.demo.common.util.ResponseResult; +import com.example.demo.domain.Dragon; +import com.example.demo.service.impl.DragonServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/dragon") +public class DragonController { + @Autowired(required = false) + DragonServiceImpl dragonService; + + @GetMapping("/dragonList") + public ResponseResult queryAll() { + return FormatResponseUtil.formatResponse(dragonService.queryAll()); + } + + @PostMapping("/addDragon") + public ResponseResult addDragon(@RequestBody Dragon dragon) { + //System.out.println("1111111111"); + return FormatResponseUtil.formatResponse(dragonService.save(dragon)); + } + + @DeleteMapping("/delete")//这里执行的是物理删除 + public ResponseResult delTDragonById(Integer id) { + return FormatResponseUtil.formatResponse(dragonService.delDragonById(id)); + } + + @GetMapping("/one") + public ResponseResult queryById(int id) { + return FormatResponseUtil.formatResponse(dragonService.queryDragonById(id)); + } + + @PostMapping("/dragonInfo") + public ResponseResult updateArea(@RequestBody Dragon dragon) { + return FormatResponseUtil.formatResponse(dragonService.updateById(dragon)); + } + +} diff --git a/src/demo/src/main/java/com/example/demo/controller/TaskuploadController.java b/src/demo/src/main/java/com/example/demo/controller/TaskuploadController.java index 94fa529..4203300 100644 --- a/src/demo/src/main/java/com/example/demo/controller/TaskuploadController.java +++ b/src/demo/src/main/java/com/example/demo/controller/TaskuploadController.java @@ -1,8 +1,10 @@ package com.example.demo.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.example.demo.domain.Dragonson; import com.example.demo.domain.Taskson; import com.example.demo.domain.User; +import com.example.demo.mapper.DragonsonMapper; import com.example.demo.mapper.TasksonMapper; import com.example.demo.mapper.UserMapper; import io.swagger.v3.oas.annotations.Operation; @@ -20,6 +22,7 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Date; import java.util.List; @Tag(name = "任务上传", description = " ") @@ -29,6 +32,9 @@ public class TaskuploadController { private TasksonMapper tasksonMapper; @Autowired private UserMapper userMapper; + @Autowired + private DragonsonMapper dragonsonMapper; + @RequestMapping(value = "/taskupload", method = RequestMethod.POST) @Operation(summary = "任务上传接口") @@ -91,10 +97,35 @@ public class TaskuploadController { } System.out.println("upload success"); taskson.setFilepath(path); + taskson.setFinishtime(new Date()); this.tasksonMapper.updateById(taskson); return "upload successful"; } + @RequestMapping("/uploadDragon") + public String uploaddragon(@RequestParam(name = "skey", required = true) String skey, + @RequestParam(name = "dragonid", required = true) int dragonid, + @RequestParam(name = "text", required = true) String text) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.like("skey", skey); + User user = this.userMapper.selectOne(queryWrapper); + QueryWrapper queryWrapper1 = new QueryWrapper<>(); + queryWrapper1.like("studentnumber", user.getStudentNumber()); + queryWrapper1.like("dragon_id", dragonid); + Dragonson dragonson = this.dragonsonMapper.selectOne(queryWrapper1); + if (dragonson == null) { + dragonson = new Dragonson(); + dragonson.setDragonid(dragonid); + dragonson.setStudentnumber(user.getStudentNumber()); + this.dragonsonMapper.insert(dragonson); + } + dragonson.setText(text); + dragonson.setFinishtime(new Date()); + this.dragonsonMapper.updateById(dragonson); + return "success"; + + } + } diff --git a/src/demo/src/main/java/com/example/demo/controller/UserController.java b/src/demo/src/main/java/com/example/demo/controller/UserController.java index 5aba5b6..527d026 100644 --- a/src/demo/src/main/java/com/example/demo/controller/UserController.java +++ b/src/demo/src/main/java/com/example/demo/controller/UserController.java @@ -6,6 +6,7 @@ import com.example.demo.common.HttpGetUtil; import com.example.demo.domain.Rcode; import com.example.demo.domain.User; import com.example.demo.mapper.RcodeMapper; +import com.example.demo.mapper.TasksonMapper; import com.example.demo.mapper.UserMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -20,10 +21,7 @@ import java.util.*; @Tag(name = "真·用户接口", description = "用户登录,") @RestController public class UserController { - @RequestMapping("/index") - public String first() { - return "index"; - } + @Autowired private UserMapper userMapper; @@ -97,6 +95,8 @@ public class UserController { * @auth:kirito * @date:2022/10/20 */ + @Autowired + TasksonMapper tasksonMapper; @RequestMapping("/atbind") @Operation(summary = "用户绑定接口") public void atbind(@RequestParam(value = "studentnumber", required = true) String studentnumber, @@ -117,6 +117,7 @@ public class UserController { /** * 获取验证码 + * s * * @param skey * @return code diff --git a/src/demo/src/main/java/com/example/demo/controller/Webcontroller.java b/src/demo/src/main/java/com/example/demo/controller/Webcontroller.java index deb075d..8e66320 100644 --- a/src/demo/src/main/java/com/example/demo/controller/Webcontroller.java +++ b/src/demo/src/main/java/com/example/demo/controller/Webcontroller.java @@ -1,167 +1,355 @@ package com.example.demo.controller; -import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.example.demo.common.HttpGetUtil; -import com.example.demo.domain.Rcode; -import com.example.demo.domain.User; -import com.example.demo.mapper.RcodeMapper; +import com.example.demo.domain.*; +import com.example.demo.mapper.*; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.apache.commons.codec.binary.Base64; - -import org.apache.tomcat.util.http.ResponseUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.ui.ModelMap; +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.RequestParam; -import org.springframework.web.client.RestTemplate; - -import javax.servlet.http.HttpServletRequest; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.net.URL; -import java.net.URLConnection; -import java.nio.Buffer; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; + +import javax.servlet.http.HttpSession; +import java.util.List; @Controller -@RequestMapping("/web") -@Tag(name = "web端") public class Webcontroller { - @RequestMapping("/dashboard") - public String login() { - return "dashboard"; + @RequestMapping("/index") + public String first(){ + return "index"; } + @Autowired + RcodeMapper rcodeMapper; + @RequestMapping("/login") + @Operation(summary = "登录") + + public String login( + @RequestParam("code") String code, + Model model, + HttpSession session + ){ + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.like("code", code); + Rcode authrcode = this.rcodeMapper.selectOne(queryWrapper); + String skey = authrcode.getSkey(); +// System.out.println(skey); + if(!skey.isEmpty()){ + QueryWrapper queryWrapper1 = new QueryWrapper<>(); + queryWrapper1.like("skey",skey); + User user=this.userMapper.selectOne(queryWrapper1); + String id=user.getStudentNumber(); + session.setAttribute("loginUser",id); + return "dashboard"; + }else{ + /* + 登录失败 + */ + model.addAttribute("msg","验证码错误"); + return "index"; + } + + - @RequestMapping("/list") - public String numer() { - return "list"; } + //@RequestMapping("/list") + /*public String numer(){ + return "list"; + }*/ + @Autowired + UserMapper userMapper; + @RequestMapping("/users") + /* + 用户管理 + */ + public String numer(ModelMap map){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select("name","student_number","power"); + List users = userMapper.selectList(queryWrapper); + map.put("users",users); +// System.out.println(users); + - /** - * 获取qrcode - * issue: 小程序未上线,无法使用获取二维码接口。 - * 此接口未启用,后续小程序上线可以启用替换验证码登录 - * - * @return +// System.out.println(userList); +// model.addAttribute("users",userList); + + + return "list"; + } + /* + 删除用户 */ - @RequestMapping("/getqrcode") - public Object getqrcode() { - RestTemplate restTemplate = new RestTemplate(); - //首先获取ACCESS_TOKEN - String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx08c675f6ba5b2cdc&secret=0c28388c09ff373d391fe66d085dd39d"; - JSONObject tokenResult = restTemplate.getForObject(getAccessTokenUrl, JSONObject.class); - assert tokenResult != null; - String accessToken = tokenResult.getString("access_token"); - //System.out.println(accessToken); - //然后调用微信官方api生成二维码 - String createQrCodeUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; - //此处我是使用的阿里巴巴的fastJson - JSONObject createQrParam = new JSONObject(); - //createQrParam.put("scene", scene); - //createQrParam.put("page", page); - - - PrintWriter out = null; - InputStream in = null; - try { - URL realUrl = new URL(createQrCodeUrl); - // 打开和URL之间的连接 - URLConnection conn = realUrl.openConnection(); - // 设置通用的请求属性 - conn.setRequestProperty("accept", "*/*"); - conn.setRequestProperty("connection", "Keep-Alive"); - conn.setRequestProperty("user-agent", - "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); - // 发送POST请求必须设置如下两行 - conn.setDoOutput(true); - conn.setDoInput(true); - // 获取URLConnection对象对应的输出流 - out = new PrintWriter(conn.getOutputStream()); - // 发送请求参数,利用connection的输出流,去写数据到connection中,我的参数数据流出我的电脑内存到connection中,让connection把参数帮我传到URL中去请求。 - out.print(createQrParam); - // flush输出流的缓冲 - out.flush(); - //获取URL的connection中的输入流,这个输入流就是我请求的url返回的数据,返回的数据在这个输入流中,流入我内存,我将从此流中读取数据。 - in = conn.getInputStream(); - //定义个空字节数组 - byte[] data = null; - // 读取图片字节数组 - try { - //创建字节数组输出流作为中转仓库,等待被写入数据 - ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); - byte[] buff = new byte[100]; - int rc = 0; - while ((rc = in.read(buff, 0, 100)) > 0) { - //向中转的输出流循环写出输入流中的数据 - swapStream.write(buff, 0, rc); - } - //此时connection的输入流返回给我们的请求结果数据已经被完全地写入了我们定义的中转输出流swapStream中 - data = swapStream.toByteArray(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - String base64Code = new String(Objects.requireNonNull(Base64.encodeBase64(data))); - //Base64转byte[]数组 - System.out.println(base64Code); - } catch (Exception e) { - System.out.println("发送 POST 请求出现异常!" + e); - e.printStackTrace(); - } + @GetMapping("/deluser/{StudentNumber}") + public String delUser(@PathVariable("StudentNumber") String StudentNumber){ + /* + 查出原来的数据 + */ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select("student_number").like("student_number", StudentNumber); + List users = userMapper.selectList(queryWrapper); + userMapper.delete(queryWrapper); +// System.out.println(users); +// System.out.println(StudentNumber); + return "redirect:/users"; + } + /* + 编辑用户 + */ + @GetMapping("/user/{StudentNumber}") + public String toUpdateUser(@PathVariable("StudentNumber")String StudentNumber,Model model,ModelMap map){ + /* + 查出原来的数据 + */ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select("name","student_number","power").like("student_number", StudentNumber); + List users = userMapper.selectList(queryWrapper); + +// System.out.println(users); +// System.out.println(users.get(10)); +// System.out.println(StudentNumber); + model.addAttribute("users",users); +// map.put("users",users); + return "user/update"; - // 使用finally块来关闭输出流、输入流 - finally { - try { - if (out != null) { - out.close(); - } - if (in != null) { - in.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - } + } + @RequestMapping("/update") + public String updateUser( + @RequestParam("Studentnumber") String Studentnumber, + @RequestParam("name") String name, + @RequestParam("power") int power, + @RequestParam("stuid") String stuid, + @RequestParam("stuname" )String stuname + ){ + // + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.like("student_number",stuid); + User user=this.userMapper.selectOne(queryWrapper); + if(!name.isEmpty()){ + user.setName(name); + }else{ + user.setName(stuname); + } + if(!Studentnumber.isEmpty()){ + user.setStudentNumber(Studentnumber); + }else{ + user.setStudentNumber(stuid); } - return null; + user.setStudentNumber(stuid); + user.setPower(power); + this.userMapper.updateById(user); +// List users = userMapper.selectList(queryWrapper); +// System.out.println(user); + return"redirect:/users"; } + @Autowired + TaskMapper taskMapper; + + @RequestMapping("totaltask") + public String totasklist(Model model){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("id","name","property","status","deadtime"); + List tasks=this.taskMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); - /** - * 用户登录接口(现阶段使用) - * 采用微信小程序获取验证码登录 - * - * @auth:kirito + return "task/tasklist"; + } + @Autowired + DragonMapper dragonMapper; + @RequestMapping("totalgroupnote") + /* + 接龙列表展示(暂时 */ + public String togroupnotelist(Model model){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("id","name","property","status","deadtime"); + List tasks=this.dragonMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); + + return "task/groupnotelist"; + } @Autowired - RcodeMapper rcodeMapper; + TasksonMapper tasksonMapper; + @RequestMapping("/item1/{id}") + public String totaskdetail(@PathVariable("id")String id,Model model){ + /* + 查询原来的任务 + 并根据子表获取详细信息 + */ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("task_id","studentnumber","finishtime","filepath").like("task_id", id); - @RequestMapping("/login") - @Operation(summary = "登录") - public void weblogin(@RequestParam(value = "code") String code) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.like("code", code); - Rcode authrcode = this.rcodeMapper.selectOne(queryWrapper); - String skey = authrcode.getSkey(); + List taskson=this.tasksonMapper.selectList(queryWrapper); +// System.out.println(taskson); + model.addAttribute("taskdetail",taskson); + return "task/taskdetail"; } +// @Autowired +// TasksonMapper tasksonMapper; + + @Autowired + DragonsonMapper dragonsonMapper; + @RequestMapping("/item2/{id}") + /* + 接龙详细展示(暂时 + */ + public String togroupdetail(@PathVariable("id")String id,Model model){ + /* + 查询原来的任务 + 并根据子表获取详细信息 + */ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("task_id","studentnumber","finishtime","filepath").like("task_id", id); + List groupson=this.dragonsonMapper.selectList(queryWrapper); + System.out.println(groupson); + + model.addAttribute("groupdetail",groupson); + return "task/groupdetail"; + } + @RequestMapping("taskedit") + public String totasklistedit(Model model){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("id","name","property","status","deadtime"); + List tasks=this.taskMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); + + return "task/taskeditlist"; + } + @GetMapping ("/itemedit1/{id}") + public String totaskedit(@PathVariable("id") String id,Model model){ + + /* + 查出原来的数据 + */ + QueryWrapperqueryWrapper=new QueryWrapper<>(); + queryWrapper.select().like("id",id); + Listtasks=this.taskMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); + return "/task/taskupdate"; + } + /* + 任务编辑 + */ + @GetMapping("taskupdate") + public String taskedit(@RequestParam("id")String id, + @RequestParam("name") String name, + @RequestParam("property") String property, + @RequestParam("deadtime") String deadtime, + @RequestParam("status") int status + + ){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select().like("id", id); + Task task =this.taskMapper.selectOne(queryWrapper); + if(!name.isEmpty()){ + task.setName(name); + } + if(!property.isEmpty()){ + task.setProperty(property); + } + if (!deadtime.isEmpty()){ + task.setDeadtime(deadtime); + } + task.setStatus(status); +// List tasks=this.taskMapper.selectList(queryWrapper); +// System.out.println(tasks); + this.taskMapper.updateById(task); -} + return "redirect:/taskedit"; + } + @RequestMapping("togroupnoteedit") + /* + 接龙列表展示(暂时 + */ + public String togroupnoteeditlist(Model model){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select("id","name","property","status","deadtime"); + List tasks=this.dragonMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); + + return "task/groupnoteeditlist"; + } + @GetMapping ("/itemedit2/{id}") + public String togroupnoteedit(@PathVariable("id") String id,Model model){ + + /* + 查出原来的数据 + */ + QueryWrapperqueryWrapper=new QueryWrapper<>(); + queryWrapper.select().like("id",id); + Listtasks=this.dragonMapper.selectList(queryWrapper); + model.addAttribute("tasks",tasks); + return "/task/groupnoteupdate"; + } + @GetMapping("groupnoteupdate") + public String groupnoteedit(@RequestParam("id")String id, + @RequestParam("name") String name, + @RequestParam("property") String property, + @RequestParam("deadtime") String deadtime, + @RequestParam("status") int status + + ){ + QueryWrapperqueryWrapper = new QueryWrapper<>(); + queryWrapper.select().like("id", id); + Dragon task =this.dragonMapper.selectOne(queryWrapper); + if(!name.isEmpty()){ + task.setName(name); + } + if(!property.isEmpty()){ + task.setProperty(property); + } + if (!deadtime.isEmpty()){ + task.setDeadtime(deadtime); + } + task.setStatus(status); +// List tasks=this.taskMapper.selectList(queryWrapper); +// System.out.println(tasks); + this.dragonMapper.updateById(task); + + return "redirect:/togroupnoteedit"; + } + /* + 删除任务 + */ + @GetMapping("/itemdel1/{id}") + public String delTask(@PathVariable("id") String id){ + /* + 查出原来的数据 + */ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select().like("id", id); + List users = this.taskMapper.selectList(queryWrapper); + this.taskMapper.delete(queryWrapper); +// System.out.println(users); +// System.out.println(StudentNumber); + return "redirect:/taskedit"; + } + /* + 删除接龙 + */ + @GetMapping("/itemdel2/{id}") + public String delgroupnote(@PathVariable("id") String id){ + /* + 查出原来的数据 + */ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select().like("id", id); + List users = this.dragonMapper.selectList(queryWrapper); + this.dragonMapper.delete(queryWrapper); +// System.out.println(users); +// System.out.println(StudentNumber); + return "redirect:/togroupnoteedit"; + } + + + +} diff --git a/src/demo/src/main/java/com/example/demo/controller/Webneed.java b/src/demo/src/main/java/com/example/demo/controller/Webneed.java new file mode 100644 index 0000000..bbf226c --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/controller/Webneed.java @@ -0,0 +1,122 @@ +package com.example.demo.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.example.demo.domain.Dragonson; +import com.example.demo.domain.User; +import com.example.demo.mapper.DragonsonMapper; +import com.example.demo.mapper.UserMapper; +import org.apache.poi.hssf.usermodel.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +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.RequestParam; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.util.List; + +@Controller +public class Webneed { + @Autowired + DragonsonMapper dragonsonMapper; + + @GetMapping("/exceldownload/{Taskid}") + public void download(HttpServletResponse response, @PathVariable("Taskid") String dragonid) throws IOException { + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("接龙情况"); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.like("dragon_id", dragonid); + + List list = this.dragonsonMapper.selectList(queryWrapper); + String filename = dragonid + ".xls"; + int rowNum = 1; + //表头 + String[] headers = {"num", "dragonid", "studentnumber", "finishtime", "text"}; + HSSFRow row = sheet.createRow(0); + for (int i = 0; i < headers.length; i++) { + HSSFCell cell = row.createCell(i); + HSSFRichTextString text = new HSSFRichTextString(headers[i]); + cell.setCellValue(text); + } + //在表中存放查询到的数据放入对应的列 + for (Dragonson dragonson : list) { + HSSFRow row1 = sheet.createRow(rowNum); + row1.createCell(0).setCellValue(dragonson.getId()); + row1.createCell(1).setCellValue(dragonson.getDragonid()); + row1.createCell(2).setCellValue(dragonson.getStudentnumber()); + row1.createCell(3).setCellValue(dragonson.getFinishtime()); + row1.createCell(4).setCellValue(dragonson.getText()); + rowNum++; + } + response.setContentType("application/octet-stream"); + response.setHeader("Content-disposition", "attachment;filename=" + filename); + response.flushBuffer(); + workbook.write(response.getOutputStream()); + } + + @RequestMapping("/daochu") + + public String daochu() { + return "daochu"; + } + + @RequestMapping("/filedownload/{Taskid}") + public String downloadfile(@PathVariable("Taskid") String taskid, + HttpServletResponse response) throws UnsupportedEncodingException { + File scFileDir = new File("./"); + String fileName = taskid + ".zip"; + File fileDir = new File(scFileDir, fileName); + System.out.println(fileDir.getName()); + if (fileDir.exists()) { + // 配置文件下载 + response.setHeader("content-type", "application/octet-stream"); + response.setContentType("application/octet-stream"); + // 下载文件能正常显示中文 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); + // 实现文件下载 + byte[] buffer = new byte[1024]; + FileInputStream fis = null; + BufferedInputStream bis = null; + try { + fis = new FileInputStream(fileDir); + bis = new BufferedInputStream(fis); + OutputStream os = response.getOutputStream(); + int i = bis.read(buffer); + while (i != -1) { + os.write(buffer, 0, i); + i = bis.read(buffer); + } + System.out.println("Download the song successfully!"); + } catch (Exception e) { + System.out.println("Download the song failed!"); + } finally { + if (bis != null) { + try { + bis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + + return null; + } + +} + + + diff --git a/src/demo/src/main/java/com/example/demo/domain/Dragon.java b/src/demo/src/main/java/com/example/demo/domain/Dragon.java new file mode 100644 index 0000000..e008546 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/domain/Dragon.java @@ -0,0 +1,108 @@ +package com.example.demo.domain; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.time.LocalDateTime; + +public class Dragon { + private static final long serialVersionUID = 1L; + + public static final String CREATE_TIME = "createTime"; + public static final String MODIFIED_TIME = "lastEditTime"; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String name; + /* + * 任务内容 + * */ + private String property; + private String deadtime; + //任务状态:默认0(未完成) + private Integer status; + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + /** + * 创建时间戳 + */ + @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + public String getDeadtime() { + return deadtime; + } + + public void setDeadtime(String deadtime) { + this.deadtime = deadtime; + } + + /** + * 最后修改时间戳 + */ + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime lastTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + + public LocalDateTime getLastTime() { + return lastTime; + } + + public void setLastTime(LocalDateTime lastTime) { + this.lastTime = lastTime; + } + + @Override + public String toString() { + return "Dragon{" + + "id=" + id + + ", name=" + name + + ", priority=" + property + + ", createTime=" + createTime + + ", lastTime=" + lastTime + + "}"; + } +} diff --git a/src/demo/src/main/java/com/example/demo/domain/Dragonson.java b/src/demo/src/main/java/com/example/demo/domain/Dragonson.java new file mode 100644 index 0000000..1fe88e2 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/domain/Dragonson.java @@ -0,0 +1,61 @@ +package com.example.demo.domain; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +@TableName("dragonson") +public class Dragonson extends Wrapper { + /** + * id + */ + @TableField("id") + private int id; + /** + * dragon_id + */ + @TableField("dragon_id") + private int dragonid; + /** + * studentnumber + */ + @TableField("studentnumber") + private String studentnumber; + /** + * finishtime + */ + @TableField("finishtime") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date finishtime; + /** + * text + */ + @TableField("text") + private String text; + + @Override + public Dragonson getEntity() { + return null; + } + + @Override + public MergeSegments getExpression() { + return null; + } + + @Override + public void clear() { + + } + + @Override + public String getSqlSegment() { + return null; + } +} diff --git a/src/demo/src/main/java/com/example/demo/domain/Rcode.java b/src/demo/src/main/java/com/example/demo/domain/Rcode.java index 76e467e..d9b574d 100644 --- a/src/demo/src/main/java/com/example/demo/domain/Rcode.java +++ b/src/demo/src/main/java/com/example/demo/domain/Rcode.java @@ -1,14 +1,36 @@ package com.example.demo.domain; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; +import lombok.Data; + import java.util.Random; -public class Rcode { +@Data +@TableName("rcode") +public class Rcode extends Wrapper { private String code; private String skey; public Rcode() { } + @Override + public Rcode getEntity() { + return null; + } + + @Override + public MergeSegments getExpression() { + return null; + } + + @Override + public void clear() { + + } + public Rcode(String code, String skey) { this.code = code; this.skey = skey; @@ -58,4 +80,9 @@ public class Rcode { return code; } + + @Override + public String getSqlSegment() { + return null; + } } diff --git a/src/demo/src/main/java/com/example/demo/mapper/DragonMapper.java b/src/demo/src/main/java/com/example/demo/mapper/DragonMapper.java new file mode 100644 index 0000000..5cd0aca --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/mapper/DragonMapper.java @@ -0,0 +1,12 @@ +package com.example.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.demo.domain.Dragon; +import org.apache.ibatis.annotations.Mapper; + +/** + * 和数据库的连接层 + */ +@Mapper +public interface DragonMapper extends BaseMapper { +} diff --git a/src/demo/src/main/java/com/example/demo/mapper/DragonsonMapper.java b/src/demo/src/main/java/com/example/demo/mapper/DragonsonMapper.java new file mode 100644 index 0000000..7fd6359 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/mapper/DragonsonMapper.java @@ -0,0 +1,10 @@ +package com.example.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.demo.domain.Dragonson; + +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface DragonsonMapper extends BaseMapper { +} diff --git a/src/demo/src/main/java/com/example/demo/mapper/xml/DragonMapper.xml b/src/demo/src/main/java/com/example/demo/mapper/xml/DragonMapper.xml new file mode 100644 index 0000000..3e1169b --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/mapper/xml/DragonMapper.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/demo/src/main/java/com/example/demo/service/IDragonService.java b/src/demo/src/main/java/com/example/demo/service/IDragonService.java new file mode 100644 index 0000000..3737521 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/service/IDragonService.java @@ -0,0 +1,25 @@ +package com.example.demo.service; + +import com.example.demo.domain.Dragon; + +import java.util.List; + +/** + * 面向数据库的接口 + */ +public interface IDragonService { + /** + * 查询所有Area + */ + List queryAll(); + + /** + * 通过Id查询Dragon + */ + Dragon queryDragonById(int id); + + /** + * 通过Id删除Dragon + */ + boolean delDragonById(int id); +} diff --git a/src/demo/src/main/java/com/example/demo/service/impl/DragonServiceImpl.java b/src/demo/src/main/java/com/example/demo/service/impl/DragonServiceImpl.java new file mode 100644 index 0000000..3092d96 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/service/impl/DragonServiceImpl.java @@ -0,0 +1,41 @@ +package com.example.demo.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.example.demo.domain.Dragon; +import com.example.demo.mapper.DragonMapper; +import com.example.demo.service.IDragonService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class DragonServiceImpl extends ServiceImpl implements IDragonService { + + + @Autowired(required = false) + DragonMapper dragonMapper; + + @Override + public List queryAll() { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.orderByAsc(Dragon::getId); + List dragonList = dragonMapper.selectList(wrapper); + return dragonList; + } + + @Override + public Dragon queryDragonById(int id) { + Dragon dragon = dragonMapper.selectById(id); + return dragon; + } + + + @Override + public boolean delDragonById(int id) { + boolean ans; + int i = dragonMapper.deleteById(id); + return ans = i > 0 ? true : false; + } + +} diff --git a/src/demo/src/main/resources/templates/daochu.html b/src/demo/src/main/resources/templates/daochu.html new file mode 100644 index 0000000..abe20ec --- /dev/null +++ b/src/demo/src/main/resources/templates/daochu.html @@ -0,0 +1,21 @@ + + + + + Title + + + + + + + + + +
数据导出
+ + \ No newline at end of file diff --git a/src/demo/src/main/resources/templates/dashboard.html b/src/demo/src/main/resources/templates/dashboard.html index 86330fb..62c0a99 100644 --- a/src/demo/src/main/resources/templates/dashboard.html +++ b/src/demo/src/main/resources/templates/dashboard.html @@ -43,11 +43,11 @@ @@ -58,7 +58,7 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/demo/src/main/resources/templates/user/update.html b/src/demo/src/main/resources/templates/user/update.html new file mode 100644 index 0000000..6252ca7 --- /dev/null +++ b/src/demo/src/main/resources/templates/user/update.html @@ -0,0 +1,203 @@ + + + + + + + + + + + Dashboard Template for Bootstrap + + + + + + + + + + + +
+
+
+ +
+ + + + + + + + + +
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file