李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?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.chinaztt.mes.production.mapper.DutyRecordMapper">
 
    <resultMap id="dtoResultMap" type="com.chinaztt.mes.production.dto.DutyRecordDTO">
        <id property="id" column="id"/>
        <result property="dutyNo" column="duty_no"/>
        <result property="dutyDate" column="duty_date"/>
        <result property="dutyMonth" column="duty_month"/>
        <result property="nowDutyDate" column="now_duty_date"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="dutyTime" column="duty_time"/>
        <result property="shiftId" column="shift_id"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="dutyOutput" column="duty_output"/>
        <result property="isSubmit" column="is_submit"/>
        <result property="isConfirm" column="is_confirm"/>
        <result property="isNight" column="is_night"/>
        <result property="receiveRemark" column="receive_remark"/>
        <result property="deliveryRemark" column="delivery_remark"/>
        <result property="createUser" column="create_user"/>
        <result property="createTime" column="create_time"/>
        <result property="crewId" column="crew_id"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="crewName" column="crew_name"/>
        <result property="shiftName" column="shift_name"/>
        <result property="pending" column="pending"/>
        <result property="staffName" column="staff_name"/>
        <result property="deptName" column="dept_name"/>
        <result property="operationType" column="operation_type"/>
        <result property="operator" column="operator"/>
        <result property="operatorName" column="operator_name"/>
        <result property="operatingTime" column="operating_time"/>
        <result property="handymanNo" column="handyman_no"/>
        <result property="handymanName" column="handyman_name"/>
        <result property="conversionCoefficient" column="conversion_coefficient"/>
        <result property="standardHourWage" column="standard_hour_wage"/>
        <result property="discountFactor" column="discount_factor"/>
        <result property="workingHours" column="working_hours"/>
        <result property="personNumber" column="person_number"/>
        <result property="personOutput" column="person_output"/>
        <result property="laborCost" column="labor_cost"/>
        <result property="remark" column="remark"/>
        <result property="workCenter" column="work_center"/>
        <result property="isAudit" column="is_audit"/>
        <result property="workstationNo" column="workstation_no"/>
        <result property="workstationType" column="workstation_type"/>
    </resultMap>
    <update id="refreshPendingById">
        update production_duty_record pdr set pending=(select count(pai."id")-count(pc."id") from production_artificial_information pai left join
        production_computation pc
        on pc.artificial_information_id=pai."id" and pc.active=true where pai.duty_record_id=pdr."id")
        where pdr."id"=#{dutyRecordId}
    </update>
    <update id="refreshDutyOutputById">
        update production_duty_record pdr set duty_output=(select coalesce(sum(ppo.product_qty),0) from production_product_output ppo
        where exists(select 1 from production_product_output_staff ppos where ppos.duty_record_id=pdr."id" and
        ppo."id"=ppos.product_out_id))
        where pdr."id"=#{dutyRecordId}
    </update>
    <select id="exportList" resultType="com.chinaztt.mes.production.excel.DutyRecordData">
        select * from (
        select pdr.*,bc.crew_name,bs."name" shift_name,bw."name" workstation_name,
        pht.handyman_no,pht.handyman_name,pht.conversion_coefficient,pht.standard_hour_wage,pht.discount_factor,
        bst.staff_name,pai.person_number,pai.working_hours,pai.remark,pc.labor_cost,pai.person_output
        from production_duty_record pdr
        left join basic_crew bc on bc."id"=pdr.crew_id
        left join basic_shift bs on bs."id"=pdr.shift_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        left join production_artificial_information pai on pai.duty_record_id=pdr."id"
        left join production_computation pc on pc.artificial_information_id=pai."id" and pc.active=true
        left join production_handyman_type pht on pht."id"=pai.handyman_type_id
        left join production_person_board ppb on ppb."id"=pai.production_person_id
        left join basic_staff bst on bst."id"=ppb.staff_id
        order by now_duty_date,workstation_name,staff_name
        ) tempA
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="exportPersonBoard" resultType="com.chinaztt.mes.production.excel.PersonBoardData">
        select * from (
        select pdr.*,bc.crew_name,bsh."name" shift_name,bw."name" workstation_name,
        bs.staff_name,bs.staff_no,bd.division_name,opd.staff_id,opd.meal_subsidy,opd.night_differential,opd.overtime_pay,
        opd.duty_time person_duty_time,
        opd.total_duty_time total_person_duty_time,
        opd.salary,
        opd.total_salary
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        left join basic_division bd on bd."id"=bs.division_id
        left join production_duty_record pdr on pdr."id"=opd.duty_record_id
        left join basic_crew bc on bc."id"=pdr.crew_id
        left join basic_shift bsh on bsh."id"=pdr.shift_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        order by now_duty_date,staff_name
        ) tempA
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="getDutyRecordPage" resultMap="dtoResultMap">
        select * from(
        select
        pdr.dept_id,
        pdr.shift_id,
        pdr.crew_id,
        pdr."id",pdr.duty_no,pdr.duty_date,pdr.start_time,pdr.end_time,
        pdr.duty_time,pdr.receive_remark,pdr.delivery_remark,pdr.create_time,
        pdr.create_user,bc.crew_name,bs."name" shift_name,bw."name" workstation_name,
        pdr.workstation_id,pdr.is_submit,pdr.is_confirm,pdr.is_audit,bst.staff_name,sd."name" dept_name,
        pdr.duty_output + COALESCE(pst.segmentation_product_qty, 0) duty_output, pdr.pending
        from production_duty_record pdr
        left join sys_dept sd on sd.dept_id=pdr.dept_id
        left join sys_user su on su.username=pdr.create_user and su.dept_id = pdr.dept_id
        left join basic_staff bst on bst."id"=su.staff_id
        left join basic_crew bc on bc."id"=pdr.crew_id
        left join basic_shift bs on bs."id"=pdr.shift_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        LEFT JOIN (
        SELECT
        SUM(pstr.product_qty) segmentation_product_qty,
        pst.duty_record_id
        FROM
        production_segmentation_task pst
        LEFT JOIN production_segmentation_task_record pstr ON pst."id" = pstr.task_id
        WHERE
        pstr.status = '02submitted'
        GROUP BY
        pst.duty_record_id
        ) pst ON pst.duty_record_id = pdr."id"
        ) tempA
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="getDtoById" resultMap="dtoResultMap">
        select pdr.*,bc.crew_name from production_duty_record pdr
        left join basic_crew bc on pdr.crew_id = bc.id
        where pdr.id=#{id}
    </select>
    <select id="getDutyRecordByWorkstationId" resultMap="dtoResultMap">
        select pdr."id",pdr.duty_no,pdr.duty_date,pdr.start_time,pdr.end_time,pdr.duty_time,
        pdr.workstation_id,pdr.is_submit,pdr.is_confirm,pdr.shift_id,pdr.crew_id
        from production_duty_record pdr
        left join basic_crew bc on bc."id"=pdr.crew_id
        left join basic_shift bs on bs."id"=pdr.shift_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        where pdr."id"=(select duty_record_id from basic_workstation where id =#{workstationId})
    </select>
    <select id="getOperatingRecord" resultMap="dtoResultMap">
        select pdrb."operator",bs.staff_name operator_name,pdrb.operating_time,pdrb."type" operation_type
        from production_duty_record_back pdrb
        left join basic_staff bs on bs.staff_no=pdrb."operator"
        where pdrb.duty_record_id=#{id}
        order by pdrb."id" desc
    </select>
 
    <insert id="backDutyRecordById">
        insert into production_duty_record_back(duty_no,duty_date,start_time,end_time,duty_time,shift_id,workstation_id,receive_remark,delivery_remark,
        create_user,create_time,crew_id,duty_output,is_submit,is_confirm,now_duty_date,duty_month,operator,operating_time,duty_record_id,type,dept_id,work_center)
        select duty_no,duty_date,start_time,end_time,duty_time,shift_id,workstation_id,receive_remark,delivery_remark,create_user,create_time,crew_id,
        duty_output,is_submit,is_confirm,now_duty_date,duty_month,update_user,now(),id,#{type},dept_id,work_center from production_duty_record where id=#{id}
    </insert>
    <insert id="backDeleteDutyRecordById">
        insert into production_duty_record_back(operator,operating_time,duty_record_id,type)
        values(#{operator},now(),#{id},'删除')
    </insert>
 
    <select id="selectComingByDutyRecordId" resultType="java.lang.Long">
        select pdr."id",pdr.now_duty_date,pdr.duty_month
        from production_duty_record pdr
        where pdr.is_confirm=true and exists(select 1 from production_duty_record pdre where pdre."id"=#{dutyRecordId}
        and pdr.duty_month=pdre.duty_month and pdr.now_duty_date>pdre.now_duty_date)
        and exists(select 1 from production_computation pc where pc.duty_record_id=pdr."id" )
        order by pdr.now_duty_date
    </select>
 
    <select id="getArtificialRecord" resultMap="dtoResultMap">
        select * from (
        select pai."id",pdr.*,bc.crew_name,bs."name" shift_name,bw."name" workstation_name,
        pht.handyman_no,pht.handyman_name,pht.conversion_coefficient,pht.standard_hour_wage,pht.discount_factor,
        bst.staff_name,pai.person_number,pai.working_hours,pai.remark,pc.labor_cost,pai.person_output
        from production_duty_record pdr
        left join basic_crew bc on bc."id"=pdr.crew_id
        left join basic_shift bs on bs."id"=pdr.shift_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        left join production_artificial_information pai on pai.duty_record_id=pdr."id"
        left join production_computation pc on pc.artificial_information_id=pai."id" and pc.active=true
        left join production_handyman_type pht on pht."id"=pai.handyman_type_id
        left join production_person_board ppb on ppb."id"=pai.production_person_id
        left join basic_staff bst on bst."id"=ppb.staff_id
        ) tempA
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="exportAttendance" resultType="com.chinaztt.mes.production.excel.AttendanceData">
        select bs.staff_no,bs.staff_name,bd.division_name,tempC.*
        from(
        select staff_id,
        sum(case when shift_name='大白班' then date_count else 0 end) as "big_day_shift",
        sum(case when shift_name='大夜班' then date_count else 0 end) as "big_night_shift",
        sum(case when shift_name='小白班' then date_count else 0 end) as "small_day_shift",
        sum(case when shift_name='小夜班' then date_count else 0 end) as "small_night_shift",
        sum(case when shift_name='日班' then date_count else 0 end) as "day_shift",
        sum(case when shift_name='中班' then date_count else 0 end) as "middle_shift",
        sum(case when shift_name='夜班' then date_count else 0 end) as "night_shift",
        sum(date_count) total_day
        from(
        select staff_id,shift_name,count(now_duty_date) date_count
        from (
        select distinct *
        from (
        select bsh."name" shift_name,pdr.now_duty_date,
        opd.staff_id,bc.crew_name
        from production_person_board opd
        left join production_duty_record pdr on pdr."id"=opd.duty_record_id
        left join basic_shift bsh on bsh."id"=pdr.shift_id
        left join basic_crew bc on pdr.crew_id = bc."id"
        where opd.duty_time>0
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
        ) temp
        ) tempA
        group by staff_id,shift_name
        ) tempB
        group by staff_id
        ) tempC
        left join basic_staff bs on bs."id"=tempC.staff_id
        left join basic_division bd on bd."id"=bs.division_id
        order by bs.staff_no
    </select>
 
    <insert id="batchbackDutyRecordByIds">
        insert into production_duty_record_back(duty_no,duty_date,start_time,end_time,duty_time,shift_id,workstation_id,receive_remark,delivery_remark,
        create_user,create_time,crew_id,duty_output,is_submit,is_confirm,now_duty_date,duty_month,operator,operating_time,duty_record_id,type,dept_id,work_center)
        select duty_no,duty_date,start_time,end_time,duty_time,shift_id,workstation_id,receive_remark,delivery_remark,create_user,create_time,crew_id,
        duty_output,is_submit,is_confirm,now_duty_date,duty_month,update_user,now(),id,#{type},dept_id,work_center from production_duty_record
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </insert>
 
    <select id="exportShiftWage" resultType="com.chinaztt.mes.production.excel.ShiftWageData">
        SELECT * FROM(
        SELECT psw.*,
        pdr.now_duty_date,bc.crew_name,
        bs.staff_no,bs.staff_name,bs.personnel_factor,
        bw."name" workstationName,
        ppos.person_output,
        pdr.duty_no,pdr.is_confirm,pdr.is_submit,pdr.duty_date,pdr.duty_time
        FROM
        production_shift_wage psw
        INNER JOIN
        production_duty_record pdr
        ON psw.duty_record_id = pdr."id"
        LEFT JOIN basic_staff bs ON psw.staff_id = bs."id"
        LEFT JOIN basic_workstation bw ON pdr.workstation_id = bw."id"
        LEFT JOIN basic_crew bc ON pdr.crew_id = bc."id"
        LEFT JOIN
        (SELECT staff_id,duty_record_id,SUM(COALESCE(quantity,0)) person_output FROM production_product_output_staff GROUP BY staff_id,duty_record_id) ppos
        ON psw.staff_id = ppos.staff_id AND psw.duty_record_id = ppos.duty_record_id)TMP
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
 
    <select id="selectUnsubmitRecord" resultMap="dtoResultMap">
        select pdr.*,bw.name as workstation_name from production_duty_record pdr
        left join basic_workstation bw on pdr.workstation_id = bw.id
        where pdr.is_submit = 'false'
        order by pdr.workstation_id,pdr.id
        limit 100 offset #{startIndex}
    </select>
 
 
    <select id="selectUnsubmitWorkstation" resultMap="dtoResultMap">
        select pdr.id,pdr.duty_no,bs.name as shift_name, bc.crew_name ,pdr.start_time,pdr.end_time,
         bw.name as workstation_name, bw.workstation_no, bw.type as workstation_type, bw.remark from production_duty_record pdr
        left join basic_workstation bw on pdr.workstation_id = bw.id
        left join basic_shift bs on bs.id = pdr.shift_id
        left join basic_crew bc on bc.id = pdr.crew_id
        where pdr.is_submit = 'false' and pdr.work_center = #{workCenter}
        order by pdr.workstation_id,pdr.id
    </select>
</mapper>