123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?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.huaxu.dao.DeviceMapper">
- <sql id="Base_Column_List">
- d.id
- ,d.TENANT_ID as "tenantId"
- ,d.DEVICE_CODE as "deviceCode"
- ,d.DEVICE_NAME as "deviceName"
- ,d.DEVICE_TYPE_ID as "deviceTypeId"
- ,d.COMPANY_ORG_ID as "companyOrgId"
- ,d.DEPT_ORG_ID as "deptOrgId"
- ,d.SCENE_ID as "sceneId"
- ,d.POINT_X as "pointX"
- ,d.POINT_Y as "pointY"
- ,d.ENABLE_STATE as "enableState"
- ,d.LAST_UPDATE_TIME as "lastUpdateTime"
- ,d.ADDRESS as "address"
- ,d.REMARK as "remark"
- ,d.`STATUS` as "status"
- ,d.DATE_CREATE as "dateCreate"
- ,d.CREATE_BY as "createBy"
- ,d.DATE_UPDATE as "dateUpdate"
- ,d.UPDATE_BY as "updateBy"
- ,s.SCENE_NAME as "sceneName"
- ,t.MANUFACTURER_NAME as "manufacturerName"
- ,t.MANUFACTURER_ID as "manufacturerId"
- ,t.DEVICE_TYPE as "deviceType"
- ,t.DEVICE_MODE as "deviceMode"
- </sql>
- <sql id="deviceJoins">
- left join sms_scene s on d.SCENE_ID =s.id
- left join sms_device_type t on d.DEVICE_TYPE_ID = t.id
- </sql>
- <select id="selectById" resultType="com.huaxu.dto.DeviceDto">
- select
- <include refid="Base_Column_List"/>
- from sms_device d
- <include refid="deviceJoins"/>
- where d.ID = #{id} and d.status = 1
- </select>
- <select id="selectByIds" resultType="com.huaxu.dto.DeviceDto">
- select
- <include refid="Base_Column_List"/>
- from sms_device d
- <include refid="deviceJoins"/>
- where d.status = 1
- and d.id in
- <foreach collection="ids" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </select>
- <!--通过实体作为筛选条件查询-->
- <select id="selectList" resultType="com.huaxu.dto.DeviceDto">
- select
- <include refid="Base_Column_List"/>
- from sms_device d
- <include refid="deviceJoins"/>
- where d.status = 1
- <if test="deviceDto.tenantId != null and deviceDto.tenantId != '' ">
- and d.tenant_id = #{deviceDto.tenantId}
- </if>
- <if test="deviceDto.condition != null and deviceDto.condition != ''">
- and (device_code like concat('%', #{deviceDto.condition},'%') or device_name like concat('%', #{deviceDto.condition},'%'))
- </if>
- <if test="deviceDto.companyOrgId != null and deviceDto.companyOrgId != 0 ">
- and d.COMPANY_ORG_ID=#{deviceDto.companyOrgId}
- </if>
- <if test="deviceDto.deptOrgId != null and deviceDto.deptOrgId != 0 ">
- and d.DEPT_ORG_ID =#{deviceDto.deptOrgId}
- </if>
- <if test="deviceDto.sceneIds != null and deviceDto.sceneIds.size() > 0">
- and d.SCENE_ID in
- <foreach collection="deviceDto.sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="deviceDto.enableState != null ">
- and d.ENABLE_STATE =#{deviceDto.enableState}
- </if>
- <if test="deviceDto.userType!=null and deviceDto.userType!=-999 and deviceDto.userType!=-9999 and deviceDto.programItems != null and deviceDto.programItems.size() > 0">
- <if test="deviceDto.permissonType == 5 or deviceDto.permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="deviceDto.permissonType == 4 or deviceDto.permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="deviceDto.permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- </select>
- <!-- 新增所有列 -->
- <insert id="insert" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO sms_device ( TENANT_ID , DEVICE_CODE , DEVICE_NAME , DEVICE_TYPE_ID ,
- <if test="companyOrgId != null and companyOrgId != 0">COMPANY_ORG_ID , </if>
- <if test="deptOrgId != null and deptOrgId != 0">DEPT_ORG_ID ,</if>
- <if test="sceneId != null and sceneId != 0">SCENE_ID ,</if>
- POINT_X , POINT_Y , ENABLE_STATE , LAST_UPDATE_TIME , ADDRESS , REMARK , STATUS , DATE_CREATE , CREATE_BY , DATE_UPDATE , UPDATE_BY )
- VALUES ( #{tenantId} ,#{deviceCode} ,#{deviceName} ,#{deviceTypeId} ,
- <if test="companyOrgId != null and companyOrgId != 0">#{companyOrgId} , </if>
- <if test="deptOrgId != null and deptOrgId != 0"> #{deptOrgId} , </if>
- <if test="sceneId != null and sceneId != 0">#{sceneId} , </if>
- #{pointX} ,#{pointY} ,#{enableState} ,#{lastUpdateTime} ,#{address} ,#{remark} ,#{status} ,#{dateCreate} ,#{createBy} ,#{dateUpdate} ,#{updateBy})
- </insert>
- <!-- 批量新增 -->
- <insert id="batchInsert">
- INSERT INTO sms_device ( TENANT_ID , DEVICE_CODE , DEVICE_NAME , DEVICE_TYPE_ID , COMPANY_ORG_ID , DEPT_ORG_ID , SCENE_ID , POINT_X , POINT_Y , ENABLE_STATE , LAST_UPDATE_TIME , ADDRESS , REMARK , STATUS , DATE_CREATE , CREATE_BY , DATE_UPDATE , UPDATE_BY )
- values
- <foreach collection="devices" item="item" index="index" separator=",">
- ( #{item.tenantId} ,#{item.deviceCode} ,#{item.deviceName} ,#{item.deviceTypeId} ,#{item.companyOrgId} ,#{item.deptOrgId} ,#{item.sceneId} ,#{item.pointX} ,#{item.pointY} ,#{item.enableState} ,#{item.lastUpdateTime} ,#{item.address} ,#{item.remark} ,#{item.status} ,#{item.dateCreate} ,#{item.createBy} ,#{item.dateUpdate} ,#{item.updateBy})
- </foreach>
- </insert>
- <!-- 通过主键修改数据 -->
- <update id="update">
- UPDATE sms_device
- <set>
- <if test="tenantId != null and tenantId != '' ">
- TENANT_ID = #{tenantId},
- </if>
- <if test="deviceCode != null ">
- DEVICE_CODE = #{deviceCode},
- </if>
- <if test="deviceName != null and deviceName != '' ">
- DEVICE_NAME = #{deviceName},
- </if>
- <if test="deviceTypeId != null and deviceTypeId != 0">
- DEVICE_TYPE_ID = #{deviceTypeId},
- </if>
- <if test="companyOrgId != null and companyOrgId != 0">
- COMPANY_ORG_ID = #{companyOrgId},
- </if>
- DEPT_ORG_ID = #{deptOrgId},
- <if test="sceneId != null and sceneId != 0">
- SCENE_ID = #{sceneId},
- </if>
- <if test="pointX != null ">
- POINT_X = #{pointX},
- </if>
- <if test="pointY != null ">
- POINT_Y = #{pointY},
- </if>
- <if test="enableState != null ">
- ENABLE_STATE = #{enableState},
- </if>
- <if test="lastUpdateTime != null ">
- LAST_UPDATE_TIME = #{lastUpdateTime},
- </if>
- ADDRESS = #{address},
- REMARK = #{remark},
- <if test="status != null ">
- STATUS = #{status},
- </if>
- <if test="dateUpdate != null ">
- DATE_UPDATE = #{dateUpdate},
- </if>
- <if test="updateBy != null and updateBy != ''">
- UPDATE_BY = #{updateBy}
- </if>
- </set>
- WHERE
- ID = #{id};
- </update>
- <!--通过主键删除-->
- <delete id="deleteById">
- UPDATE sms_device set STATUS = 0 where id = #{id}
- </delete>
- <!--通过主键删除-->
- <delete id="batchDelete">
- UPDATE sms_device set STATUS = 0
- where id in
- <foreach collection="ids" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </delete>
- <!-- 分页查询 -->
- <select id="selectPage" resultType="com.huaxu.dto.DeviceDto">
- select
- <include refid="Base_Column_List"/>
- from sms_device d
- <include refid="deviceJoins"/>
- where d.status = 1
- <if test="deviceDto.tenantId != null and deviceDto.tenantId != '' ">
- and d.tenant_id = #{deviceDto.tenantId}
- </if>
- <if test="deviceDto.condition != null and deviceDto.condition != ''">
- and (device_code like concat('%', #{deviceDto.condition},'%') or device_name like concat('%', #{deviceDto.condition},'%'))
- </if>
- <if test="deviceDto.companyOrgId != null and deviceDto.companyOrgId != 0">
- and d.COMPANY_ORG_ID=#{deviceDto.companyOrgId}
- </if>
- <if test="deviceDto.deptOrgId != null and deviceDto.deptOrgId != 0">
- and d.DEPT_ORG_ID =#{deviceDto.deptOrgId}
- </if>
- <if test="deviceDto.sceneIds != null and deviceDto.sceneIds.size() > 0">
- and d.SCENE_ID in
- <foreach collection="deviceDto.sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="deviceDto.enableState != null ">
- and d.ENABLE_STATE =#{deviceDto.enableState}
- </if>
- <if test="deviceDto.userType!=null and deviceDto.userType!=-999 and deviceDto.userType!=-9999 and deviceDto.programItems != null and deviceDto.programItems.size() > 0">
- <if test="deviceDto.permissonType == 5 or deviceDto.permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="deviceDto.permissonType == 4 or deviceDto.permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="deviceDto.permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- </select>
- </mapper>
|