|
@@ -1,39 +1,183 @@
|
|
package cn.com.qmth.stmms.api.controller.admin;
|
|
package cn.com.qmth.stmms.api.controller.admin;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
|
-import io.swagger.annotations.Api;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
-import net.sf.json.JSONObject;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.stmms.admin.utils.SessionExamUtils;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.Marker;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.MarkerService;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.SubjectUserService;
|
|
|
|
+import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.MarkStatus;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
-import cn.com.qmth.stmms.common.enums.ExamType;
|
|
|
|
|
|
+import cn.com.qmth.stmms.biz.config.service.impl.SystemCache;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ResultMessage;
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.SystemStatusVo;
|
|
|
|
+import cn.com.qmth.stmms.biz.exception.StatusException;
|
|
|
|
+import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
|
+import cn.com.qmth.stmms.biz.user.model.User;
|
|
|
|
+import cn.com.qmth.stmms.biz.user.service.UserService;
|
|
|
|
+import cn.com.qmth.stmms.common.annotation.Logging;
|
|
|
|
+import cn.com.qmth.stmms.common.domain.WebUser;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.Role;
|
|
|
|
+import cn.com.qmth.stmms.common.session.model.StmmsSession;
|
|
|
|
+import cn.com.qmth.stmms.common.session.service.SessionService;
|
|
|
|
+import cn.com.qmth.stmms.common.utils.EncryptUtils;
|
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestIPUtil;
|
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
|
+import cn.com.qmth.stmms.common.utils.VersionInfo;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
-@Api(tags = "系统配置")
|
|
|
|
|
|
+@Api(tags = "系统配置和登录")
|
|
@Controller("sysController")
|
|
@Controller("sysController")
|
|
-@RequestMapping("/api/sys")
|
|
|
|
|
|
+@RequestMapping("/api/admin/sys")
|
|
public class SystemController extends BaseApiController {
|
|
public class SystemController extends BaseApiController {
|
|
|
|
|
|
protected static final Logger log = LoggerFactory.getLogger(SystemController.class);
|
|
protected static final Logger log = LoggerFactory.getLogger(SystemController.class);
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FileService fileService;
|
|
private FileService fileService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SubjectUserService subjectUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SystemCache authCache;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SessionService sessionService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamService examService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkerService markerService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkGroupService groupService;
|
|
|
|
+
|
|
|
|
+ @Value("${index.logo}")
|
|
|
|
+ private String indexLogo;
|
|
|
|
+
|
|
@ApiOperation(value = "系统版本及配置")
|
|
@ApiOperation(value = "系统版本及配置")
|
|
@RequestMapping(value = "/version", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/version", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
- public JSONObject version() {
|
|
|
|
- JSONObject result = new JSONObject();
|
|
|
|
- result.accumulate("fileServer", fileService.getFileServer());
|
|
|
|
- return result;
|
|
|
|
|
|
+ public SystemStatusVo version() {
|
|
|
|
+ SystemStatusVo vo = new SystemStatusVo();
|
|
|
|
+ vo.setFileServer(fileService.getFileServer());
|
|
|
|
+ vo.setIndexLogo(indexLogo);
|
|
|
|
+ vo.setVersionName(VersionInfo.NAME);
|
|
|
|
+ vo.setVersionDate(VersionInfo.DATE);
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "登出")
|
|
|
|
+ @RequestMapping(value = "/logout", method = RequestMethod.POST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public ResultMessage logout(HttpServletRequest request) {
|
|
|
|
+ StmmsSession session = RequestUtils.getSession(request);
|
|
|
|
+ session.setInvalid(true);
|
|
|
|
+ return resultOk();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "登录")
|
|
|
|
+ @Logging(menu = "登录", type = LogType.QUERY)
|
|
|
|
+ @RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public User login(User user, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ StmmsSession session = RequestUtils.getSession(request);
|
|
|
|
+ User u = userService.findByLoginName(user.getLoginName());
|
|
|
|
+ if (u == null) {
|
|
|
|
+ throw new StatusException("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!u.getPassword().equals(EncryptUtils.md5(user.getPassword()))) {
|
|
|
|
+ throw new StatusException("密码错误");
|
|
|
|
+ }
|
|
|
|
+ if (!u.isEnable()) {
|
|
|
|
+ throw new StatusException("用户被禁用");
|
|
|
|
+ }
|
|
|
|
+ if (!authCache.isAuth() && u.getRole() != Role.SYS_ADMIN) {
|
|
|
|
+ throw new StatusException("系统未授权");
|
|
|
|
+ }
|
|
|
|
+ if (authCache.getExpireTime() != null && new Date(authCache.getExpireTime()).before(new Date())
|
|
|
|
+ && u.getRole() != Role.SYS_ADMIN) {
|
|
|
|
+ throw new StatusException("系统授权已过期");
|
|
|
|
+ }
|
|
|
|
+ u.setLastLoginTime(new Date());
|
|
|
|
+ u.setLastLoginIp(RequestIPUtil.getIpAddress(request));
|
|
|
|
+ u.refreshAccessToken();
|
|
|
|
+ u = userService.save(u);
|
|
|
|
+
|
|
|
|
+ ApiUser au = new ApiUser(u);
|
|
|
|
+ au.setSubjectCodeSet(subjectUserService.findSubjectCode(au.getId()));
|
|
|
|
+ RequestUtils.setApiUser(request, au);
|
|
|
|
+
|
|
|
|
+ WebUser wu = new WebUser(u);
|
|
|
|
+ session.saveWebUser(wu);
|
|
|
|
+ sessionService.put(request, response, session);
|
|
|
|
+
|
|
|
|
+ return u;
|
|
|
|
+ }
|
|
|
|
+ @ApiOperation(value = "考试选择")
|
|
|
|
+ @RequestMapping(value = "select/exam", method = RequestMethod.POST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public ResultMessage selectExam(HttpServletRequest request, @RequestParam Integer examId) {
|
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
|
+ SessionExamUtils.setExamId(request, exam);
|
|
|
|
+ return resultOk();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "分组选择")
|
|
|
|
+ @RequestMapping(value = "select/group", method = RequestMethod.POST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public ResultMessage select(HttpServletRequest request, HttpServletResponse response, @RequestParam Integer markerId) {
|
|
|
|
+ Marker marker = markerService.findById(markerId);
|
|
|
|
+ if (marker == null) {
|
|
|
|
+ throw new StatusException("评卷分组不存在");
|
|
|
|
+ }
|
|
|
|
+ Exam exam = examService.findById(marker.getExamId());
|
|
|
|
+ Date now = new Date();
|
|
|
|
+ if ((exam.getStartTime() != null && now.before(exam.getStartTime()))
|
|
|
|
+ || (exam.getEndTime() != null && now.after(exam.getEndTime()))) {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String start = exam.getStartTime() == null ? "" : " 开始时间:" + sdf.format(exam.getStartTime());
|
|
|
|
+ String end = exam.getEndTime() == null ? "" : " 结束时间:" + sdf.format(exam.getEndTime());
|
|
|
|
+ throw new StatusException("message", "不在评卷时间范围 " + start + " " + end);
|
|
|
|
+ }
|
|
|
|
+ MarkGroup group = groupService.findOne(marker.getExamId(), marker.getSubjectCode(), marker.getGroupNumber());
|
|
|
|
+ if (group == null) {
|
|
|
|
+ throw new StatusException("评卷分组不存在");
|
|
|
|
+ }
|
|
|
|
+ if (group.getStatus() == MarkStatus.FINISH) {
|
|
|
|
+ throw new StatusException("评卷分组已结束");
|
|
|
|
+ }
|
|
|
|
+ WebUser user = RequestUtils.getWebUser(request);
|
|
|
|
+ user.setMarkerId(marker.getId());
|
|
|
|
+ StmmsSession session = RequestUtils.getSession(request);
|
|
|
|
+ session.saveWebUser(user);
|
|
|
|
+ sessionService.put(request, response, session);
|
|
|
|
+ SessionExamUtils.setExamId(request, exam);
|
|
|
|
+ return resultOk();
|
|
|
|
+ }
|
|
}
|
|
}
|