KqglAssoMonthPunchSummaryMapper.xml 33.5 KB
Newer Older
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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
<?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="cn.timer.api.dao.kqmk.KqglAssoMonthPunchSummaryMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.kqmk.KqglAssoMonthPunchSummary" >
                <id column="id" property="id" />
                <result column="name" property="name" />
                <result column="num" property="num" />
                <result column="dept" property="dept" />
                <result column="post" property="post" />
                <result column="att_group" property="attGroup" />
                <result column="shift" property="shift" />
                <result column="days_on_duty" property="daysOnDuty" />
                <result column="actual_att_days" property="actualAttDays" />
                <result column="days_off" property="daysOff" />
                <result column="working_hours" property="workingHours" />
                <result column="late_times" property="lateTimes" />
                <result column="late_hours" property="lateHours" />
                <result column="serious_late_times" property="seriousLateTimes" />
                <result column="serious_late_hours" property="seriousLateHours" />
                <result column="absen_late_times" property="absenLateTimes" />
                <result column="early_leave_times" property="earlyLeaveTimes" />
                <result column="length_early_leave" property="lengthEarlyLeave" />
                <result column="number_work_card_shortage" property="numberWorkCardShortage" />
                <result column="number_duty_card_shortage" property="numberDutyCardShortage" />
                <result column="absenteeism_days" property="absenteeismDays" />
                <result column="length_business_trip" property="lengthBusinessTrip" />
                <result column="time_out" property="timeOut" />
                <result column="total_overtime_hours" property="totalOvertimeHours" />
                <result column="working_turn_compen_leave" property="workingTurnCompenLeave" />
                <result column="rest_turn_compen_leave" property="restTurnCompenLeave" />
                <result column="holiday_turn_compen_leave" property="holidayTurnCompenLeave" />
                <result column="working_transfer_overtime" property="workingTransferOvertime" />
                <result column="rest_transfer_overtime" property="restTransferOvertime" />
                <result column="holiday_transfer_overtime" property="holidayTransferOvertime" />
                <result column="day1" property="day1" />
                <result column="day2" property="day2" />
                <result column="day3" property="day3" />
                <result column="day4" property="day4" />
                <result column="day5" property="day5" />
                <result column="day6" property="day6" />
                <result column="day7" property="day7" />
                <result column="day8" property="day8" />
                <result column="day9" property="day9" />
                <result column="day10" property="day10" />
                <result column="day11" property="day11" />
                <result column="day12" property="day12" />
                <result column="day13" property="day13" />
                <result column="day14" property="day14" />
                <result column="day15" property="day15" />
                <result column="day16" property="day16" />
                <result column="day17" property="day17" />
                <result column="day18" property="day18" />
                <result column="day19" property="day19" />
                <result column="day20" property="day20" />
                <result column="day21" property="day21" />
                <result column="day22" property="day22" />
                <result column="day23" property="day23" />
                <result column="day24" property="day24" />
                <result column="day25" property="day25" />
                <result column="day26" property="day26" />
                <result column="day27" property="day27" />
                <result column="day28" property="day28" />
                <result column="day29" property="day29" />
                <result column="day30" property="day30" />
                <result column="day31" property="day31" />
                <result column="belong_year" property="belongYear" />
                <result column="belong_month" property="belongMonth" />
                <result column="org_code" property="orgCode" />
                <result column="last_modified" property="lastModified" />
    </resultMap>
    
    <resultMap id="SummarydataMap" type="cn.timer.api.dto.kqmk.KqglAssoMonthPunchSummaryDto" >
                <id column="id" property="id" />
                <result column="name" property="name" />
                <result column="num" property="num" />
                <result column="dept" property="dept" />
                <result column="post" property="post" />
                <result column="att_group" property="attGroup" />
                <result column="attname" property="attname" />
                <result column="shift" property="shift" />
                <result column="days_on_duty" property="daysOnDuty" />
                <result column="actual_att_days" property="actualAttDays" />
                <result column="days_off" property="daysOff" />
                <result column="working_hours" property="workingHours" />
                <result column="late_times" property="lateTimes" />
                <result column="late_hours" property="lateHours" />
                <result column="serious_late_times" property="seriousLateTimes" />
                <result column="serious_late_hours" property="seriousLateHours" />
                <result column="absen_late_times" property="absenLateTimes" />
                <result column="early_leave_times" property="earlyLeaveTimes" />
                <result column="length_early_leave" property="lengthEarlyLeave" />
                <result column="number_work_card_shortage" property="numberWorkCardShortage" />
                <result column="number_duty_card_shortage" property="numberDutyCardShortage" />
                <result column="absenteeism_days" property="absenteeismDays" />
                <result column="length_business_trip" property="lengthBusinessTrip" />
                <result column="time_out" property="timeOut" />
                <result column="total_overtime_hours" property="totalOvertimeHours" />
                <result column="working_turn_compen_leave" property="workingTurnCompenLeave" />
                <result column="rest_turn_compen_leave" property="restTurnCompenLeave" />
                <result column="holiday_turn_compen_leave" property="holidayTurnCompenLeave" />
                <result column="working_transfer_overtime" property="workingTransferOvertime" />
                <result column="rest_transfer_overtime" property="restTransferOvertime" />
                <result column="holiday_transfer_overtime" property="holidayTransferOvertime" />
                <result column="day1" property="day1" />
                <result column="day2" property="day2" />
                <result column="day3" property="day3" />
                <result column="day4" property="day4" />
                <result column="day5" property="day5" />
                <result column="day6" property="day6" />
                <result column="day7" property="day7" />
                <result column="day8" property="day8" />
                <result column="day9" property="day9" />
                <result column="day10" property="day10" />
                <result column="day11" property="day11" />
                <result column="day12" property="day12" />
                <result column="day13" property="day13" />
                <result column="day14" property="day14" />
                <result column="day15" property="day15" />
                <result column="day16" property="day16" />
                <result column="day17" property="day17" />
                <result column="day18" property="day18" />
                <result column="day19" property="day19" />
                <result column="day20" property="day20" />
                <result column="day21" property="day21" />
                <result column="day22" property="day22" />
                <result column="day23" property="day23" />
                <result column="day24" property="day24" />
                <result column="day25" property="day25" />
                <result column="day26" property="day26" />
                <result column="day27" property="day27" />
                <result column="day28" property="day28" />
                <result column="day29" property="day29" />
                <result column="day30" property="day30" />
                <result column="day31" property="day31" />
                <result column="belong_year" property="belongYear" />
                <result column="belong_month" property="belongMonth" />
                <result column="org_code" property="orgCode" />
                <result column="last_modified" property="lastModified" />

				<result column="turnover_status" property="turnover_status" />
				<result column="custom_num" property="customNum" />
                
                <collection property="balanceTo" ofType="cn.timer.api.dto.kqmk.BalanceSheetDataDto">
                	<id column="yzid" property="yzid"/>
			   		<result column="leaverulesid" property="leaverulesid"/>
			   		<result column="balancedays" property="balancedays"/>
			    </collection>
    </resultMap>
    
    <resultMap id="DailyDetailsMap" type="cn.timer.api.dto.kqmk.DailyDetailsDto" >
                <result column="name" property="name" />
				<result column="num" property="num" />
				<result column="custom_num" property="customNum" />
                <result column="dept" property="dept" />
                <result column="post" property="post" />
                <result column="orgcode" property="orgcode" />
                
                <result column="address" property="address" />
                <result column="remarks" property="remarks" />
                <result column="cardtype" property="cardtype" />
                <result column="macaddress" property="macaddress" />
                <result column="macname" property="macname" />
                
                 <result column="bcszid" property="bcszid" />
                 <result column="bcname" property="bcname" />
                 <result column="bcsbdk1" property="bcsbdk1" />
                 <result column="bcxbdk1" property="bcxbdk1" />
                 <result column="bcsbdk2" property="bcsbdk2" />
                 <result column="bcxbdk2" property="bcxbdk2" />
                 <result column="bcsbdk3" property="bcsbdk3" />
                 <result column="bcxbdk3" property="bcxbdk3" />
                 <result column="isxbdk" property="isxbdk" />
                 
                 <result column="dkst1" property="dkst1" />
                 <result column="dkst2" property="dkst2" />
                 <result column="dkst3" property="dkst3" />
                 
                 <result column="dktj1" property="dktj1" />
                 <result column="dktj2" property="dktj2" />
                 <result column="dktj3" property="dktj3" />
                 <result column="dktj4" property="dktj4" />
                 <result column="dktj5" property="dktj5" />
                 <result column="dktj6" property="dktj6" />
                
                <result column="attname" property="attname" />
                <result column="attpbfs" property="attpbfs" />
                <result column="attdate" property="attdate" />
                <result column="userid" property="userid" />
                <result column="data" property="data" />
                <result column="sbdk1" property="sbdk1" />
                <result column="sbdk1jg" property="sbdk1jg" />
                <result column="xbdk1" property="xbdk1" />
                <result column="xbdk1jg" property="xbdk1jg" />
                <result column="sbdk2" property="sbdk2" />
                <result column="sbdk2jg" property="sbdk2jg" />
                <result column="xbdk2" property="xbdk2" />
                <result column="xbdk2jg" property="xbdk2jg" />
                <result column="sbdk3" property="sbdk3" />
                <result column="sbdk3jg" property="sbdk3jg" />
                <result column="xbdk3" property="xbdk3" />
                <result column="xbdk3jg" property="xbdk3jg" />
                
                <result column="sbcdzs" property="sbcdzs" />
                <result column="xbztzs" property="xbztzs" />
                
                <result column="ydkcs" property="ydkcs" />
                <result column="gzsc" property="gzsc" />
                <result column="qyid" property="qyid" />
                <result column="dksj" property="dksj" />
                <result column="yzcdcs" property="yzcdcs" />
                <result column="yzcdsc" property="yzcdsc" />
                <result column="kgcdfzs" property="kgcdfzs" />
                <result column="daysonduty" property="daysonduty" />
                <result column="daysoff" property="daysoff" />
				<result column="lengthbusinesstrip" property="lengthbusinesstrip" />
				<result column="timeout" property="timeout" />
				<result column="totalovertimehours" property="totalovertimehours" />
			    <result column="workingturncompenleave" property="workingturncompenleave" />
				<result column="restturncompenleave" property="restturncompenleave" />
				<result column="holidayturncompenleave" property="holidayturncompenleave" />
				<result column="workingtransferovertime" property="workingtransferovertime" />
				<result column="resttransferovertime" property="resttransferovertime" />
				<result column="holidaytransferovertime" property="holidaytransferovertime" />
			    <result column="leaverulesid" property="leaverulesid" />
			    <result column="duration" property="duration" />
			    
			    <collection property="balanceTo" ofType="cn.timer.api.dto.kqmk.BalanceSheetDataDto">
			    	<id column="yzid" property="yzid"/>
			   		<result column="leaverulesid" property="leaverulesid"/>
			   		<result column="balancedays" property="balancedays"/>
			    </collection>
    </resultMap>
    
    <resultMap id="BalanceSheetDataMap" type="cn.timer.api.dto.kqmk.BalanceSheetDataDto" >
    			<id column="yzid" property="yzid"/>
		   		<result column="leaverulesid" property="leaverulesid"/>
		   		<result column="balancedays" property="balancedays"/>
    </resultMap>
	
	
	 <select id="AttenSumDailyDetails" resultMap="BalanceSheetDataMap">
	 	select SUM(su.duration) as balancedays,su.leave_type_id as leaverulesid from kqgl_asso_relation_summary su 
			where su.org_code = #{orgcode}
			and su.approval_type = 2 
			and su.user_id = #{userid}
			and su.app_time = #{apptime}
			GROUP BY su.leave_type_id
	 </select>
	
	<select id="MonthlySummaryLeave" resultMap="BalanceSheetDataMap">
			<!-- select aa.leaverulesid,SUM(aa.balancedays) as balancedays from (
				select res.leave_type_id as leaverulesid,res.duration as balancedays from kqgl_asso_relation_summary res 
				where res.user_id = #{userid}
				and res.approval_type = 2
				and res.org_code = #{orgcode}
				and SUBSTR(res.app_time,1,7) = #{apptime}
				GROUP BY res.leave_type_id,res.duration) as aa
			GROUP BY aa.leaverulesid -->
			
			select aa.leaverulesid,SUM(aa.balancedays) as balancedays from (
				select res.leave_type_id as leaverulesid,
								res.duration as balancedays 
				 from kqgl_asso_relation_summary res
				where res.user_id = #{userid}
					and res.approval_type = 2
					and res.org_code = #{orgcode}
					and SUBSTR(res.app_time,1,7) = #{apptime}
					and res.ordernum = 1
				) as aa
				GROUP BY aa.leaverulesid
	</select>
	
	<select id="FormMonthlySummaryLeave" resultMap="BalanceSheetDataMap">
		select IFNULL(SUM(aa.balancedays),0) as balancedays  from (
				select res.leave_type_id as leaverulesid,res.duration as balancedays from kqgl_asso_relation_summary res 
				where res.user_id = #{userid}
				and res.approval_type = 2
				and res.org_code = #{orgcode}
				and SUBSTR(res.app_time,1,7) = #{apptime}
				GROUP BY res.leave_type_id,res.duration
			) as aa
	</select>
    
     <select id="AttendanceSummaryData" resultMap="SummarydataMap">
			select sum.*,
		   		(select kqz.name from kqgl_main_kqz kqz where kqz.id = sum.att_group) as attname,
	   			IFNULL((select em.job_status from yggl_main_lzb em where em.emp_num = sum.num and em.org_code = sum.org_code LIMIT 1),0) as turnover_status,
		 		yme.custom_num AS custom_num
			from kqgl_asso_month_punch_summary sum
			LEFT JOIN yggl_main_emp yme ON yme.org_code = sum.org_code and yme.emp_num=sum.num
			where sum.org_code = #{param.orgCode}
			and sum.belong_year = #{param.year}
			and sum.belong_month = #{param.month}
			<if test="param.query != null and param.query != ''">
				and (	sum.`name` like CONCAT('%',#{param.query},'%') or 
						sum.num like CONCAT('%',#{param.query},'%')
						or yme.custom_num like CONCAT('%',#{param.query},'%')
						)
			</if>
			<if test="param.attid != null and param.attid != ''">
				and sum.att_group = #{param.attid}
			</if>
			<if test="param.turnover_status == 1">
				and sum.num not in (select em.emp_num from yggl_main_lzb em where em.org_code = #{param.orgCode} and em.job_status = 3)
			</if>
			
			<!-- yz.id as yzid,
				yz.leave_rules_id as leaverulesid,
				yz.balance_days as balancedays
			LEFT JOIN kqgl_asso_leave_employee_balance as yz on yz.userid = sum.num
			ORDER BY sum.num DESC -->
     </select>

	<select id="Dailydetails" resultMap="DailyDetailsMap">
				select sum.num,
					info.custom_num,
					sum.`name`,
					sum.org_code as orgcode,
					sum.dept,sum.post,
					IFNULL((select kqz.name from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') as attname,
					IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') as attpbfs,
					IFNULL((select kqz.id from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') as attid,
					(CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END) as bcszid,
					IFNULL((select bc.name from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcname,		
					IFNULL((select bc.sbdk1 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcsbdk1,	
					IFNULL((select bc.xbdk1 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcxbdk1,	
					IFNULL((select bc.sbdk2 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcsbdk2,	
					IFNULL((select bc.xbdk2 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcxbdk2,		
					IFNULL((select bc.sbdk3 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcsbdk3,		
					IFNULL((select bc.xbdk3 from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as bcxbdk3,	
					IFNULL((select (bc.sxbcs * 2) from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					),(select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as ydkcs,
					IFNULL((select bc.is_xbdk from kqgl_asso_bcsz bc where bc.id = ((CASE WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 1 
					THEN (IFNULL((select te.bcid from kqgl_asso_teshu te where te.kqzid = sum.att_group and te.tsrq = #{param.times}
					), (select zh.bcid from kqgl_asso_zhoupaiban zh where zh.kqzid = sum.att_group
							 and zh.type = (select CASE WHEN DAYNAME(#{param.times}) = 'Monday' THEN '1' 
							 WHEN DAYNAME(#{param.times}) = 'Tuesday' THEN '2' 
							 WHEN DAYNAME(#{param.times}) = 'Wednesday' THEN '3' 
							 WHEN DAYNAME(#{param.times}) = 'Thursday' THEN '4' 
							 WHEN DAYNAME(#{param.times}) = 'Friday' THEN '5' 
							 WHEN DAYNAME(#{param.times}) = 'Saturday' THEN '6' ELSE '7' END))))
					WHEN IFNULL((select kqz.pbfs from kqgl_main_kqz kqz where kqz.id = sum.att_group),'') = 2 
					THEN (select pb.bcid from kqgl_asso_pbmx pb where pb.userid = sum.num
							and pb.`data` = #{param.times} and pb.kqzid = sum.att_group) ELSE '' END))),'') as isxbdk,
					'' address,'' remarks,'' cardtype,'' macaddress,'' macname,
					IFNULL(rtj.attdate, '') attdate,IFNULL(rtj.userid,'') userid,
					#{param.times} data,
					IFNULL(rtj.sbdk1,'') sbdk1,IFNULL(rtj.sbdk1jg,'') sbdk1jg,
					IFNULL(rtj.xbdk1 ,'') xbdk1,IFNULL(rtj.xbdk1jg,'') xbdk1jg,
					IFNULL(rtj.sbdk2 ,'') sbdk2,IFNULL(rtj.sbdk2jg ,'') sbdk2jg,
					IFNULL(rtj.xbdk2 ,'') xbdk2,IFNULL(rtj.xbdk2jg,'') xbdk2jg,
					IFNULL(rtj.sbdk3 ,'') sbdk3,IFNULL(rtj.sbdk3jg ,'') sbdk3jg,
					IFNULL(rtj.xbdk3,'') xbdk3,IFNULL(rtj.xbdk3jg ,'') xbdk3jg,
					(IFNULL(rtj.sbdk1jg,0) + IFNULL(rtj.sbdk2jg ,0) + IFNULL(rtj.sbdk3jg ,0)) as sbcdzs,
					(IFNULL(rtj.xbdk1jg,0) + IFNULL(rtj.xbdk2jg ,0) + IFNULL(rtj.xbdk3jg ,0)) as xbztzs,
					IFNULL(rtj.dktj1,'') dktj1,IFNULL(rtj.dktj2,'') dktj2,IFNULL(rtj.dktj3,'') dktj3,IFNULL(rtj.dktj4,'') dktj4,IFNULL(rtj.dktj5,'') dktj5,IFNULL(rtj.dktj6,'') dktj6,
					IFNULL(rtj.dkst1,'') dkst1,IFNULL(rtj.dkst2,'') dkst2,IFNULL(rtj.dkst3,'') dkst3,
					IFNULL(rtj.gzsc ,'') gzsc,
					IFNULL(rtj.qyid,'') qyid,
					IFNULL(rtj.dksj ,'') dksj,
					IFNULL(rtj.yzcdcs ,'') yzcdcs,
					IFNULL(rtj.yzcdsc ,'') yzcdsc,
					IFNULL(rtj.kgcdfzs,'') kgcdfzs,
					sum.days_on_duty as daysonduty,
					sum.days_off as daysoff,
					sum.length_business_trip as lengthbusinesstrip,
					sum.time_out as timeout,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 and su.overtime_type_id = 1 
						and su.app_time = #{param.times}) as totalovertimehours,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 1 or su.compensate_id = 3) and su.overtime_type_id = 1 and su.app_time = #{param.times}) as workingturncompenleave,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 1 or su.compensate_id = 3) and su.overtime_type_id = 2 and su.app_time = #{param.times}) as restturncompenleave,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 1 or su.compensate_id = 3) and su.overtime_type_id = 3 and su.app_time = #{param.times}) as holidayturncompenleave,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 2 or su.compensate_id = 4) and su.overtime_type_id = 1 and su.app_time = #{param.times}) as workingtransferovertime,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 2 or su.compensate_id = 4) and su.overtime_type_id = 2 and su.app_time = #{param.times}) as resttransferovertime,
					(select SUM(su.duration) as duration from kqgl_asso_relation_summary su where su.user_id = sum.num and su.approval_type = 1 
					and (su.compensate_id = 2 or su.compensate_id = 4) and su.overtime_type_id = 3 and su.app_time = #{param.times}) as holidaytransferovertime
			from kqgl_asso_month_punch_summary sum
			LEFT JOIN (
				select DISTINCT info.`name` as username ,
						dkjl.attdate,bcsz.id as bcszid,
						bcsz.`name` as bcname,bcsz.sbdk1 as bcsbdk1,bcsz.xbdk1 as bcxbdk1,bcsz.sbdk2 as bcsbdk2,bcsz.xbdk2 as bcxbdk2,bcsz.sbdk3 as bcsbdk3,bcsz.xbdk3 as bcxbdk3,
						dkmx.`userid`,dkmx.`data` ,dkmx.`sbdk1`,dkmx.`sbdk1jg`,dkmx.`xbdk1` ,dkmx.`xbdk1jg`,dkmx.`sbdk2` ,dkmx.`sbdk2jg` ,dkmx.`xbdk2` ,
						dkmx.`xbdk2jg`,dkmx.`sbdk3` ,dkmx.`sbdk3jg` ,dkmx.`xbdk3`,dkmx.`xbdk3jg` ,dkmx.`ydkcs` ,dkmx.`gzsc` ,dkmx.`qyid`,dkmx.`dksj` ,
						dkmx.`yzcdcs` ,dkmx.`yzcdsc` ,dkmx.`kgcdfzs`,dkmx.dktj1,dkmx.dktj2,dkmx.dktj3,dkmx.dktj4,dkmx.dktj5,dkmx.dktj6,dkmx.dkst1,dkmx.dkst2,dkmx.dkst3,info.custom_num
					from kqgl_asso_dkmx dkmx 
					LEFT JOIN yggl_main_emp as info on info.emp_num = dkmx.userid and info.org_code = #{param.orgCode}
					LEFT JOIN kqgl_asso_dkjl as dkjl on dkjl.dkmxid = dkmx.id
					LEFT JOIN kqgl_asso_bcsz as bcsz on bcsz.id = dkjl.bcid 
						where dkmx.qyid = #{param.orgCode}
					and dkmx.`data` = #{param.times}
			) as rtj on rtj.userid = sum.num
			LEFT JOIN yggl_main_emp as info on info.emp_num = sum.num and info.org_code = #{param.orgCode}
			
			where sum.org_code = #{param.orgCode}
			and sum.belong_year = #{param.year}
			and sum.belong_month = #{param.month}
			<if test="param.query != null and param.query != ''">
				and (	sum.`name` like CONCAT('%',#{param.query},'%') or 
						sum.num like CONCAT('%',#{param.query},'%') or
				info.custom_num like CONCAT('%',#{param.query},'%'))
			</if>
			<if test="param.attid != null and param.attid != ''">
				and sum.att_group = #{param.attid}
			</if>
			<if test="param.turnover_status == 1">
				and sum.num not in (select em.emp_num from yggl_main_lzb em where em.org_code = #{param.orgCode} and em.job_status = 3)
			</if>
			
			<!-- LEFT JOIN kqgl_asso_leave_employee_balance as mrtj on mrtj.userid = sum.num 
			IFNULL(mrtj.leave_rules_id,'') as leaverulesid,
					IFNULL(mrtj.balance_days,'') as balancedays-->
					
					<!-- 
					sum.total_overtime_hours as totalovertimehours,
					sum.working_turn_compen_leave as workingturncompenleave,
					sum.rest_turn_compen_leave as restturncompenleave,
					sum.holiday_turn_compen_leave as holidayturncompenleave,
					sum.working_transfer_overtime as workingtransferovertime,
					sum.rest_transfer_overtime as resttransferovertime,
					sum.holiday_transfer_overtime as holidaytransferovertime -->
	</select>


</mapper>