whyclxw
2025-05-14 35838dd80eff7d45b6cb67e3b1ff22d432305f0e
登录成功返回用户权限和用户信息
1 文件已重命名
6个文件已修改
2个文件已添加
263 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/PowerInfController.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/StationInfController.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/PowerDto.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_user/User.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/realm/CustomRealm.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/LoginService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PermitGroupService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PowerInfService.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/StationInfService.java 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/PowerInfController.java
New file
@@ -0,0 +1,43 @@
package com.whyc.controller;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.pojo.db_station.PowerInf;
import com.whyc.service.PowerInfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@Api(tags = "电源管理")
@RequestMapping("powerInf")
public class PowerInfController {
    @Autowired
    private PowerInfService service;
    @ApiOperation(value = "添加机房")
    @PostMapping("addPower")
    public Response addPower(@RequestBody PowerInf pinf){
        return service.addPower(pinf);
    }
    @ApiOperation(value = "删除机房")
    @GetMapping("delPower")
    public Response delPower(@RequestParam Integer pid){
        return service.delPower(pid);
    }
    @ApiOperation(value = "修改机房")
    @PostMapping("updatePower")
    public Response updatePower(@RequestBody PowerInf pinf){
        return service.updatePower(pinf);
    }
    @ApiOperation(value = "查询机房")
    @PostMapping("getPower")
    public Response getPower(@RequestBody PowerDto dto){
        return service.getPower(dto);
    }
}
src/main/java/com/whyc/controller/StationInfController.java
@@ -1,8 +1,6 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.dto.StationDto;
import com.whyc.pojo.db_station.StationInf;
import com.whyc.pojo.db_user.User;
import com.whyc.service.StationInfService;
import com.whyc.util.ActionUtil;
src/main/java/com/whyc/dto/PowerDto.java
File was renamed from src/main/java/com/whyc/dto/StationDto.java
@@ -3,7 +3,7 @@
import lombok.Data;
@Data
public class StationDto {
public class PowerDto {
    private String provice;
    private String city;
    private String country;
src/main/java/com/whyc/pojo/db_user/User.java
@@ -1,6 +1,7 @@
package com.whyc.pojo.db_user;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -28,6 +29,9 @@
    private String phoneNumber;
    @TableField("身份:1普通用户,2管理层,3领导层,4运维班组")
    private int role;
    @ApiModelProperty(value = "账号类型 1:长期,2:临时 ")
    private Integer type;
    @ApiModelProperty(value = "账号状态 1:激活,2:休眠,3:锁定,0:注销")
src/main/java/com/whyc/realm/CustomRealm.java
@@ -31,7 +31,7 @@
        String name = (String) authenticationToken.getPrincipal();
        User user = userBridgeService.findPasswordByUserName(name);
        if(user.getId()==0){
            throw new UnknownAccountException(MessageUtils.getMessage("AccountOrPasswordError"));
            throw new UnknownAccountException("账号或密码错误");
        }
        String pwd = RSAUtil.decrypt(user.getPwd(),RSAUtil.getPrivateKey());
        return new SimpleAuthenticationInfo(user,pwd,getName());
src/main/java/com/whyc/service/LoginService.java
@@ -10,6 +10,7 @@
import com.whyc.mapper.PageParamMapper;
import com.whyc.mapper.UserMapper;
import com.whyc.pojo.db_app_sys.PageParam;
import com.whyc.pojo.db_user.Permitgroup;
import com.whyc.pojo.db_user.PermitgroupUsr;
import com.whyc.pojo.db_user.User;
import com.whyc.util.*;
@@ -24,7 +25,6 @@
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.*;
@Service
@@ -41,6 +41,9 @@
    @Resource
    private PermitGroupUserService permitGroupUserService;
    @Resource
    private PermitGroupService permitGroupService;
    @Autowired
    private BaojigroupService bjService;
@@ -77,7 +80,7 @@
        Enumeration<String> attributeNames = servletContext.getAttributeNames();
        QueryWrapper<User> queryWrapper = Wrappers.query();
        queryWrapper.select("id", "status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("name", userName);
        queryWrapper.select("id","role","status", "visit_ip", "visit_time", "password_update_time", "last_login_time").eq("name", userName);
        User userInf = userMapper.selectOne(queryWrapper);
        //每个登录的用户都有一个全局变量,里面存着对应的SessionId;
        //同一个账号,后面登录的,会挤掉之前登录的SessionId,这个todo,做限制账号同时登陆人数为1
@@ -236,13 +239,15 @@
            userService.updateLoginTime(userInf.getId());
            //查询用户对应的权限组id并返回给前端
            LinkedList<Object> dataList = new LinkedList<>();
            dataList.add(subject.getPrincipal());
            dataList.add(userInf);
            PermitgroupUsr permitGroup = permitGroupUserService.getPermitGroup(userInf.getId());
            if(permitGroup == null){
                return response.set(1, false, "当前用户没有对应的权限组,登录失败");
            }else {
                int permitGroupId = permitGroup.getPermitGroupId();
                dataList.add(permitGroupId);
                //查询权限组信息
                List<Permitgroup> permitgroupList=permitGroupService.getPermitGroup(permitGroupId);
                dataList.add(permitgroupList);
            }
            //查询用户对应的班组标识
            dataList.add(bjService.getGroupFlag(userInf.getId().intValue()));
src/main/java/com/whyc/service/PermitGroupService.java
@@ -184,4 +184,11 @@
        List<Permitgroup> permitGroups = mapper.selectList(wrapper);
        return permitGroups;
    }
    //查询权限组信息
    public List<Permitgroup> getPermitGroup(int permitGroupId) {
        QueryWrapper<Permitgroup> wrapper = Wrappers.query();
        wrapper.eq("permit_group_id",permitGroupId);
        List<Permitgroup> permitGroups = mapper.selectList(wrapper);
        return permitGroups;
    }
}
src/main/java/com/whyc/service/PowerInfService.java
New file
@@ -0,0 +1,106 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.mapper.PowerInfMapper;
import com.whyc.mapper.StationInfMapper;
import com.whyc.pojo.db_station.PowerInf;
import com.whyc.pojo.db_station.StationInf;
import org.apache.commons.math3.analysis.function.Power;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PowerInfService {
    @Autowired(required = false)
    private PowerInfMapper mapper;
    @Autowired(required = false)
    private StationInfMapper sinfMapper;
    //添加机房
   public Response addPower(PowerInf addpinf) {
       /* //判断添加锁的时候机房是不是新机房
        String fullName=addpinf.getProvice()+"_"+addpinf.getCity()+"_"+addpinf.getCountry()+"_"+addsinf.getStationName();
        //判断机房是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("full_name",fullName);
        wrapper.last("limit 1");
       PowerInf pinf=mapper.selectOne(wrapper);
        int stationId=0;
        if(pinf!=null){
            return new Response().set(1,false,"机房已存在");
        }else {
            //获取对应的机房id
            stationId=sinfMapper.getMaxStationId();
            if(stationId==0){//数据库中没有站点
                stationId=40000001;
            }else{
                stationId+=1;
            }
            StationInf newSinf=new StationInf();
            newSinf.setStationId(stationId);
            newSinf.setStationName(fullName);
            newSinf.setProvice(addsinf.getProvice());
            newSinf.setCity(addsinf.getCity());
            newSinf.setCountry(addsinf.getCountry());
            newSinf.setStationName(addsinf.getStationName());
            mapper.insert(newSinf);*/
            return new Response().set(1,true,"添加机房");
    }
    //删除机房
    public Response delPower(Integer pid) {
       /* UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("station_id",stationId);
        mapper.delete(wrapper);*/
        return new Response().set(1,true);
    }
    //修改机房
    public Response updatePower(PowerInf pinf) {
        UpdateWrapper wrapper=new UpdateWrapper();
        /*wrapper.eq("station_id",sinf.getStationId());
        if(sinf.getProvice()!=null){
            wrapper.set("provice",sinf.getProvice());
        }
        if(sinf.getCity()!=null){
            wrapper.set("city",sinf.getCity());
        }
        if(sinf.getCountry()!=null){
            wrapper.set("country",sinf.getCountry());
        }
        if(sinf.getStationName()!=null){
            wrapper.set("station_name",sinf.getStationName());
        }
        String fullName=sinf.getProvice()+"_"+sinf.getCity()+"_"+sinf.getCountry()+"_"+sinf.getStationName();
        wrapper.set("full_name",fullName);
        mapper.update((StationInf) ActionUtil.objeNull,wrapper);*/
        return new Response().set(1,true);
    }
    //查询机房
    public Response getPower(PowerDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        QueryWrapper wrapper=new QueryWrapper();
        if(dto.getProvice()!=null){
            wrapper.eq("provice",dto.getProvice());
        }
        if(dto.getCity()!=null){
            wrapper.eq("city",dto.getCity());
        }
        if(dto.getCountry()!=null){
            wrapper.eq("country",dto.getCountry());
        }
        if(dto.getStationName()!=null){
            wrapper.eq("station_name",dto.getStationName());
        }
        List<StationInf> list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询机房");
    }
}
src/main/java/com/whyc/service/StationInfService.java
@@ -6,11 +6,7 @@
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.dto.Station.Provice;
import com.whyc.dto.StationDto;
import com.whyc.mapper.BaojigroupMapper;
import com.whyc.mapper.StationInfMapper;
import com.whyc.pojo.db_station.StationInf;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -47,84 +43,4 @@
        List<String> list=mapper.getStationByUid(uid,stationName1,stationName2,stationName3);
        return new Response().setII(1,list.size()>0,list,"获取省市区县下的站点");
    }
    /*//添加机房
   public Response addStatiaon(StationInf addsinf) {
        //判断添加锁的时候机房是不是新机房
        String fullName=addsinf.getProvice()+"_"+addsinf.getCity()+"_"+addsinf.getCountry()+"_"+addsinf.getStationName();
        //判断机房是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("full_name",fullName);
        wrapper.last("limit 1");
        StationInf sinf=mapper.selectOne(wrapper);
        int stationId=0;
        if(sinf!=null){
            return new Response().set(1,false,"机房已存在");
        }else {
            //获取对应的机房id
            stationId=mapper.getMaxStationId();
            if(stationId==0){//数据库中没有站点
                stationId=40000001;
            }else{
                stationId+=1;
            }
            StationInf newSinf=new StationInf();
            newSinf.setStationId(stationId);
            newSinf.setStationName(fullName);
            newSinf.setProvice(addsinf.getProvice());
            newSinf.setCity(addsinf.getCity());
            newSinf.setCountry(addsinf.getCountry());
            newSinf.setStationName(addsinf.getStationName());
            mapper.insert(newSinf);
            return new Response().set(1,true,"添加机房");
        }
    }
    //删除机房
    public Response delStatiaon(Integer stationId) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("station_id",stationId);
        mapper.delete(wrapper);
        return new Response().set(1,true);
    }
    //修改机房
    public Response updateStatiaon(StationInf sinf) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("station_id",sinf.getStationId());
        if(sinf.getProvice()!=null){
            wrapper.set("provice",sinf.getProvice());
        }
        if(sinf.getCity()!=null){
            wrapper.set("city",sinf.getCity());
        }
        if(sinf.getCountry()!=null){
            wrapper.set("country",sinf.getCountry());
        }
        if(sinf.getStationName()!=null){
            wrapper.set("station_name",sinf.getStationName());
        }
        String fullName=sinf.getProvice()+"_"+sinf.getCity()+"_"+sinf.getCountry()+"_"+sinf.getStationName();
        wrapper.set("full_name",fullName);
        mapper.update((StationInf) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true);
    }
    //查询机房
    public Response getStatiaon(StationDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        QueryWrapper wrapper=new QueryWrapper();
        if(dto.getProvice()!=null){
            wrapper.eq("provice",dto.getProvice());
        }
        if(dto.getCity()!=null){
            wrapper.eq("city",dto.getCity());
        }
        if(dto.getCountry()!=null){
            wrapper.eq("country",dto.getCountry());
        }
        if(dto.getStationName()!=null){
            wrapper.eq("station_name",dto.getStationName());
        }
        List<StationInf> list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询机房");
    }
*/
}