<?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>
<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>
and ic_resi_user.customer_id=#{customerId}
and (ic_resi_user.AGENCY_ID =#{currentStaffAgencyId} or ic_resi_user.pids like concat(#{staffOrgPath},'%'))
<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' " >
and ${subCondition.tableName}.${subCondition.columnName} between #{subCondition.columnValue[0]} and #{subCondition.columnValue[1]}
</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' " >
and ${subCondition.tableName}.${subCondition.columnName} between #{subCondition.columnValue[0]} and #{subCondition.columnValue[1]}
</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>
<!-- 查询列表用 -->
<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 = #{keyword}
or MOBILE = #{keyword}
or ID_CARD = #{keyword}
)
</if>
</where>
group by IC_RESI_USER.id
<if test= "null != groupByTables and groupByTables.size() > 0" >
<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>
<update id= "updateToDel" parameterType= "java.lang.String" >
update ic_resi_user set del_flag='1' where id=#{icResiUserId}
</update>
<update id= "updateSubTableToDel" parameterType= "map" >
update ${subTalbeName} set del_flag='1' where IC_RESI_USER=#{icResiUserId}
</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>
group by IC_RESI_USER.id
<if test= "null != groupByTables and groupByTables.size() > 0" >
<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= "CUSTOMER_ID" property= "customerId" />
<result column= "GRID_ID" property= "gridId" />
<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,
IFNULL(IS_VOLUNTEER,'0') AS isVolunteer,
CUSTOMER_ID,
GRID_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}
<if test= "level != null and level != ''" >
<if test= "level=='agency'" >
AND (AGENCY_ID = #{id} OR PIDS LIKE CONCAT('%',#{id},'%'))
</if>
<if test= "level=='grid'" >
AND GRID_ID = #{id}
</if>
<if test= "level=='neighborHood'" >
AND VILLAGE_ID = #{id}
</if>
<if test= "level=='building'" >
AND BUILD_ID = #{id}
</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 `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>
<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
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 < 50 THEN '0'
WHEN age > = 50 AND age < = 59 THEN '1'
WHEN age > = 60 AND age < = 69 THEN '2'
WHEN age > = 70 AND age < = 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 < 50 THEN '0'
WHEN age > = 50 AND age < = 59 THEN '1'
WHEN age > = 60 AND age < = 69 THEN '2'
WHEN age > = 70 AND age < = 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 >
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'" >
AND VILLAGE_ID = #{id}
</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,
IFNULL( b.count, 0 ) AS vaccineCount,
IFNULL( c.count, 0 ) AS natCount
FROM
ic_resi_user a
LEFT JOIN (
SELECT ID_CARD, count( id ) 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") > #{startDate}
</if>
<if test= "endDate != null and endDate != ''" >
AND DATE_FORMAT(INOCULATE_TIME,"%Y-%m-%d") < #{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") > #{startDate}
</if>
<if test= "endDate != null and endDate != ''" >
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") < #{endDate}
</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>
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>
</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>
) 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 DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
</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= "selectMemberDetail" resultType= "com.epmet.dto.IcResiUserConfirmDTO" >
select
ID as icResiUserId,
name,
ID_CARD,
gender,
birthday,
MOBILE,
mz,
HJSZD,
yhzgx,
XJZD
from ic_resi_user
where DEL_FLAG='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>
</mapper>