VariableMapper.xml 6.82 KB
<?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="cn.runsa.portal.base.dao.VariableMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Variable" >
    <id column="vaId" property="id" />
    <result column="vaCode" property="code" />
    <result column="vaName" property="name" />
    <result column="vaDesc" property="desc" />
    <result column="vaType" property="type" />
    <result column="vaSys" property="sys" />
    <result column="vaBeginDate" property="begindate" />
    <result column="vaEndDate" property="enddate" />
    <result column="ptRemark" property="remark" />
    <result column="ptRemark1" property="remark1" />
    <result column="ptRemark2" property="remark2" />
    <result column="ptRemark3" property="remark3" />
    <result column="ptUpdater" property="updater" />
    <result column="ptUptime" property="uptime" />
    <collection property="plts" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Platform">
    	<id property="id" column="plId" />
    	<result property="name" column="plName"/>
    </collection>
    
    <collection property="items" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.VarItem">
    	<id column="vaiId" property="id" />
	    <!-- <result column="vaId" property="vaId" /> -->
	    <result column="vaiCode" property="code" />
	    <result column="vaiName" property="name" />
	    <result column="vaiGroup" property="group" />
	    <result column="vaiParent" property="parent" />
	    <result column="vaiSort" property="sort" />
	    <result column="ptRemark" property="remark" />
	    <result column="ptRemark1" property="remark1" />
	    <result column="ptRemark2" property="remark2" />
	    <result column="ptRemark3" property="remark3" />
    </collection>
  </resultMap>
   <select id="selectPageList" parameterType="cn.runsa.portal.base.entity.Variable" resultMap="BaseResultMap">
		select t1.vaId,t1.vaCode,t1.vaName,t1.vaDesc,t1.vaType,t1.vaSys,t1.vaBeginDate,t1.vaEndDate,
		      t1.ptRemark,t1.ptRemark1,t1.ptRemark2,t1.ptRemark3,t1.ptUpdater,t1.ptUptime,
		      t3.plId,t3.plName
		 from mtVariable t1 
		   left join mtVarPlatform t2 on t1.vaId = t2.vaId
		   left join smPlatform t3 on t2.plId = t3.plId  
		  where 1=1 
		<if test="id!=null">
			and t1.vaid=#{id}
		</if>
		<if test="code!=null and code!='' ">
			and t1.vaCode=#{code}
		</if>
		<if test="name!=null and name!=''">
			and t1.vaName=#{name}
		</if>
		<if test="desc!=null and desc!=''">
			and t1.vaDesc=#{desc}
		</if>
		<if test="type!=null">
			and t1.vaType=#{type}
		</if>
		<if test="updater!=null and updater!=''">
			and t1.ptUpdater=#{type}
		</if>
		order by t1.vaId desc
		limit #{offset},#{pageSize}
 </select>
 <select id="selectCount" parameterType="cn.runsa.portal.base.entity.Variable" resultType="java.lang.Integer">
		select count(*) from mtVariable t1 where 1=1 
		<if test="id!=null">
			and t1.vaid=#{id}
		</if>
		<if test="code!=null and code!='' ">
			and t1.vaCode=#{code}
		</if>
		<if test="name!=null and name!=''">
			and t1.vaName=#{name}
		</if>
		<if test="desc!=null and desc!=''">
			and t1.vaDesc=#{desc}
		</if>
		<if test="type!=null">
			and t1.vaType=#{type}
		</if>
		<if test="updater!=null and updater!=''">
			and t1.ptUpdater=#{type}
		</if>
 </select>
 
 <select id="selectList" parameterType="cn.runsa.portal.base.entity.Variable" resultMap="BaseResultMap">
		select t1.* 
		 from mtVariable t1
		    left join mtVarPlatform t2 on t1.vaId = t2.vaId
		   left join smPlatform t3 on t2.plId = t3.plId  
		  where 1=1 
		<if test="id!=null">
			and t1.vaid=#{id}
		</if>
		<if test="code!=null and code!='' ">
			and t1.vaCode=#{code}
		</if>
		<if test="name!=null and name!=''">
			and t1.vaName=#{name}
		</if>
		<if test="desc!=null and desc!=''">
			and t1.vaDesc=#{desc}
		</if>
		<if test="type!=null">
			and t1.vaType=#{type}
		</if>
		<if test="updater!=null and updater!=''">
			and t1.ptUpdater=#{type}
		</if>
		order by t1.vaId desc
 </select>

 <select id="findById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  	SELECT
	t1.vaId,
	t1.vaCode,
	t1.vaName,
	t1.vaType,
	t4.*,
	t2.*
	FROM
		mtVariable t1
	LEFT JOIN mtVarItem t2 ON t2.vaId = t1.vaId
	LEFT JOIN mtVarPlatform t3 ON t3.vaId = t1.vaId
	LEFT JOIN smPlatform t4 ON t4.plId = t3.plId
	where t1.vaId=#{vaId}
	ORDER BY
	t2.vaiSort ASC
  </select>
  
  <insert id="insert" parameterType="cn.runsa.portal.base.entity.Variable">
  <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
  </selectKey>
    insert into mtVariable(vaCode,vaName,vaDesc,vaType,vaSys
                              ,vaBeginDate,vaEndDate,ptRemark,ptRemark1,ptRemark2
                              ,ptRemark3,ptUpdater,ptUptime)
    values(#{code},#{name},#{desc},#{type},#{sys},#{begindate},#{enddate},#{remark},
           #{remark1},#{remark2},#{remark3},#{updater},now())
  </insert>
  <insert id="insertVarPlt" parameterType="cn.runsa.portal.base.entity.Variable">
      <!-- delete from mtVarPlatform where vaId=#{id} -->
      insert into mtVarPlatform (vaId,plId) values
      <foreach collection="plts" item="plt" separator=",">
         (#{id},#{plt.id})
      </foreach>
  </insert>
  <update id="updateVar" parameterType="cn.runsa.portal.base.entity.Variable">
    update mtVariable set ptUpTime=now(),ptUpdater=#{updater}
   <if test="code!=null and code!=''">
		,vaCode=#{code}
	</if>
	<if test="name!=null and name!=''">
		,vaName=#{name}
	</if>
	<if test="desc!=null and desc!=''">
		,vaDesc=#{desc}
	</if>
	<if test="type!=null">
		,vaType=#{type}
	</if>
	<if test="sys!=null">
		,vaSys=#{sys}
	</if>
	<if test="begindate!=null">
		,vaBeginDate=#{begindate}
	</if>
	<if test="enddate!=null">
		,vaEndDate=#{enddate}
	</if>
	<if test="remark!=null and remark!=''">
		,ptRemark=#{remark}
	</if>
	<if test="remark1!=null and remark1!=''">
		,ptRemark1=#{remark1}
	</if>
	<if test="remark2!=null and remark2!=''">
		,ptRemark2=#{remark2}
	</if>
	<if test="remark3!=null and remark3!=''">
		,ptRemark3=#{remark3}
	</if>
     where vaId = #{id} 
  </update>
  <delete id="deleteVariable" parameterType="java.lang.Integer">
     delete from mtVariable where vaId=#{vaId}
  </delete>
  <delete id="deleteVarItem" parameterType="java.lang.Integer">
     delete from mtVarItem where vaId=#{vaId}
  </delete>
  <delete id="deletePlatForm" parameterType="java.lang.Integer">
  	 delete from mtVarPlatform where vaId=#{vaId}
  </delete>
  <select id="existsName" resultType="java.lang.Integer" parameterType="java.lang.String" >
   select 
 		COUNT(*)
   from mtVariable
   		where vaName = #{name,jdbcType=VARCHAR}
 </select>
 <select id="existsCode" resultType="java.lang.Integer" parameterType="java.lang.String" >
   select 
 		COUNT(*)
   from mtVariable
   		where vaCode = #{code,jdbcType=VARCHAR}
 </select>
</mapper>