根据统一社会信用代码 和年份查询收入财务信息 ,取并集, 年份可为空
parent
446d48edef
commit
0f8f0c2afe
|
@ -3,14 +3,69 @@
|
|||
<mapper namespace="org.sk.module.data.dal.mapper.finance.FinanceMapper">
|
||||
|
||||
<select id="getFinanceByCreditCodeAndYear" resultType="org.sk.module.data.dal.bo.finance.FinanceBO">
|
||||
select
|
||||
a.comName,
|
||||
a.creditCode,
|
||||
a.Income,
|
||||
(b.valueAddTax + b.corporateIncomeTax)/ 10000 'tax',
|
||||
a.nd 'year'
|
||||
select a.comName,
|
||||
a.creditCode,
|
||||
a.Income,
|
||||
(b.valueAddTax + b.corporateIncomeTax) / 10000 'tax', a.nd 'year'
|
||||
from com_operate_info_year a
|
||||
left join com_pay_taxs_all b on a.creditCode = b.creditCode and b.mouth = '12' and a.nd = b.year
|
||||
where a.creditCode = ${creditCode} and a.nd = ${year}
|
||||
left join com_pay_taxs_all b on a.creditCode = b.creditCode and b.mouth = '12' and a.nd = b.year
|
||||
where a.creditCode = #{creditCode}
|
||||
and a.nd = #{year}
|
||||
</select>
|
||||
|
||||
<select id="getIncomeAndTax" resultType="org.sk.module.data.dal.bo.finance.FinanceBO">
|
||||
WITH
|
||||
income_data AS (
|
||||
SELECT comName, creditCode, nd AS year,income FROM com_operate_info_year
|
||||
where creditCode in
|
||||
<foreach item="code" collection="creditCodes" open="(" separator="," close=")">
|
||||
#{code}
|
||||
</foreach>
|
||||
<if test="year != null and year != ''">
|
||||
AND nd = #{year}
|
||||
</if>
|
||||
),
|
||||
tax_data AS (
|
||||
SELECT entName AS comName, creditCode, `year`,
|
||||
CASE WHEN
|
||||
year < YEAR(CURDATE())
|
||||
THEN
|
||||
(SELECT (valueAddTax + corporateIncomeTax) FROM com_pay_taxs_all WHERE year = t.year AND creditCode = t.creditCode AND mouth = 12)
|
||||
ELSE
|
||||
(SELECT (valueAddTax + corporateIncomeTax) FROM com_pay_taxs_all WHERE year = t.year AND creditCode = t.creditCode ORDER BY mouth DESC LIMIT 1)
|
||||
END AS tax
|
||||
FROM com_pay_taxs_all t
|
||||
where creditCode in
|
||||
<foreach item="code" collection="creditCodes" open="(" separator="," close=")">
|
||||
#{code}
|
||||
</foreach>
|
||||
<if test="year != null and year != ''">
|
||||
AND year = #{year}
|
||||
</if>
|
||||
)
|
||||
SELECT
|
||||
COALESCE(i.creditCode, t.creditCode) AS creditCode,
|
||||
COALESCE(i.comName, t.comName) AS comName,
|
||||
COALESCE(i.year, t.year) AS year,
|
||||
i.income,
|
||||
t.tax/10000
|
||||
FROM
|
||||
income_data i
|
||||
LEFT JOIN tax_data t
|
||||
ON i.creditCode = t.creditCode AND i.year = t.year
|
||||
UNION
|
||||
SELECT
|
||||
COALESCE(t.creditCode, i.creditCode) AS creditCode,
|
||||
COALESCE(t.comName, i.comName) AS comName,
|
||||
COALESCE(t.year, i.year) AS year,
|
||||
i.income,
|
||||
t.tax/10000
|
||||
FROM
|
||||
tax_data t
|
||||
LEFT JOIN income_data i
|
||||
ON t.creditCode = i.creditCode AND t.year = i.year
|
||||
ORDER BY creditCode, year
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue