zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
58
59
60
61
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?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.changhong.epc.form.mapper.tenant.apply.ApplyMergeMapper">
 
    <sql id="selectApplySql">
        select
            main.DATAROWNUM
            , main.number_apply <!-- 申请编号 -->
            , main.applicationCurrencyAmount <!-- 申请金额 -->
            , main.exchangeRate <!-- 汇率 -->
            , main.applicationCurrency <!-- 申请币种 -->
            , main.reimburseMan <!-- 申请人 -->
            , main.budgetStartDate <!-- 申请日期 -->
            , main.apply_department <!-- 申请部门 -->
            , main.loanAmount <!-- 借款金额 -->
            , sum(journey.daysOfTravel) sumDays <!-- 出差天数 -->
            , GROUP_CONCAT(journey.countries) countries <!-- 出差国家 -->
            , GROUP_CONCAT(journey.placeOfTravel) placeOfTravel <!-- 出差地点 -->
            , GROUP_CONCAT(DATE_FORMAT(journey.ToDate, '%Y-%m-%d')) ToDate <!-- 出差时间 -->
            , main.solidification
        from formdata_{tenantId}_${formId} main
        left join formdata_{tenantId}_${formId}_journey journey on main.DATAROWNUM = journey.PARENTDATAROWNUM
        where main.DELETEFLG = 0
        and main.loanAmount > 0
        and main.processState = 20
    </sql>
 
    <select id="selectApplyInfo" resultType="java.util.Map">
      <include refid="selectApplySql"/>
        and main.DATAROWNUM = #{dataRowNum}
        GROUP BY main.DATAROWNUM
    </select>
 
    <select id="selectApplyMergeList" parameterType="java.util.Map" resultType="java.util.Map">
        select * from (
          <include refid="selectApplySql"/>
          and main.apply_department = #{info.apply_department}
          and main.applicationCurrency = #{info.applicationCurrency}
          and main.DATAROWNUM != #{info.DATAROWNUM}
          GROUP BY main.DATAROWNUM
        ) m
        left join apply_merge_{rule} am on m.dataRowNum = am.apply_id and am.data_start = 0
        where m.placeOfTravel = #{info.placeOfTravel}
        and m.ToDate = #{info.ToDate}
        and am.apply_id is null
    </select>
 
    <resultMap id="selectApplyMergeListByIdsResultMap" type="java.util.Map">
        <id column="DATAROWNUM" property="DATAROWNUM"/>
        <result column="number_apply" property="number_apply"/>
        <result column="applicationCurrencyAmount" property="applicationCurrencyAmount"/>
        <result column="exchangeRate" property="exchangeRate"/>
        <result column="applicationCurrency" property="applicationCurrency"/>
        <result column="reimburseMan" property="reimburseMan"/>
        <result column="budgetStartDate" property="budgetStartDate"/>
        <result column="apply_department" property="apply_department"/>
        <result column="loanAmount" property="loanAmount"/>
        <result column="sumDays" property="sumDays"/>
        <result column="placeOfTravel" property="placeOfTravel"/>
        <result column="countries" property="countries"/>
        <result column="ToDate" property="ToDate"/>
        <result column="solidification" property="solidification"/>
    </resultMap>
 
    <select id="selectApplyMergeListByIds" resultMap="selectApplyMergeListByIdsResultMap">
        <include refid="selectApplySql"/>
        <if test="ids != null and ids.size() > 0">
            <foreach collection="ids" item="id" open="and main.DATAROWNUM in (" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        GROUP BY main.DATAROWNUM
        order by main.DATAROWNUM
    </select>
 
    <select id="selectApplyMergeChildList" parameterType="java.util.Map" resultType="java.util.Map">
        select *
        from formdata_{tenantId}_${formId}_journey
        <where>
            <foreach collection="ids" item="id" open="and PARENTDATAROWNUM in (" close=")" separator=",">
                #{id}
            </foreach>
        </where>
        order by PARENTDATAROWNUM
    </select>
 
    <delete id="deleteByDataRowNum" parameterType="int" >
        update apply_merge_{rule}
        set data_start = 99
        where group_id in (
          select c.group_id from (
            select group_id from apply_merge_{rule} where apply_id = #{dataRowNum} and data_start = 0
          ) c
        )
    </delete>
 
    <select id="countOverApply" parameterType="com.changhong.epc.bean.form.apply.ApplyMergeDto" resultType="int">
        SELECT
            count(0)
        FROM
            formdata_{tenantId}_${formId}
        WHERE
            dataRowNum IN (
              SELECT apply_id
              FROM apply_merge_{rule}
              WHERE group_id IN ( SELECT group_id FROM apply_merge_{rule} WHERE apply_id = #{dataRowNum} AND data_start = 0 )
            )
            AND processState = 30
    </select>
</mapper>