<?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">
|
<!--
|
* @title: 法律表
|
* @description: 自定义sql,请自行实现业务逻辑
|
* @company: hugeinfo
|
* @author: huangh
|
* @time:2024-12-05 16:15:00
|
* @version 1.0
|
-->
|
<mapper namespace="cn.huge.module.knowledge.dao.mapper.LawInfoMapper">
|
<!-- 结果集 -->
|
<resultMap id="dataResult" type="cn.huge.module.knowledge.domain.po.LawInfo">
|
<result property="lawInfoId" column="law_info_id"/>
|
<result property="lawOriginalInfoId" column="law_original_info_id"/>
|
<result property="title" column="title"/>
|
<result property="authority" column="authority"/>
|
<result property="authorityName" column="authority_name"/>
|
<result property="lawNature" column="law_nature"/>
|
<result property="lawNatureName" column="law_nature_name"/>
|
<result property="validity" column="validity"/>
|
<result property="validityName" column="validity_name"/>
|
<result property="publishTime" column="publish_time"/>
|
<result property="implementationTime" column="implementation_time"/>
|
<result property="createTime" column="create_time"/>
|
<result property="updateTime" column="update_time"/>
|
<result property="note" column="note"/>
|
<result property="deleteStatus" column="delete_status"/>
|
</resultMap>
|
<!-- 表 -->
|
<sql id='table-name'>law_info</sql>
|
<!-- 字段 -->
|
<sql id="column-part">
|
law_info_id,law_original_info_id,title,authority,authority_name,law_nature,law_nature_name,validity,validity_name,publish_time,implementation_time,create_time,update_time,note,delete_status
|
</sql>
|
<!-- 更新实体字段 -->
|
<sql id="set-part">
|
<if test="entity.lawOriginalInfoId != null">law_original_info_id = #{entity.lawOriginalInfoId},</if>
|
<if test="entity.title != null">title = #{entity.title},</if>
|
<if test="entity.authority != null">authority = #{entity.authority},</if>
|
<if test="entity.authorityName != null">authority_name = #{entity.authorityName},</if>
|
<if test="entity.lawNature != null">law_nature = #{entity.lawNature},</if>
|
<if test="entity.lawNatureName != null">law_nature_name = #{entity.lawNatureName},</if>
|
<if test="entity.validity != null">validity = #{entity.validity},</if>
|
<if test="entity.validityName != null">validity_name = #{entity.validityName},</if>
|
<if test="entity.publishTime != null">publish_time = #{entity.publishTime},</if>
|
<if test="entity.implementationTime != null">implementation_time = #{entity.implementationTime},</if>
|
<if test="entity.note != null">note = #{entity.note},</if>
|
<if test="entity.deleteStatus != null">delete_status = #{entity.deleteStatus}</if>
|
</sql>
|
<!-- 条件 -->
|
<sql id="where-part">
|
<if test="terms != null">
|
<where>
|
<if test="terms.lawOriginalInfoId != null and terms.lawOriginalInfoId !=''">
|
and law_original_info_id = #{terms.lawOriginalInfoId}
|
</if>
|
<if test="terms.title != null and terms.title !=''">
|
and title = #{terms.title}
|
</if>
|
<if test="terms.authority != null and terms.authority !=''">
|
and authority = #{terms.authority}
|
</if>
|
<if test="terms.authorityName != null and terms.authorityName !=''">
|
and authority_name = #{terms.authorityName}
|
</if>
|
<if test="terms.lawNature != null and terms.lawNature !=''">
|
and law_nature = #{terms.lawNature}
|
</if>
|
<if test="terms.lawNatureName != null and terms.lawNatureName !=''">
|
and law_nature_name = #{terms.lawNatureName}
|
</if>
|
<if test="terms.validity != null and terms.validity !=''">
|
and validity = #{terms.validity}
|
</if>
|
<if test="terms.validityName != null and terms.validityName !=''">
|
and validity_name = #{terms.validityName}
|
</if>
|
<if test="terms.implementationStart != null and terms.implementationStart !='' and terms.implementationEnd != null and terms.implementationEnd !=''">
|
and (DATE_FORMAT(implementation_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.implementationStart}
|
and DATE_FORMAT(implementation_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.implementationEnd})
|
</if>
|
<if test="terms.publishStart != null and terms.publishStart !='' and terms.publishEnd != null and terms.publishEnd !=''">
|
and (DATE_FORMAT(publish_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.publishStart}
|
and DATE_FORMAT(publish_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.publishEnd})
|
</if>
|
<if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
|
and (DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.createStart}
|
and DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.createEnd})
|
</if>
|
<if test="terms.updateStart != null and terms.updateStart !='' and terms.updateEnd != null and terms.updateEnd !=''">
|
and (DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.updateStart}
|
and DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.updateEnd})
|
</if>
|
<if test="terms.keyword != null and terms.keyword !=''">
|
and title like concat('%',#{terms.keyword},'%')
|
</if>
|
<if test="terms.deleteStatus == null or terms.deleteStatus ==''">
|
and delete_status = '1'
|
</if>
|
<if test="terms.deleteStatus != null and terms.deleteStatus !=''">
|
and delete_status = #{terms.deleteStatus}
|
</if>
|
</where>
|
</if>
|
</sql>
|
<!-- 更新对象 -->
|
<update id="updateLawInfo">
|
update
|
<include refid="table-name"/>
|
<set>
|
<include refid="set-part"/>
|
</set>
|
<where>
|
law_info_id = #{entity.lawInfoId}
|
</where>
|
</update>
|
<!-- 条件更新对象 -->
|
<update id="updateLawInfoTerms">
|
update
|
<include refid="table-name"/>
|
<set>
|
<include refid="set-part"/>
|
</set>
|
<include refid="where-part"/>
|
</update>
|
<!-- 根据编号物理删除 -->
|
<delete id="deleteLawInfo">
|
delete from
|
<include refid="table-name" />
|
where law_info_id = #{id}
|
</delete>
|
<!-- 根据条件查询 -->
|
<select id="listTerms" resultMap="dataResult">
|
select
|
<include refid="column-part"/>
|
from
|
<include refid="table-name" />
|
<include refid="where-part"/>
|
</select>
|
<!-- 根据条件统计 -->
|
<select id="countTerms" resultType="java.lang.Long">
|
select
|
COUNT(1)
|
from
|
<include refid="table-name" />
|
<include refid="where-part"/>
|
</select>
|
<!-- 分页查询结果集 -->
|
<resultMap id="dataPageResult" type="cn.huge.module.knowledge.domain.dto.LawInfoPageDTO">
|
<result property="lawInfoId" column="law_info_id"/>
|
<result property="lawOriginalInfoId" column="law_original_info_id"/>
|
<result property="title" column="title"/>
|
<result property="authority" column="authority"/>
|
<result property="authorityName" column="authority_name"/>
|
<result property="lawNature" column="law_nature"/>
|
<result property="lawNatureName" column="law_nature_name"/>
|
<result property="validity" column="validity"/>
|
<result property="validityName" column="validity_name"/>
|
<result property="publishTime" column="publish_time"/>
|
<result property="implementationTime" column="implementation_time"/>
|
</resultMap>
|
<!-- 根据条件分页查询 -->
|
<select id="pageTerms" resultMap="dataPageResult">
|
SELECT
|
<include refid="column-part"/>
|
FROM
|
<include refid="table-name" />
|
<include refid="where-part"/>
|
<if test="page.sort != null">
|
<foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
|
isnull(${s.property}), ${s.property} ${s.direction}
|
<!-- ${s.property} ${s.direction}-->
|
</foreach>
|
</if>
|
<if test="page.sort == null">
|
order by isnull(create_time), create_time desc
|
</if>
|
limit #{page.offset}, #{page.size}
|
</select>
|
|
<!-- 字段-包含关键词 -->
|
<sql id="column-part-lawKey">
|
li.law_info_id,law_original_info_id,title,authority,authority_name,law_nature,law_nature_name,validity,validity_name,publish_time,implementation_time
|
</sql>
|
|
<!-- 联表 -->
|
<sql id='table-name-lawKey'>
|
RelevantLawInfoIDs rli
|
JOIN
|
law_info li ON rli.law_info_id = li.law_info_id
|
</sql>
|
|
<!-- 包含关键词的联表条件 -->
|
<sql id="where-part-lawKey">
|
<if test="terms != null">
|
<where>
|
<if test="terms.authority != null and terms.authority !=''">
|
and li.authority = #{terms.authority}
|
</if>
|
<if test="terms.lawNature != null and terms.lawNature !=''">
|
and li.law_nature = #{terms.lawNature}
|
</if>
|
<if test="terms.validity != null and terms.validity !=''">
|
and li.validity = #{terms.validity}
|
</if>
|
<if test="terms.implementationStart != null and terms.implementationStart !='' and terms.implementationEnd != null and terms.implementationEnd !=''">
|
and (DATE_FORMAT(li.implementation_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.implementationStart}
|
and DATE_FORMAT(li.implementation_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.implementationEnd})
|
</if>
|
<if test="terms.publishStart != null and terms.publishStart !='' and terms.publishEnd != null and terms.publishEnd !=''">
|
and (DATE_FORMAT(li.publish_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.publishStart}
|
and DATE_FORMAT(li.publish_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.publishEnd})
|
</if>
|
<if test="terms.deleteStatus == null or terms.deleteStatus ==''">
|
and li.delete_status = '1'
|
</if>
|
<if test="terms.deleteStatus != null and terms.deleteStatus !=''">
|
and li.delete_status = #{terms.deleteStatus}
|
</if>
|
</where>
|
</if>
|
</sql>
|
|
<!-- 根据包含关键词的联表统计 -->
|
<select id="countTermsKeyLaw" resultType="java.lang.Long">
|
WITH RelevantLawInfoIDs AS (
|
SELECT DISTINCT
|
law_info_id
|
FROM
|
law_provision
|
WHERE
|
<if test="terms.keyword != null and terms.keyword !=''">
|
provision_text LIKE concat('%',#{terms.keyword},'%') AND
|
</if>
|
delete_status = '1'
|
)
|
select
|
COUNT(1)
|
FROM
|
<include refid="table-name-lawKey" />
|
<include refid="where-part-lawKey"/>
|
</select>
|
|
<!-- 根据包含关键词的联表分页查询 -->
|
<select id="pageTermsKeyLaw" resultMap="dataPageResult">
|
WITH RelevantLawInfoIDs AS (
|
SELECT DISTINCT
|
law_info_id
|
FROM
|
law_provision
|
WHERE
|
<if test="terms.keyword != null and terms.keyword !=''">
|
provision_text LIKE concat('%',#{terms.keyword},'%') AND
|
</if>
|
delete_status = '1'
|
)
|
SELECT
|
<include refid="column-part-lawKey"/>
|
FROM
|
<include refid="table-name-lawKey" />
|
<include refid="where-part-lawKey"/>
|
<if test="page.sort != null">
|
<foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
|
isnull(${s.property}), ${s.property} ${s.direction}
|
</foreach>
|
</if>
|
<if test="page.sort == null">
|
order by isnull(create_time), create_time desc
|
</if>
|
limit #{page.offset}, #{page.size}
|
</select>
|
|
<!-- 统计各类别-表 -->
|
<sql id='table-name-category'>
|
<!-- `law_original_info`-->
|
`law_info` li
|
</sql>
|
<!-- 统计各类别 查询结果集 -->
|
<resultMap id="dataCategoryResult" type="cn.huge.module.knowledge.domain.dto.DictionaryDTO">
|
<!-- <result property="" column="category"/>-->
|
<result property="code" column="code"/>
|
<result property="name" column="name"/>
|
<result property="value" column="value"/>
|
<result property="count" column="count"/>
|
</resultMap>
|
|
<!-- 包含关键词的联表条件 -->
|
<sql id="where-part-categoryCount">
|
<if test="terms != null">
|
<if test="terms.authority != null and terms.authority !=''">
|
and li.authority = #{terms.authority}
|
</if>
|
<if test="terms.lawNature != null and terms.lawNature !=''">
|
and li.law_nature = #{terms.lawNature}
|
</if>
|
<if test="terms.validity != null and terms.validity !=''">
|
and li.validity = #{terms.validity}
|
</if>
|
<if test="terms.implementationStart != null and terms.implementationStart !='' and terms.implementationEnd != null and terms.implementationEnd !=''">
|
and (DATE_FORMAT(li.implementation_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.implementationStart}
|
and DATE_FORMAT(li.implementation_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.implementationEnd})
|
</if>
|
<if test="terms.publishStart != null and terms.publishStart !='' and terms.publishEnd != null and terms.publishEnd !=''">
|
and (DATE_FORMAT(li.publish_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.publishStart}
|
and DATE_FORMAT(li.publish_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.publishEnd})
|
</if>
|
<if test="terms.deleteStatus == null or terms.deleteStatus ==''">
|
and li.delete_status = '1'
|
</if>
|
<if test="terms.deleteStatus != null and terms.deleteStatus !=''">
|
and li.delete_status = #{terms.deleteStatus}
|
</if>
|
|
</if>
|
</sql>
|
|
<!-- 统计各类别 -->
|
<select id="categoryCount" resultMap="dataCategoryResult">
|
WITH
|
<if test="terms.keyword != null and terms.keyword !=''">
|
RelevantLawInfoIDs AS (
|
SELECT DISTINCT
|
law_info_id
|
FROM
|
law_provision
|
WHERE
|
provision_text LIKE concat('%',#{terms.keyword},'%') AND
|
delete_status = '1'
|
),
|
</if>
|
LawNatureStats AS (
|
SELECT
|
'102' AS code,
|
`law_nature` AS value,
|
`law_nature_name` AS name,
|
COUNT(*) AS count
|
FROM
|
<if test="terms.keyword != null and terms.keyword !=''">
|
<include refid="table-name-lawKey" />
|
</if>
|
<if test="terms.keyword == null or terms.keyword ==''">
|
<include refid="table-name-category" />
|
</if>
|
WHERE
|
<!-- li.`law_nature` IN (1, 2, 3, 4)-->
|
1=1
|
<include refid="where-part-categoryCount"/>
|
GROUP BY
|
`law_nature`,
|
`law_nature_name`
|
),
|
ValidityStats AS (
|
SELECT
|
'103' AS code,
|
`validity` AS value,
|
`validity_name` AS name,
|
COUNT(*) AS count
|
FROM
|
<if test="terms.keyword != null and terms.keyword !=''">
|
<include refid="table-name-lawKey" />
|
</if>
|
<if test="terms.keyword == null or terms.keyword ==''">
|
<include refid="table-name-category" />
|
</if>
|
WHERE
|
<!-- li.`validity` IN ('1', '2', '3', '4', '5')-->
|
1=1
|
<include refid="where-part-categoryCount"/>
|
GROUP BY
|
`validity`,
|
`validity_name`
|
),
|
AuthorityStats AS (
|
SELECT
|
'101' AS code,
|
`authority` AS value,
|
`authority_name` AS name,
|
COUNT(*) AS count
|
FROM
|
<if test="terms.keyword != null and terms.keyword !=''">
|
<include refid="table-name-lawKey" />
|
</if>
|
<if test="terms.keyword == null or terms.keyword ==''">
|
<include refid="table-name-category" />
|
</if>
|
WHERE
|
<!-- li.`authority` IN ('1', '2', '3', '4', '5', '6')-->
|
1=1
|
<include refid="where-part-categoryCount"/>
|
GROUP BY
|
`authority`,
|
`authority_name`
|
)
|
SELECT * FROM LawNatureStats
|
UNION ALL
|
SELECT * FROM ValidityStats
|
UNION ALL
|
SELECT * FROM AuthorityStats
|
ORDER BY code, value ;
|
</select>
|
|
|
</mapper>
|