304 lines
9.2 KiB
Plaintext
304 lines
9.2 KiB
Plaintext
package com.bonus.sys.controller;
|
|
|
|
import java.sql.CallableStatement;
|
|
import java.sql.Connection;
|
|
import java.sql.SQLException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.session.Session;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import com.bonus.core.DBUtils;
|
|
import com.bonus.grade.beans.gradeBean;
|
|
import com.bonus.grade.service.gradeService;
|
|
import com.bonus.question.service.QuestionService;
|
|
import com.bonus.registration.beans.RegistrationBean;
|
|
import com.bonus.registration.service.RegistrationService;
|
|
import com.bonus.sys.AjaxRes;
|
|
import com.bonus.sys.BaseController;
|
|
import com.bonus.sys.GlobalConst;
|
|
import com.bonus.sys.MenuTreeHelper;
|
|
import com.bonus.sys.PageData;
|
|
import com.bonus.sys.UserShiroHelper;
|
|
import com.bonus.sys.beans.ResourcesBean;
|
|
import com.bonus.sys.beans.RoleResBean;
|
|
import com.bonus.sys.beans.UserBean;
|
|
import com.bonus.sys.beans.ZNode;
|
|
import com.bonus.sys.service.ResourcesService;
|
|
import com.bonus.sys.service.UserService;
|
|
|
|
@Controller
|
|
@RequestMapping("/backstage/")
|
|
public class BackstageController extends BaseController<Object> {
|
|
|
|
@Autowired
|
|
public ResourcesService menuService;
|
|
|
|
@Autowired
|
|
public gradeService gradeService;
|
|
|
|
@Autowired
|
|
private QuestionService questionService;
|
|
|
|
@Autowired
|
|
RegistrationService regiservice;
|
|
|
|
@Autowired
|
|
UserService userService;
|
|
|
|
|
|
//index 界面显示考试注意事项界面
|
|
@RequestMapping("TestRemind")
|
|
public String toTestRemind(Model model) {
|
|
return "/sys/TestRemind";
|
|
}
|
|
|
|
/**
|
|
* 访问系统首页
|
|
*/
|
|
@RequestMapping("index")
|
|
public String index(Model model) {
|
|
// shiro获取用户信息
|
|
UserBean currentAccount = UserShiroHelper.getCurrentUser();
|
|
model.addAttribute("currentAccount", currentAccount);
|
|
return "/sys/index";
|
|
}
|
|
|
|
@RequestMapping("waitExamPage")
|
|
public String toExam(Model model) {
|
|
// shiro获取用户信息
|
|
UserBean currentAccount = UserShiroHelper.getCurrentUser();
|
|
model.addAttribute("currentAccount", currentAccount);
|
|
gradeBean o = new gradeBean();
|
|
o.setUser(currentAccount);
|
|
Integer diff = 0;
|
|
//去查询是否报名
|
|
RegistrationBean bean=regiservice.findByidcard(currentAccount.getLoginName());
|
|
if(bean != null) {
|
|
o.setExamPerfession(bean.getSpecialty());
|
|
o.setExamCount(bean.getTimes());
|
|
o = gradeService.findExamPage(o);
|
|
if(o !=null && o.getIsActive().equals("1")) {
|
|
try {
|
|
o.setExamPerfession(bean.getSpecialty());
|
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
String startTime = o.getStartTime();
|
|
long start = fmt.parse(startTime).getTime();
|
|
String processTime = o.getExamTime(); //考试时长
|
|
String endTime=o.getEndTime();
|
|
long end = fmt.parse(endTime).getTime();
|
|
Date date = new Date();
|
|
long nowTime = date.getTime();
|
|
if(nowTime < start) {
|
|
diff = -1;//未到考试时间
|
|
}else if(start <= nowTime && nowTime <= end) {
|
|
//现在的时间不能超过开始的时间15分钟
|
|
long team=nowTime-start;
|
|
long hour = team/(60*60*1000);
|
|
long minute = (team - hour*60*60*1000)/(60*1000);
|
|
if(minute >15.0) {
|
|
diff = 1;//超过考试时间
|
|
long shteam=end-nowTime;
|
|
long shhour = shteam/(60*60*1000);
|
|
long shminute = (shteam - shhour*60*60*1000)/(60*1000);
|
|
o.setKstime(shteam);
|
|
diff = 1;//超过考试时间
|
|
}else {
|
|
long shteam=end-nowTime;
|
|
long days = shteam / (1000 * 60 * 60 * 24);
|
|
long hours = (shteam-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
|
|
long minutes = (shteam-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
|
|
System.out.println(""+days+"天"+hours+"小时"+minutes+"分");
|
|
o.setKstime(shteam);
|
|
diff = 0;//在考试时间中
|
|
}
|
|
}else {
|
|
diff = 1;//超过考试时间
|
|
}
|
|
} catch (ParseException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}else {
|
|
diff = 5;
|
|
}
|
|
|
|
}else {
|
|
diff = 4;//还没有报名
|
|
}
|
|
model.addAttribute("page", o);
|
|
model.addAttribute("diff", diff);
|
|
return "/sys/waitExamPage";
|
|
}
|
|
|
|
@RequestMapping("selfExamPage")
|
|
public String toSelfExamPage(Model model) {
|
|
// shiro获取用户信息
|
|
UserBean currentAccount = UserShiroHelper.getCurrentUser();
|
|
|
|
model.addAttribute("currentAccount", currentAccount);
|
|
return "/sys/selfExamPage";
|
|
}
|
|
|
|
@RequestMapping(value = "getOrgTreeList", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes getOrgTreeList(UserBean o) {
|
|
AjaxRes ar = getAjaxRes();
|
|
try {
|
|
List<ZNode> list = userService.getOrgTreeList( o);
|
|
ar.setSucceed(list);
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setFailMsg(GlobalConst.DATA_FAIL);
|
|
}
|
|
return ar;
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@RequestMapping(value = "menu/getMenu", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes getMenu() {
|
|
AjaxRes ar = getAjaxRes();
|
|
List<ResourcesBean> menus = new ArrayList<ResourcesBean>();
|
|
PageData pd = this.getPageData();
|
|
String ref = pd.getString("ref");
|
|
String layer = pd.getString("layer");
|
|
Object menu_o = null;
|
|
try {
|
|
// shiro获取用户信息,shiro管理的session
|
|
Session session = SecurityUtils.getSubject().getSession();
|
|
// 获得用户
|
|
UserBean acount = (UserBean) session
|
|
.getAttribute(GlobalConst.SESSION_USER);
|
|
// 获得用户Id
|
|
int userId = acount.getId();
|
|
logger.debug("userId=" + userId);
|
|
if (!"y".equals(ref)) {
|
|
menu_o = session.getAttribute(GlobalConst.SESSION_MENULIST);
|
|
logger.debug("menu_o=" + menu_o);
|
|
}
|
|
menus = (List<ResourcesBean>) menu_o;
|
|
if (menus == null) {
|
|
if (StringUtils.isBlank(layer)){
|
|
layer = "1";
|
|
}
|
|
menus = menuService.findMenuTree(userId, layer);
|
|
session.setAttribute(GlobalConst.SESSION_MENULIST, menus);
|
|
}
|
|
if (menus != null) {
|
|
// 将对象处理成树
|
|
String html = MenuTreeHelper.buildTreeHtml(menus);
|
|
ar.setSucceed(html);
|
|
}
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setFailMsg("获取菜单失败");
|
|
}
|
|
logger.info("ar=" + ar);
|
|
return ar;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@RequestMapping(value = "menu/getUnread", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes getUnreadInfo() {
|
|
AjaxRes ar = getAjaxRes();
|
|
try {
|
|
Session session = SecurityUtils.getSubject().getSession();
|
|
UserBean acount = (UserBean) session
|
|
.getAttribute(GlobalConst.SESSION_USER);
|
|
int userId = acount.getId();
|
|
|
|
RoleResBean rrb = new RoleResBean();
|
|
rrb.setRoleId(userId);
|
|
|
|
RoleResBean[] list = menuService.getUnreadInfo(rrb);
|
|
|
|
ar.setObj(list);
|
|
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setFailMsg("获取unReadInfo失败");
|
|
}
|
|
return ar;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@RequestMapping(value = "menu/clearUnreadFlag", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes clearAndReflushUnreadFlag(@RequestBody RoleResBean o) {
|
|
AjaxRes ar = getAjaxRes();
|
|
try {
|
|
Session session = SecurityUtils.getSubject().getSession();
|
|
UserBean acount = (UserBean) session
|
|
.getAttribute(GlobalConst.SESSION_USER);
|
|
int userId = acount.getId();
|
|
|
|
Connection conn = null;
|
|
CallableStatement cs = null;
|
|
try {
|
|
conn = DBUtils.getConn();
|
|
String sql = "{CALL clear_unread_flag(?,?)}";
|
|
cs = conn.prepareCall(sql);
|
|
cs.setInt(1,userId);
|
|
cs.setInt(2,o.getResId());
|
|
cs.execute();
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}finally {
|
|
DBUtils.close(conn, cs, null);
|
|
}
|
|
o.setRoleId(userId);
|
|
RoleResBean[] list = menuService.getUnreadInfo(o);
|
|
ar.setObj(list);
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setFailMsg("获取unReadInfo失败");
|
|
}
|
|
return ar;
|
|
}
|
|
public static void main(String[] args) {
|
|
Date date = new Date();
|
|
long nowTime = date.getTime();
|
|
System.out.println("long"+nowTime);
|
|
String longToDate = longToDate(nowTime);
|
|
System.out.println(longToDate);
|
|
|
|
}
|
|
/**
|
|
* 时间转化long
|
|
* @param lo
|
|
* @return
|
|
*/
|
|
public static String longToDate(long lo){
|
|
Date date = new Date(lo);
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
return sd.format(date);
|
|
}
|
|
/**
|
|
* long 转化时间
|
|
*/
|
|
public static String stringToDate(String lo){
|
|
long time = Long.parseLong(lo);
|
|
Date date = new Date(time);
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
return sd.format(date);
|
|
}
|
|
}
|
|
|
|
|
|
|