<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.social.mapper.TSocialSoldierMapper">

	<!-- 社保士兵基本查询-->
	<sql id="getSocialSoldierBaseOne" >
		SELECT
			s.id as socialId,
			if(a.TYPE='0','派增','派减') type,
			case a.SOCIAL_HANDLE_STATUS when '0' then '未办理' when '1' then '全部办理成功' when '2' then '全部办理失败' when '3' then '部分办理成功' when '4' then '办理中' else '-' end socialHandleStatus,
			case if(ifnull(h.id,0) != '0',h.PENSION_HANDLE,s.PENSION_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end pensionHandle,
			case if(ifnull(h.id,0) != '0',h.MEDICAL_HANDLE,s.MEDICAL_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end medicalHandle,
			case if(ifnull(h.id,0) != '0',h.UNEMPLOY_HANDLE,s.UNEMPLOY_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end unemployHandle,
			case if(ifnull(h.id,0) != '0',h.WORK_INJURY_HANDLE,s.WORK_INJURY_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end workInjuryHandle,
			case if(ifnull(h.id,0) != '0',h.BIRTH_HANDLE,s.BIRTH_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end birthHandle,
			case if(ifnull(h.id,0) != '0',h.BIGAILMENT_HANDLE,s.BIGAILMENT_HANDLE) when '0' then '派增待办理' when '1' then '派增办理成功' when '2' then '派增办理失败' when '3' then '派减-已派减' when '4' then '派减失败' when '5' then '派减待办理' else '——' end bigailmentHandle,
			a.EMP_NAME empName,
			a.EMP_IDCARD empIdcard,
			a.EDUCATION_NAME educationName,
			a.BELONG_UNIT_NAME belongUnit,
			a.SETTLE_DOMAIN_NAME settleDomain,
			emp_natrue.label empType,
			a.POST post,
			a.EMP_MOBILE empMobile,
			a.ID_CARD_ADDRESS idCardAddress,
			a.CONTACT_ADDRESS contactAddress,
			registype.label regisType,
			nation.label empNational,
			workingHours.label workingHours,
			a.CONTRACT_TERM contractTerm,
			s.SOCIAL_START_DATE contractStart,
			a.CONTRACT_END contractEnd,
			a.CREATE_NAME createUserName,
			s.RECORD_BASE recordBase,
			case s.PAYMENT_TYPE when '0' then '最低' when '1' then '自定义' when '2' then '最高' else '-' end paymentType,
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(ifnull(h.id,0) != '0',sp1.AREA_NAME,sp2.AREA_NAME) socialProvince,
			if(ifnull(h.id,0) != '0',sc1.AREA_NAME,sc2.AREA_NAME) socialCity,
			if(ifnull(h.id,0) != '0',st1.AREA_NAME,st2.AREA_NAME) socialTown,
			if(ifnull(h.id,0) != '0',h.PENSION_START,s.PENSION_START) pensionStart,
			if(ifnull(h.id,0) != '0',h.UNIT_PENSION_CARDINAL,s.UNIT_PENSION_CARDINAL) unitPensionCardinal,
			if(ifnull(h.id,0) != '0',h.MEDICAL_START,s.MEDICAL_START) medicalStart,
			if(ifnull(h.id,0) != '0',h.UNIT_MEDICAL_CARDINAL,s.UNIT_MEDICAL_CARDINAL) unitMedicalCardinal,
			if(ifnull(h.id,0) != '0',h.UNEMPLOY_START,s.UNEMPLOY_START) unemployStart,
			if(ifnull(h.id,0) != '0',h.UNIT_UNEMPLOYMENT_CARDINAL,s.UNIT_UNEMPLOYMENT_CARDINAL) unitUnemploymentCardinal,
			if(ifnull(h.id,0) != '0',h.WORK_INJURY_START,s.WORK_INJURY_START) workInjuryStart,
			if(ifnull(h.id,0) != '0',h.UNIT_WORK_INJURY_CARDINAL,s.UNIT_WORK_INJURY_CARDINAL) unitWorkInjuryCardinal,
			if(ifnull(h.id,0) != '0',h.BIRTH_START,s.BIRTH_START) birthStart,
			if(ifnull(h.id,0) != '0',h.UNIT_BIRTH_CARDINAL,s.UNIT_BIRTH_CARDINAL) unitBirthCardinal,
			if(ifnull(h.id,0) != '0',h.BIGAILMENT_START,s.BIGAILMENT_START) bigailmentStart,
			if(ifnull(h.id,0) != '0',h.UNIT_BIGAILMENT_CARDINAL,s.UNIT_BIGAILMENT_CARDINAL) unitBigailmentCardinal,
			if(ifnull(h.id,0) != '0',h.UNIT_BIGAILMENT_MONEY,s.UNIT_BIGAILMENT_MONEY) unitBigailmentMoney,
			if(ifnull(h.id,0) != '0',h.PERSONAL_BIGAILMENT_MONEY,s.PERSONAL_BIGAILMENT_MONEY) personalBigailmentMoney,
			a.TRUST_REMARK socailTrustRemark,
			reduceReason.label reduceReason,
			'1'  as exportSocialFlag,
			a.SCHOOL_NAME schoolName,
			a.MAJOR major,
			a.FIRST_PAY_TIME graduationTime,
			a.GRADUATION_TIME firstPayTime
	</sql>

	<!-- 社保士兵基本查询-->
	<sql id="getSocialSoldierBaseTwo" >

		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		left join t_dispatch_social_fund_info h on a.id = h.REDUCE_SOCIAL_FUND_ID
		left join view_sys_dict_item emp_natrue on emp_natrue.value=a.EMP_TYPE and emp_natrue.type='emp_natrue'
		left join view_sys_dict_item registype on registype.value=a.EMP_REGIS_TYPE and registype.type='emp_registype'
		left join view_sys_dict_item nation on nation.value=a.EMP_NATIONAL and nation.type='emp_national'
		left join view_sys_dict_item workingHours on workingHours.value=a.WORKING_HOURS and workingHours.type='working_hours'
		left join view_sys_dict_item reduceReason on reduceReason.value=a.REDUCE_REASON and reduceReason.type='social_reduce_reason'
		left join sys_area sp1 on sp1.id = h.SOCIAL_PROVINCE
		left join sys_area sp2 on sp2.id = s.SOCIAL_PROVINCE
		left join sys_area sc1 on sc1.id = h.SOCIAL_CITY
		left join sys_area sc2 on sc2.id = s.SOCIAL_CITY
		left join sys_area st1 on st1.id = h.SOCIAL_TOWN
		left join sys_area st2 on st2.id = s.SOCIAL_TOWN

		<include refid="where_getSocialSoldier_base_handler"/>
		and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
	</sql>

	<!-- 社保士兵养工失增加模板-->
	<select id="getSocialSoldierYgsAddVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYgsAddVo">
		<include refid="getSocialSoldierBaseOne"/>
		,'是' isAutoSubmit,'是' isAutoInsert,'是' isAutoUpload,'是' isDoShenBao,'' isDanShenBao
		<include refid="getSocialSoldierBaseTwo"/>
		and a.type = '0' and s.YGS_HANDLE_STATUS in ('0','1','2','3') and s.YGS_REQUEST_ID is null
		and (
			if(ifnull(h.id,0) != '0',h.PENSION_HANDLE,s.PENSION_HANDLE) = '0' or
			if(ifnull(h.id,0) != '0',h.WORK_INJURY_HANDLE,s.WORK_INJURY_HANDLE) = '0' or
			if(ifnull(h.id,0) != '0',h.UNEMPLOY_HANDLE,s.UNEMPLOY_HANDLE) = '0'
		)
		group by s.id
	</select>

	<sql id="where_getSocialSoldier_base_handler">
		<where>
			a.DELETE_FLAG = '0'
			<if test="idsStr != null and idsStr.size > 0">
				AND a.ID in
				<foreach item="items" index="index" collection="idsStr" open="(" separator="," close=")">
					#{items}
				</foreach>
			</if>
			/** 社保办理状态：0待办理/1已办理2办理失败3已派减4 办理中 5 部分办理失败 派单社保办理状态 0 未办理 1 全部办理成功(原-已办理) 2 全部办理失败（原-办理失败）  3 部分办理成功 4 办理中  **/
			/*社保代办理 1.派单审核通过 2.派增(type=0)：待办理(social_handle_status='0')  or 派减(type=1)：已办理完成或部分办理失败 且已派减*/
			AND a.social_id is not null
			AND a.STATUS = "2"
			and (( a.type = '0' AND (s.HANDLE_STATUS = "0" or s.HANDLE_STATUS = "4") ) or ( a.type ='1'  AND (if(ifnull(h.id,0) != '0',h.HANDLE_STATUS,s.HANDLE_STATUS) in ('1','5','6','3','7') or (s.HANDLE_STATUS in ('1','5','6','3','7') and s.REDUCE_CAN = '1'))  ))
			and a.SOCIAL_HANDLE_STATUS in ('0','4')
			and a.AUTO_FLAG = '0'
		</where>
	</sql>

	<!-- 社保士兵养工失减少模板-->
	<select id="getSocialSoldierYgsReduceVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYgsAddVo">
		<include refid="getSocialSoldierBaseOne"/>
		,'是' isAutoSubmit,'是' isAutoInsert,'是' isAutoUpload,'是' isDoShenBao,'' isDanShenBao
		<include refid="getSocialSoldierBaseTwo"/>
		and a.type = '1' and s.YGS_HANDLE_STATUS in ('0','1','2','3') and s.YGS_REQUEST_ID is null
		and (
			if(ifnull(h.id,0) != '0',h.PENSION_HANDLE,s.PENSION_HANDLE) = '5' or
			if(ifnull(h.id,0) != '0',h.WORK_INJURY_HANDLE,s.WORK_INJURY_HANDLE) = '5' or
			if(ifnull(h.id,0) != '0',h.UNEMPLOY_HANDLE,s.UNEMPLOY_HANDLE) = '5'
		)
		group by a.id
	</select>

	<!-- 社保士兵医生大增加模板-->
	<select id="getSocialSoldierYsdAddVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAddVo">
		<include refid="getSocialSoldierBaseOne"/>
		,'' isBatch,'是' isAutoMonth,'' isAdd,'' isXu,'是' isShen
		<include refid="getSocialSoldierBaseTwo"/>
		and a.type = '0' and s.YSD_HANDLE_STATUS in ('0','1','2','3')  and s.YSD_REQUEST_ID is null
		and (
			if(ifnull(h.id,0) != '0',h.MEDICAL_HANDLE,s.MEDICAL_HANDLE) = '0' or
			if(ifnull(h.id,0) != '0',h.BIRTH_HANDLE,s.BIRTH_HANDLE) = '0' or
			if(ifnull(h.id,0) != '0',h.BIGAILMENT_HANDLE,s.BIGAILMENT_HANDLE) = '0'
		)
		group by s.id
	</select>

	<!-- 社保士兵医生大减少模板-->
	<select id="getSocialSoldierYsdReduceVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAddVo">
		<include refid="getSocialSoldierBaseOne"/>
		,'' isBatch,'是' isAutoMonth,'' isAdd,'' isXu,'是' isShen
		<include refid="getSocialSoldierBaseTwo"/>
		and a.type = '1' and s.YSD_HANDLE_STATUS in ('0','1','2','3')  and s.YSD_REQUEST_ID is null
		and (
			if(ifnull(h.id,0) != '0',h.MEDICAL_HANDLE,s.MEDICAL_HANDLE) = '5' or
			if(ifnull(h.id,0) != '0',h.BIRTH_HANDLE,s.BIRTH_HANDLE) = '5' or
			if(ifnull(h.id,0) != '0',h.BIGAILMENT_HANDLE,s.BIGAILMENT_HANDLE) = '5'
		)
		group by s.id
	</select>


	<!-- 社保士兵养工失审核结果查询的模板-->
	<select id="getSocialSoldierYgsAuditVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYgsAuditVo">
		SELECT
			s.id as socialId,
			a.EMP_NAME empName,
			a.EMP_IDCARD empIdcard,
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','增员','减员') type,
			DATE_FORMAT(a.AUDIT_TIME,'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YGS_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		group by s.id
	</select>

	<!-- 社保士兵医生大审核结果【续保】查询的模板-->
	<select id="getSocialSoldierYsdAuditVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAuditVo">
		SELECT
			s.id as socialId,
			a.EMP_NAME empName,
			a.EMP_IDCARD empIdcard,
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','参保人员增员申报','参保人员减员申报') type,
			DATE_FORMAT(a.AUDIT_TIME,'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YSD_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		and s.YSD_REMARK_OLD != "新增"
		group by s.id
	</select>

	<!-- 社保士兵养工失审核结果查询的模板-->
	<select id="getSocialSoldierYgsAuditVoListByGroupBy" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYgsAuditVo">
		SELECT
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','增员','减员') type,
			DATE_FORMAT(min(a.AUDIT_TIME),'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YGS_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		group by a.SOCIAL_HOUSEHOLD_NAME,a.TYPE
	</select>

	<!-- 社保士兵医生大审核结果【续保】查询的模板-->
	<select id="getSocialSoldierYsdAuditVoListByGroupBy" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAuditVo">
		SELECT
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','参保人员增员申报','参保人员减员申报') type,
			DATE_FORMAT(min(a.AUDIT_TIME),'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YSD_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		and s.YSD_REMARK_OLD != "新增"
		group by a.SOCIAL_HOUSEHOLD_NAME,a.TYPE
	</select>

	<!-- 社保士兵医生大审核结果【新增】查询的模板-->
	<select id="getSocialSoldierYsdAddAuditVoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAuditVo">
		SELECT
			s.id as socialId,
			a.EMP_NAME empName,
			a.EMP_IDCARD empIdcard,
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','职工新参保登记','参保人员减员申报') type,
			DATE_FORMAT(a.AUDIT_TIME,'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YSD_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		and s.YSD_REMARK_OLD = "新增"
		group by s.id
	</select>

	<!-- 社保士兵医生大审核结果【新增】查询的模板-->
	<select id="getSocialSoldierYsdAddAuditVoListByGroupBy" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierYsdAuditVo">
		SELECT
			a.SOCIAL_HOUSEHOLD_NAME socialHouseholdName,
			if(a.TYPE='0','职工新参保登记','参保人员减员申报') type,
			DATE_FORMAT(min(a.AUDIT_TIME),'%Y%m%d') startDate,
			DATE_FORMAT(now(),'%Y%m%d') endDate,
			'' backInfo,'' backInfoOne,'' backInfoTwo
		FROM t_dispatch_info a
		left join t_social_info s on a.SOCIAL_ID = s.id
		where a.DELETE_FLAG = '0' AND a.social_id is not null  AND a.STATUS = "2" AND s.YSD_HANDLE_STATUS = '7'
		  and a.AUTO_FLAG = '0' and DATE_FORMAT(a.AUDIT_TIME,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
		and s.YSD_REMARK_OLD = "新增"
		group by a.SOCIAL_HOUSEHOLD_NAME,a.TYPE
	</select>

	<!-- 工资申报 -->
	<select id="getSoldierSalaryByShenBaoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierSalaryShenBaoVo">
		select
			'' companyNo,s.SOCIAL_HOUSEHOLD_NAME companyName,s.EMP_NAME empName,'201 - 居民身份证' empIdCardType
			 ,s.EMP_IDCARD empIdCard,'' fenZu,'' oldSalary,s.RECORD_BASE newSalary,s.UNIT_PENSION_CARDINAL yangLao
			 ,s.UNIT_UNEMPLOYMENT_CARDINAL shiYe,s.UNIT_MEDICAL_CARDINAL yiLiao,s.UNIT_BIGAILMENT_CARDINAL daBing
			 ,s.UNIT_WORK_INJURY_CARDINAL gongShang,'按人申报' shenBaoType,'1' returnInfo
		from t_social_info s
				 left join t_dispatch_info d on s.id=d.SOCIAL_ID
				 LEFT JOIN sys_house_hold_info h on h.id=s.SOCIAL_HOUSEHOLD
		where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
		  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m') <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
		  and h.DEL_FLAG='0' and h.TYPE = '0' and (h.AUTO_STATUS = '0' or h.AUTO_STATUS_YSD = '0')
		GROUP BY s.EMP_IDCARD
	</select>
	<!-- 工资调整 -->
	<select id="getSoldierSalaryByTiaoZhengList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierSalaryTiaoZhengVo">
		select
			'' companyNo,s.SOCIAL_HOUSEHOLD_NAME companyName,'' shengXiaoYear,s.EMP_NAME empName,'201 - 居民身份证' empIdCardType
			 ,s.EMP_IDCARD empIdCard,'' fenZu,'' oldSalary,s.RECORD_BASE newSalary,s.UNIT_PENSION_CARDINAL yangLao
			 ,s.UNIT_UNEMPLOYMENT_CARDINAL shiYe,s.UNIT_MEDICAL_CARDINAL yiLiao
			 ,s.UNIT_WORK_INJURY_CARDINAL gongShang,'按人申报' shenBaoType,'1' returnInfo
		from t_social_info s
				 left join t_dispatch_info d on s.id=d.SOCIAL_ID
				 LEFT JOIN sys_house_hold_info h on h.id=s.SOCIAL_HOUSEHOLD
		where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
		  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0'
		  and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m') <![CDATA[ < ]]> DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y12')
		  and h.DEL_FLAG='0' and h.TYPE = '0' and (h.AUTO_STATUS = '0' or h.AUTO_STATUS_YSD = '0')
		GROUP BY s.EMP_IDCARD
	</select>

	<!-- 社保士兵实缴3张表查询1_合肥-社保费管理客户端-日常申报导出 -->
	<select id="getSoldierPaymentSelectOneList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierPaymentSelectOneVo">
		select
			'' companyNo ,s.NAME companyName,'' isPrint,'' createMonth,'是' isDownLoad,'否' danDuoSheet
		     ,'否' danDanSheet,'是' duoDanSheet,'' startDate,'' endDate,'' isSalary,'' returnInfo
		from sys_house_hold_info s
		where s.DEL_FLAG='0' and s.TYPE = '0' and (s.AUTO_STATUS = '0' or s.AUTO_STATUS_YSD = '0')
	</select>
	<!-- 社保士兵实缴3张表查询2_合肥-社保-人员缴费明细打印 -->
	<select id="getSoldierPaymentSelectTwoList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierPaymentSelectTwoVo">
		select
			s.NAME companyName,'' paymentType,'' payMonth,'' returnInfo ,'' returnInfoOne ,'' returnInfoTwo
		from sys_house_hold_info s
		where s.DEL_FLAG='0' and s.TYPE = '0' and (s.AUTO_STATUS = '0' or s.AUTO_STATUS_YSD = '0')
	</select>
	<!-- 社保士兵实缴3张表查询3_合肥-医保-单位缴费明细查询 -->
	<select id="getSoldierPaymentSelectThreeList" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.SocialSoldierPaymentSelectThreeVo">
		select
			s.NAME companyName
			 ,'' createMonth
			 ,'' paymentType
			 ,'' returnInfo
			 ,'' returnInfoOne
			 ,'' returnInfoTwo
		from sys_house_hold_info s
		where s.DEL_FLAG='0' and s.TYPE = '0' and (s.AUTO_STATUS = '0' or s.AUTO_STATUS_YSD = '0')
	</select>


	<!-- 核验1户 -->
	<insert id="getSoldierPaymentErrorInfoOne">
		insert into t_auto_payment_error
			select concat(d.id,'_1_',#{parentId}) id,#{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该员工的姓名、社保户与派单不一致' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
			and not EXISTS (
			select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT
			and p.EMP_NAME = d.EMP_NAME
			and p.EMP_IDCARD = d.CERT_NUM
		)
		and not EXISTS (
			select 1 from t_social_info s
			left join t_dispatch_info d on s.id=d.SOCIAL_ID
			where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
			and s.EMP_IDCARD = d.CERT_NUM
			and s.EMP_NAME = d.EMP_NAME
			and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
		)
		and not EXISTS (
			select 1 from t_social_info s
			left join t_dispatch_info d on s.id=d.SOCIAL_ID
			where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
			and s.EMP_IDCARD = d.CERT_NUM
			and s.EMP_NAME = d.EMP_NAME
			and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
		)
	</insert>
	<!-- 核验2险种 -->
	<insert id="getSoldierPaymentErrorInfoTwo">
		insert into t_auto_payment_error
		select concat(d.id,'_2_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
		 and d.INSURANCE_TYPE = '职工基本养老保险(单位缴纳)'
		 and not EXISTS (
			select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
												  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
												  and p.UNIT_PENSION_MONEY > 0
		)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_PERSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_PERSION_MONEY > 0
				)
		union all
		select concat(d.id,'_3_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '职工基本养老保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_PENSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_PERSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_PERSION_MONEY > 0
				)
		union all
		select concat(d.id,'_4_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '失业保险(单位缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_UNEMPLOYMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_5_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '失业保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_6_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '职工基本医疗保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_MEDICAL_MONEY > 0
				)
		union all
		select concat(d.id,'_7_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '职工基本医疗保险(单位缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_MEDICAL_MONEY > 0
				)
		union all
		select concat(d.id,'_8_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '工伤保险'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_INJURY_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_INJURY_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_INJURY_MONEY > 0
				)
		union all
		select concat(d.id,'_9_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	 and d.INSURANCE_TYPE = '单位大病救助金'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_BIGMAILMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIGAILMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIGAILMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_10_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	  and d.INSURANCE_TYPE = '个人大病救助金'
																																																	  and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_BIGMAILMENT_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_BIGAILMENT_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_BIGAILMENT_MONEY > 0
				)

		union all
		select concat(d.id,'_11_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')
																																																	  and d.INSURANCE_TYPE = '单位生育'
																																																	  and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_BIRTH_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIRTH_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIRTH_MONEY > 0
				)


	</insert>

	<sql id="get_t_payment_info_" >
		<if test="paymentTableName == 2024">
			t_payment_info_2024
		</if>
		<if test="paymentTableName == 2025">
			t_payment_info_2025
		</if>
		<if test="paymentTableName == 2026">
			t_payment_info_2026
		</if>
		<if test="paymentTableName == 2027">
			t_payment_info_2027
		</if>
		<if test="paymentTableName == 2028">
			t_payment_info_2028
		</if>
		<if test="paymentTableName == 2029">
			t_payment_info_2029
		</if>
		<if test="paymentTableName == 2030">
			t_payment_info_2030
		</if>
		<if test="paymentTableName == 2031">
			t_payment_info_2031
		</if>
		<if test="paymentTableName == 2032">
			t_payment_info_2032
		</if>
		<if test="paymentTableName == 2033">
			t_payment_info_2033
		</if>
		<if test="paymentTableName == 2034">
			t_payment_info_2034
		</if>
		<if test="paymentTableName == 2035">
			t_payment_info_2035
		</if>
	</sql>

	<!-- 复核-核验1户 -->
	<insert id="getSoldierPaymentErrorInfoOneByRe">
		insert into t_auto_payment_error
			select concat(d.id,'_1_',#{parentId}) id,#{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该员工的姓名、社保户与派单不一致' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m') and d.REPEAT_HANDLE_FLAG = '0'
									   and not EXISTS (
			select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT
			and p.EMP_NAME = d.EMP_NAME
			and p.EMP_IDCARD = d.CERT_NUM
		)
		and not EXISTS (
			select 1 from t_social_info s
			left join t_dispatch_info d on s.id=d.SOCIAL_ID
			where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
			and s.EMP_IDCARD = d.CERT_NUM
			and s.EMP_NAME = d.EMP_NAME
			and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
		)
		and not EXISTS (
			select 1 from t_social_info s
			left join t_dispatch_info d on s.id=d.SOCIAL_ID
			where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
			and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
			and s.EMP_IDCARD = d.CERT_NUM
			and s.EMP_NAME = d.EMP_NAME
			and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
		)
	</insert>
	<!-- 复核-核验2险种 -->
	<insert id="getSoldierPaymentErrorInfoTwoByRe">
		insert into t_auto_payment_error
		select concat(d.id,'_2_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '职工基本养老保险(单位缴纳)'
		 and not EXISTS (
			select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
												  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
												  and p.UNIT_PENSION_MONEY > 0
		)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_PERSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_PERSION_MONEY > 0
				)
		union all
		select concat(d.id,'_3_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '职工基本养老保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_PENSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_PERSION_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_PERSION_MONEY > 0
				)
		union all
		select concat(d.id,'_4_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '失业保险(单位缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_UNEMPLOYMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_5_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '失业保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_UNEMPLOYMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_6_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '职工基本医疗保险(个人缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_MEDICAL_MONEY > 0
				)
		union all
		select concat(d.id,'_7_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '职工基本医疗保险(单位缴纳)'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_MEDICAL_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_MEDICAL_MONEY > 0
				)
		union all
		select concat(d.id,'_8_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '工伤保险'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_INJURY_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_INJURY_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_INJURY_MONEY > 0
				)
		union all
		select concat(d.id,'_9_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '单位大病救助金'
																																																	 and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_BIGMAILMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIGAILMENT_MONEY > 0
				)
																																																	 and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIGAILMENT_MONEY > 0
				)
		union all
		select concat(d.id,'_10_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '个人大病救助金'
																																																	  and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.PERSONAL_BIGMAILMENT_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_BIGAILMENT_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.PERSONAL_BIGAILMENT_MONEY > 0
				)

		union all
		select concat(d.id,'_11_', #{parentId}) id, #{parentId} PARENT_ID,d.CERT_NUM,d.EMP_NAME,d.SOCIAL_SECURITY_ACCOUNT,d.INSURANCE_TYPE,'该险种无此派单或该险种已减员' ERROR_INFO
		from t_auto_payment_detail d where d.CREATE_MONTH = DATE_FORMAT(now(),'%Y%m')  and d.REPEAT_HANDLE_FLAG = '0'
									   and d.INSURANCE_TYPE = '单位生育'
																																																	  and not EXISTS (
					select 1 from <include refid="get_t_payment_info_"/> p where p.SOCIAL_CREATE_MONTH = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
														  and p.SOCIAL_HOUSEHOLD = d.SOCIAL_SECURITY_ACCOUNT and p.EMP_NAME = d.EMP_NAME and p.EMP_IDCARD = d.CERT_NUM
														  and p.UNIT_BIRTH_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS in ('1','5','6','7') and d.type = '0' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIRTH_MONEY > 0
				)
																																																	  and not EXISTS (
					select 1 from t_social_info s left join t_dispatch_info d on s.id=d.SOCIAL_ID
					where DATE_FORMAT(d.CREATE_TIME,'%Y%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y%m')
					  and s.HANDLE_STATUS = '3' and d.type = '1' and DATE_FORMAT(s.SOCIAL_START_DATE,'%Y%m')  <![CDATA[ < ]]> DATE_FORMAT(now(),'%Y%m')
					  and s.EMP_IDCARD = d.CERT_NUM and s.EMP_NAME = d.EMP_NAME and s.SOCIAL_HOUSEHOLD_NAME = d.SOCIAL_SECURITY_ACCOUNT
					  and s.UNIT_BIRTH_MONEY > 0
				)


	</insert>

</mapper>
