wangh_branch
王壕 3 years ago
parent 38d80d8b32
commit 6b78674dab

Binary file not shown.

@ -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";

@ -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<File> 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);
}
}

@ -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));
}
}

@ -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<User> queryWrapper = new QueryWrapper<>();
queryWrapper.like("skey", skey);
User user = this.userMapper.selectOne(queryWrapper);
QueryWrapper<Dragonson> 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";
}
}

@ -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<User> list = this.userMapper.selectList(null);
String filename = taskid + ".xls";
HSSFSheet sheet = workbook.createSheet("接龙情况");
QueryWrapper<Dragonson> queryWrapper = new QueryWrapper<>();
queryWrapper.like("dragon_id", dragonid);
List<Dragonson> 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;
}
}

@ -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 +
"}";
}
}

@ -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<Dragonson> {
/**
* 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;
}
}

@ -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<Dragon> {
}

@ -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<Dragonson> {
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.DragonMapper">
</mapper>

@ -0,0 +1,25 @@
package com.example.demo.service;
import com.example.demo.domain.Dragon;
import java.util.List;
/**
*
*/
public interface IDragonService {
/**
* Area
*/
List<Dragon> queryAll();
/**
* IdDragon
*/
Dragon queryDragonById(int id);
/**
* IdDragon
*/
boolean delDragonById(int id);
}

@ -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<DragonMapper, Dragon> implements IDragonService {
@Autowired(required = false)
DragonMapper dragonMapper;
@Override
public List<Dragon> queryAll() {
LambdaQueryWrapper<Dragon> wrapper = Wrappers.lambdaQuery();
wrapper.orderByAsc(Dragon::getId);
List<Dragon> 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;
}
}

@ -13,7 +13,7 @@
</tr>
<script>
function downloadfile() {
window.location.href = "/exceldownload";
window.location.href = "/exceldownload?dragonid=1";
}
</script>
</table>

Loading…
Cancel
Save