btxtgxq-system-population/target/classes/mybatis/mapper/homeperson/homeperson-mapper.xml
2021-03-22 14:45:21 +08:00

357 lines
12 KiB
XML

<?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.cm.population.dao.homeperson.IHomePersonDao">
<resultMap id="homePersonDTO" type="com.cm.population.pojo.dtos.homeperson.HomePersonDTO">
<id column="home_person_id" property="homePersonId"/>
<result column="healthy" property="healthy"/>
<result column="relationship_with_home_people" property="relationshipWithHomePeople"/>
<result column="leading_healthy" property="leadingHealthy"/>
<result column="annual_income_family" property="annualIncomeFamily"/>
<result column="home_person_type" property="homePersonType"/>
<result column="difficulty" property="difficulty"/>
<result column="leading_address" property="leadingAddress"/>
<result column="annual_income_self" property="annualIncomeSelf"/>
<result column="base_id" property="baseId"/>
<result column="leading_phone" property="leadingPhone"/>
<result column="leading_card" property="leadingCard"/>
<result column="help_situation" property="helpSituation"/>
<result column="people_same_census" property="peopleSameCensus"/>
<result column="leading_name" property="leadingName"/>
<result column="id_card_number" property="idCardNumber"/>
<result column="relationship_with_home_people_name" property="relationshipWithHomePeopleName"/>
<result column="full_name" property="fullName"/>
<result column="gender" property="gender"/>
<result column="telephone" property="telephone"/>
<result column="native_place" property="nativePlace"/>
<result column="current_residence" property="currentResidence"/>
</resultMap>
<!-- 新增留守人员 -->
<insert id="saveHomePerson" parameterType="map" useGeneratedKeys="true" keyProperty="id">
INSERT IGNORE INTO gen_home_person(
home_person_id,
healthy,
relationship_with_home_people,
leading_healthy,
annual_income_family,
home_person_type,
difficulty,
leading_address,
annual_income_self,
base_id,
leading_phone,
leading_card,
help_situation,
people_same_census,
leading_name,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) SELECT
#{homePersonId},
#{healthy},
#{relationshipWithHomePeople},
#{leadingHealthy},
#{annualIncomeFamily},
#{homePersonType},
#{difficulty},
#{leadingAddress},
#{annualIncomeSelf},
#{baseId},
#{leadingPhone},
#{leadingCard},
#{helpSituation},
#{peopleSameCensus},
#{leadingName},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
FROM
DUAL
WHERE
NOT EXISTS (
SELECT
*
FROM
gen_home_person
WHERE
base_id = #{baseId}
AND is_delete = 0
)
</insert>
<!-- 批量新增留守人员 -->
<insert id="saveHomePersonList" parameterType="java.util.List">
INSERT IGNORE INTO gen_home_person(
home_person_id,
healthy,
relationship_with_home_people,
leading_healthy,
annual_income_family,
home_person_type,
difficulty,
leading_address,
annual_income_self,
base_id,
leading_phone,
leading_card,
help_situation,
people_same_census,
leading_name,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
)
<foreach collection="list" index="index" item="item" separator="union all">
SELECT
#{item.homePersonId},
#{item.healthy},
#{item.relationshipWithHomePeople},
#{item.leadingHealthy},
#{item.annualIncomeFamily},
#{item.homePersonType},
#{item.difficulty},
#{item.leadingAddress},
#{item.annualIncomeSelf},
#{item.baseId},
#{item.leadingPhone},
#{item.leadingCard},
#{item.helpSituation},
#{item.peopleSameCensus},
#{item.leadingName},
#{item.creator},
#{item.gmtCreate},
#{item.modifier},
#{item.gmtModified},
#{item.isDelete}
FROM
DUAL
WHERE
NOT EXISTS (
SELECT
*
FROM
gen_home_person
WHERE
base_id = #{item.baseId}
AND is_delete = 0
)
</foreach>
</insert>
<!-- 删除留守人员 -->
<update id="removeHomePerson" parameterType="map">
UPDATE
gen_home_person
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
home_person_id IN
<foreach collection="homePersonIds" index="index" open="(" separator="," close=")">
#{homePersonIds[${index}]}
</foreach>
</update>
<!-- 删除留守人员(物理) -->
<update id="deleteHomePerson" parameterType="map">
DELETE FROM
gen_home_person
WHERE
home_person_id IN
<foreach collection="homePersonIds" index="index" open="(" separator="," close=")">
#{homePersonIds[${index}]}
</foreach>
</update>
<!-- 修改留守人员 -->
<update id="updateHomePerson" parameterType="map">
UPDATE
gen_home_person
SET
<if test="healthy != null and healthy != ''">
healthy = #{healthy},
</if>
<if test="relationshipWithHomePeople != null and relationshipWithHomePeople != ''">
relationship_with_home_people = #{relationshipWithHomePeople},
</if>
<if test="leadingHealthy != null and leadingHealthy != ''">
leading_healthy = #{leadingHealthy},
</if>
<if test="annualIncomeFamily != null and annualIncomeFamily != ''">
annual_income_family = #{annualIncomeFamily},
</if>
<if test="homePersonType != null and homePersonType != ''">
home_person_type = #{homePersonType},
</if>
<if test="difficulty != null and difficulty != ''">
difficulty = #{difficulty},
</if>
<if test="leadingAddress != null and leadingAddress != ''">
leading_address = #{leadingAddress},
</if>
<if test="annualIncomeSelf != null and annualIncomeSelf != ''">
annual_income_self = #{annualIncomeSelf},
</if>
<if test="baseId != null and baseId != ''">
base_id = #{baseId},
</if>
<if test="leadingPhone != null and leadingPhone != ''">
leading_phone = #{leadingPhone},
</if>
<if test="leadingCard != null and leadingCard != ''">
leading_card = #{leadingCard},
</if>
<if test="helpSituation != null and helpSituation != ''">
help_situation = #{helpSituation},
</if>
<if test="peopleSameCensus != null and peopleSameCensus != ''">
people_same_census = #{peopleSameCensus},
</if>
<if test="leadingName != null and leadingName != ''">
leading_name = #{leadingName},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
home_person_id = #{homePersonId}
</update>
<!-- 留守人员详情 -->
<select id="getHomePerson" parameterType="map" resultMap="homePersonDTO">
SELECT
t1.healthy,
t1.relationship_with_home_people,
t1.leading_healthy,
t1.annual_income_family,
t1.home_person_type,
t1.difficulty,
t1.leading_address,
t1.annual_income_self,
t1.base_id,
t1.leading_phone,
t1.leading_card,
t1.help_situation,
t1.people_same_census,
t1.leading_name,
t1.home_person_id,
t2.id_card_number
FROM
gen_home_person t1
LEFT JOIN gen_base_population_info t2 ON t1.base_id = t2.base_population_info_id AND t2.is_delete = 0
WHERE
t1.is_delete = 0
<if test="homePersonId != null and homePersonId != ''">
AND
t1.home_person_id = #{homePersonId}
</if>
</select>
<!-- 留守人员列表 -->
<select id="listHomePerson" parameterType="map" resultMap="homePersonDTO">
SELECT
t1.healthy,
t1.relationship_with_home_people,
t1.leading_healthy,
t1.annual_income_family,
t1.home_person_type,
t1.difficulty,
t1.leading_address,
t1.annual_income_self,
t1.base_id,
t1.leading_phone,
t1.leading_card,
t1.help_situation,
t1.people_same_census,
t1.leading_name,
t1.home_person_id,
t3.id_card_number,
t3.full_name,
t3.gender,
t3.telephone,
t3.native_place,
t3.current_residence
FROM
gen_home_person t1
LEFT JOIN gen_base_population_info t3 ON t1.base_id = t3.base_population_info_id AND t3.is_delete = 0
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
t1.leading_name LIKE CONCAT('%', #{keywords}, '%')
OR
t1.leading_card LIKE CONCAT('%', #{keywords}, '%')
OR
t3.id_card_number LIKE CONCAT('%', #{keywords}, '%')
OR
<!-- 全名 -->
t3.full_name LIKE CONCAT('%', #{keywords}, '%')
OR
<!-- 曾用名 -->
t3.name_used_before LIKE CONCAT('%', #{keywords}, '%')
)
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="homePersonIds != null and homePersonIds.size > 0">
AND
t1.home_person_id IN
<foreach collection="homePersonIds" index="index" open="(" separator="," close=")">
#{homePersonIds[${index}]}
</foreach>
</if>
</select>
<!-- 留守人员统计 -->
<select id="countHomePerson" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
gen_home_person t1
WHERE
t1.is_delete = 0
</select>
<!-- 通过身份证号码查询信息是否存在 -->
<select id="hasMsg" parameterType="map" resultMap="homePersonDTO">
SELECT
t1.healthy,
t1.relationship_with_home_people,
t1.leading_healthy,
t1.annual_income_family,
t1.home_person_type,
t1.difficulty,
t1.leading_address,
t1.annual_income_self,
t1.base_id,
t1.leading_phone,
t1.leading_card,
t1.help_situation,
t1.people_same_census,
t1.leading_name,
t1.home_person_id,
t2.id_card_number
FROM
gen_home_person t1
LEFT JOIN gen_base_population_info t2 ON t1.base_id = t2.base_population_info_id AND t2.is_delete = 0
WHERE
t1.is_delete = 0
AND t2.id_card_number = #{idCardNumber}
LIMIT 0, 1
</select>
</mapper>