TemplateExtendsMapper.xml 5.67 KB
Newer Older
1 2 3
<?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="pwc.taxtech.atms.dao.TemplateMapper">
neo's avatar
neo committed
4

sherlock's avatar
sherlock committed
5
    <resultMap id="TemplateUniqDto" type="pwc.taxtech.atms.dpo.TemplateUniqDto">
neo's avatar
neo committed
6 7 8 9 10 11 12 13 14 15 16 17 18
        <id column="ID" jdbcType="INTEGER" property="id"/>
        <result column="CODE" jdbcType="VARCHAR" property="code"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
        <result column="ORDER_INDEX" jdbcType="INTEGER" property="orderIndex"/>
        <result column="REPORT_TYPE" jdbcType="INTEGER" property="reportType"/>
        <result column="TEMPLATE_GROUP_ID" jdbcType="VARCHAR" property="templateGroupId"/>
        <result column="TEMPLATE_GROUP_NAME" jdbcType="VARCHAR" property="templateGroupName"/>
        <result column="PARENT_ID" jdbcType="VARCHAR" property="parentId"/>
        <result column="PARENT_NAME" jdbcType="VARCHAR" property="parentName"/>
        <result column="PAY_TAX_TYPE" jdbcType="INTEGER" property="payTaxType"/>
        <result column="INDUSTRY_IDS" jdbcType="VARCHAR" property="industryIds"/>
        <result column="SERVICE_TYPE_ID" jdbcType="VARCHAR" property="serviceTypeId"/>
        <result column="IS_ACTIVE_ASSOCIATION" jdbcType="INTEGER" property="isActiveAssociation"/>
19 20 21
    </resultMap>

    <select id="getTemplateUniqDtosByTemplateAndTemplateGroup" parameterType="map" resultMap="TemplateUniqDto">
neo's avatar
neo committed
22
        SELECT
gary's avatar
gary committed
23
        P.id as ID,
24 25
        P.code as Code,
        P.name as Name,
gary's avatar
gary committed
26 27 28 29
        P.report_type as ReportType,
        Q.id AS TEMPLATE_GROUP_ID,
        Q.name AS TEMPLATE_GROUP_NAME,
        P.is_active_association as IsActiveAssociation
neo's avatar
neo committed
30
        FROM
gary's avatar
gary committed
31
        template P
neo's avatar
neo committed
32
        JOIN
gary's avatar
gary committed
33
        template_group Q
neo's avatar
neo committed
34
        ON
gary's avatar
gary committed
35
        P.template_group_id=Q.id
36 37 38
        <where>
            1=1
            <if test="serviceTypeId!=null">
gary's avatar
gary committed
39
                AND Q.service_type_id= #{serviceTypeId,jdbcType=VARCHAR}
40 41
            </if>
            <if test="payTaxType!=null">
gary's avatar
gary committed
42
                AND Q.pay_tax_type = #{payTaxType,jdbcType=INTEGER}
43 44
            </if>
            <if test="reportType!=null">
gary's avatar
gary committed
45
                AND P.report_type = #{reportType,jdbcType=INTEGER}
46 47
            </if>
            <if test="industryIds!=null">
gary's avatar
gary committed
48
                AND Q.industry_ids = #{industryID,jdbcType=VARCHAR}
49 50
            </if>
        </where>
neo's avatar
neo committed
51
        ORDER BY
gary's avatar
gary committed
52 53
        P.template_group_id,
        P.order_index
54
    </select>
neo's avatar
neo committed
55

56
    <resultMap id="TemplateAndGroupDbDto" type="pwc.taxtech.atms.dpo.TemplateAndGroupDbDto">
neo's avatar
neo committed
57 58 59
        <id column="ID" jdbcType="VARCHAR" property="templateId"/>
        <result column="TEMPLATE_GROUP_ID" jdbcType="VARCHAR" property="templateGroupId"/>
        <result column="TEMPLATE_CODE" jdbcType="VARCHAR" property="templateCode"/>
60
    </resultMap>
61
    <select id="getTemplateAndGroupById" parameterType="java.lang.String" resultMap="TemplateAndGroupDbDto">
neo's avatar
neo committed
62
        SELECT
gary's avatar
gary committed
63 64 65
        P.id AS ID,
        Q.id AS TEMPLATE_GROUP_ID,
        P.code AS TEMPLATE_CODE
neo's avatar
neo committed
66
        FROM
gary's avatar
gary committed
67
        template P
neo's avatar
neo committed
68
        JOIN
gary's avatar
gary committed
69
        template_group Q
neo's avatar
neo committed
70
        ON
gary's avatar
gary committed
71
        P.template_group_id=Q.id
neo's avatar
neo committed
72
        WHERE
gary's avatar
gary committed
73
        p.id= #{id,jdbcType=VARCHAR}
gary's avatar
gary committed
74
        LIMIT 1
75
    </select>
neo's avatar
neo committed
76

77
    <select id="getCountOfTemplateAndGroupByTemplateName" parameterType="map" resultType="java.lang.Long">
neo's avatar
neo committed
78
        SELECT
gary's avatar
gary committed
79
        COUNT (1)
neo's avatar
neo committed
80
        FROM
gary's avatar
gary committed
81
        template P
neo's avatar
neo committed
82
        JOIN
gary's avatar
gary committed
83
        template_group Q
neo's avatar
neo committed
84
        ON
gary's avatar
gary committed
85
        P.template_group_id=Q.id
86 87 88
        <where>
            1=1
            <if test="templateGroupId!=null">
gary's avatar
gary committed
89
                AND Q.id = #{templateGroupId,jdbcType=VARCHAR}
90 91
            </if>
            <if test="templateId!=null">
gary's avatar
gary committed
92
                AND P.id&lt;&gt; #{templateId,jdbcType=VARCHAR}
93 94
            </if>
            <if test="templateName!=null">
gary's avatar
gary committed
95
                AND P.name= #{templateName,jdbcType=VARCHAR}
96 97 98
            </if>
        </where>
    </select>
neo's avatar
neo committed
99

sherlock's avatar
sherlock committed
100
    <resultMap id="reportDto" type="pwc.taxtech.atms.dpo.ReportDto">
neo's avatar
neo committed
101 102 103 104 105
        <id column="ID" jdbcType="VARCHAR" property="id"/>
        <result column="PERIOD" jdbcType="INTEGER" property="period"/>
        <result column="TEMPLATE_ID" jdbcType="INTEGER" property="templateId"/>
        <result column="TEMPLATE_NAME" jdbcType="VARCHAR" property="templateName"/>
        <result column="TEMPLATE_CODE" jdbcType="VARCHAR" property="templateCode"/>
106
        <result column="REPORT_TYPE" jdbcType="INTEGER" property="reportType"/>
107 108
    </resultMap>

frank.xa.zhang's avatar
frank.xa.zhang committed
109
    <!--TODO: 考虑项目库表迁移-->
110 111
    <select id="getTemplateLeftJoinReport" parameterType="map" resultMap="reportDto">
        SELECT
gary's avatar
gary committed
112 113 114 115
        D.id AS ID,
        D.period AS PERIOD,
        C.id AS TEMPLATE_ID,
        C.name AS TEMPLATE_NAME,
116 117
        C.code AS TEMPLATE_CODE,
        C.reportType AS REPORT_TYPE
neo's avatar
neo committed
118 119 120
        FROM
        (
        SELECT
gary's avatar
gary committed
121 122
        A.id as ID,
        A.name AS NAME,
123 124
        A.code AS CODE,
        A.report_type AS reportType
neo's avatar
neo committed
125
        FROM
gary's avatar
gary committed
126
        template A
neo's avatar
neo committed
127
        WHERE
gary's avatar
gary committed
128 129
        A.template_group_id = #{templateGroupID,jdbcType=VARCHAR}
        AND A.is_active_association = 1
neo's avatar
neo committed
130
        ORDER BY
gary's avatar
gary committed
131
        A.order_index
neo's avatar
neo committed
132 133 134 135 136
        )
        C
        LEFT JOIN
        (
        SELECT
gary's avatar
gary committed
137 138 139
        B.id as ID,
        B.period AS PERIOD,
        B.template_id AS TEMPLATE_ID
neo's avatar
neo committed
140
        FROM
141
        period_report B
neo's avatar
neo committed
142
        WHERE
143
        B.period = #{period,jdbcType=INTEGER}
gary's avatar
gary committed
144
        AND B.project_id = #{projectId,jdbcType=VARCHAR}
neo's avatar
neo committed
145 146 147
        )
        D
        ON
gary's avatar
gary committed
148
        C.id = D.template_id
149 150
    </select>

frank.xa.zhang's avatar
frank.xa.zhang committed
151
    <select id="getIdsForExceptTemplate" resultType="java.lang.Long">
152
        SELECT
gary's avatar
gary committed
153
        A.id
154
        FROM
gary's avatar
gary committed
155
        template A
neo's avatar
neo committed
156
        JOIN
gary's avatar
gary committed
157
        template_group B
neo's avatar
neo committed
158
        ON
gary's avatar
gary committed
159
        A.template_group_id = B.id
160
        WHERE
gary's avatar
gary committed
161 162
        B.group_type = 2
        AND B.service_type_id = 2
163
    </select>
neo's avatar
neo committed
164

165
</mapper>