MsgChannelMapper.xml 11.5 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.MsgChannelMapper" >
   <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.MsgChannel" >
    <id column="mcId" property="id" jdbcType="INTEGER" />
    <result column="mcName" property="name" jdbcType="VARCHAR" />
    <result column="mcDesc" property="desc" jdbcType="VARCHAR" />
    <result column="mcType" property="type" jdbcType="SMALLINT" />
    <result column="mcProvider" property="provider" jdbcType="VARCHAR" />
    <result column="mcAccount" property="account" jdbcType="VARCHAR" />
    <result column="mcPassword" property="password" jdbcType="VARCHAR" />
    <result column="mcProtocol" property="protocol" jdbcType="SMALLINT" />
    <result column="mcRemain" property="remain" jdbcType="INTEGER" />
    <result column="mcPort" property="port" jdbcType="INTEGER" />
    <result column="mtRemark" property="remark" jdbcType="VARCHAR" />
    <result column="mtUpdater" property="updater" jdbcType="INTEGER" />
    <result column="mtUpTime" property="upTime" jdbcType="TIMESTAMP" />
    <result column="GZH_ID" property="gzhId" jdbcType="VARCHAR" />
    <result column="bebLimit" property="bebLimit" jdbcType="BIT" />
    <result column="plCreateId" property="createId" jdbcType="INTEGER" />
    <association property="msgProvider" javaType="cn.runsa.portal.base.entity.MsgProvider">
    	<id column="mpId" property="id"/>
    	<result column="mpName" property="name"/>
    	<result column="mpUrl" property="url"/>
    	<result column="mpAuthType" property="authType"/>
    	<result column="mpServiceType" property="serviceType"/>
    	<result column="mpClassname" property="classname"/>
    </association>
    <association property="bizEntity" javaType="cn.runsa.portal.base.entity.BizEntity" column="bizEntity">  
		<id column="beId" property="id" jdbcType="INTEGER"/>  
		<result column="beName" property="name"/>  
	</association>
	<association property="platform" javaType="cn.runsa.portal.base.entity.Platform" column="platform">  
		<id column="plId" property="id" jdbcType="INTEGER"/>  
		<result column="plName" property="name"/>  
	</association>
	<collection property="bizSetOfBookList" ofType="cn.runsa.portal.base.entity.BizSetOfBook" column="bizSetOfBookList">
    	<id column="bebId" property="id" />
    	<result column="bebName" property="name"/>
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
     mc.mcId,mc.mcName,mc.mcDesc,mc.mcType,mc.mcProvider,mc.mcAccount,mc.mcPassword,mc.mcProtocol,mc.mcRemain,mc.mtRemark,mc.mtUpdater
  </sql>
  <select id="findById" parameterType="Integer" resultMap="BaseResultMap">
  	select * 
  	from smMsgChannel mc
  	left join smMsgProvider mp on mc.mcProvider=mp.mpId
  	where mc.mcId=#{id}
  </select>
  <!-- 查询所有推送通道 -->
  <select id="findList" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.MsgChannel" >
    select 
    <include refid="Base_Column_List" />
    	,be.beId,be.beName
    from
		smMsgChannel mc
	LEFT JOIN mtBizMsgChannel bmc ON mc.mcId=bmc.mcId
	LEFT JOIN mtBizEntity be ON bmc.beId= be.beId
	WHERE 1=1
	order by mcType
  </select>
    <!-- 查询短信推送通道 -->
  <select id="findListMsg" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.MsgChannel" >
    select 
  <include refid="Base_Column_List" />
    	,be.beId,be.beName
    from
		smMsgChannel mc
	LEFT JOIN mtBizMsgChannel bmc ON mc.mcId=bmc.mcId
	LEFT JOIN mtBizEntity be ON bmc.beId= be.beId
	WHERE mc.mcType=1 <!-- 1为短信通道 -->
	<if test="plid != null" >
    	and plId = #{plid,jdbcType=INTEGER}
    </if>
	order by mcType
  </select>
  <!-- 删除推送通道 -->
  <delete id="deteleById" parameterType="java.lang.Integer" >
    delete from smMsgChannel
    where mcId = #{id,jdbcType=INTEGER}
  </delete>
  <!-- 编辑推送通道 -->
  <update id="update" parameterType="cn.runsa.portal.base.entity.MsgChannel" >
     update smMsgChannel
    <set >
      <if test="name != null" >
        mcName = #{name,jdbcType=VARCHAR},
      </if>
      <if test="desc != null" >
        mcDesc = #{desc,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        mcType = #{type,jdbcType=SMALLINT},
      </if>
      <if test="provider != null" >
        mcProvider = #{provider,jdbcType=VARCHAR},
      </if>
      <if test="gzhId != null" >
        GZH_ID = #{gzhId,jdbcType=VARCHAR},
      </if>
      <if test="account != null" >
        mcAccount = #{account,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        mcPassword = #{password,jdbcType=VARCHAR},
      </if>
      <if test="protocol != null" >
        mcProtocol = #{protocol,jdbcType=SMALLINT},
      </if>
      <if test="remain != null" >
        mcRemain = #{remain,jdbcType=INTEGER},
      </if>
      <if test="remark != null" >
        mtRemark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="plid != null" >
        plId = #{plid,jdbcType=INTEGER},
      </if>
      <if test="bizEntity.id != null" >
        beId = #{bizEntity.id,jdbcType=INTEGER},
      </if>
      <if test="updater != null" >
        mtUpdater = #{updater,jdbcType=INTEGER},
      </if>
      <if test="upTime != null" >
        mtUpTime = #{upTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bebLimit != null" >
        bebLimit = #{bebLimit,jdbcType=BIT},
      </if>
      <if test="createId != null" >
        plCreateId = #{createId,jdbcType=INTEGER},
      </if>
    </set>
    where mcId = #{id,jdbcType=INTEGER}
  </update>
  <insert id="insert" useGeneratedKeys="true" keyProperty="id"  parameterType="cn.runsa.portal.base.entity.MsgChannel" >
    insert into smMsgChannel
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="name != null" >
        mcName,
      </if>
      <if test="desc != null" >
        mcDesc,
      </if>
      <if test="type != null" >
        mcType,
      </if>
      <if test="provider != null" >
        mcProvider,
      </if>
      <if test="gzhId != null" >
        GZH_ID,
      </if>
      <if test="account != null" >
        mcAccount,
      </if>
      <if test="password != null" >
        mcPassword,
      </if>
      <if test="protocol != null" >
        mcProtocol,
      </if>
      <!-- <if test="remain != null" >
        mcRemain,
      </if> -->
      <if test="remark != null" >
        mtRemark,
      </if>
      <if test="platform !=null">
	      <if test="platform.id != null" >
	        plId,
	      </if>
      </if>
      <if test="bizEntity.id != null" >
        beId,
      </if>
      <if test="updater != null" >
        mtUpdater,
      </if>
      <if test="upTime != null" >
        mtUpTime,
      </if>
      <if test="bebLimit != null" >
        bebLimit,
      </if>
      <if test="createId != null" >
        plCreateId,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="desc != null" >
        #{desc,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=SMALLINT},
      </if>
      <if test="provider != null" >
        #{provider,jdbcType=VARCHAR},
      </if>
      <if test="gzhId != null" >
        #{gzhId,jdbcType=VARCHAR},
      </if>
      <if test="account != null" >
        #{account,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="protocol != null" >
        #{protocol,jdbcType=SMALLINT},
      </if>
      <!-- <if test="remain != null" >
        #{remain,jdbcType=INTEGER},
      </if> -->
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="platform !=null">
	      <if test="platform.id != null" >
	        #{platform.id,jdbcType=INTEGER},
	      </if>
      </if>
      <if test="bizEntity.id != null" >
        #{bizEntity.id,jdbcType=INTEGER},
      </if>
      <if test="updater != null" >
        #{updater,jdbcType=INTEGER},
      </if>
      <if test="upTime != null" >
        #{upTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bebLimit != null" >
        #{bebLimit,jdbcType=BIT},
      </if>
      <if test="createId != null" >
        #{createId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <!-- 推送通道名称校验 -->
  <select id="existsByName" resultType="Boolean" parameterType="java.lang.String">
      select count(*) from smMsgChannel where mcName = #{name,jdbcType=VARCHAR}
      <if test="mcId != null" >
        AND mcId != #{mcId,jdbcType=INTEGER}
      </if>
  </select>
  <!--删除推送通道经营主体关系 -->
  <delete id="deteleBizMsg" parameterType="java.lang.Integer" >
      delete from mtBizMsgChannel
      where mcId = #{id,jdbcType=INTEGER}
  </delete>
  <!--新增推送通道经营主体关系 -->
  <insert id="insertBizMsg" parameterType="cn.runsa.portal.base.entity.MsgChannel" >
      insert into mtBizMsgChannel (beid,mcid) values
	     (#{bizEntity.id,jdbcType=INTEGER},#{id,jdbcType=INTEGER})  
  </insert>
  <!-- 删除经营主体与结算账套的关系 -->
  <delete id="deleteMsgSetOfBook" parameterType="java.lang.Integer" >
    delete from smMsgChannelSetOfBook
    where mcId = #{id,jdbcType=INTEGER}
  </delete>
  <!--新增经营主体与结算账套的关系 -->
  <insert  id="insertbizSetOfBook" parameterType="cn.runsa.portal.base.entity.MsgChannel" >
      insert into smMsgChannelSetOfBook (mcId,bebId) values
      <foreach collection="bizSetOfBookList" item="item" index="index" separator="," >  
	     (
	      #{id,jdbcType=INTEGER},
	      #{item.id,jdbcType=INTEGER}
	      )  
	  </foreach> 
  </insert>
  <select id="existsPlatMsg" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.MsgChannel">
     SELECT COUNT(*) FROM smPlatMsgChannel WHERE mcId = #{id,jdbcType=INTEGER}
  </select>
  <select id="existsCRM" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.MsgChannel">
     SELECT count(*) FROM crm_account_set_channel WHERE CHL_ID = #{id,jdbcType=INTEGER}
  </select>
  
  <select id="selectAllBybeId" resultMap="BaseResultMap">
    SELECT 
    <include refid="Base_Column_List" />
    FROM smMsgChannel mc LEFT JOIN mtBizMsgChannel b ON mc.mcId = b.mcId
	WHERE mc.mcType = #{type,jdbcType=INTEGER} 
    <if test="protocol != null" >
    	AND mc.mcProtocol = #{protocol,jdbcType=SMALLINT}
    </if>
    <if test="beId == 1" >
       AND b.beId IN 
       (SELECT beId FROM mtBizEntity WHERE beOrgType = (SELECT b.vaiId FROM mtVariable a LEFT JOIN mtVarItem b ON a.vaId = b.vaId WHERE a.vaCode = 'OrgType' AND b.vaiCode ='HQ'))
    </if>
    <if test="beId != 1" >
       AND b.beId IN (SELECT beParent FROM mtBizEntityInfo WHERE beId = #{beId,jdbcType=INTEGER})
    </if>
  </select>
  
  <select id="selectAllByPlId" resultMap="BaseResultMap">
    SELECT 
    <include refid="Base_Column_List" />
    FROM smMsgChannel mc LEFT JOIN mtBizMsgChannel b ON mc.mcId = b.mcId
    WHERE mc.mcType = #{type,jdbcType=INTEGER} 
    <if test="protocol != null" >
    	AND mc.mcProtocol = #{protocol,jdbcType=SMALLINT}
    </if>
    <if test="plId == 1" >
       AND b.beId IN 
       (SELECT beId FROM mtBizEntity WHERE beOrgType = (SELECT b.vaiId FROM mtVariable a LEFT JOIN mtVarItem b ON a.vaId = b.vaId WHERE a.vaCode = 'OrgType' AND b.vaiCode ='HQ'))
    </if>
    <if test="plId != 1" >
       AND b.beId IN (SELECT beParent FROM mtBizEntityInfo WHERE beId = (SELECT beId FROM smPlatform WHERE plId = #{plId,jdbcType=INTEGER}))
    </if>
  </select>
</mapper>