New file |
| | |
| | | package com.fgkj.services;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.servlet.ServletContext;
|
| | |
|
| | | import com.fgkj.actions.ActionUtil;
|
| | | import com.fgkj.dao.BaseDAO;
|
| | | import com.fgkj.dao.BaseDAOFactory;
|
| | | import com.fgkj.dao.impl.User_infImpl;
|
| | | import com.fgkj.dto.Page;
|
| | | import com.fgkj.dto.ServiceModel;
|
| | | import com.fgkj.dto.UserClient;
|
| | | import com.fgkj.dto.User_inf;
|
| | |
|
| | | public class User_infService extends ActionUtil {
|
| | | private ServiceModel model;
|
| | | private BaseDAO dao;
|
| | |
|
| | | public User_infService() {
|
| | | model = new ServiceModel();
|
| | | dao = BaseDAOFactory.getBaseDAO(BaseDAO.USER_INF);
|
| | | }
|
| | |
|
| | | //5.1用户管理(添加)
|
| | | public ServiceModel add(Object obj) {
|
| | | int flag=((User_infImpl)dao).addJudge(obj);
|
| | | //System.out.println(flag);
|
| | | if(flag!=0){
|
| | | Boolean bl=dao.add(obj);
|
| | | if(bl){
|
| | | model.setCode(1);
|
| | | model.setMsg("添加成功!");
|
| | | }
|
| | | else{
|
| | | model.setCode(0);
|
| | | model.setMsg("添加失败!");
|
| | | }
|
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("用户名存在,请重新输入!");
|
| | | }
|
| | | return model;
|
| | | }
|
| | |
|
| | | // 5.1用户管理(编辑)
|
| | | public ServiceModel update(Object obj) {
|
| | | Boolean bl = false;
|
| | | bl=dao.update(obj);
|
| | | if(bl){
|
| | | model.setCode(1);
|
| | | model.setMsg("修改成功");
|
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("修改失败");
|
| | | }
|
| | | return model;
|
| | | }
|
| | |
|
| | | // 5.1用户管理(删除)
|
| | | public ServiceModel delete(Object obj) {
|
| | | Boolean bl = dao.del(obj);
|
| | | //System.out.println(obj);
|
| | | if (bl) {
|
| | | model.setCode(1);
|
| | | model.setMsg("删除成功!");
|
| | | } else {
|
| | | model.setMsg("删除失败!");
|
| | | }
|
| | | return model;
|
| | | }
|
| | |
|
| | | public ServiceModel serchByCondition(Object obj) {
|
| | | List list = dao.serchByCondition(obj);
|
| | | /*
|
| | | * for (Object object : list) { System.out.println(object); }
|
| | | */
|
| | |
|
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | | }
|
| | | // System.out.println(model);
|
| | | return model;
|
| | | }
|
| | | //5.1查询所有员工信息
|
| | | public ServiceModel searchAll() {
|
| | | List<User_inf> list = dao.searchAll();
|
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | | }
|
| | | return model;
|
| | | }
|
| | |
|
| | | /*// 根据battgroupid查对应的包机人
|
| | | public ServiceModel searchByBattGroupId(Object obj) {
|
| | | model = new ServiceModel();
|
| | | List<User_inf> list = ((User_infImpl) dao).searchByBattGroupId(obj);
|
| | | // System.out.println(list.size());
|
| | | |
| | | * for(User_inf u:list){ System.out.println(u); }
|
| | | |
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | | // battgroupid对应的所有包机人姓名和id
|
| | | String uStrN = "";
|
| | | String uStrI = "";
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | uStrN += ",";
|
| | | uStrI += ",";
|
| | | uStrN += list.get(i).getUName().toString();
|
| | | uStrI += list.get(i).getUId().toString();
|
| | | }
|
| | | uStrN = uStrN.substring(1, uStrN.length());
|
| | | uStrI = uStrI.substring(1, uStrI.length());
|
| | | model.setMsg(uStrN);
|
| | | model.setMsgO(uStrI);
|
| | | } else {
|
| | | model.setCode(0);
|
| | | }
|
| | | // System.out.println(model.getMsg());
|
| | | // System.out.println(model);
|
| | | return model;
|
| | | }
|
| | | */
|
| | | // 3.1根据uid查用户信息(uname)
|
| | | public ServiceModel serchuName(Object obj) {
|
| | | model = new ServiceModel();
|
| | | List list = ((User_infImpl) dao).serchUname(obj);
|
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | | } else {
|
| | | model.setCode(0);
|
| | | }
|
| | | // System.out.println(model);
|
| | | return model;
|
| | | }
|
| | |
|
| | | /*// 5.1查询员工的所有信息
|
| | | public ServiceModel searchAll(Object obj) {
|
| | | // System.out.println((Batt_User_Permit)obj);
|
| | | model = new ServiceModel();
|
| | | Batt_User_Permit bup = new Batt_User_Permit();
|
| | | User_permitgroup usergroup = new User_permitgroup();
|
| | | List<Batt_User_Permit> list = ((User_infImpl) dao).searchAll(obj);// 存放的是员工信息
|
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | ServiceModel model1 = upservice.serchByCondition(list.get(i).getUinf());// 存放权限
|
| | | // System.out.println(model1.getMsgN());
|
| | | if (model1.getCode() > 0) {
|
| | | list.get(i).getUinf().setPermitgroupName(model1.getMsgN());
|
| | | } else {
|
| | | list.get(i).getUinf().setPermitgroupName("");
|
| | | }
|
| | | }
|
| | | model.setData(list);
|
| | | }
|
| | | // System.out.println(model);
|
| | | return model;
|
| | | }
|
| | |
|
| | | // 5.3根据uid查所在的包机组
|
| | | public ServiceModel serchByInfo(Object obj) {
|
| | | model = new ServiceModel();
|
| | | List<User_battgroup_baojigroup> list = dao.serchByInfo(obj);
|
| | | // System.out.println(list.size());
|
| | | // for(User_battgroup_baojigroup u:list){
|
| | | // System.out.println(u);
|
| | | // }
|
| | | if (list != null && list.size() > 0) {
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | |
|
| | | } else {
|
| | | model.setCode(0);
|
| | | }
|
| | | // System.out.println(model);
|
| | | return model;
|
| | | }*/
|
| | |
|
| | | /*// 用户登录
|
| | | public ServiceModel login(Object obj) {
|
| | | User_inf uinf = (User_inf) obj;
|
| | | //String usnId64 = (String) ActionUtil.DecryptionBase64(uinf.getUpassword());
|
| | | //String usnIdMd5 = (String) ActionUtil.EncryptionMD5(usnId64);
|
| | | // System.out.println(uinf.getUSnId()+" "+usnId64+" "+usnIdMd5+" :service");
|
| | | //uinf.setUpassword(usnIdMd5);
|
| | | List list = dao.serchByCondition(uinf);
|
| | | if (list == null || list.size() < 1) {
|
| | | model.setMsg(this.getText("Username_error"));
|
| | | // System.out.println("用户名不存在");
|
| | | } else {
|
| | | User_inf u = (User_inf) list.get(0);
|
| | | //System.out.println(uinf.getUpassword());
|
| | | // System.out.println(uinf.getUSnId()+"=="+u.getUNote());
|
| | | if (!uinf.getUpassword().equals(u.getUpassword())) {
|
| | | System.out.println("密码错误"+uinf.getUpassword()+"=="+u.getUpassword());
|
| | | model.setMsg(getText("Password_error"));
|
| | | } else {
|
| | | uinf.setUSnId(u.getUSnId());
|
| | | model.setCode(1);
|
| | | model.setMsg("index.jsp");
|
| | | //model.setMsg("index-outline.jsp");
|
| | | // 将登陆成功的用户存入session
|
| | | ActionUtil.getSession().setAttribute("user", u);
|
| | | |
| | | //设置session不活动时间为30分
|
| | | ActionUtil.getSession().setMaxInactiveInterval(60*30);
|
| | | ActionUtil.getSession().setAttribute("ip",ActionUtil.getRequest().getRemoteAddr());
|
| | | User_permitgroupService upgs=new User_permitgroupService();
|
| | | ServiceModel model1=upgs.serchItem(u);
|
| | | //System.out.println(model.getData());
|
| | | if(model1.getCode()==1){
|
| | | ActionUtil.getSession().setAttribute("permits", ActionUtil.tojson(model1.getData()));
|
| | | }else{
|
| | | model.setCode(0);
|
| | | model.setMsg("还未分配权限");
|
| | | }
|
| | | //将新登录的用户存入application
|
| | | setApplication(u);
|
| | | }
|
| | | }
|
| | | return model;
|
| | | }*/
|
| | |
|
| | | // 将所有登陆的用户的信息存到application中
|
| | | public void setApplication(User_inf user) {
|
| | | ServletContext application = ActionUtil.getApplication();
|
| | | Map<String, UserClient> map = (Map) application.getAttribute("users");
|
| | | if (map == null) {
|
| | | map = new HashMap<String, UserClient>();
|
| | | } else {
|
| | | UserClient client = map.get(user.getUName());
|
| | | if (client != null) {
|
| | | map.remove(user.getUName());
|
| | | }
|
| | | }
|
| | | Long login_time = new Date().getTime();
|
| | | ActionUtil.getSession().setAttribute("login_time", login_time);
|
| | | map.put(user.getUName(), new UserClient(ActionUtil.getRequest().getRemoteAddr(),user,login_time));
|
| | | application.setAttribute("users", map);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 开始查看application中是否有另一用使用该账号登陆
|
| | | * |
| | | * @return
|
| | | */
|
| | | |
| | | public ServiceModel checkUser() {
|
| | | Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("users");
|
| | | // System.out.println(map);
|
| | | if (map != null && map.size() > 0) {
|
| | | User_inf user = (User_inf) ActionUtil.getSession().getAttribute("user");
|
| | | Long login_time = (Long) ActionUtil.getSession().getAttribute("login_time");
|
| | | if (user != null && login_time != null) {
|
| | | UserClient client = map.get(user.getUName());
|
| | | if (client != null) {
|
| | | if (login_time == client.getLogin_times()) {
|
| | | model.setCode(0);
|
| | | }else {
|
| | | model.setCode(1);
|
| | | model.setMsg(getText("The landing on the account in another host, please log in again"));
|
| | | }
|
| | | }else {
|
| | | model.setCode(1);
|
| | | model.setMsg(getText("You are not logged in, please log in"));
|
| | | }
|
| | | } else {
|
| | | model.setCode(1);
|
| | | model.setMsg(getText("You are not logged in, please log in"));
|
| | | }
|
| | | } else {
|
| | | model.setCode(1);
|
| | | model.setMsg(getText("You are not logged in, please log in"));
|
| | | }
|
| | | return model;
|
| | | }
|
| | |
|
| | | //修改用户密码
|
| | | public ServiceModel updatePassword(Object obj){
|
| | | User_inf uinf=(User_inf) obj;
|
| | | uinf.setUpassword((String)ActionUtil.EncryptionMD5(uinf.getUSnId()));
|
| | | //System.out.println(uinf);
|
| | | Boolean bl=((User_infImpl)dao).updatePassword(uinf);
|
| | | if(bl){
|
| | | model.setCode(1);
|
| | | model.setMsg("修改成功!");
|
| | | }
|
| | | else{
|
| | | model.setMsg("修改失败!");
|
| | | }
|
| | | return model;
|
| | | }
|
| | | |
| | | /*//根据员工信息和员工编号去匹配合适的员工
|
| | | public ServiceModel searchByNameOrId(Object obj){
|
| | | List<User_inf> list=((User_infImpl)dao).searchByNameOrId(obj);
|
| | | |
| | | if(list!=null&&list.size()>0){
|
| | | model.setCode(1);
|
| | | model.setData(list);
|
| | | model.setMsg("查询成功!");
|
| | | }
|
| | | else{
|
| | | model.setCode(0);
|
| | | model.setMsg("查询失败!");
|
| | | }
|
| | | return model;
|
| | | }*/
|
| | |
|
| | | //重置用户密码
|
| | | public ServiceModel resetPassword(Object obj){
|
| | | Boolean bl=((User_infImpl)dao).resetPassword(obj);
|
| | | if(bl){
|
| | | model.setCode(1);
|
| | | model.setMsg("修改成功!");
|
| | | }
|
| | | else{
|
| | | model.setMsg("修改失败!");
|
| | | }
|
| | | return model;
|
| | | }
|
| | | public static void main(String[] args) {
|
| | | |
| | | }
|
| | |
|
| | | public ServiceModel login(User_inf uinf) {
|
| | | // TODO Auto-generated method stub
|
| | | return null;
|
| | | }
|
| | | }
|