瀏覽代碼

网格管理提交

hym 4 年之前
父節點
當前提交
865fc583af

+ 95 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/GridManagementMapper.java

@@ -0,0 +1,95 @@
+package com.bz.smart_city.dao;
+
+import com.bz.smart_city.entity.Building;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.GridManagement;
+import com.bz.smart_city.grid.GridUser;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * (GridManagement)表数据库访问层
+ *
+ * @author hym
+ * @since 2021-02-23 11:48:07
+ */
+@Mapper
+public interface GridManagementMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    GridManagement selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<GridManagement> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param gridManagement 实例对象
+     * @return 对象列表
+     */
+    List<GridManagement> selectList(GridManagement gridManagement);
+
+    /**
+     * 新增数据
+     *
+     * @param gridManagement 实例对象
+     * @return 影响行数
+     */
+    int insert(GridManagement gridManagement);
+
+    /**
+     * 批量新增
+     *
+     * @param gridManagements 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("gridManagements") List<GridManagement> gridManagements);
+
+    /**
+     * 修改数据
+     *
+     * @param gridManagement 实例对象
+     * @return 影响行数
+     */
+    int update(GridManagement gridManagement);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    List<GridUser> selectGirdUserInfo(@Param("username") String username,
+                                      @Param("orgId")Integer orgId,
+                                      @Param("roleId") Integer roleId);
+
+    List<Community> getCommutityByOrg(@Param("orgId") Integer orgId);
+
+    List<Building> getBuildingByCommutity(@Param("commutityId") Integer commutityId);
+
+    List<Device> getDevices(@Param("buildingId") Integer buildingId,
+                            @Param("userId") Integer userId);
+}

+ 75 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/GridManagement.java

@@ -0,0 +1,75 @@
+package com.bz.smart_city.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * (GridManagement)实体类
+ *
+ * @author hym
+ * @since 2021-02-23 11:48:07
+ */
+@Data
+@ApiModel
+public class GridManagement implements Serializable {
+    private static final long serialVersionUID = 458833882113660963L;
+    /**
+     * 主键
+     */
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+    /**
+     * 设备id
+     */
+    @ApiModelProperty(value = "设备id")
+    private Long deviceId;
+    /**
+     * 客户编号
+     */
+    @ApiModelProperty(value = "客户编号")
+    private String customerNo;
+    /**
+     * 客户手机
+     */
+    @ApiModelProperty(value = "客户手机")
+    private String customerPhone;
+    /**
+     * 客户名称
+     */
+    @ApiModelProperty(value = "客户名称")
+    private String customerName;
+    /**
+     * 标签
+     */
+    @ApiModelProperty(value = "标签")
+    private String label;
+    /**
+     * 紧急联系人
+     */
+    @ApiModelProperty(value = "紧急联系人")
+    private String emergencyContact;
+    /**
+     * 紧急联系人电话
+     */
+    @ApiModelProperty(value = "紧急联系人电话")
+    private String emergencyContactPhoneNumber;
+    /**
+     * 用户id
+     */
+    @ApiModelProperty(value = "用户id")
+    private Integer userId;
+    @ApiModelProperty(value = "水表电子号")
+    private String waterMeterNo;
+    @ApiModelProperty(value = "水表档案号")
+    private String waterMeterFileNo;
+    @ApiModelProperty(value = "机构")
+    private String orgName;
+    @ApiModelProperty(value = "建筑")
+    private String bulidingName;
+    @ApiModelProperty(value = "安装地址")
+    private String address;
+
+}

+ 10 - 0
smart-city-platform/src/main/java/com/bz/smart_city/grid/GridInfo.java

@@ -0,0 +1,10 @@
+package com.bz.smart_city.grid;
+
+import lombok.Data;
+
+import java.util.List;
+@Data
+public class GridInfo {
+    private Integer userId;
+    private List<Long> deviceIds;
+}

+ 170 - 0
smart-city-platform/src/main/java/com/bz/smart_city/grid/GridManagementController.java

@@ -0,0 +1,170 @@
+package com.bz.smart_city.grid;
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.entity.Building;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.GridManagement;
+
+
+import com.github.pagehelper.PageHelper;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * (GridManagement)控制层
+ *
+ * @author hym
+ * @since 2021-02-23 11:47:59
+ */
+@RestController
+@RequestMapping("/gridManagement")
+@Api(tags = "网格管理")
+public class GridManagementController {
+    /**
+     * 服务对象
+     */
+    @Autowired
+    private GridManagementService gridManagementService;
+
+
+
+    /**
+     * 新增一条数据
+     *
+     * @param gridInfo 实体类
+     * @return Response对象
+     */
+    @RequestMapping(value = "insert", method = RequestMethod.POST)
+    @ApiOperation(value = "插入网格管理户表信息")
+    public AjaxMessage<Integer> insert(@ApiParam(value = "设置配置", required = true) @RequestBody GridInfo gridInfo) {
+        int result = gridManagementService.insert(gridInfo);
+
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    /**
+     * 修改一条数据
+     *
+     * @param gridManagement 实体类
+     * @return Response对象
+     */
+    @RequestMapping(value = "update", method = RequestMethod.POST)
+    @ApiOperation(value = "更改网格户表信息")
+    public AjaxMessage<Integer> update(@ApiParam(value = "设置配置", required = true) @RequestBody GridManagement gridManagement) {
+        int result = gridManagementService.update(gridManagement);
+        return new AjaxMessage<>(ResultStatus.OK, result);
+
+    }
+
+    /**
+     * 删除一条数据
+     *
+     * @param gridManagement 参数对象
+     * @return Response对象
+     */
+    @RequestMapping(value = "delete", method = RequestMethod.POST)
+    @ApiOperation(value = "查询设施配置列表")
+    public AjaxMessage<Integer> delete(@ApiParam(value = "设置配置", required = true) @RequestBody GridManagement gridManagement) {
+        int result = gridManagementService.deleteById(gridManagement.getId());
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+
+    /**
+     * 分页查询
+     *
+     * @param pageNum  偏移
+     * @param pageSize 条数
+     * @return Response对象
+     */
+    @RequestMapping(value = "selectPage", method = RequestMethod.POST)
+    @ApiOperation(value = "查询网格管理列表")
+    public AjaxMessage<Pagination<GridManagement>> selectPage(Integer pageNum, Integer pageSize,
+                                                              Integer userId,String waterNo
+            ,String adddress,String name) {
+        GridManagement gridManagement = new GridManagement();
+        gridManagement.setAddress(adddress);
+        gridManagement.setUserId(userId);
+        gridManagement.setWaterMeterNo(waterNo);
+        gridManagement.setCustomerName(name);
+        PageHelper.startPage(pageNum, pageSize);
+        List<GridManagement> gridManagements = gridManagementService.selectList(gridManagement);
+        Pagination<GridManagement> pages = new Pagination<>(gridManagements);
+        return new AjaxMessage<>(ResultStatus.OK, pages);
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param pageNum  偏移
+     * @param pageSize 条数
+     * @return Response对象
+     */
+    @RequestMapping(value = "selectGridPage", method = RequestMethod.POST)
+    @ApiOperation(value = "查询网格管理列表")
+    public AjaxMessage<Pagination<GridUser>> selectGridPage(Integer pageNum, Integer pageSize,
+                                                        String name, Integer orgId) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<GridUser>gridUsers=gridManagementService.selectGirdUserInfo(name,orgId);
+        Pagination<GridUser> pages = new Pagination<>(gridUsers);
+        return new AjaxMessage<>(ResultStatus.OK, pages);
+    }
+    /**
+     * 分页查询
+     *
+     * @param
+     * @param
+     * @return Response对象
+     */
+    @RequestMapping(value = "getCommutityByOrg", method = RequestMethod.POST)
+    @ApiOperation(value = "查询小区信息")
+    public AjaxMessage<List<Community>> selectGridPage(Integer orgId) {
+
+        List<Community>communities=gridManagementService.getCommutityByOrg(orgId);
+
+        return new AjaxMessage<>(ResultStatus.OK, communities);
+    }
+    /**
+     * 分页查询
+     *
+     * @param
+     * @param
+     * @return Response对象
+     */
+    @RequestMapping(value = "getBuildingByCommutity", method = RequestMethod.POST)
+    @ApiOperation(value = "查询建筑信息")
+    public AjaxMessage<List<Building>> getBuildingByCommutity(Integer commutityId) {
+
+        List<Building>buildings=gridManagementService.getBuildingByCommutity(commutityId);
+
+        return new AjaxMessage<>(ResultStatus.OK, buildings);
+    }
+    /**
+     * 分页查询
+     *
+     * @param
+     * @param
+     * @return Response对象
+     */
+    @RequestMapping(value = "getDevices", method = RequestMethod.POST)
+    @ApiOperation(value = "查询建筑信息")
+    public AjaxMessage<List<Device>> getDevices(Integer buildingId,Integer userId) {
+
+        List<Device>devices=gridManagementService.getDevices(buildingId,userId);
+
+        return new AjaxMessage<>(ResultStatus.OK, devices);
+    }
+}

+ 89 - 0
smart-city-platform/src/main/java/com/bz/smart_city/grid/GridManagementService.java

@@ -0,0 +1,89 @@
+package com.bz.smart_city.grid;
+
+import com.bz.smart_city.entity.Building;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.GridManagement;
+
+import java.util.List;
+
+
+/**
+ * (GridManagement)表服务接口
+ *
+ * @author hym
+ * @since 2021-02-23 11:48:06
+ */
+public interface GridManagementService {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    GridManagement selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<GridManagement> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param gridManagement 实例对象
+     * @return 对象列表
+     */
+    List<GridManagement> selectList(GridManagement gridManagement);
+
+    /**
+     * 新增数据
+     *
+     * @param gridManagement 实例对象
+     * @return 影响行数
+     */
+    int insert(GridInfo gridManagement);
+
+    /**
+     * 批量新增
+     *
+     * @param gridManagements 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(List<GridManagement> gridManagements);
+
+    /**
+     * 修改数据
+     *
+     * @param gridManagement 实例对象
+     * @return 修改
+     */
+    int update(GridManagement gridManagement);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    List<GridUser> selectGirdUserInfo(String name, Integer orgId);
+
+    List<Community> getCommutityByOrg(Integer orgId);
+
+    List<Building> getBuildingByCommutity(Integer commutityId);
+
+    List<Device> getDevices(Integer buildingId,Integer userId);
+}

+ 148 - 0
smart-city-platform/src/main/java/com/bz/smart_city/grid/GridManagementServiceImpl.java

@@ -0,0 +1,148 @@
+package com.bz.smart_city.grid;
+
+import com.bz.smart_city.dao.GridManagementMapper;
+import com.bz.smart_city.entity.Building;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.GridManagement;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * (GridManagement表)服务实现类
+ *
+ * @author hym
+ * @since 2021-02-23 11:48:08
+ */
+@Service("gridManagementService")
+public class GridManagementServiceImpl implements GridManagementService {
+    @Autowired
+    private GridManagementMapper gridManagementMapper;
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    @Override
+    public GridManagement selectById(Integer id) {
+        return this.gridManagementMapper.selectById(id);
+    }
+
+
+    /**
+     * 查询所有
+     *
+     * @return 实例对象的集合
+     */
+    @Override
+    public List<GridManagement> selectAll() {
+        return this.gridManagementMapper.selectAll();
+    }
+
+    /**
+     * 根据条件查询
+     *
+     * @return 实例对象的集合
+     */
+    @Override
+    public List<GridManagement> selectList(GridManagement gridManagement) {
+        return this.gridManagementMapper.selectList(gridManagement);
+    }
+
+    /**
+     * 新增数据
+     *
+     * @param gridInfo 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public int insert(GridInfo gridInfo) {
+        Integer userId = gridInfo.getUserId();
+        List<Long> deviceIds = gridInfo.getDeviceIds();
+        List<GridManagement> gridManagements=new ArrayList<>();
+        deviceIds.forEach(deviceId->{
+            GridManagement gridManagement=new GridManagement();
+            gridManagement.setUserId(userId);
+            gridManagement.setDeviceId(deviceId);
+            gridManagements.add(gridManagement);
+        });
+        if(gridManagements.size()>0)
+        gridManagementMapper.batchInsert(gridManagements);
+        return 1;
+    }
+
+    /**
+     * 批量新增
+     *
+     * @param gridManagements 实例对象的集合
+     * @return 生效的条数
+     */
+    @Override
+    public int batchInsert(List<GridManagement> gridManagements) {
+        return this.gridManagementMapper.batchInsert(gridManagements);
+    }
+
+    /**
+     * 修改数据
+     *
+     * @param gridManagement 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public int update(GridManagement gridManagement) {
+
+        return this.gridManagementMapper.update(gridManagement);
+    }
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 是否成功
+     */
+    @Override
+    public int deleteById(Integer id) {
+        return this.gridManagementMapper.deleteById(id);
+    }
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    @Override
+    public int count() {
+        return this.gridManagementMapper.count();
+    }
+
+    @Override
+    public List<GridUser> selectGirdUserInfo(String name, Integer orgId) {
+        Integer roleId=108;
+        List<GridUser> users=gridManagementMapper.selectGirdUserInfo(name,orgId,roleId);
+        return users;
+    }
+
+    @Override
+    public List<Community> getCommutityByOrg(Integer orgId) {
+        List<Community> communities=gridManagementMapper.getCommutityByOrg(orgId);
+        return communities;
+    }
+
+    @Override
+    public List<Building> getBuildingByCommutity(Integer commutityId) {
+        List<Building>buildings= gridManagementMapper.getBuildingByCommutity( commutityId);
+        return buildings;
+    }
+
+    @Override
+    public List<Device> getDevices(Integer buildingId,Integer userId) {
+        List<Device> devices=gridManagementMapper.getDevices(buildingId,userId);
+        return devices;
+    }
+
+}

+ 24 - 0
smart-city-platform/src/main/java/com/bz/smart_city/grid/GridUser.java

@@ -0,0 +1,24 @@
+package com.bz.smart_city.grid;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class GridUser {
+    @ApiModelProperty(value = "id")
+    private Integer id;
+    @ApiModelProperty(value = "用户名")
+    private String username;
+    @ApiModelProperty(value = "姓名")
+    private String mobilePhone;
+    @ApiModelProperty(value = "手机号")
+    private String name;
+    @ApiModelProperty(value = "机构名称")
+    private String orgName;
+    @ApiModelProperty(value = "地址")
+    private String address;
+    @ApiModelProperty(value = "管理户表")
+    private Integer peoples;
+    @ApiModelProperty(value = "机构id")
+    private Integer orgId;
+}

+ 177 - 0
smart-city-platform/src/main/resources/mapper/GridManagementMapper.xml

@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.GridManagementMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.bz.smart_city.entity.GridManagement" id="GridManagementMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
+        <result property="customerNo" column="customer_no" jdbcType="VARCHAR"/>
+        <result property="customerPhone" column="customer_phone" jdbcType="VARCHAR"/>
+        <result property="customerName" column="customer_name" jdbcType="VARCHAR"/>
+        <result property="label" column="label" jdbcType="VARCHAR"/>
+        <result property="emergencyContact" column="emergency_contact" jdbcType="VARCHAR"/>
+        <result property="emergencyContactPhoneNumber" column="emergency_contact_phone_number" jdbcType="VARCHAR"/>
+        <result property="userId" column="user_id" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, device_id, customer_no, customer_phone, customer_name, label, emergency_contact, emergency_contact_phone_number, user_id    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="GridManagementMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_grid_management
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="GridManagementMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_grid_management
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="GridManagementMap">
+        select
+         a.*,b.water_meter_no,b.water_meter_file_no,b.loc_desc address,c.name bulidingName,
+         e.name orgName
+        from sc_grid_management a join sc_device b on a.device_id=b.id
+        join sc_building c on b.building_id=c.id join sc_community d on c.community =d.id
+        left join sc_organization e on d.org_id=e.id
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="deviceId != null">
+                and device_id = #{deviceId}
+            </if>
+            <if test="customerNo != null and customerNo != ''">
+                and customer_no = #{customerNo}
+            </if>
+            <if test="customerPhone != null and customerPhone != ''">
+                and customer_phone = #{customerPhone}
+            </if>
+            <if test="customerName != null and customerName != ''">
+                and customer_name LIKE concat('%',#{customerName},'%')
+            </if>
+            <if test="label != null and label != ''">
+                and label = #{label}
+            </if>
+            <if test="emergencyContact != null and emergencyContact != ''">
+                and emergency_contact = #{emergencyContact}
+            </if>
+            <if test="emergencyContactPhoneNumber != null and emergencyContactPhoneNumber != ''">
+                and emergency_contact_phone_number = #{emergencyContactPhoneNumber}
+            </if>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+            <if test="address != null and address !=''">
+                and b.loc_desc LIKE concat('%',#{address},'%')
+            </if>
+            <if test="waterMeterNo != null and waterMeterNo !=''">
+                and ( b.water_meter_no LIKE concat('%',#{waterMeterNo},'%') or
+                      b.water_meter_file_no LIKE concat('%',#{waterMeterNo},'%'))
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into sc_grid_management(id, device_id, customer_no, customer_phone, customer_name, label,
+                                       emergency_contact, emergency_contact_phone_number, user_id)
+        values (#{id}, #{deviceId}, #{customerNo}, #{customerPhone}, #{customerName}, #{label}, #{emergencyContact},
+                #{emergencyContactPhoneNumber}, #{userId})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into sc_grid_management(id, device_id, customer_no, customer_phone, customer_name, label,
+        emergency_contact, emergency_contact_phone_number, user_id)
+        values
+        <foreach collection="gridManagements" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.deviceId}, #{item.customerNo}, #{item.customerPhone}, #{item.customerName},
+            #{item.label}, #{item.emergencyContact}, #{item.emergencyContactPhoneNumber}, #{item.userId} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update sc_grid_management
+        <set>
+            <if test="deviceId != null">
+                device_id = #{deviceId},
+            </if>
+            <if test="customerNo != null and customerNo != ''">
+                customer_no = #{customerNo},
+            </if>
+            <if test="customerPhone != null and customerPhone != ''">
+                customer_phone = #{customerPhone},
+            </if>
+            <if test="customerName != null and customerName != ''">
+                customer_name = #{customerName},
+            </if>
+            <if test="label != null and label != ''">
+                label = #{label},
+            </if>
+            <if test="emergencyContact != null and emergencyContact != ''">
+                emergency_contact = #{emergencyContact},
+            </if>
+            <if test="emergencyContactPhoneNumber != null and emergencyContactPhoneNumber != ''">
+                emergency_contact_phone_number = #{emergencyContactPhoneNumber},
+            </if>
+            <if test="userId != null">
+                user_id = #{userId},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from sc_grid_management
+        where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from sc_grid_management
+    </select>
+    <select id="selectGirdUserInfo" resultType="com.bz.smart_city.grid.GridUser">
+        select b.id orgId,a.id,username,mobile_phone,a.name,b.name org_name,b.address,c.peoples from
+         sc_user a join sc_organization b on a.organ_id=b.id
+         join sc_user_role d on d.uid=a.id join sc_role e on e.id=d.rid
+         left join (select count(*)peoples,user_id from sc_grid_management group by user_id)c
+         on a.id=c.user_id
+        <where>
+            <if test="username != null and username!='' ">
+                and username LIKE concat('%',#{username},'%')
+            </if>
+            <if test="orgId != null  ">
+                and a.organ_id = #{orgId}
+            </if>
+            <if test="roleId != null  ">
+                and e.id = #{roleId}
+            </if>
+       </where>
+    </select>
+    <select id="getCommutityByOrg" resultType="com.bz.smart_city.entity.Community">
+        select * from sc_community a
+        where a.org_id=#{orgId}
+    </select>
+    <select id="getBuildingByCommutity" resultType="com.bz.smart_city.entity.Building">
+        select * from sc_building where community=#{commutityId}
+    </select>
+    <select id="getDevices" resultType="com.bz.smart_city.entity.Device">
+        select * from sc_device where building_id=#{buildingId} and
+         id not in (select distinct device_id from sc_grid_management where user_id=#{userId})
+    </select>
+
+</mapper>