IntelligentRemindServiceMapper.xml 7.32 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.com.glsx.dj.weapp.mapper.IntelligentRemindServiceMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.weapp.model.IntelligentRemindService" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="video_url" property="videoUrl" jdbcType="VARCHAR" />
    <result column="online_flag" property="onlineFlag" jdbcType="CHAR" />
    <result column="cover_url" property="coverUrl" jdbcType="VARCHAR" />
    <result column="share_recommend" property="shareRecommend" jdbcType="VARCHAR" />
    <result column="remind_rule_id" property="remindRuleId" jdbcType="INTEGER" />
    <result column="activity_id" property="activityId" jdbcType="INTEGER" />
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
    <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
    <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
    <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
  </resultMap>
  <resultMap id="DTOResultMap" type="cn.com.glsx.dj.weapp.dto.IntelligentRemindServiceDTO" extends="BaseResultMap">
    <result column="mile_rule" property="searchKey" jdbcType="VARCHAR" />
    <result column="time_rule" property="searchKey" jdbcType="VARCHAR" />
    <result column="season_rule" property="searchKey" jdbcType="VARCHAR" />
    <result column="rule_name" property="projectName" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, merchant_id, title, video_url, online_flag, cover_url, share_recommend, remind_rule_id, activity_id,
    created_by, created_date, updated_by, updated_date, deleted_flag
  </sql>

  <select id="selectByPage" resultMap="DTOResultMap" parameterType="cn.com.glsx.dj.weapp.dto.IntelligentRemindServiceDTO" >
    select a.*
    from dj_weapp_intelligent_remind_service a
    WHERE a.deleted_flag='N'
    and a.merchant_id = #{merchantId,jdbcType=INTEGER}
    <if test="searchKey != null">
      <choose>
        <when test='searchKey=="1"'>
          and EXISTS(select 1 from dj_weapp_intelligent_remind_rule b WHERE b.id = a.remind_rule_id and b.deleted_flag='N'
          and (b.mile_rule is not null and b.mile_rule != '' or (b.season_rule is not null and b.season_rule != '')))
        </when>
        <when test='searchKey=="2"'>
          and EXISTS(select 1 from dj_weapp_intelligent_remind_rule b WHERE b.id = a.remind_rule_id and b.deleted_flag='N'
          and (b.time_rule is not null and b.time_rule != '' or (b.season_rule is not null and b.season_rule != '')))
        </when>
        <otherwise>
          and a.remind_rule_id is null
        </otherwise>
      </choose>
    </if>
    <if test="onlineFlag != null">
      and a.online_flag = #{onlineFlag, jdbcType=VARCHAR}
    </if>
    order by a.updated_date desc
  </select>

  <select id="getById" resultMap="DTOResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from dj_weapp_intelligent_remind_service
    WHERE id = #{id,jdbcType=INTEGER} and deleted_flag='N'
  </select>

  <select id="getByMerchantId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from dj_weapp_intelligent_remind_service
    WHERE  merchant_id = #{merchantId,jdbcType=INTEGER} and deleted_flag='N' order by updated_date desc
  </select>

  <select id="getByCondition" resultMap="DTOResultMap">
    select a.*
    from dj_weapp_intelligent_remind_service a
    WHERE a.deleted_flag='N' and a.online_flag = 'Y'
    and a.merchant_id = #{record.merchantId,jdbcType=INTEGER}
    <if test="record.searchKey != null">
      <choose>
        <when test='record.searchKey=="1"'>
          and EXISTS(select 1 from dj_weapp_intelligent_remind_rule b WHERE b.id = a.remind_rule_id and b.deleted_flag='N'
          and (b.mile_rule is not null and b.mile_rule != '' or (b.season_rule is not null and b.season_rule != '')))
        </when>
        <when test='record.searchKey=="2"'>
          and EXISTS(select 1 from dj_weapp_intelligent_remind_rule b WHERE b.id = a.remind_rule_id and b.deleted_flag='N'
          and (b.time_rule is not null and b.time_rule != '' or (b.season_rule is not null and b.season_rule != '')))
        </when>
        <when test='record.searchKey=="3"'>
          and a.remind_rule_id is null
        </when>
      </choose>
    </if>
    order by a.updated_date desc
  </select>

  <select id="getByRemindRuleId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from dj_weapp_intelligent_remind_service
    WHERE  remind_rule_id = #{remindRuleId,jdbcType=INTEGER} and deleted_flag='N' order by updated_date desc
  </select>

  <update id="update" parameterType="cn.com.glsx.dj.weapp.model.IntelligentRemindService" >
    update dj_weapp_intelligent_remind_service
    <set >
      <if test="record.merchantId != null" >
        merchant_id = #{record.merchantId,jdbcType=INTEGER},
      </if>
      <if test="record.title != null" >
        title = #{record.title,jdbcType=VARCHAR},
      </if>
      <if test="record.videoUrl != null" >
        video_url = #{record.videoUrl,jdbcType=VARCHAR},
      </if>
      <if test="record.onlineFlag != null" >
        online_flag = #{record.onlineFlag,jdbcType=CHAR},
      </if>
      <if test="record.coverUrl != null" >
        cover_url = #{record.coverUrl,jdbcType=VARCHAR},
      </if>
        share_recommend = #{record.shareRecommend,jdbcType=VARCHAR},
        remind_rule_id = #{record.remindRuleId,jdbcType=INTEGER},
        activity_id = #{record.activityId,jdbcType=INTEGER},
      <if test="record.createdBy != null" >
        created_by = #{record.createdBy,jdbcType=VARCHAR},
      </if>
      <if test="record.createdDate != null" >
        created_date = #{record.createdDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updatedBy != null" >
        updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedDate != null" >
        updated_date = #{record.updatedDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedFlag != null" >
        deleted_flag = #{record.deletedFlag,jdbcType=CHAR},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <update id="deleteById" parameterType="java.lang.Integer">
    update dj_weapp_intelligent_remind_service
    set deleted_flag = 'D'
    where id = #{id}
  </update>

  <select id="getRemindServiceList" parameterType="cn.com.glsx.dj.weapp.dto.IntelligentRemindServiceListConditionDTO" resultMap="BaseResultMap">
  	select a.*
    from 
    	dj_weapp_intelligent_remind_service a
    left join 
    	dj_weapp_intelligent_remind_service_classify_tag_ref b
    on a.id = b.service_id
    WHERE a.deleted_flag='N' 
    	and a.online_flag = 'Y'
    	and b.deleted_flag='N'
    	and a.merchant_id = #{condition.merchantId}
    <if test="condition.classifyTagId != null">
    	and b.classify_tag_id = #{condition.classifyTagId}
    </if>
  </select>
</mapper>