whycrzg
2021-02-23 351b9a53cb9ecebdf8f79db0117f540d9c42c2a4
src/main/java/com/fgkj/services/User_infService.java
@@ -1,45 +1,61 @@
package com.fgkj.services;
import com.fgkj.util.*;
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.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class User_infService{
   private ServiceModel model;
   ServiceModel model = new ServiceModel();
   @Autowired
   @Resource
   private User_permitgroupService upservice;
   @Autowired
   @Resource
   private User_infMapper mapper;;
//   @Autowired
//   DataSourceTransactionManager dataSourceTransactionManager;
//   @Autowired
//   TransactionDefinition transactionDefinition;
   //5.1用户管理(添加)
   public ServiceModel add(Object obj) {
      int flag=mapper.addJudge(obj);
   public ServiceModel add(User_inf obj) {
      ServiceModel model = new ServiceModel();
      int flag = mapper.addJudge(obj); //查询,不需要开启事务
      //System.out.println(flag);
      if(flag!=0){
         Boolean bl=mapper.add(obj);
         if(bl){
      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{
         } else {
            model.setCode(0);
            model.setMsg("添加失败!");
         }
      }else{
      } else {
         model.setCode(0);
         model.setMsg("用户名存在,请重新输入!");
      }
@@ -47,13 +63,21 @@
   }
   // 5.1用户管理(编辑)
   public ServiceModel update(Object obj) {
   public ServiceModel update(User_inf obj) {
      ServiceModel model = new ServiceModel();
      Boolean bl = false;
      bl=mapper.update(obj);
      if(bl){
      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{
      } else {
         model.setCode(0);
         model.setMsg("修改失败");
      }
@@ -61,8 +85,9 @@
   }
   // 5.1用户管理(删除)
   public ServiceModel delete(Object obj) {
      Boolean bl = mapper.del(obj);
   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);
@@ -73,7 +98,8 @@
      return model;
   }
   
   public ServiceModel serchByCondition(Object obj) {
   public ServiceModel serchByCondition(User_inf obj) {
      ServiceModel model = new ServiceModel();
      List list = mapper.serchByCondition(obj);
      /*
       * for (Object object : list) { System.out.println(object); }
@@ -89,9 +115,6 @@
   public ServiceModel searchAll() {
      List<User_inf> list = mapper.searchAll();
      /*
       * for (User_inf u : list) { System.out.println(u); }
       */
      if (list != null && list.size() > 0) {
         model.setCode(1);
@@ -101,8 +124,8 @@
   }
   // 根据battgroupid查对应的包机人
   public ServiceModel searchByBattGroupId(Object obj) {
      model = new ServiceModel();
   public ServiceModelImpl2 searchByBattGroupId(User_battgroup_baojigroup_battgroup obj) {
      ServiceModelImpl2 model = new ServiceModelImpl2();
      List<User_inf> list = mapper.searchByBattGroupId(obj);
      // System.out.println(list.size());
      /*
@@ -117,26 +140,25 @@
         for (int i = 0; i < list.size(); i++) {
            uStrN += ",";
            uStrI += ",";
            uStrN += list.get(i).getUName().toString();
            uStrI += list.get(i).getUId().toString();
            uStrN += list.get(i).getuName().toString();
            uStrI += list.get(i).getuId().toString();
         }
         uStrN = uStrN.substring(1, uStrN.length());
         uStrI = uStrI.substring(1, uStrI.length());
         //TODO perry
         /*model.setMsg(uStrN);
         model.setMsgO(uStrI);*/
         model.setMsg(uStrN);
         model.setMsgO(uStrI);
      } else {
         model.setCode(0);
      }
      // System.out.println(model.getMsg());
      // System.out.println(model);
//       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 = mapper.serchUname(obj);
   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);
@@ -148,33 +170,33 @@
   }
   // 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 = mapper.searchAll(obj);// 存放的是员工信息
   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++) {
            ServiceModel model1 = upservice.serchByCondition(list.get(i).getUinf());// 存放权限
            ServiceModelImpl model1 = upservice.serchByCondition(list.get(i).getUinf());// 存放权限
            // System.out.println(model1.getMsgN());
            if (model1.getCode() > 0) {
               //TODO perry
               // list.get(i).getUinf().setPermitgroupName(model1.getMsgN());
                list.get(i).getUinf().setPermitgroupName(model1.getMsgN());
            } else {
               list.get(i).getUinf().setPermitgroupName("");
            }
         }
         model.setData(list);
         PageInfo<Batt_User_Permit> pageInfo = new PageInfo<>(list);
         model.setData(pageInfo);
      }
      // System.out.println(model);
      return model;
   }
   // 5.3根据uid查所在的包机组
   public ServiceModel serchByInfo(Object obj) {
      model = new ServiceModel();
   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){
@@ -196,7 +218,7 @@
      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");
      // System.out.println(uinf.getuSnId()+"    "+usnId64+"   "+usnIdMd5+"     :service");
      //uinf.setUpassword(usnIdMd5);
      List list = mapper.serchByCondition(uinf);
      if (list == null || list.size() < 1) {
@@ -206,13 +228,13 @@
      } else {
         User_inf u = (User_inf) list.get(0);
         //System.out.println(uinf.getUpassword());
         // System.out.println(uinf.getUSnId()+"=="+u.getUNote());
         // 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());
            uinf.setuSnId(u.getuSnId());
            model.setCode(1);
            //model.setMsg("index.jsp");
            model.setMsg("index-outline.jsp");
@@ -247,14 +269,14 @@
      if (map == null) {
         map = new HashMap<String, UserClient>();
      } else {
         UserClient client = map.get(user.getUName());
         UserClient client = map.get(user.getuName());
         if (client != null) { //已存在
            map.remove(user.getUName());
            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));
      map.put(user.getuName(), new UserClient(ActionUtil.getRequest().getRemoteAddr(),user,login_time));
      application.setAttribute("users", map);
   }
@@ -273,7 +295,7 @@
         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());
            UserClient client = map.get(user.getuName());
            if (client != null) {
               if (login_time != client.getLogin_times()) {
                  model.setCode(1);
@@ -295,9 +317,9 @@
   }
   //修改用户密码
   public ServiceModel updatePassword(Object obj){
      User_inf uinf=(User_inf) obj;
      uinf.setUpassword((String)ActionUtil.EncryptionMD5(uinf.getUSnId()));
   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){
@@ -311,12 +333,18 @@
   }
   
   //根据员工信息和员工编号去匹配合适的员工
   public ServiceModel searchByNameOrId(Object obj){
      List<User_inf> list=mapper.searchByNameOrId(obj);
   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(list);
         model.setData(pageInfo);
         model.setMsg("查询成功!");
      }
      else{
@@ -327,7 +355,9 @@
   }
   //重置用户密码
   public ServiceModel resetPassword(Object obj){
   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);
@@ -341,6 +371,7 @@
   
   //包机组重做(穿梭框)查询所有的用户
   public ServiceModel searchCS_All() {
      ServiceModel model = new ServiceModel();
        List list=mapper.searchCS_All();
      if(list!=null&&list.size()>0){
         model.setCode(1);
@@ -357,9 +388,9 @@
   /*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);
      u.setuName("a");
      u.setuEmployeeId("a");
      u.setuId(1003);
      Batt_User_Permit bup = new Batt_User_Permit();
      Page page = new Page();
      page.setPageSize(10);