xuekang
2024-05-13 15a0280ae9e7db96fdf0744c722d214d2cb5a0e5
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
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
<?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.nuvole.four.mapper.ActivityDistributeRecordMapper" >
  <select id="selectList" parameterType="com.nuvole.four.domain.query.ActivityDistributeRecordQuery" resultType="com.nuvole.four.domain.ActivityDistributeRecord">
    select <include refid="Base_Column_List"></include>
    from activity_distribute_record
    <where>
      <if test="orgId!=null">
        and org_id =#{orgId}
      </if>
      <if test="orgName!=null and orgName!=''">
        and org_name like concat('%',#{orgName},'%')
      </if>
      <if test="totalFee!=null">
        and total_fee =#{totalFee}
      </if>
      <if test="useFee!=null">
        and use_fee =#{useFee}
      </if>
      <if test="surplusFee!=null">
        and surplus_fee =#{surplusFee}
      </if>
      <if test="lv1Id!=null">
        and lv1_id =#{lv1Id}
      </if>
      <if test="lv2Id!=null">
        and lv2_id =#{lv2Id}
      </if>
      <if test="lv3Id!=null">
        and lv3_id =#{lv3Id}
      </if>
      <if test="lv4Id!=null">
        and lv4_id =#{lv4Id}
      </if>
      <if test="status!=null">
        and status =#{status}
      </if>
      <if test="deleted!=null">
        and deleted =#{deleted}
      </if>
      <if test="createBy!=null">
        and create_by =#{createBy}
      </if>
      <if test="createTime!=null">
        and create_time =#{createTime}
      </if>
      <if test="updateBy!=null">
        and update_by =#{updateBy}
      </if>
      <if test="updateTime!=null">
        and update_time =#{updateTime}
      </if>
    </where>
  </select>
 
  <select id="getActivityDistributeRecordDetail" parameterType="java.lang.Long"
          resultType="com.nuvole.four.domain.dto.ActivityDistributeBudgetDto">
    SELECT
      adr.id,
      adr.total_fee totalFee,
      adr.surplus_fee surplusFee,
      so.id orgId,
      so.NAME orgName,
      so.org_code orgCode,
      so.pid pId,
      so.lv orgLv,
      IFNULL( adr.use_fee, 0 ) useFee,
      if( adr.id is null, 0, 1) useOrNot
    FROM
      sys_org so
        LEFT JOIN activity_distribute_record adr ON adr.org_id = so.id
        AND adr.deleted = 0 and adr.activity_id = #{activityId}
        <where>
            <if test="orgId != null">
              and so.pid = #{orgId}
            </if>
        </where>
    GROUP BY
      so.id
    ORDER BY
      sort_no
  </select>
 
 
  <select id="getActivityDistributeRecordDetailByAId" parameterType="java.lang.Long"
          resultType="com.nuvole.four.domain.dto.ActivityDistributeBudgetDto">
    SELECT
      adr.id,
      adr.total_fee totalFee,
      adr.surplus_fee surplusFee,
      so.id orgId,
      so.NAME orgName,
      so.org_code orgCode,
      so.pid pId,
      so.lv orgLv,
      IFNULL( adr.use_fee, 0 ) useFee
    FROM
      sys_org so
        JOIN activity_distribute_record adr ON adr.org_id = so.id
        AND adr.deleted = 0 and adr.activity_id = #{activityId}
        <where>
            AND adr.deleted = 0
          <if test="activityId != null">
            and adr.activity_id = #{activityId}
          </if>
          <if test="orgCode!=null and orgCode!=''">
            and adr.org_code like concat(#{orgCode}, '%')
          </if>
        </where>
      GROUP BY
        so.id
      ORDER BY
        sort_no
  </select>
 
  <select id="selectAllByActivityIds" resultType="com.nuvole.four.domain.ActivityDistributeRecord">
    select * from activity_distribute_record
    <where>
      and deleted = 0
      <if test="ids != null">
        and activity_id = in
        <foreach collection="ids" open="(" separator="," item="item" close=")">
          #{item}
        </foreach>
      </if>
    </where>
  </select>
 
 
  <insert id="batchInsertOrUpdate" parameterType="list">
    insert into activity_distribute_record
    (id,org_id,org_name,org_code,activity_id,total_fee,use_fee,surplus_fee,lv1_id,lv2_id,lv3_id,lv4_id,status,deleted,create_by,create_time,update_by,update_time)
    values
    <foreach collection="list" item="i" separator=",">
      (
      #{i.id},
      #{i.orgId},
      #{i.orgName},
      #{i.orgCode},
      #{i.activityId},
      #{i.totalFee},
      #{i.useFee},
      #{i.surplusFee},
      #{i.lv1Id},
      #{i.lv2Id},
      #{i.lv3Id},
      #{i.lv4Id},
      #{i.status},
      #{i.deleted},
      #{i.createBy},
      #{i.createTime},
      #{i.updateBy},
      #{i.updateTime}
      )
    </foreach>
    ON duplicate KEY UPDATE
      use_fee = values(use_fee),
      deleted = values(deleted),
      update_by = values(update_by),
      update_time = values(update_time)
  </insert>
</mapper>