TStatisticsCurrentReportMapper.xml 16.2 KB
Newer Older
hongguangwu's avatar
hongguangwu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?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.salary.mapper.TStatisticsCurrentReportMapper">

  <resultMap id="tStatisticsCurrentReportMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TStatisticsCurrentReport">
    <id property="id" column="id"/>
    <result property="invoiceTitle" column="INVOICE_TITLE"/>
    <result property="settleDepartId" column="SETTLE_DEPART_ID"/>
    <result property="settleDepartNo" column="SETTLE_DEPART_NO"/>
    <result property="settleDepartName" column="SETTLE_DEPART_NAME"/>
    <result property="declareMonth" column="declare_MONTH"/>
    <result property="empId" column="EMP_ID"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="costReduction" column="cost_reduction"/>
    <result property="childEduinfoMoney" column="child_eduInfo_money"/>
    <result property="housingRentalinfoMoney" column="housing_rentalInfo_money"/>
    <result property="housingLoanInterestExpenseMoney" column="housing_loan_Interest_expense_money"/>
    <result property="supportElderlyExpenseMoney" column="support_elderly_expense_money"/>
    <result property="continuingEducationExpenseMoney" column="continuing_education_expense_money"/>
    <result property="realSalary" column="REAL_SALARY"/>
    <result property="personalPensionMoney" column="PERSONAL_PENSION_MONEY"/>
    <result property="personalMedicalMoney" column="PERSONAL_MEDICAL_MONEY"/>
    <result property="personalUnemploymentMoney" column="PERSONAL_UNEMPLOYMENT_MONEY"/>
    <result property="personalSocial" column="PERSONAL_SOCIAL"/>
    <result property="personalProvidentFee" column="PERSONAL_PROVIDENT_FEE"/>
    <result property="enterpriseAnnuity" column="enterprise_annuity"/>
    <result property="taxable" column="taxable"/>
    <result property="taxFee" column="tax_fee"/>
    <result property="quickDeducation" column="QUICK_DEDUCATION"/>
    <result property="salaryTax" column="salary_tax"/>
    <result property="unitId" column="UNIT_ID"/>
    <result property="unitNo" column="UNIT_NO"/>
    <result property="unitName" column="UNIT_NAME"/>
    <result property="specialDeduMoney" column="SPECIAL_DEDU_MONEY"/>
    <result property="sumBabyMoney" column="sum_baby_money"/>
58
	<result property="sumPrivatePension" column="SUM_PRIVATE_PENSION"/>
hongguangwu's avatar
hongguangwu committed
59 60 61
	<result property="isNewEmployee" column="IS_NEW_EMPLOYEE"/>
	<result property="createMonth" column="CREATE_MONTH"/>
	<result property="empPhone" column="EMP_PHONE"/>
hongguangwu's avatar
hongguangwu committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  </resultMap>
    <sql id="Base_Column_List">
                a.id,
                a.INVOICE_TITLE,
                a.SETTLE_DEPART_ID,
                a.SETTLE_DEPART_NO,
                a.SETTLE_DEPART_NAME,
                a.declare_MONTH,
                a.EMP_ID,
                a.EMP_NAME,
                a.EMP_IDCARD,
                a.cost_reduction,
                a.child_eduInfo_money,
                a.housing_rentalInfo_money,
                a.housing_loan_Interest_expense_money,
                a.support_elderly_expense_money,
                a.continuing_education_expense_money,
                a.REAL_SALARY,
                a.PERSONAL_PENSION_MONEY,
                a.PERSONAL_MEDICAL_MONEY,
                a.PERSONAL_UNEMPLOYMENT_MONEY,
                a.PERSONAL_SOCIAL,
                a.PERSONAL_PROVIDENT_FEE,
                a.enterprise_annuity,
                a.taxable,
                a.tax_fee,
                a.QUICK_DEDUCATION,
                a.salary_tax,
                a.UNIT_ID,
                a.UNIT_NO,
                a.UNIT_NAME,
                a.SPECIAL_DEDU_MONEY,
hongguangwu's avatar
hongguangwu committed
94
                a.sum_baby_money,
95
				a.SUM_PRIVATE_PENSION,
hongguangwu's avatar
hongguangwu committed
96 97
                a.IS_NEW_EMPLOYEE,
                a.CREATE_MONTH,
98
                a.EMP_PHONE
hongguangwu's avatar
hongguangwu committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    </sql>
    <sql id="tStatisticsCurrentReport_where">
        <if test="tStatisticsCurrentReport != null">
                    <if test="tStatisticsCurrentReport.id != null and tStatisticsCurrentReport.id.trim() != ''">
                        AND a.id = #{tStatisticsCurrentReport.id}
                    </if>
                    <if test="tStatisticsCurrentReport.invoiceTitle != null and tStatisticsCurrentReport.invoiceTitle.trim() != ''">
                        AND a.INVOICE_TITLE = #{tStatisticsCurrentReport.invoiceTitle}
                    </if>
                    <if test="tStatisticsCurrentReport.settleDepartId != null and tStatisticsCurrentReport.settleDepartId.trim() != ''">
                        AND a.SETTLE_DEPART_ID = #{tStatisticsCurrentReport.settleDepartId}
                    </if>
                    <if test="tStatisticsCurrentReport.settleDepartNo != null and tStatisticsCurrentReport.settleDepartNo.trim() != ''">
                        AND a.SETTLE_DEPART_NO = #{tStatisticsCurrentReport.settleDepartNo}
                    </if>
                    <if test="tStatisticsCurrentReport.settleDepartName != null and tStatisticsCurrentReport.settleDepartName.trim() != ''">
                        AND a.SETTLE_DEPART_NAME = #{tStatisticsCurrentReport.settleDepartName}
                    </if>
                    <if test="tStatisticsCurrentReport.declareMonth != null and tStatisticsCurrentReport.declareMonth.trim() != ''">
                        AND a.declare_MONTH = #{tStatisticsCurrentReport.declareMonth}
                    </if>
                    <if test="tStatisticsCurrentReport.empId != null and tStatisticsCurrentReport.empId.trim() != ''">
                        AND a.EMP_ID = #{tStatisticsCurrentReport.empId}
                    </if>
                    <if test="tStatisticsCurrentReport.empName != null and tStatisticsCurrentReport.empName.trim() != ''">
                        AND a.EMP_NAME = #{tStatisticsCurrentReport.empName}
                    </if>
                    <if test="tStatisticsCurrentReport.empIdcard != null and tStatisticsCurrentReport.empIdcard.trim() != ''">
                        AND a.EMP_IDCARD = #{tStatisticsCurrentReport.empIdcard}
                    </if>
                    <if test="tStatisticsCurrentReport.costReduction != null">
                        AND a.cost_reduction = #{tStatisticsCurrentReport.costReduction}
                    </if>
                    <if test="tStatisticsCurrentReport.childEduinfoMoney != null">
                        AND a.child_eduInfo_money = #{tStatisticsCurrentReport.childEduinfoMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.housingRentalinfoMoney != null">
                        AND a.housing_rentalInfo_money = #{tStatisticsCurrentReport.housingRentalinfoMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.housingLoanInterestExpenseMoney != null">
                        AND a.housing_loan_Interest_expense_money = #{tStatisticsCurrentReport.housingLoanInterestExpenseMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.supportElderlyExpenseMoney != null">
                        AND a.support_elderly_expense_money = #{tStatisticsCurrentReport.supportElderlyExpenseMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.continuingEducationExpenseMoney != null">
                        AND a.continuing_education_expense_money = #{tStatisticsCurrentReport.continuingEducationExpenseMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.realSalary != null">
                        AND a.REAL_SALARY = #{tStatisticsCurrentReport.realSalary}
                    </if>
                    <if test="tStatisticsCurrentReport.personalPensionMoney != null">
                        AND a.PERSONAL_PENSION_MONEY = #{tStatisticsCurrentReport.personalPensionMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.personalMedicalMoney != null">
                        AND a.PERSONAL_MEDICAL_MONEY = #{tStatisticsCurrentReport.personalMedicalMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.personalUnemploymentMoney != null">
                        AND a.PERSONAL_UNEMPLOYMENT_MONEY = #{tStatisticsCurrentReport.personalUnemploymentMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.personalSocial != null">
                        AND a.PERSONAL_SOCIAL = #{tStatisticsCurrentReport.personalSocial}
                    </if>
                    <if test="tStatisticsCurrentReport.personalProvidentFee != null">
                        AND a.PERSONAL_PROVIDENT_FEE = #{tStatisticsCurrentReport.personalProvidentFee}
                    </if>
                    <if test="tStatisticsCurrentReport.enterpriseAnnuity != null">
                        AND a.enterprise_annuity = #{tStatisticsCurrentReport.enterpriseAnnuity}
                    </if>
                    <if test="tStatisticsCurrentReport.taxable != null">
                        AND a.taxable = #{tStatisticsCurrentReport.taxable}
                    </if>
                    <if test="tStatisticsCurrentReport.taxFee != null">
                        AND a.tax_fee = #{tStatisticsCurrentReport.taxFee}
                    </if>
                    <if test="tStatisticsCurrentReport.quickDeducation != null">
                        AND a.QUICK_DEDUCATION = #{tStatisticsCurrentReport.quickDeducation}
                    </if>
                    <if test="tStatisticsCurrentReport.salaryTax != null">
                        AND a.salary_tax = #{tStatisticsCurrentReport.salaryTax}
                    </if>
                    <if test="tStatisticsCurrentReport.unitId != null and tStatisticsCurrentReport.unitId.trim() != ''">
                        AND a.UNIT_ID = #{tStatisticsCurrentReport.unitId}
                    </if>
                    <if test="tStatisticsCurrentReport.unitNo != null and tStatisticsCurrentReport.unitNo.trim() != ''">
                        AND a.UNIT_NO = #{tStatisticsCurrentReport.unitNo}
                    </if>
                    <if test="tStatisticsCurrentReport.unitName != null and tStatisticsCurrentReport.unitName.trim() != ''">
                        AND a.UNIT_NAME = #{tStatisticsCurrentReport.unitName}
                    </if>
                    <if test="tStatisticsCurrentReport.specialDeduMoney != null">
                        AND a.SPECIAL_DEDU_MONEY = #{tStatisticsCurrentReport.specialDeduMoney}
                    </if>
                    <if test="tStatisticsCurrentReport.sumBabyMoney != null">
                        AND a.sum_baby_money = #{tStatisticsCurrentReport.sumBabyMoney}
                    </if>
hongguangwu's avatar
hongguangwu committed
195 196 197
					<if test="tStatisticsCurrentReport.sumPrivatePension != null">
						AND a.SUM_PRIVATE_PENSION = #{tStatisticsCurrentReport.sumPrivatePension}
					</if>
hongguangwu's avatar
hongguangwu committed
198 199 200 201 202 203 204 205 206 207 208
        </if>
    </sql>
    <!--tStatisticsCurrentReport简单分页查询-->
    <select id="getTStatisticsCurrentReportPage" resultMap="tStatisticsCurrentReportMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_statistics_current_report a
        <where>
            1=1
            <include refid="tStatisticsCurrentReport_where"/>
        </where>
hongguangwu's avatar
hongguangwu committed
209
		order by a.DECLARE_MONTH desc
hongguangwu's avatar
hongguangwu committed
210
    </select>
211 212 213 214 215

	<!-- 本期申报 -->
	<insert id="insertStatisticsCurrentReport">
		insert into t_statistics_current_report (
			select
hongguangwu's avatar
hongguangwu committed
216
				concat(s.id,#{declareMonth}) id,
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
				s.INVOICE_TITLE,
				s.SETTLE_DEPART_ID,
				s.SETTLE_DEPART_NO,
				s.SETTLE_DEPART_NAME,
				s.DECLARE_MONTH,
				s.EMP_ID,
				if(s.EMP_NAME REGEXP '[0-9]',REPLACE(s.EMP_NAME,right(s.EMP_NAME,4),''),s.EMP_NAME) EMP_NAME,
				s.EMP_IDCARD,
				s.cost_reduction,
				s.child_eduInfo_money,
				s.housing_rentalInfo_money,
				s.housing_loan_Interest_expense_money,
				s.support_elderly_expense_money,
				s.continuing_education_expense_money,
				s.REAL_SALARY - ifnull(m.all_income,0) REAL_SALARY,
				s.PERSONAL_PENSION_MONEY - ifnull(m.PERSONAL_PENSION_MONEY,0) PERSONAL_PENSION_MONEY,
				s.PERSONAL_MEDICAL_MONEY - ifnull(m.PERSONAL_MEDICAL_MONEY,0) PERSONAL_MEDICAL_MONEY,
				s.PERSONAL_UNEMPLOYMENT_MONEY - ifnull(m.PERSONAL_UNEMPLOYMENT_MONEY,0) PERSONAL_UNEMPLOYMENT_MONEY,
				s.PERSONAL_SOCIAL,
				s.PERSONAL_FUND - ifnull(m.PERSONAL_PROVIDENT_FEE,0) PERSONAL_PROVIDENT_FEE,
				s.enterprise_annuity - ifnull(m.enterprise_annuity,0) enterprise_annuity,
				s.taxable,
				s.tax_fee,
				s.QUICK_DEDUCATION,
				s.salary_tax - ifnull(m.all_tax_prepaid,0) - ifnull(m.all_tax_payable,0) salary_tax,
				s.UNIT_ID,
				s.UNIT_NO,
				s.UNIT_NAME,
				s.SPECIAL_DEDU_MONEY,
hongguangwu's avatar
hongguangwu committed
246
				s.sum_baby_money,
hongguangwu's avatar
hongguangwu committed
247
				s.SUM_PRIVATE_PENSION,
hongguangwu's avatar
hongguangwu committed
248
				if (#{lastMonth} = s.CREATE_MONTH,1,0) IS_NEW_EMPLOYEE,
hongguangwu's avatar
hongguangwu committed
249 250
				s.CREATE_MONTH,
				s.EMP_PHONE
251 252 253 254 255 256 257 258 259
			from t_statistics_tax_salary s
					 left join
				 (
					 select m.INVOICE_TITLE,m.EMP_IDCARD,
							sum(ifnull(m.PERSONAL_PENSION_MONEY,0)) PERSONAL_PENSION_MONEY,
							sum(ifnull(m.PERSONAL_MEDICAL_MONEY,0)) PERSONAL_MEDICAL_MONEY,
							sum(ifnull(m.PERSONAL_UNEMPLOYMENT_MONEY,0)) PERSONAL_UNEMPLOYMENT_MONEY,
							sum(ifnull(m.PERSONAL_PROVIDENT_FEE,0)) PERSONAL_PROVIDENT_FEE,
							sum(ifnull(m.enterprise_annuity,0)) enterprise_annuity,
hongguangwu's avatar
hongguangwu committed
260 261 262
							sum(if(m.declare_MONTH = #{lastTwoMonth},all_income,0)) all_income,
							sum(if(m.declare_MONTH = #{lastTwoMonth},all_tax_prepaid,0)) all_tax_prepaid,
							sum(if(m.declare_MONTH = #{lastTwoMonth},all_tax_payable,0)) all_tax_payable
263
					 from t_statistics_current_report_market m
hongguangwu's avatar
hongguangwu committed
264
					 where m.declare_MONTH <![CDATA[<=]]> #{lastTwoMonth} and m.declare_MONTH like '${lastTwoYear}%'
265 266
					 GROUP BY m.EMP_IDCARD,m.INVOICE_TITLE
				 ) m on m.EMP_IDCARD=s.EMP_IDCARD and m.INVOICE_TITLE = s.INVOICE_TITLE
hongguangwu's avatar
hongguangwu committed
267 268 269
			 left join t_statistics_declarer d on d.EMP_IDCARD=s.EMP_IDCARD and d.DECLARE_UNIT=s.INVOICE_TITLE
			                                          and d.OCCUPATION_TYPE='0' and d.DECLARE_MONTH=#{declareMonth}
			where s.DECLARE_MONTH = #{declareMonth} and (d.id is null or d.IS_DECLARE = '0')
270 271 272 273 274 275 276 277
		)
	</insert>

	<!-- 删除-按申报月份 -->
	<delete id="deleteByYearMonth">
		DELETE FROM t_statistics_current_report WHERE DECLARE_MONTH = #{yearMonth}
	</delete>

278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
	<!--导出-->
	<select id="getCurrentReportExport" resultMap="tStatisticsCurrentReportMap" parameterType="com.yifu.cloud.plus.v1.yifu.salary.vo.TStatisticsCurrentReportSearchVo">
		SELECT
			a.id,
			a.INVOICE_TITLE,
			a.SETTLE_DEPART_ID,
			a.SETTLE_DEPART_NO,
			a.SETTLE_DEPART_NAME,
			a.declare_MONTH,
			a.EMP_ID,
			a.EMP_NAME,
			a.EMP_IDCARD,
			a.cost_reduction,
			a.child_eduInfo_money,
			a.housing_rentalInfo_money,
			a.housing_loan_Interest_expense_money,
			a.support_elderly_expense_money,
			a.continuing_education_expense_money,
			a.REAL_SALARY,
			a.PERSONAL_PENSION_MONEY,
			a.PERSONAL_MEDICAL_MONEY,
			a.PERSONAL_UNEMPLOYMENT_MONEY,
			a.PERSONAL_SOCIAL,
			a.PERSONAL_PROVIDENT_FEE,
			a.enterprise_annuity,
			a.taxable,
			a.tax_fee,
			a.QUICK_DEDUCATION,
			a.salary_tax,
			a.UNIT_ID,
			a.UNIT_NO,
			a.UNIT_NAME,
			a.SPECIAL_DEDU_MONEY,
			a.sum_baby_money,
			a.SUM_PRIVATE_PENSION,
			if(a.IS_NEW_EMPLOYEE ='0','否','是') IS_NEW_EMPLOYEE,
			a.CREATE_MONTH,
			a.EMP_PHONE
		FROM t_statistics_current_report a
		<where>
			1=1
			<include refid="tStatisticsCurrentReport_where"/>
		</where>
		order by a.DECLARE_MONTH desc
322 323 324
		<if test="tStatisticsCurrentReport != null">
			<if test="tStatisticsCurrentReport.limitStart != null">
				limit #{tStatisticsCurrentReport.limitStart},#{tStatisticsCurrentReport.limitEnd}
325 326 327 328
			</if>
		</if>
	</select>

hongguangwu's avatar
hongguangwu committed
329
</mapper>