diff --git a/doc/“班级通”软件系统的需求构思及描述.docx b/doc/“班级通”软件系统的需求构思及描述.docx index 4e972dd..bbb7f50 100644 Binary files a/doc/“班级通”软件系统的需求构思及描述.docx and b/doc/“班级通”软件系统的需求构思及描述.docx differ diff --git a/doc/界面图.rp b/doc/界面图.rp deleted file mode 100644 index 77cabd8..0000000 Binary files a/doc/界面图.rp and /dev/null differ 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/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/Webneed.java b/src/demo/src/main/java/com/example/demo/controller/Webneed.java index 501b1d9..ed028ad 100644 --- a/src/demo/src/main/java/com/example/demo/controller/Webneed.java +++ b/src/demo/src/main/java/com/example/demo/controller/Webneed.java @@ -1,7 +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.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; @@ -10,24 +13,29 @@ import org.springframework.web.bind.annotation.GetMapping; 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.IOException; +import java.io.*; +import java.net.URLEncoder; import java.util.List; @Controller public class Webneed { @Autowired - UserMapper userMapper; + DragonsonMapper dragonsonMapper; @GetMapping("/exceldownload") - public void download(HttpServletResponse response, @RequestParam(value = "taskid", required = false) String taskid) throws IOException { + public void download(HttpServletResponse response, @RequestParam(value = "dragonid", required = false) String dragonid) throws IOException { HSSFWorkbook workbook = new HSSFWorkbook(); - HSSFSheet sheet = workbook.createSheet("任务情况"); - List list = this.userMapper.selectList(null); - String filename = taskid + ".xls"; + 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 = {"学号", "姓名", "power"}; + 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); @@ -35,11 +43,13 @@ public class Webneed { cell.setCellValue(text); } //在表中存放查询到的数据放入对应的列 - for (User user : list) { + for (Dragonson dragonson : list) { HSSFRow row1 = sheet.createRow(rowNum); - row1.createCell(0).setCellValue(user.getStudentNumber()); - row1.createCell(1).setCellValue(user.getName()); - row1.createCell(2).setCellValue(user.getPower()); + 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"); @@ -54,7 +64,57 @@ public class Webneed { return "daochu"; } - @RequestMapping("") + @RequestMapping("/filedownload") + public String downloadfile(@RequestParam(value = "taskid", required = true) 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..867b137 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/domain/Dragon.java @@ -0,0 +1,89 @@ +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; + + /** + * 创建时间戳 + */ + @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + /** + * 最后修改时间戳 + */ + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime lastEditTime; + + 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 getLastEditTime() { + return lastEditTime; + } + + public void setLastEditTime(LocalDateTime lastEditTime) { + this.lastEditTime = lastEditTime; + } + + @Override + public String toString() { + return "Dragon{" + + "id=" + id + + ", name=" + name + + ", priority=" + property + + ", createTime=" + createTime + + ", lastEditTime=" + lastEditTime + + "}"; + } +} 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/mapper/DragonMapper.java b/src/demo/src/main/java/com/example/demo/mapper/DragonMapper.java new file mode 100644 index 0000000..0b998f9 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/mapper/DragonMapper.java @@ -0,0 +1,10 @@ +package com.example.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.demo.domain.Dragon; + +/** + * 和数据库的连接层 + */ +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 index abe20ec..d24304f 100644 --- a/src/demo/src/main/resources/templates/daochu.html +++ b/src/demo/src/main/resources/templates/daochu.html @@ -13,7 +13,7 @@