Browse Source

新增多图片服务器配置

ting.yin 3 năm trước cách đây
mục cha
commit
5c1485804e

+ 14 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/dao/SystemConfigDao.java

@@ -0,0 +1,14 @@
+package cn.com.qmth.stmms.biz.config.dao;
+
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.PagingAndSortingRepository;
+
+import cn.com.qmth.stmms.biz.config.model.SystemConfig;
+import cn.com.qmth.stmms.common.enums.ConfigType;
+
+public interface SystemConfigDao extends PagingAndSortingRepository<SystemConfig, Integer>,
+        JpaSpecificationExecutor<SystemConfig> {
+
+    SystemConfig findByType(ConfigType type);
+
+}

+ 80 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/model/SystemConfig.java

@@ -0,0 +1,80 @@
+package cn.com.qmth.stmms.biz.config.model;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+import cn.com.qmth.stmms.common.enums.ConfigType;
+
+@Cacheable
+@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+@Entity
+@Table(name = "b_sys_config")
+public class SystemConfig implements Serializable {
+
+    private static final long serialVersionUID = 6151033013226678852L;
+
+    @Id
+    @GeneratedValue
+    private Integer id;
+
+    @Enumerated(EnumType.STRING)
+    @Column(name = "type", length = 16, nullable = false)
+    private ConfigType type;
+
+    @Column(name = "description")
+    private String description;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "update_time")
+    private Date updateTime;
+
+    public SystemConfig() {
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public ConfigType getType() {
+        return type;
+    }
+
+    public void setType(ConfigType type) {
+        this.type = type;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+}

+ 18 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/service/SystemConfigService.java

@@ -0,0 +1,18 @@
+package cn.com.qmth.stmms.biz.config.service;
+
+import java.util.List;
+
+import cn.com.qmth.stmms.biz.config.model.SystemConfig;
+import cn.com.qmth.stmms.common.enums.ConfigType;
+
+public interface SystemConfigService {
+
+    SystemConfig update(Integer id, String value);
+
+    List<SystemConfig> findAll();
+
+    SystemConfig findById(Integer id);
+
+    String findByType(ConfigType type);
+
+}

+ 48 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/service/impl/SystemConfigServiceImpl.java

@@ -0,0 +1,48 @@
+package cn.com.qmth.stmms.biz.config.service.impl;
+
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.stmms.biz.common.BaseQueryService;
+import cn.com.qmth.stmms.biz.config.dao.SystemConfigDao;
+import cn.com.qmth.stmms.biz.config.model.SystemConfig;
+import cn.com.qmth.stmms.biz.config.service.SystemConfigService;
+import cn.com.qmth.stmms.common.enums.ConfigType;
+
+@Service("systemConfigService")
+public class SystemConfigServiceImpl extends BaseQueryService<SystemConfig> implements SystemConfigService {
+
+    @Autowired
+    private SystemConfigDao configDao;
+
+    @Override
+    public SystemConfig update(Integer id, String value) {
+        SystemConfig s = configDao.findOne(id);
+        s.setDescription(value);
+        s.setUpdateTime(new Date());
+        return configDao.save(s);
+    }
+
+    @Override
+    public List<SystemConfig> findAll() {
+        return (List<SystemConfig>) configDao.findAll();
+    }
+
+    @Override
+    public SystemConfig findById(Integer id) {
+        return configDao.findOne(id);
+    }
+
+    @Override
+    public String findByType(ConfigType type) {
+        SystemConfig s = configDao.findByType(type);
+        if (s != null) {
+            return s.getDescription();
+        }
+        return null;
+    }
+
+}

+ 2 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/file/service/FileService.java

@@ -9,6 +9,8 @@ public interface FileService {
 
     String getFileServer();
 
+    String getRandomFileServer();
+
     byte[] downloadSheet(int examId, String examNumber, int index) throws Exception;
 
     byte[] downloadSlice(int examId, String secretNumber, int index) throws Exception;

+ 49 - 18
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/file/service/impl/FileServiceImpl.java

@@ -1,21 +1,23 @@
 package cn.com.qmth.stmms.biz.file.service.impl;
 
-import cn.com.qmth.stmms.biz.file.enums.FileType;
-import cn.com.qmth.stmms.biz.file.enums.FormatType;
-import cn.com.qmth.stmms.biz.file.service.FileService;
-import cn.com.qmth.stmms.biz.file.store.FileStore;
-import cn.com.qmth.stmms.biz.file.store.impl.DiskStore;
-import cn.com.qmth.stmms.biz.file.store.impl.OssStore;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
 
+import org.apache.commons.lang.math.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
+import cn.com.qmth.stmms.biz.file.enums.FileType;
+import cn.com.qmth.stmms.biz.file.enums.FormatType;
+import cn.com.qmth.stmms.biz.file.service.FileService;
+import cn.com.qmth.stmms.biz.file.store.FileStore;
+import cn.com.qmth.stmms.biz.file.store.impl.DiskStore;
+import cn.com.qmth.stmms.biz.file.store.impl.OssStore;
 
 @Service("fileService")
 public class FileServiceImpl implements FileService, InitializingBean, DisposableBean {
@@ -24,8 +26,12 @@ public class FileServiceImpl implements FileService, InitializingBean, Disposabl
 
     private static final int DEFAULT_SUFFIX_LENGTH = 3;
 
+    public static final String SERVER_SPLIT = ",";
+
     @Value("${file.server}")
-    private String fileServer;
+    private String fileServerString;
+
+    private List<String> fileServers;
 
     @Value("${file.store}")
     private String fileStore;
@@ -47,11 +53,21 @@ public class FileServiceImpl implements FileService, InitializingBean, Disposabl
 
     @Override
     public String getFileServer() {
-        return fileServer;
+        return fileServers.get(0);
+
+    }
+
+    @Override
+    public String getRandomFileServer() {
+        return fileServers.get(RandomUtils.nextInt(fileServers.size()));
     }
 
-    public void setFileServer(String fileServer) {
-        this.fileServer = fileServer;
+    public String getFileServerString() {
+        return fileServerString;
+    }
+
+    public void setFileServerString(String fileServerString) {
+        this.fileServerString = fileServerString;
     }
 
     public String getFileStore() {
@@ -217,17 +233,31 @@ public class FileServiceImpl implements FileService, InitializingBean, Disposabl
 
     @Override
     public void afterPropertiesSet() {
-        fileServer = StringUtils.trimToNull(fileServer);
+        fileServerString = StringUtils.trimToNull(fileServerString);
         fileStore = StringUtils.trimToNull(fileStore);
-        if (fileServer == null) {
+
+        if (fileServerString == null) {
             throw new RuntimeException("invald property: ${file.server} should not be empty");
         }
         if (fileStore == null) {
             throw new RuntimeException("invald property: ${file.store} should not be empty");
         }
-        if (!fileServer.endsWith("/")) {
-            fileServer = fileServer.concat("/");
+        // 按逗号拆分多个文件服务器地址
+        fileServers = new ArrayList<>();
+        String[] servers = StringUtils.split(fileServerString, SERVER_SPLIT);
+        for (String server : servers) {
+            server = StringUtils.trimToNull(server);
+            if (server != null) {
+                if (!server.endsWith("/")) {
+                    server = server.concat("/");
+                }
+                fileServers.add(server);
+            }
         }
+        if (fileServers.isEmpty()) {
+            throw new RuntimeException("invald property: ${file.server} should not be empty");
+        }
+        // 按前缀解析文件存储引擎
         if (fileStore.startsWith("oss")) {
             store = new OssStore(fileStore);
         } else {
@@ -257,7 +287,8 @@ public class FileServiceImpl implements FileService, InitializingBean, Disposabl
 
     public static void main(String[] args) throws Exception {
         FileServiceImpl service = new FileServiceImpl();
-        service.fileServer = "123";
+        service.fileServerString = "123";
+
         service.fileStore = "oss://LTAI4FnJ2pgV6aGceYcCkeEi:ktrMEVE7PfoxRPeJUPDFeygOIH4aU7@qmth-test.oss-cn-shenzhen.aliyuncs.com";
         service.afterPropertiesSet();
 

+ 5 - 2
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/service/Impl/MarkCronService.java

@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import cn.com.qmth.stmms.biz.config.service.SystemConfigService;
 import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
 import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
@@ -21,6 +22,7 @@ import cn.com.qmth.stmms.biz.exam.service.MarkerService;
 import cn.com.qmth.stmms.biz.lock.LockService;
 import cn.com.qmth.stmms.biz.mark.service.MarkService;
 import cn.com.qmth.stmms.biz.utils.TaskLockUtil;
+import cn.com.qmth.stmms.common.enums.ConfigType;
 import cn.com.qmth.stmms.common.enums.LockType;
 import cn.com.qmth.stmms.common.enums.MarkStatus;
 
@@ -52,8 +54,8 @@ public class MarkCronService {
     @Autowired
     private MarkerService markerService;
 
-    @Value("${mark.cleanTimeoutMinute}")
-    private long timeoutMinute;
+    @Autowired
+    private SystemConfigService configService;
 
     @Value("${mark.activeExpireMinute}")
     private long markerActiveExpireMinute;
@@ -76,6 +78,7 @@ public class MarkCronService {
     @Scheduled(cron = "${mark.cleanTaskSchedule}")
     public void cronCleanTask() {
         try {
+            long timeoutMinute = Long.parseLong(configService.findByType(ConfigType.MARK_TIME));
             TaskLockUtil.clearTimeoutTask(timeoutMinute * 60 * 1000);
         } catch (Exception e) {
             log.error("CronCleanTask error", e);

+ 0 - 4
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/school/service/SchoolService.java

@@ -1,12 +1,8 @@
 package cn.com.qmth.stmms.biz.school.service;
 
-import java.util.List;
-
 import cn.com.qmth.stmms.biz.school.model.School;
 import cn.com.qmth.stmms.biz.school.query.SchoolSearchQuery;
 
-import org.springframework.transaction.annotation.Transactional;
-
 public interface SchoolService {
 
     School save(School school);

+ 31 - 0
stmms-common/src/main/java/cn/com/qmth/stmms/common/enums/ConfigType.java

@@ -0,0 +1,31 @@
+package cn.com.qmth.stmms.common.enums;
+
+public enum ConfigType {
+    FILE_SERVER("图片服务", 1), MARK_TIME("评卷时长", 2);
+
+    private String name;
+
+    private int value;
+
+    private ConfigType(String name, int value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public static ConfigType findByValue(int value) {
+        for (ConfigType c : ConfigType.values()) {
+            if (c.getValue() == value) {
+                return c;
+            }
+        }
+        return null;
+    }
+}

+ 58 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/admin/config/SystemConfigController.java

@@ -0,0 +1,58 @@
+package cn.com.qmth.stmms.admin.config;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import cn.com.qmth.stmms.biz.config.model.SystemConfig;
+import cn.com.qmth.stmms.biz.config.service.SystemConfigService;
+import cn.com.qmth.stmms.common.annotation.Logging;
+import cn.com.qmth.stmms.common.annotation.RoleRequire;
+import cn.com.qmth.stmms.common.controller.BaseController;
+import cn.com.qmth.stmms.common.enums.LogType;
+import cn.com.qmth.stmms.common.enums.Role;
+
+@Controller
+@RequestMapping("/admin/sys/config")
+public class SystemConfigController extends BaseController {
+
+    @Autowired
+    private SystemConfigService configService;
+
+    @Logging(menu = "查询", type = LogType.QUERY)
+    @RoleRequire(Role.SYS_ADMIN)
+    @RequestMapping
+    public ModelAndView list(HttpServletRequest request) {
+        ModelAndView view = new ModelAndView("modules/sys/configList");
+        List<SystemConfig> list = configService.findAll();
+        view.addObject("list", list);
+        return view;
+    }
+
+    @RequestMapping(value = "/edit", method = RequestMethod.GET)
+    public ModelAndView editInit(HttpServletRequest request, @RequestParam Integer id) {
+        SystemConfig config = configService.findById(id);
+        if (config != null) {
+            ModelAndView view = new ModelAndView("modules/sys/configEdit");
+            view.addObject("config", config);
+            return view;
+        } else {
+            return new ModelAndView("redirect:/admin/sys/config");
+        }
+    }
+
+    @Logging(menu = "修改配置", type = LogType.UPDATE)
+    @RequestMapping(value = "/update", method = RequestMethod.POST)
+    public String save(HttpServletRequest request, SystemConfig config) {
+        configService.update(config.getId(), config.getDescription());
+        return "redirect:/admin/sys/config";
+    }
+
+}

+ 1 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/mark/MarkController.java

@@ -279,7 +279,7 @@ public class MarkController extends BaseController {
         group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(group.getExamId(),
                 group.getSubjectCode(), false, group.getNumber()));
         setting.accumulate("groupTitle", group.getTitle());
-        setting.accumulate("fileServer", fileService.getFileServer());
+        setting.accumulate("fileServer", fileService.getRandomFileServer());
         setting.accumulate("uiSetting",
                 StringUtils.isBlank(marker.getMarkSetting()) ? new JSONObject() : marker.getMarkSetting());
         setting.accumulate("splitConfig", getSplitConfig());

+ 51 - 0
stmms-web/src/main/webapp/WEB-INF/views/modules/sys/configEdit.jsp

@@ -0,0 +1,51 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
+<html>
+<head>
+    <title>修改配置</title>
+    <meta name="decorator" content="default"/>
+    <%@include file="/WEB-INF/views/include/head.jsp" %>
+    <script type="text/javascript">
+        $(document).ready(function () {
+            $("#name").focus();
+            $("#inputForm").validate({
+                submitHandler: function (form) {
+                    loading('正在提交,请稍等...');
+                    form.submit();
+                },
+                errorContainer: "#messageBox",
+                errorPlacement: function (error, element) {
+                    $("#messageBox").text("输入有误,请先更正。");
+                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
+                        error.appendTo(element.parent().parent());
+                    } else {
+                        error.insertAfter(element);
+                    }
+                }
+            });
+        });
+    </script>
+</head>
+<body>
+<form:form id="inputForm" modelAttribute="config" action="${ctx}/admin/sys/config/update" method="post" class="form-horizontal">
+    <form:hidden path="id"/>
+    <tags:message content="${message}"/>
+    <div class="control-group">
+        <label class="control-label">类型</label>
+        <div class="controls">
+            <input type="text" value="${config.type.name }" readonly="readonly"/>
+        </div>
+    </div>
+    <div class="control-group">
+        <label class="control-label">详情</label>
+        <div class="controls">
+            <form:textarea path="description" htmlEscape="false" rows="4" maxlength="200" class="input-xxlarge"/>
+        </div>
+    </div>
+    <div class="form-actions">
+        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
+        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
+    </div>
+</form:form>
+</body>
+</html>

+ 33 - 0
stmms-web/src/main/webapp/WEB-INF/views/modules/sys/configList.jsp

@@ -0,0 +1,33 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
+<html>
+<head>
+	<title>配置管理</title>
+	<meta name="decorator" content="default"/>
+	<%@include file="/WEB-INF/views/include/head.jsp" %>
+	<style type="text/css">.sort{color:#0663A2;cursor:pointer;}</style>
+</head>
+<body>
+	<tags:message content="${message}"/>
+	<table id="contentTable" class="table table-striped table-bordered table-condensed">
+		<thead>
+			<tr>
+				<th>类型</th>
+				<th>详情</th>
+				<th>操作</th>
+			</tr>
+		</thead>
+		<tbody>
+		<c:forEach items="${list}" var="config">
+			<tr>
+				<td>${config.type.name}</td>
+				<td>${config.description}</td>
+				<td>
+					<a href="${ctx}/admin/sys/config/edit?id=${config.id}">修改</a>
+				</td>
+			</tr>
+		</c:forEach>
+		</tbody>
+	</table>
+</body>
+</html>

+ 2 - 1
stmms-web/src/main/webapp/WEB-INF/views/modules/sys/sysIndex.jsp

@@ -87,7 +87,8 @@
 							    <div id="collapse1" class="accordion-body collapse ${firstMenu?'in':''}">
 									<div class="accordion-inner">
 										<ul class="nav nav-list">
-											<li><a href="${ctx}/admin/sys/school" target="mainFrame" ><i class="icon-th-list"></i>学校管理</a></li>								
+											<li><a href="${ctx}/admin/sys/school" target="mainFrame" ><i class="icon-th-list"></i>学校管理</a></li>	
+											<li><a href="${ctx}/admin/sys/config" target="mainFrame" ><i class="icon-th-list"></i>配置管理</a></li>							
 											<c:set var="firstMenu" value="false"/>
 										</ul>
 									</div>

+ 24 - 0
stmms-web/src/main/webapp/sql/stmms_ft.sql

@@ -30,7 +30,31 @@ CREATE TABLE `b_school`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4 COMMENT ='学校表';
 
+  
+# Dump of table b_sys_config
+# ------------------------------------------------------------
 
+DROP TABLE IF EXISTS `b_sys_config`;
+CREATE TABLE `b_sys_config`
+(
+    `id`            int(11)     NOT NULL AUTO_INCREMENT COMMENT '主键',
+    `type`          varchar(64) NOT NULL COMMENT '类型',
+    `description`   varchar(128) DEFAULT NULL COMMENT '描述',
+    `update_time`   datetime     DEFAULT NULL COMMENT '修改时间',
+    PRIMARY KEY (`id`),
+    UNIQUE KEY `index1` (`type`)
+) ENGINE = InnoDB
+  DEFAULT CHARSET = utf8mb4 COMMENT ='配置表';
+  
+LOCK TABLES `b_sys_config` WRITE;
+
+INSERT INTO `b_sys_config` (`id`, `type`, `description`, `update_time`)
+VALUES (1, 'FILE_SERVER', 'http://192.168.10.42:9000/,http://192.168.10.42:9000/', '2021-08-09 15:38:58');
+INSERT INTO `b_sys_config` (`id`, `type`, `description`, `update_time`)
+VALUES (2, 'MARK_TIME', '30', '2021-08-09 15:38:58');
+
+UNLOCK TABLES;
+  
 # Dump of table b_user
 # ------------------------------------------------------------