package com.fgkj.services;
|
|
import com.fgkj.dto.*;
|
import com.fgkj.mapper.UinfDaoFactory;
|
import com.fgkj.mapper.impl.User_infMapper;
|
import com.fgkj.util.ActionUtil;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionStatus;
|
|
import javax.annotation.Resource;
|
import javax.servlet.ServletContext;
|
import javax.servlet.http.HttpSession;
|
import java.util.*;
|
|
@Service
|
public class User_infService{
|
|
ServiceModel model = new ServiceModel();
|
|
@Resource
|
private User_permitgroupService upservice;
|
|
@Resource
|
private User_infMapper mapper;;
|
|
// @Autowired
|
// DataSourceTransactionManager dataSourceTransactionManager;
|
// @Autowired
|
// TransactionDefinition transactionDefinition;
|
|
//5.1用户管理(添加)
|
public ServiceModel add(User_inf obj) {
|
ServiceModel model = new ServiceModel();
|
int flag = mapper.addJudge(obj); //查询,不需要开启事务
|
//System.out.println(flag);
|
if (flag == 0) {
|
Boolean bl = null;
|
try {
|
bl = mapper.add(obj) > 0;
|
} catch (Exception e) {
|
e.printStackTrace();
|
model.setCode(0);
|
model.setMsg("添加失败!");
|
return model;
|
}
|
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(User_inf obj) {
|
ServiceModel model = new ServiceModel();
|
Boolean bl = false;
|
try {
|
bl = mapper.update(obj);
|
} catch (Exception e) {
|
e.printStackTrace();
|
model.setCode(0);
|
model.setMsg("添加失败!");
|
return model;
|
}
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("修改成功");
|
} else {
|
model.setCode(0);
|
model.setMsg("修改失败");
|
}
|
return model;
|
}
|
|
// 5.1用户管理(删除)
|
public ServiceModel delete(User_inf obj) {
|
ServiceModel model = new ServiceModel();
|
Boolean bl = mapper.del(obj)>0;
|
//System.out.println(obj);
|
if (bl) {
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
} else {
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
|
public ServiceModel serchByCondition(User_inf obj) {
|
ServiceModel model = new ServiceModel();
|
List list = mapper.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;
|
}
|
|
public ServiceModel searchAll() {
|
List<User_inf> list = mapper.searchAll();
|
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
|
// 根据battgroupid查对应的包机人
|
public ServiceModelImpl2 searchByBattGroupId(User_battgroup_baojigroup_battgroup obj) {
|
ServiceModelImpl2 model = new ServiceModelImpl2();
|
List<User_inf> list = mapper.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(User_inf inf) {
|
ServiceModel model = new ServiceModel();
|
List list = mapper.serchUname(inf);
|
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(Batt_User_Permit bup) {
|
ServiceModel model = new ServiceModel();
|
//分页
|
PageBean pageBean = bup.getPageBean();
|
PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize(),true);
|
List<Batt_User_Permit> list = mapper.searchAll2(bup);// 存放的是员工信息
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
for (int i = 0; i < list.size(); i++) {
|
ServiceModelImpl 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("");
|
}
|
}
|
PageInfo<Batt_User_Permit> pageInfo = new PageInfo<>(list);
|
model.setData(pageInfo);
|
}
|
// System.out.println(model);
|
return model;
|
}
|
|
// 5.3根据uid查所在的包机组
|
public ServiceModel serchByInfo(User_inf obj) {
|
ServiceModel model = new ServiceModel();
|
List<User_battgroup_baojigroup> list = mapper.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 = mapper.serchByCondition(uinf);
|
if (list == null || list.size() < 1) {
|
// model.setMsg(this.getText("UsernameOrPassword_error"));
|
model.setMsg("UsernameOrPassword_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("UsernameOrPassword_error"));
|
model.setMsg("UsernameOrPassword_error");
|
} else {
|
uinf.setuSnId(u.getuSnId());
|
model.setCode(1);
|
//model.setMsg("index.jsp");
|
model.setMsg("index-outline.jsp");
|
// 将登陆成功的用户存入session
|
HttpSession session = ActionUtil.getSession();
|
System.out.println(session);
|
session.setAttribute("user", u);
|
|
//设置session不活动时间为30分
|
session.setMaxInactiveInterval(60*30);
|
session.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){
|
session.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) {
|
HttpSession session = ActionUtil.getSession();
|
System.out.println(session);
|
User_inf user = (User_inf) session.getAttribute("user");
|
Long login_time = (Long) session.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(1);
|
// model.setMsg(getText("The landing on the account in another host, please log in again"));
|
model.setMsg("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"));
|
model.setMsg("You are not logged in, please log in");
|
}
|
} else {
|
model.setCode(1);
|
// model.setMsg(getText("You are not logged in, please log in"));
|
model.setMsg("You are not logged in, please log in");
|
}
|
return model;
|
}
|
|
//修改用户密码
|
public ServiceModel updatePassword(User_inf uinf){
|
ServiceModel model = new ServiceModel();
|
uinf.setUpassword((String)ActionUtil.EncryptionMD5(uinf.getuSnId()));
|
//System.out.println(uinf);
|
Boolean bl=mapper.updatePassword(uinf);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else{
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
//根据员工信息和员工编号去匹配合适的员工
|
public ServiceModel searchByNameOrId(Batt_User_Permit bup){
|
|
//分页
|
PageBean pageBean = bup.getPageBean();
|
PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize(),true);
|
List<User_inf> list=mapper.searchByNameOrId(bup);
|
|
if(list!=null&&list.size()>0){
|
list.get(list.size()-1).setuNote(""+pageBean.getPageAll());
|
PageInfo<User_inf> pageInfo = new PageInfo<>(list);
|
model.setCode(1);
|
model.setData(pageInfo);
|
model.setMsg("查询成功!");
|
}
|
else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
//重置用户密码
|
public ServiceModel resetPassword(User_inf obj){
|
ServiceModel model = new ServiceModel();
|
obj.setUpassword((String)ActionUtil.EncryptionMD5(UinfDaoFactory.MR_PWD));
|
Boolean bl=mapper.resetPassword(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else{
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
|
//包机组重做(穿梭框)查询所有的用户
|
public ServiceModel searchCS_All() {
|
ServiceModel model = new ServiceModel();
|
List list=mapper.searchCS_All();
|
if(list!=null&&list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
model.setMsg("查询成功!");
|
}
|
else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
return model;
|
}
|
|
/*public static void main(String[] args) {
|
User_infService us = new User_infService();
|
User_inf u = new User_inf();
|
u.setuName("a");
|
u.setuEmployeeId("a");
|
u.setuId(1003);
|
Batt_User_Permit bup = new Batt_User_Permit();
|
Page page = new Page();
|
page.setPageSize(10);
|
page.setPageCurr(1);
|
bup.setPage(page);
|
bup.setUinf(u);
|
|
//User_battgroup_baojigroup_battgroup ub = new User_battgroup_baojigroup_battgroup();
|
// ub.setBattGroupId(1000012);
|
// us.searchByBattGroupId(ub);
|
// us.serchByInfo(u);
|
// System.out.println(us.searchAll(bup).getData());
|
us.searchByNameOrId(bup);
|
}*/
|
}
|