package com.shlanbao.tzsc.pms.sys.user.controller;
|
|
import java.text.ParseException;
|
import java.util.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpSession;
|
|
import com.shlanbao.tzsc.base.mapping.MdEquipment;
|
import com.shlanbao.tzsc.init.BaseParams;
|
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.ResponseBody;
|
import com.alibaba.fastjson.JSON;
|
import com.shlanbao.tzsc.base.controller.BaseController;
|
import com.shlanbao.tzsc.base.dao.SchStatFaultDaoI;
|
import com.shlanbao.tzsc.base.dao.SysUserDaoI;
|
import com.shlanbao.tzsc.base.mapping.SchStatFault;
|
import com.shlanbao.tzsc.base.mapping.SysModelPermis;
|
import com.shlanbao.tzsc.base.model.DataGrid;
|
import com.shlanbao.tzsc.base.model.Json;
|
import com.shlanbao.tzsc.base.model.PageParams;
|
import com.shlanbao.tzsc.base.model.SessionInfo;
|
import com.shlanbao.tzsc.base.model.Tree;
|
import com.shlanbao.tzsc.pms.md.fixCode.beans.FixCodeBean;
|
import com.shlanbao.tzsc.pms.md.fixCode.service.FixCodeServiceI;
|
import com.shlanbao.tzsc.pms.qm.check.service.impl.QmCheckMassServiceImpl;
|
import com.shlanbao.tzsc.pms.qm.onlineCheck.bean.QMOnlineCheckBean;
|
import com.shlanbao.tzsc.pms.qm.onlineCheck.service.QMOnlineCheckService;
|
import com.shlanbao.tzsc.pms.qm.onlineCheck.service.impl.QmOnlineCheckServiceImpl;
|
import com.shlanbao.tzsc.pms.sys.org.service.OrgServiceI;
|
import com.shlanbao.tzsc.pms.sys.resource.service.ResourceServiceI;
|
import com.shlanbao.tzsc.pms.sys.role.beans.RoleBean;
|
import com.shlanbao.tzsc.pms.sys.role.service.RoleServiceI;
|
import com.shlanbao.tzsc.pms.sys.user.beans.UserBean;
|
import com.shlanbao.tzsc.pms.sys.user.service.ModelPermisServiceI;
|
import com.shlanbao.tzsc.pms.sys.user.service.UserServiceI;
|
import com.shlanbao.tzsc.pms.sys.user.service.schStatFaultServiceI;
|
import com.shlanbao.tzsc.utils.tools.MD5Util;
|
import com.shlanbao.tzsc.utils.tools.WebContextUtil;
|
|
import net.sf.json.JSONArray;
|
/**
|
* 用户管理控制器
|
* <li>@author Leejean
|
* <li>@create 2014-6-27下午02:56:31
|
*/
|
@Controller
|
@RequestMapping("/pms/sysUser")
|
public class UserController extends BaseController{
|
private static final ResourceBundle bundle = ResourceBundle.getBundle("config");
|
@Autowired
|
private UserServiceI userService;
|
@Autowired
|
private OrgServiceI orgService;
|
@Autowired
|
private ResourceServiceI resourceService;
|
@Autowired
|
private RoleServiceI roleService;
|
|
@Autowired
|
private ModelPermisServiceI modelService;
|
|
@Autowired
|
private QMOnlineCheckService service;
|
|
@Autowired
|
private FixCodeServiceI fixService;
|
@Autowired
|
private schStatFaultServiceI schService;
|
|
/**
|
* 首页
|
* @author Leejean
|
* @create 2014-8-14下午07:03:44
|
* @return
|
*/
|
@RequestMapping("/index")
|
public String index(HttpServletRequest request){
|
try {
|
String pms_websocket = bundle.getString("pms_websocket");
|
String wct_websocket = bundle.getString("wct_websocket");
|
if(pms_websocket!=null){
|
request.setAttribute("pms_websocket",pms_websocket);
|
}
|
if(wct_websocket!=null){
|
request.setAttribute("wct_websocket",wct_websocket);
|
}
|
|
return "/pms/index";
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return "/error/noResource";
|
}
|
/**
|
* 退出
|
* @author Leejean
|
* @create 2014-8-14下午07:03:44
|
* @return
|
*/
|
@RequestMapping("/exit")
|
public String exit(HttpSession session){
|
try {
|
session.invalidate();
|
return "/pms/sys/user/login";
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return "/error/noResource";
|
}
|
/**
|
* 用户登录
|
* @author Leejean
|
* @create 2014-6-27下午03:00:36
|
*/
|
@ResponseBody
|
@RequestMapping("/login")
|
public Json login(UserBean userBean,HttpSession session,HttpServletRequest request){
|
Json json=new Json();
|
try {
|
userBean=userService.login(userBean);
|
if(userBean!=null){
|
String uid=userBean.getId();
|
json.setMsg("登录成功!");
|
json.setSuccess(true);
|
|
SessionInfo sessionInfo=new SessionInfo();
|
sessionInfo.setUser(userBean);
|
sessionInfo.setIp(WebContextUtil.getRemoteIp(request));
|
//得到用户的机构
|
List<Tree> organizations=orgService.getOrgsByUser(userBean.getId());
|
sessionInfo.setOrganizations(JSON.toJSONString(organizations));
|
|
//得到用户的角色
|
List<RoleBean> roles=roleService.getRolesByUser(uid);
|
sessionInfo.setRoles(roles);
|
|
//得到用户的权限(显示成树,拥有的权限才会checked=true)
|
List<Tree> resources = resourceService.getResByUser(uid);
|
sessionInfo.setResources(JSON.toJSONString(resources));
|
|
Map<String,String> resourcesMap = new HashMap<String,String>();
|
for (Tree tree : resources) {
|
if(tree.isChecked()){
|
if(tree.getAttributes()!=null){
|
resourcesMap.put(tree.getAttributes().toString(),tree.getText() );
|
}
|
|
}
|
}
|
sessionInfo.setResourcesMap(resourcesMap);
|
|
WebContextUtil.saveObjToSession(session,"sessionInfo", sessionInfo,60*60*8);//保存8小时
|
List <SysModelPermis> list = modelService.getDefaultSysModel(userBean.getId(), roles.get(0).getId());
|
FixCodeBean fcb = new FixCodeBean();
|
fcb.setUpcode("SYZSMK001");
|
List<FixCodeBean> fixList = fixService.queryFixCode(fcb);
|
if(list.size()<=0)
|
{
|
if(fixList.size()>0){
|
for(int i=0;i<fixList.size();i++){
|
fcb = (FixCodeBean)fixList.get(i);
|
if("YZSMK0001001".equals(fcb.getType())){
|
SysModelPermis sp = new SysModelPermis();
|
sp.setRoleId(roles.get(0).getId());
|
sp.setUserId(userBean.getId());
|
sp.setMdFixCodeId(fcb.getId());
|
sp.setCreateTime(new Date());
|
sp.setRemark("默认添加");
|
modelService.insertDefaultSysModel(sp);
|
}
|
}
|
}
|
|
|
}
|
request.setAttribute("sysModelList", list);
|
request.setAttribute("fixList", fixList);
|
}else{
|
json.setMsg("账号密码错误或该用户已被禁用,请重新登录!");
|
}
|
} catch (Exception e) {
|
log.error("用户登录", e);
|
}
|
return json;
|
}
|
|
/**
|
* 锁定用户登录
|
* @author Leejean
|
* @create 2014-7-10下午01:47:16
|
*/
|
@ResponseBody
|
@RequestMapping("/lockUser")
|
public void lockUser(HttpSession session){
|
try {
|
SessionInfo sessionInfo=(SessionInfo)session.getAttribute("sessionInfo");
|
sessionInfo.setIslock(true);
|
} catch (Exception e) {
|
log.error("锁定用户登录", e);
|
}
|
}
|
/**
|
* 用户登录解锁
|
* @author Leejean
|
* @create 2014-7-10下午02:06:47
|
*/
|
@ResponseBody
|
@RequestMapping("/breakLock")
|
public Json breakLock(UserBean userBean,HttpSession session){
|
Json json=new Json();
|
try {
|
SessionInfo sessionInfo=(SessionInfo)session.getAttribute("sessionInfo");
|
if(sessionInfo.getUser().getPwd().equals(MD5Util.SHA256(userBean.getPwd()))){
|
sessionInfo.setIslock(false);
|
json.setMsg("解锁成功");
|
json.setSuccess(true);
|
}else{
|
json.setMsg("密码错误");
|
}
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return json;
|
}
|
/**
|
* 修改密码
|
* @author Leejean
|
* @create 2014-7-10下午02:16:36
|
*/
|
@ResponseBody
|
@RequestMapping("/editPwd")
|
public Json editPwd(UserBean userBean,HttpSession session){
|
Json json=new Json();
|
try {
|
SessionInfo sessionInfo=(SessionInfo)session.getAttribute("sessionInfo");
|
UserBean user=sessionInfo.getUser();
|
if(user.getPwd().equals(MD5Util.SHA256(userBean.getOldpwd()))){
|
userService.editPwd(user.getId(),userBean.getPwd());
|
json.setMsg("修改成功");
|
user.setPwd(MD5Util.SHA256(userBean.getPwd()));
|
json.setSuccess(true);
|
}else{
|
json.setMsg("输入的原始密码错误");
|
}
|
} catch (Exception e) {
|
log.error("修改密码异常", e);
|
}
|
return json;
|
}
|
/**
|
* 查询系统用户
|
*/
|
@ResponseBody
|
@RequestMapping("/getAllUser")
|
public DataGrid getAllUser(UserBean userBean,PageParams pageParams){
|
try {
|
return userService.querySysUser(userBean,pageParams);
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return null;
|
}
|
@RequestMapping("/goToUserAddJsp")
|
public String goToAddUserJsp(){
|
return "/pms/sys/user/userAdd";
|
}
|
/**
|
* 新建用户
|
*/
|
@ResponseBody
|
@RequestMapping("/addSysUser")
|
public Json addSysUser(UserBean userBean){
|
Json json=new Json();
|
try {
|
userService.addSysUser(userBean);
|
json.setMsg("新增用户成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("新增用户失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 编辑用户
|
*/
|
@ResponseBody
|
@RequestMapping("/editSysUser")
|
public Json editSysUser(UserBean userBean){
|
Json json=new Json();
|
try {
|
userService.editSysUser(userBean);
|
json.setMsg("编辑用户成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("编辑用户失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 删除用户
|
*/
|
@ResponseBody
|
@RequestMapping("/deleteSysUser")
|
public Json deleteSysUser(String id){
|
Json json=new Json();
|
try {
|
userService.deleteSysUser(id);
|
json.setMsg("删除用户成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("删除用户失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 批量删除用户
|
*/
|
@ResponseBody
|
@RequestMapping("/batchDeleteSysUser")
|
public Json batchDeleteSysUser(String ids){
|
Json json=new Json();
|
try {
|
userService.batchDeleteSysUser(ids);
|
json.setMsg("批量删除用户成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("批量删除用户失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 跳转到用户编辑页面
|
* @author Leejean
|
* @create 2014-8-14下午07:03:44
|
* @return
|
*/
|
@RequestMapping("/goToUserEditJsp")
|
public String goToUserEditJsp(String id,HttpServletRequest request){
|
try {
|
request.setAttribute("checkedUser", userService.getSysUserById(id));
|
} catch (Exception e) {
|
log.error("跳转到用户编辑页面失败", e);
|
}
|
return "/pms/sys/user/userEdit";
|
}
|
/**
|
* 重置密码
|
* @author Leejean
|
* @create 2014-8-18下午08:36:38
|
* @param id 用户id
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/resetPwd")
|
public Json resetPwd(String id){
|
Json json=new Json();
|
try {
|
userService.editSysUser(new UserBean(id,MD5Util.SHA256("123456")));
|
json.setMsg("重置密码为:123456,为了账户安全,请尽早修改密码!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("批量删除用户失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 重置密码
|
* @author Leejean
|
* @create 2014-8-18下午08:36:38
|
* @param id 用户id
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/enableOrUnenableSysUser")
|
public Json enableOrUnenableSysUser(UserBean userBean){
|
Json json=new Json();
|
try {
|
userService.editSysUser(userBean);
|
json.setMsg("操作成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("操作失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/*****************用户-角色******************/
|
/**
|
* 跳转到用户角色分配页面
|
* @author Leejean
|
* @create 2014-8-18下午09:51:14
|
* @param id
|
* @param request
|
* @return
|
*/
|
@RequestMapping("/goToUserAssignRoleJsp")
|
public String goToUserAssignRoleJsp(String id,String name,HttpServletRequest request){
|
try {
|
request.setCharacterEncoding("utf-8");
|
request.setAttribute("checkedUserId", id);
|
request.setAttribute("checkedUserName",name);
|
} catch (Exception e) {
|
log.error("跳转到用户角色分配页面失败", e);
|
}
|
return "/pms/sys/user/assignRole";
|
}
|
/**
|
* 给用户分配角色
|
* @author Leejean
|
* @create 2014-8-19下午03:28:55
|
* @param id 用户id
|
* @param ids 授权角色Ids
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/assignRole")
|
public Json assignRole(String id,String ids){
|
Json json=new Json();
|
try {
|
roleService.assignRole(id,ids);
|
json.setMsg("角色分配成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("操作分配失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 获得用户角色
|
* @author Leejean
|
* @create 2014-8-18下午08:36:38
|
* @param id 用户id
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/getRolesByUser")
|
public List<RoleBean> getRolesByUser(String id){
|
try {
|
return roleService.getRolesByUser(id);
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return null;
|
}
|
/**
|
* 跳转到用户批量角色分配页面
|
* @author Leejean
|
* @create 2014-8-18下午09:51:14
|
* @param id
|
* @param request
|
* @return
|
*/
|
@RequestMapping("/goToUserBatchAssignRoleJsp")
|
public String goToUserBatchAssignRoleJsp(String ids,String names,HttpServletRequest request){
|
try {
|
request.setAttribute("checkedUserIds", ids);
|
request.setAttribute("checkedUserNames",names);
|
} catch (Exception e) {
|
log.error("跳转到用户角色分配页面失败", e);
|
}
|
return "/pms/sys/user/batchAssignRole";
|
}
|
/**
|
* 用户角色批量分配
|
* @author Leejean
|
* @create 2014-8-19下午07:22:22
|
* @param uids 用户ids
|
* @param rids 角色ids
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/batchAssignRole")
|
public Json batchAssignRole(String uids,String rids){
|
Json json=new Json();
|
try {
|
roleService.batchAssignRole(uids,rids);
|
json.setMsg("用户角色批量分配成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("用户角色批量分配失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/*****************用户-机构******************/
|
/**
|
* 跳转到用户组织机构分配页面
|
* @author Leejean
|
* @create 2014-8-18下午09:50:25
|
* @param id
|
* @param request
|
* @return
|
*/
|
@RequestMapping("/goToUserAssignOrgJsp")
|
public String goToUserAssignOrgJsp(String id,HttpServletRequest request){
|
try {
|
request.setAttribute("checkedUserId", id);
|
} catch (Exception e) {
|
log.error("跳转到用户组织机构分配页面失败", e);
|
}
|
return "/pms/sys/user/assignOrg";
|
}
|
/**
|
* 获得用户的机构
|
* @author Leejean
|
* @create 2014-8-18下午08:36:38
|
* @param id 用户id
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/getOrgsByUser")
|
public List<Tree> getOrgsByUser(String id){
|
try {
|
return orgService.getOrgsByUser(id);
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return null;
|
}
|
|
/**
|
* 给用户分配组织机构
|
* @author Leejean
|
* @create 2014-8-20上午09:27:20
|
* @param id 用户id
|
* @param ids 组织机构id
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/assignOrg")
|
public Json assignOrg(String id,String ids){
|
Json json=new Json();
|
try {
|
orgService.assignOrg(id,ids);
|
json.setMsg("分配组织机构成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("分配组织机构失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
/**
|
* 跳转到用户组织机构批量分配页面
|
* @author Leejean
|
* @create 2014-8-18下午09:50:25
|
* @param id
|
* @param request
|
* @return
|
*/
|
@RequestMapping("/goToUserBatchAssignOrgJsp")
|
public String goToUserBatchAssignOrgJsp(String id,HttpServletRequest request){
|
try {
|
//request.setAttribute("checkedUserId", id);
|
} catch (Exception e) {
|
log.error("跳转到用户组织机构批量分配页面", e);
|
}
|
return "/pms/sys/user/batchAssignOrg";
|
}
|
/**
|
* 用户组织机构批量分配
|
* @author Leejean
|
* @create 2014-8-19下午07:22:22
|
* @param uids 用户ids
|
* @param oids 角色ids
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/batchAssignOrg")
|
public Json batchAssignOrg(String uids,String oids){
|
Json json=new Json();
|
try {
|
orgService.batchAssignOrg(uids,oids);
|
json.setMsg("用户组织机构批量分配成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("用户组织机构分配失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
|
/**
|
* 跳转到统计图编辑页面
|
* @author Rengj
|
* @create 2016-12-23下午13:50:25
|
* @param id
|
* @param request
|
* @return
|
*/
|
@RequestMapping("/goToUserModelJsp")
|
public String goToUserModelJsp(HttpServletRequest request){
|
List list= service.getProdJson();
|
request.setAttribute("Json", JSONArray.fromObject(list));
|
return "/pms/sys/user/model/modelEdit";
|
}
|
|
/**
|
* 跳转到统计图编辑页面
|
* @author Rengj
|
* @create 2016-12-23下午13:50:25
|
* @param id
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/updateModelPremis")
|
public Json updateModelPremis(String mdFixCodeId,String remark,HttpSession session){
|
Json json=new Json();
|
//得到用户的角色
|
SessionInfo sessionInfo = (SessionInfo) session.getAttribute("sessionInfo");
|
String[] ids = mdFixCodeId.split(",");
|
String[] param = remark.split(",");
|
try {
|
for(int i=0;i<ids.length;i++){
|
List<SysModelPermis> sysModelList = modelService.getSysModel(sessionInfo.getUser().getId(),sessionInfo.getRoles().get(0).getId(), ids[i]);
|
if(sysModelList.size()>0 && "del".equals(param[i])){
|
for(int j = 0;j<sysModelList.size();j++ ){
|
SysModelPermis sp = (SysModelPermis)sysModelList.get(j);
|
modelService.deleteSysModel(sp.getId());
|
}
|
}else if(sysModelList.size()<=0 && "save".equals(param[i])){
|
SysModelPermis smp =new SysModelPermis();
|
smp.setUserId(sessionInfo.getUser().getId());
|
smp.setRoleId(sessionInfo.getRoles().get(0).getId());
|
smp.setMdFixCodeId(ids[i]);
|
smp.setCreateTime(new Date());
|
smp.setRemark("界面添加");
|
modelService.insertDefaultSysModel(smp);
|
}
|
}
|
json.setMsg("首页统计显示维护成功!");
|
json.setSuccess(true);
|
} catch (Exception e) {
|
log.error(message, e);
|
json.setMsg("首页统计显示维护失败!");
|
json.setSuccess(false);
|
}
|
return json;
|
}
|
|
|
/**
|
* 首页统计显示权限
|
* @author Rengj
|
* @create 2016-12-26上午9:50:25
|
* @param id
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/getModel")
|
public String getModelPremis(HttpSession session,HttpServletRequest request){
|
List list =new ArrayList();
|
try {
|
FixCodeBean fcb = new FixCodeBean();
|
fcb.setUpcode("SYZSMK001");
|
List<FixCodeBean> fixList = fixService.queryFixCode(fcb);
|
//得到用户的角色
|
SessionInfo sessionInfo = (SessionInfo) session.getAttribute("sessionInfo");
|
List <SysModelPermis> sysModellist = modelService.getDefaultSysModel(sessionInfo.getUser().getId(),sessionInfo.getRoles().get(0).getId());
|
String param = request.getParameter("param");
|
for(int j=0; j<fixList.size();j++){
|
fcb = (FixCodeBean) fixList.get(j);
|
if(!"edit".equals(param)){
|
for(int i=0;i<sysModellist.size();i++){
|
SysModelPermis smp = (SysModelPermis)sysModellist.get(i);
|
if(smp.getMdFixCodeId().equals(fcb.getId())){
|
list.add(fcb);
|
}
|
}
|
}else{
|
list.add(fcb);
|
}
|
}
|
|
} catch (Exception e) {
|
log.error(message, e);
|
}
|
return JSON.toJSONString(list);
|
}
|
/**
|
* 生产实绩故障数据统
|
* @author Rengj
|
* @create 2016-12-26下午12:42:22
|
* @return string
|
*/
|
@ResponseBody
|
@RequestMapping("/getSchStatfaultJson")
|
public String getJson() throws Exception{
|
List<?> list= schService.getSchStatFault();
|
List<SchStatFault> schStatlist = new ArrayList<SchStatFault>();
|
for(int i=0;i<list.size();i++){
|
Object[] o = (Object[]) list.get(i);
|
SchStatFault sf =new SchStatFault();
|
sf.setName(o[0].toString());
|
sf.setTime(Double.parseDouble(o[1].toString()));
|
sf.setTimes(Long.parseLong(o[2].toString()));
|
sf.setFlag(Long.parseLong(o[3].toString()));
|
schStatlist.add(sf);
|
}
|
return JSON.toJSONString(schStatlist);
|
}
|
}
|