AttendanceTaskTiming.java 34.6 KB
Newer Older
lal committed
1 2
package cn.timer.api.controller.kqgl.atttimer;

lal committed
3
import java.text.DateFormat;
lal committed
4 5
import java.text.ParseException;
import java.text.SimpleDateFormat;
lal committed
6
import java.util.ArrayList;
lal committed
7 8 9 10
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
lal committed
11
import java.util.Locale;
lal committed
12 13

import org.springframework.beans.factory.annotation.Autowired;
lal committed
14 15 16
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
lal committed
17 18 19 20 21

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.timer.api.bean.kqgl.AttendanceWeeklySch;
import cn.timer.api.bean.kqgl.PunchCardDetails;
lal committed
22
import cn.timer.api.bean.kqgl.PunchRecord;
lal committed
23 24
import cn.timer.api.bean.kqgl.Schedule;
import cn.timer.api.bean.kqmk.KqglAssoBcsz;
lal committed
25
import cn.timer.api.bean.kqmk.KqglAssoLeaveRules;
lal committed
26
import cn.timer.api.bean.kqmk.KqglAssoMonthPunchSummary;
lal committed
27
import cn.timer.api.bean.kqmk.KqglAssoOvertimeBasics;
lal committed
28
import cn.timer.api.bean.kqmk.KqglAssoPbmx;
lal committed
29
import cn.timer.api.bean.kqmk.KqglAssoRelationSummary;
lal committed
30 31 32
import cn.timer.api.bean.kqmk.KqglAssoTeshu;
import cn.timer.api.bean.kqmk.KqglAssoZhoupaiban;
import cn.timer.api.bean.kqmk.KqglMainKqz;
lal committed
33
import cn.timer.api.bean.qyzx.QyzxEntInfoM;
lal committed
34 35 36
import cn.timer.api.controller.kqgl.ClockInTool;
import cn.timer.api.dao.kqgl.AttendanceWeeklySchMapper;
import cn.timer.api.dao.kqgl.PunchCardDetailsMapper;
lal committed
37
import cn.timer.api.dao.kqgl.PunchRecordMapper;
lal committed
38
import cn.timer.api.dao.kqgl.ScheduleMapper;
lal committed
39
import cn.timer.api.dao.kqmk.KqglAssoDkmxMapper;
lal committed
40
import cn.timer.api.dao.kqmk.KqglAssoLeaveBalanceMapper;
lal committed
41
import cn.timer.api.dao.kqmk.KqglAssoRelationSummaryMapper;
lal committed
42 43 44 45
import cn.timer.api.dao.kqmk.KqglAssoTeshuMapper;
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
import cn.timer.api.dao.qyzx.QyzxEntInfoMMapper;
import cn.timer.api.dto.kqmk.AdditionalDto;
lal committed
46
import cn.timer.api.dto.kqmk.AttSubsidiaryDto;
lal committed
47 48 49 50
import cn.timer.api.utils.DateUtil;

/**
 * @author lal
lal committed
51
 *	考勤报表汇总数据
lal committed
52
 */
lal committed
53 54 55 56 57
//@Component
//@Lazy
@Configuration      //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class AttendanceTaskTiming{
lal committed
58

lal committed
59
//	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
lal committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	static String tablename = null;
	
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
	@Autowired
	private QyzxEntInfoMMapper qyzxentinfommapper;
	@Autowired
	private KqglAssoLeaveBalanceMapper kqglassoleavebalancemapper;
	@Autowired
	private KqglAssoTeshuMapper kqglassoteshumapper;
	@Autowired
	private PunchCardDetailsMapper punchcarddetailsmapper;
	@Autowired
	private AttendanceWeeklySchMapper attendanceweeklyschmapper;
	@Autowired
	private ScheduleMapper schedulemapper;
lal committed
76 77
	static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	static SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
lal committed
78 79 80
	/**
	 *	数据库动态更改定时配置(attendance_socks)
	 */
lal committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94
//	@Override
//	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//		taskRegistrar.addTriggerTask(() -> {
//			// 任务逻辑
//			try {
//				tablename = AttendanceTask();
//			} catch (ParseException e) {
//				e.printStackTrace();
//			}
//		}, triggerContext -> {
//			CronTrigger cron = new CronTrigger(AttendanceUtil.getCron(tablename)); // cron配置
//			return cron.nextExecutionTime(triggerContext); // 下次执行任务的时间
//		});
//	}
lal committed
95
	
lal committed
96 97 98 99 100 101
	@Autowired
	private KqglAssoRelationSummaryMapper kqglassorelationsummarymapper;
	@Autowired
	private PunchRecordMapper punchrecordmapper;
	@Autowired
	private KqglAssoDkmxMapper kqglassodkmxmapper;
lal committed
102 103 104 105
	/**
	 * @return
	 * @throws ParseException 
	 */
lal committed
106
	
lal committed
107
	 //3.添加定时任务 每天下午七点执行一次
lal committed
108
     @Scheduled(cron = "0 37 10 * * ?")
lal committed
109 110 111 112 113
    //或直接指定时间间隔,例如:5秒
    //@Scheduled(fixedRate=5000)
	
//	@Scheduled(cron = "0/5 * * * * ?") // 测试:5秒执行一次  0 0 19 * * ?
	public  void  AttendanceTask() throws ParseException {
lal committed
114
		
lal committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
//		boolean implement = false;
//		int sockid = 0;
//		KqglTaskTiming sock = KqglTaskTiming.builder().build().selectOne(new QueryWrapper<KqglTaskTiming>().lambda().eq(KqglTaskTiming::getTask, "AttendanceTask"));
//		if(sock == null) {
//			KqglTaskTiming sock1 =  KqglTaskTiming.builder().task("AttendanceTask").executionStatus(1).lastExecutionTime(new Date().getTime()).build();
//			sock1.insert();
//			sockid = sock1.getId();
//			implement = true;
//		}else {
//			sockid = sock.getId();
//			if(sock.getExecutionStatus() == 0) {
//				KqglTaskTiming.builder().task("AttendanceTask").id(sock.getId()).executionStatus(1).lastExecutionTime(new Date().getTime()).build().updateById();
//				implement = true;
//			}
//		}
		boolean implement = true;
lal committed
131
		//逻辑
lal committed
132
		if(implement) {
lal committed
133
			
lal committed
134
//			System.err.println("时间:" + dateFormat.format(new Date()));
lal committed
135 136 137 138 139 140 141 142 143 144
			
			Calendar c = Calendar.getInstance();    
			c.add(Calendar.MONTH, 0);
			c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
			Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdf1.format(c.getTime()),"yyyy-MM-dd")).getTime();
			//获取当前月最后一天
			Calendar ca = Calendar.getInstance();    
			ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
			Long endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(sdf1.format(ca.getTime()),"yyyy-MM-dd")).getTime();
			
lal committed
145
			List<QyzxEntInfoM> orgcodelist = qyzxentinfommapper.selectList(new QueryWrapper<QyzxEntInfoM>());//系统中的所有公司  所有未到期的公司
lal committed
146 147
			
			String str = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();//
lal committed
148
			String ttstr = new SimpleDateFormat("yyyy-MM").format(new Date()).toString();//
lal committed
149 150
			String[] rangeArray=ClockInTool.listToString(ClockInTool.getDays(sdf1.format(c.getTime()),str)).split(";");//目前为止所有日期
			String[] range=rangeArray[0].split(",");
lal committed
151
			
lal committed
152 153 154 155 156
			int year = Calendar.getInstance().get(Calendar.YEAR);
			int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
			
			KqglAssoMonthPunchSummary.builder().build().delete(new QueryWrapper<KqglAssoMonthPunchSummary>().lambda().eq(KqglAssoMonthPunchSummary::getBelongYear, year).eq(KqglAssoMonthPunchSummary::getBelongMonth, month));
			
lal committed
157 158
			for(int t = 0;t<orgcodelist.size();t++){
				int org_code = orgcodelist.get(t).getId();//企业组织代码
lal committed
159 160
				List<AdditionalDto> userlist = kqglassoleavebalancemapper.selectAdditionalList(org_code);
				for(AdditionalDto user : userlist) {
lal committed
161
					double traveltotal = 0,egresstotal = 0,overtimetotal = 0;
lal committed
162 163 164 165 166 167 168 169 170
					//出差总时长
					KqglAssoRelationSummary travel = kqglassorelationsummarymapper.SecondaryValue(user.getEmpnum(), 3, ttstr);
					if(travel !=null) { traveltotal = travel.getDuration(); }
					//外出总时长
					KqglAssoRelationSummary egress = kqglassorelationsummarymapper.SecondaryValue(user.getEmpnum(), 4, ttstr);
					if(egress!=null) { egresstotal = egress.getDuration(); }
					//加班总时长
					KqglAssoRelationSummary overtime = kqglassorelationsummarymapper.SecondaryValue(user.getEmpnum(), 1, ttstr);
					if(overtime!= null) { overtimetotal = overtime.getDuration(); }
lal committed
171 172 173
						//考勤组信息
						KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(user.getEmpnum(),org_code); 
						//目前为止打卡记录
lal committed
174
						List<PunchCardDetails> attendance = punchcarddetailsmapper.selectAttendanceDays(user.getEmpnum(), startDate, new Date().getTime());
lal committed
175
						int dkjl = 0;//目前为止打卡次数
lal committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
						int sbqkcs = 0,xbqkcs = 0,dk=0;
						String[] sblacks = new String[31];//上班缺卡天数
						String[] xblacks = new String[31];//下班缺卡天数
						String[] dkjtts = new String[attendance.size()];//目前打卡日期明细
						if(attendance.size() > 0) { 
							dkjl = attendance.size();
							for(PunchCardDetails pcd:attendance){
								dkjtts[dk] = pcd.getData();
								dk++;
				            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
				            		if(pcd.getSbdk1() == null){ sblacks[sbqkcs] = pcd.getData(); sbqkcs++; }
				            		if(pcd.getXbdk1() == null){ xblacks[xbqkcs] = pcd.getData(); xbqkcs++; }
				            	}
				            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
				            		if(pcd.getSbdk2() == null){ sblacks[sbqkcs] = pcd.getData(); sbqkcs++; }
				            		if(pcd.getXbdk2() == null){ xblacks[xbqkcs] = pcd.getData(); xbqkcs++; }
				            	}
				            	if(pcd.getYdkcs() == 6){
				            		if(pcd.getSbdk3() == null){ sblacks[sbqkcs] = pcd.getData(); sbqkcs++; }
				            		if(pcd.getXbdk3() == null){ xblacks[xbqkcs] = pcd.getData(); xbqkcs++; }
				            	}
				            }
						}
lal committed
199
						//具体打卡时间入汇总表(打卡成功才会录入汇总表)
lal committed
200 201
//						 KqglAssoMonthPunchSummary isyessum = KqglAssoMonthPunchSummary.builder().build().selectOne(new QueryWrapper<KqglAssoMonthPunchSummary>().lambda()
//								 .eq(KqglAssoMonthPunchSummary::getNum, user.getEmpnum()).eq(KqglAssoMonthPunchSummary::getOrgCode, org_code));
lal committed
202 203 204 205 206 207 208 209 210 211
						 String[] ycqts = new String[31];//应上班的具体天数(yyyy-MM-dd)
						 String[] xxts = new String[31];//休息的具体天数(yyyy-MM-dd)
						 List<String> rowData = new ArrayList<String>();
						//休息天数,应出勤天数,实际出勤
						double daysOff = 0,daysOnDuty = 0;//,actualAttDays = 0;
						int zjgzts = 0;//目前为止应该出勤的天数
						//工作时长(分钟)、严重迟到次数、严重迟到时长(分钟)、旷工迟到次数
						double workinghours = 0,seriouslatetimes = 0,seriouslatehours = 0,absenlatetimes = 0;
						// 迟到次数  迟到时长  早退次数  早退时长
					    int latenum = 0,latehours = 0,leanum = 0,leahours = 0;// 迟到次数
lal committed
212 213 214 215 216
					    int answer =0;//班次ID
					    //工作日(转调休)、休息日(转调休)、节假日(转调休)
					    double workingturncompenleave = 0,restturncompenleave = 0,holidayturncompenleave = 0;//工作日(转调休)
					    //工作日(转加班费)、休息日(转加班费)、节假日(转加班费)
					    double workingtransferovertime = 0,resttransferovertime = 0,holidaytransferovertime = 0;
lal committed
217
					    int attgroid = 0;
lal committed
218
						if(attgro != null){//该员工是否加入到考勤组  排班方式 1:固定排班;2:自由排班;3:自由工时         计算出应出勤,实际出勤,休息天数
lal committed
219
							attgroid = attgro.getId();
lal committed
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
//								KqglAssoBcsz shif = KqglAssoBcsz.builder().build();
//								//休息天数,应出勤天数,实际出勤
//								double daysOff = 0,daysOnDuty = 0;//,actualAttDays = 0;
//								int zjgzts = 0;//目前为止应该出勤的天数
							if(attgro.getPbfs() == 1){	//固定排班
								List<KqglAssoTeshu> bxdklist = kqglassoteshumapper.ShouldSpecialDatessetByKqzid(attgro.getId(), ttstr,1);//当前月     必须打卡日期
								int bxdk = bxdklist.size();
								String[] bxdkss = new String[bxdk];////特殊-必须打卡天数(工作日)
								int b = 0;
								for(KqglAssoTeshu bxd : bxdklist) {
									bxdkss[b] = bxd.getTsrq();
									b++;
								}
								List<KqglAssoTeshu> wxdk = kqglassoteshumapper.ShouldSpecialDatessetByKqzid(attgro.getId(), ttstr,2);//当前月     无需打卡日期
								String[] appmaps= new String[wxdk.size()];//特殊-无需打卡天数(休息日)
								int d1 = 0;
								for(KqglAssoTeshu spe:wxdk){
									appmaps[d1] = spe.getTsrq();
									d1++;
								}
								List<AttendanceWeeklySch> atwek = attendanceweeklyschmapper.selectAttendanceMadeByUserid(user.getEmpnum());
								String[] week= new String[atwek.size()];
								String[] needfig = new String[atwek.size()];//应打卡周期时间
								int e = 0;
								for(AttendanceWeeklySch awek : atwek){
									week[e] = awek.getWekmc();
									needfig[e] = String.valueOf(awek.getType());//获取设置的应打卡周几
									e++;
								}
								String yemo = year + "-" + month;
								sdf1.setLenient(false);
								int y = 0,q = 0;
								 for(int i = 1; i <= ClockInTool.getDaysByYearMonth(year,month); i++){
										Date date1 = sdf1.parse(yemo + "-" + i);
										for(int u=0;u<week.length;u++){
											if(sdf2.format(date1).equals(week[u])){
												q++;
												y++;
												if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
													y = y-1;
lal committed
260 261
												}
											}
lal committed
262 263 264 265 266 267 268 269 270 271
										}
								 }
								 int xiuxi = ClockInTool.getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
								 daysOff = xiuxi;
								 daysOnDuty = y+bxdk;
//								 String[] range=ClockInTool.listToString(ClockInTool.getDays(sdf1.format(c.getTime()),str)).split(";");//目前为止所有日期
//								 int zjgzts = 0;//目前为止应该出勤的天数
								//目前为止应出勤天数
								 int w = 0,x=0;
								 for(String num : range) {
lal committed
272
									if(Arrays.binarySearch(needfig, String.valueOf(ClockInTool.dateToWeek(num))) >= 0) {//对比排班应打卡时间
lal committed
273 274
										ycqts[w] = num;
										w++;
lal committed
275
										zjgzts++;
lal committed
276 277 278
									}else {
										xxts[x] = num;
										x++;
lal committed
279 280
									}
									if(Arrays.binarySearch(bxdkss, num) >= 0) {//检查是否存在 必须打卡名单中
lal committed
281 282
										ycqts[w] = num;
										w++;
lal committed
283
										zjgzts++;
lal committed
284
										if(user.getEmpnum() == 257) {
lal committed
285
											ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(xxts), num);//为必须上班的话从休息日期中去除
lal committed
286
										}
lal committed
287 288
									}
									if(Arrays.binarySearch(appmaps, num) >= 0) {//检查是否存在 无需打卡名单中
lal committed
289
										ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num);//为必须休息的话从上班日期中去除
lal committed
290
										zjgzts = zjgzts - 1;
lal committed
291 292
										xxts[x] = num;
										x++;
lal committed
293
									}
lal committed
294 295
								 }
							}else if(attgro.getPbfs() == 2){	//自由排班
lal committed
296
								DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
lal committed
297 298 299 300
								List<Schedule> ycqs = schedulemapper.getAttendanceShouldList(user.getEmpnum(),startDate,endDate);
								int xiuxi = 0,shangban = 0,z=0;
								String[] ziyoupb = new String[ycqs.size()];
								for(Schedule sc : ycqs){
lal committed
301 302
									String data = new SimpleDateFormat("yyyy-MM-dd").format(df.parse(String.valueOf(sc.getData())));// 获得格式化后的日期字符串
									ziyoupb[z] = data;
lal committed
303 304 305 306 307
									z++;
									if(sc.getBcid().equals(0)){
										xiuxi++;
									}else{
										shangban++;
lal committed
308
									}
lal committed
309 310 311 312 313 314
								}
								daysOff = xiuxi;
								daysOnDuty = shangban;
								//目前为止应出勤天数
								int y = 0,x=0;
								for(String num : range) {
lal committed
315 316 317
									if(Arrays.binarySearch(ziyoupb, num) >= 0) {
										KqglAssoPbmx pbx = KqglAssoPbmx.builder().build().selectOne(new QueryWrapper<KqglAssoPbmx>().lambda().eq(KqglAssoPbmx::getUserid, user.getEmpnum()).eq(KqglAssoPbmx::getData, num).eq(KqglAssoPbmx::getKqzid, attgro.getId()));
										if(pbx!=null && pbx.getBcid()!=0) {
lal committed
318
											ycqts[y] = num;
lal committed
319
											y++;
lal committed
320
											zjgzts++;
lal committed
321 322 323
										}else {
											xxts[x] = num;
											x++;
lal committed
324 325
										}
									}
lal committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
								}
							}else{
								List<AttendanceWeeklySch> atwek = attendanceweeklyschmapper.selectAttendanceMadeByUserid(user.getEmpnum());
								String[] week= new String[atwek.size()];
								int e = 0;
								String[] ziyoupb = new String[atwek.size()];
								for(AttendanceWeeklySch awek : atwek){
									week[e] = awek.getWekmc();
									ziyoupb[e] = String.valueOf(awek.getType());
									e++;
								}
								String yemo = year + "-" + month;
								sdf1.setLenient(false);
								int y = 0;
								 for(int i = 1; i <= ClockInTool.getDaysByYearMonth(year,month); i++){
										Date date1 = sdf1.parse(yemo + "-" + i);
										for(int u=0;u<week.length;u++){
											if(sdf2.format(date1).equals(week[u])){
												y++;
lal committed
345 346
											}
										}
lal committed
347 348 349 350 351 352 353
								 }
								 int xiuxi = ClockInTool.getDaysByYearMonth(year,month) - y;
								 daysOff = xiuxi;
							     daysOnDuty = y;
							     //目前为止应出勤天数
							     int g = 0,x=0;
							     for(String num : range) {
lal committed
354
							    	 if(Arrays.binarySearch(ziyoupb, String.valueOf(ClockInTool.dateToWeek(num))) >= 0) {//对比排班应打卡时间
lal committed
355
							    		 ycqts[g] = num;	
lal committed
356
							    		 g++;
lal committed
357
							    		 zjgzts++;
lal committed
358
									 }else {
lal committed
359 360
										xxts[x] = num;
										x++;
lal committed
361
									 }
lal committed
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
							     }
							}
						List<PunchRecord> initial = punchrecordmapper.getMaintenancePunchCardList(startDate,new Date().getTime(),user.getEmpnum());
//					    // 迟到次数  迟到时长  早退次数  早退时长
//					    int latenum = 0,latehours = 0,leanum = 0,leahours = 0;// 迟到次数
					    String[] cdts = new String[31];//迟到的具体天数
					    String[] ztts = new String[31];//早退的具体天数
						if(initial.size() > 0){
							for(PunchRecord prd : initial){
								if(prd.getType() == 1 && prd.getResults() > 0){
									cdts[latenum] = new SimpleDateFormat("yyyy-MM-dd").format(prd.getDktime());
									latenum++;
									latehours += prd.getResults();
								}
								if(prd.getType() == 2 && prd.getResults() > 0){
									ztts[leanum] = new SimpleDateFormat("yyyy-MM-dd").format(prd.getDktime());
									leanum++;
									leahours += prd.getResults();
								}
							}
						}
						AttSubsidiaryDto subs = kqglassodkmxmapper.subsidiary(user.getEmpnum(), ttstr);
//							//工作时长(分钟)、严重迟到次数、严重迟到时长(分钟)、旷工迟到次数
//							double workinghours = 0,seriouslatetimes = 0,seriouslatehours = 0,absenlatetimes = 0;
						if(subs != null) {
							workinghours = subs.getGzsctotalgzsc();
							seriouslatetimes = subs.getYzcdcstotal();
							seriouslatehours = subs.getYzcdsctotal();
							absenlatetimes = subs.getKgcdfzstotal();
						}
						//具体请假天数
						List<KqglAssoRelationSummary> leavetotal = kqglassorelationsummarymapper.SpecificLeave(user.getEmpnum(), 2, ttstr);
						String[] leaves = new String[leavetotal.size()];
						int l = 0;
						if(leavetotal.size()>0) {
							for(KqglAssoRelationSummary lea : leavetotal){
								leaves[l] = lea.getAppTime();
								l++;
							} 
						}
						//具体加班天数
						List<KqglAssoRelationSummary> overtitotal = kqglassorelationsummarymapper.SpecificLeave(user.getEmpnum(), 1, ttstr);
						String[] overtimes = new String[overtitotal.size()];
						int o = 0;
						if(overtitotal.size() > 0) {
							for(KqglAssoRelationSummary over : overtitotal) {
								overtimes[o] = over.getAppTime();
								o++;
							}
						}
						//具体出差天数
						List<KqglAssoRelationSummary> trtotal = kqglassorelationsummarymapper.SpecificLeave(user.getEmpnum(), 3, ttstr);
						String[] travels = new String[trtotal.size()];
						int cx = 0;
						if(trtotal.size()>0) {
							for(KqglAssoRelationSummary trt : trtotal) {
								travels[cx] = trt.getAppTime();
								cx++;
							}
						}
						//具体外出天数
						List<KqglAssoRelationSummary> goouttotal = kqglassorelationsummarymapper.SpecificLeave(user.getEmpnum(), 4, ttstr);
						String[] goouts = new String[goouttotal.size()];
						int wc = 0;
						if(goouttotal.size()>0) {
							for(KqglAssoRelationSummary go:goouttotal) {
								goouts[wc] = go.getAppTime();
								wc++;
							}
						}
						//具体补卡天数
						List<KqglAssoRelationSummary> cardtotal = kqglassorelationsummarymapper.SpecificLeave(user.getEmpnum(), 5, ttstr);
						String[] cards = new String[cardtotal.size()]; 
						int bk = 0;
						if(cardtotal.size()>0) {
							for(KqglAssoRelationSummary car : cardtotal) {
								cards[bk] = car.getAppTime();
								bk++;
							}
						}
lal committed
442
						
lal committed
443
						//排查请假是否在最后一次打卡范围内  查询当月的请假所有日期
lal committed
444
						List<KqglAssoRelationSummary> leainv = kqglassorelationsummarymapper.LeaveInvestigation(user.getEmpnum(), 2, ttstr);
lal committed
445
						KqglAssoBcsz shif = KqglAssoBcsz.builder().build();
lal committed
446 447 448 449 450
						String beginTime = sdf1.format(new Date());
//							List<String> rowData = new ArrayList<String>();
						//遍历目前为止所有日期 结合该用户发起的审批进行结合
						//1:加班 2:请假 3:出差 4:外出 5:补卡
						for(String num : range) {
lal committed
451
							if(Arrays.binarySearch(ClockInTool.deleteArrayNull(xxts), num) >= 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(dkjtts),num) >= 0) {
lal committed
452
								rowData.add("休息并打卡");
lal committed
453
							}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(xxts), num) >= 0){
lal committed
454
								rowData.add("休息");
lal committed
455
							}else {
lal committed
456
								if(Arrays.binarySearch(ClockInTool.deleteArrayNull(ycqts), num) >= 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(dkjtts), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(leaves), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(travels), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(goouts), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(cards), num) < 0) {
lal committed
457
									rowData.add("旷工");
lal committed
458
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(ycqts), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(xxts), num) < 0) {//日期不在上班也不在休息里面即为未排班
lal committed
459
									rowData.add("未排班");
lal committed
460
								}else if(sdf1.parse(beginTime).getTime() < sdf1.parse(num).getTime()) {
lal committed
461
									rowData.add("未到班期");
lal committed
462
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(leaves), num) >= 0) {//请假
lal committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476
									KqglAssoRelationSummary lea = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, user.getEmpnum()).eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getApprovalType, 2));
									String leavetype = "未知";//请假类型
									String company = "未知";//请假单位
									if(lea != null) {
										KqglAssoLeaveRules rul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getId, lea.getLeaveTypeId()));
										if(rul != null) {
											leavetype = rul.getName();
											//1:按天请假;2:按半天;3:按小时
											if(rul.getCompany() == 1) { company = "天"; }
											else if(rul.getCompany() == 2) { company = "半天"; }
											else { company = "小时"; }
										}
									}
									rowData.add(lea.getStartTime() +"到"+ lea.getEndTime()+"请"+leavetype+lea.getDuration()+company);
lal committed
477
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(travels), num) >= 0) {//出差
lal committed
478 479
									KqglAssoRelationSummary lea = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, user.getEmpnum()).eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getApprovalType, 3));
									rowData.add(lea.getStartTime() +"到"+ lea.getEndTime()+"出差"+lea.getDuration()+"天");
lal committed
480
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(goouts), num) >= 0){//外出
lal committed
481 482
									KqglAssoRelationSummary lea = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, user.getEmpnum()).eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getApprovalType, 4));
									rowData.add(lea.getStartTime() +"到"+ lea.getEndTime()+"外出"+lea.getDuration()+"天");
lal committed
483
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(cards), num) >= 0){//补卡
lal committed
484 485
									KqglAssoRelationSummary lea = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, user.getEmpnum()).eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getApprovalType, 5));
									rowData.add("已补卡:"+lea.getStartTime());
lal committed
486
								}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(overtimes), num) >= 0) {//加班
lal committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500
									KqglAssoRelationSummary lea = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, user.getEmpnum()).eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getApprovalType, 1));
									String company = "未知",method = "无";//加班单位、加班补偿方式
									//最小加班单位 1:按分钟加班、2:按半小时加班、3:按小时加班、4:按半天加班、5:按天加班
									KqglAssoOvertimeBasics basics = KqglAssoOvertimeBasics.builder().build().selectOne(new QueryWrapper<KqglAssoOvertimeBasics>().lambda().eq(KqglAssoOvertimeBasics::getOrgCode, org_code));
									if(basics.getMinimumUnit() == 1) { company = "分钟"; }
									else if(basics.getMinimumUnit() == 2) { company = "半小时";}
									else if(basics.getMinimumUnit() == 3) { company = "小时";}
									else if(basics.getMinimumUnit() == 4) { company = "半天";}
									else if(basics.getMinimumUnit() == 5) { company = "天";}
									//1:转调休;2:转加班费;3:转调休或加班费
									if(lea.getCompensateId() == 1) { method="转调休"; }
									else if(lea.getCompensateId() == 2) { method="转加班费"; }
									else {method="转调休或加班费";}
									rowData.add(lea.getStartTime() +"到"+ lea.getEndTime()+"加班"+lea.getDuration()+company+"["+method+"]");
lal committed
501 502
									//加班补偿方式 1:转调休;2:转加班费;3:转调休或加班费
									//工作日
lal committed
503
									if(Arrays.binarySearch(ClockInTool.deleteArrayNull(ycqts), num) >= 0) {
lal committed
504 505 506 507 508 509 510
										if(lea.getCompensateId() == 1) {
											workingturncompenleave++;
										}else if(lea.getCompensateId() == 2) {
											workingtransferovertime++;
										}
									}
									//休息日
lal committed
511
									if(Arrays.binarySearch(ClockInTool.deleteArrayNull(xxts), num) >= 0) {
lal committed
512 513 514 515 516 517
										if(lea.getCompensateId() == 1) {
											restturncompenleave++;
										}else if(lea.getCompensateId() == 2) {
											resttransferovertime++;
										}
									}
lal committed
518
									if(Arrays.binarySearch(ClockInTool.deleteArrayNull(ycqts), num) < 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(xxts), num) < 0) {
lal committed
519 520 521 522 523 524
										if(lea.getCompensateId() == 1) {
											holidayturncompenleave++;
										}else if(lea.getCompensateId() == 2) {
											holidaytransferovertime++;
										}
									}
lal committed
525
								}else{
lal committed
526
									if(Arrays.binarySearch(ClockInTool.deleteArrayNull(sblacks), num) >= 0) {
lal committed
527
										rowData.add("上班缺卡");
lal committed
528
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(sblacks), num) >= 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(ztts), num) >= 0) {
lal committed
529
										rowData.add("上班缺卡,下班早退");
lal committed
530
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(cdts), num) >= 0) {
lal committed
531
										rowData.add("上班迟到");
lal committed
532
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(cdts), num) >= 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(xblacks), num) >= 0) {
lal committed
533
										rowData.add("上班迟到,下班缺卡");
lal committed
534
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(cdts), num) >= 0 && Arrays.binarySearch(ClockInTool.deleteArrayNull(ztts), num) >= 0) {
lal committed
535
										rowData.add("上班迟到,下班早退");
lal committed
536
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(xblacks), num) >= 0) {
lal committed
537
										rowData.add("下班缺卡");
lal committed
538
									}else if(Arrays.binarySearch(ClockInTool.deleteArrayNull(ztts), num) >= 0) {
lal committed
539 540 541 542 543
										rowData.add("下班早退");
									}else {
										rowData.add("正常");
									}
								}
lal committed
544
							}
lal committed
545
							
lal committed
546 547 548 549 550 551 552
							if(attgro.getPbfs() == 1){
								int several = Integer.valueOf(ClockInTool.dateToWeek(num));//
								KqglAssoTeshu tesu = KqglAssoTeshu.builder().build().selectOne(new QueryWrapper<KqglAssoTeshu>().lambda().eq(KqglAssoTeshu::getKqzid, attgro.getId()).eq(KqglAssoTeshu::getTsrq, num));
								if(tesu == null) {
									//获取该员工最新班次
									KqglAssoZhoupaiban gudingpb = KqglAssoZhoupaiban.builder().build().selectOne(new QueryWrapper<KqglAssoZhoupaiban>().lambda().eq(KqglAssoZhoupaiban::getKqzid, attgro.getId())
											.eq(KqglAssoZhoupaiban::getType, several));
lal committed
553 554 555
									if(gudingpb!=null) {
										shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, gudingpb.getBcid()));
									}
lal committed
556
								}else {
lal committed
557 558 559 560
									if(tesu.getBcid() > 0) {
										shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, tesu.getBcid()));
									}
									
lal committed
561 562 563 564
								}
								//获取该员工最新班次
								KqglAssoZhoupaiban gudingpb = KqglAssoZhoupaiban.builder().build().selectOne(new QueryWrapper<KqglAssoZhoupaiban>().lambda().eq(KqglAssoZhoupaiban::getKqzid, attgro.getId())
										.eq(KqglAssoZhoupaiban::getType, several));
lal committed
565
								if(gudingpb != null) {
lal committed
566
										shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, gudingpb.getBcid()));
lal committed
567
								}
lal committed
568 569
							}else if(attgro.getPbfs() == 2){
								KqglAssoPbmx pbmxx = KqglAssoPbmx.builder().build().selectOne(new QueryWrapper<KqglAssoPbmx>().lambda().eq(KqglAssoPbmx::getUserid, user.getEmpnum()).eq(KqglAssoPbmx::getData, num).eq(KqglAssoPbmx::getKqzid, attgro.getId()));
lal committed
570 571 572
								if(pbmxx != null && pbmxx.getBcid() != 0) {
									shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, pbmxx.getBcid()));
								}
lal committed
573
							}
lal committed
574
							
lal committed
575 576
							if(shif != null && shif.getSxbcs() != null) {
								System.out.println(shif.getSxbcs());
lal committed
577
								answer = shif.getSxbcs();//1=2次  2=4次  3=6次
lal committed
578 579 580 581
								//未打最后一次卡的时候  判断最后一次打卡时间是否在请假范围内    相对应减少下班缺卡次数
								//最后一次应打卡时间
								String latimeclock = "";
								if(answer == 1) {
lal committed
582
									latimeclock = num +" "+ shif.getXbdk1();//ClockInTool.dealDateFormat(shif.getXbdk1(),3);
lal committed
583
								}else if(answer == 2) {
lal committed
584
									latimeclock = num +" "+ shif.getXbdk2();//ClockInTool.dealDateFormat(shif.getXbdk2(),3);
lal committed
585
								}else {
lal committed
586
									latimeclock = num +" "+ shif.getXbdk3();//ClockInTool.dealDateFormat(shif.getXbdk3(),3);
lal committed
587 588 589 590 591 592
								}
								for(KqglAssoRelationSummary learel:leainv) {
									boolean adopt = ClockInTool.hourMinuteBetween(latimeclock, learel.getStartTime().substring(0, 16), learel.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
									if(adopt) {
										xbqkcs = xbqkcs-1;
									}
lal committed
593 594
								}
							}
lal committed
595 596 597 598 599 600 601 602 603
						}
					}else {
						for (String num2 : range) { 
							if (Arrays.binarySearch(dkjtts, num2) >= 0) {
			    				rowData.add("未排班并打卡");
			    			}else{
			    				rowData.add("未排班");
			    			}
						}
lal committed
604
						System.err.print("该员工未加入考勤组");
lal committed
605
					}
lal committed
606
						
lal committed
607 608 609 610 611 612 613 614 615
					String[] range1=ClockInTool.listToString(rowData).split(";");
					String[] noticesArray=range1[0].split(",");
					noticesArray = ClockInTool.arrycopy(noticesArray);
					for(int ct=noticesArray.length-1;ct<31;ct++) {
						noticesArray[ct] = "";
						if(ct<30) {
							noticesArray = ClockInTool.arrycopy(noticesArray);
						}
					}
lal committed
616 617 618 619 620 621 622 623 624
					String department = "",position="";
					if(user.getDepartment() != null) {
						department = user.getDepartment();
					}
					if(user.getPosition() != null) {
						position = user.getPosition();
					}
					
					 KqglAssoMonthPunchSummary summary = KqglAssoMonthPunchSummary.builder().name(user.getEmpname()).num(user.getEmpnum()).dept(department)
lal committed
625
							 .post(position).attGroup(attgroid).shift(answer).build();
lal committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
					 summary.setDaysOnDuty(daysOnDuty);//应出勤天数
					 summary.setActualAttDays(Double.valueOf(dkjl));//实际出勤天数
					 summary.setDaysOff(daysOff);//休息天数
					 summary.setWorkingHours(workinghours);
					 summary.setLateTimes(Double.valueOf(latenum));//迟到次数
					 summary.setLateHours(Double.valueOf(latehours));//迟到时长(分钟)
					 summary.setSeriousLateTimes(seriouslatetimes);//严重迟到次数
					 summary.setSeriousLateHours(seriouslatehours);//严重迟到时长(分钟)
					 summary.setAbsenLateTimes(absenlatetimes);//旷工迟到次数
					 summary.setEarlyLeaveTimes(Double.valueOf(leanum));//早退次数
					 summary.setLengthEarlyLeave(Double.valueOf(leahours));//早退时长(分钟)
					 summary.setNumberWorkCardShortage(Double.valueOf(sbqkcs));//上班缺卡次数
					 summary.setNumberDutyCardShortage(Double.valueOf(xbqkcs));//下班缺卡次数
					 summary.setLengthBusinessTrip(traveltotal);//出差时长
					 summary.setTimeOut(egresstotal);//外出时长
					 summary.setTotalOvertimeHours(overtimetotal);//加班总时长
					 summary.setBelongYear(ca.get(Calendar.YEAR));
					 summary.setBelongMonth(ca.get(Calendar.MONTH)+1);
					 summary.setOrgCode(org_code);
					 summary.setLastModified(new Date().getTime());
lal committed
646 647 648 649
					 
					 int absenteeismdays=0;
					 if(zjgzts-dkjl > 0) { absenteeismdays = zjgzts-dkjl; }
					 summary.setAbsenteeismDays(Double.valueOf(absenteeismdays));//旷工天数
lal committed
650 651 652 653 654 655 656
					 
					 summary.setWorkingTurnCompenLeave(workingturncompenleave);//工作日(转调休)
					 summary.setRestTurnCompenLeave(restturncompenleave);//休息日(转调休)
					 summary.setHolidayTurnCompenLeave(holidayturncompenleave);//节假日(转调休)
					 summary.setWorkingTransferOvertime(workingtransferovertime);//工作日(转加班费)
					 summary.setRestTransferOvertime(resttransferovertime);//休息日(转加班费)
					 summary.setHolidayTransferOvertime(holidaytransferovertime);//节假日(转加班费)
lal committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
					 summary.setDay1(noticesArray[0]);
					 summary.setDay2(noticesArray[1]);
					 summary.setDay3(noticesArray[2]);
					 summary.setDay4(noticesArray[3]);
					 summary.setDay5(noticesArray[4]);
					 summary.setDay6(noticesArray[5]);
					 summary.setDay7(noticesArray[6]);
					 summary.setDay8(noticesArray[7]);
					 summary.setDay9(noticesArray[8]);
					 summary.setDay10(noticesArray[9]);
					 summary.setDay11(noticesArray[10]);
					 summary.setDay12(noticesArray[11]);
					 summary.setDay13(noticesArray[12]);
					 summary.setDay14(noticesArray[13]);
					 summary.setDay15(noticesArray[14]);
					 summary.setDay16(noticesArray[15]);
					 summary.setDay17(noticesArray[16]);
					 summary.setDay18(noticesArray[17]);
					 summary.setDay19(noticesArray[18]);
					 summary.setDay20(noticesArray[19]);
					 summary.setDay21(noticesArray[20]);
					 summary.setDay22(noticesArray[21]);
					 summary.setDay23(noticesArray[22]);
					 summary.setDay24(noticesArray[23]);
					 summary.setDay25(noticesArray[24]);
					 summary.setDay26(noticesArray[25]);
					 summary.setDay27(noticesArray[26]);
					 summary.setDay28(noticesArray[27]);
					 summary.setDay29(noticesArray[28]);
					 summary.setDay30(noticesArray[29]);
					 summary.setDay31(noticesArray[30]);
					 summary.insert();
lal committed
689
				}
lal committed
690
			}
lal committed
691 692
				
//			KqglTaskTiming.builder().task("AttendanceTask").id(sockid).executionStatus(0).lastExecutionTime(new Date().getTime()).build().updateById();
lal committed
693 694 695 696 697
//			return new Exception().getStackTrace()[0].getMethodName();
 		}
//		else {
//			return null;
//		}
lal committed
698 699 700 701
	}
	
  
}