package com.manage.controller; import com.alibaba.fastjson.JSON; import com.manage.dao.Power_Login_SetMapper; import com.manage.encrypt.Base64; import com.manage.encrypt.MD5; import com.manage.entity.*; import com.manage.service.*; import com.manage.service.cache.Cache; import com.manage.service.cache.CacheManager; import com.manage.util.*; import com.manage.vo.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; @Controller public class LoginController { @Value("${TOKEN_EXPIRE_TIME}") private long TOKEN_EXPIRE_TIME; @Autowired private Power_UserService powerUserService; @Autowired private Power_MenuService powerMenuService; @Autowired private LogService logService; @Autowired private Power_DeptService power_deptService; @Autowired private Power_Login_SetMapper powerLoginSetMapper; @RequestMapping(value = "login",method = RequestMethod.GET) public String toLogin(Model model){ Power_Login_Set loginSet = powerLoginSetMapper.selectByPrimaryKey(1); model.addAttribute("loginSet",loginSet); CacheManager.addExcCount("noExc"); return "loginDir/login"; } @RequestMapping(value = "login",method = RequestMethod.POST) public String login(Power_User powerUser,HttpServletResponse response, HttpServletRequest request,Model model){ try { Power_UserVo user = powerUserService.findPowerUserByUserNameAndUserPwd(powerUser); //添加进操作日志 Power_Log log = new Power_Log(); if( user != null){ //如处于登录状态,先清除缓存 //CacheManager.removeCacheByObject(user); //记住 MyCookieUtil.remember(request, response); //清除用户登录错误次数缓存 CacheManager.clearOnly(powerUser.getUserName()); //存session密码置空 //是否记住密码功能 MyCookieUtil.remember(request, response); //设置token缓存 String date = String.valueOf(DateUtils.getDate()); String token = Base64.encode(MD5.KL(date)); //查询归属医院 /* long start5 = System.currentTimeMillis(); Power_User_Dict powerUserDict = powerUserDictMapper.selectDictIdByUserId(user.getUserId()); long end5 = System.currentTimeMillis(); System.out.println("查询医院时间="+(end5-start5)/1000.0+"s"); user.setDictId(powerUserDict.getDictId());*/ //科室id科室名 ActionScopeUtils.setSessionAttribute("token",token,Integer.valueOf(String.valueOf(TOKEN_EXPIRE_TIME))/1000); //设置用户登录次数缓存 //CacheManager.addloginUserCount(fmt.format(new Date()),user.getUserName()); CacheManager.addExcCount("noExc"); List list = null; List menuList = new ArrayList<>(); Set menus = new LinkedHashSet<>(); if (user.getRoleId().equals(0) || user.getRoleId().equals(-100)) { list = powerMenuService.queryAllPowerMenu(null,user.getRoleId()); } else { list = powerMenuService.selectUserAndRoleMenuListPower(user.getUserId(),null); } if(null != list && !list.isEmpty()){ for (Power_Menu powerMenu : list) { User_Dept_Menu deptMenu = new User_Dept_Menu(); String menuUrl = powerMenu.getMenuUrl(); if (StringUtils.isNotBlank(menuUrl)) { BeanUtils.copyProperties(powerMenu, deptMenu); deptMenu.setMethodParent(powerMenu.getParentId()); menuList.add(deptMenu); } if (StringUtils.isNotBlank(powerMenu.getMethod())) { menus.add(powerMenu.getMenuUrl()); } } } user.setMenuList(menuList); user.setMenus(menus); //设置科室 StringBuilder powerDepts = new StringBuilder(); List powerDeptsList = power_deptService.selectByPrimaryKeys(user.getDeptId()); for(int j=0;j