|
@@ -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>
|