123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- <?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.zoniot.ccrc.dao.DeviceMapper">
- <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.Device">
- <!--@mbg.generated-->
- <!--@Table sc_device-->
- <id column="id" property="id" />
- <result column="device_no" property="deviceNo" />
- <result column="meter_no" property="meterNo" />
- <result column="file_no" property="fileNo" />
- <result column="seal_no" property="sealNo" />
- <result column="site_id" property="siteId" />
- <result column="sys_id" property="sysId" />
- <result column="device_type_id" property="deviceTypeId" />
- <result column="manufacturer_id" property="manufacturerId" />
- <result column="building_id" property="buildingId" />
- <result column="community_id" property="communityId" />
- <result column="loc_desc" property="locDesc" />
- <result column="meter_reading" property="meterReading" />
- <result column="valve_status" property="valveStatus" />
- <result column="device_status" property="deviceStatus" />
- <result column="last_receive_time" property="lastReceiveTime" />
- <result column="status" property="status" />
- <result column="create_by" property="createBy" />
- <result column="date_create" property="dateCreate" />
- <result column="update_by" property="updateBy" />
- <result column="date_update" property="dateUpdate" />
- </resultMap>
- <sql id="Base_Column_List">
- <!--@mbg.generated-->
- id, device_no, meter_no, file_no, seal_no, site_id, sys_id, device_type_id, manufacturer_id,
- building_id, community_id, loc_desc, meter_reading, valve_status, device_status,
- last_receive_time, `status`, create_by, date_create, update_by, date_update
- </sql>
- <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.zoniot.ccrc.entity.Device" useGeneratedKeys="true">
- <!--@mbg.generated-->
- insert into sc_device
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="deviceNo != null">
- device_no,
- </if>
- <if test="meterNo != null">
- meter_no,
- </if>
- <if test="fileNo != null">
- file_no,
- </if>
- <if test="sealNo != null">
- seal_no,
- </if>
- <if test="siteId != null">
- site_id,
- </if>
- <if test="sysId != null">
- sys_id,
- </if>
- <if test="deviceTypeId != null">
- device_type_id,
- </if>
- <if test="manufacturerId != null">
- manufacturer_id,
- </if>
- <if test="buildingId != null">
- building_id,
- </if>
- <if test="communityId != null">
- community_id,
- </if>
- <if test="locDesc != null">
- loc_desc,
- </if>
- <if test="meterReading != null">
- meter_reading,
- </if>
- <if test="valveStatus != null">
- valve_status,
- </if>
- <if test="deviceStatus != null">
- device_status,
- </if>
- <if test="lastReceiveTime != null">
- last_receive_time,
- </if>
- <if test="status != null">
- `status`,
- </if>
- <if test="createBy != null">
- create_by,
- </if>
- <if test="dateCreate != null">
- date_create,
- </if>
- <if test="updateBy != null">
- update_by,
- </if>
- <if test="dateUpdate != null">
- date_update,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="deviceNo != null">
- #{deviceNo},
- </if>
- <if test="meterNo != null">
- #{meterNo},
- </if>
- <if test="fileNo != null">
- #{fileNo},
- </if>
- <if test="sealNo != null">
- #{sealNo},
- </if>
- <if test="siteId != null">
- #{siteId},
- </if>
- <if test="sysId != null">
- #{sysId},
- </if>
- <if test="deviceTypeId != null">
- #{deviceTypeId},
- </if>
- <if test="manufacturerId != null">
- #{manufacturerId},
- </if>
- <if test="buildingId != null">
- #{buildingId},
- </if>
- <if test="communityId != null">
- #{communityId},
- </if>
- <if test="locDesc != null">
- #{locDesc},
- </if>
- <if test="meterReading != null">
- #{meterReading},
- </if>
- <if test="valveStatus != null">
- #{valveStatus},
- </if>
- <if test="deviceStatus != null">
- #{deviceStatus},
- </if>
- <if test="lastReceiveTime != null">
- #{lastReceiveTime},
- </if>
- <if test="status != null">
- #{status},
- </if>
- <if test="createBy != null">
- #{createBy},
- </if>
- <if test="dateCreate != null">
- #{dateCreate},
- </if>
- <if test="updateBy != null">
- #{updateBy},
- </if>
- <if test="dateUpdate != null">
- #{dateUpdate},
- </if>
- </trim>
- </insert>
- <insert id="replaceSelective" keyColumn="id" keyProperty="id" parameterType="com.zoniot.ccrc.entity.Device" useGeneratedKeys="true">
- replace into sc_device
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="deviceNo != null">
- device_no,
- </if>
- <if test="meterNo != null">
- meter_no,
- </if>
- <if test="fileNo != null">
- file_no,
- </if>
- <if test="sealNo != null">
- seal_no,
- </if>
- <if test="siteId != null">
- site_id,
- </if>
- <if test="sysId != null">
- sys_id,
- </if>
- <if test="deviceTypeId != null">
- device_type_id,
- </if>
- <if test="manufacturerId != null">
- manufacturer_id,
- </if>
- <if test="buildingId != null">
- building_id,
- </if>
- <if test="communityId != null">
- community_id,
- </if>
- <if test="locDesc != null">
- loc_desc,
- </if>
- <if test="meterReading != null">
- meter_reading,
- </if>
- <if test="valveStatus != null">
- valve_status,
- </if>
- <if test="deviceStatus != null">
- device_status,
- </if>
- <if test="lastReceiveTime != null">
- last_receive_time,
- </if>
- <if test="status != null">
- `status`,
- </if>
- <if test="createBy != null">
- create_by,
- </if>
- <if test="dateCreate != null">
- date_create,
- </if>
- <if test="updateBy != null">
- update_by,
- </if>
- <if test="dateUpdate != null">
- date_update,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id},
- </if>
- <if test="deviceNo != null">
- #{deviceNo},
- </if>
- <if test="meterNo != null">
- #{meterNo},
- </if>
- <if test="fileNo != null">
- #{fileNo},
- </if>
- <if test="sealNo != null">
- #{sealNo},
- </if>
- <if test="siteId != null">
- #{siteId},
- </if>
- <if test="sysId != null">
- #{sysId},
- </if>
- <if test="deviceTypeId != null">
- #{deviceTypeId},
- </if>
- <if test="manufacturerId != null">
- #{manufacturerId},
- </if>
- <if test="buildingId != null">
- #{buildingId},
- </if>
- <if test="communityId != null">
- #{communityId},
- </if>
- <if test="locDesc != null">
- #{locDesc},
- </if>
- <if test="meterReading != null">
- #{meterReading},
- </if>
- <if test="valveStatus != null">
- #{valveStatus},
- </if>
- <if test="deviceStatus != null">
- #{deviceStatus},
- </if>
- <if test="lastReceiveTime != null">
- #{lastReceiveTime},
- </if>
- <if test="status != null">
- #{status},
- </if>
- <if test="createBy != null">
- #{createBy},
- </if>
- <if test="dateCreate != null">
- #{dateCreate},
- </if>
- <if test="updateBy != null">
- #{updateBy},
- </if>
- <if test="dateUpdate != null">
- #{dateUpdate},
- </if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective" parameterType="com.zoniot.ccrc.entity.Device">
- <!--@mbg.generated-->
- update sc_device
- <set>
- <if test="deviceNo != null">
- device_no = #{deviceNo},
- </if>
- <if test="meterNo != null">
- meter_no = #{meterNo},
- </if>
- <if test="fileNo != null">
- file_no = #{fileNo},
- </if>
- <if test="sealNo != null">
- seal_no = #{sealNo},
- </if>
- <if test="siteId != null">
- site_id = #{siteId},
- </if>
- <if test="sysId != null">
- sys_id = #{sysId},
- </if>
- <if test="deviceTypeId != null">
- device_type_id = #{deviceTypeId},
- </if>
- <if test="manufacturerId != null">
- manufacturer_id = #{manufacturerId},
- </if>
- <if test="buildingId != null">
- building_id = #{buildingId},
- </if>
- <if test="communityId != null">
- community_id = #{communityId},
- </if>
- <if test="locDesc != null">
- loc_desc = #{locDesc},
- </if>
- <if test="meterReading != null">
- meter_reading = #{meterReading},
- </if>
- <if test="valveStatus != null">
- valve_status = #{valveStatus},
- </if>
- <if test="deviceStatus != null">
- device_status = #{deviceStatus},
- </if>
- <if test="lastReceiveTime != null">
- last_receive_time = #{lastReceiveTime},
- </if>
- <if test="status != null">
- `status` = #{status},
- </if>
- <if test="createBy != null">
- create_by = #{createBy},
- </if>
- <if test="dateCreate != null">
- date_create = #{dateCreate},
- </if>
- <if test="updateBy != null">
- update_by = #{updateBy},
- </if>
- <if test="dateUpdate != null">
- date_update = #{dateUpdate},
- </if>
- </set>
- where id = #{id}
- </update>
- <update id="updateBatch" parameterType="java.util.List">
- <!--@mbg.generated-->
- update sc_device
- <trim prefix="set" suffixOverrides=",">
- <trim prefix="device_no = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.deviceNo}
- </foreach>
- </trim>
- <trim prefix="meter_no = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.meterNo}
- </foreach>
- </trim>
- <trim prefix="file_no = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.fileNo}
- </foreach>
- </trim>
- <trim prefix="seal_no = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.sealNo}
- </foreach>
- </trim>
- <trim prefix="site_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.siteId}
- </foreach>
- </trim>
- <trim prefix="sys_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.sysId}
- </foreach>
- </trim>
- <trim prefix="device_type_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.deviceTypeId}
- </foreach>
- </trim>
- <trim prefix="manufacturer_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.manufacturerId}
- </foreach>
- </trim>
- <trim prefix="building_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.buildingId}
- </foreach>
- </trim>
- <trim prefix="community_id = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.communityId}
- </foreach>
- </trim>
- <trim prefix="loc_desc = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.locDesc}
- </foreach>
- </trim>
- <trim prefix="meter_reading = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.meterReading}
- </foreach>
- </trim>
- <trim prefix="valve_status = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.valveStatus}
- </foreach>
- </trim>
- <trim prefix="device_status = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.deviceStatus}
- </foreach>
- </trim>
- <trim prefix="last_receive_time = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.lastReceiveTime}
- </foreach>
- </trim>
- <trim prefix="`status` = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.status}
- </foreach>
- </trim>
- <trim prefix="create_by = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.createBy}
- </foreach>
- </trim>
- <trim prefix="date_create = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.dateCreate}
- </foreach>
- </trim>
- <trim prefix="update_by = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.updateBy}
- </foreach>
- </trim>
- <trim prefix="date_update = case" suffix="end,">
- <foreach collection="list" index="index" item="item">
- when id = #{item.id} then #{item.dateUpdate}
- </foreach>
- </trim>
- </trim>
- where id in
- <foreach close=")" collection="list" item="item" open="(" separator=", ">
- #{item.id}
- </foreach>
- </update>
- <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
- <!--@mbg.generated-->
- insert into sc_device
- (device_no, meter_no, file_no, seal_no, site_id, sys_id, device_type_id, manufacturer_id,
- building_id, community_id, loc_desc, meter_reading, valve_status, device_status,
- last_receive_time, `status`, create_by, date_create, update_by, date_update)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.deviceNo}, #{item.meterNo}, #{item.fileNo}, #{item.sealNo}, #{item.siteId},
- #{item.sysId}, #{item.deviceTypeId}, #{item.manufacturerId}, #{item.buildingId},
- #{item.communityId}, #{item.locDesc}, #{item.meterReading}, #{item.valveStatus},
- #{item.deviceStatus}, #{item.lastReceiveTime}, #{item.status}, #{item.createBy},
- #{item.dateCreate}, #{item.updateBy}, #{item.dateUpdate})
- </foreach>
- </insert>
- <select id="getList" resultType="com.zoniot.ccrc.dto.DeviceDto">
- select
- sd.*,
- sb.name as building_name,
- sc.name as community_name,
- so.name as org_name,
- sdt.equipment_type,
- sdt.model,
- sdt.is_valve,
- sdm.name manufacturer_name,
- sgm.customer_no,
- sgm.customer_phone,
- sgm.customer_name,
- sgm.label,
- su.username
- from sc_device sd
- left join sc_building sb on(sb.id = sd.building_id)
- left join sc_community sc on(sc.id = sd.community_id)
- left join sc_organization so on(so.id = sc.org_id)
- left join sc_device_type sdt on(sdt.id = sd.device_type_id)
- left join sc_device_manufacturer sdm on(sdm.id = sd.manufacturer_id)
- left join sc_grid_management sgm on(sgm.device_id = sd.id)
- left join sc_user su on(su.id = sgm.user_id)
- where sd.status = 1
- <if test="siteId != null"> and sd.site_id = #{siteId}</if>
- <if test="userId != null"> and sgm.user_id = #{userId}</if>
- <if test="sysId != null"> and sd.sys_id = #{sysId}</if>
- <if test="deviceTypeId != null"> and sd.device_type_id = #{deviceTypeId}</if>
- <if test="orgId != null"> and sc.org_id = #{orgId}</if>
- <if test="province != null"> and sb.province = #{province}</if>
- <if test="city != null"> and sb.city = #{city}</if>
- <if test="region != null"> and sb.region = #{region}</if>
- <if test="communityId != null"> and sd.community_id = #{communityId}</if>
- <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
- <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%') or sd.file_no LIKE concat('%',#{deviceNo},'%'))</if>
- <if test="clientName != null and clientName != ''"> AND sgm.customer_name LIKE concat('%',#{clientName},'%')</if>
- <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
- <if test="status != null and status != ''"> and sd.device_status = #{status}</if>
- <if test="valveStatus != null"> and sd.valve_status = #{valveStatus}</if>
- <if test="communityIds != null and communityIds.size() != 0">
- and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <select id="deviceAreaList" resultType="com.zoniot.ccrc.dto.BuildingSelectInfoDto">
- select
- b.id,
- b.name,
- b.province,
- b.city,
- b.region,
- b.community_id as community,
- b.longitude,
- b.latitude,
- t1.device_count
- from sc_building b
- right join (
- select sd.building_id,count(1) as device_count
- from sc_device sd
- left join sc_grid_management sgm on(sgm.device_id = sd.id)
- <if test="province != null or city != null or region != null or communityId != null">left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)</if>
- <if test="orgId != null">left join sc_community sc on(sc.id = sd.community_id)</if>
- where sd.status = 1
- <if test="siteId != null"> and sd.site_id = #{siteId}</if>
- <if test="userId != null"> and sgm.user_id = #{userId}</if>
- <if test="sysId != null"> and sd.sys_id = #{sysId}</if>
- <if test="deviceTypeId != null"> and sd.device_type_id = #{deviceTypeId}</if>
- <if test="orgId != null"> and sc.org_id = #{orgId}</if>
- <if test="province != null"> and sb.province = #{province}</if>
- <if test="city != null"> and sb.city = #{city}</if>
- <if test="region != null"> and sb.region = #{region}</if>
- <if test="communityId != null"> and sd.community_id = #{communityId}</if>
- <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
- <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%') or sd.file_no LIKE concat('%',#{deviceNo},'%'))</if>
- <if test="clientName != null and clientName != ''"> AND sgm.customer_name LIKE concat('%',#{clientName},'%')</if>
- <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
- <if test="status != null and status != ''"> and sd.device_status = #{status}</if>
- <if test="valveStatus != null"> and sd.valve_status = #{valveStatus}</if>
- <if test="communityIds != null and communityIds.size() != 0">
- and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- GROUP BY sd.building_id
- ) t1 on (t1.building_id = b.id)
- where b.status = 1
- <if test="siteId != null"> and b.site_id=#{siteId} </if>
- </select>
- <select id="getDeviceIdByUserNumber" resultType="java.lang.Long">
- select b.id
- from sc_grid_management a
- inner join sc_device b on b.id=a.device_id where a.id=#{id}
- </select>
- <select id="getBuildingStatistics" resultType="com.zoniot.ccrc.dto.BuildingInfoListDto">
- select
- sb.id as building_id,
- sb.name as building_name,
- sb.address ,
- sb.province,
- sb.city,
- sb.region,
- sb.community_id as community,
- sa1.name as province_name,
- sa2.name as city_name,
- sa3.name as region_name,
- sc.name as community_name,
- sb.latitude,
- sb.longitude,
- temp.device_count,
- temp.normal_count,
- temp.alarm_count,
- temp.fault_count,
- temp.offline_count,
- temp.device_unused_count
- from sc_building sb
- LEFT JOIN(
- SELECT
- sd.building_id,
- <if test="sysId != null">sd.sys_id,</if>
- count(1) as device_count,
- SUM(IF(sd.device_status = 1, 1, 0)) as normal_count,
- SUM(IF(sd.device_status = 2, 1, 0)) as alarm_count,
- SUM(IF(sd.device_status = 3, 1, 0)) as fault_count,
- SUM(IF(sd.device_status = 4, 1, 0)) as offline_count,
- SUM(IF(sd.device_status = 5, 1, 0)) as device_unused_count
- from sc_device sd
- <if test="userId != null"> left join sc_grid_management scm on(scm.device_id = sd.id) </if>
- WHERE sd.status = 1
- <if test="siteId != null"> and sd.site_id = #{siteId} </if>
- <if test="sysId != null"> and sd.sys_id = #{sysId} </if>
- <if test="userId != null"> and scm.user_id = #{userId} </if>
- <if test="communityIds != null and communityIds.size() != 0"> and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach></if>
- GROUP BY sd.building_id <if test="sysId != null">,sd.sys_id</if>
- ) temp on (sb.id = temp.building_id)
- left join sc_area sa1 on sa1.id = sb.province
- left join sc_area sa2 on sa2.id = sb.city
- left join sc_area sa3 on sa3.id = sb.region
- left join sc_community sc on sc.id = sb.community_id
- where sb.status = 1
- <if test="siteId != null"> and sb.site_id = #{siteId} </if>
- <if test="sysId != null"> and temp.sys_id = #{sysId} </if>
- <if test="province != null"> AND sb.province = #{province}</if>
- <if test="city != null"> AND sb.city = #{city}</if>
- <if test="region != null"> AND sb.region = #{region}</if>
- <if test="community != null"> AND sb.community_id = #{community}</if>
- <if test="type != null and (type == 4 or type == 5) and longitudeMin != 0 and longitudeMax != 0"> and sb.longitude > #{longitudeMin} AND sb.longitude <![CDATA[ < ]]> #{longitudeMax} </if>
- <if test="type != null and (type == 4 or type == 5) and latitudeMin != 0 and latitudeMax != 0"> and sb.latitude > #{latitudeMin} AND sb.latitude <![CDATA[ < ]]> #{latitudeMax} </if>
- order by sb.update_date desc
- </select>
- </mapper>
|