package com.qxueyou.scc.controller;
|
|
import com.qxueyou.scc.admin.examroom.model.ExamRoom;
|
import com.qxueyou.scc.admin.examroom.service.IExamRoomService;
|
import com.qxueyou.scc.base.dao.CommonDAO;
|
import com.qxueyou.scc.base.model.Pager;
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.QBeanUtils;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
import java.util.Map;
|
|
@Api(tags = "考场管理")
|
@RestController
|
@RequestMapping(value = "admin/examroom")
|
public class ExamRoomController {
|
//日志
|
private final Logger log = LogManager.getLogger(ExamRoomController.class);
|
|
// 分页查询中,默认记录条数和页数
|
private static final int DEFAULT_PAGE_SIZE = 10;
|
private static final int DEFAULT_PAGE_NUM = 1;
|
|
@Autowired
|
private IExamRoomService examRoomService;
|
|
@Autowired
|
private CommonDAO commonDAO;
|
|
/**
|
* 考场列表
|
*/
|
@ApiOperation(value = "获取考场列表")
|
@RequestMapping(value = "list", method = RequestMethod.GET)
|
public @ResponseBody Result list(String roomId,String keyword,Short status,Integer pageSize,Integer pageNum) {
|
pageSize = pageSize != null && pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
|
pageNum = pageNum != null && pageNum > 0 ? pageNum : DEFAULT_PAGE_NUM;
|
|
//总考试数量
|
int totalCount = examRoomService.listCount(roomId,keyword, status);
|
Pager pager = new Pager(pageSize,pageNum);
|
pager.setTotalCount(totalCount);
|
|
List<ExamRoom> list = examRoomService.list(roomId,keyword == null ? "" : keyword.trim(),status,pageSize,pageNum);
|
|
List<Map<String, Object>> listResult =QBeanUtils.listBean2ListMap(list,
|
CollectionUtils.newStringMap("examroomId", "examroomId", "examroomName", "examroomName",
|
"status","status","creator", "creator", "updateTime", "updateTime","seatsNum","seatsNum"));
|
|
return new Result(true,"",CollectionUtils.newObjectMap("examRoomList",listResult,"page",pager));
|
}
|
|
/**
|
* 保存
|
*
|
* @param examRoom
|
* @return
|
*/
|
@ApiOperation(value = "保存考场")
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
public @ResponseBody Result save(@RequestBody ExamRoom examRoom) {
|
|
|
if (StringUtils.isEmpty(examRoom.getExamroomId())) {
|
if(checkIsDumplicate(examRoom.getExamroomId(),examRoom.getExamroomName())){
|
return new Result(false, "添加失败!重复的考场信息");
|
}
|
return new Result(true,"",CollectionUtils.newObjectMap("examroomId", examRoomService.add(examRoom)));
|
} else {
|
return examRoomService.update(examRoom);
|
}
|
}
|
|
|
private boolean checkIsDumplicate(String roomId,String name){
|
|
if(StringUtils.isEmpty(name)){
|
return false;
|
}
|
|
StringBuffer hql = new StringBuffer(500);
|
hql.append("from ExamRoom r where r.examroomName=? ");
|
List<Object> args = CollectionUtils.newList(name);
|
|
if(StringUtils.isNotEmpty(roomId)){
|
hql.append(" and examroomId!=?");
|
args.add(roomId);
|
}
|
|
hql.append(" and r.deleteFlag is false");
|
|
int count = commonDAO.findCount(hql.toString(), args);
|
|
return count>0;
|
}
|
|
|
|
/**
|
* 删除
|
*
|
* @param examroomIds
|
* @return
|
*/
|
@ApiOperation(value = "删除考场", httpMethod = "GET")
|
@ApiImplicitParam(name = "examroomIds", value = "考场ID字符串", required = true, dataType = "String", paramType = "body")
|
@RequestMapping(value = "delete", method = RequestMethod.GET)
|
public @ResponseBody Result delete(String examroomIds) {
|
Result result = new Result(true);
|
if (StringUtils.isNotEmpty(examroomIds)) {
|
result = examRoomService.delete(examroomIds.split(","));
|
}
|
return result;
|
}
|
|
/**
|
* 发布考场
|
*
|
* @param roomIds
|
* @return
|
*/
|
@ApiOperation(value = "发布考场", httpMethod = "GET")
|
@RequestMapping(value = "/publish", method = RequestMethod.GET)
|
public @ResponseBody Result publish(String roomIds) {
|
if (StringUtils.isEmpty(roomIds)) {
|
return new Result(false, "参数错误");
|
}
|
|
return this.examRoomService.doRelease(roomIds.split(","));
|
}
|
|
/**
|
* 撤回发布的考场
|
*
|
* @param roomIds
|
* @return
|
*/
|
@ApiOperation(value = "撤回考场", httpMethod = "GET")
|
@RequestMapping(value = "/cancel", method = RequestMethod.GET)
|
public @ResponseBody Result cancel(String roomIds) {
|
if (StringUtils.isEmpty(roomIds)) {
|
return new Result(false, "参数错误");
|
}
|
|
return this.examRoomService.doCancel(roomIds.split(","));
|
}
|
|
|
/**
|
* 详情页面数据
|
*
|
* @param examroomId
|
* @return
|
*/
|
@ApiOperation(value = "详情页面数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name="roomId", dataType="String", paramType="query", value="考场ID", required=true),
|
})
|
@RequestMapping(value = "/detail", method = RequestMethod.GET)
|
public @ResponseBody Result detail(String examroomId) {
|
return new Result(true,"",CollectionUtils.newObjectMap("detail",this.examRoomService.detail(examroomId)));
|
}
|
|
/**
|
* 查询所有考场的ID和名称
|
* @return
|
*/
|
@ApiOperation(value = "可选择考场ID和名称")
|
@RequestMapping(value = "/allExamRoomIdAndNames", method = RequestMethod.GET)
|
public @ResponseBody Result listClassRoomIdAndNames() {
|
List<Map<String,Object>> listResult = this.examRoomService.queryAllRoomIdAndNames();
|
return new Result(true,"",CollectionUtils.newObjectMap("listExamRooms",listResult));
|
}
|
|
|
}
|