package com.fgkj.services;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.ServletContext;
|
import javax.servlet.http.Cookie;
|
|
import com.fgkj.actions.ActionUtil;
|
import com.fgkj.dao.BaseDAO;
|
import com.fgkj.dao.BaseDAOFactory;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.UserClient;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.dto.Vip_user;
|
|
public class Vip_userService extends ActionUtil{
|
private ServiceModel model;
|
private BaseDAO dao;
|
|
|
public Vip_userService() {
|
model=new ServiceModel();
|
dao=BaseDAOFactory.getBaseDAO(BaseDAO.VIP_USER);
|
}
|
|
public ServiceModel add(Object obj) {
|
Boolean bl=dao.add(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("添加成功!");
|
}
|
else{
|
model.setMsg("添加失败!");
|
}
|
return model;
|
|
}
|
public ServiceModel update(Object obj) {
|
Boolean bl=dao.update(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("修改成功!");
|
}
|
else{
|
model.setMsg("修改失败!");
|
}
|
return model;
|
}
|
public ServiceModel delete(Object obj) {
|
Boolean bl=dao.del(obj);
|
if(bl){
|
model.setCode(1);
|
model.setMsg("删除成功!");
|
}
|
else{
|
model.setMsg("删除失败!");
|
}
|
return model;
|
}
|
//根据vip账号查询密码
|
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);
|
}else{
|
model.setCode(0);
|
model.setMsg("查询失败!");
|
}
|
// System.out.println(model);
|
return model;
|
}
|
|
//超级管理员登陆
|
public ServiceModel login(Object obj){
|
User_inf uinf=(User_inf)obj;
|
//System.out.println(uinf.getUSnId()+" "+usnId64+" "+usnIdMd5+" :service");
|
Vip_user vuser=new Vip_user();
|
vuser.setVipname(uinf.getUName());
|
List<Vip_user> list = dao.serchByCondition(vuser);
|
model=new ServiceModel();
|
if(list!=null && list.size()>0){
|
for(int i=0;i<list.size();i++){
|
if(list.get(i).getVipname().equals(uinf.getUName()) && list.get(i).getVipPassword().equals(uinf.getUpassword())){
|
uinf.setUSnId(list.get(i).getVipSnId());
|
model.setCode(1);
|
model.setMsg("navConfig.jsp");
|
getSession().setAttribute("vip",list.get(i));
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
|
|
setMyCookie("user",uinf,30,uinf.getUId() == 1); //用户记住密码功能
|
if (map == null) {
|
map = new HashMap<String, UserClient>();
|
} else {
|
UserClient client = map.get(list.get(i).getVipname());
|
if (client != null) {
|
map.remove(list.get(i).getVipname());
|
}
|
}
|
map.put(list.get(i).getVipname(), new UserClient(ActionUtil.getRequest().getRemoteAddr(), uinf));
|
ActionUtil.getApplication().setAttribute("vips", map);
|
}
|
}
|
}
|
return model;
|
}
|
|
/**
|
* 保存指定的cookie值
|
* @param key cookie 键
|
* @param obj 值
|
* @param timelong 保存时长(秒)
|
* @param flag 是否保存
|
*/
|
public void setMyCookie(String key,Object obj,long timelong,boolean flag){
|
Cookie c = null;
|
if(flag){
|
//记住密码
|
c = new Cookie(key, ActionUtil.EncryptionBase64(ActionUtil.getGson().toJson(obj)).toString());
|
}else{
|
c = new Cookie(key, "");
|
}
|
//让Cookie保留30天
|
c.setMaxAge(30*24*60*60);
|
ActionUtil.getResponse().addCookie(c);
|
}
|
|
/**
|
* 开始是否有另一台主机登陆当前账号
|
*
|
* @return
|
*/
|
|
public ServiceModel checkVip() {
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
|
// System.out.println(map);
|
if (map != null && map.size() > 0) {
|
Vip_user user = (Vip_user) ActionUtil.getSession().getAttribute(
|
"vip");
|
if (user != null) {
|
UserClient client = map.get(user.getVipname());
|
if (client != null) {
|
if (!ActionUtil.getRequest().getRemoteAddr().equals(client.getIp())) {
|
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"));
|
}
|
return model;
|
}
|
|
public ServiceModel searchAll(){
|
List list=dao.searchAll();
|
// for (Object object : list) {
|
// System.out.println(object);
|
// }
|
//System.out.println(list);
|
if(list!=null && list.size()>0){
|
model.setCode(1);
|
model.setData(list);
|
}
|
//System.out.println(model);
|
return model;
|
}
|
public static void main(String[] args) {
|
Vip_userService vservice=new Vip_userService();
|
//System.out.println(vservice.dao);
|
Vip_user vuser=new Vip_user();
|
vuser.setVipname("vip");
|
vservice.serchByCondition(vuser);
|
}
|
}
|