ClockInController.java 195 KB
Newer Older
ilal committed
1 2 3
package cn.timer.api.controller.kqgl;

import java.math.BigDecimal;
lal committed
4
import java.sql.Timestamp;
lal committed
5
import java.text.DateFormat;
ilal committed
6 7 8
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
lal committed
9 10
import java.util.Arrays;
import java.util.Calendar;
ilal committed
11 12
import java.util.Date;
import java.util.List;
lal committed
13
import java.util.Locale;
ilal committed
14 15 16

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
lal committed
17 18
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
ilal committed
19
import org.springframework.web.bind.annotation.PostMapping;
lal committed
20
import org.springframework.web.bind.annotation.RequestBody;
ilal committed
21 22 23 24 25 26 27
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

lal committed
28
import cn.hutool.core.bean.BeanUtil;
ilal committed
29
import cn.hutool.json.JSONObject;
lal committed
30 31 32
import cn.timer.api.bean.kqgl.AttConditions;
import cn.timer.api.bean.kqgl.AttGroupBinPunchMode;
import cn.timer.api.bean.kqgl.AttendanceMachine;
lal committed
33
import cn.timer.api.bean.kqgl.AttendanceWeeklySch;
lal committed
34 35
import cn.timer.api.bean.kqgl.PunchCardAddress;
import cn.timer.api.bean.kqgl.PunchCardWiFi;
lal committed
36
import cn.timer.api.bean.kqgl.Schedule;
ilal committed
37 38 39 40 41
import cn.timer.api.bean.kqmk.KqglAssoBcsz;
import cn.timer.api.bean.kqmk.KqglAssoDkjl;
import cn.timer.api.bean.kqmk.KqglAssoDkmx;
import cn.timer.api.bean.kqmk.KqglAssoKqj;
import cn.timer.api.bean.kqmk.KqglAssoKqzdkfs;
ilal committed
42
import cn.timer.api.bean.kqmk.KqglAssoLeaveRules;
lal committed
43 44
import cn.timer.api.bean.kqmk.KqglAssoPbmx;
import cn.timer.api.bean.kqmk.KqglAssoRelationSummary;
ilal committed
45 46 47 48
import cn.timer.api.bean.kqmk.KqglAssoTeshu;
import cn.timer.api.bean.kqmk.KqglAssoZhoupaiban;
import cn.timer.api.bean.kqmk.KqglMainKqz;
import cn.timer.api.bean.yggl.YgglMainEmp;
lal committed
49 50
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
ilal committed
51
import cn.timer.api.config.exception.CustomException;
lal committed
52 53
import cn.timer.api.dao.kqgl.AttGroupBinPunchModeMapper;
import cn.timer.api.dao.kqgl.AttendanceMachineMapper;
lal committed
54
import cn.timer.api.dao.kqgl.AttendanceWeeklySchMapper;
lal committed
55 56
import cn.timer.api.dao.kqgl.PunchCardAddressMapper;
import cn.timer.api.dao.kqgl.PunchCardWiFiMapper;
lal committed
57
import cn.timer.api.dao.kqgl.ScheduleMapper;
lal committed
58 59
import cn.timer.api.dao.kqmk.KqglAssoBcszMapper;
import cn.timer.api.dao.kqmk.KqglAssoDkjlMapper;
lal committed
60
import cn.timer.api.dao.kqmk.KqglAssoDkmxMapper;
ilal committed
61
import cn.timer.api.dao.kqmk.KqglAssoPbmxMapper;
lal committed
62
import cn.timer.api.dao.kqmk.KqglAssoRelationSummaryMapper;
lal committed
63
import cn.timer.api.dao.kqmk.KqglAssoTeshuMapper;
ilal committed
64
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
lal committed
65
import cn.timer.api.dto.kqmk.AttClockMethod;
ilal committed
66 67 68 69 70
import cn.timer.api.dto.kqmk.AttLateLate;
import cn.timer.api.dto.kqmk.AttSchedule;
import cn.timer.api.dto.kqmk.AttendanceCardListDto;
import cn.timer.api.dto.kqmk.ClockCollectData;
import cn.timer.api.dto.kqmk.KqglAssoPbmxDto;
ilal committed
71
import cn.timer.api.dto.kqmk.TransactionApprovalDto;
lal committed
72
import cn.timer.api.dto.kqmk.WorkbenchCalendarDto;
ilal committed
73 74 75 76 77 78
import cn.timer.api.utils.DateUtil;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

ilal committed
79
@Api(tags = "3.0[3]考勤打卡")
ilal committed
80 81 82 83 84 85
@RestController
@Transactional
@RequestMapping(value = "/kqdk", produces = { "application/json", "multipart/form-data" })
public class ClockInController {
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
lal committed
86
	
lal committed
87 88 89
	//打卡明细表
	@Autowired
	private KqglAssoDkmxMapper kqglassodkmxmapper;
lal committed
90 91 92 93
	@Autowired
	private KqglAssoDkjlMapper kqglassodkjlmapper;
	@Autowired
	private KqglAssoBcszMapper kqglassobcszmapper;
lal committed
94 95
	@Autowired
	private KqglAssoRelationSummaryMapper kqglassorelationsummarymapper;
lal committed
96
	
lal committed
97 98 99
	
	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
lal committed
100
	SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ilal committed
101 102 103 104 105 106 107 108 109 110 111
	/**
	 * 考勤打卡
	 * 
	 * @param json dev_id : 考勤机id user_id : 打卡用户id verify_mode : 打卡方式(1:指纹、20:人脸)
	 *             io_time : 打卡时间
	 * @return
	 */
	@PostMapping(value = "/punchclock")
	@ApiOperation(value = "1:考勤机打卡", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 1)
	public Result<Object> punchclock(@RequestParam String json) throws Exception {
lal committed
112
		
lal committed
113 114 115
		String current_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		
		String current = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
lal committed
116
		String yesterday = ClockInTool.requires_extra_times(current,-1,3,1);//前一天
lal committed
117 118 119 120 121 122 123
		
		Long startDateyesterday = DateUtil.getStartTime(0,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
		Long endDateyesterday = DateUtil.getnowEndTime(23,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
		
		Long attendance_date = 0l;//考勤日期
		String toweek = "";
		
lal committed
124
		String msg = "未知错误,请联系管理员";
lal committed
125
		int sbyf = 1;//0:失败;1:成功
lal committed
126
		int status_ = 0;
lal committed
127
		
ilal committed
128
		JSONObject jsonArray = new JSONObject(json);
lal committed
129 130 131
		String asDevId = jsonArray.get("dev_id").toString();//考勤机编码
		String asUserId = jsonArray.get("user_id").toString();//打卡用户id
		String asVerifyMode = jsonArray.get("verify_mode").toString();//考勤机打卡方式(1:指纹;20:人脸;40:掌纹;60:密码(猜的^v^))
lal committed
132
		String sStdIoTime = jsonArray.get("io_time").toString();//打卡时间 **判断次日打卡情况**
lal committed
133
		
ilal committed
134 135 136 137 138
		KqglAssoKqj kqjdev = KqglAssoKqj.builder().build().selectOne(new QueryWrapper<KqglAssoKqj>().lambda().eq(KqglAssoKqj::getCode, asDevId));
		if (kqjdev == null) 
			return ResultUtil.error("考勤机不存在!");
		YgglMainEmp user = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, asUserId).eq(YgglMainEmp::getOrgCode, kqjdev.getQyid()));
		if(user != null) {
lal committed
139 140
			int qyid = user.getOrgCode();
			int userid = user.getEmpNum();
ilal committed
141 142
			KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
			//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
lal committed
143 144
			
			/*******/
lal committed
145 146
			long time_ = DateUtil.getStringTime(sStdIoTime, "yyyy-MM-dd HH:mm:ss");//打卡时间戳
			String putime = new SimpleDateFormat("yyyy-MM-dd").format(time_);//转换打卡时间格式 年月日
lal committed
147 148
			
			String putimehhmm = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_);//转换打卡时间格式 年月日
lal committed
149 150 151 152 153
			//打卡当天开始时间,打卡当天结束时间
			Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			Long endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			int dkmx = 0;
			int shifid = 0;
lal committed
154
			long punchcardtime = 0,punchstart = 0,punchend = 0;//应打卡时间,应打卡开始时间,应打卡结束时间
lal committed
155
			boolean isRange = true;//是否在打卡时间范围内
lal committed
156
			int atttype = 0;
lal committed
157
			int execution_status = 0;//执行状态
lal committed
158 159
			boolean kskd = true;//识别是否更新最后一次打卡   针对于最后一次下班卡
			boolean sbdkkd = false;//针对于上班  未超过上班卡打卡  视为无效打卡
lal committed
160
			ClockCollectData clockt = new ClockCollectData();
lal committed
161 162
			//putime: 根据日期  得到打卡所需的详细信息
			AttendanceCardListDto attdate = MethodCall(qyid,userid,putime);
lal committed
163
			/*******/
lal committed
164
			if(attgro != null) {//判断考勤组是否存在
ilal committed
165 166
				List<KqglAssoKqzdkfs> kqjs = KqglAssoKqzdkfs.builder().build().selectList(new QueryWrapper<KqglAssoKqzdkfs>().lambda().eq(KqglAssoKqzdkfs::getKqzId, attgro.getId()));
				if(kqjs.size() > 0) {
lal committed
167 168 169 170
					/**
					 * 	当考勤组为“固定排班”和“自定义排班”时 方可使用
					 */
					if(attdate.getAttgrouptype() != 3) {
lal committed
171
							 //查询打卡当天是否有记录**********************************
lal committed
172 173 174
							KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build();
							String dakariqi = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDateyesterday))+" "+ClockInTool.dateToWeek2(yesterday);
							//检查昨日的班次是否存在次日打卡
ilal committed
175
							KqglAssoDkjl balan = kqglassodkjlmapper.selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getUserId, userid).eq(KqglAssoDkjl::getQyid, qyid).eq(KqglAssoDkjl::getAttdate, dakariqi).ne(KqglAssoDkjl::getBcid, 0).orderByDesc(KqglAssoDkjl :: getSort).last("LIMIT 1"));
lal committed
176 177
							boolean dnck = false;
							boolean crdk = false;//当次打卡是否存在次日打卡
lal committed
178 179 180 181 182 183 184 185 186 187 188
							if(balan != null) {//前一天是否打过卡    去班次id查询是否存在次日打卡
								//班次信息
								KqglAssoBcsz shif = kqglassobcszmapper.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, balan.getBcid()));
								int dkcs = shif.getSxbcs()*2;
								List<AttSchedule> ashss = attdate.getAttsch();//获取今天应打卡时间
								if(ashss.size() > 0) {
									Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(ashss.get(0).getTime())));//当天应打的首次上班卡时间
									Date sd2=df1.parse(current_time);//当前时间
									if(sd1.after(sd2)) {
										dnck = true;
									}
lal committed
189
								}
lal committed
190 191 192 193 194 195
								int isXbdk1Cr = shif.getIsXbdk1Cr();//下班1是否次日(0:否;1:是)
								int isSbdk2Cr = shif.getIsSbdk2Cr();//上班2是否次日(0:否;1:是)
								int isXbdk2Cr = shif.getIsXbdk2Cr();//下班2是否次日(0:否;1:是)
								int isSbdk3Cr = shif.getIsSbdk3Cr();//上班3是否次日(0:否;1:是)
								int isXbdk3Cr = shif.getIsXbdk3Cr();//下班3是否次日(0:否;1:是)
								if(balan.getSort() < dkcs) {
ilal committed
196 197
									if((isXbdk1Cr + isSbdk2Cr +isXbdk2Cr +  isSbdk3Cr + isXbdk3Cr) > 0) {
										crdk = true;
lal committed
198
									}
ilal committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
									
//									if(balan.getSort()+1 == 2 && dkcs == 2) {
//										//次日
//										if(isXbdk1Cr > 0) { crdk = true; }
//									}
//									if(balan.getSort()+1 == 3 && dkcs == 4) {
//										if(isSbdk2Cr > 0) {crdk = true; }
//									}
//									if(balan.getSort()+1 == 4 && dkcs == 4) {
//										if(isXbdk2Cr > 0) { crdk = true; }
//									}
//									if(balan.getSort()+1 == 5 && dkcs == 6) {
//										if(isSbdk3Cr > 0) { crdk = true; }
//									}
//									if(balan.getSort()+1 == 6 && dkcs == 6) {
//										if(isXbdk3Cr > 0) { crdk = true; }
//									}
lal committed
216
								}
lal committed
217
								
lal committed
218
							}else {
ilal committed
219 220
								List<AttSchedule> ashss = attdate.getAttsch();//获取今天应打卡时间
								
lal committed
221
								//无记录的话就找昨天的数据
ilal committed
222 223
								AttendanceCardListDto attdate1 = MethodCall(qyid,userid,yesterday);
								List<AttSchedule> ashssyebo = attdate1.getAttsch();//获取昨天应打卡时间
224 225 226 227 228 229 230
								if(ashssyebo!=null) {
									if (ashssyebo.size() > 0) {
										Date sd1 = df1.parse(ClockInTool.stampToDate(String.valueOf(ashssyebo.get(0).getTime())));//当天应打的首次上班卡时间
										Date sd2 = df1.parse(current_time);//当前时间
										if (sd2.after(sd1)) {//大于
											dnck = true;
										}
ilal committed
231 232
									}
								}
ilal committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
//								crdk = true;
//								attdate = MethodCall(qyid,userid,yesterday);
								if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && ashss.get(0).getId() != 0) {//班次不为空
									KqglAssoBcsz shifi = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ashss.get(0).getId()));
									int isXbdk1Cr = shifi.getIsXbdk1Cr();//下班1是否次日(0:否;1:是)
									int isSbdk2Cr = shifi.getIsSbdk2Cr();//上班2是否次日(0:否;1:是)
									int isXbdk2Cr = shifi.getIsXbdk2Cr();//下班2是否次日(0:否;1:是)
									int isSbdk3Cr = shifi.getIsSbdk3Cr();//上班3是否次日(0:否;1:是)
									int isXbdk3Cr = shifi.getIsXbdk3Cr();//下班3是否次日(0:否;1:是)
									
									if((isXbdk1Cr + isSbdk2Cr +isXbdk2Cr +  isSbdk3Cr + isXbdk3Cr) > 0) {
										crdk = true;
										
										attdate = MethodCall(qyid,userid,yesterday);
										
									}else {
										crdk = false;
									}
								}
lal committed
252
							}
lal committed
253 254
							
							if(crdk && dnck) {
ilal committed
255
								dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
256
										.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday).eq(KqglAssoDkmx::getData, yesterday));
lal committed
257 258 259 260
								attdate = MethodCall(qyid,userid,yesterday);
								attendance_date = startDateyesterday;
								toweek = yesterday;
							}else {
ilal committed
261
								dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
262
										.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate).eq(KqglAssoDkmx::getData, putime));
lal committed
263 264 265 266 267 268
								attendance_date = startDate;
								toweek = putime;
							}
							if(EmptyUtil.isEmpty(attdate.getAttsch())) {
								msg = "当前未排班";
								sbyf = 0;
lal committed
269
								status_ = 2;
lal committed
270
							}else {
lal committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284
								//排查请假是否在最后一次打卡范围内  查询当月的请假所有日期
								KqglAssoRelationSummary leainv = kqglassorelationsummarymapper.leaveinvesti(userid, 2, putime,qyid);
								boolean adopt = false;
								if(leainv != null) {
									adopt = ClockInTool.hourMinuteBetween(putimehhmm, leainv.getStartTime().substring(0, 16), leainv.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
								}
								
								if(adopt) {
									msg = "已请假";
									sbyf = 0;
									status_ = 2;
								}else {
									long starttime1 = 0,starttime1ks = 0,starttime1js = 0,endtime1 = 0,endtime1ks = 0,endtime1js = 0,starttime2 = 0,starttime2ks = 0,starttime2js = 0,endtime2 = 0,endtime2ks = 0,endtime2js = 0,starttime3 = 0,starttime3ks = 0,starttime3js = 0,
											endtime3 = 0,endtime3ks = 0,endtime3js = 0; 
ilal committed
285
									List<AttSchedule> ash = null;
lal committed
286
									if(attdate.getAttsch().size() > 0) {
ilal committed
287
										ash = attdate.getAttsch();
lal committed
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
										 int y = 0;
										 clockt.setShifid(ash.get(y).getId());
										 shifid = ash.get(y).getId();//班次id
										 if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
											 starttime1 = ash.get(0).getTime();starttime1ks = ash.get(0).getStarttime();starttime1js = ash.get(0).getEndtime();
											 endtime1 = ash.get(1).getTime();endtime1ks = ash.get(1).getStarttime();endtime1js = ash.get(1).getEndtime();
										 }
									 	if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
									 		starttime2 = ash.get(2).getTime();starttime2ks = ash.get(2).getStarttime();starttime2js = ash.get(2).getEndtime();
										    endtime2 = ash.get(3).getTime();endtime2ks = ash.get(3).getStarttime();endtime2js = ash.get(3).getEndtime();
										}
									 	if(attdate.getAttsch().size() == 6) {
									 		starttime3 = ash.get(4).getTime();starttime3ks = ash.get(4).getStarttime();starttime3js = ash.get(4).getEndtime();
											endtime3 = ash.get(5).getTime();endtime3ks = ash.get(5).getStarttime();endtime3js = ash.get(5).getEndtime();
										 }
									 	
									 	if(dkmc == null) {
									 		kskd = false;
									 		
									 		if(attdate.getAttsch().size() == 2) {//一套上下班  上班1
									 			Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(starttime1)));//应打卡时间
												Date sd2=df1.parse(sStdIoTime);//打卡时间
												Date sd3=df1.parse(ClockInTool.stampToDate(String.valueOf(endtime1)));//应打卡时间
												if(sd2.before(sd3)) {
													atttype = 1;
												}
												
												if(sd2.after(sd1) && sd2.after(sd3)) {
													atttype = 2;
												}
									 			
									 		}else {
									 			boolean getinto = true;
									 			//打卡时间  对比班次  接近哪个时间就打哪个时间的卡
										 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
										 			//punchstart 应打卡开始时间 punchend:应打卡结束时间  time_:打卡时间
										 			boolean effectiveDate1 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate1) {//在范围内就打卡 
												    	atttype = 1;
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }
												    boolean effectiveDate2 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate2) {//在范围内就打卡 
												    	atttype = 2;
												    	isRange = true;//在范围
												    	
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }	
													boolean effectiveDate3 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate3) {//在范围内就打卡 
												    	atttype = 3;
												    	isRange = true;//在范围
												    	
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }
												    boolean effectiveDate4 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate4) {//在范围内就打卡 
												    	atttype = 4;
												    	isRange = true;//在范围
												    	
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }	
										 		}
										 		if(attdate.getAttsch().size() == 6) {
										 			boolean effectiveDate5 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate5) {//在范围内就打卡 
												    	atttype = 5;
												    	isRange = true;//在范围
												    	
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }
												    boolean effectiveDate6 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3js),"yyyy-MM-dd HH:mm");
												    if (effectiveDate6) {//在范围内就打卡 
												    	atttype = 6;
												    	isRange = true;//在范围
												    	
												    	getinto = false;
												    }else {
												    	if(getinto) {
												    		isRange = false;
												    	}
												    }	
										 		}
									 		}
										 	 execution_status = 1;
									 	}else {
									 		boolean getinto2 = true;
									 		execution_status = 2;
									 		if(attdate.getAttsch().size() == 2) {	//下班1
									 			if(dkmc.getSbdk1() != null && dkmc.getXbdk1() == null){
									 				//如果第二次后打卡,未超过上班时间  即为打卡失效
									 				Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(starttime1)));//应打卡时间
													Date sd2=df1.parse(sStdIoTime);//打卡时间
													if(sd1.after(sd2)) {
														sbdkkd = true;//打卡无效
//														atttype = 1;
													}else {
														kskd = false;
ilal committed
406
														atttype = 2;
lal committed
407 408 409 410 411 412 413
													}
											     }else {
											    	//最后一次卡的时候 再继续打视为更新最后一次打卡
											    	 kskd = true;
											    	 atttype = 2;
											     }
									 		}	
lal committed
414
									 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
lal committed
415
									 			boolean effectiveDate1 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js),"yyyy-MM-dd HH:mm");
lal committed
416
											    if (effectiveDate1) {//在范围内就打卡 
lal committed
417 418 419 420 421 422 423 424 425 426 427
											    	if(dkmc.getSbdk1() != null) {
											    		sbdkkd = true;//打卡无效
//											    		atttype = 1;
											    	}else {
											    		atttype = 1;
											    		getinto2 = false;
											    		isRange = true;//在范围
											    	}
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
lal committed
428
											    	}
lal committed
429
											    }
lal committed
430
											    boolean effectiveDate2 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js),"yyyy-MM-dd HH:mm");
lal committed
431
											    if (effectiveDate2) {//在范围内就打卡 
lal committed
432 433 434 435 436
											    	if(dkmc.getXbdk1() != null) {
											    		kskd = true;
											    		atttype = 2;
											    	}else {
											    		kskd = false;
ilal committed
437
											    		atttype = 2;
lal committed
438 439
											    		getinto2 = false;
											    		isRange = true;//在范围
lal committed
440
											    	}
lal committed
441 442 443 444 445 446
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
											    	}
											    }
									 			boolean effectiveDate3 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2js),"yyyy-MM-dd HH:mm");
lal committed
447
											    if (effectiveDate3) {//在范围内就打卡 
lal committed
448 449 450 451 452 453 454 455 456 457 458
											    	if(dkmc.getSbdk2() != null) {
											    		sbdkkd = true;//
//											    		atttype = 3;
											    	}else {
											    		atttype = 3;
											    		getinto2 = false;
											    		isRange = true;//在范围
											    	}
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
lal committed
459
											    	}
lal committed
460
											    }
lal committed
461
											    boolean effectiveDate4 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2js),"yyyy-MM-dd HH:mm");
lal committed
462
											    if (effectiveDate4) {//在范围内就打卡 
lal committed
463 464 465 466 467
											    	if(dkmc.getXbdk2() != null) {
											    		kskd = true;//更新最后一次打卡
											    		atttype = 4;
											    	}else {
											    		kskd = false;
ilal committed
468
											    		atttype = 4;
lal committed
469 470 471 472 473 474
											    		getinto2 = false;
											    		isRange = true;//在范围
											    	}
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
lal committed
475
											    	}
lal committed
476 477 478
											    }	
									 		}
									 		if(attdate.getAttsch().size() == 6) {
lal committed
479
									 			boolean effectiveDate5 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3js),"yyyy-MM-dd HH:mm");
lal committed
480
											    if (effectiveDate5) {//在范围内就打卡 
lal committed
481 482 483 484 485 486 487
											    	if(dkmc.getSbdk2() != null) {
											    		sbdkkd = true;//
//											    		atttype = 5;
											    	}else {
											    		atttype = 5;
											    		getinto2 = false;
											    		isRange = true;//在范围
lal committed
488
											    	}
lal committed
489 490 491 492
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
										    		}
lal committed
493
											    }
lal committed
494
											    boolean effectiveDate6 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3js),"yyyy-MM-dd HH:mm");
lal committed
495
											    if (effectiveDate6) {//在范围内就打卡 
lal committed
496 497 498 499 500
											    	if(dkmc.getXbdk2() != null) {
											    		kskd = true;////更新最后一次打卡
											    		atttype = 6;
											    	}else {
											    		kskd = false;
ilal committed
501
											    		atttype = 6;
lal committed
502 503
											    		getinto2 = false;
											    		isRange = true;//在范围
lal committed
504
											    	}
lal committed
505 506 507 508
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
										    		}
lal committed
509 510
											    }	
									 		}
lal committed
511
									 	}
lal committed
512
									 }
lal committed
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
									if(atttype == 1) {
										punchcardtime = starttime1;
										 punchstart = starttime1ks;
								    	 punchend = starttime1js;
									}else if(atttype == 2) {
										punchcardtime = endtime1;
										 punchstart = endtime1ks;
										 punchend = endtime1js;
									}else if(atttype == 3) {
										punchcardtime = starttime2;
								    	 punchstart = starttime2ks;
								    	 punchend = starttime2js;
									}else if(atttype == 4) {
										punchcardtime = endtime2;
								    	 punchstart = endtime2ks;
								    	 punchend = endtime2js;
									}else if(atttype == 5) {
										 punchcardtime = starttime3;
								    	 punchstart = starttime3ks;
								    	 punchend = starttime3js;
									}else if(atttype == 6) {
										punchcardtime = endtime3;
								    	 punchstart = endtime3ks;
								    	 punchend = endtime3js;
									}
									
									
									 if(clockt.getShifid() != 0) {
ilal committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
										 
										 boolean dddbdk = true;//
										boolean dak2 = true;
										 //打卡无限制时  当前时间必须大于上班打卡时间 才能打下班卡
										 if(punchstart==0 && punchend==0 && (atttype == 2 || atttype == 4 || atttype == 6)) {
											 String xbdk = "";
											 if(atttype == 2) {
												 xbdk = String.valueOf(ash.get(0).getTime());
											 }else if(atttype == 4){
												 xbdk = String.valueOf(ash.get(2).getTime());
											 }else {
												 xbdk = String.valueOf(ash.get(4).getTime());
											 }
											 Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(xbdk)));//当天应打的首次上班卡时间
											 Date sd2=df1.parse(current_time);//当前时间
											 if(sd2.before(sd1)) {//小于
												 dak2 = false;
											 }
lal committed
559
										 }
ilal committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
										 if(!dak2) { dddbdk = false; }
										 
										 if(dddbdk) {
											 KqglAssoBcsz shif = KqglAssoBcsz.builder().build();
											 if(attdate.getAttsch().size() > 0 && clockt.getShifid() > 0){//有无班次
												 shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, clockt.getShifid()));
											 }
											//打卡记录录入 -- 打卡是否有时间范围限制
											 if(attdate.getAttsch().size() == 2) {
												 if(punchstart>0 && punchend>0) {
													 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchstart);//应打卡开始时间
													 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchend);//应打卡结束时间
													 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_);//打卡时间
													 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
													 if (!effectiveDate) {
														 System.out.println("当前打卡时间不在范围内");
														// 手动抛出异常
														 isRange = false;
					//									throw new Exception();
													 }
lal committed
580
												 }
lal committed
581
											 }
ilal committed
582 583 584 585
												if(isRange) {
													int yxcd = shif.getYxcdfzs();//允许迟到
													int yzcd = shif.getYzcdfzs();//严重迟到分钟数
													int kgcdfzs  = shif.getKgcdfzs();//旷工迟到分钟数 
lal committed
586
													
ilal committed
587 588
													int dkcs_ = shif.getSxbcs();//上下班打卡次数
													int iswzwd = shif.getIsWzwd();//是否开启晚走晚到(0:否;1:是)
lal committed
589
													
ilal committed
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
													long rest_time = 0;
													if(shif.getStartTime() != null && shif.getEndTime() != null) {
														long kaishixiuxi = Long.valueOf(ClockInTool.dateToStamp(putime + " " +shif.getStartTime()+":00"));
													    long jieshuxiuxi = Long.valueOf(ClockInTool.dateToStamp(putime + " " +shif.getEndTime()+":00"));
													    rest_time = (jieshuxiuxi - kaishixiuxi)/1000/60;//休息时间
													}
													
													double xbwz1 = 0,xbwz2=0,xbwz3=0;
													int sbwd1=0,sbwd2=0,sbwd3=0;
													
													int arrive_late = 0;//晚到时间
													String clock_date = "";//应打卡时间
													Long latetime = 0l;//前天晚走时长(分钟)
													
													KqglAssoDkmx yesterdaymx = KqglAssoDkmx.builder().build();
													AttendanceCardListDto attdateyesterday;
													long yesendtime1=0,yesendtime2=0,yesendtime3=0;
													//存在晚走玩到
													 if(iswzwd > 0) {
														//统一分钟数
													    xbwz1 = Double.valueOf(shif.getXbwz1()) * 60;//下班晚走1
													    String sbwd1_ = String.valueOf(Double.valueOf(shif.getSbwd1()) * 60);
														sbwd1 = Integer.valueOf(sbwd1_.substring(0, sbwd1_.lastIndexOf(".")));//上班晚到1
lal committed
613
														
ilal committed
614 615 616 617 618 619 620 621 622
														xbwz2 = Double.valueOf(shif.getXbwz2()) * 60;//下班晚走2
														String sbwd2_ = String.valueOf(Double.valueOf(shif.getSbwd2()) * 60);
														sbwd2 = Integer.valueOf(sbwd2_.substring(0, sbwd2_.lastIndexOf(".")));//上班晚到2
														
														xbwz3 = Double.valueOf(shif.getXbwz3()) * 60;//下班晚走3
														String sbwd3_ = String.valueOf(Double.valueOf(shif.getSbwd3()) * 60);
														sbwd3 = Integer.valueOf(sbwd3_.substring(0, sbwd3_.lastIndexOf(".")));//上班晚到3
															
														 //获取前一天最后下班的时间
ilal committed
623
														 yesterdaymx = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
624 625
																	.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
														 attdateyesterday = MethodCall(qyid,userid,yesterday);
lal committed
626
														 
ilal committed
627 628 629
														 List<AttSchedule> ash1 = attdateyesterday.getAttsch();
														 if(attdateyesterday.getAttsch().size() == 2 || attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
															 yesendtime1 = ash1.get(1).getTime();
lal committed
630
														 }
ilal committed
631 632 633 634 635 636
													 	 if(attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
													 		yesendtime2 = ash1.get(3).getTime();
														 }
													 	 if(attdateyesterday.getAttsch().size() == 6) {
													 		yesendtime3 = ash1.get(5).getTime();
														  }
lal committed
637
													 }
ilal committed
638 639 640 641
													
													 if(execution_status == 1) {//上班1   ****新增
														 KqglAssoDkmx pcd = KqglAssoDkmx.builder().userid(userid).data(putime).qyid(qyid).dksj(startDate).build();
														 int sbdkjg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst1 = 0;
lal committed
642 643
														 if(punchcardtime != 0){//有应打卡时间时
															 Long time = (time_ - punchcardtime)/1000/60;
ilal committed
644 645 646 647 648 649 650 651
															 if((atttype)%2 > 0){//上班
																if(time > 0){
																	sbdkjg = Integer.valueOf(time.toString());
																}// 打卡结果
															 }else{//下班
																if(time > 0){}else{
																	sbdkjg = Math.abs(Integer.valueOf(time.toString()));
																}// 打卡结果
lal committed
652
															 }
ilal committed
653 654 655 656 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 689 690 691 692 693 694 695 696 697 698 699
															 
															 //存在晚走玩到
															 if(iswzwd > 0 && yesterdaymx != null) {
																 if(dkcs_ == 1) {
																	 if(yesterdaymx.getXbdk1() != null && yesterdaymx.getXbdk1jg() == 0) {
																		 latetime = (yesterdaymx.getXbdk1() - yesendtime1)/1000/60;
																	 }
																 }else if(dkcs_ == 2){
																	 if(yesterdaymx.getXbdk2() != null && yesterdaymx.getXbdk2jg() == 0) {
																		 latetime = (yesterdaymx.getXbdk2() - yesendtime2)/1000/60;
																	 }
																 }else {
																	 if(yesterdaymx.getXbdk3() != null && yesterdaymx.getXbdk3jg() == 0) {
																		 latetime = (yesterdaymx.getXbdk3() - yesendtime3)/1000/60;
																	 }
																 }
																 if(latetime != 0) {
																	 double latetime_ = Double.valueOf(String.valueOf(latetime));//前天晚走时长(分钟)
																	 if(latetime_ > xbwz1 && latetime_ < xbwz2) {
																		 arrive_late = sbwd1;
																	 }else if(latetime_ > xbwz2 && latetime_ < xbwz3) {
																		 arrive_late = sbwd2;
																	 }else if(latetime_ > xbwz3) {
																		 arrive_late = sbwd3;
																	 }
																	 
																	 clock_date = ClockInTool.stampToDate(String.valueOf(punchcardtime));
																	 Long changed_time = Long.valueOf(ClockInTool.dateToStamp(ClockInTool.addtime(clock_date, "+"+arrive_late)));//晚到后应打卡时间
																	 
																	 punchcardtime = changed_time;//更换当天打卡时间
																	 Long timeyes = (time_ - changed_time)/1000/60;//
																	 if((atttype)%2 > 0){//上班
																		if(timeyes > 0){
																			sbdkjg = Integer.valueOf(timeyes.toString());
																		}else {
																			sbdkjg = 0;
																		}
																	 }else{//下班
																		if(timeyes > 0){
																			sbdkjg = 0;
																		}else{
																			sbdkjg = Math.abs(Integer.valueOf(timeyes.toString()));
																		}
																	 }
																 }
															 }
															 
lal committed
700
														 }
ilal committed
701 702 703
														 //允许迟到范围
														 if(sbdkjg <= yxcd) {
															 sbdkjg = 0;
lal committed
704
														 }
lal committed
705
														 
ilal committed
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
													    if(atttype == 1) {
													    	pcd.setSbdk1(time_);
													    	pcd.setSbdk1jg(sbdkjg);
														}else if(atttype == 2) {
															pcd.setXbdk1(time_);
															pcd.setXbdk1jg(sbdkjg);
														}else if(atttype == 3) {
															pcd.setSbdk2(time_);
													    	pcd.setSbdk2jg(sbdkjg);
														}else if(atttype == 4) {
															pcd.setXbdk2(time_);
															pcd.setXbdk2jg(sbdkjg);
														}else if(atttype == 5) {
															pcd.setSbdk3(time_);
													    	pcd.setSbdk3jg(sbdkjg);
														}else if(atttype == 6) {
															pcd.setXbdk3(time_);
															pcd.setXbdk3jg(sbdkjg);
														}
														 int ydkcs = 0;
														 if(shif != null){
															 ydkcs = shif.getSxbcs()*2;
														 }//应打卡次数
														 pcd.setYdkcs(ydkcs);
lal committed
730 731
														 
														 //严重迟到范围
ilal committed
732 733 734 735
														 if(sbdkjg>yzcd && sbdkjg < kgcdfzs && yzcd>0) {
															 yzcdcs++;
															 yzcdsc = sbdkjg;
															 dkst1 = 1;
lal committed
736 737
														 }
														 //旷工迟到
ilal committed
738
														 if(sbdkjg>kgcdfzs && kgcdfzs>0) {
lal committed
739
															 kgcdcs++;
ilal committed
740
															 dkst1 = 2;
lal committed
741
														 }
lal committed
742
														 
ilal committed
743
														 pcd.setDkst1(dkst1);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
ilal committed
744
														 
ilal committed
745 746 747
														 pcd.setYzcdcs(yzcdcs);//严重迟到次数
														 pcd.setYzcdsc(Double.valueOf(yzcdsc));//严重迟到时长(分钟)
														 pcd.setKgcdfzs(kgcdcs);//旷工迟到次数
lal committed
748
														 
ilal committed
749 750
														 if (!pcd.insert()) {
															throw new CustomException("打卡明细-新增异常-1");
lal committed
751
														 }
ilal committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
														 dkmx = pcd.getId();
													 }else if(execution_status == 2){ //*****修改
														 dkmx = dkmc.getId();
														 KqglAssoDkmx pcd = KqglAssoDkmx.builder().build();
														 if(atttype == 2){//下班1
															 pcd.setId(dkmc.getId());
															 pcd.setXbdk1(time_);//下班1打卡时间
															 if(punchcardtime != 0){//有应打卡时间时
																 Long time = (time_ - punchcardtime)/1000/60;
																 if(time > 0){
																	 pcd.setXbdk1jg(0);// 打卡结果
																 }else{
																	 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));
																 }
															 }
															 if(dkmc.getSbdk1() != null){
																Long time = (time_ - dkmc.getSbdk1())/1000/60 - rest_time;
																pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
															 }
															 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
lal committed
772
															 
ilal committed
773 774 775 776 777 778 779
													     }else if(atttype == 3){//上班2
													    	 
													    	 int sbdk2jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst2=0;
															 if(punchcardtime != 0){//有应打卡时间时
																 Long time = (time_ - punchcardtime)/1000/60;
																 if(time > 0){sbdk2jg = Math.abs(Integer.valueOf(time.toString()));}
															 }
lal committed
780
															 
ilal committed
781 782 783 784
															//允许迟到范围
															 if(sbdk2jg <= yxcd) {
																 sbdk2jg = 0;
															 }
lal committed
785
															 
ilal committed
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
															 //严重迟到范围
															 if(sbdk2jg>yzcd && sbdk2jg < kgcdfzs && yzcd>0) {
																 yzcdcs = dkmc.getYzcdcs()+1;
																 yzcdsc = sbdk2jg;
																 dkst2 = 1;
															 }
															 //旷工迟到
															 if(sbdk2jg>kgcdfzs && kgcdfzs>0) {
																 kgcdcs++;
																 kgcdcs = kgcdcs + dkmc.getKgcdfzs();
																 dkst2 = 2;
															 }
															 
															 pcd.setDkst2(dkst2);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
															 
															 pcd.setId(dkmc.getId());
													    	 pcd.setSbdk2(time_);//上班1打卡时间
															 pcd.setSbdk2jg(sbdk2jg);
															 
															 pcd.setYzcdcs(yzcdcs);
															 pcd.setYzcdsc(Double.valueOf(yzcdsc));
															 pcd.setKgcdfzs(kgcdcs);
															 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
													     }else if(atttype == 4){//下班2
															 pcd.setId(dkmc.getId());
													    	 pcd.setXbdk2(time_);//下班1打卡时间
															 if(punchcardtime != 0){//有应打卡时间时
																 Long time = (time_ - punchcardtime)/1000/60;
																 if(time > 0){
																	 pcd.setXbdk2jg(0);// 打卡结果
																 }else{
																	 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
																 }
															 }
															//班次为4次时,计算工作时长
															 if(dkmc.getSbdk2() != null){
																 Long time = (time_ - dkmc.getSbdk2())/1000/60;
																 BigDecimal om = new BigDecimal(dkmc.getGzsc());
																 BigDecimal on = new BigDecimal(time);
																 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
																 
																 BigDecimal xx = new BigDecimal(rest_time);
																 
																 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
																 
																 pcd.setGzsc(worktime);
															 }
															 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
													     }else if(atttype == 5){//上班3
													    	 int sbdk3jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst3=0;
															 if(punchcardtime != 0){//有应打卡时间时
																 Long time = (time_ - punchcardtime)/1000/60;
																 if(time > 0){sbdk3jg = Math.abs(Integer.valueOf(time.toString()));}
															 }
															//允许迟到范围
															 if(sbdk3jg <= yxcd) {
																 sbdk3jg = 0;
lal committed
843 844
															 }
															 
ilal committed
845 846 847 848 849 850 851 852 853 854 855 856
															 //严重迟到范围
															 if(sbdk3jg>yzcd && sbdk3jg < kgcdfzs && yzcd>0) {
																 yzcdcs = dkmc.getYzcdcs()+1;
																 yzcdsc = sbdk3jg;
																 dkst3 = 1;
															 }
															 //旷工迟到
															 if(sbdk3jg>kgcdfzs && kgcdfzs>0) {
																 kgcdcs++;
																 kgcdcs = kgcdcs + dkmc.getKgcdfzs();
																 dkst3 = 2;
															 }
lal committed
857
															 
ilal committed
858
															 pcd.setDkst3(dkst3);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
lal committed
859
															 
ilal committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
															 pcd.setId(dkmc.getId());
													    	 pcd.setSbdk3(time_);//上班1打卡时间
															 pcd.setSbdk3jg(sbdk3jg);
															 pcd.setYzcdcs(yzcdcs);
															 pcd.setYzcdsc(Double.valueOf(yzcdsc));
															 pcd.setKgcdfzs(kgcdcs);
															 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
													     }else if(atttype == 6){//下班3
															 pcd.setId(dkmc.getId());
													    	 pcd.setXbdk3(time_);//下班1打卡时间
															 if(punchcardtime != 0){//有应打卡时间时
																 Long time = (time_ - punchcardtime)/1000/60;
																 if(time > 0){
																	 pcd.setXbdk3jg(0);// 打卡结果
																 }else{
																	 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
																 }
															 }
															//班次为6次时,计算工作时长
															 if(dkmc.getSbdk3() != null){
																 Long time = (time_ - dkmc.getSbdk3())/1000/60;
																 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
																 BigDecimal on = new BigDecimal(time);
																 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
																 
																 BigDecimal xx = new BigDecimal(rest_time);
																 
																 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
																 
																 pcd.setGzsc(worktime);
															 }
													     }
														 pcd.setId(dkmc.getId());
														 if(atttype <= 6 && atttype > 0 && !sbdkkd){
															 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
lal committed
895
														 }
lal committed
896
													 }
ilal committed
897 898 899 900
												 }else {
													 msg = "当前打卡时间不在范围内";
													 sbyf = 0;
													 status_ = 2;
lal committed
901
												 }
ilal committed
902 903 904 905 906
										 }else {
											 msg = "当前时间必须大于上班打卡时间 才能打下班卡";
											 sbyf = 0;
											 status_ = 2;
										 }
lal committed
907 908 909
									 }else {
										 msg = "当前是休息时间";
										 sbyf = 0;
lal committed
910
										 status_ = 2;
lal committed
911 912 913
									 }
								}
							}
lal committed
914 915 916 917 918 919 920 921
					}else {
						//自由工时打卡
						Long stapclotime = attdate.getStapclotime();// 今天考勤 自由排班开始时间
						int canpunchworkdate = Integer.valueOf(String.valueOf(attdate.getCanpunchworkdate()).replaceAll("(\\d+)(?:(\\.\\d*[^0])|\\.)0*", "$1$2"));// 上班打卡后多久大下班卡
						KqglAssoDkmx zydkmc = KqglAssoDkmx.builder().build();
						Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(stapclotime)));//应打卡时间   2020-06-10 18:30:00
						Date sd2=df1.parse(current_time);//当前时间  2020-06-10 16:06:58
						if(sd1.after(sd2)) {//为true时  打的是昨天的卡
ilal committed
922
							zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
lal committed
923 924 925 926
									.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
							attendance_date = startDateyesterday;
							toweek = yesterday;
						}else {
ilal committed
927
							zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
lal committed
928 929 930
									.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate));
							attendance_date = startDate;
							toweek = putime;
lal committed
931 932 933 934 935 936 937 938 939 940 941
						}  
						if(zydkmc == null) {//新增
							KqglAssoDkmx pcd  = KqglAssoDkmx.builder().build();
							if(sd1.after(sd2)) {
								pcd = KqglAssoDkmx.builder().userid(userid).data(yesterday).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDateyesterday).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
							}else {
								pcd = KqglAssoDkmx.builder().userid(userid).data(putime).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDate).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
							}
//							KqglAssoDkmx pcd = KqglAssoDkmx.builder().userid(userid).data(putime).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDate).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
							 if (!pcd.insert()) {
								throw new CustomException("打卡明细-新增异常-1");
ilal committed
942
							 }
lal committed
943 944 945
							 dkmx = pcd.getId();
							 atttype = 1;
						}else {//修改	
ilal committed
946
							boolean zydk = true;
lal committed
947 948 949 950 951 952 953 954 955
							dkmx = zydkmc.getId();
							KqglAssoDkmx zypcd = KqglAssoDkmx.builder().build();
							if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() == null)){//下班1
								String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk1())),canpunchworkdate,5,2);
								Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
								Date zysd2=df1.parse(current_time);//当前时间  
								if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
									msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
									sbyf = 0;
ilal committed
956 957
									zydk = false;
									atttype = 0;
lal committed
958
									status_ = 2;
lal committed
959 960 961 962 963 964
								}else {
									zypcd.setId(zydkmc.getId());
									zypcd.setXbdk1(time_);//下班1打卡时间
									if(zydkmc.getSbdk1() != null){
										Long time = (time_ - zydkmc.getSbdk1())/1000/60;
										zypcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
lal committed
965
									 }
lal committed
966 967
									kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
ilal committed
968 969 970
								if(zydk) {
									atttype = 2;
								}
lal committed
971 972 973 974 975 976 977 978 979 980 981 982 983 984
							}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
						    		 && (("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() == null)){//上班2
								zypcd.setId(zydkmc.getId());
								zypcd.setSbdk2(time_);//上班1打卡时间
								kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								atttype = 3;
							}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
						    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() == null)){//下班2
								String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk2())),canpunchworkdate,5,2);
								Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
								Date zysd2=df1.parse(current_time);//当前时间  
								if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
									msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
									sbyf = 0;
ilal committed
985 986
									zydk = false;
									atttype = 0;
lal committed
987
									status_ = 2;
lal committed
988 989 990 991 992 993 994 995 996 997
								}else {
									zypcd.setId(zydkmc.getId());
									zypcd.setXbdk2(time_);//下班1打卡时间
									//班次为4次时,计算工作时长
									 if(zydkmc.getSbdk2() != null){
										 Long time = (time_ - zydkmc.getSbdk2())/1000/60;
										 BigDecimal om = new BigDecimal(zydkmc.getGzsc());
										 BigDecimal on = new BigDecimal(time);
										 double worktime = Math.abs(om.add(on).doubleValue());
										 zypcd.setGzsc(worktime);
lal committed
998
									 }
lal committed
999 1000
									 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
ilal committed
1001 1002 1003
								if(zydk) {
									atttype = 4;
								}
lal committed
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
							}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
						    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
						    		 && (("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() == null)){//上班3
								zypcd.setId(zydkmc.getId());
								zypcd.setSbdk3(time_);//上班1打卡时间
								kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								atttype = 5;
							}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
						    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
						    		 && (!("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() != null) && (("").equals(zydkmc.getXbdk3()) || zydkmc.getXbdk3() == null)){//下班3
								String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk3())),canpunchworkdate,5,2);
								Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
								Date zysd2=df1.parse(current_time);//当前时间  
								if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
									msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
									sbyf = 0;
ilal committed
1020 1021
									zydk = false;
									atttype = 0;
lal committed
1022
									status_ = 2;
lal committed
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
								}else {
									zypcd.setId(zydkmc.getId());
									zypcd.setXbdk3(time_);//下班1打卡时间
									//班次为6次时,计算工作时长
									 if(zydkmc.getSbdk3() != null){
										 Long time = (time_ - zydkmc.getSbdk3())/1000/60;
										 BigDecimal om = new BigDecimal(zydkmc.getGzsc());//第二次
										 BigDecimal on = new BigDecimal(time);
										 double worktime = Math.abs(om.add(on).doubleValue());
										 zypcd.setGzsc(worktime);
lal committed
1033
									 }
lal committed
1034 1035
									 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
ilal committed
1036 1037 1038
								if(zydk) {
									atttype = 6;
								}
lal committed
1039 1040 1041 1042 1043
							}else {
								atttype = 7;
							}
						}
					}
lal committed
1044
				}else {
lal committed
1045
					msg = "未检测到考勤机";
lal committed
1046
					sbyf = 0;
lal committed
1047
					status_ = 2;
lal committed
1048
				}
lal committed
1049
				
lal committed
1050 1051 1052 1053
/*****************************************************************************************************************************************************************************************************/
/*******************************************************************原始打卡记录数据录入**************************************************************************************************************/
/*****************************************************************************************************************************************************************************************************/
				
lal committed
1054 1055 1056
				String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(attendance_date));//转换打卡时间格式
				
				//true:确认为最后一次打卡更新打卡时  之前打卡的一条数据变为“打卡更新数据”
lal committed
1057
				if(kskd && (atttype == 2 || atttype == 4 || atttype == 6) && attdate.getAttgrouptype() != 3) {
lal committed
1058 1059 1060 1061
					KqglAssoDkjl dkjj = KqglAssoDkjl.builder().build().selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getUserId, userid).eq(KqglAssoDkjl::getType, 2)
							.eq(KqglAssoDkjl::getSort, atttype).eq(KqglAssoDkjl::getQyid, qyid).eq(KqglAssoDkjl::getAttdate, attdate_+" "+ClockInTool.dateToWeek2(toweek)));
					
					KqglAssoDkjl.builder().id(dkjj.getId()).status(0).sort(0).build().updateById();
lal committed
1062 1063
					msg = "打卡已更新数据";
					sbyf = 0;
ilal committed
1064
//					status_ = 2;
lal committed
1065
				}
lal committed
1066
					
ilal committed
1067 1068 1069 1070 1071
					int results = 0;
					Long time = (time_ - punchcardtime)/1000/60;
					if(punchcardtime != 0){
						if(isRange) {
							if((atttype)%2 > 0){//上班
lal committed
1072 1073 1074
								if(time > 0){
									results = Integer.valueOf(time.toString());
								}// 打卡结果
ilal committed
1075
							}else{//下班
lal committed
1076 1077 1078
								if(time > 0){}else{
									results = Math.abs(Integer.valueOf(time.toString()));
								}// 打卡结果
ilal committed
1079 1080 1081
							}
						}
					}
lal committed
1082
					int type = 0,status = 0;
ilal committed
1083
					if(atttype > 0) {
lal committed
1084 1085 1086 1087 1088 1089 1090
						if((atttype)%2 > 0){
							type = 1;// 类型(类型 0:无排班打卡 1:上班 2:下班)   punchcardtime == 0:无班次打卡
							if(attdate.getAttgrouptype() != 3) {
								if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
									if(punchcardtime == 0 && clockt.getShifid() != 0){
										status = 1;
									}if(punchcardtime == 0 && clockt.getShifid() == 0) {
lal committed
1091
										status = 2;
lal committed
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
									}else{
										if(isRange) {// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											if(time > 0){
												status = 3;
											}else if(results == 0){
												status = 1;
											}
										}else {
											status = 2;
										}
lal committed
1102
									}
lal committed
1103 1104
								}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
									status = 2;
lal committed
1105 1106
								}
							}else {
lal committed
1107
								if(sbyf == 1) {
lal committed
1108
									status = 1;
lal committed
1109
								}else {
lal committed
1110
									status = 2;
lal committed
1111 1112 1113 1114 1115 1116 1117 1118 1119
								}
							}
						}else{
							type = 2;// 类型(类型 0:无排班打卡 1:上班 2:下班)
							if(attdate.getAttgrouptype() != 3) {
								if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
									if(punchcardtime == 0 && clockt.getShifid() != 0){
										status = 1;
									}if(punchcardtime == 0 && clockt.getShifid() == 0) {
lal committed
1120
										status = 2;
lal committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
									}else{
										if(isRange) {
											if(time < 0){
												status = 4;
											}else if(results == 0){
												status = 1;
											}
										}else {
											status = 2;
										}
lal committed
1131
									}
lal committed
1132 1133
								}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
									status = 2;
lal committed
1134 1135
								}
							}else {
lal committed
1136 1137 1138 1139 1140
								if(sbyf == 1) {
									status = 1;
								}else {
									status = 2;
								}
lal committed
1141
							}
ilal committed
1142 1143
						}
					}
lal committed
1144
					
lal committed
1145 1146
					//第二次未超过应上班打卡时间 打卡为无效
					if(sbdkkd) {
lal committed
1147
						sbyf = 0;
lal committed
1148
						status = 2;
lal committed
1149
						atttype = 0;
lal committed
1150
						msg = "已有最优的打卡记录存在";
lal committed
1151
					}
lal committed
1152
					
ilal committed
1153
					long attime;
lal committed
1154 1155 1156 1157 1158
					if(punchcardtime == 0){// 考勤时间(应打卡时间)
						attime = new Date().getTime();
					}else{
						attime = punchcardtime;
					}
ilal committed
1159
					String remarks = "";
lal committed
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
					if(("1").equals(asVerifyMode)) {
						remarks = "考勤机指纹打卡";
					}else if(("20").equals(asVerifyMode)) {
						remarks = "考勤机人脸打卡";
					}else if(("40").equals(asVerifyMode)) {
						remarks = "考勤机掌纹打卡";
					}else if(("60").equals(asVerifyMode)) {
						remarks = "考勤机密码打卡";
					}
					String commentary = "未知";
					if(sbyf == 1) {
						commentary = "打卡成功";
					}else {
						commentary = msg;
lal committed
1174 1175 1176
						if(status_ == 2) {
							status = status_;
						}
lal committed
1177
					}
ilal committed
1178 1179
					
					
ilal committed
1180 1181
					//cardtype--1:GPS,2:WIFI,3:考勤机
					KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(time_).results(results).userId(userid).type(type).status(status).sort(atttype)
lal committed
1182
							.cardType(3).qyid(qyid).attdate(attdate_+" "+ClockInTool.dateToWeek2(toweek)).attime(attime).dkmxid(dkmx).bcid(shifid).remarks(remarks).punchmode(Integer.valueOf(asVerifyMode))
lal committed
1183
							.punchequipment(asDevId).commentary(commentary).build();
ilal committed
1184 1185 1186 1187
					
					if (!pre.insert()) {
						throw new CustomException("打卡记录-新增异常-2");
					 }
lal committed
1188 1189 1190
				}else {
					msg="打卡失败!,未加入考勤组!";
					sbyf = 0;
ilal committed
1191 1192 1193 1194
				}
		}else {
			return ResultUtil.error("打卡失败!,用户不存在!");
		}
lal committed
1195 1196 1197 1198 1199 1200
		
		if(sbyf == 1) {
			return  ResultUtil.data(null, "打卡成功");
		}else {
			return  ResultUtil.data(msg, "打卡失败");
		}
ilal committed
1201 1202 1203 1204
	}
	
	@Autowired
	private KqglAssoPbmxMapper kqglassopbmxmapper;
lal committed
1205 1206 1207 1208 1209 1210 1211
	/**
	 * @param qyid 
	 * @param userid
	 * @param date
	 * @return
	 *	获取当天打卡班次数据
	 */
ilal committed
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
	public AttendanceCardListDto MethodCall(int qyid,int userid,String date) throws ParseException {
		 
		AttendanceCardListDto attcar = new AttendanceCardListDto();
		 String str = null;
		 if(!("").equals(date)){
			 str = date;
		 }else{
			 Date d = new Date();
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 str = sdf.format(d);
		 }
	     KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
	     //pbfs:排班方式 1:固定排班;2:自由排班;3:自由工时
		 if(attgro != null){//判断当前用户是否加入到考勤组
			 //排班制
			 KqglAssoPbmxDto jrpb = kqglassopbmxmapper.getScheduleSpecificAttendance(attgro.getId(),userid,str);
		     //固定排班
		     int week = Integer.valueOf(ClockInTool.dateToWeek(str));//4
		     KqglAssoZhoupaiban atwek = KqglAssoZhoupaiban.builder().build().selectOne(new QueryWrapper<KqglAssoZhoupaiban>().lambda().eq(KqglAssoZhoupaiban::getKqzid, attgro.getId())
		    		 .eq(KqglAssoZhoupaiban::getType, week).ne(KqglAssoZhoupaiban::getBcid, 0));
		    if(attgro.getPbfs() == 1){//固定排班
		    	if(atwek != null){//有固定周排班
		    		KqglAssoTeshu rest = KqglAssoTeshu.builder().build().selectOne(new QueryWrapper<KqglAssoTeshu>().lambda().eq(KqglAssoTeshu::getKqzid, attgro.getId())
		    				.eq(KqglAssoTeshu::getTsrq, str).eq(KqglAssoTeshu::getBcid, 0));
		    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
		    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    		AttSchedule as = AttSchedule.builder().id(0).sort(0).time(0l).starttime(0l).endtime(0l).build();
			    		atts.add(as);
			    		attcar.setAttsch(atts);
		    		}else{//今天上班
			    		KqglAssoBcsz bcz = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, atwek.getBcid()));
			    		
			    		if(bcz != null){
			    			Getshiftinformationbatch(bcz,attcar,str);
			    		}
		    		}
		    	}else{//必须打卡
		    		KqglAssoTeshu tsri = KqglAssoTeshu.builder().build().selectOne(new QueryWrapper<KqglAssoTeshu>().lambda().eq(KqglAssoTeshu::getKqzid, attgro.getId())
		    				.eq(KqglAssoTeshu::getTsrq, str).ne(KqglAssoTeshu::getBcid, 0));
		    		if(tsri != null){
		    			KqglAssoBcsz tsrq = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, tsri.getBcid()));
		    			if(tsrq!=null){
		    				Getshiftinformationbatch(tsrq,attcar,str);
		    			}
		    		}else{//休息
		    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    		AttSchedule as = AttSchedule.builder().id(0).sort(0).time(0l).starttime(0l).endtime(0l).build();
			    		atts.add(as);
			    		attcar.setAttsch(atts);
		    		}
		    	}
			}else if(attgro.getPbfs() == 2){//自由排班
				//未排班时,员工可选择班次打卡
lal committed
1265 1266 1267 1268 1269
//			    if(attgro.getIsXzbcdk() == 1){
//			    	attcar.setOptscheduling(true);	
//			    }else{
//			    	attcar.setOptscheduling(false);
//			    }
ilal committed
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
				if(jrpb != null){
					if(jrpb.getBcid() != 0){//有班次时("Bcid"不为0时)
						KqglAssoBcsz tsrq = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, jrpb.getBcid()));
						/**已简化**/
						Getshiftinformationbatch(tsrq,attcar,str);
					}else{//当天排班为休息
						List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
			    		AttSchedule as = AttSchedule.builder().id(0).sort(0).time(0l).starttime(0l).endtime(0l).build();
			    		atts1.add(as);
			    		attcar.setAttsch(atts1);
					}
				}
			}else{//自由工时
				KqglAssoZhoupaiban wekz = KqglAssoZhoupaiban.builder().build().selectOne(new QueryWrapper<KqglAssoZhoupaiban>().lambda().eq(KqglAssoZhoupaiban::getKqzid, attgro.getId())
						.eq(KqglAssoZhoupaiban::getBcid, 0).eq(KqglAssoZhoupaiban::getType, week));
				if(wekz != null){//
					String dada = str+" "+attgro.getKqkssjTime()+":00";
					attcar.setStapclotime(Long.valueOf(ClockInTool.dateToStamp(dada)));
				}
				
				if(!("").equals(attgro.getJbzdsc())){
					attcar.setCanpunchworkdate(Double.valueOf(attgro.getJbzdsc()));//上班打卡后多久大下班卡
				}
			}
		    if(jrpb != null || atwek != null){
		    	KqglAssoBcsz shif = KqglAssoBcsz.builder().build();
		    	if(attgro.getPbfs() == 1){
		    		shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, atwek.getBcid()));
		    	}else if(attgro.getPbfs() == 2){
		    		shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, jrpb.getBcid()));
		    	}
		    	
		    	if(shif != null){
		    		if(shif.getIsXbdk() == 1){
		    			attcar.setNoclockout(true);// 下班不用打卡
		    		}else{
		    			attcar.setNoclockout(false);// 下班不用打卡
		    		}
		    		attcar.setAllowlate(shif.getYxcdfzs());// 允许迟到分钟数
		    		attcar.setSeriouslate(shif.getYzcdfzs());// 严重迟到分钟数
		    		attcar.setAbsenteeismlate(shif.getKgcdfzs());// 旷工迟到分钟数
		    		if(shif.getIsWzwd() == 1){
		    			attcar.setIslatelate(true);// 晚走晚到
		    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
		    			int p = 0;
		    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1())){p = 2;}
		    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2())){p = 4;}
		    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2()) && !("").equals(shif.getXbwz3()) && !("").equals(shif.getSbwd3())){p = 6;}
		    			AttLateLate ala = AttLateLate.builder().build();
		    			ala.setLatewalk(shif.getXbwz1());
		    			ala.setArrivelate(shif.getSbwd1());
		    			atwzwd.add(ala);
		    			if(p == 4 || p == 6){
		    				AttLateLate alat = AttLateLate.builder().build();
		    				alat.setLatewalk(shif.getXbwz2());
		    				alat.setArrivelate(shif.getSbwd2());
		    				atwzwd.add(alat);
		    			}
		    			if(p == 6){
		    				AttLateLate alas = AttLateLate.builder().build();
		    				alas.setLatewalk(shif.getXbwz3());
		    				alas.setArrivelate(shif.getSbwd3());
		    				atwzwd.add(alas);
		    			}
		    			attcar.setAttlat(atwzwd);
		    		}else{
		    			attcar.setIslatelate(false);// 晚走晚到
		    		}
		    	}
		    }
		    attcar.setAttgrouptype(attgro.getPbfs());//1:固定排班;2:自由排班;3:自由工时
		 }else{
			 attcar.setAttgrouptype(0);//1:固定排班;2:自由排班;3:自由工时
		 }
lal committed
1344 1345 1346
		 
		 
		 
ilal committed
1347 1348 1349
		 return attcar;
	 }
	
lal committed
1350 1351 1352 1353 1354
	/**
	 * @param shiftm
	 * @param attcar
	 * @param str
	 */
ilal committed
1355
	public void Getshiftinformationbatch(KqglAssoBcsz shiftm,AttendanceCardListDto attcar,String str){
lal committed
1356 1357 1358 1359 1360 1361 1362
		int isXbdk1Cr = shiftm.getIsXbdk1Cr();//下班1是否次日(0:否;1:是)
		int isSbdk2Cr = shiftm.getIsSbdk2Cr();//上班2是否次日(0:否;1:是)
		int isXbdk2Cr = shiftm.getIsXbdk2Cr();//下班2是否次日(0:否;1:是)
		int isSbdk3Cr = shiftm.getIsSbdk3Cr();//上班3是否次日(0:否;1:是)
		int isXbdk3Cr = shiftm.getIsXbdk3Cr();//下班3是否次日(0:否;1:是)
		
		//次日专用
lal committed
1363
		String next_day = ClockInTool.requires_extra_times(str,1,2,1);
lal committed
1364
		
ilal committed
1365 1366 1367 1368
		 List<AttSchedule> atts = new ArrayList<AttSchedule>();
	    	if(shiftm.getSxbcs() == 1 || shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//1次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
lal committed
1369
			    		AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(1).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbdk1()+":00").replaceAll("\r|\n", ""))))
lal committed
1370
			    				.starttime(("").equals(shiftm.getSbqjks1()) || shiftm.getSbqjks1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjks1()+":00").replaceAll("\r|\n", ""))))
lal committed
1371 1372
			    				.endtime(("").equals(shiftm.getSbqjjs1()) || shiftm.getSbqjjs1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjjs1()+":00").replaceAll("\r|\n", ""))))
			    				.nextday(0).build();
ilal committed
1373 1374 1375
			    		
			    		atts.add(as);
	    			}else{
lal committed
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
	    				//次日
	    				if(isXbdk1Cr > 0) {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(2).time(Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbdk1()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks1()) || shiftm.getXbqjks1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjks1()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs1()) || shiftm.getXbqjjs1() ==null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjjs1()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(1).build();
				    		atts.add(as);
	    				}else {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(2).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbdk1()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks1()) || shiftm.getXbqjks1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjks1()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs1()) || shiftm.getXbqjjs1() ==null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjjs1()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(0).build();
				    		atts.add(as);
	    				}
			    		
ilal committed
1391 1392 1393 1394 1395 1396 1397
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//2次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
lal committed
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
	    				if(isSbdk2Cr > 0) {//次日
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(3).time(Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbdk2()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getSbqjks2())|| shiftm.getSbqjks2()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbqjks2()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getSbqjjs2()) || shiftm.getSbqjjs2()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbqjjs2()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(1).build();
				    		atts.add(as);
	    				}else {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(3).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbdk2()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getSbqjks2())|| shiftm.getSbqjks2()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjks2()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getSbqjjs2()) || shiftm.getSbqjjs2()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjjs2()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(0).build();
				    		atts.add(as);
	    				}
			    		
ilal committed
1412
	    			}else{
lal committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
	    				if(isXbdk2Cr > 0) {//次日
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(4).time(Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbdk2()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks2()) || shiftm.getXbqjks2()== null? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjks2()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs2()) || shiftm.getXbqjjs2()== null? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjjs2()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(1).build();
				    		atts.add(as);
	    				}else {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(4).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbdk2()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks2()) || shiftm.getXbqjks2()== null? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjks2()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs2()) || shiftm.getXbqjjs2()== null? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjjs2()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(0).build();
				    		atts.add(as);
	    				}
			    		
ilal committed
1427 1428 1429 1430 1431 1432 1433
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
lal committed
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
	    				if(isSbdk3Cr > 0) {//次日
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(5).time(Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbdk3()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getSbqjks3()) || shiftm.getSbqjks3() == null? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbqjks3()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getSbqjjs3()) || shiftm.getSbqjjs3() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getSbqjjs3()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(1).build();
				    		atts.add(as);
	    				}else {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(5).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbdk3()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getSbqjks3()) || shiftm.getSbqjks3() == null? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjks3()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getSbqjjs3()) || shiftm.getSbqjjs3() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjjs3()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(0).build();
				    		atts.add(as);
	    				}
			    		
ilal committed
1448
	    			}else{
lal committed
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
	    				if(isXbdk3Cr > 0) {//次日
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(6).time(Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbdk3()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks3()) || shiftm.getXbqjks3()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjks3()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs3()) || shiftm.getXbqjjs3() ==null? 0 : Long.valueOf(ClockInTool.dateToStamp((next_day+" "+shiftm.getXbqjjs3()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(1).build();
				    		atts.add(as);
	    				}else {
	    					AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(6).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbdk3()+":00").replaceAll("\r|\n", ""))))
				    				.starttime(("").equals(shiftm.getXbqjks3()) || shiftm.getXbqjks3()== null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjks3()+":00").replaceAll("\r|\n", ""))))
				    				.endtime(("").equals(shiftm.getXbqjjs3()) || shiftm.getXbqjjs3() ==null? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getXbqjjs3()+":00").replaceAll("\r|\n", ""))))
				    				.nextday(0).build();
				    		atts.add(as);
	    				}
			    		
ilal committed
1463 1464 1465 1466 1467
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
lal committed
1468 1469 1470 1471 1472 1473 1474 1475 1476
	
	
	
	/************************************************************************************************************************************************************************************************/
	/**************************************************************************	APP打卡	*************************************************************************************************************/
	/************************************************************************************************************************************************************************************************/
	
	/**
	  * 	考勤打卡------APP打卡
lal committed
1477
	 * @throws ParseException 
lal committed
1478 1479 1480
	  */
	 @PostMapping(value = "/AttendanceCard")
	 @ApiOperation(value = "考勤打卡------APP打卡", httpMethod = "POST", notes = "接口发布说明")
lal committed
1481
	 @ApiOperationSupport(order = 2)
lal committed
1482 1483 1484 1485 1486 1487
	 public Result<Object> AttendanceCard(@CurrentUser UserBean userBean,@RequestBody ClockCollectData clock) throws ParseException {
		 //当前时间
		 String current_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		 String current = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		 //当前用户打卡时间
		 String sStdIoTime = clock.getPunchtime();
lal committed
1488
		 
lal committed
1489 1490 1491 1492
		 //基于当前的前一天时间   和当天开始与结束时间戳
		 String yesterday = ClockInTool.requires_extra_times(current,-1,3,1);
		 Long startDateyesterday = DateUtil.getStartTime(0,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
		 Long endDateyesterday = DateUtil.getnowEndTime(23,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
lal committed
1493
		 
lal committed
1494 1495
		 Long attendance_date = 0l;//考勤日期
		 String toweek = "";
lal committed
1496
		 
lal committed
1497 1498
		 String msg = "未知错误,请联系管理员";
		 int sbyf = 1;//0:失败;1:成功
ilal committed
1499
		 int status_ = 0;
lal committed
1500
		 
ilal committed
1501 1502
		 int xiuxidaka = 0;//休息并打卡
		 
lal committed
1503 1504 1505 1506
		 YgglMainEmp user = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, clock.getUserid()).eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()));
		 if(user != null) {
			 int qyid = user.getOrgCode();
			 int userid = user.getEmpNum();	 
lal committed
1507
				 
lal committed
1508 1509 1510 1511 1512
//		     AttendanceGroup attgro = attendancegroupmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		     KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
//			 pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
			 
		     long time_ = DateUtil.getStringTime(clock.getPunchtime(), "yyyy-MM-dd HH:mm:ss");//打卡时间戳
lal committed
1513
				
ilal committed
1514
			 String putime = sStdIoTime.substring(0, 10);////转换打卡时间格式 yyyy-MM-dd
ilal committed
1515
			
ilal committed
1516
			 String putimehhmm = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_);//转换打卡时间格式 年月日
lal committed
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
		     
			 Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();//打卡当天开始时间
		     Long endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();//打卡当天结束时间
			 
		     int dkmx = 0;//打卡明细id
		     int atttype = 0;//打卡顺序
		     int shifid = 0;//班次id
		     boolean isRange = true;//是否在打卡时间范围内
		     int execution_status = 0;//执行状态
		     boolean kskd = true;//识别是否更新最后一次打卡   针对于最后一次下班卡
			 boolean sbdkkd = false;//针对于上班  未超过上班卡打卡  视为无效打卡
			 long punchcardtime = 0,punchstart = 0,punchend = 0;//应打卡时间,应打卡开始时间,应打卡结束时间
		     
ilal committed
1530 1531
			 boolean chenexday = false;
			 
lal committed
1532 1533 1534 1535 1536 1537
		     ClockCollectData clockt = new ClockCollectData();
//			 putime: 根据日期  得到打卡所需的详细信息
			 AttendanceCardListDto attdate = MethodCall(qyid,userid,putime);
			 if(attgro != null) {//判断考勤组是否存在
				 
				 if(attdate.getAttgrouptype() != 3) {
ilal committed
1538 1539
					 
					 List<AttSchedule> checknextday = attdate.getAttsch();
ilal committed
1540 1541 1542 1543 1544 1545 1546 1547
					 
					 if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && checknextday.get(0).getId() != 0) {
					 
						 if(checknextday.size() > 0) {
							 for(int c=0;c<checknextday.size();c++) {
								 if(checknextday.get(c).getNextday() == 2) {
									 chenexday = true;
								 }
ilal committed
1548 1549 1550 1551
							 }
						 }
					 }
					 
lal committed
1552 1553 1554
					KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build();
					boolean dnck = false;
					boolean crdk = false;//当次打卡是否存在次日打卡
ilal committed
1555 1556 1557 1558 1559 1560
					
					if(chenexday) {
						//查询打卡当天是否有记录**********************************
//						KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build();
						String dakariqi = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDateyesterday))+" "+ClockInTool.dateToWeek2(yesterday);
						//检查昨日的班次是否存在次日打卡
ilal committed
1561
						KqglAssoDkjl balan = kqglassodkjlmapper.selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getUserId, userid).eq(KqglAssoDkjl::getAttdate, dakariqi).eq(KqglAssoDkjl::getQyid, qyid).ne(KqglAssoDkjl::getBcid, 0).orderByDesc(KqglAssoDkjl :: getSort).last("LIMIT 1"));
ilal committed
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
//						boolean dnck = false;
//						boolean crdk = false;//当次打卡是否存在次日打卡
						if(balan != null) {//前一天是否打过卡    去班次id查询是否存在次日打卡
							//昨日的班次信息
							KqglAssoBcsz shif = kqglassobcszmapper.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, balan.getBcid()));
							int dkcs = shif.getSxbcs()*2;
							List<AttSchedule> ashss = attdate.getAttsch();//获取今天应打卡时间
							if(ashss.size() > 0) {
								Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(ashss.get(0).getTime())));//当天应打的首次上班卡时间
								Date sd2=df1.parse(current_time);//当前时间
								if(sd1.after(sd2)) {//大于
									dnck = true;
								}
lal committed
1575
							}
ilal committed
1576 1577 1578 1579 1580 1581 1582 1583 1584
							int isXbdk1Cr = shif.getIsXbdk1Cr();//下班1是否次日(0:否;1:是)
							int isSbdk2Cr = shif.getIsSbdk2Cr();//上班2是否次日(0:否;1:是)
							int isXbdk2Cr = shif.getIsXbdk2Cr();//下班2是否次日(0:否;1:是)
							int isSbdk3Cr = shif.getIsSbdk3Cr();//上班3是否次日(0:否;1:是)
							int isXbdk3Cr = shif.getIsXbdk3Cr();//下班3是否次日(0:否;1:是)
							if(balan.getSort() <= dkcs) {
								if((isXbdk1Cr + isSbdk2Cr +isXbdk2Cr +  isSbdk3Cr + isXbdk3Cr) > 0) {
									crdk = true;
								}
lal committed
1585
							}
ilal committed
1586 1587
						}else {
							List<AttSchedule> ashss = attdate.getAttsch();//获取今天应打卡时间
ilal committed
1588
							
ilal committed
1589 1590 1591 1592 1593 1594 1595 1596 1597
							//无记录的话就找昨天的数据
							AttendanceCardListDto attdate1 = MethodCall(qyid,userid,yesterday);
							List<AttSchedule> ashssyebo = attdate1.getAttsch();//获取昨天应打卡时间
							if(ashssyebo.size() > 0) {
								Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(ashssyebo.get(0).getTime())));//当天应打的首次上班卡时间
								Date sd2=df1.parse(current_time);//当前时间
								if(sd2.after(sd1)) {//大于
									dnck = true;
								}
ilal committed
1598
							}
ilal committed
1599
							
ilal committed
1600 1601 1602 1603 1604 1605 1606
							if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && ashss.get(0).getId() != 0) {//班次不为空
								KqglAssoBcsz shifi = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ashss.get(0).getId()));
								int isXbdk1Cr = shifi.getIsXbdk1Cr();//下班1是否次日(0:否;1:是)
								int isSbdk2Cr = shifi.getIsSbdk2Cr();//上班2是否次日(0:否;1:是)
								int isXbdk2Cr = shifi.getIsXbdk2Cr();//下班2是否次日(0:否;1:是)
								int isSbdk3Cr = shifi.getIsSbdk3Cr();//上班3是否次日(0:否;1:是)
								int isXbdk3Cr = shifi.getIsXbdk3Cr();//下班3是否次日(0:否;1:是)
ilal committed
1607
								
ilal committed
1608 1609 1610 1611 1612 1613 1614 1615
								if((isXbdk1Cr + isSbdk2Cr +isXbdk2Cr +  isSbdk3Cr + isXbdk3Cr) > 0) {
									crdk = true;
									
									attdate = MethodCall(qyid,userid,yesterday);
									
								}else {
									crdk = false;
								}
ilal committed
1616 1617
							}
						}
lal committed
1618
					}
ilal committed
1619
					
lal committed
1620
					if(crdk && dnck) {
ilal committed
1621
						dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
1622
								.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday).eq(KqglAssoDkmx::getData, yesterday));
lal committed
1623 1624 1625
						attdate = MethodCall(qyid,userid,yesterday);
						attendance_date = startDateyesterday;
						toweek = yesterday;
ilal committed
1626
						putime = toweek;
lal committed
1627
					}else {
ilal committed
1628
						dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
1629
								.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate).eq(KqglAssoDkmx::getData, putime));
lal committed
1630 1631 1632 1633 1634 1635 1636
						attendance_date = startDate;
						toweek = putime;
					}
					
					if(EmptyUtil.isEmpty(attdate.getAttsch())) {
						msg = "当前未排班";
						sbyf = 0;
ilal committed
1637
						status_ = 2;
lal committed
1638 1639
					}else {
						
ilal committed
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
						//排查请假是否在最后一次打卡范围内  查询当月的请假所有日期
						KqglAssoRelationSummary leainv = kqglassorelationsummarymapper.leaveinvesti(userid, 2, putime,qyid);
						boolean adopt = false;
						if(leainv != null) {
							adopt = ClockInTool.hourMinuteBetween(putimehhmm, leainv.getStartTime().substring(0, 16), leainv.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
						}
						
						if(adopt) {
							msg = "已请假";
							sbyf = 0;
							status_ = 2;
						}else {
							long starttime1 = 0,starttime1ks = 0,starttime1js = 0,endtime1 = 0,endtime1ks = 0,endtime1js = 0,starttime2 = 0,starttime2ks = 0,starttime2js = 0,endtime2 = 0,endtime2ks = 0,endtime2js = 0,starttime3 = 0,starttime3ks = 0,starttime3js = 0,
									endtime3 = 0,endtime3ks = 0,endtime3js = 0; 
ilal committed
1654
							List<AttSchedule> ash =null;
ilal committed
1655
							if(attdate.getAttsch().size() > 0) {
ilal committed
1656
								 ash = attdate.getAttsch();
ilal committed
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
								 int y = 0;
								 clockt.setShifid(ash.get(y).getId());
								 shifid = ash.get(y).getId();//班次id
								 if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
									 starttime1 = ash.get(0).getTime();starttime1ks = ash.get(0).getStarttime();starttime1js = ash.get(0).getEndtime();
									 endtime1 = ash.get(1).getTime();endtime1ks = ash.get(1).getStarttime();endtime1js = ash.get(1).getEndtime();
								 }
							 	if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
							 		starttime2 = ash.get(2).getTime();starttime2ks = ash.get(2).getStarttime();starttime2js = ash.get(2).getEndtime();
								    endtime2 = ash.get(3).getTime();endtime2ks = ash.get(3).getStarttime();endtime2js = ash.get(3).getEndtime();
								}
							 	if(attdate.getAttsch().size() == 6) {
							 		starttime3 = ash.get(4).getTime();starttime3ks = ash.get(4).getStarttime();starttime3js = ash.get(4).getEndtime();
									endtime3 = ash.get(5).getTime();endtime3ks = ash.get(5).getStarttime();endtime3js = ash.get(5).getEndtime();
								 }
							 	
							 	if(dkmc == null) {
							 		kskd = false;
							 		if(attdate.getAttsch().size() == 2) {//一套上下班  上班1
ilal committed
1676
							 			if(clock.getType() == 1) {
ilal committed
1677 1678
							 				if(starttime1ks == 0 && starttime1js == 0) {
							 					atttype = clock.getType();
ilal committed
1679
										    	isRange = true;//在范围
ilal committed
1680 1681 1682 1683 1684 1685 1686 1687 1688
							 				}else {
								 				boolean effectiveDate1 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate1) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    }else {
											    	isRange = false;
											    }
							 				}
ilal committed
1689
							 			}else if(clock.getType() == 2){
ilal committed
1690 1691
							 				if(endtime1ks == 0 && endtime1js == 0) {
							 					atttype = clock.getType();
ilal committed
1692
										    	isRange = true;//在范围
ilal committed
1693 1694 1695 1696 1697 1698 1699 1700 1701
							 				}else {
								 				boolean effectiveDate2 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate2) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    }else {
										    		isRange = false;
											    }
							 				}
ilal committed
1702
							 			}
ilal committed
1703 1704 1705 1706 1707 1708 1709 1710 1711
							 		}else {
							 			boolean getinto = true;
							 			//打卡时间  对比班次  接近哪个时间就打哪个时间的卡
								 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
								 			//punchstart 应打卡开始时间 punchend:应打卡结束时间  time_:打卡时间
								 			if(clock.getType() == 1) {
								 				boolean effectiveDate1 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate1) {//在范围内就打卡 
											    	atttype = clock.getType();
ilal committed
1712
											    	isRange = true;//在范围
ilal committed
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}else if(clock.getType() == 2){
								 				boolean effectiveDate2 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate2) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    	
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}else if(clock.getType() == 3) {
								 				boolean effectiveDate3 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate3) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    	
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}else if(clock.getType() == 4) {
								 				boolean effectiveDate4 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate4) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    	
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}
								 		}
								 		if(attdate.getAttsch().size() == 6) {
								 			if(clock.getType() == 5) {
								 				boolean effectiveDate5 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate5) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    	
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}else if(clock.getType() == 6) {
								 				boolean effectiveDate6 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate6) {//在范围内就打卡 
											    	atttype = clock.getType();
											    	isRange = true;//在范围
											    	
											    	getinto = false;
											    }else {
											    	if(getinto) {
											    		isRange = false;
											    	}
											    }
								 			}
								 		}
							 		}
								 	 execution_status = 1;
							 	}else {
							 		boolean getinto2 = true;
							 		execution_status = 2;
							 		if(attdate.getAttsch().size() == 2) {	//下班1
							 			if(clock.getType() == 1) {
							 				if(clock.getDiffer() == 2) {//更新打卡
							 					//如果第二次后打卡,未超过上班时间  即为打卡失效
ilal committed
1793 1794 1795
//								 				Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(starttime1)));//应打卡时间
//												Date sd2=df1.parse(sStdIoTime);//打卡时间
//												if(sd1.after(sd2)) {//大于
ilal committed
1796
													sbdkkd = true;//打卡无效
ilal committed
1797 1798
													atttype = clock.getType();
//												}
ilal committed
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811
							 				}
							 			}else if(clock.getType() == 2){
							 				if(dkmc.getSbdk1() != null && dkmc.getXbdk1() == null){
							 					kskd = false;
							 					atttype = clock.getType();
							 				}else {
							 					//最后一次卡的时候 再继续打视为更新最后一次打卡
										    	kskd = true;//更新最后一次打卡
										    	atttype = clock.getType();
							 				}
							 				
							 			}
							 		}	
lal committed
1812 1813 1814 1815
							 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
							 			if(clock.getType() == 1) {
							 				boolean effectiveDate1 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js),"yyyy-MM-dd HH:mm");
										    if (effectiveDate1) {//在范围内就打卡 
ilal committed
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
										    	if(dkmc.getSbdk1() != null) {
										    		sbdkkd = true;//打卡无效
										    	}else {
										    		atttype = clock.getType();
										    		isRange = true;//在范围
											    	getinto2 = false;
										    	}
										    }else { 
										    	if(getinto2) {
										    		isRange = false; 
lal committed
1826 1827
										    	}
										    }
ilal committed
1828
							 			}else if(clock.getType() == 2) {
lal committed
1829 1830
							 				boolean effectiveDate2 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js),"yyyy-MM-dd HH:mm");
										    if (effectiveDate2) {//在范围内就打卡 
ilal committed
1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
										    	if(dkmc.getXbdk1() != null) {
										    		kskd = true;////更新最后一次打卡
										    		atttype = clock.getType();
										    		isRange = true;//在范围
											    	getinto2 = false;
										    	}else {
										    		kskd = false;//更新最后一次打卡
										    		atttype = clock.getType();
										    	}
										    }else { 
										    	if(getinto2) {
										    		isRange = false; 
lal committed
1843 1844 1845 1846 1847
										    	}
										    }
							 			}else if(clock.getType() == 3) {
							 				boolean effectiveDate3 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime2js),"yyyy-MM-dd HH:mm");
										    if (effectiveDate3) {//在范围内就打卡 
ilal committed
1848 1849 1850 1851 1852 1853
										    	if(dkmc.getSbdk2() != null) {
										    		sbdkkd = true;//打卡无效
										    	}else {
										    		atttype = clock.getType();
										    		isRange = true;//在范围
											    	getinto2 = false;
lal committed
1854
										    	}
ilal committed
1855 1856 1857
										    }else { 
										    	if(getinto2) {
										    		isRange = false; 
lal committed
1858 1859
										    	}
										    }
ilal committed
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876
							 			}else if(clock.getType() == 4) {
							 				 boolean effectiveDate4 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime2js),"yyyy-MM-dd HH:mm");
											    if (effectiveDate4) {//在范围内就打卡 
											    	if(dkmc.getXbdk2() != null) {
											    		kskd = true;////更新最后一次打卡
											    		atttype = clock.getType();
											    		isRange = true;//在范围
												    	getinto2 = false;
											    	}else {
											    		kskd = false;
											    		atttype = clock.getType();
											    	}
											    }else { 
											    	if(getinto2) {
											    		isRange = false; 
											    	}
											    }	
lal committed
1877 1878 1879 1880 1881 1882
							 			}
							 		}
							 		if(attdate.getAttsch().size() == 6) {
							 			if(clock.getType() == 5) {
							 				boolean effectiveDate5 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime3js),"yyyy-MM-dd HH:mm");
										    if (effectiveDate5) {//在范围内就打卡 
ilal committed
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
										    	if(dkmc.getSbdk2() != null) {
										    		sbdkkd = true;//打卡无效
										    	}else {
										    		atttype = clock.getType();
										    		isRange = true;//在范围
											    	getinto2 = false;
										    	}
										    }else { 
										    	if(getinto2) {
										    		isRange = false; 
lal committed
1893 1894 1895 1896 1897 1898
										    	}
										    }
							 			}else if(clock.getType() == 6) {
							 				boolean effectiveDate6 = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3ks), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime3js),"yyyy-MM-dd HH:mm");
										    if (effectiveDate6) {//在范围内就打卡 
										    	if(dkmc.getXbdk2() != null) {
ilal committed
1899
										    		kskd = true;//更新最后一次打卡
lal committed
1900 1901 1902
										    		atttype = clock.getType();
										    		isRange = true;//在范围
											    	getinto2 = false;
lal committed
1903 1904
										    	}else {
										    		kskd = false;
ilal committed
1905
										    		atttype = clock.getType();
lal committed
1906 1907
										    	}
										    }else { 
lal committed
1908 1909 1910
										    	if(getinto2) {
										    		isRange = false; 
										    	}
lal committed
1911
										    }	
ilal committed
1912 1913 1914
							 			}
							 		}
							 	}
lal committed
1915
							 }
ilal committed
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
							if(atttype == 1) {
								punchcardtime = starttime1; punchstart = starttime1ks; punchend = starttime1js;
							}else if(atttype == 2) {
								punchcardtime = endtime1; punchstart = endtime1ks; punchend = endtime1js;
							}else if(atttype == 3) {
								punchcardtime = starttime2; punchstart = starttime2ks; punchend = starttime2js;
							}else if(atttype == 4) {
								punchcardtime = endtime2; punchstart = endtime2ks; punchend = endtime2js;
							}else if(atttype == 5) {
								punchcardtime = starttime3; punchstart = starttime3ks; punchend = starttime3js;
							}else if(atttype == 6) {
								punchcardtime = endtime3; punchstart = endtime3ks; punchend = endtime3js;
							}
							
							if(clockt.getShifid() != 0) {
ilal committed
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
								boolean dddbdk = true;//
								boolean dak2 = true;
								 //打卡无限制时  当前时间必须大于上班打卡时间 才能打下班卡
								 if(punchstart==0 && punchend==0 && (atttype == 2 || atttype == 4 || atttype == 6)) {
									 String xbdk = "";
									 if(atttype == 2) {
										 xbdk = String.valueOf(ash.get(0).getTime());
									 }else if(atttype == 4){
										 xbdk = String.valueOf(ash.get(2).getTime());
									 }else {
										 xbdk = String.valueOf(ash.get(4).getTime());
lal committed
1942
									 }
ilal committed
1943 1944 1945 1946
									 Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(xbdk)));//当天应打的首次上班卡时间
									 Date sd2=df1.parse(current_time);//当前时间
									 if(sd2.before(sd1)) {//小于
										 dak2 = false;
lal committed
1947
									 }
ilal committed
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
								 }
								 if(!dak2) { dddbdk = false; }
								 
								 if(dddbdk) {
									 KqglAssoBcsz shif = KqglAssoBcsz.builder().build();
										if(attdate.getAttsch().size() > 0 && clockt.getShifid() > 0){//有无班次
											shif = shif.selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, clockt.getShifid()));
										}
										//打卡记录录入 -- 打卡是否有时间范围限制
										 if(attdate.getAttsch().size() == 2) {
											 if(punchstart>0 && punchend>0) {
												 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchstart);//应打卡开始时间
												 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchend);//应打卡结束时间
												 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_);//打卡时间
												 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
												 if (!effectiveDate) {
			//										 System.out.println("当前打卡时间不在范围内");
													 isRange = false;
ilal committed
1966
												 }
lal committed
1967
											 }
ilal committed
1968
										 }
ilal committed
1969
										 if(isRange) {
lal committed
1970
											 
ilal committed
1971 1972 1973
											 int yxcd = shif.getYxcdfzs();//允许迟到
											 int yzcd = shif.getYzcdfzs();//严重迟到分钟数
											 int kgcdfzs  = shif.getKgcdfzs();//旷工迟到分钟数 
lal committed
1974
											 
ilal committed
1975 1976
											 int dkcs_ = shif.getSxbcs();//上下班打卡次数
											 int iswzwd = shif.getIsWzwd();//是否开启晚走晚到(0:否;1:是)
lal committed
1977
											 
ilal committed
1978 1979
											 //班次的休息时间
											 long rest_time = 0;
ilal committed
1980
											 if(shif.getStartTime() != null && !("").equals(shif.getStartTime()) && shif.getEndTime() != null && !("").equals(shif.getEndTime())) {
ilal committed
1981 1982 1983
												 long kaishixiuxi = Long.valueOf(ClockInTool.dateToStamp(putime + " " +shif.getStartTime()+":00"));
											     long jieshuxiuxi = Long.valueOf(ClockInTool.dateToStamp(putime + " " +shif.getEndTime()+":00"));
											     rest_time = (jieshuxiuxi - kaishixiuxi)/1000/60;//休息时间
ilal committed
1984 1985
											 }
											 
ilal committed
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012
											 double xbwz1 = 0,xbwz2=0,xbwz3=0;
											int sbwd1=0,sbwd2=0,sbwd3=0;
											
											int arrive_late = 0;//晚到时间
											String clock_date = "";//应打卡时间
											Long latetime = 0l;//前天晚走时长(分钟)
											
											KqglAssoDkmx yesterdaymx = KqglAssoDkmx.builder().build();
											AttendanceCardListDto attdateyesterday;
											long yesendtime1=0,yesendtime2=0,yesendtime3=0;
											
											//存在晚走玩到
											 if(iswzwd > 0) {
												//统一分钟数
											    xbwz1 = Double.valueOf(shif.getXbwz1()) * 60;//下班晚走1
											    String sbwd1_ = String.valueOf(Double.valueOf(shif.getSbwd1()) * 60);
												sbwd1 = Integer.valueOf(sbwd1_.substring(0, sbwd1_.lastIndexOf(".")));//上班晚到1
												
												xbwz2 = Double.valueOf(shif.getXbwz2()) * 60;//下班晚走2
												String sbwd2_ = String.valueOf(Double.valueOf(shif.getSbwd2()) * 60);
												sbwd2 = Integer.valueOf(sbwd2_.substring(0, sbwd2_.lastIndexOf(".")));//上班晚到2
												
												xbwz3 = Double.valueOf(shif.getXbwz3()) * 60;//下班晚走3
												String sbwd3_ = String.valueOf(Double.valueOf(shif.getSbwd3()) * 60);
												sbwd3 = Integer.valueOf(sbwd3_.substring(0, sbwd3_.lastIndexOf(".")));//上班晚到3
													
												 //获取前一天最后下班的时间
ilal committed
2013
												 yesterdaymx = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
															.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
												 attdateyesterday = MethodCall(qyid,userid,yesterday);
												 
												 List<AttSchedule> ash1 = attdateyesterday.getAttsch();
												 if(attdateyesterday.getAttsch().size() == 2 || attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
													 yesendtime1 = ash1.get(1).getTime();
												 }
											 	 if(attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
											 		yesendtime2 = ash1.get(3).getTime();
												 }
											 	 if(attdateyesterday.getAttsch().size() == 6) {
											 		yesendtime3 = ash1.get(5).getTime();
												  }
ilal committed
2027
											 }
ilal committed
2028
											
ilal committed
2029
											 
ilal committed
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
											 if(execution_status == 1) {//上班1   ****新增
												 KqglAssoDkmx pcd = KqglAssoDkmx.builder().userid(userid).data(putime).qyid(qyid).dksj(startDate).build();
												 int sbdkjg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst1 = 0;
												 if(punchcardtime != 0){//有应打卡时间时
													 Long time = (time_ - punchcardtime)/1000/60;
													 if((atttype)%2 > 0){//上班
														if(time > 0){
															sbdkjg = Integer.valueOf(time.toString());
														}// 打卡结果
													 }else{//下班
														if(time > 0){}else{
															sbdkjg = Math.abs(Integer.valueOf(time.toString()));
														}// 打卡结果
													 }
													 
													 
													//存在晚走玩到
													 if(iswzwd > 0 && yesterdaymx != null) {
														 if(dkcs_ == 1) {
															 if(yesterdaymx.getXbdk1() != null && yesterdaymx.getXbdk1jg() == 0) {
																 latetime = (yesterdaymx.getXbdk1() - yesendtime1)/1000/60;
															 }
														 }else if(dkcs_ == 2){
															 if(yesterdaymx.getXbdk2() != null && yesterdaymx.getXbdk2jg() == 0) {
																 latetime = (yesterdaymx.getXbdk2() - yesendtime2)/1000/60;
															 }
														 }else {
															 if(yesterdaymx.getXbdk3() != null && yesterdaymx.getXbdk3jg() == 0) {
																 latetime = (yesterdaymx.getXbdk3() - yesendtime3)/1000/60;
															 }
														 }
														 if(latetime != 0) {
															 double latetime_ = Double.valueOf(String.valueOf(latetime));//前天晚走时长(分钟)
															 if(latetime_ > xbwz1 && latetime_ < xbwz2) {
																 arrive_late = sbwd1;
															 }else if(latetime_ > xbwz2 && latetime_ < xbwz3) {
																 arrive_late = sbwd2;
															 }else if(latetime_ > xbwz3) {
																 arrive_late = sbwd3;
															 }
															 
															 clock_date = ClockInTool.stampToDate(String.valueOf(punchcardtime));
															 Long changed_time = Long.valueOf(ClockInTool.dateToStamp(ClockInTool.addtime(clock_date, "+"+arrive_late)));//晚到后应打卡时间
															 
															 punchcardtime = changed_time;//更换当天打卡时间
															 Long timeyes = (time_ - changed_time)/1000/60;//
															 if((atttype)%2 > 0){//上班
																if(timeyes > 0){
																	sbdkjg = Integer.valueOf(timeyes.toString());
																}else {
																	sbdkjg = 0;
																}
															 }else{//下班
																if(timeyes > 0){
																	sbdkjg = 0;
																}else{
																	sbdkjg = Math.abs(Integer.valueOf(timeyes.toString()));
																}
															 }
														 }
													 }
													 
												 }
												 
												//允许迟到范围
												 if(sbdkjg <= yxcd) {
													 sbdkjg = 0;
ilal committed
2097 2098
												 }
												 
ilal committed
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111
												 if(atttype == 1) {
											    	pcd.setSbdk1(time_); pcd.setSbdk1jg(sbdkjg);
												 }else if(atttype == 2) {
													pcd.setXbdk1(time_); pcd.setXbdk1jg(sbdkjg);
												 }else if(atttype == 3) {
													pcd.setSbdk2(time_); pcd.setSbdk2jg(sbdkjg);
												 }else if(atttype == 4) {
													pcd.setXbdk2(time_); pcd.setXbdk2jg(sbdkjg);
												 }else if(atttype == 5) {
													pcd.setSbdk3(time_); pcd.setSbdk3jg(sbdkjg);
												 }else if(atttype == 6) {
													pcd.setXbdk3(time_); pcd.setXbdk3jg(sbdkjg);
												 }
ilal committed
2112
												 
ilal committed
2113 2114 2115 2116 2117
												 int ydkcs = 0;
												 if(shif != null){
													 ydkcs = shif.getSxbcs()*2;
												 }//应打卡次数
												 pcd.setYdkcs(ydkcs);
ilal committed
2118
												 
ilal committed
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
												 //严重迟到范围
												 if(sbdkjg>yzcd && sbdkjg < kgcdfzs && yzcd>0) {
													 yzcdcs++;
													 yzcdsc = sbdkjg;
													 dkst1 = 1;
												 }
												 //旷工迟到
												 if(sbdkjg>kgcdfzs && kgcdfzs>0) {
													 kgcdcs++;
													 dkst1 = 2;
ilal committed
2129 2130
												 }
												 
ilal committed
2131
												 pcd.setDkst1(dkst1);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
ilal committed
2132
												 
ilal committed
2133 2134 2135 2136 2137 2138 2139 2140
												 pcd.setYzcdcs(yzcdcs);//严重迟到次数
												 pcd.setYzcdsc(Double.valueOf(yzcdsc));//严重迟到时长(分钟)
												 pcd.setKgcdfzs(kgcdcs);//旷工迟到次数
												 
												 if (!pcd.insert()) {
													throw new CustomException("打卡明细-新增异常-1");
												 }
												 dkmx = pcd.getId();
ilal committed
2141
												 
ilal committed
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287
											 }else if(execution_status == 2){
												 dkmx = dkmc.getId();
												 KqglAssoDkmx pcd = KqglAssoDkmx.builder().build();
												 if(atttype == 2){//下班1
													 pcd.setId(dkmc.getId());
													 pcd.setXbdk1(time_);//下班1打卡时间
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){
															 pcd.setXbdk1jg(0);// 打卡结果
														 }else{
															 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));
														 }
													 }
													 if(dkmc.getSbdk1() != null){
														Long time = (time_ - dkmc.getSbdk1())/1000/60 - rest_time;
														pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
													 }
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
													 
											     }else if(atttype == 3){//上班2
											    	 
											    	 int sbdk2jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst2=0;
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){sbdk2jg = Math.abs(Integer.valueOf(time.toString()));}
													 }
													 
													 
													//允许迟到范围
													 if(sbdk2jg <= yxcd) {
														 sbdk2jg = 0;
													 }
													 
													 //严重迟到范围
													 if(sbdk2jg>yzcd && sbdk2jg < kgcdfzs && yzcd>0) {
														 yzcdcs = dkmc.getYzcdcs()+1;
														 yzcdsc = sbdk2jg;
														 dkst2 = 1;
													 }
													 //旷工迟到
													 if(sbdk2jg>kgcdfzs && kgcdfzs>0) {
														 kgcdcs++;
														 kgcdcs = kgcdcs + dkmc.getKgcdfzs();
														 dkst2 = 2;
													 }
													 
													 pcd.setDkst2(dkst2);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
													 
													 pcd.setId(dkmc.getId());
											    	 pcd.setSbdk2(time_);//上班1打卡时间
													 pcd.setSbdk2jg(sbdk2jg);
													 
													 pcd.setYzcdcs(yzcdcs);
													 pcd.setYzcdsc(Double.valueOf(yzcdsc));
													 pcd.setKgcdfzs(kgcdcs);
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
											     }else if(atttype == 4){//下班2
													 pcd.setId(dkmc.getId());
											    	 pcd.setXbdk2(time_);//下班1打卡时间
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){
															 pcd.setXbdk2jg(0);// 打卡结果
														 }else{
															 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
														 }
													 }
													//班次为4次时,计算工作时长
													 if(dkmc.getSbdk2() != null){
														 Long time = (time_ - dkmc.getSbdk2())/1000/60;
														 BigDecimal om = new BigDecimal(dkmc.getGzsc());
														 BigDecimal on = new BigDecimal(time);
														 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
														 
														 BigDecimal xx = new BigDecimal(rest_time);
														 
														 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
														 
														 pcd.setGzsc(worktime);
													 }
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
											     }else if(atttype == 5){//上班3
											    	 int sbdk3jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0,dkst3=0;
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){sbdk3jg = Math.abs(Integer.valueOf(time.toString()));}
													 }
													 
													//允许迟到范围
													 if(sbdk3jg <= yxcd) {
														 sbdk3jg = 0;
													 }
													 
													 //严重迟到范围
													 if(sbdk3jg>yzcd && sbdk3jg < kgcdfzs && yzcd>0) {
														 yzcdcs = dkmc.getYzcdcs()+1;
														 yzcdsc = sbdk3jg;
														 dkst3 = 1;
													 }
													 //旷工迟到
													 if(sbdk3jg>kgcdfzs && kgcdfzs>0) {
														 kgcdcs++;
														 kgcdcs = kgcdcs + dkmc.getKgcdfzs();
														 dkst3 = 2;
													 }
													 
													 pcd.setDkst3(dkst3);//打卡时态(0:无;1:严重迟到;2:旷工迟到)
													 
													 pcd.setId(dkmc.getId());
											    	 pcd.setSbdk3(time_);//上班1打卡时间
													 pcd.setSbdk3jg(sbdk3jg);
													 
													 pcd.setYzcdcs(yzcdcs);
													 pcd.setYzcdsc(Double.valueOf(yzcdsc));
													 pcd.setKgcdfzs(kgcdcs);
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
											     }else if(atttype == 6){//下班3
													 pcd.setId(dkmc.getId());
											    	 pcd.setXbdk3(time_);//下班1打卡时间
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){
															 pcd.setXbdk3jg(0);// 打卡结果
														 }else{
															 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
														 }
													 }
													//班次为6次时,计算工作时长
													 if(dkmc.getSbdk3() != null){
														 Long time = (time_ - dkmc.getSbdk3())/1000/60;
														 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
														 BigDecimal on = new BigDecimal(time);
														 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
														 
														 BigDecimal xx = new BigDecimal(rest_time);
														 
														 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
														 
														 pcd.setGzsc(worktime);
													 }
											     }
												 pcd.setId(dkmc.getId());
												 if(atttype <= 6 && atttype > 0 && !sbdkkd){
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
												 }
ilal committed
2288
											 }
ilal committed
2289 2290 2291 2292
										 }else {
											 msg = "当前打卡时间不在范围内";
											 sbyf = 0;
											 status_ = 2;
lal committed
2293
										 }
ilal committed
2294
								 }else {
ilal committed
2295
									 msg = "当前时间必须大于上班打卡时间 才能打下班卡";
ilal committed
2296 2297
									 sbyf = 0;
									 status_ = 2;
lal committed
2298
								 }
ilal committed
2299
							}else {
ilal committed
2300 2301 2302 2303 2304 2305
								//判断 考勤组是否开启休息日打卡
								if(attgro.getRestdayclock().equals(0)) {
									  msg = "当前是休息时间";
									  sbyf = 0;
									  status_ = 2;
								}else {
ilal committed
2306
									
ilal committed
2307
									KqglAssoDkmx zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
ilal committed
2308 2309 2310
											.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate));
									if(zydkmc == null) {//新增
										KqglAssoDkmx pcd  = KqglAssoDkmx.builder().build();
ilal committed
2311
										
ilal committed
2312 2313 2314 2315 2316 2317
										pcd = KqglAssoDkmx.builder().userid(userid).data(putime).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDate).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
										if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										}
										dkmx = pcd.getId();
										atttype = 1;
ilal committed
2318
										xiuxidaka = 1;
ilal committed
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386
									}else {//修改	
										dkmx = zydkmc.getId();
										KqglAssoDkmx zypcd = KqglAssoDkmx.builder().build();
										kskd = false;
										if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() == null)){//下班1
											
											zypcd.setId(zydkmc.getId());
											zypcd.setXbdk1(time_);//下班1打卡时间
											if(zydkmc.getSbdk1() != null){
												Long time = (time_ - zydkmc.getSbdk1())/1000/60;
												zypcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
											 }
											kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
											
											atttype = 2;
											xiuxidaka = 1;
										}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
									    		 && (("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() == null)){//上班2
											zypcd.setId(zydkmc.getId());
											zypcd.setSbdk2(time_);//上班1打卡时间
											kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
											atttype = 3;
											xiuxidaka = 1;
										}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
									    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() == null)){//下班2
											
											zypcd.setId(zydkmc.getId());
											zypcd.setXbdk2(time_);//下班1打卡时间
											//班次为4次时,计算工作时长
											 if(zydkmc.getSbdk2() != null){
												 Long time = (time_ - zydkmc.getSbdk2())/1000/60;
												 BigDecimal om = new BigDecimal(zydkmc.getGzsc());
												 BigDecimal on = new BigDecimal(time);
												 double worktime = Math.abs(om.add(on).doubleValue());
												 zypcd.setGzsc(worktime);
											 }
											 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
											 atttype = 4;
											 xiuxidaka = 1;
										}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
									    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
									    		 && (("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() == null)){//上班3
											zypcd.setId(zydkmc.getId());
											zypcd.setSbdk3(time_);//上班1打卡时间
											kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
											atttype = 5;
											xiuxidaka = 1;
										}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
									    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
									    		 && (!("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() != null) && (("").equals(zydkmc.getXbdk3()) || zydkmc.getXbdk3() == null)){
											
											zypcd.setId(zydkmc.getId());
											zypcd.setXbdk3(time_);//下班1打卡时间
											//班次为6次时,计算工作时长
											 if(zydkmc.getSbdk3() != null){
												 Long time = (time_ - zydkmc.getSbdk3())/1000/60;
												 BigDecimal om = new BigDecimal(zydkmc.getGzsc());//第二次
												 BigDecimal on = new BigDecimal(time);
												 double worktime = Math.abs(om.add(on).doubleValue());
												 zypcd.setGzsc(worktime);
											 }
											 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
											 atttype = 6;
											 xiuxidaka = 1;
										}else {
											atttype = 7;
											xiuxidaka = 1;
										}
ilal committed
2387 2388 2389 2390 2391
										
									}
									
								}
								
ilal committed
2392 2393
							}
						}	
lal committed
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405
					}
				 }else {
					 
					//需要再次调整********************
					 
					//自由工时打卡
					Long stapclotime = attdate.getStapclotime();// 今天考勤 自由排班开始时间
					int canpunchworkdate = Integer.valueOf(String.valueOf(attdate.getCanpunchworkdate()).replaceAll("(\\d+)(?:(\\.\\d*[^0])|\\.)0*", "$1$2"));// 上班打卡后多久大下班卡
					KqglAssoDkmx zydkmc = KqglAssoDkmx.builder().build();
					Date sd1=df1.parse(ClockInTool.stampToDate(String.valueOf(stapclotime)));//应打卡时间   2020-06-10 18:30:00
					Date sd2=df1.parse(current_time);//当前时间  2020-06-10 16:06:58
					if(sd1.after(sd2)) {//为true时  打的是昨天的卡
ilal committed
2406
						zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
lal committed
2407 2408 2409 2410
								.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
						attendance_date = startDateyesterday;
						toweek = yesterday;
					}else {
ilal committed
2411
						zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid).eq(KqglAssoDkmx::getQyid, qyid)
lal committed
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
								.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate));
						attendance_date = startDate;
						toweek = putime;
					}  
					if(zydkmc == null) {//新增
						KqglAssoDkmx pcd  = KqglAssoDkmx.builder().build();
						if(sd1.after(sd2)) {
							pcd = KqglAssoDkmx.builder().userid(userid).data(yesterday).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDateyesterday).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
						}else {
							pcd = KqglAssoDkmx.builder().userid(userid).data(putime).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDate).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
						}
//							KqglAssoDkmx pcd = KqglAssoDkmx.builder().userid(userid).data(putime).sbdk1(time_).sbdk1jg(0).ydkcs(0).qyid(qyid).dksj(startDate).yzcdcs(0).yzcdsc(Double.valueOf(0)).kgcdfzs(0).build();
						 if (!pcd.insert()) {
							throw new CustomException("打卡明细-新增异常-1");
lal committed
2426
						 }
lal committed
2427 2428 2429
						 dkmx = pcd.getId();
						 atttype = 1;
					}else {//修改	
ilal committed
2430
						boolean zydk = true;
lal committed
2431 2432 2433 2434 2435 2436 2437 2438 2439
						dkmx = zydkmc.getId();
						KqglAssoDkmx zypcd = KqglAssoDkmx.builder().build();
						if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() == null)){//下班1
							String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk1())),canpunchworkdate,5,2);
							Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
							Date zysd2=df1.parse(current_time);//当前时间  
							if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
								msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
								sbyf = 0;
ilal committed
2440 2441
								zydk = false;
								atttype = 0;
ilal committed
2442
								status_ = 2;
lal committed
2443 2444 2445 2446 2447 2448 2449 2450 2451
							}else {
								zypcd.setId(zydkmc.getId());
								zypcd.setXbdk1(time_);//下班1打卡时间
								if(zydkmc.getSbdk1() != null){
									Long time = (time_ - zydkmc.getSbdk1())/1000/60;
									zypcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
								 }
								kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
							}
ilal committed
2452 2453 2454 2455
							if(zydk) {
								atttype = 2;
							}
							
lal committed
2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469
						}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
					    		 && (("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() == null)){//上班2
							zypcd.setId(zydkmc.getId());
							zypcd.setSbdk2(time_);//上班1打卡时间
							kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
							atttype = 3;
						}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
					    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() == null)){//下班2
							String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk2())),canpunchworkdate,5,2);
							Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
							Date zysd2=df1.parse(current_time);//当前时间  
							if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
								msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
								sbyf = 0;
ilal committed
2470 2471
								zydk = false;
								atttype = 0;
ilal committed
2472
								status_ = 2;
lal committed
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
							}else {
								zypcd.setId(zydkmc.getId());
								zypcd.setXbdk2(time_);//下班1打卡时间
								//班次为4次时,计算工作时长
								 if(zydkmc.getSbdk2() != null){
									 Long time = (time_ - zydkmc.getSbdk2())/1000/60;
									 BigDecimal om = new BigDecimal(zydkmc.getGzsc());
									 BigDecimal on = new BigDecimal(time);
									 double worktime = Math.abs(om.add(on).doubleValue());
									 zypcd.setGzsc(worktime);
								 }
								 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
							}
ilal committed
2486
							if(zydk) {
lal committed
2487
							 atttype = 4;
ilal committed
2488
							}
lal committed
2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504
						}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
					    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
					    		 && (("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() == null)){//上班3
							zypcd.setId(zydkmc.getId());
							zypcd.setSbdk3(time_);//上班1打卡时间
							kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
							atttype = 5;
						}else if((!("").equals(zydkmc.getSbdk1()) || zydkmc.getSbdk1() != null) && (!("").equals(zydkmc.getXbdk1()) || zydkmc.getXbdk1() != null)
					    		 && (!("").equals(zydkmc.getSbdk2()) || zydkmc.getSbdk2() != null) && (!("").equals(zydkmc.getXbdk2()) || zydkmc.getXbdk2() != null)
					    		 && (!("").equals(zydkmc.getSbdk3()) || zydkmc.getSbdk3() != null) && (("").equals(zydkmc.getXbdk3()) || zydkmc.getXbdk3() == null)){//下班3
							String clock_time = ClockInTool.requires_extra_times(ClockInTool.stampToDate(String.valueOf(zydkmc.getSbdk3())),canpunchworkdate,5,2);
							Date zysd1=df1.parse(clock_time);//上班打卡后多久大下班卡的时间
							Date zysd2=df1.parse(current_time);//当前时间  
							if(zysd1.after(zysd2)) {//当zysd1大于zysd2时,返回TRUE,当小于等于时,返回false; 
								msg = "自由工时:上班打卡后"+canpunchworkdate+"小时后,才可打下班卡";
								sbyf = 0;
ilal committed
2505 2506
								zydk = false;
								atttype = 0;
ilal committed
2507
								status_ = 2;
lal committed
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520
							}else {
								zypcd.setId(zydkmc.getId());
								zypcd.setXbdk3(time_);//下班1打卡时间
								//班次为6次时,计算工作时长
								 if(zydkmc.getSbdk3() != null){
									 Long time = (time_ - zydkmc.getSbdk3())/1000/60;
									 BigDecimal om = new BigDecimal(zydkmc.getGzsc());//第二次
									 BigDecimal on = new BigDecimal(time);
									 double worktime = Math.abs(om.add(on).doubleValue());
									 zypcd.setGzsc(worktime);
								 }
								 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
							}
ilal committed
2521
							if(zydk) {
lal committed
2522
							 atttype = 6;
ilal committed
2523
							}
lal committed
2524 2525 2526 2527
						}else {
							atttype = 7;
						}
					}
lal committed
2528 2529
				 }
				 
lal committed
2530 2531 2532
 /*****************************************************************************************************************************************************************************************************/
 /*******************************************************************APP 原始打卡记录数据录入**************************************************************************************************************/
 /*****************************************************************************************************************************************************************************************************/
lal committed
2533
				 
lal committed
2534 2535 2536
				 String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(attendance_date));//转换打卡时间格式
					
				//true:确认为最后一次打卡更新打卡时  之前打卡的一条数据变为“打卡更新数据”
ilal committed
2537
				if(kskd && (atttype == 2 || atttype == 4 || atttype == 6) && attdate.getAttgrouptype() != 3) {
lal committed
2538 2539 2540 2541
					KqglAssoDkjl dkjj = KqglAssoDkjl.builder().build().selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getUserId, userid).eq(KqglAssoDkjl::getType, 2)
							.eq(KqglAssoDkjl::getSort, atttype).eq(KqglAssoDkjl::getQyid, qyid).eq(KqglAssoDkjl::getAttdate, attdate_+" "+ClockInTool.dateToWeek2(toweek)));
					
					KqglAssoDkjl.builder().id(dkjj.getId()).status(0).sort(0).build().updateById();
lal committed
2542 2543
					msg = "打卡已更新数据";
					sbyf = 0;
ilal committed
2544
//					status_ = 2;
lal committed
2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561
				}
				
				int results = 0;
				Long time = (time_ - punchcardtime)/1000/60;
				if(punchcardtime != 0){
					if(isRange) {
						if((atttype)%2 > 0){//上班
							if(time > 0){
								results = Integer.valueOf(time.toString());
							}// 打卡结果
						}else{//下班
							if(time > 0){}else{
								results = Math.abs(Integer.valueOf(time.toString()));
							}// 打卡结果
						}
					}
				}
ilal committed
2562 2563 2564 2565
				int type = 0,status = 0;
				if(atttype > 0) {
					if((atttype)%2 > 0){
						type = 1;// 类型(类型 0:无排班打卡 1:上班 2:下班)   punchcardtime == 0:无班次打卡
ilal committed
2566 2567 2568 2569 2570 2571 2572 2573 2574
						
						if(xiuxidaka > 0) {
							status = 1;
						}else {
							if(attdate.getAttgrouptype() != 3) {
								if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
									if(punchcardtime == 0 && clockt.getShifid() != 0){
										status = 1;
									}if(punchcardtime == 0 && clockt.getShifid() == 0) {
ilal committed
2575
										status = 2;
ilal committed
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585
									}else{
										if(isRange) {// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											if(time > 0){
												status = 3;
											}else if(results == 0){
												status = 1;
											}
										}else {
											status = 2;
										}
ilal committed
2586
									}
ilal committed
2587 2588
								}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
									status = 2;
lal committed
2589
								}
ilal committed
2590
							}else {
ilal committed
2591 2592 2593 2594 2595
								if(sbyf == 1) {
									status = 1;
								}else {
									status = 2;
								}
ilal committed
2596 2597
							}
						}
ilal committed
2598 2599
						
						
ilal committed
2600 2601
					}else{
						type = 2;// 类型(类型 0:无排班打卡 1:上班 2:下班)
ilal committed
2602 2603 2604 2605 2606 2607 2608 2609 2610
						if(xiuxidaka > 0) {
							status = 1;
						}else {
							
							if(attdate.getAttgrouptype() != 3) {
								if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
									if(punchcardtime == 0 && clockt.getShifid() != 0){
										status = 1;
									}if(punchcardtime == 0 && clockt.getShifid() == 0) {
ilal committed
2611
										status = 2;
ilal committed
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621
									}else{
										if(isRange) {
											if(time < 0){
												status = 4;
											}else if(results == 0){
												status = 1;
											}
										}else {
											status = 2;
										}
ilal committed
2622
									}
ilal committed
2623 2624
								}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
									status = 2;
lal committed
2625
								}
ilal committed
2626
							}else {
ilal committed
2627 2628 2629 2630 2631
								if(sbyf == 1) {
									status = 1;
								}else {
									status = 2;
								}
ilal committed
2632
							}
lal committed
2633
						}
ilal committed
2634 2635
						
						
lal committed
2636
					}
lal committed
2637
				}
lal committed
2638 2639 2640
				
				//第二次未超过应上班打卡时间 打卡为无效
				if(sbdkkd) {
lal committed
2641
					sbyf = 0;
lal committed
2642 2643 2644 2645 2646 2647 2648 2649
					status = 2;
					atttype = 0;
					msg = "已有最优的打卡记录存在";
				}
				
				long attime;
				if(punchcardtime == 0){// 考勤时间(应打卡时间)
					attime = new Date().getTime();
lal committed
2650
				}else{
lal committed
2651
					attime = punchcardtime;
lal committed
2652
				}
lal committed
2653 2654 2655 2656 2657 2658 2659
				
				String remarks = "";//考勤备注
				String punchequipment = "";//打卡设备
				
				String commentary = "未知";
				if(sbyf == 1) {
					commentary = "打卡成功";
ilal committed
2660
					msg = "打卡成功";
lal committed
2661 2662
				}else {
					commentary = msg;
ilal committed
2663 2664 2665
					if(status_ == 2) {
						status = status_;
					}
lal committed
2666
				}
lal committed
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
				
				
				KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(time_).results(results).userId(userid).type(type).status(status).sort(atttype)
						.qyid(qyid).attdate(attdate_+" "+ClockInTool.dateToWeek2(toweek)).attime(attime).dkmxid(dkmx).bcid(shifid).remarks(remarks)
						.punchequipment(punchequipment).commentary(commentary).build();
				//cardtype--1:GPS,2:WIFI,3:考勤机,4:外勤
				int cardtype = 0;
				if(clock.getPunchcardtype() == 1 || clock.getPunchcardtype() == 4) {
					pre.setAddress(clock.getAddress());
					pre.setLat(Double.valueOf(clock.getLat()));
					pre.setLon(Double.valueOf(clock.getLon()));
				}else if(clock.getPunchcardtype() == 2) {
					pre.setMacname(clock.getMacname());
					pre.setMac(clock.getMac());
lal committed
2681
				}
lal committed
2682
				pre.setCardType(clock.getPunchcardtype());
lal committed
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694
				
				if (!pre.insert()) {
					throw new CustomException("打卡记录-新增异常-2");
				 }
				
			 }else {
				msg="打卡失败!,未加入考勤组!";
				sbyf = 0;
			 }
		 }else {
			 return ResultUtil.error("打卡失败!,用户不存在!");
		 }
ilal committed
2695 2696 2697 2698 2699 2700
//		 if(sbyf == 1) {
//			return  ResultUtil.data("打卡成功");
//		 }else {
//			return  ResultUtil.data(msg, "打卡失败"); 
//		 }
		 return ResultUtil.success(msg);
lal committed
2701
	 }
lal committed
2702
	 
ilal committed
2703 2704 2705 2706
	 //****************************************************&&*******&&&******&&&****************************************************//
	 //***************************************************&**&******&***&****&***&**************************************************//
	 //**************************************************&&&&&&*****&&&******&&&****************************************************//
	 //*************************************************&******&****&********&******************************************************//
lal committed
2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726
	//考勤组绑定的打卡方式
	@Autowired
	private AttGroupBinPunchModeMapper attgroupbinpunchmodemapper;
	//考勤机
	@Autowired
	private AttendanceMachineMapper attendancemachinemapper;
	//考勤地址
	@Autowired
	private PunchCardAddressMapper punchcardaddressmapper;
	//考勤WIFI
	@Autowired
	private PunchCardWiFiMapper punchcardwifimapper;
	/**
	 * 	获取考勤打卡数据------APP打卡
	 * @throws ParseException 
	 */
	 @PostMapping(value = "/ClockData")
	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 3)
	 public Result<Object> getAttClockData(@CurrentUser UserBean userBean,@RequestBody AttConditions attconditions) throws ParseException {
lal committed
2727 2728 2729
		 
		 long nowdate = new Date().getTime();
		 
lal committed
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743
		 String str = null;
		 if(!("").equals(attconditions.getDate())){
			 str = attconditions.getDate();
		 }else{
			 Date d = new Date();
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 str = sdf.format(d);
		 }
		 
		 //前一天时间
		 String yesterday = ClockInTool.requires_extra_times(str,-1,3,1);//前一天
		 Long startDateyesterday = DateUtil.getStartTime(0,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
		 Long endDateyesterday = DateUtil.getnowEndTime(23,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
		 
lal committed
2744 2745
		 Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
	     Long endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
lal committed
2746
		 
lal committed
2747 2748
	     String stampToDate = ClockInTool.stampToDate(String.valueOf(endDate));//当天打卡的最后时间
		 Timestamp d = Timestamp.valueOf(stampToDate);
lal committed
2749 2750 2751
		 
		 Timestamp b = Timestamp.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));//当前时间
		 
ilal committed
2752 2753
		 String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		 
lal committed
2754 2755
		 KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userBean.getEmpNum(),userBean.getOrgCode()); //考勤组信息
		 
lal committed
2756
		 if(attgro != null) {
lal committed
2757
			 //APP获取当前天的考勤信息
lal committed
2758
			 AttendanceCardListDto attdate = MethodCall(userBean.getOrgCode(),userBean.getEmpNum(),attconditions.getDate());
lal committed
2759 2760 2761
			 //打卡记录
//		     List<KqglAssoDkjl> dajllist = kqglassodkjlmapper.getDetailedRecordClock(startDate,endDate,userBean.getEmpNum());
//		     attdate.setAttpr(dajllist);
ilal committed
2762
			 int dkcs = 0;
ilal committed
2763
			 int isxbdk = 0;
ilal committed
2764 2765 2766 2767 2768
			 
			 String yymmdd = str.substring(2, 10);
			 
			 String nowattdate = yymmdd+" "+ClockInTool.dateToWeek2(str);
			 //查询当天考勤记录
ilal committed
2769
			 List<KqglAssoDkjl> dajllist_ = kqglassodkjlmapper.getDetailedRecordClock(startDate,endDate,userBean.getEmpNum(),nowattdate,userBean.getOrgCode());
ilal committed
2770 2771 2772 2773 2774 2775
			 
			 if(dajllist_.size() > 0) {
				 dkcs = dajllist_.size();
				 isxbdk = dajllist_.get(dajllist_.size()-1).getSort();
			 }
			 
lal committed
2776 2777
			 if(attdate.getAttgrouptype() != 3) {
				 List<AttSchedule> attsch = attdate.getAttsch();
ilal committed
2778
				 
lal committed
2779
				 if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && attsch.get(0).getId() != 0) {//班次不为空
ilal committed
2780 2781
					 int bc = 0;
					 int bsz = 0;
ilal committed
2782
					 int cr = 0;
ilal committed
2783
					 boolean iscrdk = true;
ilal committed
2784
					 String crlasttime = null;//次日最后打卡时间
ilal committed
2785
					 boolean bycf = true;
ilal committed
2786
					 /****************昨日开始***************/
ilal committed
2787 2788 2789
					 int sb1 = 0,xb1 = 0,sb2 = 0,xb2 = 0,sb3 = 0,xb3 = 0;
					 //先判断前一天是否存在次日打卡的方式
					 KqglAssoBcsz jianchashif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, attsch.get(0).getId()));
ilal committed
2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807
					 if(jianchashif.getIsSbdk1Cr() == 1) { 
						 sb1 = 1; 
						 crlasttime = (str+" "+jianchashif.getSbdk1()+":00").replaceAll("\r|\n", "");}
					 if(jianchashif.getIsXbdk1Cr() == 1) { 
						 xb1 = 1; 
						 crlasttime = (str+" "+jianchashif.getXbdk1()+":00").replaceAll("\r|\n", "");}
					 if(jianchashif.getIsSbdk2Cr() == 1) { 
						 sb2 = 1; 
						 crlasttime = (str+" "+jianchashif.getSbdk2()+":00").replaceAll("\r|\n", "");}
					 if(jianchashif.getIsXbdk2Cr() == 1) { 
						 xb2 = 1; 
						 crlasttime = (str+" "+jianchashif.getXbdk2()+":00").replaceAll("\r|\n", "");}
					 if(jianchashif.getIsSbdk3Cr() == 1) { 
						 sb3 = 1; 
						 crlasttime = (str+" "+jianchashif.getSbdk3()+":00").replaceAll("\r|\n", "");}
					 if(jianchashif.getIsXbdk3Cr() == 1) { 
						 xb3 = 1; 
						 crlasttime = (str+" "+jianchashif.getXbdk3()+":00").replaceAll("\r|\n", "");}
ilal committed
2808
					 //
ilal committed
2809
					 if(sb1 == 1 ||xb1 == 1 ||sb2 == 1 ||xb2 == 1 || sb3 == 1 ||xb3 == 1) {
ilal committed
2810 2811 2812
						 //前一天的班次
						 AttendanceCardListDto beforeattdate = MethodCall(userBean.getOrgCode(),userBean.getEmpNum(),yesterday);
						 //前一天的打卡数据
ilal committed
2813 2814 2815 2816 2817 2818 2819 2820 2821
						 
//						String yesterday = ClockInTool.requires_extra_times(now,-1,3,1);//前一天
						
//						Long startDateyesterday = DateUtil.getStartTime(0,DateUtil.getStringTime(yesterday,"yyyy-MM-dd")).getTime();
						
						 String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDateyesterday));//转换打卡时间格式
						
						 String yeboattdate = attdate_+" "+ClockInTool.dateToWeek2(yesterday);
						 //次日查询昨日考勤时   时间范围扩大到 昨日开始到今日结束
ilal committed
2822
						 List<KqglAssoDkjl> dajllistbefo = kqglassodkjlmapper.getDetailedRecordClock(startDateyesterday,endDate,userBean.getEmpNum(),yeboattdate,userBean.getOrgCode());
ilal committed
2823 2824 2825 2826
						 
						 List<AttSchedule> beforeattsch = beforeattdate.getAttsch();
						 
						 int p = 0;
ilal committed
2827
						 if(EmptyUtil.isNotEmpty(beforeattdate.getAttsch()) && beforeattsch.get(0).getId() != 0) {
ilal committed
2828
							 int g = 1;
ilal committed
2829 2830 2831
							 for(AttSchedule befo : beforeattsch) {
								 boolean isdkjl = true;
								 if(befo.getNextday() == 1) {
ilal committed
2832
									 iscrdk = false;
ilal committed
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843
									 cr++;
									 AttSchedule attschbefo = AttSchedule.builder().build();
									 BeanUtil.copyProperties(befo, attschbefo,"nextdaycard","dajl");
									 attschbefo.setNextdaycard(1);
									 attschbefo.setNextday(2);//昨日
									 KqglAssoDkjl dkjlbefo = KqglAssoDkjl.builder().build();
									 for(KqglAssoDkjl ka : dajllistbefo) {
										 if(befo.getId() == ka.getBcid() && befo.getSort() == ka.getSort()) {//班次id和打卡顺序对应
											 BeanUtil.copyProperties(ka, dkjlbefo,"attdate","remarks","userId","attime","dkmxid","commentary","punchequipment","punchmode");
											 isdkjl = false;
										 }
ilal committed
2844
									 }
ilal committed
2845
									 
ilal committed
2846
									 if(dkjlbefo.getDktime() != null) {
ilal committed
2847
										 bycf = false;
ilal committed
2848 2849
										 bc++;
										 attschbefo.setIsdk(1);
ilal committed
2850 2851
									 }else {
										 attschbefo.setIsdk(0);
ilal committed
2852
									 }
ilal committed
2853 2854
									 
								 	 if(beforeattdate.getAttsch().size() == 2) {
ilal committed
2855 2856 2857 2858 2859 2860
								 		if(befo.getStarttime() != 0 && befo.getEndtime() != 0) {
									 		boolean ectivedate = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(nowdate), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(befo.getStarttime()), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(befo.getEndtime()),"yyyy-MM-dd HH:mm");
									 		if(g == 1) {
									 			if(ectivedate) {
													 attschbefo.setIsdk(0);
												 }else {
ilal committed
2861
													 bc++;
ilal committed
2862 2863 2864 2865 2866 2867 2868
													 attschbefo.setIsdk(1);
												 }
									 		}
									 		if(g == 2) {
									 			if(ectivedate) {
													 attschbefo.setIsdk(0);
												 }else {
ilal committed
2869
													 bc++;
ilal committed
2870 2871 2872 2873 2874
													 attschbefo.setIsdk(1);
												 }
									 		}
									 		g++;
								 		}
ilal committed
2875 2876 2877 2878 2879
									 }else {
										 boolean ectivedate = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(nowdate), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(befo.getStarttime()), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(befo.getEndtime()),"yyyy-MM-dd HH:mm");
										 if(ectivedate) {
											 if(isdkjl) {
												 bsz = 1;
ilal committed
2880
												 bc--;
ilal committed
2881 2882 2883 2884
												 attschbefo.setIsdk(0);
											 }
											 
										 }else {
ilal committed
2885 2886 2887 2888
											 if(bycf) {
												 bc++;
												 attschbefo.setIsdk(1);
											 }
ilal committed
2889 2890 2891 2892 2893
										 }
									 }
									 
								 	Timestamp tt = Timestamp.valueOf(ClockInTool.stampToDate(String.valueOf(befo.getTime())));
								 	
ilal committed
2894
								 	if(attschbefo.getIsdk() == 1 && b.after(tt) && isdkjl) {
ilal committed
2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
								 		dkjlbefo.setStatus(17);//缺卡
								 		dkjlbefo.setSort(befo.getSort());
								 		dkjlbefo.setId(888);
										 //更新打卡关闭
								 		attschbefo.setIsupdate(0);
									 }
								 	 
								 	 attschbefo.setDajl(dkjlbefo);
								 	 
									 attsch.add(p,attschbefo);
									 p++;
ilal committed
2906
								 }
ilal committed
2907 2908
							 }
						 }
ilal committed
2909
						 
ilal committed
2910
					 }
ilal committed
2911
					 /****************昨日结束***************/
ilal committed
2912
					 
lal committed
2913
					 int bccs = attdate.getAttsch().size();
ilal committed
2914 2915 2916
					 int r = 1;
//					 int bc = 0;
//					 int bsz = 0;
ilal committed
2917 2918 2919 2920 2921 2922
					 boolean dk1 = true;//上
					 boolean dk2 = true;//下
					 boolean dk3 = true;
					 boolean dk4 = true;
					 boolean dk5 = true;
					 boolean dk6 = true;
lal committed
2923
					 for(AttSchedule ash : attsch) {
ilal committed
2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935
						 if(ash.getNextdaycard() == 0) {
							 if(attdate.getAttsch().size() == 2) {
								 //有范围
								 if(ash.getStarttime() != 0 && ash.getEndtime() != 0) {
									 boolean ectivedate = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(nowdate), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(ash.getStarttime()), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(ash.getEndtime()),"yyyy-MM-dd HH:mm");
									 
									 String timme = ClockInTool.stampToDate2(String.valueOf(ash.getTime()));
									 
									 if(r == 1) {
										 if(ectivedate) {
											 bsz = 1;
											 ash.setIsdk(0);
ilal committed
2936
										 }else {
ilal committed
2937
											 dk1 = false;
ilal committed
2938 2939 2940
											 bc++;
											 ash.setIsdk(1);
											 
ilal committed
2941
											 
ilal committed
2942
											 if(!now.equals(timme)) {
ilal committed
2943 2944 2945 2946 2947
												 ash.setIsupdate(0);
											 }else {
												 
												 ash.setIsupdate(1);
											 }
ilal committed
2948 2949
										 }
									 }
ilal committed
2950 2951 2952 2953 2954
									 
									 if(r == 2) {
										 if(ectivedate) {
											 bsz = 1;
											 ash.setIsdk(0);
ilal committed
2955
										 }else {
ilal committed
2956
											 dk2 = false;
ilal committed
2957 2958
											 bc++;
											 ash.setIsdk(1);
ilal committed
2959
											 
ilal committed
2960
											 if(!now.equals(timme)) {
ilal committed
2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984
												 ash.setIsupdate(0);
											 }else {
												 if(isxbdk == 2) {
													 ash.setIsupdate(1);
												 }
												 
											 }
										 }
									 }
									 r++;
									 
									 //是否请假
							        KqglAssoRelationSummary leainv = kqglassorelationsummarymapper.leaveinvesti(userBean.getEmpNum(), 2, str,userBean.getOrgCode());
									boolean adopt = false;
									if(leainv != null) {
										String time = ClockInTool.stampToDate4(String.valueOf(ash.getTime()));//当天打卡的最后时间
										adopt = ClockInTool.hourMinuteBetween(time, leainv.getStartTime().substring(0, 16), leainv.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
									}
									if(adopt) {
										ash.setIsleave(1);
									}
								 }else {
									 KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ash.getId()));
									 String xbdk1 = (str+" "+shif.getXbdk1()+":00").replaceAll("\r|\n", "");
ilal committed
2985
									 Timestamp a = Timestamp.valueOf(xbdk1);//下班
ilal committed
2986
									 String sbdk1 = (str+" "+shif.getSbdk1()+":00").replaceAll("\r|\n", "");
ilal committed
2987
							         Timestamp c = Timestamp.valueOf(sbdk1);//上班
ilal committed
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006
									 
									 if(r == 1) {
								         if (b.after(a) && b.after(c)) {//  当前时间大于下班打卡时间
								        	 bc++;
								        	 ash.setIsdk(1);
								        	 if(b.before(d)) {
								        		 ash.setIsupdate(1);
								        	 }
								         }else {
								        	 bsz = 1;
								         }
									 }
									 if(r == 2) {
										 if(b.after(a) && b.after(c) && b.before(d)) {
											 bsz = 1;
											 ash.setIsdk(0);
										 }else {
											 bc++;
											 ash.setIsdk(1);
ilal committed
3007 3008
										 }
									 }
ilal committed
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020
									 r++;
									 
									 //是否请假
							        KqglAssoRelationSummary leainv = kqglassorelationsummarymapper.leaveinvesti(userBean.getEmpNum(), 2, str,userBean.getOrgCode());
									boolean adopt = false;
									if(leainv != null) {
										String time = ClockInTool.stampToDate4(String.valueOf(ash.getTime()));//当天打卡的最后时间
										adopt = ClockInTool.hourMinuteBetween(time, leainv.getStartTime().substring(0, 16), leainv.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
									}
									if(adopt) {
										ash.setIsleave(1);
									}
lal committed
3021 3022
								 }
							 }else {
ilal committed
3023 3024 3025 3026 3027 3028 3029
								 boolean ectivedate = ClockInTool.hourMinuteBetween(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(nowdate), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(ash.getStarttime()), new SimpleDateFormat("yyyy-MM-dd HH:mm").format(ash.getEndtime()),"yyyy-MM-dd HH:mm");
								 if(ectivedate) {
									 bsz = 1;
									 ash.setIsdk(0);
								 }else {
									 bc++;
									 ash.setIsdk(1);
ilal committed
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048
									 
									 if(ash.getSort() == 1) {
										 dk1 = false;
									 }
									 if(ash.getSort() == 2) {
										 dk2 = false;
									 }
									 if(ash.getSort() == 3) {
										 dk3 = false;
									 }
									 if(ash.getSort() == 4) {
										 dk4 = false;
									 }
									 if(ash.getSort() == 5) {
										 dk5 = false;
									 }
									 if(ash.getSort() == 6) {
										 dk6 = false;
									 }
lal committed
3049
								 }
lal committed
3050
								 
ilal committed
3051
								//是否请假
lal committed
3052 3053 3054 3055 3056 3057 3058 3059 3060
						        KqglAssoRelationSummary leainv = kqglassorelationsummarymapper.leaveinvesti(userBean.getEmpNum(), 2, str,userBean.getOrgCode());
								boolean adopt = false;
								if(leainv != null) {
									String time = ClockInTool.stampToDate4(String.valueOf(ash.getTime()));//当天打卡的最后时间
									adopt = ClockInTool.hourMinuteBetween(time, leainv.getStartTime().substring(0, 16), leainv.getEndTime().substring(0, 16),"yyyy-MM-dd HH:mm");
								}
								if(adopt) {
									ash.setIsleave(1);
								}
lal committed
3061
							 }
lal committed
3062
							 
ilal committed
3063 3064 3065 3066
							 String afterday = ClockInTool.requires_extra_times(str,+1,3,1);//后一天
							 Long endDateafterday = DateUtil.getnowEndTime(23,DateUtil.getStringTime(afterday,"yyyy-MM-dd")).getTime();
							 
							 if(sb1 == 1 ||xb1 == 1 || sb2 == 1 ||xb2 == 1 || sb3 == 1 ||xb3 == 1) {//当天存在次日打卡数据时  查询打卡记录范围应该是:当天的开始到后一天的结束
ilal committed
3067
								 dajllist_ = kqglassodkjlmapper.getDetailedRecordClock(startDate,endDateafterday,userBean.getEmpNum(),nowattdate,userBean.getOrgCode());
ilal committed
3068 3069
							 }
							 
ilal committed
3070 3071 3072 3073 3074 3075 3076
							 KqglAssoDkjl dkjl = KqglAssoDkjl.builder().build();
							 for(KqglAssoDkjl daj : dajllist_) {
								 if(ash.getId() == daj.getBcid() && ash.getSort() == daj.getSort()) {//班次id和打卡顺序对应
									 BeanUtil.copyProperties(daj, dkjl,"attdate","remarks","userId","attime","dkmxid","commentary","punchequipment","punchmode");
									 int bcid = dkjl.getBcid();
									 int results = dkjl.getResults();
									 KqglAssoBcsz bcsz = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, bcid));
ilal committed
3077 3078 3079 3080 3081 3082
									 
									 if(now.equals(ClockInTool.stampToDate2(String.valueOf(ash.getTime())))) {
										 if(attdate.getAttsch().size() == 2) {
											 if(dkjl.getSort() == 2) {
												 ash.setIsupdate(1);
											 }
ilal committed
3083 3084 3085 3086 3087 3088 3089 3090
										 }else if(attdate.getAttsch().size() == 4) {
											 if(dkjl.getSort() == 4) {
												 ash.setIsupdate(1);
											 }
										 }else if(attdate.getAttsch().size() == 6) {
											 if(dkjl.getSort() == 6) {
												 ash.setIsupdate(1);
											 }
ilal committed
3091 3092 3093
										 }
									 }
									 
ilal committed
3094
									 if(bcsz != null && (dkjl.getSort())%2 > 0) {
ilal committed
3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111
										 int yxcdfzs = bcsz.getYxcdfzs();//允许迟到分钟数
										 int yzcdfzs = bcsz.getYzcdfzs();//严重迟到分钟数
										 int kgcdfzs = bcsz.getKgcdfzs();//旷工迟到分钟数
										 //允许迟到范围
										 if(results < yxcdfzs) {
											 dkjl.setResults(0);
											 if(dkjl.getStatus() == 3) {//原本是迟到的  但是在“允许迟到”范围内  则更改为正常
												 dkjl.setStatus(1);
											 }
										 }
										 //严重迟到范围
										 if(results>yzcdfzs && results < kgcdfzs && yzcdfzs>0) {
											 dkjl.setStatus(15);//严重迟到
										 }
										 //旷工迟到
										 if(results>kgcdfzs && kgcdfzs>0) {
											 dkjl.setStatus(16);//旷工迟到
ilal committed
3112
										 }
ilal committed
3113
									 }
ilal committed
3114 3115 3116 3117 3118 3119
									 
									 if(bsz == 1) {
										 bc++;
										 ash.setIsdk(1);
									 }else {
										 ash.setIsdk(1);
ilal committed
3120
									 }
ilal committed
3121 3122
								 }else if(ash.getSort() == daj.getSort()){
									 BeanUtil.copyProperties(daj, dkjl,"attdate","remarks","userId","attime","dkmxid","commentary","punchequipment","punchmode");
ilal committed
3123
								 }
ilal committed
3124 3125 3126 3127 3128 3129
							 }
							 
							 KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ash.getId()));
							 Timestamp tt = Timestamp.valueOf(ClockInTool.stampToDate(String.valueOf(ash.getTime())));
							 //处理下班不用打卡的数据
							 if(shif.getIsXbdk() == 1 && (ash.getSort())%2 == 0) { 
ilal committed
3130
								 
ilal committed
3131 3132 3133 3134 3135 3136 3137
								 if(dkjl.getDktime() == null && b.after(tt)) {
									 dkjl.setDktime(ash.getTime());
									 dkjl.setStatus(1);
									 dkjl.setSort(ash.getSort());
									 dkjl.setId(999);
								 }else if(dkjl.getDktime() != null){
									 dkjl.setStatus(1);
lal committed
3138
								 }
lal committed
3139
							 }
ilal committed
3140
							 //处理当天完全没打卡的数据
ilal committed
3141
							 if(ash.getIsdk() == 1 && b.after(tt) && dkcs == 0 && iscrdk && dkjl.getCardType() == null) {
ilal committed
3142 3143 3144 3145 3146 3147
								 dkjl.setDktime(null);
								 dkjl.setStatus(17);//缺卡
								 dkjl.setSort(ash.getSort());
								 dkjl.setId(888);
								 //更新打卡关闭
								 ash.setIsupdate(0);
ilal committed
3148
								 ash.setIsdk(1);
ilal committed
3149
							 }
ilal committed
3150
							 
ilal committed
3151
							 //
ilal committed
3152
							 if(ash.getIsdk() == 1 && b.after(tt) && dkjl.getDktime() == null && dkjl.getId() == null && dkcs > 0 && iscrdk) {
ilal committed
3153
								 dkjl.setStatus(17);//缺卡
ilal committed
3154
								 dkjl.setSort(ash.getSort());
ilal committed
3155
								 dkjl.setId(888);
ilal committed
3156 3157
								 //更新打卡关闭
								 ash.setIsupdate(0);
ilal committed
3158
								 ash.setIsdk(1);
ilal committed
3159 3160 3161 3162
							 }else if(ash.getIsdk() == 1 && b.after(tt) && dkjl.getDktime() == null && dkjl.getId() == null){
								 dkjl.setStatus(17);//缺卡
								 dkjl.setSort(ash.getSort());
								 dkjl.setId(888);
ilal committed
3163
							 }
ilal committed
3164
							 
ilal committed
3165
							 
ilal committed
3166
							 ash.setDajl(dkjl);//班次信息中插入打卡打卡 数据
ilal committed
3167
							 /****/
ilal committed
3168 3169
								//事务(请假,加班,调休,出差)
		 		    			KqglAssoRelationSummary asssum1 = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, userBean.getEmpNum())
ilal committed
3170
				    						.eq(KqglAssoRelationSummary::getAppTime, str).eq(KqglAssoRelationSummary::getOrgCode, userBean.getOrgCode()).last("LIMIT 1"));
ilal committed
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192
			    				if(asssum1 != null) {
			    					
			    					if(asssum1.getApprovalType() != 5) {
			 		    				String startTime = asssum1.getStartTime();//
			 		    				String endTime = asssum1.getEndTime();//
			 		    				if(ash.getDajl().getCardType() != null) {
			 		    					boolean affair = ClockInTool.hourMinuteBetween(ClockInTool.stampToDate(String.valueOf(ash.getDajl().getDktime())), startTime, endTime,"yyyy-MM-dd HH:mm:ss");
			 		    					if(affair && ash.getDajl().getStatus() != 9 && ash.getDajl().getStatus() != 10 && ash.getDajl().getStatus() != 11
			 		    							&& ash.getDajl().getStatus() != 12 && ash.getDajl().getStatus() != 13 && ash.getDajl().getStatus() != 14) {
			 		    						ash.getDajl().setStatus(1);
			 		    					}
			 		    				}
			 		    			}
			    					
			    					//0:无;1:事假;2:调休;3:病假;4:年假;5:产假;6:陪产假;7:婚假;8:例假;9:丧假;10:哺乳假;11:加班;12:出差;13:外出
			    					if(asssum1.getApprovalType() == 1) {
			    						dkjl.setCalendar_status_type(11);
			    						
			    						ash.setCalendar_status_type(11);
			    					}else if(asssum1.getApprovalType() == 2) {
			    						//请假
			    						KqglAssoLeaveRules rul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getId,asssum1.getLeaveTypeId()));
ilal committed
3193
			    						if(rul.getRulesType() != null) {
ilal committed
3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229
				    						if(rul.getRulesType() == 1) {
				    							dkjl.setCalendar_status_type(1);
				    							ash.setCalendar_status_type(1);
				    						}else if(rul.getRulesType() == 2) {
				    							dkjl.setCalendar_status_type(2);
				    							ash.setCalendar_status_type(2);
				    						}else if(rul.getRulesType() == 3) {
				    							dkjl.setCalendar_status_type(3);
				    							ash.setCalendar_status_type(3);
				    						}else if(rul.getRulesType() == 4) {
				    							dkjl.setCalendar_status_type(4);
				    							ash.setCalendar_status_type(4);
				    						}else if(rul.getRulesType() == 5) {
				    							dkjl.setCalendar_status_type(5);
				    							ash.setCalendar_status_type(5);
				    						}else if(rul.getRulesType() == 6) {
				    							dkjl.setCalendar_status_type(6);
				    							ash.setCalendar_status_type(6);
				    						}else if(rul.getRulesType() == 7) {
				    							dkjl.setCalendar_status_type(7);
				    							ash.setCalendar_status_type(7);
				    						}else if(rul.getRulesType() == 8) {
				    							dkjl.setCalendar_status_type(8);
				    							ash.setCalendar_status_type(8);
				    						}else if(rul.getRulesType() == 9) {
				    							dkjl.setCalendar_status_type(9);
				    							ash.setCalendar_status_type(9);
				    						}else if(rul.getRulesType() == 10) {
				    							dkjl.setCalendar_status_type(10);
				    							ash.setCalendar_status_type(10);
				    						}
			    						}else {
			    							dkjl.setCalendar_status_type(-1);
			    							dkjl.setCalendar_status_name(rul.getName());
			    							ash.setCalendar_status_type(-1);
			    							dkjl.setCalendar_status_name(rul.getName());
ilal committed
3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241
			    						}
			    					}else if(asssum1.getApprovalType() == 3) {
			    						dkjl.setCalendar_status_type(12);
			    						ash.setCalendar_status_type(12);
			    					}else if(asssum1.getApprovalType() == 4) {
			    						dkjl.setCalendar_status_type(13);
			    						ash.setCalendar_status_type(13);
			    					}
			    				}else {
			    					dkjl.setCalendar_status_type(0);
			    					ash.setCalendar_status_type(0);
			    				}
ilal committed
3242 3243
								 /****/
							 
ilal committed
3244
//							 ash.setDajl(dkjl);//班次信息中插入打卡打卡 数据
ilal committed
3245
						 }
lal committed
3246
					 }
ilal committed
3247 3248
					 
					 
ilal committed
3249
					 boolean lcdkgb = true;
ilal committed
3250
					 if(attdate.getAttsch().size() == 2 && dkcs == 2 && now.equals(str)) {
ilal committed
3251 3252 3253 3254 3255 3256
						 lcdkgb = false;
						 
						 KqglAssoDkjl dk = KqglAssoDkjl.builder().build().selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getQyid, userBean.getOrgCode())
								 .eq(KqglAssoDkjl::getUserId, userBean.getEmpNum()).ge(KqglAssoDkjl::getDktime, startDate).le(KqglAssoDkjl::getDktime, endDate)
								 .ne(KqglAssoDkjl::getSort, 0).ne(KqglAssoDkjl::getStatus, 2).ne(KqglAssoDkjl::getStatus, 0)
								 .orderByDesc(KqglAssoDkjl::getSort).last("LIMIT 1"));
ilal committed
3257 3258 3259 3260 3261 3262 3263
						 if(dk != null) {
							 AttSchedule att = attsch.get(dk.getSort()-1);
							 att.setIsupdate(1);
							 
							 AttSchedule attw = attsch.get(dk.getSort()-2);
							 attw.setIsupdate(0);
						 }
ilal committed
3264
					 }
lal committed
3265
					 
ilal committed
3266
					 //全部为缺卡时 没有打卡按钮显示
ilal committed
3267
					 if(attsch.get(0).getDajl().getId() != null && iscrdk) {
ilal committed
3268
						 if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
ilal committed
3269 3270
							 if(attsch.get(0).getDajl().getId() != null && attsch.get(0).getDajl().getId() == 888 && attsch.get(0).getDajl().getStatus() == 17
								&& attsch.get(1).getDajl().getId() != null && attsch.get(1).getDajl().getId() == 888 && attsch.get(1).getDajl().getStatus() == 17) {
ilal committed
3271 3272 3273
								 lcdkgb = false;
							 }
						 }else if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
ilal committed
3274 3275 3276 3277
							 if(attsch.get(2).getDajl().getId() != null && attsch.get(2).getDajl().getId() == 888 && attsch.get(2).getDajl().getStatus() == 17
								&& attsch.get(3).getDajl().getId() != null && attsch.get(3).getDajl().getId() == 888 && attsch.get(3).getDajl().getStatus() == 17) {
								 lcdkgb = false;
							 }
ilal committed
3278
						 }else if(attdate.getAttsch().size() == 6) {
ilal committed
3279 3280 3281 3282
							 if(attsch.get(4).getDajl().getId() != null && attsch.get(4).getDajl().getId() == 888 && attsch.get(4).getDajl().getStatus() == 17
								&& attsch.get(5).getDajl().getId()!= null && attsch.get(5).getDajl().getId() == 888 && attsch.get(5).getDajl().getStatus() == 17) {
								 lcdkgb = false;
							 }
ilal committed
3283 3284 3285
						 }
					 }
					 
ilal committed
3286
					 //当天最后一个班打完后  打卡按钮全部不显示(没打卡的显示缺卡)
ilal committed
3287 3288 3289 3290
					 boolean isdkjj = true;
					 if(attdate.getAttsch().size() == 2) {
						 if(attsch.get(1).getDajl().getId() != null && attsch.get(1).getDajl().getDktime() != null) {
							 isdkjj = false;
ilal committed
3291 3292 3293 3294 3295 3296 3297 3298
							 if(attsch.get(0).getDajl().getId() == null && attsch.get(0).getDajl().getDktime() == null) {
								 attsch.get(0).getDajl().setDktime(null);
								 attsch.get(0).getDajl().setStatus(17);//缺卡
								 attsch.get(0).getDajl().setSort(attdate.getAttsch().get(0).getSort());
								 attsch.get(0).getDajl().setId(888);
								 
								 attdate.getAttsch().get(0).setIsdk(1);
							 }
ilal committed
3299 3300 3301 3302
						 }
					 }else if(attdate.getAttsch().size() == 4) {
						 if(attsch.get(3).getDajl().getId() != null && attsch.get(3).getDajl().getDktime() != null) {
							 isdkjj = false;
ilal committed
3303 3304 3305 3306 3307 3308 3309 3310 3311 3312
							 
							 if(attsch.get(0).getDajl().getId() == null && attsch.get(0).getDajl().getDktime() == null) {
								 attsch.get(0).getDajl().setDktime(null);
								 attsch.get(0).getDajl().setStatus(17);//缺卡
								 attsch.get(0).getDajl().setSort(attdate.getAttsch().get(0).getSort());
								 attsch.get(0).getDajl().setId(888);
								 
								 attdate.getAttsch().get(0).setIsdk(1);
							 }
							 
ilal committed
3313
							 if(attsch.get(1).getDajl().getId() == null && attsch.get(1).getDajl().getDktime() == null && attsch.get(1).getDajl().getId() != 999) {
ilal committed
3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329
								 attsch.get(1).getDajl().setDktime(null);
								 attsch.get(1).getDajl().setStatus(17);//缺卡
								 attsch.get(1).getDajl().setSort(attdate.getAttsch().get(1).getSort());
								 attsch.get(1).getDajl().setId(888);
								 
								 attdate.getAttsch().get(1).setIsdk(1);
							 }
							 
							 if(attsch.get(2).getDajl().getId() == null && attsch.get(2).getDajl().getDktime() == null) {
								 attsch.get(2).getDajl().setDktime(null);
								 attsch.get(2).getDajl().setStatus(17);//缺卡
								 attsch.get(2).getDajl().setSort(attdate.getAttsch().get(2).getSort());
								 attsch.get(2).getDajl().setId(888);
								 
								 attdate.getAttsch().get(2).setIsdk(1);
							 }
ilal committed
3330 3331 3332 3333
						 }
					 }else if(attdate.getAttsch().size() == 6) {
						 if(attsch.get(5).getDajl().getId() != null && attsch.get(5).getDajl().getDktime() != null) {
							 isdkjj = false;
ilal committed
3334 3335 3336 3337 3338 3339 3340 3341
							 
							 if(attsch.get(0).getDajl().getId() == null && attsch.get(0).getDajl().getDktime() == null) {
								 attsch.get(0).getDajl().setDktime(null);
								 attsch.get(0).getDajl().setStatus(17);//缺卡
								 attsch.get(0).getDajl().setSort(attdate.getAttsch().get(0).getSort());
								 attsch.get(0).getDajl().setId(888);
								 attdate.getAttsch().get(0).setIsdk(1);
							 }
ilal committed
3342
							 if(attsch.get(1).getDajl().getId() == null && attsch.get(1).getDajl().getDktime() == null && attsch.get(1).getDajl().getId() != 999) {
ilal committed
3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355
								 attsch.get(1).getDajl().setDktime(null);
								 attsch.get(1).getDajl().setStatus(17);//缺卡
								 attsch.get(1).getDajl().setSort(attdate.getAttsch().get(1).getSort());
								 attsch.get(1).getDajl().setId(888);
								 attdate.getAttsch().get(1).setIsdk(1);
							 }
							 if(attsch.get(2).getDajl().getId() == null && attsch.get(2).getDajl().getDktime() == null) {
								 attsch.get(2).getDajl().setDktime(null);
								 attsch.get(2).getDajl().setStatus(17);//缺卡
								 attsch.get(2).getDajl().setSort(attdate.getAttsch().get(2).getSort());
								 attsch.get(2).getDajl().setId(888);
								 attdate.getAttsch().get(2).setIsdk(1);
							 }
ilal committed
3356
							 if(attsch.get(3).getDajl().getId() == null && attsch.get(3).getDajl().getDktime() == null && attsch.get(3).getDajl().getId() != 999) {
ilal committed
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369
								 attsch.get(3).getDajl().setDktime(null);
								 attsch.get(3).getDajl().setStatus(17);//缺卡
								 attsch.get(3).getDajl().setSort(attdate.getAttsch().get(3).getSort());
								 attsch.get(3).getDajl().setId(888);
								 attdate.getAttsch().get(3).setIsdk(1);
							 }
							 if(attsch.get(4).getDajl().getId() == null && attsch.get(4).getDajl().getDktime() == null) {
								 attsch.get(4).getDajl().setDktime(null);
								 attsch.get(4).getDajl().setStatus(17);//缺卡
								 attsch.get(4).getDajl().setSort(attdate.getAttsch().get(4).getSort());
								 attsch.get(4).getDajl().setId(888);
								 attdate.getAttsch().get(4).setIsdk(1);
							 }
ilal committed
3370 3371
						 }
					 }
ilal committed
3372
					 
ilal committed
3373
//					 System.out.println(attsch.get(attdate.getAttsch().size()-1).getTime());
ilal committed
3374
					 
ilal committed
3375
					 //全部为 1 时 iscrdk
ilal committed
3376
					 if(bccs == bc && b.before(d) && lcdkgb && isdkjj) {
lal committed
3377
						 KqglAssoDkjl dk = KqglAssoDkjl.builder().build().selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getQyid, userBean.getOrgCode())
lal committed
3378 3379 3380 3381
								 .eq(KqglAssoDkjl::getUserId, userBean.getEmpNum()).ge(KqglAssoDkjl::getDktime, startDate).le(KqglAssoDkjl::getDktime, endDate)
								 .ne(KqglAssoDkjl::getSort, 0).ne(KqglAssoDkjl::getStatus, 2).ne(KqglAssoDkjl::getStatus, 0)
								 .orderByDesc(KqglAssoDkjl::getSort).last("LIMIT 1"));
						 
lal committed
3382
						 if(dk != null && attdate.getAttsch().size() != dk.getSort()) {
ilal committed
3383
							 AttSchedule att = attsch.get(dk.getSort()-cr);
ilal committed
3384 3385
							 if(att.getDajl().getId() != null && att.getDajl().getStatus() != 17 && att.getDajl().getId() != 888) {
								 att.setIsdk(0);
ilal committed
3386 3387 3388
								 
								 AttSchedule attw = attsch.get(dk.getSort()-1);
								 attw.setIsupdate(1);
ilal committed
3389 3390 3391
							 }else {
								 AttSchedule att1 = attsch.get(dk.getSort()+cr);
								 att1.setIsdk(0);
ilal committed
3392 3393 3394
								 
								 AttSchedule attw = attsch.get(dk.getSort()+cr-1);
								 attw.setIsupdate(1);
ilal committed
3395
							 }
lal committed
3396
						 }else {
ilal committed
3397
							 if(iscrdk) {
ilal committed
3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429
								 if(attdate.getAttsch().size() == 2) {
									 AttSchedule attc = attsch.get(0);
									 AttSchedule attcto = attsch.get(1);
									 Timestamp tt1 = Timestamp.valueOf(ClockInTool.stampToDate(String.valueOf(attsch.get(0).getTime())));
									 Timestamp tt2 = Timestamp.valueOf(ClockInTool.stampToDate(String.valueOf(attsch.get(1).getTime())));
									 if(!dk1 && dk2) {
										 attc.getDajl().setStatus(17);//缺卡
										 attc.getDajl().setSort(attc.getSort());
										 attc.getDajl().setId(888);
										 attc.setIsdk(1);
									 }
									 if(!dk1 && !dk2 && b.after(tt1) && b.before(tt2)) {
										 attcto.getDajl().setStatus(null);//缺卡
										 attcto.getDajl().setSort(null);
										 attcto.getDajl().setId(null);
										 attcto.setIsdk(0);
									 }
									 if(!dk1 && !dk2 && b.after(tt1) && b.after(tt2)) {
										 attcto.getDajl().setStatus(17);//缺卡
										 attcto.getDajl().setSort(attc.getSort());
										 attcto.getDajl().setId(888);
										 attcto.setIsdk(1);
									 }
								 }else if(attdate.getAttsch().size() == 4) {
									 
									 AttSchedule attc = attsch.get(0);
									 if(attc.getDajl().getId() != null && attc.getDajl().getStatus() == 17 && attc.getDajl().getId() == 888) {
										 attc.getDajl().setId(null);
										 attc.getDajl().setSort(null);
										 attc.getDajl().setStatus(null);
									 }
									 attc.setIsdk(0);
ilal committed
3430
								 }
ilal committed
3431
							 }else {
ilal committed
3432 3433 3434 3435
								 if(crlasttime != null) {
									 Timestamp dd = Timestamp.valueOf(crlasttime);
									 if(dd.after(b)) {//after:大于  before:小于
										 AttSchedule attc = attsch.get(0);
ilal committed
3436 3437 3438 3439 3440
										 if(attc.getDajl().getId() != null && attc.getDajl().getStatus() == 17 && attc.getDajl().getId() == 888) {
											 attc.getDajl().setId(null);
											 attc.getDajl().setSort(null);
											 attc.getDajl().setStatus(null);
										}
ilal committed
3441 3442 3443
										 attc.setIsdk(0);
								 	 }else {
								 		AttSchedule attc = attsch.get(cr);
ilal committed
3444 3445 3446 3447 3448 3449 3450 3451 3452 3453
								 		Timestamp ag = Timestamp.valueOf(ClockInTool.stampToDate(String.valueOf(attc.getTime())));
								 		if(ag.after(b)) {
								 			if(attc.getDajl().getId() != null && attc.getDajl().getStatus() == 17 && attc.getDajl().getId() == 888) {
												 attc.getDajl().setId(null);
												 attc.getDajl().setSort(null);
												 attc.getDajl().setStatus(null);
											}
											 attc.setIsdk(0);
								 		}
								 		
ilal committed
3454 3455 3456
								 	 }
								 }
								 
ilal committed
3457 3458
							 }
							 
lal committed
3459
						 }
ilal committed
3460
						 
ilal committed
3461 3462 3463 3464 3465 3466 3467 3468
						 //没有打卡按钮时
						 for(int y=0;y<bc;y++) {
							 AttSchedule attc = attsch.get(y);
							 if(attc.getDajl().getCardType() == null && attc.getDajl().getId() == null && attc.getDajl().getStatus() == null) {
								 attc.setIsdk(0);
								 break;
							 }
						 }
lal committed
3469
					 }
ilal committed
3470
					 
lal committed
3471 3472
				 }else {
					 //休息的时候
ilal committed
3473 3474 3475
//					 List<AttSchedule> attsch_ = new ArrayList<AttSchedule>();
//					 attdate.setAttsch(attsch_);
					 
lal committed
3476
					 List<AttSchedule> attsch_ = new ArrayList<AttSchedule>();
ilal committed
3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507
					 
					 if(dajllist_.size() > 0) {
						 for(int i=1;i<=dajllist_.size();i++){
							 KqglAssoDkjl dkjl = KqglAssoDkjl.builder().build();
							 BeanUtil.copyProperties(dajllist_.get(i-1), dkjl,"attdate","bcid","remarks","userId","attime","dkmxid","commentary","punchequipment","punchmode");
							 AttSchedule ast = AttSchedule.builder().build();
							 ast.setId(0);
							 ast.setIsdk(1);
							 ast.setDajl(dkjl);
							 ast.setSort(i);
							 attsch_.add(ast);
							 attdate.setAttsch(attsch_);
						 }
						 KqglAssoDkjl dkjj_ = KqglAssoDkjl.builder().build();
						 AttSchedule ast_ = AttSchedule.builder().build();
						 ast_.setId(0);
						 ast_.setIsdk(0);
						 ast_.setDajl(dkjj_);
						 ast_.setSort(dajllist_.size() + 1);
						 attsch_.add(ast_);
						 attdate.setAttsch(attsch_);
					 }else {
						 KqglAssoDkjl dkjj = KqglAssoDkjl.builder().build();
						 AttSchedule ast = AttSchedule.builder().build();
						 ast.setId(0);
						 ast.setIsdk(0);
						 ast.setDajl(dkjj);
						 ast.setSort(1);
						 attsch_.add(ast);
						 attdate.setAttsch(attsch_);
					 }
lal committed
3508
				 }
lal committed
3509 3510
				 
				 
lal committed
3511 3512 3513 3514
			 }else {
				 //自由工时
				 List<AttSchedule> attsch = new ArrayList<AttSchedule>();
				 
lal committed
3515
				 if(dajllist_.size() > 0) {
ilal committed
3516
					 for(int i=1;i<=dajllist_.size();i++){
ilal committed
3517
						 KqglAssoDkjl dkjl = KqglAssoDkjl.builder().build();
ilal committed
3518
						 BeanUtil.copyProperties(dajllist_.get(i-1), dkjl,"attdate","bcid","remarks","userId","attime","dkmxid","commentary","punchequipment","punchmode");
ilal committed
3519 3520 3521 3522 3523 3524 3525
						 AttSchedule ast = AttSchedule.builder().build();
						 ast.setId(0);
						 ast.setIsdk(1);
						 ast.setDajl(dkjl);
						 ast.setSort(i);
						 attsch.add(ast);
						 attdate.setAttsch(attsch);
lal committed
3526
					 }
ilal committed
3527 3528 3529 3530 3531 3532 3533 3534 3535 3536
					 KqglAssoDkjl dkjj_ = KqglAssoDkjl.builder().build();
					 AttSchedule ast_ = AttSchedule.builder().build();
					 ast_.setId(0);
					 ast_.setIsdk(0);
					 ast_.setDajl(dkjj_);
					 ast_.setSort(dajllist_.size() + 1);
					 attsch.add(ast_);
					 attdate.setAttsch(attsch);
				 }else {
					 KqglAssoDkjl dkjj = KqglAssoDkjl.builder().build();
lal committed
3537 3538
					 AttSchedule ast = AttSchedule.builder().build();
					 ast.setId(0);
ilal committed
3539 3540 3541
					 ast.setIsdk(0);
					 ast.setDajl(dkjj);
					 ast.setSort(1);
lal committed
3542 3543 3544
					 attsch.add(ast);
					 attdate.setAttsch(attsch);
				 }
lal committed
3545 3546
			 }
			 
ilal committed
3547 3548 3549
			 List<TransactionApprovalDto> tranappr = new ArrayList<TransactionApprovalDto>();
			 //事务审批单
			 List<KqglAssoRelationSummary> trap = KqglAssoRelationSummary.builder().build().selectList(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, userBean.getEmpNum())
ilal committed
3550
						.eq(KqglAssoRelationSummary::getAppTime, str).eq(KqglAssoRelationSummary::getOrgCode, userBean.getOrgCode()));
ilal committed
3551 3552
			 if(trap.size() > 0) {
				 for(KqglAssoRelationSummary spnsw : trap) {
ilal committed
3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596
					 if(spnsw.getApprovalType() != 5) {
						 TransactionApprovalDto taap = TransactionApprovalDto.builder().build();
						 
						 if(spnsw.getApprovalType() == 1) {
							 taap.setCalendar_status_type(11);
	 					 }else if(spnsw.getApprovalType() == 2) {
							 KqglAssoLeaveRules rul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getId,spnsw.getLeaveTypeId()));
						 	if(rul.getRulesType() != null) {
								if(rul.getRulesType() == 1) {
							 		taap.setCalendar_status_type(1);
								}else if(rul.getRulesType() == 2) {
									taap.setCalendar_status_type(2);
								}else if(rul.getRulesType() == 3) {
									taap.setCalendar_status_type(3);
								}else if(rul.getRulesType() == 4) {
									taap.setCalendar_status_type(4);
								}else if(rul.getRulesType() == 5) {
									taap.setCalendar_status_type(5);
								}else if(rul.getRulesType() == 6) {
									taap.setCalendar_status_type(6);
								}else if(rul.getRulesType() == 7) {
									taap.setCalendar_status_type(7);
								}else if(rul.getRulesType() == 8) {
									taap.setCalendar_status_type(8);
								}else if(rul.getRulesType() == 9) {
									taap.setCalendar_status_type(9);
								}else if(rul.getRulesType() == 10) {
									taap.setCalendar_status_type(10);
								}
						 	}else {
						 		taap.setCalendar_status_type(-1);
						 		taap.setCalendar_status_name(rul.getName());
						 	}
						}else if(spnsw.getApprovalType() == 3) {
							taap.setCalendar_status_type(12);
	 					}else if(spnsw.getApprovalType() == 4) {
	 						taap.setCalendar_status_type(13);
	 					}
						 
						 taap.setApproval_form(spnsw.getApprovalId());
						 tranappr.add(taap);	
						 
						 attdate.setTranappr(tranappr);
					 }
ilal committed
3597 3598 3599 3600 3601 3602
				 }
			 }else {
				 attdate.setTranappr(tranappr);
			 }
			 
			 
lal committed
3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629
			   //外勤   true:开   false:关
			    if(attgro.getIsWq() == 1) {
			    	attdate.setFieldpersonnel(true);
			    }else {
			    	attdate.setFieldpersonnel(false);
			    }
			    
				//打卡方式
			    List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodemapper.selectByPrimaryByKqzId(attgro.getId());
			    for(AttGroupBinPunchMode agbp:attmetlist){
			    	//类型(1:考勤机;2:地址;3:WIFI)
			    	if(agbp.getType() == 1){
			    		attdate.setAttmachine(true);
			    	}else if(agbp.getType() == 2){
			    		attdate.setAttaddress(true);
			    	}else{
			    		attdate.setAttwifi(true);
			    	}
			    }
			    
			    //详细打卡方式
			    List<AttClockMethod> akms = new ArrayList<AttClockMethod>();
			    
			    for(AttGroupBinPunchMode abp:attmetlist){
			    	if(abp.getType() == 1){
			    		AttendanceMachine kqjs = attendancemachinemapper.selectByPrimaryKey(abp.getDkfsid()); 
			    		AttClockMethod akm = AttClockMethod.builder().build();
ilal committed
3630 3631 3632 3633 3634 3635 3636 3637
			    		if(kqjs != null) {
				    		akm.setName(kqjs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(1);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
			    		}
lal committed
3638 3639 3640 3641
			    		akms.add(akm);
			    	}else if(abp.getType() == 2){
			    		PunchCardAddress kqdzs = punchcardaddressmapper.selectByPrimaryKey(abp.getDkfsid()); 
			    		AttClockMethod akm = AttClockMethod.builder().build();
ilal committed
3642 3643 3644 3645 3646 3647 3648 3649
			    		if(kqdzs != null) {
				    		akm.setName(kqdzs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(kqdzs.getDkfw());// 范围【地址】
				    		akm.setType(2);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(kqdzs.getLon());// 经度【地址】
				    		akm.setLatitude(kqdzs.getLat());// 纬度【地址】
				    	}
lal committed
3650 3651 3652 3653
			    		akms.add(akm);
			    	}else{
			    		PunchCardWiFi kqwfs = punchcardwifimapper.selectByPrimaryKey(abp.getDkfsid()); 
			    		AttClockMethod akm = AttClockMethod.builder().build();
ilal committed
3654 3655 3656 3657 3658 3659 3660 3661
			    		if(kqwfs != null) {
				    		akm.setName(kqwfs.getName());// 打卡名称
				    		akm.setMac(kqwfs.getMac());// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(3);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
			    		}
lal committed
3662 3663 3664 3665 3666 3667 3668 3669 3670 3671
			    		akms.add(akm);
			    	}
			    }
			    attdate.setMachine(akms);
			    
		     
		    //当天第一次打卡 前一天晚走小时**************************************************
		     double latetime_ = 0;//前天晚走时长(分钟)
		     Long changed_time = 0l;//晚到后应打卡时间
		     
lal committed
3672 3673
		     if(attdate.getAttgrouptype() != 3) {
		    	 List<AttSchedule> ash = attdate.getAttsch();
lal committed
3674 3675 3676 3677 3678 3679 3680
		    	 if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && ash.get(0).getId() != 0) {
		    		 KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ash.get(0).getId()));
					 
				     if(shif != null) {
						int dkcs_ = shif.getSxbcs();//上下班打卡次数
						int iswzwd = shif.getIsWzwd();//是否开启晚走晚到(0:否;1:是)
						
lal committed
3681
						//统一分钟数
lal committed
3682 3683 3684 3685 3686 3687 3688 3689 3690 3691
						double xbwz1 = 0,xbwz2=0,xbwz3=0;
						int sbwd1=0,sbwd2=0,sbwd3=0;
						
						int arrive_late = 0;//晚到时间
						String clock_date = "";//应打卡时间
						Long latetime = 0l;//前天晚走时长(分钟)
						
						KqglAssoDkmx yesterdaymx = KqglAssoDkmx.builder().build();
						AttendanceCardListDto attdateyesterday;
						long yesendtime1=0,yesendtime2=0,yesendtime3=0;
lal committed
3692
						String regex = "(\\d+)(?:(\\.\\d*[^0])|\\.)0*";
lal committed
3693 3694 3695 3696
						//存在晚走玩到
						 if(iswzwd > 0) {
							//统一分钟数
							xbwz1 = Double.valueOf(shif.getXbwz1()) * 60;//下班晚走1
lal committed
3697 3698 3699 3700
							
							String as = String.valueOf(Double.valueOf(shif.getSbwd1()) * 60);
							sbwd1 = Integer.valueOf(as.replaceAll(regex, "$1$2"));//上班晚到1
							
lal committed
3701
							xbwz2 = Double.valueOf(shif.getXbwz2()) * 60;//下班晚走2
lal committed
3702 3703
							String qw = String.valueOf(Double.valueOf(shif.getSbwd2()) * 60);
							sbwd2 = Integer.valueOf(qw.replaceAll(regex, "$1$2"));//上班晚到2
lal committed
3704
							xbwz3 = Double.valueOf(shif.getXbwz3()) * 60;//下班晚走3
lal committed
3705 3706 3707
							
							String ed = String.valueOf(Double.valueOf(shif.getSbwd3()) * 60);
							sbwd3 = Integer.valueOf(ed.replaceAll(regex, "$1$2"));//上班晚到3
lal committed
3708 3709 3710
							 
							 //获取前一天最后下班的时间
							 yesterdaymx = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userBean.getEmpNum())
ilal committed
3711
										.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday).eq(KqglAssoDkmx::getQyid, userBean.getOrgCode()));
lal committed
3712 3713 3714 3715 3716
							 attdateyesterday = MethodCall(userBean.getOrgCode(),userBean.getEmpNum(),yesterday);
							 
							 List<AttSchedule> ashyes = attdateyesterday.getAttsch();
							 if(attdateyesterday.getAttsch().size() == 2 || attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
								 yesendtime1 = ashyes.get(1).getTime();
lal committed
3717
							 }
lal committed
3718 3719
						 	 if(attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
						 		yesendtime2 = ashyes.get(3).getTime();
lal committed
3720
							 }
lal committed
3721 3722 3723
						 	 if(attdateyesterday.getAttsch().size() == 6) {
						 		yesendtime3 = ashyes.get(5).getTime();
							  }
lal committed
3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737
						 	 
						 	 if(yesterdaymx != null) {
						 		 if(dkcs_ == 1) {
									 if(yesterdaymx.getXbdk1() != null && yesterdaymx.getXbdk1jg() == 0) {
										 latetime = (yesterdaymx.getXbdk1() - yesendtime1)/1000/60;
									 }
								 }else if(dkcs_ == 2){
									 if(yesterdaymx.getXbdk2() != null && yesterdaymx.getXbdk2jg() == 0) {
										 latetime = (yesterdaymx.getXbdk2() - yesendtime2)/1000/60;
									 }
								 }else {
									 if(yesterdaymx.getXbdk3() != null && yesterdaymx.getXbdk3jg() == 0) {
										 latetime = (yesterdaymx.getXbdk3() - yesendtime3)/1000/60;
									 }
lal committed
3738
								 }
lal committed
3739 3740
						 	 }
							 
lal committed
3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752
							 if(latetime != 0) {
								 latetime_ = Double.valueOf(String.valueOf(latetime));//前天晚走时长(分钟)
								 if(latetime_ > xbwz1 && latetime_ < xbwz2) {
									 arrive_late = sbwd1;
								 }else if(latetime_ > xbwz2 && latetime_ < xbwz3) {
									 arrive_late = sbwd2;
								 }else if(latetime_ > xbwz3) {
									 arrive_late = sbwd3;
								 }
								 //ash.get(0).getTime():当天第一次应打卡时间
								 clock_date = ClockInTool.stampToDate(String.valueOf(ash.get(0).getTime()));
								 changed_time = Long.valueOf(ClockInTool.dateToStamp(ClockInTool.addtime(clock_date, "+"+arrive_late)));//晚到后应打卡时间
lal committed
3753
							 }
lal committed
3754
						 }
lal committed
3755 3756 3757 3758 3759
						 attdate.setLatetime(latetime_);
						 attdate.setChanged_time(changed_time);
				     }
		    	 }
			     
lal committed
3760
		     }
lal committed
3761
		     
lal committed
3762 3763 3764 3765 3766 3767
			return ResultUtil.data(attdate);
		 }else {
			 
			 AttendanceCardListDto attdate_ = AttendanceCardListDto.builder().build();
			 
			 return ResultUtil.data(attdate_,"未加入考勤组");
lal committed
3768 3769
		 }
	 }
lal committed
3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801
	 
	 
	 private SimpleDateFormat mat = new SimpleDateFormat("yyyy-MM-dd");
	 
	    @Autowired
		private KqglAssoTeshuMapper kqglassoteshumapper;
	    @Autowired
		private AttendanceWeeklySchMapper attendanceweeklyschmapper;
	    @Autowired
		private ScheduleMapper schedulemapper;
	   /**
		 * 	APP 手机日历数据
		 * @param userBean
		 * @return
		 * @throws ParseException 
		 */
		@GetMapping(value = "/workbench_calendar/{date}")
		@ApiOperation(value = "手机日历数据", httpMethod = "GET", notes = "查询数据")
		public Result<Object> Workbench_calendar(@CurrentUser UserBean userBean,@PathVariable("date") String date) throws ParseException {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式  
			
			String current = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
			String yue = new SimpleDateFormat("yyyy-MM").format(new Date());
			
			SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM");
	        Date date_;
	        try {
	        	date_ = df1.parse(date);
	        }catch (ParseException e){
	            e.printStackTrace();
	            date_=new Date();
	        }
ilal committed
3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817
//	        int dateOne= ClockInTool.getYearMonth(date_);
	        
	        // 准备第一个模板,从字符串中提取出日期数字    
	        String pat1 = "yyyy-MM" ;    
	        String pat = "yyyyMM";
	        SimpleDateFormat sdfi = new SimpleDateFormat(pat1) ;        // 实例化模板对象    
	        SimpleDateFormat sdf = new SimpleDateFormat(pat) ;        // 实例化模板对象    
	        Date d = null ;    
	        try{    
	            d = sdfi.parse(date) ;   // 将给定的字符串中的日期提取出来    
	        }catch(Exception e){            // 如果提供的字符串格式有错误,则进行异常处理    
	            e.printStackTrace() ;       // 打印异常信息    
	        }    
	        
	        int dateOne = Integer.valueOf(sdf.format(d));
	        int dangqian = Integer.valueOf(new SimpleDateFormat("yyyyMM").format(new Date()));//当前
lal committed
3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860
			
	        List<WorkbenchCalendarDto> workcal = new ArrayList<WorkbenchCalendarDto>();
	        
	        if(dateOne<=dangqian){
	        	Long startMonth = 0l;
	    		Long endMonth = 0l;
	    		if(date == null || ("").equals(date)) {
	    			Calendar c = Calendar.getInstance();    
	    	        c.add(Calendar.MONTH, 0);
	    	        c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
	    	        String first = mat.format(c.getTime());
	    	        startMonth = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
	    	        
	    	        endMonth = new Date().getTime();
	    	        
	    		}else {
	    			String time = date+"-01";
	    			String sdaet = ClockInTool.getMinMonthDate(time);
	    		    startMonth = ClockInTool.getStartTime(0,ClockInTool.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
	    			String edate = ClockInTool.getMaxMonthDate(time);
	    		    endMonth = ClockInTool.getnowEndTime(23,ClockInTool.getStringTime(edate,"yyyy-MM-dd")).getTime();
	    		    
	    		    if(date.equals(yue)) {
	    		    	endMonth = new Date().getTime();
	    		    }
	    		    
	    		}
	    		
	    	    String[] rangeArray=ClockInTool.listToString(ClockInTool.getDays(df.format(startMonth),df.format(endMonth))).split(";");//目前为止所有日期
	    		String[] range=rangeArray[0].split(",");
	    		
	    		KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userBean.getEmpNum(),userBean.getOrgCode()); //考勤组信息
	    		
	    	    for(String num : range) {
	    	    	Long start_time = DateUtil.getStartTime(0,DateUtil.getStringTime(num,"yyyy-MM-dd")).getTime();
	    	        Long end_time = DateUtil.getnowEndTime(23,DateUtil.getStringTime(num,"yyyy-MM-dd")).getTime();
	    	    	
	    	    	WorkbenchCalendarDto wocal = WorkbenchCalendarDto.builder().build();
	    	    	wocal.setDate(num);
	    	    	if(attgro != null) {//有无考勤组  
	    	    		AttendanceCardListDto attdate = MethodCall(userBean.getOrgCode(),userBean.getEmpNum(),num);//获取当天所打卡班次
	    	    		List<AttSchedule> ashss = attdate.getAttsch();//获取今天应打卡时间
	    	    		
ilal committed
3861
	    	    		if(EmptyUtil.isNotEmpty(attdate.getAttsch()) && attdate.getAttgrouptype() != 3) {//班次不为空
lal committed
3862
	    	    			
ilal committed
3863 3864
	    	    			KqglAssoBcsz bcsts = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ashss.get(0).getId()));
	    	    			
lal committed
3865 3866 3867 3868 3869 3870 3871
	    	    			if(ashss.get(0).getId() != 0) {
	    	    				KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userBean.getEmpNum()).eq(KqglAssoDkmx::getQyid, userBean.getOrgCode())
	    								.ge(KqglAssoDkmx::getDksj, start_time).le(KqglAssoDkmx::getDksj, end_time));
	    		    			if(dkmc != null) {
	    		    				if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
	    			    				if(dkmc.getSbdk1() != null && dkmc.getSbdk1jg() == 0 && dkmc.getXbdk1() != null && dkmc.getXbdk1jg() == 0) {
	    			    					wocal.setCalendar_status(1);//打卡正常
ilal committed
3872
	    			    					wocal.setCalendar_status_type(0);
lal committed
3873
	    			    				}else {
ilal committed
3874 3875 3876
	    			    					if(dkmc.getXbdk1() == null && attdate.getAttsch().size() == 2) {
	    			    						if(bcsts.getIsXbdk()==1) {//下班不用打卡
	    			    							wocal.setCalendar_status(1);//打卡正常
ilal committed
3877
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3878 3879
	    			    						}else {
	    			    							wocal.setCalendar_status(3);//打卡异常
ilal committed
3880
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3881 3882 3883
	    			    						}
	    			    					}else {
	    			    						wocal.setCalendar_status(3);//打卡异常
ilal committed
3884
	    			    						wocal.setCalendar_status_type(0);
ilal committed
3885
	    			    					}
lal committed
3886 3887 3888 3889 3890 3891
	    			    				}
	    			    			}
	    		    				
	    		    				if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
	    		    					if(dkmc.getSbdk2() != null && dkmc.getSbdk2jg() == 0 && dkmc.getXbdk2() != null && dkmc.getXbdk2jg() == 0) {
	    			    					wocal.setCalendar_status(1);//打卡正常
ilal committed
3892
	    			    					wocal.setCalendar_status_type(0);
lal committed
3893
	    			    				}else {
ilal committed
3894 3895 3896
	    			    					if(dkmc.getXbdk2() == null && attdate.getAttsch().size() == 4) {
	    			    						if(bcsts.getIsXbdk()==1) {//下班不用打卡
	    			    							wocal.setCalendar_status(1);//打卡正常
ilal committed
3897
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3898 3899
	    			    						}else {
	    			    							wocal.setCalendar_status(3);//打卡异常
ilal committed
3900
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3901 3902 3903
	    			    						}
	    			    					}else {
	    			    						wocal.setCalendar_status(3);//打卡异常	
ilal committed
3904
	    			    						wocal.setCalendar_status_type(0);
ilal committed
3905
	    			    					}
lal committed
3906 3907 3908 3909 3910 3911
	    			    				}
	    		    				}
	    		    				
	    		    				if(attdate.getAttsch().size() == 6) {
	    		    					if(dkmc.getSbdk3() != null && dkmc.getSbdk3jg() == 0 && dkmc.getXbdk3() != null && dkmc.getXbdk3jg() == 0) {
	    			    					wocal.setCalendar_status(1);//打卡正常
ilal committed
3912
	    			    					wocal.setCalendar_status_type(0);
lal committed
3913
	    			    				}else {
ilal committed
3914 3915 3916
	    			    					if(dkmc.getXbdk3() == null && attdate.getAttsch().size() == 6) {
	    			    						if(bcsts.getIsXbdk()==1) {//下班不用打卡
	    			    							wocal.setCalendar_status(1);//打卡正常
ilal committed
3917
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3918 3919
	    			    						}else {
	    			    							wocal.setCalendar_status(3);//打卡异常
ilal committed
3920
	    			    							wocal.setCalendar_status_type(0);
ilal committed
3921 3922 3923
	    			    						}
	    			    					}else {
	    			    						wocal.setCalendar_status(3);//打卡异常	
ilal committed
3924
	    			    						wocal.setCalendar_status_type(0);
ilal committed
3925
	    			    					}
lal committed
3926 3927 3928
	    			    				}
	    		    				}
	    		    				
ilal committed
3929 3930 3931 3932 3933
//	    		    				KqglAssoRelationSummary asssum = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, userBean.getEmpNum())
//	    		    						.eq(KqglAssoRelationSummary::getAppTime, num).last("LIMIT 1"));
//	    		    				if(asssum != null) {
//	    		    					wocal.setCalendar_status(2);//事务(请假,加班,调休,出差)
//	    		    				}
lal committed
3934 3935
	    		    			}else {
	    		    				wocal.setCalendar_status(3);//打卡异常
ilal committed
3936
	    		    				wocal.setCalendar_status_type(0);
lal committed
3937
	    		    			}
ilal committed
3938 3939 3940
	    		    			
	    		    			//事务(请假,加班,调休,出差)
	    		    			KqglAssoRelationSummary asssum = KqglAssoRelationSummary.builder().build().selectOne(new QueryWrapper<KqglAssoRelationSummary>().lambda().eq(KqglAssoRelationSummary::getUserId, userBean.getEmpNum())
ilal committed
3941
    		    						.eq(KqglAssoRelationSummary::getAppTime, num).eq(KqglAssoRelationSummary::getOrgCode, userBean.getOrgCode()).last("LIMIT 1"));
ilal committed
3942
    		    				if(asssum != null) {
ilal committed
3943 3944 3945 3946 3947 3948
    		    					if(asssum.getApprovalType() == 5) {//补卡
    		    						wocal.setCalendar_status(1);//打卡正常
    		    					}else {
    		    						wocal.setCalendar_status(2);//事务(请假,加班,调休,出差)
    		    					}
    		    					
ilal committed
3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981
    		    					//0:无;1:事假;2:调休;3:病假;4:年假;5:产假;6:陪产假;7:婚假;8:例假;9:丧假;10:哺乳假;11:加班;12:出差;13:外出
    		    					if(asssum.getApprovalType() == 1) {
    		    						wocal.setCalendar_status_type(11);
    		    					}else if(asssum.getApprovalType() == 2) {
    		    						//请假
    		    						KqglAssoLeaveRules rul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getId,asssum.getLeaveTypeId()));
    		    						if(rul.getRulesType() == 1) {
    		    							wocal.setCalendar_status_type(1);
    		    						}else if(rul.getRulesType() == 2) {
    		    							wocal.setCalendar_status_type(2);
    		    						}else if(rul.getRulesType() == 3) {
    		    							wocal.setCalendar_status_type(3);
    		    						}else if(rul.getRulesType() == 4) {
    		    							wocal.setCalendar_status_type(4);
    		    						}else if(rul.getRulesType() == 5) {
    		    							wocal.setCalendar_status_type(5);
    		    						}else if(rul.getRulesType() == 6) {
    		    							wocal.setCalendar_status_type(6);
    		    						}else if(rul.getRulesType() == 7) {
    		    							wocal.setCalendar_status_type(7);
    		    						}else if(rul.getRulesType() == 8) {
    		    							wocal.setCalendar_status_type(8);
    		    						}else if(rul.getRulesType() == 9) {
    		    							wocal.setCalendar_status_type(9);
    		    						}else if(rul.getRulesType() == 10) {
    		    							wocal.setCalendar_status_type(10);
    		    						}
    		    					}else if(asssum.getApprovalType() == 3) {
    		    						wocal.setCalendar_status_type(12);
    		    					}else if(asssum.getApprovalType() == 4) {
    		    						wocal.setCalendar_status_type(13);
    		    					}
    		    				}
lal committed
3982 3983
	    	    			}else {
	    	    				wocal.setCalendar_status(4);//休息
ilal committed
3984
	    	    				wocal.setCalendar_status_type(0);
lal committed
3985 3986 3987
	    	    			}
	    	    		}else {
	    	    			wocal.setCalendar_status(0);//无排班
ilal committed
3988
	    	    			wocal.setCalendar_status_type(0);
lal committed
3989 3990 3991
	    	    		}
	    	    	}else {
	    	    		wocal.setCalendar_status(0);//无排班
ilal committed
3992
	    	    		wocal.setCalendar_status_type(0);
lal committed
3993 3994 3995 3996 3997 3998
	    	    	}
	    	    	workcal.add(wocal);
	    	    }
	    	    
	    	    //当月后续补贴数据
	    	    if(date == null || ("").equals(date) || date.equals(yue)) {
ilal committed
3999
	    	    	int pbfs = 0;
lal committed
4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013
	    	    	String next_day = ClockInTool.requires_extra_times(current,1,2,1);
					Calendar ca = Calendar.getInstance();    
	    	        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
	    	        String last = mat.format(ca.getTime());
	    	        Long endMonth_ = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
	    	    	String[] nextrangeArray=ClockInTool.listToString(ClockInTool.getDays(next_day,sdf1.format(endMonth_))).split(";");//目前为止所有日期
					String[] nextrange=nextrangeArray[0].split(",");
	    	    	
	    			String ttstr = date;//
	    			String[] ycqts = new String[31];//应上班的具体天数(yyyy-MM-dd)
					String[] xxts = new String[31];//休息的具体天数(yyyy-MM-dd)
	    			
		    		if(attgro != null){//该员工是否加入到考勤组  排班方式 1:固定排班;2:自由排班;3:自由工时         计算出应出勤,实际出勤,休息天数
		    			if(attgro.getPbfs() == 1){	//固定排班
ilal committed
4014
		    				pbfs = 1;
lal committed
4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043
							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(userBean.getEmpNum(),userBean.getOrgCode());
							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++;
							}
							 
							//目前为止应出勤天数
							 int w = 0,x=0;
							 int zj = 6;
ilal committed
4044 4045 4046 4047 4048
							 if(!(nextrange[0]).equals("")) {
								 for(String num : nextrange) {
										if(Arrays.binarySearch(needfig, String.valueOf(ClockInTool.dateToWeek(num))) >= 0) {//对比排班应打卡时间
											String[] ycqtst = new String[ycqts.length + zj];
											System.arraycopy(ycqts, 0, ycqtst, 0, ycqts.length);
leialin committed
4049 4050 4051 4052 4053 4054
											if(ycqtst.length != w) {
												ycqtst[w] = num;
												ycqts = ycqtst;
												w++;
											}
											
ilal committed
4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070
										}else {
											String[] xxtst = new String[xxts.length + zj];
											System.arraycopy(xxts, 0, xxtst, 0, xxts.length);
											xxtst[x] = num;
											xxts = xxtst;
											x++;
										}
										if(Arrays.binarySearch(bxdkss, num) >= 0) {//检查是否存在 必须打卡名单中
											String[] ycqtst = new String[ycqts.length + zj];
											System.arraycopy(ycqts, 0, ycqtst, 0, ycqts.length);
											ycqtst[w] = num;
											ycqts = ycqtst;
											w++;
											xxts =	ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(xxts), num);//为必须上班的话从休息日期中去除
										}
										if(Arrays.binarySearch(appmaps, num) >= 0) {//检查是否存在 无需打卡名单中
ilal committed
4071 4072 4073
											if(ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num) != null) {
												ycqts = ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num);//为必须休息的话从上班日期中去除
											}
ilal committed
4074 4075 4076 4077 4078 4079 4080
											String[] xxtst = new String[xxts.length + zj];
											System.arraycopy(xxts, 0, xxtst, 0, xxts.length);
											xxtst[x] = num;
											xxts = xxtst;
											x++;
										}
									 }
lal committed
4081 4082
							 }
						}else if(attgro.getPbfs() == 2){	//自由排班
ilal committed
4083
							pbfs = 2;
lal committed
4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107
							DateFormat df11 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
							List<Schedule> ycqs = schedulemapper.getAttendanceShouldList(userBean.getEmpNum(),startMonth,endMonth);
							int z=0;
							String[] ziyoupb = new String[ycqs.size()];
							for(Schedule sc : ycqs){
								String data = new SimpleDateFormat("yyyy-MM-dd").format(df11.parse(String.valueOf(sc.getData())));// 获得格式化后的日期字符串
								ziyoupb[z] = data;
								z++;
							}
							//目前为止应出勤天数
							int y = 0,x=0;
							for(String num : nextrange) {
								if(Arrays.binarySearch(ziyoupb, num) >= 0) {
									KqglAssoPbmx pbx = KqglAssoPbmx.builder().build().selectOne(new QueryWrapper<KqglAssoPbmx>().lambda().eq(KqglAssoPbmx::getUserid, userBean.getEmpNum()).eq(KqglAssoPbmx::getData, num).eq(KqglAssoPbmx::getKqzid, attgro.getId()));
									if(pbx!=null && pbx.getBcid()!=0) {
										ycqts[y] = num;
										y++;
									}else {
										xxts[x] = num;
										x++;
									}
								}
							}
						}else{
ilal committed
4108
							pbfs = 3;
lal committed
4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131
							List<AttendanceWeeklySch> atwek = attendanceweeklyschmapper.selectAttendanceMadeByUserid(userBean.getEmpNum(),userBean.getOrgCode());
							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++;
							}
						     //目前为止应出勤天数
						     int g = 0,x=0;
						     for(String num : nextrange) {
						    	 if(Arrays.binarySearch(ziyoupb, String.valueOf(ClockInTool.dateToWeek(num))) >= 0) {//对比排班应打卡时间
						    		 ycqts[g] = num;	
						    		 g++;
								 }else {
									xxts[x] = num;
									x++;
								 }
						     }
						}
		    		}
					
ilal committed
4132 4133 4134 4135 4136 4137
		    		if(!(nextrange[0]).equals("")) {
		    			for(String nus : nextrange) {
			    			WorkbenchCalendarDto wocal = WorkbenchCalendarDto.builder().build();
			    	    	wocal.setDate(nus);
			    	    	if(pbfs == 3) {
			    	    		wocal.setCalendar_status(0);//
ilal committed
4138
			    	    		wocal.setCalendar_status_type(0);
ilal committed
4139 4140 4141 4142 4143 4144 4145 4146 4147
			    	    	}else {
			    	    		if(ClockInTool.contains(ClockInTool.deleteArrayNull(ycqts),nus)) {
				    	    		wocal.setCalendar_status(1);//
				    	    		wocal.setCalendar_status_type(0);
				    	    	}
				    	    	if(ClockInTool.contains(ClockInTool.deleteArrayNull(xxts),nus)) {
				    	    		wocal.setCalendar_status(4);//
				    	    		wocal.setCalendar_status_type(0);
				    	    	}
ilal committed
4148
			    	    	}
ilal committed
4149 4150 4151
			    	    	
			    	    	workcal.add(wocal);
			    		}
lal committed
4152 4153
		    		}
		    		
ilal committed
4154
		    		
lal committed
4155
	    		}
ilal committed
4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252
	        }else {
	        	String time = date+"-01";
    			String sdaet = ClockInTool.getMinMonthDate(time);
    			Long startMonth = ClockInTool.getStartTime(0,ClockInTool.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
    			String edate = ClockInTool.getMaxMonthDate(time);
    			Long endMonth = ClockInTool.getnowEndTime(23,ClockInTool.getStringTime(edate,"yyyy-MM-dd")).getTime();
	        	
	        	//固定排班
	        	String[] rangeArray=ClockInTool.listToString(ClockInTool.getDays(df.format(startMonth),df.format(endMonth))).split(";");//目前为止所有日期
	    		String[] range=rangeArray[0].split(",");
	        	/******************/
	    		String[] ycqts = new String[31];//应上班的具体天数(yyyy-MM-dd)
				String[] xxts = new String[31];//休息的具体天数(yyyy-MM-dd)
				
	        	//考勤组信息
				KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userBean.getEmpNum(),userBean.getOrgCode()); 
				//固定排班
				if(attgro.getPbfs() == 1) {
		        	List<KqglAssoTeshu> bxdklist = kqglassoteshumapper.ShouldSpecialDatessetByKqzid(attgro.getId(), date,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(), date,2);//当前月     无需打卡日期
					String[] appmaps= new String[wxdk.size()];//特殊-无需打卡天数(休息日)
					int d1 = 0;
					for(KqglAssoTeshu spe:wxdk){
						appmaps[d1] = spe.getTsrq();
						d1++;
					}
					//应打卡周期时间
					List<AttendanceWeeklySch> atwek = attendanceweeklyschmapper.selectAttendanceMadeByUserid(userBean.getEmpNum(),userBean.getOrgCode());
					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++;
					}
					
					//目前为止应出勤天数
					 int w = 0,x=0;
					 int zj = 6;
					 for(String num : range) {
						if(ClockInTool.useArrayUtils(needfig, String.valueOf(ClockInTool.dateToWeek(num)))) {//对比排班应打卡时间
							String[] ycqtst = new String[ycqts.length + zj];
							System.arraycopy(ycqts, 0, ycqtst, 0, ycqts.length);
							ycqtst[w] = num;
							ycqts = ycqtst;
							w++;
						}else {
							String[] xxtst = new String[xxts.length + zj];
							System.arraycopy(xxts, 0, xxtst, 0, xxts.length);
							xxtst[x] = num;
							xxts = xxtst;
							x++;
						}
						if(ClockInTool.useArrayUtils(bxdkss, num)) {//检查是否存在 必须打卡名单中
							String[] ycqtst = new String[ycqts.length + zj];
							System.arraycopy(ycqts, 0, ycqtst, 0, ycqts.length);
							ycqtst[w] = num;
							ycqts = ycqtst;
							w++;
							xxts =	ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(xxts), num);//为必须上班的话从休息日期中去除
						}
						if(ClockInTool.useArrayUtils(appmaps, num)) {//检查是否存在 无需打卡名单中
							ycqts = ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num);//为必须休息的话从上班日期中去除
							String[] xxtst = new String[xxts.length + zj];
							System.arraycopy(xxts, 0, xxtst, 0, xxts.length);
							xxtst[x] = num;
							xxts = xxtst;
							x++;
						}
					 }
		        	/******************/
		    		
		    		for(String num : range) {
		    			WorkbenchCalendarDto wocal = WorkbenchCalendarDto.builder().build();
		    			wocal.setDate(num);
		    			if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(ycqts), num)) {
		    				wocal.setCalendar_status(1);//
		    			}
		    			if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(xxts), num)) {
		    				wocal.setCalendar_status(4);//
		    			}
		    			
		    			if(!ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(ycqts), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(xxts), num)) {
		    				wocal.setCalendar_status(0);//
		    			}
		    			workcal.add(wocal);
		    		}
		        	
		        }
lal committed
4253 4254 4255 4256 4257 4258
	        }
			
			return ResultUtil.data(workcal, "操作成功!");
		}
	 
	 
lal committed
4259
	
ilal committed
4260
}