新增定时任务自动同步token到数据库

案例更新
文件导入
master
whb 8 months ago
parent f87500d77d
commit 25ee8393ff

@ -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<AdminJupyterToken> 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<AdminJupyterToken> 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 {
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);
if (exitCode == 0) {
Object out = map.get("output");
String output = Convert.toStr(out);
System.out.println(output);
//新增notebook可用
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()));
public static void main(String[] args) throws Exception {
createNotebookAndExecuteCode();
// 等待进程执行完成
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 {
}
}

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

@ -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<Criteria> 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<Criteria> 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<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<Integer> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Integer> 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<Integer> values) {
addCriterion("type in", values, "type");
return (Criteria) this;
}
public Criteria andTypeNotIn(List<Integer> 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<String> values) {
addCriterion("token in", values, "token");
return (Criteria) this;
}
public Criteria andTokenNotIn(List<String> 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<Date> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Date> 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<Date> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Date> 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);
}
}
}

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

@ -84,4 +84,6 @@ public interface IFileUtil {
*/
String getDiskRelativePath(String fileName, String suffix);
String uploadByRelativePath(MultipartFile file, String relativePath);
}

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

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

@ -0,0 +1,211 @@
<?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.sztzjy.resource_center.mapper.AdminJupyterTokenMapper">
<resultMap id="BaseResultMap" type="com.sztzjy.resource_center.entity.AdminJupyterToken">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="token" jdbcType="VARCHAR" property="token" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, type, token, create_time, update_time
</sql>
<select id="selectByExample" parameterType="com.sztzjy.resource_center.entity.AdminJupyterTokenExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from admin_jupyter_token
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from admin_jupyter_token
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from admin_jupyter_token
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.sztzjy.resource_center.entity.AdminJupyterTokenExample">
delete from admin_jupyter_token
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.sztzjy.resource_center.entity.AdminJupyterToken">
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>
<insert id="insertSelective" parameterType="com.sztzjy.resource_center.entity.AdminJupyterToken">
insert into admin_jupyter_token
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="type != null">
type,
</if>
<if test="token != null">
token,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=INTEGER},
</if>
<if test="token != null">
#{token,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.sztzjy.resource_center.entity.AdminJupyterTokenExample" resultType="java.lang.Long">
select count(*) from admin_jupyter_token
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update admin_jupyter_token
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.type != null">
type = #{record.type,jdbcType=INTEGER},
</if>
<if test="record.token != null">
token = #{record.token,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.sztzjy.resource_center.entity.AdminJupyterToken">
update admin_jupyter_token
<set>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="token != null">
token = #{token,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.sztzjy.resource_center.entity.AdminJupyterToken">
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}
</update>
</mapper>
Loading…
Cancel
Save