heheng
2025-03-27 5d2cfd4562f74496a5263db3451c1e78ff53aead
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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?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.gkhy.assess.system.mapper.AssProjectMapper">
 
    <resultMap type="com.gkhy.assess.system.domain.AssProject" id="projectResult">
        <id     property="id"        column="id"         />
        <result property="name"     column="name"      />
        <result property="code"     column="code"      />
        <result property="client"     column="client"      />
        <result property="province"     column="province"      />
        <result property="city"     column="city"      />
        <result property="district"     column="district"      />
        <result property="business"     column="business"      />
        <result property="invest"     column="invest"      />
        <result property="address"     column="address"      />
        <result property="actualLocation"     column="actual_location"      />
        <result property="location"     column="location"      />
        <result property="materialCnt"     column="material_cnt"      />
        <result property="estimateType"     column="estimate_type"      />
        <result property="filingDate"     column="filing_date"      />
        <result property="creditCode"     column="credit_code"      />
        <result property="reportProgress"     column="report_progress"      />
        <result property="phase"     column="phase"      />
        <result property="state"     column="state"      />
        <result property="agencyId"     column="agency_id"      />
        <result property="introduction"     column="introduction"      />
        <result property="isReview"     column="is_review"      />
        <result property="delFlag"     column="del_flag"      />
        <result property="version"     column="version"      />
        <result property="createBy"     column="create_by"      />
        <result property="createTime"     column="create_time"      />
        <result property="updateBy"     column="update_by"      />
        <result property="updateTime"     column="update_time"      />
        <result property="remark"     column="remark"      />
        <result property="businessName"     column="business_name"      />
        <result property="leaderId"     column="leader_id"      />
        <result property="estimateTypeName"     column="estimate_type_name"      />
        <result property="agencyName"     column="agency_name"      />
        <association property="leader" javaType="com.gkhy.assess.system.domain.SysUser" resultMap="userResult" />
        <association property="contract" javaType="com.gkhy.assess.system.domain.AssContract" resultMap="contractResult" />
    </resultMap>
 
    <resultMap id="userResult" type="com.gkhy.assess.system.domain.SysUser">
        <id     property="id"       column="leader_id"        />
        <result property="name"     column="leader_name"      />
        <result property="phone"     column="link_phone"      />
    </resultMap>
 
    <resultMap id="contractResult" type="com.gkhy.assess.system.domain.AssContract">
        <id     property="id"       column="contract_id"        />
        <result property="contractMoney"     column="contract_money"      />
        <result property="actualContractMoney"     column="actual_contract_money"      />
    </resultMap>
 
    <sql id="selectProjectVo">
        select distinct p.id,p.name, p.code,p.client,p.province,p.city,p.district,p.business,p.invest,p.address,p.agency_id,
               p.actual_location,p.location,p.estimate_type,p.filing_date,
               p.credit_code,p.report_progress,p.phase,p.state,p.introduction,p.is_review,p.del_flag,p.create_by,p.create_time,
               p.update_by,p.update_time,p.remark,d1.label as business_name,d2.label as estimate_type_name,e.leader_id,u.name as leader_name,e.link_phone,
               c.id as contract_id,c.contract_money,c.actual_contract_money,a.name as agency_name,
               (select count(*) from ass_project_material m where m.project_id=p.id and m.file_id is not null) as material_cnt
        from ass_project p
        left join ass_estimate_task e on e.project_id=p.id
        left join sys_user u on u.id=e.leader_id
        left join sys_dict_data  d1 on d1.id=p.business
        left join sys_dict_data  d2 on d2.id=p.estimate_type
        left join ass_contract c on c.project_id=p.id
        left join sys_agency a on a.id=p.agency_id
    </sql>
 
 
    <select id="projectList"  resultMap="projectResult">
        <include refid="selectProjectVo"/>
        <if test="params.personId != null and params.personId != ''">
            left join ass_plan_person pp on pp.project_id=p.id
        </if>
        <if test="params.lostMaterial != null">
            left join ass_project_material m on m.project_id=p.id
        </if>
        <where>
            and p.del_flag = 0
            <if test="safetyCheck != null and safetyCheck == 0">
                and p.estimate_type != 33
            </if>
            <if test="safetyCheck != null and safetyCheck == 1">
                and p.estimate_type = 33
            </if>
            <if test="unFinish != null and unFinish == 1">
                and p.report_progress != 14
            </if>
            <if test="agencyName != null and agencyName != ''">
                and a.name=#{agencyName}
            </if>
            <if test="name != null and name != ''">
                AND p.name like concat('%', #{name}, '%')
            </if>
            <if test="client != null and client != ''">
                AND p.client like concat('%', #{client}, '%')
            </if>
            <if test="business != null and business != ''">
                AND p.business = #{business}
            </if>
            <if test="estimateType != null and estimateType != ''">
                AND p.estimate_type = #{estimateType}
            </if>
            <if test="province != null and province != ''">
                AND p.province = #{province}
            </if>
            <if test="city != null and city != ''">
                AND p.city = #{city}
            </if>
            <if test="district != null and district != ''">
                AND p.district = #{district}
            </if>
            <if test="agencyId!=null and agencyId!=''">
                AND p.agency_id=#{agencyId}
            </if>
            <if test="phase!=null and phase!=''">
                AND p.phase=#{phase}
            </if>
            <if test="params.startTime != null "><!-- 开始时间检索 -->
                and date_format(p.create_time,'%y%m%d') &gt;= date_format(#{params.startTime},'%y%m%d')
            </if>
            <if test="params.endTime != null "><!-- 结束时间检索 -->
                and date_format(p.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="params.personId != null and params.personId != ''">
                and pp.person_id=#{params.personId} and pp.del_flag=0
            </if>
            <if test="params.lostMaterial != null and params.lostMaterial==1">
                and (m.file_id is null)
            </if>
            <if test="params.lostMaterial != null and params.lostMaterial==0">
                and (m.file_id is not null)
            </if>
        </where>
        order by p.create_time desc
    </select>
 
    <select id="getProjectById"  resultMap="projectResult">
        <include refid="selectProjectVo"/>
        where p.id=#{projectId}
    </select>
 
    <select id="getProjectByName" resultType="com.gkhy.assess.system.domain.AssProject">
        select id,name from ass_project
        where name=#{name} and agency_id=#{agencyId} and del_flag=0
        <if test="safetyCheck != null and safetyCheck == 0">
            and estimate_type != 33
        </if>
        <if test="safetyCheck != null and safetyCheck == 1">
            and estimate_type = 33
        </if>
            limit 1
    </select>
 
    <select id="getReportProgress" resultType="java.lang.Integer">
        select report_progress from ass_project
        where id=#{projectId}
    </select>
<!--a.id as plan_person_id, sql字段无用  增加后组件分页查询数量有问题-->
    <select id="getMemberProjectByUserId" resultMap="projectResult">
        select distinct p.id,p.name,p.report_progress,p.code,p.client,p.province,p.city,p.district,p.business,p.create_time,
        e.leader_id,u.name as leader_name
        from ass_project p
        left join ass_plan_person a on a.project_id=p.id
        left join ass_estimate_task e on e.project_id=p.id
        left join sys_user u on u.id=e.leader_id
        <where>
            and a.person_id=#{personId} and p.del_flag=0 and a.del_flag=0
            <if test="finish!=null and finish==1">
            and p.report_progress=14
            </if>
            <if test="finish!=null and finish==0">
                and p.report_progress!=14
            </if>
            <if test="agencyId!=null and agencyId!=''">
                AND p.agency_id=#{agencyId}
            </if>
        </where>
        order by p.create_time desc
    </select>
 
    <select id="getLeaderProjectByUserId" resultMap="projectResult">
        select distinct p.id,p.name,p.report_progress,p.code,p.client,p.province,p.city,p.district,p.business,p.create_time,a.id as plan_person_id,
        e.leader_id,u.name as leader_name
        from ass_project p
        left join ass_plan_person a on a.project_id=p.id
        left join ass_estimate_task e on e.project_id=p.id
        left join sys_user u on u.id=e.leader_id
        where a.person_id=#{personId} and p.del_flag=0 and a.job_type=2 and a.del_flag=0
        <if test="agencyId!=null and agencyId!=''">
            and p.agency_id=#{agencyId}
        </if>
        order by p.create_time desc
    </select>
 
    <select id="getProjectCount" resultType="java.lang.Integer">
        select Ifnull(count(distinct  p.id),0) from ass_project p
        <if test="params.lostMaterial != null">
            left join ass_project_material m on m.project_id=p.id
        </if>
        <if test="agencyName != null and agencyName != ''">
            left join sys_agency a on a.id=p.agency_id
        </if>
        <where>
            and p.del_flag=0
            <if test="safetyCheck != null and safetyCheck == 0">
                and p.estimate_type != 33
            </if>
            <if test="safetyCheck != null and safetyCheck == 1">
                and p.estimate_type = 33
            </if>
            <if test="unFinish != null and unFinish == 1">
                and p.report_progress != 14
            </if>
            <if test="agencyId!=null and agencyId!=''">
                and p.agency_id=#{agencyId}
            </if>
            <if test="agencyName != null and agencyName != ''">
                and a.name=#{agencyName}
            </if>
            <if test="name != null and name != ''">
                AND p.name like concat('%', #{name}, '%')
            </if>
            <if test="client != null and client != ''">
                AND p.client like concat('%', #{client}, '%')
            </if>
            <if test="business != null and business != ''">
                AND p.business = #{business}
            </if>
            <if test="estimateType != null and estimateType != ''">
                AND p.estimate_type = #{estimateType}
            </if>
            <if test="province != null and province != ''">
                AND p.province = #{province}
            </if>
            <if test="city != null and city != ''">
                AND p.city = #{city}
            </if>
            <if test="district != null and district != ''">
                AND p.district = #{district}
            </if>
            <if test="phase!=null and phase!=''">
                AND p.phase=#{phase}
            </if>
            <if test="params.startTime != null "><!-- 开始时间检索 -->
                and date_format(p.create_time,'%y%m%d') &gt;= date_format(#{params.startTime},'%y%m%d')
            </if>
            <if test="params.endTime != null "><!-- 结束时间检索 -->
                and date_format(p.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="params.lostMaterial != null and params.lostMaterial==1">
                and (m.file_id is null)
            </if>
            <if test="params.lostMaterial != null and params.lostMaterial==0">
                and (m.file_id is not null)
            </if>
        </where>
    </select>
 
    <select id="getProjectByPersonIds" resultType="com.gkhy.assess.system.domain.vo.PersonProjectVO">
        select d.person_id,count(*) as project_count,max(d.create_time) as last_estimate_time from
        (select a.person_id,a.project_id,max(p.create_time) as create_time from ass_project p
        left join ass_plan_person a on a.project_id=p.id
        where  a.del_flag=0 and p.del_flag=0 and a.person_id in
        <foreach collection="personIds" item="personId" open="(" separator="," close=")">
            #{personId}
        </foreach>
        group by a.person_id,a.project_id) d
        group by d.person_id
    </select>
 
</mapper>