package com.fgkj.services;
|
|
import com.fgkj.util.*;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User;
|
import com.fgkj.dto.UserClient;
|
import com.fgkj.mapper.impl.UserMapper;
|
import com.fgkj.report.FileUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
@Service
|
public class UserService {
|
|
@Resource
|
private UserMapper mapper;
|
|
// 添加员工
|
public ServiceModel addUser(User user) {
|
ServiceModel model = new ServiceModel();
|
/*if (mapper.add(user)) {
|
user = (User) mapper.serchByCondition(user).get(0);
|
dao = BaseDAOFactory.getBaseDAO(Basemapper.USERROLE);
|
UserRole userrole = new UserRole(user, new Roles(user.getPid()));
|
if (dao.add(userrole)) {
|
model.setCode(1);
|
model.setMsg("添加成功");
|
}
|
} else {
|
model.setMsg("添加失败");
|
}
|
return model;*/
|
return model;
|
}
|
|
public ServiceModel delUser(User user) {
|
ServiceModel model = new ServiceModel();
|
if (mapper.del(user)) {
|
model.setCode(1);
|
model.setMsg("删除成功");
|
} else {
|
model.setMsg("删除失败");
|
}
|
return model;
|
}
|
|
public ServiceModel updateUser(User user) {
|
ServiceModel model = new ServiceModel();
|
/*if (mapper.update(user)) {
|
dao = BaseDAOFactory.getBaseDAO(Basemapper.USERROLE);
|
boolean flag = dao.update(new UserRole(user, new Roles(user.getPid())));
|
if (flag) {
|
model.setCode(1);
|
model.setMsg("修改成功");
|
}
|
} else {
|
model.setMsg("修改成功");
|
}*/
|
return model;
|
}
|
|
public ServiceModel findUser(User user) {
|
ServiceModel model = new ServiceModel();
|
List list = mapper.serchByCondition(user);
|
if (list != null && list.size() > 0) {
|
model.setData(list);
|
model.setCode(1);
|
} else {
|
model.setMsg("查询失败");
|
}
|
return model;
|
}
|
|
public ServiceModel findUserAll() {
|
ServiceModel model = new ServiceModel();
|
List list = mapper.searchAll();
|
if (list != null && list.size() > 0) {
|
FileUtil.WriterFile(list);
|
model.setCode(1);
|
model.setData(list);
|
}
|
return model;
|
}
|
|
public ServiceModel findByInfo(Object obj) {
|
ServiceModel model = new ServiceModel();
|
User user = (User) obj;
|
List list = mapper.serchByInfo(user);
|
if (list == null || list.size() < 1) {
|
model.setMsg("没有匹配的员工");
|
} else {
|
model.setData(list);
|
model.setCode(1);
|
}
|
return model;
|
}
|
|
public ServiceModel updatePass(Object obj) {
|
ServiceModel model = new ServiceModel();
|
boolean flag = mapper.updatePass(obj);
|
if (!flag) {
|
model.setMsg("修改失败");
|
} else {
|
model.setCode(1);
|
List list = mapper.serchByCondition(obj);
|
if (list != null && list.size() > 0) {
|
User u = (User) list.get(0);
|
ActionUtil.getSession().setAttribute("user", u);
|
}
|
}
|
return model;
|
}
|
|
public ServiceModel findByAge(int currentPage, int PageSize) {
|
ServiceModel model = new ServiceModel();
|
List list = mapper.serchByPage(currentPage, PageSize);
|
if (list != null && list.size() > 0) {
|
model.setCode(1);
|
model.setData(list);
|
} else {
|
model.setMsg("查询失败");
|
}
|
return model;
|
}
|
|
// public ServiceModel login(Object obj) {
|
// User user = (User) obj;
|
// List list = mapper.serchByCondition(user);
|
// if (list == null || list.size() < 1) {
|
// model.setMsg(this.getText("Username_error"));
|
// // System.out.println("用户名不存在");
|
// } else {
|
// User u = (User) list.get(0);
|
//
|
// if (!user.getUpass().equals(u.getUpass())) {
|
// model.setMsg(getText("Password_error"));
|
// } else {
|
// model.setCode(1);
|
// // 将登陆成功的用户存入session
|
// ActionUtil.getSession().setAttribute("user", u);
|
// ActionUtil.getSession().setAttribute("ip",
|
// ActionUtil.getRequest().getRemoteAddr());
|
// // 将新登录的用户存入application
|
// setApplication(u);
|
// }
|
// }
|
// return model;
|
// }
|
|
// public void setApplication(User 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());
|
// }
|
// }
|
// //map.put(user.getuName(), new UserClient(ActionUtil.getRequest().getRemoteAddr(), user));
|
// application.setAttribute("users", map);
|
// }
|
|
/**
|
* 开始查看application中是否有另一用使用该账号登陆
|
*
|
* @return
|
*/
|
public ServiceModel checkUser() {
|
ServiceModel model = new ServiceModel();
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication()
|
.getAttribute("users");
|
//System.out.println(map);
|
if (map != null && map.size()>0) {
|
User user = (User) ActionUtil.getSession().getAttribute("user");
|
if(user!=null){
|
UserClient client = map.get(user.getuName());
|
if(client!=null){
|
if (!ActionUtil.getRequest().getRemoteAddr().equals(client.getIp())) {
|
model.setCode(1);
|
model.setMsg("The landing on the account in another host, please log in again");
|
}
|
}
|
}else{
|
model.setCode(1);
|
model.setMsg("You are not logged in, please log in");
|
}
|
} else {
|
model.setCode(1);
|
model.setMsg("You are not logged in, please log in");
|
}
|
return model;
|
}
|
}
|