123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?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.SiteMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.Site">
- <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
- <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
- <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
- <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
- <result column="id" property="id" jdbcType="INTEGER"/>
- <result column="name" property="name" jdbcType="VARCHAR"/>
- <result column="website" property="website" jdbcType="VARCHAR"/>
- <result column="logo_url" property="logoUrl" jdbcType="VARCHAR"/>
- <result column="status" property="status" jdbcType="INTEGER"/>
- <result column="type" property="type" jdbcType="INTEGER"/>
- <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
- <result column="account" property="account" jdbcType="VARCHAR"/>
- </resultMap>
- <!--auto generated Code-->
- <sql id="Base_Column_List">
- create_date,
- create_by,
- update_date,
- update_by,
- id,
- name,
- website,
- logo_url,
- status,
- type,
- customer_id,
- account
- </sql>
- <!--auto generated Code-->
- <insert id="insert" useGeneratedKeys="true" keyProperty="site.id">
- INSERT INTO sc_site (
- create_date,
- create_by,
- update_date,
- update_by,
- id,
- name,
- website,
- logo_url,
- status,
- type,
- customer_id,
- account
- ) VALUES (
- #{site.createDate,jdbcType=TIMESTAMP},
- #{site.createBy,jdbcType=VARCHAR},
- #{site.updateDate,jdbcType=TIMESTAMP},
- #{site.updateBy,jdbcType=VARCHAR},
- #{site.id,jdbcType=INTEGER},
- #{site.name,jdbcType=VARCHAR},
- #{site.website,jdbcType=VARCHAR},
- #{site.logoUrl,jdbcType=VARCHAR},
- #{site.status,jdbcType=INTEGER},
- #{site.type,jdbcType=INTEGER},
- #{site.customerId,jdbcType=INTEGER},
- #{site.account,jdbcType=VARCHAR}
- )
- </insert>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="site.id">
- INSERT INTO sc_site
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="site.createDate!=null"> create_date,</if>
- <if test="site.createBy!=null"> create_by,</if>
- <if test="site.updateDate!=null"> update_date,</if>
- <if test="site.updateBy!=null"> update_by,</if>
- <if test="site.id!=null"> id,</if>
- <if test="site.name!=null"> name,</if>
- <if test="site.website!=null"> website,</if>
- <if test="site.logoUrl!=null"> logo_url,</if>
- <if test="site.status!=null"> status,</if>
- <if test="site.type!=null"> type,</if>
- <if test="site.customerId!=null"> customer_id,</if>
- <if test="site.account!=null"> account,</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="site.createDate!=null">#{site.createDate,jdbcType=TIMESTAMP},
- </if>
- <if test="site.createBy!=null">#{site.createBy,jdbcType=VARCHAR},
- </if>
- <if test="site.updateDate!=null">#{site.updateDate,jdbcType=TIMESTAMP},
- </if>
- <if test="site.updateBy!=null">#{site.updateBy,jdbcType=VARCHAR},
- </if>
- <if test="site.id!=null">#{site.id,jdbcType=INTEGER},
- </if>
- <if test="site.name!=null">#{site.name,jdbcType=VARCHAR},
- </if>
- <if test="site.website!=null">#{site.website,jdbcType=VARCHAR},
- </if>
- <if test="site.logoUrl!=null">#{site.logoUrl,jdbcType=VARCHAR},
- </if>
- <if test="site.status!=null">#{site.status,jdbcType=INTEGER},
- </if>
- <if test="site.type!=null">#{site.type,jdbcType=INTEGER},
- </if>
- <if test="site.customerId!=null">#{site.customerId,jdbcType=INTEGER},
- </if>
- <if test="site.account!=null">#{site.account,jdbcType=VARCHAR},
- </if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <insert id="insertList">
- INSERT INTO sc_site (
- create_date,
- create_by,
- update_date,
- update_by,
- id,
- name,
- website,
- logo_url,
- status,
- type,
- customer_id,
- account
- )VALUES
- <foreach collection="sites" item="site" index="index" separator=",">
- (
- #{site.createDate,jdbcType=TIMESTAMP},
- #{site.createBy,jdbcType=VARCHAR},
- #{site.updateDate,jdbcType=TIMESTAMP},
- #{site.updateBy,jdbcType=VARCHAR},
- #{site.id,jdbcType=INTEGER},
- #{site.name,jdbcType=VARCHAR},
- #{site.website,jdbcType=VARCHAR},
- #{site.logoUrl,jdbcType=VARCHAR},
- #{site.status,jdbcType=INTEGER},
- #{site.type,jdbcType=INTEGER},
- #{site.customerId,jdbcType=INTEGER}
- )
- </foreach>
- </insert>
- <!--auto generated Code-->
- <update id="updateByPrimaryKeySelective">
- UPDATE sc_site
- <set>
- <if test="site.createDate != null"> create_date= #{site.createDate,jdbcType=TIMESTAMP},</if>
- <if test="site.createBy != null"> create_by= #{site.createBy,jdbcType=VARCHAR},</if>
- <if test="site.updateDate != null"> update_date= #{site.updateDate,jdbcType=TIMESTAMP},</if>
- <if test="site.updateBy != null"> update_by= #{site.updateBy,jdbcType=VARCHAR},</if>
- <if test="site.name != null"> name= #{site.name,jdbcType=VARCHAR},</if>
- <if test="site.website != null"> website= #{site.website,jdbcType=VARCHAR},</if>
- <if test="site.logoUrl != null"> logo_url= #{site.logoUrl,jdbcType=VARCHAR},</if>
- <if test="site.status != null"> status= #{site.status,jdbcType=INTEGER},</if>
- <if test="site.type != null"> type= #{site.type,jdbcType=INTEGER},</if>
- <if test="site.customerId != null"> customer_id= #{site.customerId,jdbcType=INTEGER},</if>
- <if test="site.account != null"> account= #{site.account,jdbcType=VARCHAR}</if>
- </set>
- WHERE id = #{site.id,jdbcType=INTEGER}
- </update>
- <select id="getList" resultType="com.zoniot.ccrc.dto.SiteDto">
- select
- ss.*,ifnull(a.buildingCount,0)buildingCount,ifnull(b.deviceCount,0)deviceCount,
- (SELECT GROUP_CONCAT(su.username SEPARATOR '、') FROM sc_site_user ssu LEFT JOIN sc_user su on(su.id = ssu.user_id and su.`status`= 1) WHERE ssu.site_id = ss.id and ssu.`status` =1 and ssu.is_admin= 1) as username
- from sc_site ss
- left join (select count(*)buildingCount,site_id from sc_building group by site_id) a on ss.id=a.site_id
- left join (select count(*)deviceCount,site_id from sc_device group by site_id) b on ss.id=b.site_id
- where ss.status = 1
- <if test="siteIds != null and siteIds.size()>0">
- and ss.id in <foreach collection="siteIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test="name != null and name != ''"> AND ss.name LIKE concat('%',#{name},'%')</if>
- order by ss.create_date desc
- </select>
- <update id="delete">
- update sc_site set status = 0,update_date=NOW(),update_by=#{updateBy} where id = #{id}
- </update>
- <update id="deleteCustomerRelations">
- update sc_customer set site_id=null where site_id=#{id}
- </update>
- <update id="updateCustomerSiteId">
- update sc_customer set site_id=#{id}
- where id in (
- <foreach collection="customerIds" item="cid" index="index" open="" close="" separator=",">
- #{cid}
- </foreach>
- )
- </update>
- <update id="updateOrgId">
- update sc_site_user set organ_id=#{orgId} where user_id=#{userId}
- </update>
- <select id="findByNameUnique" resultType="int">
- select count(1) from sc_site where status = 1 and name = #{name}
- <if test="id != null"> and id != #{id}</if>
- </select>
- <select id="findById" resultMap="BaseResultMap">
- select ss.*,sc.customer_name
- from sc_site as ss
- left join sc_customer as sc on (sc.id = ss.customer_id)
- where ss.status = 1 and ss.id = #{siteId}
- </select>
- <select id="findByCustomerIdUnique" resultType="int">
- select count(1) from sc_site where status = 1 and customer_id = #{customerId}
- <if test="id != null"> and id != #{id}</if>
- </select>
- <select id="getSiteCustomerIds" resultType="java.lang.Integer">
- select customer_id from sc_site where status = 1
- </select>
- <select id="getCustomerList" resultType="com.zoniot.ccrc.entity.Customer">
- select * from sc_customer where parent_id=0 and status=1
- </select>
- <select id="getAllCustomerIds" resultType="java.lang.Integer">
- SELECT DATA.id FROM(
- SELECT
- @ids as _ids,
- ( SELECT @ids := GROUP_CONCAT(id)
- FROM sc_customer
- WHERE FIND_IN_SET(parent_id, @ids)
- ) as cids,
- @l := @l+1 as level
- FROM sc_customer,
- (SELECT @ids :=#{customerId}, @l := 0 ) b
- WHERE @ids IS NOT NULL
- ) id, sc_customer DATA
- WHERE FIND_IN_SET(DATA.id, ID._ids)
- </select>
- </mapper>
|