| <?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.matrix.system.shopXcx.dao.ShopArticleDao"> | 
|   | 
|     <!-- 定义ShopArticle 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopArticle" id="ShopArticleMap"> | 
|         <id property="artId" column="art_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="artTitle" column="art_title" /> | 
|             <result property="artReleasestatus" column="art_releasestatus" /> | 
|             <result property="artypeId" column="artype_id" /> | 
|             <result property="artAuthor" column="art_author" /> | 
|             <result property="artVisitstimes" column="art_visitstimes" /> | 
|             <result property="artLabel" column="art_label" /> | 
|             <result property="artSort" column="art_sort" /> | 
|             <result property="artReleasedate" column="art_releasedate" /> | 
|             <result property="artAbstract" column="art_abstract" /> | 
|             <result property="artContent" column="art_content" /> | 
|             <result property="artImgurl" column="art_imgurl" /> | 
|             <result property="artypeName" column="artype_name" /> | 
|             <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopArticle 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopArticle" id="ShopArticleSimpleMap"> | 
|         <id property="artId" column="art_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="artTitle" column="art_title" /> | 
|             <result property="artReleasestatus" column="art_releasestatus" /> | 
|             <result property="artypeId" column="artype_id" /> | 
|             <result property="artAuthor" column="art_author" /> | 
|             <result property="artVisitstimes" column="art_visitstimes" /> | 
|             <result property="artLabel" column="art_label" /> | 
|             <result property="artSort" column="art_sort" /> | 
|             <result property="artReleasedate" column="art_releasedate" /> | 
|             <result property="artAbstract" column="art_abstract" /> | 
|             <result property="artContent" column="art_content" /> | 
|             <result property="artImgurl" column="art_imgurl" /> | 
|             <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             art_id, | 
|             art_title, | 
|             art_releasestatus, | 
|             artype_id, | 
|             art_author, | 
|             art_visitstimes, | 
|             art_label, | 
|             art_sort, | 
|             art_releasedate, | 
|             art_abstract, | 
|             art_content, | 
|             art_imgurl, | 
|             company_id | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.artId}, | 
|             #{item.artTitle}, | 
|             #{item.artReleasestatus}, | 
|             #{item.artypeId}, | 
|             #{item.artAuthor}, | 
|             #{item.artVisitstimes}, | 
|             #{item.artLabel}, | 
|             #{item.artSort}, | 
|             #{item.artReleasedate}, | 
|             #{item.artAbstract}, | 
|             #{item.artContent}, | 
|             #{item.artImgurl}, | 
|             #{item.companyId} | 
|     </sql> | 
|      | 
|     <!-- where sql --> | 
|     <sql id="where_sql"> | 
|           | 
|          <if test="record!=null"> | 
|             <if test="(record.artId!=null and record.artId!='') or  (record.artId!='' and record.artId==0)  "> | 
|                 and art_id  = #{record.artId}  | 
|             </if> | 
|             <if test="(record.artTitle!=null and record.artTitle!='') or  (record.artTitle!='' and record.artTitle==0)  "> | 
|                 and art_title  = #{record.artTitle}  | 
|             </if> | 
|             <if test="(record.artReleasestatus!=null and record.artReleasestatus!='') or  (record.artReleasestatus!='' and record.artReleasestatus==0)  "> | 
|                 and art_releasestatus  = #{record.artReleasestatus}  | 
|             </if> | 
|             <if test="(record.artypeId!=null and record.artypeId!='') or  (record.artypeId!='' and record.artypeId==0)  "> | 
|                 and artype_id  = #{record.artypeId}  | 
|             </if> | 
|             <if test="(record.artAuthor!=null and record.artAuthor!='') or  (record.artAuthor!='' and record.artAuthor==0)  "> | 
|                 and art_author  = #{record.artAuthor}  | 
|             </if> | 
|             <if test="(record.artVisitstimes!=null and record.artVisitstimes!='') or  (record.artVisitstimes!='' and record.artVisitstimes==0)  "> | 
|                 and art_visitstimes  = #{record.artVisitstimes}  | 
|             </if> | 
|             <if test="(record.artLabel!=null and record.artLabel!='') or  (record.artLabel!='' and record.artLabel==0)  "> | 
|                 and art_label  = #{record.artLabel}  | 
|             </if> | 
|             <if test="(record.artSort!=null and record.artSort!='') or  (record.artSort!='' and record.artSort==0)  "> | 
|                 and art_sort  = #{record.artSort}  | 
|             </if> | 
|             <if test="(record.artReleasedate!=null and record.artReleasedate!='') or  (record.artReleasedate!='' and record.artReleasedate==0)  "> | 
|                 and art_releasedate  = #{record.artReleasedate}  | 
|             </if> | 
|             <if test="(record.artAbstract!=null and record.artAbstract!='') or  (record.artAbstract!='' and record.artAbstract==0)  "> | 
|                 and art_abstract  = #{record.artAbstract}  | 
|             </if> | 
|             <if test="(record.artContent!=null and record.artContent!='') or  (record.artContent!='' and record.artContent==0)  "> | 
|                 and art_content  = #{record.artContent}  | 
|             </if> | 
|             <if test="(record.artImgurl!=null and record.artImgurl!='') or  (record.artImgurl!='' and record.artImgurl==0)  "> | 
|                 and art_imgurl  = #{record.artImgurl}  | 
|             </if> | 
|   | 
|              <if test="record.companyId != null and record.companyId !='' "> | 
|                  and company_id = #{record.companyId} | 
|              </if> | 
|   | 
|         </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopArticle" | 
|         useGeneratedKeys="true" keyProperty="item.artId"> | 
|         INSERT INTO shop_article ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_article ( | 
|         <include refid="columns"></include>     | 
|         ) | 
|     VALUES  | 
|     <foreach collection="list" item="item" index="index" separator=",">( | 
|         <include refid="propertys"></include>     | 
|     )</foreach> | 
|     </insert> | 
|      | 
|      | 
|      | 
|      | 
|      | 
|     <!--  根据Map更新 部分更新   --> | 
|     <update id="updateByMap" parameterType="java.util.HashMap" > | 
|         UPDATE shop_article | 
|         <set> | 
|             <if test="_parameter.containsKey('artTitle')"> | 
|                     art_title = #{artTitle}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artReleasestatus')"> | 
|                     art_releasestatus = #{artReleasestatus}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artypeId')"> | 
|                     artype_id = #{artypeId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artAuthor')"> | 
|                     art_author = #{artAuthor}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artVisitstimes')"> | 
|                     art_visitstimes = #{artVisitstimes}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artLabel')"> | 
|                     art_label = #{artLabel}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artSort')"> | 
|                     art_sort = #{artSort}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artReleasedate')"> | 
|                     art_releasedate = #{artReleasedate}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artAbstract')"> | 
|                     art_abstract = #{artAbstract}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artContent')"> | 
|                     art_content = #{artContent}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('artImgurl')"> | 
|                     art_imgurl = #{artImgurl}, | 
|                 </if>         | 
|         </set> | 
|         WHERE art_id=#{artId}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Integer"> | 
|         UPDATE shop_article | 
|         <set> | 
|             <if test="record.artTitle != null and record.artTitle != '' "> | 
|                 art_title  = #{record.artTitle},  | 
|             </if> | 
|             <if test="record.artReleasestatus != null "> | 
|                 art_releasestatus  = #{record.artReleasestatus},  | 
|             </if> | 
|             <if test="record != null "> | 
|                 artype_id  = #{record.artypeId},  | 
|             </if> | 
|             <if test="record.artAuthor != null"> | 
|                 art_author  = #{record.artAuthor},  | 
|             </if> | 
|                 art_visitstimes  = #{record.artVisitstimes}, | 
|             <if test="record.artLabel != null"> | 
|                 art_label  = #{record.artLabel},  | 
|             </if> | 
|                 art_sort  = #{record.artSort}, | 
|             <if test="record.artReleasedate != null"> | 
|                 art_releasedate  = #{record.artReleasedate},  | 
|             </if> | 
|             <if test="record.artAbstract != null and record.artAbstract != '' "> | 
|                 art_abstract  = #{record.artAbstract},  | 
|             </if> | 
|             <if test="record.artContent != null"> | 
|                 art_content  = #{record.artContent},  | 
|             </if> | 
|             <if test="record.artImgurl != null and record.artImgurl != '' "> | 
|                 art_imgurl  = #{record.artImgurl},  | 
|             </if> | 
|         </set> | 
|         WHERE art_id=#{record.artId}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_article where  art_id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|          | 
|     <!-- 根据id删除--> | 
|     <delete id="deleteById" parameterType="Integer"> | 
|         DELETE FROM shop_article | 
|         where  art_id=#{artId}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopArticle"> | 
|         DELETE FROM shop_article | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopArticleMap"> | 
|         select | 
|         a.art_id, | 
|         a.art_title, | 
|         a.art_releasestatus, | 
|         a.artype_id, | 
|         a.art_author, | 
|         a.art_visitstimes, | 
|         a.art_label, | 
|         a.art_sort, | 
|         a.art_releasedate, | 
|         a.art_abstract, | 
|         a.art_content, | 
|         a.art_imgurl, | 
|         t.artype_name | 
|         from shop_article a | 
|         LEFT join shop_article_type t on a. artype_id = t.artype_id | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if test="(record.artId!=null and record.artId!='') or  (record.artId!='' and record.artId==0)  "> | 
|                     and a.art_id  = #{record.artId} | 
|                 </if> | 
|                 <if test="(record.artTitle!=null and record.artTitle!='') or  (record.artTitle!='' and record.artTitle==0)  "> | 
|                     and a.art_title like concat('%', #{record.artTitle}, '%') | 
|                 </if> | 
|                 <if test="(record.artReleasestatus!=null and record.artReleasestatus!='') or  (record.artReleasestatus!='' and record.artReleasestatus==0)  "> | 
|                     and a.art_releasestatus  = #{record.artReleasestatus} | 
|                 </if> | 
|                 <if test="(record.artypeId!=null and record.artypeId!='') or  (record.artypeId!='' and record.artypeId==0)  "> | 
|                     and a.artype_id  = #{record.artypeId} | 
|                 </if> | 
|                 <if test="(record.artAuthor!=null and record.artAuthor!='') or  (record.artAuthor!='' and record.artAuthor==0)  "> | 
|                     and a.art_author  = #{record.artAuthor} | 
|                 </if> | 
|                 <if test="(record.artVisitstimes!=null and record.artVisitstimes!='') or  (record.artVisitstimes!='' and record.artVisitstimes==0)  "> | 
|                     and a.art_visitstimes  = #{record.artVisitstimes} | 
|                 </if> | 
|                 <if test="(record.artLabel!=null and record.artLabel!='') or  (record.artLabel!='' and record.artLabel==0)  "> | 
|                     and a.art_label  = #{record.artLabel} | 
|                 </if> | 
|                 <if test="(record.artSort!=null and record.artSort!='') or  (record.artSort!='' and record.artSort==0)  "> | 
|                     and a.art_sort  = #{record.artSort} | 
|                 </if> | 
|                 <if test="(record.artReleasedate!=null and record.artReleasedate!='') or  (record.artReleasedate!='' and record.artReleasedate==0)  "> | 
|                     and a.art_releasedate  = #{record.artReleasedate} | 
|                 </if> | 
|                 <if test="(record.artAbstract!=null and record.artAbstract!='') or  (record.artAbstract!='' and record.artAbstract==0)  "> | 
|                     and a.art_abstract  = #{record.artAbstract} | 
|                 </if> | 
|                 <if test="(record.artContent!=null and record.artContent!='') or  (record.artContent!='' and record.artContent==0)  "> | 
|                     and a.art_content  = #{record.artContent} | 
|                 </if> | 
|                 <if test="(record.artImgurl!=null and record.artImgurl!='') or  (record.artImgurl!='' and record.artImgurl==0)  "> | 
|                     and a.art_imgurl  = #{record.artImgurl} | 
|                 </if> | 
|                 <if test="(record.artypeName!=null and record.artypeName!='') or  (record.artypeName!='' and record.artypeName==0)  "> | 
|                     and t.artype_name like concat('%', #{record.artypeName}, '%') | 
|                 </if> | 
|   | 
|                 <if test="record.companyId != null and record.companyId !='' "> | 
|                     and a.company_id = #{record.companyId} | 
|                 </if> | 
|             </if> | 
|          </where> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             order by a.create_time desc | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|      | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer"> | 
|     select count(*) | 
|     from shop_article | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopArticleMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_article | 
|         where  art_id=#{artId} | 
|     </select> | 
|   | 
|     <!-- 根据类别ID查询文章--> | 
|     <select id="selectByArtypeId" resultMap="ShopArticleMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_article a where a.artype_id = #{artypeId} | 
|     </select> | 
|   | 
|     <!-- 查询常见问题类型文章--> | 
|     <select id="selectArticle" resultMap="ShopArticleMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_article a | 
|         where a.artype_id in ( SELECT t.artype_id FROM shop_article_type t WHERE t.artype_code = 'cjwt' ) | 
|         order by a.art_sort | 
|     </select> | 
|   | 
|     <!-- 根据类型code查询类型文章--> | 
|     <select id="selectArticleByArtypeCode" resultMap="ShopArticleMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_article a | 
|         where a.artype_id in ( SELECT t.artype_id FROM shop_article_type t WHERE t.artype_code = #{artypeCode} ) | 
|         order by a.art_sort | 
|     </select> | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopArticleMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_article | 
|         where  art_id=#{art_id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopArticleMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_article | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
|   | 
|     <!-- 根据标题和类型查询文章接口 --> | 
|     <select id="findArticleByTitleAndType" resultMap="ShopArticleMap"> | 
|         select | 
|         a.art_id, | 
|         a.art_title, | 
|         a.art_releasestatus, | 
|         a.artype_id, | 
|         a.art_author, | 
|         a.art_visitstimes, | 
|         a.art_label, | 
|         a.art_sort, | 
|         a.art_releasedate, | 
|         a.art_abstract, | 
|         a.art_content, | 
|         a.art_imgurl, | 
|         t.artype_name, | 
|         a.company_id | 
|         from shop_article a | 
|         LEFT join shop_article_type t on a. artype_id = t.artype_id | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if test="(record.artId!=null and record.artId!='') or  (record.artId!='' and record.artId==0)  "> | 
|                     and a.art_id  = #{record.artId} | 
|                 </if> | 
|                 <if test="(record.artTitle!=null and record.artTitle!='') or  (record.artTitle!='' and record.artTitle==0)  "> | 
|                     and a.art_title like concat('%', #{record.artTitle}, '%') | 
|                 </if> | 
|                 <if test="(record.artReleasestatus!=null and record.artReleasestatus!='') or  (record.artReleasestatus!='' and record.artReleasestatus==0)  "> | 
|                     and a.art_releasestatus  = #{record.artReleasestatus} | 
|                 </if> | 
|                 <if test="(record.artypeId!=null and record.artypeId!='') or  (record.artypeId!='' and record.artypeId==0)  "> | 
|                     and a.artype_id  = #{record.artypeId} | 
|                 </if> | 
|                 <if test="(record.artypeName!=null and record.artypeName!='') or  (record.artypeName!='' and record.artypeName==0)  "> | 
|                     and t.artype_name like concat('%', #{record.artypeName}, '%') | 
|                 </if> | 
|             </if> | 
|         </where> | 
|   | 
|     </select> | 
| </mapper> |