|
@@ -1,16 +1,17 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.SystemPropertyDomain;
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.SystemPropertyInfo;
|
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache;
|
|
|
|
-import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
-import io.swagger.annotations.Api;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Base64;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
+
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
|
|
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,14 +21,33 @@ import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
|
-import javax.validation.Valid;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.UUID;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.SystemPropertyDomain;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.SystemPropertyInfo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache;
|
|
|
|
+import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
|
+import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 系统配置
|
|
* 系统配置
|
|
@@ -40,7 +60,8 @@ import java.util.stream.Stream;
|
|
@Api(tags = "系统配置相关接口")
|
|
@Api(tags = "系统配置相关接口")
|
|
@RequestMapping("${$rmp.ctr.basic}/systemProperty")
|
|
@RequestMapping("${$rmp.ctr.basic}/systemProperty")
|
|
public class SystemPropertyController extends ControllerSupport {
|
|
public class SystemPropertyController extends ControllerSupport {
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SystemProperties systemConfig;
|
|
@Autowired
|
|
@Autowired
|
|
SystemPropertyService systemPropertyService;
|
|
SystemPropertyService systemPropertyService;
|
|
|
|
|
|
@@ -50,6 +71,64 @@ public class SystemPropertyController extends ControllerSupport {
|
|
@Autowired
|
|
@Autowired
|
|
SystemPropertyCache systemPropertyCache;
|
|
SystemPropertyCache systemPropertyCache;
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "获取软件黑名单")
|
|
|
|
+ @GetMapping("blacklist")
|
|
|
|
+ public String getBlacklist() {
|
|
|
|
+ File dir=new File(systemConfig.getTempDataDir() +"/" + UUID.randomUUID()+"/");
|
|
|
|
+ try {
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ File file = new File(dir.getAbsoluteFile()+"/software.json");
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ try {
|
|
|
|
+ FileStorageUtil.saveUrlAs(FileStorageUtil.realPath("aliyun-1://oe_client/software.json"), file);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ String content=FileUtils.readFileToString(file, "UTF-8");
|
|
|
|
+ if(StringUtils.isBlank(content)) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ content=content.substring(0,content.length()-32);
|
|
|
|
+ StringBuilder sb=new StringBuilder(content);
|
|
|
|
+ sb.reverse();
|
|
|
|
+ return new String(Base64.getDecoder().decode(sb.toString()));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("500","保存失败",e);
|
|
|
|
+ }finally {
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.deleteDirectory(dir);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "保存软件黑名单")
|
|
|
|
+ @PutMapping("blacklist")
|
|
|
|
+ public void saveBlacklist(@RequestParam(required = false) String blacklist) {
|
|
|
|
+ File dir=new File(systemConfig.getTempDataDir() +"/" + UUID.randomUUID()+"/");
|
|
|
|
+ try {
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ File file = new File(dir.getAbsoluteFile()+"/software.json");
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ if(StringUtils.isNotBlank(blacklist)) {
|
|
|
|
+ StringBuilder sb=new StringBuilder(Base64.getEncoder().encodeToString(blacklist.getBytes()));
|
|
|
|
+ sb.reverse();
|
|
|
|
+ String ret=sb.toString()+UUID.randomUUID().toUpperCase();
|
|
|
|
+ FileUtils.write(file, ret, "UTF-8");
|
|
|
|
+ }
|
|
|
|
+ FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
|
+ FileStorageUtil.saveFile("blacklist", env, file, null,0L);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("500","保存失败",e);
|
|
|
|
+ }finally {
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.deleteDirectory(dir);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@ApiOperation(value = "查询系统配置")
|
|
@ApiOperation(value = "查询系统配置")
|
|
@GetMapping("{key}")
|
|
@GetMapping("{key}")
|
|
public Object get(@PathVariable String key) {
|
|
public Object get(@PathVariable String key) {
|