| | |
| | | |
| | | @ApiOperation(value = "修改区域") |
| | | @GetMapping("updateArea") |
| | | public Response updateArea(@RequestParam(required = false) Integer id,@RequestParam String areaName,@RequestParam(required = false) String areaDescript){ |
| | | return service.updateArea(id,areaName,areaDescript); |
| | | public Response updateArea(@RequestParam(required = false) Integer id,@RequestParam String areaName,@RequestParam String uname,@RequestParam(required = false) String areaDescript){ |
| | | return service.updateArea(id,areaName,uname,areaDescript); |
| | | } |
| | | /*@ApiOperation(value = "查询所在区域下所有用户信息") |
| | | @GetMapping("getUinfById") |
| | |
| | | return service.updateKey(kinf); |
| | | } |
| | | |
| | | @ApiOperation(value = "当前人所在区域的所有id卡钥匙") |
| | | @GetMapping("getKeyInAreaByIdCard") |
| | | public Response getKeyInAreaByIdCard(){ |
| | | return service.getKeyInAreaByIdCard(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.pojo.db_area.AreaUser; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface AreaUserMapper extends CustomMapper<AreaUser>{ |
| | | |
| | | } |
| | |
| | | private String idPath; |
| | | |
| | | @TableField(exist = false) |
| | | private List<UserInf> userInfs; |
| | | private List<AreaUser> areaUsers; |
| | | |
| | | } |
New file |
| | |
| | | package com.whyc.pojo.db_area; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | | @NoArgsConstructor |
| | | @TableName(schema = "db_area",value ="tb_area_user") |
| | | @ApiModel(value="AreaUser对象", description="") |
| | | public class AreaUser { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @TableId(value = "num", type = IdType.AUTO) |
| | | private Integer num; |
| | | |
| | | @ApiModelProperty(value = "area_id") |
| | | private Integer areaId; |
| | | |
| | | @ApiModelProperty(value = "归属人id") |
| | | private Integer uid; |
| | | |
| | | @ApiModelProperty(value = "归属人") |
| | | private String uname; |
| | | } |
| | |
| | | @ApiModelProperty(value = "keyid") |
| | | private Integer keyId; |
| | | |
| | | @ApiModelProperty(value = "区域id") |
| | | private Integer areaId; |
| | | |
| | | @ApiModelProperty(value = "归属人") |
| | | private String uname; |
| | | |
| | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | @ApiModelProperty(value = "管理的区域id:管理区域-1超级管理员,0普通用户") |
| | | private Integer areaId; |
| | | |
| | | |
| | | @ApiModelProperty(value = "电话号码") |
| | | private String phoneNumber; |
| | | |
| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.db_area.AreaInf; |
| | | import com.whyc.pojo.db_area.AreaUser; |
| | | import com.whyc.pojo.db_area.KeyInf; |
| | | import com.whyc.pojo.db_area.LockInf; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | |
| | | @Autowired(required = false) |
| | | private LockCtlLogMapper ctlLogMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private AreaUserService areaUserService; |
| | | |
| | | //查看当前用户管理的所有区域 |
| | | public List getAllAreaUser(int uid,int urole){ |
| | | //获取用户所管理的区域 |
| | | List<Integer> list =areaUserService.setAreaId(uid); |
| | | List areaList=new ArrayList(); |
| | | if (urole==1) { |
| | | for (Integer aid:list) { |
| | | List list1=new ArrayList(); |
| | | getAllAreaId(aid, list1); |
| | | areaList.addAll(list1); |
| | | } |
| | | } |
| | | return areaList; |
| | | } |
| | | |
| | | //查询所有区域信息 |
| | | public Response getAllAreaInf() { |
| | | /*UserInf uinf=new UserInf(); |
| | | uinf.setUname("test_admin"); |
| | | uinf.setUid(105); |
| | | uinf.setUrole(2); |
| | | uinf.setAreaId(3);*/ |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | if(uinf.getUrole()!=2) {//当前用户不是超级管理员 |
| | | //查询出当前用户所在区域 |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.eq("id", uinf.getAreaId()); |
| | | wrapper.last("limit 1"); |
| | | AreaInf ainf = mapper.selectOne(wrapper); |
| | | List areaList = new ArrayList(); |
| | | if (ainf != null) { |
| | | areaList.add(ainf.getId()); |
| | | getAllAreaId(ainf.getId(), areaList); |
| | | } |
| | | List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | List<AreaInf> list1 = mapper.selectAreaByUid(areaList, 1); |
| | | return new Response().setII(1, list1 != null, list1, "查询当前用户的所有信息"); |
| | | }else { |
| | |
| | | mapper.delete(wrapper1); |
| | | } |
| | | //修改区域 |
| | | public Response updateArea(Integer id, String areaName, String areaDescript) { |
| | | @Transactional |
| | | public Response updateArea(Integer id, String areaName, String uname, String areaDescript) { |
| | | //改区域 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("id",id); |
| | | wrapper.last("limit 1"); |
| | |
| | | wrapper1.eq("id",id); |
| | | mapper.update(ainf,wrapper1); |
| | | updateAll(id,newPath); |
| | | // |
| | | return new Response().set(1,true); |
| | | } |
| | | public void updateAll(Integer id, String newPath) { |
| | |
| | | public Response getInfByAreaManage() { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | UserInf uinf=ActionUtil.getUser(); |
| | | List areaList=new ArrayList(); |
| | | areaList.add(uinf.getAreaId()); |
| | | getAllAreaId(uinf.getAreaId(),areaList); |
| | | List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | //通过区域id查询所有的锁 |
| | | QueryWrapper linfWrapper=new QueryWrapper(); |
| | | linfWrapper.in("area_id",areaList); |
| | |
| | | //区域管理员点击管理的区域跳转--区域管理员 |
| | | public Response getAinfByManage() { |
| | | UserInf uinf=ActionUtil.getUser(); |
| | | List areaList=new ArrayList(); |
| | | areaList.add(uinf.getAreaId()); |
| | | getAllAreaId(uinf.getAreaId(),areaList); |
| | | |
| | | List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.in("id",areaList); |
| | | wrapper.orderByAsc("id"); |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.whyc.mapper.AreaUserMapper; |
| | | import com.whyc.pojo.db_area.AreaUser; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class AreaUserService { |
| | | @Autowired(required = false) |
| | | private AreaUserMapper mapper; |
| | | |
| | | |
| | | |
| | | //获取用户所管理的区域 |
| | | public List setAreaId(int uid) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("uid",uid); |
| | | List<AreaUser> list=mapper.selectList(wrapper); |
| | | List areaList=list.stream().map(AreaUser::getAreaId) // 提取id |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return areaList; |
| | | } |
| | | } |
| | |
| | | //根据mac检测蓝牙锁是否有权限 |
| | | public Response getAuthByUidAndMac(Integer mac) { |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | List areaList=new ArrayList(); |
| | | areaList.add(uinf.getAreaId()); |
| | | areaInfService.getAllAreaId(uinf.getAreaId(),areaList); |
| | | List areaList=areaInfService.getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | //获取锁是否在人管理的区域下面 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("lock_mac",mac); |
| | |
| | | wrapper.like("uname",uname); |
| | | } |
| | | wrapper.ne("key_id",0); |
| | | /*List areaList=new ArrayList(); |
| | | areaList.add(areaId); |
| | | areaInfService.getAllAreaId(areaId,areaList); |
| | | if(areaList!=null){ |
| | | wrapper.in("area_id",areaList); |
| | | }*/ |
| | | List<KeyInf> list=mapper.selectList(wrapper); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询所有钥匙信息"); |
| | |
| | | }else { |
| | | UpdateWrapper wrapper = new UpdateWrapper(); |
| | | wrapper.eq("key_id", kinf.getKeyId()); |
| | | if (kinf.getAreaId() != null) { |
| | | wrapper.set("area_id", kinf.getAreaId()); |
| | | } |
| | | if (kinf.getKeyName() != null) { |
| | | wrapper.set("key_name", kinf.getKeyName()); |
| | | } |
| | |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return new Response().setII(1,list!=null,lnameList,"查询所有钥匙名信息(用于下拉)"); |
| | | } |
| | | //当前人所在区域的所有id卡钥匙 |
| | | public Response getKeyInAreaByIdCard() { |
| | | //获取当前用户管理的区域 |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | List areaList=new ArrayList(); |
| | | areaList.add(uinf.getAreaId()); |
| | | areaInfService.getAllAreaId(uinf.getAreaId(),areaList); |
| | | //查询区域下的钥匙 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.in("area_id",areaList); |
| | | wrapper.eq("key_type",1); |
| | | List<KeyInf> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"当前人所在区域的所有id卡钥匙"); |
| | | } |
| | | |
| | | } |
| | |
| | | areaInfService.getAllAreaId(areaId,areaList); |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<UserInf> list=mapper.getAllUser(uname,realName,uinf.getUrole(),areaList); |
| | | for (UserInf u:list) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("id",u.getAreaId()); |
| | | wrapper.last("limit 1"); |
| | | AreaInf ainf=ainfMapper.selectOne(wrapper); |
| | | u.setAinf(ainf); |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"数据返回"); |
| | | } |
| | |
| | | if(uinf.getPhoneNumber()!=null){ |
| | | wrapper.set("phone_number",uinf.getPhoneNumber()); |
| | | } |
| | | if(uinf.getAreaId()!=null){ |
| | | /* if(uinf.getAreaId()!=null){ |
| | | wrapper.set("area_id",uinf.getAreaId()); |
| | | } |
| | | }*/ |
| | | if(uinf.getUrole()!=null){ |
| | | wrapper.set("urole",uinf.getUrole()); |
| | | } |
| | |
| | | <result property="areaPath" column="area_path"></result> |
| | | <result property="areaLevel" column="area_level"></result> |
| | | <result property="areaDescript" column="area_descript"></result> |
| | | <collection property="userInfs" javaType="java.util.ArrayList" ofType="com.whyc.pojo.db_user.UserInf" column="{id=id}" select="selectUinfByAreaId"> |
| | | <collection property="areaUsers" javaType="java.util.ArrayList" ofType="com.whyc.pojo.db_area.AreaUser" column="{areaId=id}" select="selectUinfByAreaId"> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | |
| | | order by id asc |
| | | </select> |
| | | <select id="selectUinfByAreaId" resultType="userInf"> |
| | | select uid,uname,area_id from db_user.tb_user_inf |
| | | where area_id=#{id} |
| | | select uid,uname,area_id from db_area.tb_area_user |
| | | where area_id=#{areaId} |
| | | </select> |
| | | </mapper> |