From 25ee8393ff538d455313ec32b34bb6a7f2e82a74 Mon Sep 17 00:00:00 2001 From: whb <17803890193@163.com> Date: Mon, 22 Jul 2024 14:51:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5token=E5=88=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=20=E6=A1=88=E4=BE=8B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20=E6=96=87=E4=BB=B6=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../new_module/stu/StuJupyterController.java | 274 +++++++++- .../entity/AdminJupyterToken.java | 64 +++ .../entity/AdminJupyterTokenExample.java | 510 ++++++++++++++++++ .../mapper/AdminJupyterTokenMapper.java | 32 ++ .../resource_center/util/file/IFileUtil.java | 2 + .../util/file/LocalFileUtil.java | 25 +- src/main/resources/application-dev.yml | 5 +- .../mapper/AdminJupyterTokenMapper.xml | 211 ++++++++ 8 files changed, 1093 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/sztzjy/resource_center/entity/AdminJupyterToken.java create mode 100644 src/main/java/com/sztzjy/resource_center/entity/AdminJupyterTokenExample.java create mode 100644 src/main/java/com/sztzjy/resource_center/mapper/AdminJupyterTokenMapper.java create mode 100644 src/main/resources/mapper/AdminJupyterTokenMapper.xml diff --git a/src/main/java/com/sztzjy/resource_center/controller/new_module/stu/StuJupyterController.java b/src/main/java/com/sztzjy/resource_center/controller/new_module/stu/StuJupyterController.java index 1903c90..ae9170c 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/new_module/stu/StuJupyterController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/new_module/stu/StuJupyterController.java @@ -3,29 +3,37 @@ package com.sztzjy.resource_center.controller.new_module.stu; import cn.hutool.core.convert.Convert; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; +import com.nimbusds.jose.shaded.gson.Gson; import com.sztzjy.resource_center.annotation.AnonymousAccess; +import com.sztzjy.resource_center.entity.AdminJupyterToken; +import com.sztzjy.resource_center.entity.AdminJupyterTokenExample; +import com.sztzjy.resource_center.mapper.AdminJupyterTokenMapper; +import com.sztzjy.resource_center.util.ResultDataEntity; import com.sztzjy.resource_center.util.ResultEntity; +import com.sztzjy.resource_center.util.file.IFileUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** * @author 17803 @@ -35,22 +43,33 @@ import java.util.Optional; @RestController @Api(tags = "jupyter相关") @RequestMapping("api/stu/jupyter") +@Slf4j public class StuJupyterController { @Value("${tch.serverAddress}") String JUPYTER_URL; - @Value("${tch.token}") - String TOKEN; + @Resource + IFileUtil localFileUtil; - //获取最新token - @ApiOperation("教师端获取token") - @GetMapping("/tokenTch") - @AnonymousAccess - public ResultEntity getBlockResources(@ApiParam("参数为:jupytertch/jupyterstu") String type) throws IOException, InterruptedException { + @Autowired + private AdminJupyterTokenMapper adminJupyterTokenMapper; + + + @Scheduled(fixedDelay = 3600000) + public void updateToken() throws IOException, InterruptedException { + + log.info("定时任务:==================根据学校更新排名======================"); + + //删除全部文件 + AdminJupyterTokenExample tokenExample = new AdminJupyterTokenExample(); + tokenExample.createCriteria().getAllCriteria(); + adminJupyterTokenMapper.deleteByExample(tokenExample); - String[] command = {"docker", "exec", type, "jupyter", "server", "list"}; + + + String[] command = {"docker", "exec", "jupytertch", "jupyter", "server", "list"}; Map map = connectdocker(command); Object o = map.get("exitCode"); @@ -66,16 +85,85 @@ public class StuJupyterController { int i1 = output.toString().lastIndexOf("::"); String substring = output.toString().substring(i + 1, i1 - 1); System.out.println(substring); - //todo 保存数据库 每半小时执行一次更新token ,如果相同就变换,否则就不变 - return new ResultEntity<>(HttpStatus.OK, type + "token为:", substring); + + AdminJupyterToken adminJupyterToken = new AdminJupyterToken(); + adminJupyterToken.setToken(substring); + adminJupyterToken.setType(1); + adminJupyterToken.setCreateTime(new Date()); + adminJupyterTokenMapper.insertSelective(adminJupyterToken); } else { // 执行失败,输出错误信息 Object err = map.get("errors"); String errors = Convert.toStr(err); System.err.println("Error executing Python code:\n" + errors.toString()); - return new ResultEntity(HttpStatus.OK, errors.toString()); + } + + + String[] commandStu = {"docker", "exec", "jupyterstu", "jupyter", "server", "list"}; + + Map map1 = connectdocker(commandStu); + Object o1 = map1.get("exitCode"); + System.out.println(o1); + Integer exitCode1 = Convert.toInt(o1); + System.out.println(exitCode1); + + if (exitCode1 == 0) { + Object out1 = map1.get("output"); + String output = Convert.toStr(out1); +// String s="Currently running servers: http://27fedcc1ea32:8888/?token=0201325a5e218f35db24f90b8a4c23373ec86987ce9d0a56 :: /home/jovyan/work"; + int i = output.toString().indexOf("="); + int i1 = output.toString().lastIndexOf("::"); + String substring = output.toString().substring(i + 1, i1 - 1); + System.out.println(substring); + + AdminJupyterToken adminJupyterToken = new AdminJupyterToken(); + adminJupyterToken.setToken(substring); + adminJupyterToken.setType(0); + adminJupyterToken.setCreateTime(new Date()); + adminJupyterTokenMapper.insertSelective(adminJupyterToken); + } else { + // 执行失败,输出错误信息 + Object err = map.get("errors"); + String errors = Convert.toStr(err); + System.err.println("Error executing Python code:\n" + errors.toString()); + + } + + log.info("定时任务:==================执行结束======================"); + } + + + //获取最新token + @ApiOperation("教师端获取token") + @GetMapping("/tokenTch") + @AnonymousAccess + public ResultEntity getBlockResources(@ApiParam("参数为:jupytertch/jupyterstu") String type) throws IOException, InterruptedException { + + Integer info = -1; + if ("jupytertch".equals(type)) + { + info = 1; + }else if ("jupyterstu".equals(type)){ + info = 0; + } + + AdminJupyterTokenExample tokenExample = new AdminJupyterTokenExample(); + tokenExample.createCriteria().andTypeEqualTo(info); + + List adminJupyterTokenList = adminJupyterTokenMapper.selectByExample(tokenExample); + if (adminJupyterTokenList.isEmpty()) + { + return new ResultEntity<>(HttpStatus.BAD_REQUEST,"Token不存在!"); + } + + + return new ResultEntity<>(HttpStatus.OK, type + "token为:", adminJupyterTokenList.get(0).getToken()); + + + + } @@ -86,7 +174,7 @@ public class StuJupyterController { public ResultEntity convertToObj(@ApiParam("参数为:案例名") String name) throws IOException, InterruptedException { String caseName = "/home/jovyan/work/" + name + ".ipynb"; - String[] command = {"docker", "exec", "jupytertch", "sudo", "jupyter", "nbconvert", "--to", "markdown", caseName}; + String[] command = {"docker", "exec", "jupytertch", "jupyter", "nbconvert", "--to", "html", caseName}; Map map = connectdocker(command); Object o = map.get("exitCode"); @@ -99,10 +187,10 @@ public class StuJupyterController { //文件移动 - String path = "/usr/local/tianzeProject/jupyter/tch/" + name + ".md"; - String toPath = "/usr/local/tianzeProject/jupyter/html"; + String path = "/usr/local/tianzeProject/jupyter/tch/" + name + ".html"; + String toPath = "/usr/local/tianzeProject/jupyter/md/html"; - String[] commandMove = {"sudo", "mv", path, toPath}; + String[] commandMove = {"mv" ,"-f", path, toPath}; Process process = Runtime.getRuntime().exec(commandMove); // 获取进程的输入流 BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); @@ -159,7 +247,7 @@ public class StuJupyterController { // String pathFile = "/usr/local/tianzeProject/jupyter/tch/"+name+".ipynb"; String toPath = "/usr/local/tianzeProject/jupyter/stu"; - String[] commandMove = {"sudo", "cp", "-f", targetFile.get().getPath(), toPath}; + String[] commandMove = {"cp", "-f", targetFile.get().getPath(), toPath}; Process process = Runtime.getRuntime().exec(commandMove); @@ -221,6 +309,19 @@ public class StuJupyterController { //没有就创建 + + AdminJupyterTokenExample tokenExample = new AdminJupyterTokenExample(); + tokenExample.createCriteria().andTypeEqualTo(1); + + List adminJupyterTokenList = adminJupyterTokenMapper.selectByExample(tokenExample); + if (adminJupyterTokenList.isEmpty()) + { + return new ResultEntity<>(HttpStatus.BAD_REQUEST,"Token不存在!"); + } + + + + try (CloseableHttpClient client = HttpClients.createDefault()) { String notebookContent = "{" + "\"cells\": [" @@ -255,9 +356,17 @@ public class StuJupyterController { + "\"nbformat_minor\": 2" + "}"; + + + + + // 在根目录下创建新的笔记本 HttpPut createNotebookRequest = new HttpPut(JUPYTER_URL + "/api/contents/"+name+".ipynb"); - createNotebookRequest.addHeader("Authorization", "token " + TOKEN); + + + + createNotebookRequest.addHeader("Authorization", "token " + adminJupyterTokenList.get(0).getToken()); createNotebookRequest.addHeader("Content-Type", "application/json"); createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}")); @@ -282,6 +391,70 @@ public class StuJupyterController { + //文件查询 ,判断有无文件 + @ApiOperation("文件上传") + @PostMapping("/importIpynb") + @AnonymousAccess + public ResultEntity importIpynb(@ApiParam("案例名") String caseName,@RequestPart MultipartFile file ) { + + + + + String originalFilename = file.getOriginalFilename(); + int i = originalFilename.lastIndexOf("."); + String substring = originalFilename.substring(i); + if ("html".equals(substring)|| "md".equals(substring)) + { + // 上传到不同文件夹 + if (!(caseName+".md").equals(file.getOriginalFilename())) + { + return new ResultEntity<>(HttpStatus.ACCEPTED,"请上传和案例名相同的文件!"); + } + String upload = localFileUtil.uploadByRelativePath(file,"/usr/local/tianzeProject/jupyter/tch"); + + if (upload!=null) + { + return new ResultEntity<>(HttpStatus.OK,"上传成功!"); + }else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传失败!"); + } + + + + } + if ("ipynb".equals(substring)) + { + // 上传到不同文件夹 + if (!(caseName+".ipynb").equals(file.getOriginalFilename())) + { + return new ResultEntity<>(HttpStatus.ACCEPTED,"请上传和案例名相同的文件!"); + } + String upload = localFileUtil.uploadByRelativePath(file,"/usr/local/tianzeProject/jupyter/tch"); + + if (upload!=null) + { + return new ResultEntity<>(HttpStatus.OK,"上传成功!"); + }else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传失败!"); + } + + + } + + + + + + //转换出md文件 + + + return new ResultEntity<>("上传成功!"); + + + } + + + // 导入ipynb文件 @@ -326,19 +499,68 @@ public class StuJupyterController { return map; } + @ApiOperation("更新案例") + @GetMapping("/updateNoteBookByName") + @AnonymousAccess + public ResultEntity updateNoteBookByName(@ApiParam("参数为:案例名") String oldName,@ApiParam("参数为:新文件名")String newName) throws IOException, InterruptedException { - //新增notebook可用 + String caseTchName = "/usr/local/tianzeProject/jupyter/tch/"+oldName+".ipynb"; + String caseTchNewName = "/usr/local/tianzeProject/jupyter/tch/"+newName+".ipynb"; + String[] command = {"mv", caseTchName, caseTchNewName}; + Map map = connectdocker(command); + Object o = map.get("exitCode"); + Integer exitCode = Convert.toInt(o); - public static void main(String[] args) throws Exception { - createNotebookAndExecuteCode(); - } + if (exitCode == 0) { + Object out = map.get("output"); + String output = Convert.toStr(out); + System.out.println(output); + + + String caseStuName = "/usr/local/tianzeProject/jupyter/stu/"+oldName+".ipynb"; + + //判断学生端有无这个文件 + File fileNew = new File(caseStuName); + + + if (fileNew.exists()) { + //文件移动 + + String caseStuNewName = "/usr/local/tianzeProject/jupyter/stu/"+newName+".ipynb"; + + String[] commandMove = { "mv", caseStuName, caseStuNewName}; + Process process = Runtime.getRuntime().exec(commandMove); + // 获取进程的输入流 + BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); + + // 获取进程的输出流 + BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); + + // 等待进程执行完成 + int exitCodeInfo = process.waitFor(); + if (exitCodeInfo == 0) { + return new ResultEntity<>(HttpStatus.OK, "导出成功"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "导出失败!请联系管理员"); + } + } else { + return new ResultEntity<>(HttpStatus.OK,"更新成功!"); + } + + } else { + // 执行失败,输出错误信息 + Object err = map.get("errors"); + String errors = Convert.toStr(err); + System.err.println("Error executing Python code:\n" + errors.toString()); + return new ResultEntity(HttpStatus.OK, errors.toString()); + } - public static void createNotebookAndExecuteCode() throws IOException { } + } diff --git a/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterToken.java b/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterToken.java new file mode 100644 index 0000000..cfa830d --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterToken.java @@ -0,0 +1,64 @@ +package com.sztzjy.resource_center.entity; + +import java.util.Date; + +import io.swagger.annotations.ApiModelProperty; +/** + * jupyter token + * + * @author xcj + * admin_jupyter_token + */ +public class AdminJupyterToken { + private Integer id; + + @ApiModelProperty("0:学生 1:教师") + private Integer type; + + @ApiModelProperty("jupyterToken") + private String token; + + private Date createTime; + + private Date updateTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token == null ? null : token.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterTokenExample.java b/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterTokenExample.java new file mode 100644 index 0000000..9e243b3 --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/entity/AdminJupyterTokenExample.java @@ -0,0 +1,510 @@ +package com.sztzjy.resource_center.entity; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class AdminJupyterTokenExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public AdminJupyterTokenExample() { + oredCriteria = new ArrayList<>(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList<>(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Integer value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Integer value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Integer value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Integer value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Integer value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Integer value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Integer value1, Integer value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Integer value1, Integer value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andTypeIsNull() { + addCriterion("type is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("type is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(Integer value) { + addCriterion("type =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(Integer value) { + addCriterion("type <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(Integer value) { + addCriterion("type >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(Integer value) { + addCriterion("type >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(Integer value) { + addCriterion("type <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(Integer value) { + addCriterion("type <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("type in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("type not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(Integer value1, Integer value2) { + addCriterion("type between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(Integer value1, Integer value2) { + addCriterion("type not between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTokenIsNull() { + addCriterion("token is null"); + return (Criteria) this; + } + + public Criteria andTokenIsNotNull() { + addCriterion("token is not null"); + return (Criteria) this; + } + + public Criteria andTokenEqualTo(String value) { + addCriterion("token =", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenNotEqualTo(String value) { + addCriterion("token <>", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenGreaterThan(String value) { + addCriterion("token >", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenGreaterThanOrEqualTo(String value) { + addCriterion("token >=", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenLessThan(String value) { + addCriterion("token <", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenLessThanOrEqualTo(String value) { + addCriterion("token <=", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenLike(String value) { + addCriterion("token like", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenNotLike(String value) { + addCriterion("token not like", value, "token"); + return (Criteria) this; + } + + public Criteria andTokenIn(List values) { + addCriterion("token in", values, "token"); + return (Criteria) this; + } + + public Criteria andTokenNotIn(List values) { + addCriterion("token not in", values, "token"); + return (Criteria) this; + } + + public Criteria andTokenBetween(String value1, String value2) { + addCriterion("token between", value1, value2, "token"); + return (Criteria) this; + } + + public Criteria andTokenNotBetween(String value1, String value2) { + addCriterion("token not between", value1, value2, "token"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Date value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Date value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Date value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Date value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Date value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Date value1, Date value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Date value1, Date value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/AdminJupyterTokenMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/AdminJupyterTokenMapper.java new file mode 100644 index 0000000..4a20d66 --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/mapper/AdminJupyterTokenMapper.java @@ -0,0 +1,32 @@ +package com.sztzjy.resource_center.mapper; + +import com.sztzjy.resource_center.entity.AdminJupyterToken; +import com.sztzjy.resource_center.entity.AdminJupyterTokenExample; +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +@Mapper +public interface AdminJupyterTokenMapper { + long countByExample(AdminJupyterTokenExample example); + + int deleteByExample(AdminJupyterTokenExample example); + + int deleteByPrimaryKey(Integer id); + + int insert(AdminJupyterToken record); + + int insertSelective(AdminJupyterToken record); + + List selectByExample(AdminJupyterTokenExample example); + + AdminJupyterToken selectByPrimaryKey(Integer id); + + int updateByExampleSelective(@Param("record") AdminJupyterToken record, @Param("example") AdminJupyterTokenExample example); + + int updateByExample(@Param("record") AdminJupyterToken record, @Param("example") AdminJupyterTokenExample example); + + int updateByPrimaryKeySelective(AdminJupyterToken record); + + int updateByPrimaryKey(AdminJupyterToken record); +} \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java b/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java index afe9aae..586fd27 100644 --- a/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java +++ b/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java @@ -84,4 +84,6 @@ public interface IFileUtil { */ String getDiskRelativePath(String fileName, String suffix); + String uploadByRelativePath(MultipartFile file, String relativePath); + } diff --git a/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java b/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java index d802472..45ada64 100644 --- a/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java +++ b/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java @@ -129,6 +129,7 @@ public class LocalFileUtil implements IFileUtil{ } + @Override public String getDiskRelativePath(String fileName, String suffix) { Calendar c = Calendar.getInstance(); @@ -147,7 +148,7 @@ public class LocalFileUtil implements IFileUtil{ } - private String upload(String fileName, MultipartFile file, String relativePath) { + public String upload(String fileName, MultipartFile file, String relativePath) { Assert.isTrue(!file.isEmpty(), "文件不存在"); String originalFilename = file.getOriginalFilename(); if (fileName == null) fileName = IdUtil.simpleUUID(); @@ -173,4 +174,26 @@ public class LocalFileUtil implements IFileUtil{ throw new IllegalArgumentException("上传文件失败,IO错误"); } } + + + public String uploadByRelativePath(MultipartFile file, String relativePath) { + Assert.isTrue(!file.isEmpty(), "文件不存在"); + String originalFilename = file.getOriginalFilename(); + + try { + String filePath; + + relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/"; + filePath = relativePath + originalFilename; + + File destFile = new File(getFullPath(filePath)); + destFile.getParentFile().mkdirs(); + file.transferTo(destFile); + return filePath; + } catch (FileNotFoundException e) { + throw new IllegalArgumentException("上传文件失败,FileNotFound错误"); + } catch (IOException e) { + throw new IllegalArgumentException("上传文件失败,IO错误"); + } + } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 2ca10cf..ddfc691 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -11,8 +11,8 @@ spring: # 文件存储 file: type: local -# path: /usr/local/tianzeProject/resourceCenter/uploadFile - path: D:/home + path: /usr/local/tianzeProject/resourceCenter/uploadFile +# path: D:/home timer: enable: false @@ -28,4 +28,3 @@ swagger: tch: serverAddress: http://118.31.7.2:9998 - token: 26a5b8081702080b150b9d4a715a4b9b442b1d3b5c38823c \ No newline at end of file diff --git a/src/main/resources/mapper/AdminJupyterTokenMapper.xml b/src/main/resources/mapper/AdminJupyterTokenMapper.xml new file mode 100644 index 0000000..ece68bf --- /dev/null +++ b/src/main/resources/mapper/AdminJupyterTokenMapper.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, type, token, create_time, update_time + + + + + delete from admin_jupyter_token + where id = #{id,jdbcType=INTEGER} + + + delete from admin_jupyter_token + + + + + + insert into admin_jupyter_token (id, type, token, + create_time, update_time) + values (#{id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{token,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) + + + insert into admin_jupyter_token + + + id, + + + type, + + + token, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{type,jdbcType=INTEGER}, + + + #{token,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + + update admin_jupyter_token + + + id = #{record.id,jdbcType=INTEGER}, + + + type = #{record.type,jdbcType=INTEGER}, + + + token = #{record.token,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + + + + + + + update admin_jupyter_token + set id = #{record.id,jdbcType=INTEGER}, + type = #{record.type,jdbcType=INTEGER}, + token = #{record.token,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP} + + + + + + update admin_jupyter_token + + + type = #{type,jdbcType=INTEGER}, + + + token = #{token,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update admin_jupyter_token + set type = #{type,jdbcType=INTEGER}, + token = #{token,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file