城阳项目国产化平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1746 lines
67 KiB

<?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.epmet.dao.IcResiUserDao">
<resultMap id="homeMemberList" type="com.epmet.dto.result.HouseIcResiUserResultDTO">
<result column="customer_id" property="customerId"/>
<result column="agency_id" property="agencyId"/>
<result column="grid_id" property="gridId"/>
<result column="village_id" property="villageId"/>
<result column="build_id" property="buildId"/>
<result column="unit_id" property="unitId"/>
<result column="home_id" property="homeId"/>
<collection property="houseMemberList" ofType="com.epmet.dto.result.HouseIcResiUserResultDTO$HouseMemberResultDTO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="mobile" property="mobile"/>
<result column="gender" property="gender"/>
<result column="id_card" property="idCard"/>
<result column="birthday" property="birthday"/>
<result column="hjszd" property="hjszd"/>
<result column="yhzgx" property="yhzgx"/>
<result column="is_party" property="isParty"/>
<result column="is_tenant" property="isTenant"/>
<result column="is_floating" property="isFloating"/>
<result column="gzdw" property="gzdw"/>
<result column="mz" property="mz"/>
<result column="jg" property="jg"/>
<result column="hyzk" property="hyzk"/>
<result column="culture" property="culture"/>
<result column="faith" property="faith"/>
<result column="remarks" property="remarks"/>
</collection>
</resultMap>
<insert id="add">
insert into ${tableName}
(
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
${key}
</foreach>
,DEL_FLAG
,REVISION
,CREATED_TIME
,UPDATED_TIME
) values
(
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
#{value}
</foreach>
,'0'
,'0'
,NOW()
,NOW()
)
</insert>
<delete id="del">
DELETE
FROM
${tableName}
WHERE
ic_resi_user = #{resiUserId}
</delete>
<update id="upTable">
UPDATE ${tableName}
SET
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
${key} = #{value}
</foreach>
,UPDATED_TIME = NOW()
WHERE id = #{id}
</update>
<!-- 选择性更新(只更新不为null的) -->
<update id="updateTableSelective">
UPDATE ${tableName}
SET
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
<if test="value != null and value != ''">
${key} = #{value}
</if>
</foreach>
,UPDATED_TIME = NOW()
WHERE id = #{id}
</update>
<select id="selectListMapById" parameterType="map" resultType="map">
select * from ic_resi_user where del_flag='0' and id=#{icResiUserId} and customer_id=#{customerId}
</select>
<select id="selectSubTableRecords" parameterType="map" resultType="map">
select * from ${subTableName} where del_flag='0' and IC_RESI_USER=#{icResiUserId} and customer_id=#{customerId}
</select>
<!-- 列表查询 -->
<sql id="listWhereForPage">
ic_resi_user.DEL_FLAG = '0'
AND ic_resi_user.status = '0'
<!--如果查询的left表则不显示空的数据-->
<if test="resultTableName != null and resultTableName != ''">
AND ${resultTableName}.ID IS NOT NULL
</if>
<!-- orgIdPath过滤 -->
and (
<foreach collection="staffOrgPaths" item="orgIdPath" separator="or">
ic_resi_user.pids like concat(#{orgIdPath},'%')
</foreach>
<if test='staffOrgPaths != null and staffOrgPaths.size() > 0 and gridIds != null and gridIds.size() > 0'>
or
</if>
<!-- 网格id过滤 -->
<if test="gridIds != null and gridIds.size() > 0">
ic_resi_user.GRID_ID in (
<foreach collection="gridIds" item="gridId" separator=",">
#{gridId}
</foreach>
)
</if>
)
<if test="null != conditions and conditions.size() > 0">
<foreach item="subCondition" collection="conditions" open="" separator="" close="">
<if test="null != subCondition.columnValue and subCondition.columnValue.size() > 0">
<if test="subCondition.queryType!= null and subCondition.queryType == 'equal' ">
<if test="null!=subCondition.columnValue[0] and ''!=subCondition.columnValue[0]">
and ${subCondition.tableName}.${subCondition.columnName} = #{subCondition.columnValue[0]}
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'like' ">
<if test="null!=subCondition.columnValue[0] and ''!=subCondition.columnValue[0]">
and ${subCondition.tableName}.${subCondition.columnName} like concat('%',#{subCondition.columnValue[0]},'%')
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'daterange' ">
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 2">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &gt;= #{subCondition.columnValue[0]}
</if>
<if test='null != subCondition.columnValue[1] and subCondition.columnValue[1] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &lt;= #{subCondition.columnValue[1]}
</if>
</if>
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 1">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &gt;= #{subCondition.columnValue[0]}
</if>
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'agerange' ">
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 2">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &gt;= #{subCondition.columnValue[0]}
</if>
<if test='null != subCondition.columnValue[1] and subCondition.columnValue[1] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &lt;= #{subCondition.columnValue[1]}
</if>
</if>
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 1">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &gt;= #{subCondition.columnValue[0]}
</if>
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'notnull' ">
<if test="null!=subCondition.columnValue[0] and subCondition.columnValue[0] =='1'.toString()">
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
</if>
<if test="null!=subCondition.columnValue[0] and subCondition.columnValue[0] =='0'.toString()">
and (${subCondition.tableName}.${subCondition.columnName} is null
or ${subCondition.tableName}.${subCondition.columnName} ='')
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'list_equal' ">
<foreach collection="subCondition.columnValue" item="colValue" open="AND ( " separator=" OR " close=" ) ">
${subCondition.tableName}.${subCondition.columnName} like concat('%',#{colValue},'%')
</foreach>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'resi_category' ">
<if test="null!=subCondition.columnValue[0] and ''!=subCondition.columnValue[0]">
<foreach collection="subCondition.columnValue" item="colValue" open="" separator="" close="">
<if test="colValue != null and colValue != ''">
and ${subCondition.tableName}.${colValue} ='1'
</if>
</foreach>
</if>
</if>
</if>
</foreach>
</if>
</sql>
<!-- 导出公用where条件 -->
<sql id="listWhere">
ic_resi_user.DEL_FLAG = '0'
and ic_resi_user.customer_id=#{customerId}
<if test="null != conditions and conditions.size() > 0">
<foreach item="subCondition" collection="conditions" open="" separator="" close="">
<if test="null != subCondition.columnValue and subCondition.columnValue.size() > 0">
<if test="subCondition.queryType!= null and subCondition.queryType == 'equal' ">
<if test="null!=subCondition.columnValue[0] and ''!=subCondition.columnValue[0]">
and ${subCondition.tableName}.${subCondition.columnName} = #{subCondition.columnValue[0]}
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'like' ">
<if test="null!=subCondition.columnValue[0] and ''!=subCondition.columnValue[0]">
and ${subCondition.tableName}.${subCondition.columnName} like concat('%',#{subCondition.columnValue[0]},'%')
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'daterange' ">
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 2">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &gt;= #{subCondition.columnValue[0]}
</if>
<if test='null != subCondition.columnValue[1] and subCondition.columnValue[1] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &lt;= #{subCondition.columnValue[1]}
</if>
</if>
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 1">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
and ${subCondition.tableName}.${subCondition.columnName} &gt;= #{subCondition.columnValue[0]}
</if>
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'agerange' ">
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 2">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &gt;= #{subCondition.columnValue[0]}
</if>
<if test='null != subCondition.columnValue[1] and subCondition.columnValue[1] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &lt;= #{subCondition.columnValue[1]}
</if>
</if>
<if test="subCondition.columnValue != null and subCondition.columnValue.size() == 1">
<if test='null != subCondition.columnValue[0] and subCondition.columnValue[0] != "" '>
and ic_resi_user.BIRTHDAY is not null
and ic_resi_user.BIRTHDAY !=''
and YEAR(NOW())-SUBSTR(ic_resi_user.BIRTHDAY, 1, 4) &gt;= #{subCondition.columnValue[0]}
</if>
</if>
</if>
<if test="subCondition.queryType!= null and subCondition.queryType == 'notnull' ">
<if test="null!=subCondition.columnValue[0] and subCondition.columnValue[0] =='1'.toString()">
and ${subCondition.tableName}.${subCondition.columnName} is not null
and ${subCondition.tableName}.${subCondition.columnName} !=''
</if>
<if test="null!=subCondition.columnValue[0] and subCondition.columnValue[0] =='0'.toString()">
and (${subCondition.tableName}.${subCondition.columnName} is null
or ${subCondition.tableName}.${subCondition.columnName} ='')
</if>
</if>
</if>
</foreach>
</if>
</sql>
<!-- 查询列表用 -->
<!-- 2022.11.18 小寨子写死排序 -->
<select id="selectListResiMap" parameterType="map" resultType="map">
select
ic_resi_user.id as icResiUserId,
ic_resi_user.AGENCY_ID as ORG_ID,
<foreach item="column" collection="resultColumns" open="" separator="," close="">
${column.columnName}
</foreach>
FROM
ic_resi_user
<if test="null != subTables and subTables.size() > 0">
<foreach item="subTableName" collection="subTables" open="" separator="" close="">
${subTableName}
</foreach>
</if>
<where>
<include refid="listWhereForPage"></include>
<if test="keyword != null and keyword != ''">
AND (
NAME like concat('%', #{keyword},'%')
or MOBILE like concat('%', #{keyword},'%')
or ID_CARD like concat('%', #{keyword},'%')
)
</if>
</where>
<if test="null != groupByTables and groupByTables.size() > 0">
group by ic_resi_user.id
<foreach item="groupTableName" collection="groupByTables" open="," separator="," close="">
${groupTableName}.ID
</foreach>
</if>
<choose>
<when test="customerId == '1536638904600752130' ">
ORDER BY
field( ic_resi_user.GRID_ID, '1537272060187049986', '1537272342477508609', '1537275342477501111', '1593432493598076929','1595582620679204865' ),
ic_resi_user.VILLAGE_ID ASC,
ic_resi_user.BUILD_ID ASC,
ic_resi_user.UNIT_ID ASC,
ic_resi_user.HOME_ID ASC,
ic_resi_user.ID ASC
</when>
<otherwise>
ORDER BY
ic_resi_user.GRID_ID asc,
ic_resi_user.VILLAGE_ID ASC,
ic_resi_user.BUILD_ID ASC,
ic_resi_user.UNIT_ID ASC,
ic_resi_user.HOME_ID ASC,
ic_resi_user.ID ASC
</otherwise>
</choose>
</select>
<update id="updateToDel" parameterType="map">
update ic_resi_user
set del_flag='1',
UPDATED_TIME = now(),
UPDATED_BY = #{currentStaffId}
where id = #{icResiUserId}
</update>
<update id="updateSubTableToDel" parameterType="map">
update ${subTalbeName}
set del_flag='1',
UPDATED_TIME = now(),
UPDATED_BY = #{currentStaffId}
where IC_RESI_USER=#{icResiUserId}
</update>
<update id="updateIcResiUserByIdCard">
update
ic_resi_user
set
name = #{entity.name},
mobile = #{entity.mobile},
birthday = #{entity.birthday},
home_id = #{entity.homeId},
village_id = #{entity.villageId},
build_id = #{entity.buildId},
unit_id = #{entity.unitId},
pids = #{entity.pids},
grid_id = #{entity.gridId},
updated_time = now()
where
id_card = #{entity.idCard}
AND customer_id = #{entity.customerId}
</update>
<select id="dynamicQuery" parameterType="map" resultType="java.util.LinkedHashMap">
select
<choose>
<when test="showSqlColumns != null and showSqlColumns.size() != 0">
<foreach collection="showSqlColumns" item="column" separator=",">
${column.tableName}.${column.columnName}
</foreach>
</when>
<otherwise>${resultTableName}.*</otherwise>
</choose>
FROM
ic_resi_user
<if test="null != subTables and subTables.size() > 0">
<foreach item="subTableName" collection="subTables" open="" separator="" close="">
${subTableName}
</foreach>
</if>
<where>
<include refid="listWhereForPage"></include>
</where>
<if test="null != groupByTables and groupByTables.size() > 0">
group by IC_RESI_USER.id
<foreach item="groupTableName" collection="groupByTables" open="," separator="," close="">
${groupTableName}.ID
</foreach>
</if>
order by IC_RESI_USER.GRID_ID ASC,
IC_RESI_USER.VILLAGE_ID ASC,
IC_RESI_USER.BUILD_ID ASC,
IC_RESI_USER.UNIT_ID ASC,
IC_RESI_USER.HOME_ID ASC,
IC_RESI_USER.ID ASC
</select>
<!-- 查询个人信息 -->
<resultMap id="selectPersonData" type="com.epmet.dto.result.PersonDataResultDTO">
<result column="GZDW" property="workUnit"/>
<result column="ID_CARD" property="idCard"/>
<result column="name" property="name"/>
<result column="isVolunteer" property="isVolunteer"/>
<result column="mobile" property="mobile"/>
<result column="isTenant" property="isTenant"/>
<result column="CUSTOMER_ID" property="customerId"/>
<result column="GRID_ID" property="gridId"/>
<result column="HOME_ID" property="homeId"/>
<collection property="financialSituation" ofType="com.epmet.dto.FinancialSituationDTO">
<result column="YSR" property="monthlyIncome"/>
<result column="TXJE" property="retirementAmount"/>
</collection>
</resultMap>
<select id="personData" resultMap="selectPersonData">
SELECT
GZDW,
name,
YSR,
TXJE,
ID_CARD,
MOBILE,
IS_TENANT as isTenant,
IFNULL(IS_VOLUNTEER,'0') AS isVolunteer,
CUSTOMER_ID,
GRID_ID,
HOME_ID
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND ID = #{userId}
</select>
<!-- 根据名字,组织查询人 -->
<select id="searchByName" resultType="com.epmet.dto.result.SearchByNameResultDTO">
SELECT
ID AS userId,
`NAME`,
VILLAGE_ID AS neighborHoodId,
BUILD_ID,
GRID_ID,
MOBILE,
( case when GENDER='1'then '男'
when GENDER='2' then '女'
else '未知'
end
) as GENDER,
ID_CARD,
IFNULL(BIRTHDAY,'') AS BIRTHDAY,
IFNULL(REMARKS,'') AS REMARKS
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE CONCAT('%',#{agencyId},'%'))
<if test="level != null and level != ''">
<if test="level=='agency'">
<if test="id != null and id != ''">
AND (AGENCY_ID = #{id} OR PIDS LIKE CONCAT('%',#{id},'%'))
</if>
</if>
<if test="level=='grid'">
<if test="id != null and id != ''">
AND GRID_ID = #{id}
</if>
</if>
<if test="level=='neighborHood'">
<if test="id != null and id != ''">
AND VILLAGE_ID = #{id}
</if>
</if>
<if test="level=='building'">
<if test="id != null and id != ''">
AND BUILD_ID = #{id}
</if>
</if>
</if>
<if test="name != null and name != ''">
AND `NAME` LIKE CONCAT('%',#{name},'%')
</if>
<if test="columnName != null and columnName != ''">
and ${columnName}='1'
</if>
AND `STATUS`='0'
ORDER BY `CREATED_TIME` DESC, `NAME`
</select>
<select id="selectUserDemandCode" parameterType="java.lang.String" resultType="java.lang.String">
SELECT DISTINCT
m.CATEGORY_CODE
FROM
ic_resi_demand m
WHERE
m.DEL_FLAG = '0'
AND m.IC_RESI_USER = #{icResiUserId}
ORDER BY
m.CREATED_TIME ASC
</select>
<select id="selectCategoryNames" parameterType="map" resultType="java.lang.String">
SELECT
GROUP_CONCAT(m.CATEGORY_NAME)
FROM
ic_resi_demand_dict m
WHERE
m.DEL_FLAG = '0'
AND m.CUSTOMER_ID = #{customerId}
<if test="null != codeSet and codeSet.size() > 0">
AND m.CATEGORY_CODE IN
<foreach item="code" collection="codeSet" open="(" separator="," close=")">
#{code}
</foreach>
</if>
</select>
<!-- 查询每个楼栋,18类别下,居民数量 -->
<select id="getHomeUserCategoryCount" resultType="java.util.Map">
SELECT
HOME_ID,
SUM(IF('1' = IS_PARTY, 1, 0)) AS IS_PARTY,
SUM(IF('1' = IS_DBH, 1, 0)) AS IS_DBH,
SUM(IF('1' = IS_ENSURE_HOUSE, 1, 0)) AS IS_ENSURE_HOUSE,
SUM(IF('1' = IS_UNEMPLOYED, 1, 0)) AS IS_UNEMPLOYED,
SUM(IF('1' = IS_YLFN, 1, 0)) AS IS_YLFN,
SUM(IF('1' = IS_VETERANS, 1, 0)) AS IS_VETERANS,
SUM(IF('1' = IS_UNITED_FRONT, 1, 0)) AS IS_UNITED_FRONT,
SUM(IF('1' = IS_XFRY, 1, 0)) AS IS_XFRY,
SUM(IF('1' = IS_VOLUNTEER, 1, 0)) AS IS_VOLUNTEER,
SUM(IF('1' = IS_OLD_PEOPLE, 1, 0)) AS IS_OLD_PEOPLE,
SUM(IF('1' = IS_KC, 1, 0)) AS IS_KC,
SUM(IF('1' = IS_SD, 1, 0)) AS IS_SD,
SUM(IF('1' = IS_SN, 1, 0)) AS IS_SN,
SUM(IF('1' = IS_SZ, 1, 0)) AS IS_SZ,
SUM(IF('1' = IS_CJ, 1, 0)) AS IS_CJ,
SUM(IF('1' = IS_DB, 1, 0)) AS IS_DB,
SUM(IF('1' = IS_MB, 1, 0)) AS IS_MB,
SUM(IF('1' = IS_SPECIAL, 1, 0)) AS IS_SPECIAL
FROM ic_resi_user
WHERE DEL_FLAG = 0
AND BUILD_ID = #{buildId}
GROUP BY HOME_ID
</select>
<!-- 根据userId查询志愿者 -->
<select id="selectVolunteerByUserId" resultType="java.lang.String">
SELECT VOLUNTEER_CATEGORY FROM ic_volunteer WHERE DEL_FLAG = '0' AND ic_resi_user = #{userId}
</select>
<!-- 查询人员类别 -->
<select id="selectPersonType" resultType="java.util.Map">
select
<foreach collection="columns" separator="," item="c">
IFNULL(`${c}`,'0') AS `${c}`
</foreach>
from ${tableName}
where DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
<if test=' tableName == "ic_resi_user" '>
AND ID = #{userId}
</if>
<if test=' tableName != "ic_resi_user" '>
AND IC_RESI_USER = #{userId}
</if>
</select>
<select id="getResiUserByIdCard" resultType="com.epmet.dto.IcResiUserDTO">
SELECT
id,
`name`,
id_card,
mobile,
agency_id,
grid_id,
home_id,
IS_PARTY as isParty
FROM
ic_resi_user
WHERE
del_flag = '0'
AND customer_id = #{customerId}
AND id_card = #{idCard}
</select>
<select id="selectDemandUsers" parameterType="map" resultType="com.epmet.dto.result.DemandUserResDTO">
SELECT
ir.id as demandUserId,
IFNULL(ir.`NAME`,'') AS demandUserName,
IFNULL(ir.MOBILE,'') AS demandUserMobile,
(
case when ir.MOBILE is not null and ir.MOBILE!=''
then concat(ir.`NAME`,'(',ir.MOBILE,')')
else ir.`NAME`
end
) as label,
ir.grid_id as gridId,
ir.ID_CARD as idCard,
ir.AGENCY_ID as agencyId,
ir.HOME_ID as houseId
FROM
ic_resi_user ir
WHERE
ir.DEL_FLAG = '0'
<if test="agencyId != null and agencyId != ''">
AND ir.AGENCY_ID = #{agencyId}
</if>
<if test="gridId != null and gridId != ''">
AND ir.GRID_ID = #{gridId}
</if>
<if test="name != null and name != ''">
AND ir.`NAME` concat('%',#{name},'%')
</if>
and ir.status='0'
ORDER BY
CONVERT ( ir.NAME USING gbk ) ASC
</select>
<select id="selectIdByIdCard" parameterType="map" resultType="com.epmet.dto.IcResiUserDTO">
select
ir.*
FROM
ic_resi_user ir
WHERE
ir.DEL_FLAG = '0'
and ir.customer_id=#{customerId}
<if test="idNum != null and idNum != ''">
and ir.ID_CARD=#{idNum}
</if>
<if test="icResiUserId != null and icResiUserId != ''">
and ir.id=#{icResiUserId}
</if>
</select>
<resultMap id="IcResiUserBriefDTOMap" type="com.epmet.dto.result.IcResiUserBriefDTO">
<id property="icResiUserId" column="ID" ></id>
<result property="houseId" column="HOME_ID"/>
<result property="icUserName" column="NAME"/>
<collection property="houseUserList" ofType="com.epmet.dto.result.HouseUserDTO"
column="{currentIcResiUserId=ID,homeId=HOME_ID}" select="com.epmet.dao.IcResiUserDao.selectListFamilyMember">
</collection>
</resultMap>
<!-- 查询当前居民的姓名,和房屋id -->
<select id="selectIcResuUser" parameterType="map" resultMap="IcResiUserBriefDTOMap">
SELECT
m.ID,
m.HOME_ID,
m.`NAME`
FROM
ic_resi_user m
WHERE
m.DEL_FLAG = '0'
AND m.id = #{isResiUserId}
</select>
<!-- 除了本人以外,住在这个房子的人 -->
<select id="selectListFamilyMember" parameterType="map" resultType="com.epmet.dto.result.HouseUserDTO">
SELECT
m.ID AS icResiUserId,
m.`NAME` AS icUserName,
m.AGENCY_ID AS agencyId,
m.GRID_ID AS gridId
FROM
ic_resi_user m
WHERE
m.DEL_FLAG = '0'
AND m.id != #{currentIcResiUserId}
and m.HOME_ID=#{homeId}
order by m.CREATED_TIME asc
</select>
<select id="getPartyMemberAgeStatistics" resultType="com.epmet.commons.tools.dto.result.OptionDataResultDTO">
SELECT
ageGroup AS "code",
COUNT(ID) AS "value"
FROM
(
SELECT
ID,
CASE
WHEN age &lt; 50 THEN '0'
WHEN age &gt;= 50 AND age &lt;= 59 THEN '1'
WHEN age &gt;= 60 AND age &lt;= 69 THEN '2'
WHEN age &gt;= 70 AND age &lt;= 79 THEN '3'
ELSE '4'
END AS ageGroup
FROM
(
SELECT
ID,
YEAR (FROM_DAYS(DATEDIFF(NOW(),SUBSTRING( ID_CARD, 7, 8 )))) AS age
FROM
ic_resi_user
WHERE
DEL_FLAG = '0'
AND IS_PARTY = '1'
<choose>
<when test='orgType == "grid"'>
AND GRID_ID = #{orgId}
</when>
<otherwise>
AND (AGENCY_ID = #{orgId} OR PIDS LIKE CONCAT('%',#{orgId},'%'))
</otherwise>
</choose>
) a
) a
GROUP BY ageGroup
</select>
<select id="getPartyMemberAgeList" resultType="com.epmet.dto.result.PartyMemberAgeResultDTO">
SELECT
ID AS "userId",
NAME,
MOBILE,
age
FROM
(
SELECT
ID,
NAME,
MOBILE,
age,
CASE
WHEN age &lt; 50 THEN '0'
WHEN age &gt;= 50 AND age &lt;= 59 THEN '1'
WHEN age &gt;= 60 AND age &lt;= 69 THEN '2'
WHEN age &gt;= 70 AND age &lt;= 79 THEN '3'
ELSE '4'
END AS ageGroup
FROM
(
SELECT
ID,
NAME,
MOBILE,
YEAR (FROM_DAYS(DATEDIFF(NOW(),SUBSTRING( ID_CARD, 7, 8 )))) AS age
FROM
ic_resi_user
WHERE
DEL_FLAG = '0'
AND IS_PARTY = '1'
<choose>
<when test='orgType == "grid"'>
AND GRID_ID = #{orgId}
</when>
<otherwise>
AND (AGENCY_ID = #{orgId} OR PIDS LIKE CONCAT('%',#{orgId},'%'))
</otherwise>
</choose>
) a
) a
<if test="null != code and '' != code">
WHERE ageGroup = #{code}
</if>
ORDER BY CONVERT(NAME USING GBK) ASC
</select>
<select id="getPartyMemberEducationList" resultType="com.epmet.dto.result.PartyMemberEducationResultDTO">
SELECT
ID AS "userId",
NAME,
MOBILE,
CULTURE AS education
FROM
ic_resi_user
WHERE
DEL_FLAG = '0'
AND IS_PARTY = '1'
AND CULTURE IS NOT NULL
<if test="null != code and '' != code">
AND CULTURE = #{code}
</if>
<choose>
<when test='orgType == "grid"'>
AND GRID_ID = #{orgId}
</when>
<otherwise>
AND (AGENCY_ID = #{orgId} OR PIDS LIKE CONCAT('%',#{orgId},'%'))
</otherwise>
</choose>
ORDER BY CONVERT(NAME USING GBK) ASC
</select>
<select id="getPartyMemberEducationStatistics" resultType="com.epmet.commons.tools.dto.result.OptionDataResultDTO">
SELECT
CULTURE AS "code",
count(ID) AS "value"
FROM
ic_resi_user
WHERE
DEL_FLAG = '0'
AND IS_PARTY = '1'
AND CULTURE IS NOT NULL
<choose>
<when test='orgType == "grid"'>
AND GRID_ID = #{orgId}
</when>
<otherwise>
AND (AGENCY_ID = #{orgId} OR PIDS LIKE CONCAT('%',#{orgId},'%'))
</otherwise>
</choose>
GROUP BY CULTURE
</select>
<select id="listIcResiInfosByUserIds"
resultType="com.epmet.dto.result.VolunteerDistributionResultDTO$Distribution">
select userbaseinfo.USER_ID as epmetUserId,
icuser.ID as icResiUserId,
icuser.BUILD_ID as buildingId,
icvol.VOLUNTEER_CATEGORY as volunteerCategoriesStr
from user_base_info userbaseinfo
inner join ic_resi_user icuser on (userbaseinfo.ID_NUM = icuser.ID_CARD and icuser.DEL_FLAG = '0')
inner join ic_volunteer icvol on (icuser.ID = icvol.IC_RESI_USER and icvol.DEL_FLAG = '0')
where userbaseinfo.DEL_FLAG = '0'
and userbaseinfo.ID_NUM is not null
and userbaseinfo.USER_ID in
<foreach collection="userIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</select>
<select id="getCategoryListMap" resultType="java.util.Map">
SELECT
<foreach collection="columns" separator="," item="c">
IFNULL(`${c}`,'0') AS `${c}`
</foreach>
FROM
ic_resi_user
WHERE
del_flag = '0'
AND id = #{icUserId}
</select>
<select id="selectResiUsers" resultType="java.util.Map">
SELECT
ID AS userId,
GRID_ID AS gridId,
HOME_ID AS homeId,
`NAME` AS name,
MOBILE AS mobile,
<foreach collection="types" item="t" separator=",">
${t}
</foreach>
FROM ic_resi_user
WHERE DEL_FLAG = 0
AND STATUS = '0'
AND CONCAT(PIDS,':',AGENCY_ID) LIKE CONCAT('%',#{orgId},'%')
AND(
<foreach collection="types" item="t" separator="OR">
(${t} IS NOT NULL AND ${t} != 0)
</foreach>)
ORDER BY CREATED_TIME DESC
</select>
<!--查询居民信息(map格式)-->
<select id="selectResiInfoMap" resultType="java.util.Map">
select * from ic_resi_user
<where>
CUSTOMER_ID = #{customerId}
AND DEL_FLAG='0'
<if test="idCard != null and idCard != ''">
AND ID_CARD=#{idCard}
</if>
<if test="resiId != null and resiId != ''">
AND ID=#{resiId}
</if>
</where>
</select>
<select id="icUserCustomerIds" resultType="java.lang.String">
SELECT customer_id FROM ic_resi_user GROUP BY customer_id
</select>
<select id="getIcUserList" resultType="java.util.Map">
SELECT
iru.id ID,
iru.customer_id CUSTOMER_ID,
iru.agency_id AGENCY_ID,
iru.pids PIDS,
iru.grid_id GRID_ID,
iru.village_id VILLAGE_ID,
iru.build_id BUILD_ID,
iru.unit_id UNIT_ID,
iru.home_id HOME_ID,
iru.name NAME,
iru.created_by CREATED_BY,
date_format(iru.created_time, '%Y-%m-%d %h:%i:%s') CREATED_TIME
<if test="columns != null and columns.size() > 0">
,
<foreach collection="columns" separator="," item="c">
IFNULL(`${c}`,'0') AS `${c}`
</foreach>
</if>
FROM
ic_resi_user iru
<!-- 只查询在变更记录表不存在新增节点的居民 -->
LEFT JOIN ic_user_change_record iucr ON iru.id = iucr.ic_user_id AND iucr.type = 'add' AND iucr.del_flag = '0'
WHERE
iucr.ic_user_id IS NULL
AND iru.del_flag = '0'
AND iru.`status` = '0'
AND iru.customer_id = #{customerId}
ORDER BY iru.created_time ASC
</select>
<select id="getDataAnalyseCount" resultType="java.util.Map">
SELECT
<foreach collection="columnList" item="item" separator=",">
sum(case ${item} when '1' then 1 else 0 end) ${item}
</foreach>
FROM ic_resi_user
WHERE 1=1
<if test="level != null and level != ''">
<if test="level=='agency'">
AND (CONCAT(PIDS,':', agency_id) like CONCAT('%',#{id},'%'))
</if>
<if test="level=='grid'">
AND GRID_ID = #{id}
</if>
<if test="level=='neighborHood'">
<if test="id != null and id != ''">
AND VILLAGE_ID = #{id}
</if>
<if test="idList != null and idList.size() > 0">
<foreach collection="idList" item="id" open="AND (" close=")" separator=" OR ">
VILLAGE_ID = #{id}
</foreach>
</if>
</if>
<if test="level=='building'">
AND BUILD_ID = #{id}
</if>
</if>
AND CUSTOMER_ID = #{customerId}
AND DEL_FLAG = 0
AND `STATUS` = '0'
<if test="tableName!='ic_resi_user'">
and ID in (
select IC_RESI_USER from ${tableName} where ${columnName} = '1' and CUSTOMER_ID = #{customerId} and DEL_FLAG = '0'
)
</if>
</select>
<!-- 根据房屋IDs查询房屋下是否有存在居民的 -->
<select id="getExistUserByHouseIds" resultType="java.lang.String">
SELECT
DISTINCT home_id
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND home_id IN (
<foreach collection="ids" item="id" separator=",">
#{id}
</foreach>
)
</select>
<select id="getEpidemicPreventionList" resultType="com.epmet.dto.result.EpidemicPreventionResultDTO">
SELECT * FROM
(SELECT
ID,
`NAME`,
GRID_ID,
HOME_ID,
MOBILE,
a.ID_CARD,
a.BIRTHDAY,
IFNULL( b.count, 0 ) AS vaccineCount,
IFNULL( c.count, 0 ) AS natCount
FROM
ic_resi_user a
LEFT JOIN (
SELECT ID_CARD, count(distinct INOCULATE_TIME ) AS count
FROM ic_vaccine
WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
<if test="startDate != null and startDate != ''">
AND DATE_FORMAT(INOCULATE_TIME,"%Y-%m-%d") &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND DATE_FORMAT(INOCULATE_TIME,"%Y-%m-%d") &lt;= #{endDate}
</if>
GROUP BY ID_CARD ) b ON a.ID_CARD = b.ID_CARD
LEFT JOIN (
SELECT ID_CARD, count( id ) AS count
FROM ic_nat
WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
<if test="startDate != null and startDate != ''">
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") &lt;= #{endDate}
</if>
<if test='natStartDate != null and natStartDate != "" '>
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") &gt;= #{natStartDate}
</if>
<if test='natEndDate != null and natEndDate != "" '>
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") &lt;= #{natEndDate}
</if>
GROUP BY ID_CARD ) c ON a.ID_CARD = c.ID_CARD
WHERE
a.DEL_FLAG = '0'
AND a.`STATUS` = '0'
<if test="customerId != null and customerId != ''">
AND a.CUSTOMER_ID = #{customerId}
</if>
<if test="agencyId != null and agencyId != ''">
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE concat( '%', #{agencyId}, '%' ))
</if>
<if test="id != null and id != ''">
AND ID = #{id}
</if>
<if test="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
<if test="neighborId != null and neighborId != ''">
AND VILLAGE_ID = #{neighborId}
</if>
<if test="buildingId != null and buildingId != ''">
AND BUILD_ID = #{buildingId}
</if>
<if test="unitId != null and unitId != ''">
AND UNIT_ID = #{unitId}
</if>
<if test="houseId != null and houseId != ''">
AND HOME_ID = #{houseId}
</if>
<if test="name != null and name != ''">
AND `NAME` LIKE concat( '%', #{name}, '%' )
</if>
<if test="mobile != null and mobile != ''">
AND MOBILE LIKE concat( '%', #{mobile}, '%' )
</if>
<if test="idCard != null and idCard != ''">
AND a.ID_CARD LIKE concat( '%', #{idCard}, '%' )
</if>
<if test=" null != startBirthDay and startBirthDay != '' ">
AND a.BIRTHDAY <![CDATA[ >= ]]> #{startBirthDay}
</if>
<if test="null != endBirthDay and endBirthDay != '' ">
AND a.BIRTHDAY <![CDATA[ <= ]]> #{endBirthDay}
</if>
ORDER BY GRID_ID,VILLAGE_ID,BUILD_ID,UNIT_ID,HOME_ID, convert(NAME using gbk)
) t
WHERE
1=1
<if test="vaccineCount != null">
AND vaccineCount = #{vaccineCount}
</if>
<if test="natCount != null">
AND natCount = #{natCount}
</if>
order by t.vaccineCount desc, t.natCount desc
</select>
<select id="natList" resultType="com.epmet.dto.result.EpidemicPreventionResultDTO">
SELECT * FROM
(SELECT
ID,
`NAME`,
GRID_ID,
HOME_ID,
MOBILE,
a.ID_CARD,
c.created_time,
IFNULL( c.count, 0 ) AS natCount
FROM ic_resi_user a
LEFT JOIN ( SELECT ID_CARD, count( id ) AS count,created_time FROM ic_nat WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) c ON a.ID_CARD = c.ID_CARD
WHERE a.DEL_FLAG = '0'
and a.status = 0
<if test="customerId != null and customerId != ''">
AND a.CUSTOMER_ID = #{customerId}
</if>
<if test="agencyId != null and agencyId != ''">
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE concat( '%', #{agencyId}, '%' ))
</if>
<if test="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
<if test="neighborId != null and neighborId != ''">
AND a.VILLAGE_ID = #{neighborId}
</if>
<if test="buildingId != null and buildingId != ''">
AND a.BUILD_ID = #{buildingId}
</if>
<if test="unitId != null and unitId != ''">
AND a.UNIT_ID = #{unitId}
</if>
<if test="houseId != null and houseId != ''">
AND a.HOME_ID = #{houseId}
</if>
<if test="name != null and name != ''">
AND a.`NAME` LIKE concat( '%', #{name}, '%' )
</if>
<if test="mobile != null and mobile != ''">
AND a.MOBILE LIKE concat( '%', #{mobile}, '%' )
</if>
<if test="idCard != null and idCard != ''">
AND a.ID_CARD LIKE concat( '%', #{idCard}, '%' )
</if>
<if test=" null != startBirthDay and startBirthDay != '' ">
AND a.BIRTHDAY <![CDATA[ >= ]]> #{startBirthDay}
</if>
<if test="null != endBirthDay and endBirthDay != '' ">
AND a.BIRTHDAY <![CDATA[ <= ]]> #{endBirthDay}
</if>
) t
WHERE 1=1
<if test="startDate != null and startDate != ''">
AND date_format(created_time,'%Y%m%d') >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND date_format(created_time,'%Y%m%d') <![CDATA[ <= ]]> #{endDate}
</if>
<if test="natCount != null">
AND natCount <![CDATA[ <= ]]> #{natCount}
</if>
ORDER BY `NAME`
</select>
<select id="vaccineList" resultType="com.epmet.dto.result.EpidemicPreventionResultDTO">
SELECT * FROM
(SELECT
ID,
`NAME`,
GRID_ID,
HOME_ID,
MOBILE,
a.ID_CARD,
b.created_time,
IFNULL( b.count, 0 ) AS vaccineCount
FROM ic_resi_user a
LEFT JOIN ( SELECT ID_CARD, count( id ) AS count,created_time FROM ic_vaccine WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) b ON a.ID_CARD = b.ID_CARD
WHERE a.DEL_FLAG = '0'
and a.status = 0
<if test="customerId != null and customerId != ''">
AND a.CUSTOMER_ID = #{customerId}
</if>
<if test="agencyId != null and agencyId != ''">
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE concat( '%', #{agencyId}, '%' ))
</if>
<if test="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
) t
WHERE 1=1
<if test="startDate != null and startDate != ''">
AND date_format(created_time,'%Y%m%d') >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND date_format(created_time,'%Y%m%d') <![CDATA[ <= ]]> #{endDate}
</if>
<if test="vaccineCount != null">
AND vaccineCount <![CDATA[ <= ]]> #{vaccineCount}
</if>
ORDER BY `NAME`
</select>
<select id="selectResiNoDelFlag" resultType="com.epmet.entity.IcResiUserEntity">
SELECT ID,NAME,ID_CARD,DEL_FLAG FROM ic_resi_user WHERE ID = #{icResiUserId}
</select>
<select id="userChart" resultType="com.epmet.dto.result.UserChartResultDTO">
SELECT
COUNT(id) num,
is_floating isFloating
FROM
ic_resi_user
WHERE
del_flag = '0'
AND status = '0'
<choose>
<when test='orgType == "agency"'>
AND (agency_id = #{orgId} OR pids LIKE CONCAT('%', #{orgId}, '%'))
<if test='null != agencyIdList and agencyIdList.size() > 0'>
<foreach collection="agencyIdList" item="agencyId" open="AND agency_id NOT IN (" separator="," close=")">
#{agencyId}
</foreach>
</if>
<if test='null != gridIdList and gridIdList.size() > 0'>
<foreach collection="gridIdList" item="gridId" open="AND grid_id NOT IN (" separator="," close=")">
#{gridId}
</foreach>
</if>
</when>
<when test='orgType == "grid"'>
AND grid_id = #{orgId}
</when>
<otherwise>
AND village_id = #{orgId}
</otherwise>
</choose>
GROUP BY is_floating
</select>
<select id="getResiUserGroupHomeId" resultMap="homeMemberList">
SELECT
HOME_ID,
ID,NAME,GENDER,MOBILE,ID_CARD,BIRTHDAY,HJSZD,YHZGX,IS_PARTY,IS_TENANT,IS_FLOATING,GZDW,MZ,JG,HYZK,CULTURE,FAITH,REMARKS
FROM ic_resi_user
WHERE
STATUS = '0'
AND DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
<if test="pids != null and pids.trim() != ''">
and ( AGENCY_ID = #{agencyId} OR PIDS like CONCAT(#{pids}, '%') )
</if>
<if test="gridId != null and gridId.trim() != ''">
and GRID_ID = #{gridId}
</if>
<if test="neighborHoodId != null and neighborHoodId.trim() != ''">
and VILLAGE_ID = #{neighborHoodId}
</if>
<if test="buildingId != null and buildingId.trim() != ''">
and BUILD_ID = #{buildingId}
</if>
<if test="houseId != null and houseId.trim() != ''">
and HOME_ID = #{houseId}
</if>
</select>
<select id="listUserIds" resultType="java.lang.String">
SELECT ID from ic_resi_user
WHERE
GRID_ID = #{gridId}
AND CUSTOMER_ID = #{customerId}
and VILLAGE_ID = #{neighborhoodId}
AND DEL_FLAG = '0'
</select>
<select id="getAllUserIds" parameterType="map" resultType="java.lang.String">
SELECT
I.ID
FROM
ic_resi_user i
WHERE
i.DEL_FLAG = '0'
AND i.CUSTOMER_ID = #{customerId}
AND i.ID_CARD = #{idCard}
UNION
SELECT
ubi.USER_ID
FROM
user_base_info ubi
WHERE
ubi.DEL_FLAG = '0'
AND ubi.CUSTOMER_ID = #{customerId}
AND ubi.ID_NUM = #{idCard}
</select>
<select id="getVolunteerList" resultType="com.epmet.dto.IcVolunteerPolyDTO">
SELECT
a.ID AS icResiUser,
a.CUSTOMER_ID,
a.AGENCY_ID,
a.PIDS AS agencyPids,
`NAME`,
ID_CARD,
MOBILE,
GENDER,
IS_PARTY,
IFNULL( VOLUNTEER_CATEGORY, "qita" ) AS VOLUNTEER_CATEGORY,
IFNULL( IS_DYZXH, "0" ) AS IS_DYZXH
FROM
ic_resi_user a
LEFT JOIN ic_volunteer b ON a.ID = b.IC_RESI_USER
AND b.DEL_FLAG = '0'
LEFT JOIN ic_party_member c ON a.ID = c.IC_RESI_USER
AND c.DEL_FLAG = '0'
WHERE
a.DEL_FLAG = '0'
AND a.IS_VOLUNTEER = '1'
AND a.CUSTOMER_ID = #{customerId}
<if test="null != userId and userId.trim() != ''">
AND a.ID = #{userId}
</if>
UNION ALL
SELECT
a.ID AS icResiUser,
a.CUSTOMER_ID,
a.AGENCY_ID,
a.PIDS AS agencyPids,
`NAME`,
ID_CARD,
MOBILE,
GENDER,
IS_PARTY,
'dangyuanzhongxinhu' AS VOLUNTEER_CATEGORY,
IFNULL( IS_DYZXH, "0" ) AS IS_DYZXH
FROM
ic_resi_user a
INNER JOIN ic_party_member c ON a.ID = c.IC_RESI_USER
AND c.DEL_FLAG = '0'
WHERE
a.DEL_FLAG = '0'
AND a.IS_VOLUNTEER != '1'
AND a.IS_PARTY = '1'
AND a.CUSTOMER_ID = #{customerId}
AND c.IS_DYZXH = '1'
<if test="null != userId and userId.trim() != ''">
AND a.ID = #{userId}
</if>
</select>
<select id="selectCountByIdCard" resultType="java.lang.Integer">
select
count(*)
from
ic_resi_user
where
id_card = #{idCard}
and customer_id = #{customerId}
and del_flag = '0'
</select>
<select id="seletIdByIdCard" resultType="java.lang.String">
select id from ic_resi_user where id_card = #{idCard} and customer_id = #{customerId}
</select>
<select id="selectMemberDetail" resultType="com.epmet.dto.IcResiUserConfirmDTO">
select
ID as icResiUserId,
name,
ID_CARD,
gender,
birthday,
MOBILE,
mz,
HJSZD,
yhzgx,
XJZD,
HOME_ID AS houseId
from ic_resi_user
where DEL_FLAG='0'
and Status='0'
and id=#{icResiUserId}
</select>
<select id="moveOutMember" resultType="com.epmet.dto.form.MoveOutMemberFormDTO">
SELECT
AGENCY_ID,
PIDS,
HOME_ID AS houseId,
NAME as allName,
MOBILE,
GENDER,
ID_CARD,
BIRTHDAY,
HJSZD,
XJZD,
mz,
YHZGX
FROM
ic_resi_user
WHERE
id = #{icResiUserId}
AND customer_id = #{customerId}
AND STATUS = '0'
AND DEL_FLAG = '0'
</select>
<select id="selectResiUserEntityByIdCard" resultType="com.epmet.entity.IcResiUserEntity">
select * from ic_resi_user
WHERE
ID_CARD = #{idCard}
AND customer_id = #{customerId}
AND DEL_FLAG = '0'
</select>
<select id="getResiUserCountGroupHomeId" resultType="java.util.Map">
select
HOME_ID houseId,
count(1) resiNumber,
AVG(YSR) avgYsr
from ic_resi_user WHERE CUSTOMER_ID = #{customerId} and DEL_FLAG = '0' AND `status` = '0' group by HOME_ID
</select>
<select id="getListIcResiUserDTO" parameterType="map" resultType="com.epmet.dto.IcResiUserDTO">
select id, NAME,MOBILE
from ic_resi_user
WHERE 1=1
<foreach collection="icResiUserIdList" item="icResiUserId" open="AND (" separator="or" close=")">
id = #{icResiUserId}
</foreach>
</select>
<select id="getUserListByCommunityId" resultType="com.epmet.dto.result.SendPointNoticeResultDTO">
select
ru.ID_CARD,
ru.MOBILE,
ub.USER_ID
from ic_resi_user ru
left join user_base_info ub on ub.ID_NUM = ru.ID_CARD and ub.DEL_FLAG = 0
where ru.DEL_FLAG = 0
and ub.USER_ID is not null
and ru.MOBILE is not null
and ru.MOBILE != ''
and ru.PIDS like CONCAT('%',#{communityId},'%')
</select>
<select id="getIcUserCount" resultType="com.epmet.dto.result.IcUserCountResultDTO">
SELECT
<if test='type == "0"'>
CASE #{orgType}
WHEN '0' THEN AGENCY_ID
WHEN '1' THEN GRID_ID
WHEN '2' THEN VILLAGE_ID
WHEN '3' THEN BUILD_ID
WHEN '4' THEN UNIT_ID
ELSE HOME_ID END AS "id",
</if>
<if test='type == "1"'>
CASE #{orgType}
WHEN '0' THEN GRID_ID
WHEN '1' THEN VILLAGE_ID
WHEN '2' THEN BUILD_ID
WHEN '3' THEN UNIT_ID
WHEN '4' THEN HOME_ID
ELSE HOME_ID END AS "id",
</if>
COUNT(ID) AS "count"
FROM
ic_resi_user
WHERE
DEL_FLAG = '0'
AND STATUS = '0'
<choose>
<when test='orgType == "0"'>
AND AGENCY_ID = #{orgId}
</when>
<when test='orgType == "1"'>
AND GRID_ID = #{orgId}
</when>
<when test='orgType == "2"'>
AND VILLAGE_ID = #{orgId}
</when>
<when test='orgType == "3"'>
AND BUILD_ID = #{orgId}
</when>
<when test='orgType == "4"'>
AND UNIT_ID = #{orgId}
</when>
</choose>
<if test='type == "1"'>
GROUP BY
<choose>
<when test='orgType == "0"'>
GRID_ID
</when>
<when test='orgType == "1"'>
VILLAGE_ID
</when>
<when test='orgType == "2"'>
BUILD_ID
</when>
<when test='orgType == "3"'>
UNIT_ID
</when>
<when test='orgType == "4"'>
HOME_ID
</when>
</choose>
</if>
</select>
<select id="icUserStatisList" resultType="com.epmet.dto.result.SearchByNameResultDTO">
SELECT
id AS userId,
`name`,
village_id AS neighborHoodId,
build_id,
grid_id,
mobile,
(
case when gender = '1'then '男'
when gender = '2' then '女'
else '未知'
end
) as gender,
id_card,
IFNULL(birthday,'') AS birthday,
IFNULL(remarks,'') AS remarks
FROM
ic_resi_user
WHERE
del_flag = '0'
AND status = '0'
AND customer_id = #{customerId}
<if test='null != type and type.trim() != "" and type == "cz" '>
AND is_floating = '0'
</if>
<if test='null != type and type.trim() != "" and type == "ld" '>
AND (is_floating != '0' or is_floating is null)
</if>
<if test='null != rhType and rhType.trim() != "" and rhType == "rhyz" '>
AND RHZK = 'rhyz'
</if>
<if test='null != rhType and rhType.trim() != "" and rhType == "rzhbz" '>
AND RHZK = 'rzhbz'
</if>
<if test='null != rhType and rhType.trim() != "" and rhType == "hzrbz" '>
AND RHZK = 'hzrbz'
</if>
<if test='null != rhType and rhType.trim() != "" and rhType == "no" '>
AND(RHZK = '' or RHZK IS null)
</if>
<choose>
<when test='orgType == "agency"'>
AND (agency_id = #{orgId} OR pids LIKE CONCAT('%', #{orgId}, '%'))
<if test='null != agencyIdList and agencyIdList.size() > 0'>
<foreach collection="agencyIdList" item="agencyId" open="AND agency_id NOT IN (" separator="," close=")">
#{agencyId}
</foreach>
</if>
<if test='null != gridIdList and gridIdList.size() > 0'>
<foreach collection="gridIdList" item="gridId" open="AND grid_id NOT IN (" separator="," close=")">
#{gridId}
</foreach>
</if>
</when>
<when test='orgType == "grid"'>
AND grid_id = #{orgId}
</when>
<otherwise>
AND village_id = #{orgId}
</otherwise>
</choose>
ORDER BY `name` ASC
</select>
<!-- 根据身份证获取组织下的居民个数 -->
<select id="getResiCount" resultType="com.epmet.dto.result.ResiAndLocalResiResultDTO">
SELECT
(SELECT
COUNT(ID)
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND `STATUS` = 0
AND PIDS LIKE CONCAT('%',#{agencyId},'%')
AND ID_CARD = #{idCard}) AS isLocal,
COUNT(ID) AS isResi,
id as userId
from ic_resi_user
WHERE DEL_FLAG = '0'
AND `STATUS` = 0
AND CUSTOMER_ID = #{customerId}
AND ID_CARD = #{idCard}
</select>
<!-- 根据人户状况查询每个类型的人数 -->
<select id="getUserByRenHu" resultType="com.epmet.dto.result.RHZKStatisticsResultDTO">
SELECT
COUNT(ID) AS total,
rhzk,
orgId
FROM
(SELECT
ID,
IFNULL(RHZK,'') AS rhzk,
<if test='orgType == "agency" '>
AGENCY_ID AS orgId
</if>
<if test='orgType == "grid" '>
GRID_ID AS orgId
</if>
<if test='orgType == "village" '>
VILLAGE_ID AS orgId
</if>
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND `STATUS` = '0'
<if test='orgType == "agency" '>
AND PIDS LIKE CONCAT('%',#{orgId},'%')
</if>
<if test='orgType == "grid" '>
AND GRID_ID = #{orgId}
</if>
<if test='orgType == "village" '>
AND VILLAGE_ID = #{orgId}
</if>
) t
GROUP BY rhzk
</select>
<select id="getResiUserList" resultType="com.epmet.dto.IcResiUserDTO">
SELECT
a.id,
a.customer_id,
a.`name`,
a.id_card
FROM
ic_resi_user a
LEFT JOIN ic_resi_comparison_record b on a.id = b.RESI_ID
WHERE
a.del_flag = '0'
AND a.pids LIKE CONCAT('%',#{agencyId},'%')
<if test='null != userIdList and userIdList.size() > 0'>
<foreach collection="userIdList" item="id" open="AND a.id IN (" separator="," close=")">
#{id}
</foreach>
</if>
AND b.id is null
order by a.pids ASC, a.created_time DESC
</select>
<select id="getImportUserList" resultType="com.epmet.dto.IcResiUserDTO">
select * from ic_resi_user where pids like concat('%',#{agencyId},'%') and status='0' and customer_id=#{customerId}
</select>
<!-- 烟台居民画像:按照学历分组,查询居民数量-->
<select id="queryEducationDistribute" parameterType="map" resultType="com.epmet.dto.result.resi.ResiPortrayalResultDTO">
SELECT
CULTURE AS `code`,
count( id ) AS totalResi
FROM (SELECT ID, IF(CULTURE = '', NULL, CULTURE) AS CULTURE FROM
ic_resi_user r
WHERE
r.DEL_FLAG = '0'
AND r.CUSTOMER_ID = #{customerId}
<if test='orgType == "agency" '>
and r.PIDS LIKE concat(#{orgIdPath},'%')
</if>
<if test='orgType == "grid" '>
and r.GRID_ID = #{orgId}
</if>
AND r.`STATUS` = '0'
-- AND r.CULTURE IS NOT NULL
-- AND r.CULTURE != ''
) iru
GROUP BY
iru.CULTURE
</select>
<!-- 烟台居民画像:年龄分布 -->
<select id="selectAgeAgeDistribute" parameterType="map" resultType="com.epmet.dto.result.resi.ResiPortrayalResultDTO">
select
temp.CODE,
count(temp.ID) as totalResi
from (
select
temp1.id,
(
case when temp1.age &lt; 50 then '0'
when temp1.age &gt;= 50 and temp1.age &lt;= 59 then '1'
when temp1.age &gt;= 60 and temp1.age &lt;= 69 then '2'
when temp1.age &gt;= 70 and temp1.age &lt;= 79 then '3'
when temp1.age &gt;= 80 then '4'
-- when temp1.age is NULL then '5'
end
) as `code`
from (
SELECT
u.ID,
IF((u.BIRTHDAY IS NULL OR u.BIRTHDAY =''),NULL,YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4)) as age
FROM
ic_resi_user u
WHERE
u.DEL_FLAG = '0'
AND u.CUSTOMER_ID = #{customerId}
and u.`STATUS`='0'
-- and u.BIRTHDAY is not null
-- and u.BIRTHDAY !=''
<if test='orgType == "agency" '>
and u.PIDS LIKE concat(#{orgIdPath},'%')
</if>
<if test='orgType == "grid" '>
and u.GRID_ID = #{orgId}
</if>
)temp1
)temp
group by temp.`code`
</select>
<!-- 居民画像,居民列表 codeType 学历:education 年龄:age -->
<select id="selectPortrayalResiList" parameterType="map" resultType="com.epmet.dto.result.resi.ResiPortrayalDetailDTO">
SELECT
u.ID AS icResiUserId,
u.grid_id as gridId,
u.VILLAGE_ID as villageId,
u.BUILD_ID as buildId,
u.UNIT_ID as unitId,
u.HOME_ID as homeId,
u.`NAME` AS `name`,
u.MOBILE AS mobile,
u.ID_CARD AS idCard,
u.GENDER AS gender,
( CASE WHEN u.GENDER = '1' THEN '男' WHEN u.GENDER = '2' THEN '女' ELSE '未知' END ) AS genderName,
YEAR (NOW())- SUBSTR( u.BIRTHDAY, 1, 4 ) AS age,
u.CULTURE AS educationCode,
(
case when u.CULTURE='0' then '小学及文盲'
when u.CULTURE='1' then '初中'
when u.CULTURE='2' then '高中'
when u.CULTURE='3' then '大专'
when u.CULTURE='4' then '本科'
when u.CULTURE='5' then '硕士'
when u.CULTURE='6' then '博士'
when u.CULTURE='7' then '中专'
else ''
end
)as educationName,
'' AS educationName,
IFNULL(u.CULTURE,'')AS educationCode,
u.BIRTHDAY AS birthday
FROM
ic_resi_user u
WHERE
u.DEL_FLAG = '0'
AND u.CUSTOMER_ID = #{customerId}
AND u.`STATUS` = '0'
<if test='orgType == "agency" '>
and u.PIDS LIKE concat(#{orgIdPath},'%')
</if>
<if test='orgType == "grid" '>
and u.GRID_ID = #{orgId}
</if>
<if test='codeType == "education" '>
<if test="code != null and code != ''">
and u.CULTURE = #{code}
</if>
</if>
<if test='codeType == "age" '>
<if test=" 0 == code">
and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &lt; 50
</if>
<if test=" 1 == code">
and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &gt;=50 and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &lt;=59
</if>
<if test=" 2 == code">
and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &gt;= 60 and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &lt;= 69
</if>
<if test=" 3 == code">
and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &gt;=70 and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &lt;=79
</if>
<if test=" 4 == code">
and YEAR(NOW())-SUBSTR(u.BIRTHDAY, 1, 4) &gt;=80
</if>
</if>
order by u.ID asc
</select>
<!-- 不限制任何状态 -->
<select id="getById" parameterType="java.lang.String" resultType="com.epmet.entity.IcResiUserEntity">
select r.* from ic_resi_user r where r.id = #{icResiUserId}
</select>
</mapper>