ClockInController.java 88.8 KB
Newer Older
ilal committed
1 2 3 4 5 6 7 8 9 10 11 12
package cn.timer.api.controller.kqgl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
lal committed
13
import org.springframework.web.bind.annotation.RequestBody;
ilal committed
14 15 16 17 18 19 20 21
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;

import cn.hutool.json.JSONObject;
lal committed
22 23
import cn.timer.api.bean.kqgl.AttConditions;
import cn.timer.api.bean.kqgl.AttGroupBinPunchMode;
lal committed
24
import cn.timer.api.bean.kqgl.AttendanceGroup;
lal committed
25 26
import cn.timer.api.bean.kqgl.AttendanceMachine;
import cn.timer.api.bean.kqgl.PunchCardAddress;
lal committed
27
import cn.timer.api.bean.kqgl.PunchCardDetails;
lal committed
28 29
import cn.timer.api.bean.kqgl.PunchCardWiFi;
import cn.timer.api.dto.kqmk.PunchRecord;
lal committed
30
import cn.timer.api.bean.kqgl.ShiftManagement;
ilal committed
31 32 33 34 35 36 37 38 39
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;
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
40 41
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
ilal committed
42
import cn.timer.api.config.exception.CustomException;
lal committed
43
import cn.timer.api.dao.kqgl.AttGroupBinPunchModeMapper;
lal committed
44
import cn.timer.api.dao.kqgl.AttendanceGroupMapper;
lal committed
45 46
import cn.timer.api.dao.kqgl.AttendanceMachineMapper;
import cn.timer.api.dao.kqgl.PunchCardAddressMapper;
lal committed
47
import cn.timer.api.dao.kqgl.PunchCardDetailsMapper;
lal committed
48
import cn.timer.api.dao.kqgl.PunchCardWiFiMapper;
lal committed
49 50
import cn.timer.api.dao.kqgl.PunchRecordMapper;
import cn.timer.api.dao.kqgl.ShiftManagementMapper;
lal committed
51 52
import cn.timer.api.dao.kqmk.KqglAssoBcszMapper;
import cn.timer.api.dao.kqmk.KqglAssoDkjlMapper;
lal committed
53
import cn.timer.api.dao.kqmk.KqglAssoDkmxMapper;
ilal committed
54 55
import cn.timer.api.dao.kqmk.KqglAssoPbmxMapper;
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
lal committed
56
import cn.timer.api.dto.kqmk.AttClockMethod;
ilal committed
57 58 59 60 61 62 63 64 65 66 67
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;
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
68
@Api(tags = "3.0[3]考勤打卡")
ilal committed
69 70 71 72 73 74
@RestController
@Transactional
@RequestMapping(value = "/kqdk", produces = { "application/json", "multipart/form-data" })
public class ClockInController {
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
lal committed
75
	
lal committed
76 77 78
	//打卡明细表
	@Autowired
	private KqglAssoDkmxMapper kqglassodkmxmapper;
lal committed
79 80 81 82 83
	@Autowired
	private KqglAssoDkjlMapper kqglassodkjlmapper;
	@Autowired
	private KqglAssoBcszMapper kqglassobcszmapper;
	
lal committed
84 85 86
	
	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
lal committed
87
	SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ilal committed
88 89 90 91 92 93 94 95 96 97 98
	/**
	 * 考勤打卡
	 * 
	 * @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
99
		
lal committed
100 101 102
		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
103
		String yesterday = ClockInTool.requires_extra_times(current,-1,3,1);//前一天
lal committed
104 105 106 107 108 109 110
		
		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
111
		String msg = "未知错误,请联系管理员";
lal committed
112
		int sbyf = 1;//0:失败;1:成功
lal committed
113
		
ilal committed
114
		JSONObject jsonArray = new JSONObject(json);
lal committed
115 116 117
		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
118
		String sStdIoTime = jsonArray.get("io_time").toString();//打卡时间 **判断次日打卡情况**
lal committed
119
		
ilal committed
120 121 122 123 124
		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
125 126
			int qyid = user.getOrgCode();
			int userid = user.getEmpNum();
ilal committed
127 128
			KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
			//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
lal committed
129 130
			
			/*******/
lal committed
131 132
			long time_ = DateUtil.getStringTime(sStdIoTime, "yyyy-MM-dd HH:mm:ss");//打卡时间戳
			String putime = new SimpleDateFormat("yyyy-MM-dd").format(time_);//转换打卡时间格式 年月日
lal committed
133 134 135 136 137
			//打卡当天开始时间,打卡当天结束时间
			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
138
			long punchcardtime = 0,punchstart = 0,punchend = 0;//应打卡时间,应打卡开始时间,应打卡结束时间
lal committed
139
			boolean isRange = true;//是否在打卡时间范围内
lal committed
140
			int atttype = 0;
lal committed
141
			int execution_status = 0;//执行状态
lal committed
142 143
			boolean kskd = true;//识别是否更新最后一次打卡   针对于最后一次下班卡
			boolean sbdkkd = false;//针对于上班  未超过上班卡打卡  视为无效打卡
lal committed
144
			ClockCollectData clockt = new ClockCollectData();
lal committed
145 146
			//putime: 根据日期  得到打卡所需的详细信息
			AttendanceCardListDto attdate = MethodCall(qyid,userid,putime);
lal committed
147
			/*******/
lal committed
148
			if(attgro != null) {//判断考勤组是否存在
ilal committed
149 150
				List<KqglAssoKqzdkfs> kqjs = KqglAssoKqzdkfs.builder().build().selectList(new QueryWrapper<KqglAssoKqzdkfs>().lambda().eq(KqglAssoKqzdkfs::getKqzId, attgro.getId()));
				if(kqjs.size() > 0) {
lal committed
151 152 153 154 155 156 157 158 159
					/**
					 * 	当考勤组为“固定排班”和“自定义排班”时 方可使用
					 */
					if(attdate.getAttgrouptype() != 3) {
						    //查询打卡当天是否有记录**********************************
							KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build();
							String dakariqi = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDateyesterday))+" "+ClockInTool.dateToWeek2(yesterday);
							//检查昨日的班次是否存在次日打卡
							KqglAssoDkjl balan = kqglassodkjlmapper.selectOne(new QueryWrapper<KqglAssoDkjl>().lambda().eq(KqglAssoDkjl::getUserId, userid).eq(KqglAssoDkjl::getAttdate, dakariqi).ne(KqglAssoDkjl::getBcid, 0).orderByDesc(KqglAssoDkjl :: getSort).last("LIMIT 1"));
lal committed
160 161
							boolean dnck = false;
							boolean crdk = false;//当次打卡是否存在次日打卡
lal committed
162 163 164 165 166 167 168 169 170 171 172
							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
173
								}
lal committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
								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(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
205
								}
lal committed
206
								
lal committed
207 208
							}else {
								//无记录的话就找昨天的数据
lal committed
209
//								AttendanceCardListDto attdate1 = MethodCall(qyid,userid,yesterday);
lal committed
210
							}
lal committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
							
							if(crdk && dnck) {
								dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid)
										.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
								attdate = MethodCall(qyid,userid,yesterday);
								attendance_date = startDateyesterday;
								toweek = yesterday;
							}else {
								dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid)
										.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate));
								attendance_date = startDate;
								toweek = putime;
							}
							if(EmptyUtil.isEmpty(attdate.getAttsch())) {
								msg = "当前未排班";
								sbyf = 0;
							}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; 
								if(attdate.getAttsch().size() > 0) {
									 List<AttSchedule> ash = attdate.getAttsch();
									 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();
									 }
lal committed
247 248
								 	
								 	if(dkmc == null) {
lal committed
249
								 		kskd = false;
lal committed
250 251
								 		
								 		if(attdate.getAttsch().size() == 2) {//一套上下班  上班1
lal committed
252 253 254 255 256 257 258 259 260 261 262
								 			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;
											}
								 			
lal committed
263
								 		}else {
lal committed
264
								 			boolean getinto = true;
lal committed
265 266 267
								 			//打卡时间  对比班次  接近哪个时间就打哪个时间的卡
									 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
									 			//punchstart 应打卡开始时间 punchend:应打卡结束时间  time_:打卡时间
lal committed
268
									 			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
269 270
											    if (effectiveDate1) {//在范围内就打卡 
											    	atttype = 1;
lal committed
271
											    	getinto = false;
lal committed
272
											    }else {
lal committed
273 274 275
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
276
											    }
lal committed
277
											    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
278 279
											    if (effectiveDate2) {//在范围内就打卡 
											    	atttype = 2;
lal committed
280 281 282
											    	isRange = true;//在范围
											    	
											    	getinto = false;
lal committed
283
											    }else {
lal committed
284 285 286
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
287
											    }	
lal committed
288
												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
289 290
											    if (effectiveDate3) {//在范围内就打卡 
											    	atttype = 3;
lal committed
291 292 293
											    	isRange = true;//在范围
											    	
											    	getinto = false;
lal committed
294
											    }else {
lal committed
295 296 297
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
298
											    }
lal committed
299
											    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
300 301
											    if (effectiveDate4) {//在范围内就打卡 
											    	atttype = 4;
lal committed
302 303 304
											    	isRange = true;//在范围
											    	
											    	getinto = false;
lal committed
305
											    }else {
lal committed
306 307 308
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
309 310 311
											    }	
									 		}
									 		if(attdate.getAttsch().size() == 6) {
lal committed
312
									 			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
313 314
											    if (effectiveDate5) {//在范围内就打卡 
											    	atttype = 5;
lal committed
315 316 317
											    	isRange = true;//在范围
											    	
											    	getinto = false;
lal committed
318
											    }else {
lal committed
319 320 321
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
322
											    }
lal committed
323
											    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
324 325
											    if (effectiveDate6) {//在范围内就打卡 
											    	atttype = 6;
lal committed
326 327 328
											    	isRange = true;//在范围
											    	
											    	getinto = false;
lal committed
329
											    }else {
lal committed
330 331 332
											    	if(getinto) {
											    		isRange = false;
											    	}
lal committed
333 334
											    }	
									 		}
lal committed
335 336 337 338
								 		}
									 	 execution_status = 1;
								 	}else {
								 		execution_status = 2;
lal committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
								 		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;
													atttype = 2;
												}
										     }else {
										    	//最后一次卡的时候 再继续打视为更新最后一次打卡
										    	 kskd = true;
										    	 atttype = 2;
										     }
lal committed
356
								 		}	
lal committed
357
								 		if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
lal committed
358
								 			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
359 360
										    if (effectiveDate1) {//在范围内就打卡 
										    	if(dkmc.getSbdk1() != null) {
lal committed
361
										    		sbdkkd = true;//打卡无效
lal committed
362
										    		atttype = 1;
lal committed
363 364 365
										    	}else {
										    		atttype = 1;
										    	}
lal committed
366 367 368
										    }else { 
										    	isRange = false; 
										    }
lal committed
369
										    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
370 371 372 373 374 375 376
										    if (effectiveDate2) {//在范围内就打卡 
										    	if(dkmc.getXbdk1() != null) {
										    		kskd = true;
										    	}else {
										    		kskd = false;
										    		atttype = 2;
										    	}
lal committed
377 378 379
										    }else { 
										    	isRange = false; 
										    }
lal committed
380
								 			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
381 382 383
										    if (effectiveDate3) {//在范围内就打卡 
										    	if(dkmc.getSbdk2() != null) {
										    		sbdkkd = true;//
lal committed
384
										    		atttype = 3;
lal committed
385 386 387
										    	}else {
										    		atttype = 3;
										    	}
lal committed
388 389 390
										    }else { 
										    	isRange = false; 
										    }
lal committed
391
										    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
392 393 394 395 396 397 398
										    if (effectiveDate4) {//在范围内就打卡 
										    	if(dkmc.getXbdk2() != null) {
										    		kskd = true;
										    	}else {
										    		kskd = false;
										    		atttype = 4;
										    	}
lal committed
399 400 401
										    }else { 
										    	isRange = false; 
										    }	
lal committed
402 403
								 		}
								 		if(attdate.getAttsch().size() == 6) {
lal committed
404
								 			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
405 406 407
										    if (effectiveDate5) {//在范围内就打卡 
										    	if(dkmc.getSbdk2() != null) {
										    		sbdkkd = true;//
lal committed
408
										    		atttype = 5;
lal committed
409 410 411 412
										    	}else {
										    		atttype = 5;
										    	}
										    }else { isRange = false; }
lal committed
413
										    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
414 415 416 417 418 419 420 421
										    if (effectiveDate6) {//在范围内就打卡 
										    	if(dkmc.getXbdk2() != null) {
										    		kskd = true;
										    	}else {
										    		kskd = false;
										    		atttype = 6;
										    	}
										    }else { isRange = false; }	
lal committed
422 423
								 		}
								 	}
lal committed
424
								 }
lal committed
425 426
								if(atttype == 1) {
									punchcardtime = starttime1;
lal committed
427 428
									 punchstart = starttime1ks;
							    	 punchend = starttime1js;
lal committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
								}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;
								}
lal committed
450 451 452 453 454
								 if(clockt.getShifid() != 0) {
								 
									 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()));
lal committed
455
									 }
lal committed
456
									//打卡记录录入 -- 打卡是否有时间范围限制
lal committed
457 458
									 if(attdate.getAttsch().size() == 2) {
										 if(punchstart>0 && punchend>0) {
lal committed
459 460 461 462
											 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");
lal committed
463 464 465 466 467
											 if (!effectiveDate) {
												 System.out.println("当前打卡时间不在范围内");
												// 手动抛出异常
												 isRange = false;
			//									throw new Exception();
lal committed
468
											 }
lal committed
469
										 }
lal committed
470
									 }
lal committed
471 472 473
										if(isRange) {
											int yzcd = shif.getYzcdfzs();//严重迟到分钟数
											int kgcdfzs  = shif.getKgcdfzs();//旷工迟到分钟数 
lal committed
474
											
lal committed
475 476 477
											int dkcs_ = shif.getSxbcs();//上下班打卡次数
											int iswzwd = shif.getIsWzwd();//是否开启晚走晚到(0:否;1:是)
											
lal committed
478 479 480 481 482 483 484
											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;//休息时间
											}
											
lal committed
485 486 487
											double xbwz1 = 0,xbwz2=0,xbwz3=0;
											int sbwd1=0,sbwd2=0,sbwd3=0;
											
lal committed
488 489 490 491 492 493 494 495 496
											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) {
lal committed
497 498 499 500 501 502 503 504
												//统一分钟数
											    xbwz1 = Double.valueOf(shif.getXbwz1()) * 60;//下班晚走1
												sbwd1 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd1()) * 60));//上班晚到1
												xbwz2 = Double.valueOf(shif.getXbwz2()) * 60;//下班晚走2
												sbwd2 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd2()) * 60));//上班晚到2
												xbwz3 = Double.valueOf(shif.getXbwz3()) * 60;//下班晚走3
												sbwd3 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd3()) * 60));//上班晚到3
													
lal committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
												 //获取前一天最后下班的时间
												 yesterdaymx = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid)
															.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
												 attdateyesterday = MethodCall(qyid,userid,yesterday);
												 
												 List<AttSchedule> ash = attdateyesterday.getAttsch();
												 if(attdateyesterday.getAttsch().size() == 2 || attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
													 yesendtime1 = ash.get(1).getTime();
												 }
											 	 if(attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
											 		yesendtime2 = ash.get(3).getTime();
												 }
											 	 if(attdateyesterday.getAttsch().size() == 6) {
											 		yesendtime3 = ash.get(5).getTime();
												  }
											 }
											
lal committed
522 523 524
											 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;
lal committed
525 526
												 if(punchcardtime != 0){//有应打卡时间时
													 Long time = (time_ - punchcardtime)/1000/60;
lal committed
527 528 529 530 531 532 533 534
													 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
535
													 }
lal committed
536
													 
lal committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
													 //存在晚走玩到
													 if(iswzwd > 0) {
														 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)));//晚到后应打卡时间
lal committed
564
															 
lal committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578
															 punchcardtime = changed_time;//更换当天打卡时间
															 Long timeyes = (time_ - changed_time)/1000/60;//
															 if((atttype)%2 > 0){//上班
																if(timeyes > 0){
																	sbdkjg = Integer.valueOf(timeyes.toString());
																}
															 }else{//下班
																if(timeyes > 0){}else{
																	sbdkjg = Math.abs(Integer.valueOf(timeyes.toString()));
																}
															 }
														 }
													 }
													 
lal committed
579
												 }
lal committed
580
												 
lal committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
											    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);
												}
lal committed
600 601
												 int ydkcs = 0;
												 if(shif != null){ydkcs = shif.getSxbcs()*2;}//应打卡次数
lal committed
602
												 if(sbdkjg > yzcd && yzcd>0) {
lal committed
603
													 yzcdcs++;
lal committed
604
													 yzcdsc = sbdkjg - yzcd;
lal committed
605
												 }
lal committed
606
												 if(sbdkjg > kgcdfzs && kgcdfzs>0) {kgcdcs++;}
lal committed
607 608 609 610
												 pcd.setYdkcs(ydkcs);
												 pcd.setYzcdcs(yzcdcs);
												 pcd.setYzcdsc(Double.valueOf(yzcdsc));
												 pcd.setKgcdfzs(kgcdcs);
lal committed
611 612
												 if (!pcd.insert()) {
													throw new CustomException("打卡明细-新增异常-1");
lal committed
613
												 }
lal committed
614
												 dkmx = pcd.getId();
lal committed
615
											 }else if(execution_status == 2){ //*****修改
lal committed
616 617
												 dkmx = dkmc.getId();
												 KqglAssoDkmx pcd = KqglAssoDkmx.builder().build();
lal committed
618
												 if(atttype == 2){//下班1
lal committed
619 620 621 622 623 624 625
													 pcd.setId(dkmc.getId());
													 pcd.setXbdk1(time_);//下班1打卡时间
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){
															 pcd.setXbdk1jg(0);// 打卡结果
														 }else{
lal committed
626
															 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));
lal committed
627
														 }
lal committed
628
													 }
lal committed
629
													 if(dkmc.getSbdk1() != null){
lal committed
630
														Long time = (time_ - dkmc.getSbdk1())/1000/60 - rest_time;
lal committed
631
														pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
lal committed
632
													 }
lal committed
633 634
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
													 
lal committed
635
											     }else if(atttype == 3){//上班2
lal committed
636 637 638 639 640 641
											    	 
											    	 int sbdk2jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0;
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){sbdk2jg = Math.abs(Integer.valueOf(time.toString()));}
													 }
lal committed
642
													 if(sbdk2jg > yzcd&& yzcd>0) {
lal committed
643 644 645
														 yzcdcs = dkmc.getYzcdcs()+1;
														 yzcdsc = sbdk2jg - yzcd;
													 }
lal committed
646
													 if(sbdk2jg > kgcdfzs&& kgcdfzs>0) {kgcdcs++;}
lal committed
647 648 649 650 651 652 653 654
													 
													 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);//修改打卡记录
lal committed
655
											     }else if(atttype == 4){//下班2
lal committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
													 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);
lal committed
671 672 673 674 675 676
														 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
														 
														 BigDecimal xx = new BigDecimal(rest_time);
														 
														 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
														 
lal committed
677 678 679
														 pcd.setGzsc(worktime);
													 }
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
lal committed
680
											     }else if(atttype == 5){//上班3
lal committed
681 682 683 684 685
											    	 int sbdk3jg = 0,yzcdsc = 0,yzcdcs = 0,kgcdcs = 0;
													 if(punchcardtime != 0){//有应打卡时间时
														 Long time = (time_ - punchcardtime)/1000/60;
														 if(time > 0){sbdk3jg = Math.abs(Integer.valueOf(time.toString()));}
													 }
lal committed
686
													 if(sbdk3jg > yzcd&& yzcd>0) {
lal committed
687 688 689
														 yzcdcs = dkmc.getYzcdcs()+1;
														 yzcdsc = sbdk3jg - yzcd;
													 }
lal committed
690
													 if(sbdk3jg > kgcdfzs&& kgcdfzs>0) {kgcdcs++;}
lal committed
691 692 693 694 695 696 697
													 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);//修改打卡记录
lal committed
698
											     }else if(atttype == 6){//下班3
lal committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
													 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);
lal committed
714 715 716 717 718 719
														 BigDecimal worktime_ = new BigDecimal(Math.abs(om.add(on).doubleValue()));
														 
														 BigDecimal xx = new BigDecimal(rest_time);
														 
														 double worktime = Math.abs(worktime_.subtract(xx).doubleValue());
														 
lal committed
720 721 722 723
														 pcd.setGzsc(worktime);
													 }
											     }
												 pcd.setId(dkmc.getId());
lal committed
724
												 if(atttype <= 6 && atttype > 0 && !sbdkkd){
lal committed
725
													 kqglassodkmxmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
lal committed
726 727
												 }
											 }
lal committed
728 729 730
										 }else {
											 msg = "当前打卡时间不在范围内";
											 sbyf = 0;
lal committed
731
										 }
lal committed
732 733 734 735 736
								 }else {
									 msg = "当前是休息时间";
									 sbyf = 0;
								 }
						}
lal committed
737 738 739 740 741 742 743 744 745
					}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时  打的是昨天的卡
							zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid)
lal committed
746 747 748 749
									.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
							attendance_date = startDateyesterday;
							toweek = yesterday;
						}else {
lal committed
750
							zydkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userid)
lal committed
751 752 753
									.ge(KqglAssoDkmx::getDksj, startDate).le(KqglAssoDkmx::getDksj, endDate));
							attendance_date = startDate;
							toweek = putime;
lal committed
754 755 756 757 758 759 760 761 762 763 764
						}  
						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
765
							 }
lal committed
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
							 dkmx = pcd.getId();
							 atttype = 1;
						}else {//修改	
							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;
								}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
784
									 }
lal committed
785 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
									kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
								atttype = 2;
							}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;
								}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
812
									 }
lal committed
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
									 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
								 atttype = 4;
							}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;
								}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
842
									 }
lal committed
843 844 845 846 847 848 849 850 851
									 kqglassodkmxmapper.updateByPrimaryKeySelective(zypcd);//修改打卡记录
								}
								
								 atttype = 6;
							}else {
								atttype = 7;
							}
						}
					}
lal committed
852
				}else {
lal committed
853
					msg = "未检测到考勤机";
lal committed
854 855
					sbyf = 0;
				}
lal committed
856
				
lal committed
857 858 859 860
/*****************************************************************************************************************************************************************************************************/
/*******************************************************************原始打卡记录数据录入**************************************************************************************************************/
/*****************************************************************************************************************************************************************************************************/
				
lal committed
861 862 863
				String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(attendance_date));//转换打卡时间格式
				
				//true:确认为最后一次打卡更新打卡时  之前打卡的一条数据变为“打卡更新数据”
lal committed
864
				if(kskd && (atttype == 2 || atttype == 4 || atttype == 6)) {
lal committed
865 866 867 868 869
					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
870
					
ilal committed
871 872 873 874 875
					int results = 0;
					Long time = (time_ - punchcardtime)/1000/60;
					if(punchcardtime != 0){
						if(isRange) {
							if((atttype)%2 > 0){//上班
lal committed
876 877 878
								if(time > 0){
									results = Integer.valueOf(time.toString());
								}// 打卡结果
ilal committed
879
							}else{//下班
lal committed
880 881 882
								if(time > 0){}else{
									results = Math.abs(Integer.valueOf(time.toString()));
								}// 打卡结果
ilal committed
883 884 885 886 887 888
							}
						}
					}
					int type,status = 0;
					if((atttype)%2 > 0){
						type = 1;// 类型(类型 0:无排班打卡 1:上班 2:下班)   punchcardtime == 0:无班次打卡
lal committed
889
						if(attdate.getAttgrouptype() != 3) {
lal committed
890 891 892 893
							if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
								if(punchcardtime == 0 && clockt.getShifid() != 0){
									status = 1;
								}if(punchcardtime == 0 && clockt.getShifid() == 0) {
lal committed
894
									status = 2;
lal committed
895 896 897 898 899 900 901 902 903 904
								}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
905
								}
lal committed
906 907
							}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
								status = 2;
lal committed
908 909 910 911
							}
						}else {
							if(sbyf == 1) {
								status = 1;
lal committed
912 913 914
							}else {
								status = 2;
							}
ilal committed
915 916 917
						}
					}else{
						type = 2;// 类型(类型 0:无排班打卡 1:上班 2:下班)
lal committed
918
						if(attdate.getAttgrouptype() != 3) {
lal committed
919 920 921 922
							if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {
								if(punchcardtime == 0 && clockt.getShifid() != 0){
									status = 1;
								}if(punchcardtime == 0 && clockt.getShifid() == 0) {
lal committed
923
									status = 2;
lal committed
924 925 926 927 928 929 930 931 932 933
								}else{
									if(isRange) {
										if(time < 0){
											status = 4;
										}else if(results == 0){
											status = 1;
										}
									}else {
										status = 2;
									}
lal committed
934
								}
lal committed
935 936
							}else if(EmptyUtil.isEmpty(attdate.getAttsch())) {
								status = 2;
lal committed
937 938 939 940
							}
						}else {
							if(sbyf == 1) {
								status = 1;
lal committed
941 942 943
							}else {
								status = 2;
							}
ilal committed
944 945
						}
					}
lal committed
946
					
lal committed
947 948
					//第二次未超过应上班打卡时间 打卡为无效
					if(sbdkkd) {
lal committed
949
						status = 2;
lal committed
950
						atttype = 0;
lal committed
951
						msg = "已有最优的打卡记录存在";
lal committed
952
					}
lal committed
953
					
ilal committed
954
					long attime;
lal committed
955 956 957 958 959
					if(punchcardtime == 0){// 考勤时间(应打卡时间)
						attime = new Date().getTime();
					}else{
						attime = punchcardtime;
					}
ilal committed
960
					String remarks = "";
lal committed
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
					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;
					}
ilal committed
976 977
					//cardtype--1:GPS,2:WIFI,3:考勤机
					KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(time_).results(results).userId(userid).type(type).status(status).sort(atttype)
lal committed
978
							.cardType(3).qyid(qyid).attdate(attdate_+" "+ClockInTool.dateToWeek2(toweek)).attime(attime).dkmxid(dkmx).bcid(shifid).remarks(remarks).punchmode(Integer.valueOf(asVerifyMode))
lal committed
979
							.punchequipment(asDevId).commentary(commentary).build();
ilal committed
980 981 982 983
					
					if (!pre.insert()) {
						throw new CustomException("打卡记录-新增异常-2");
					 }
lal committed
984 985 986
				}else {
					msg="打卡失败!,未加入考勤组!";
					sbyf = 0;
ilal committed
987 988 989 990
				}
		}else {
			return ResultUtil.error("打卡失败!,用户不存在!");
		}
lal committed
991 992 993 994 995 996
		
		if(sbyf == 1) {
			return  ResultUtil.data(null, "打卡成功");
		}else {
			return  ResultUtil.data(msg, "打卡失败");
		}
ilal committed
997 998 999 1000
	}
	
	@Autowired
	private KqglAssoPbmxMapper kqglassopbmxmapper;
lal committed
1001 1002 1003 1004 1005 1006 1007
	/**
	 * @param qyid 
	 * @param userid
	 * @param date
	 * @return
	 *	获取当天打卡班次数据
	 */
ilal committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
	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
1061 1062 1063 1064 1065
//			    if(attgro.getIsXzbcdk() == 1){
//			    	attcar.setOptscheduling(true);	
//			    }else{
//			    	attcar.setOptscheduling(false);
//			    }
ilal committed
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
				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
1140 1141 1142
		 
		 
		 
ilal committed
1143 1144 1145
		 return attcar;
	 }
	
lal committed
1146 1147 1148 1149 1150
	/**
	 * @param shiftm
	 * @param attcar
	 * @param str
	 */
ilal committed
1151
	public void Getshiftinformationbatch(KqglAssoBcsz shiftm,AttendanceCardListDto attcar,String str){
lal committed
1152 1153 1154 1155 1156 1157 1158
		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
1159
		String next_day = ClockInTool.requires_extra_times(str,1,2,1);
lal committed
1160
		
ilal committed
1161 1162 1163 1164
		 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
1165
			    		AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(1).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbdk1()+":00").replaceAll("\r|\n", ""))))
lal committed
1166
			    				.starttime(("").equals(shiftm.getSbqjks1()) || shiftm.getSbqjks1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjks1()+":00").replaceAll("\r|\n", ""))))
lal committed
1167 1168
			    				.endtime(("").equals(shiftm.getSbqjjs1()) || shiftm.getSbqjjs1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjjs1()+":00").replaceAll("\r|\n", ""))))
			    				.nextday(0).build();
ilal committed
1169 1170 1171
			    		
			    		atts.add(as);
	    			}else{
lal committed
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
	    				//次日
	    				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
1187 1188 1189 1190 1191 1192 1193
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//2次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
lal committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
	    				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
1208
	    			}else{
lal committed
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
	    				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
1223 1224 1225 1226 1227 1228 1229
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
lal committed
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
	    				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
1244
	    			}else{
lal committed
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
	    				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
1259 1260 1261 1262 1263
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
lal committed
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
	
	
	
	/************************************************************************************************************************************************************************************************/
	/**************************************************************************	APP打卡	*************************************************************************************************************/
	/************************************************************************************************************************************************************************************************/
	
	//考勤组
	@Autowired
	private AttendanceGroupMapper attendancegroupmapper;
	//班次
	@Autowired
	private ShiftManagementMapper shiftmanagementmapper;
	//打卡明细表
	@Autowired
	private PunchCardDetailsMapper punchcarddetailsmapper;
	//打卡记录
	@Autowired
	private PunchRecordMapper punchrecordmapper;
	
	/**
	  * 	考勤打卡------APP打卡
	  */
	 @PostMapping(value = "/AttendanceCard")
	 @ApiOperation(value = "考勤打卡------APP打卡", httpMethod = "POST", notes = "接口发布说明")
lal committed
1289
	 @ApiOperationSupport(order = 2)
lal committed
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 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
	 public Result<Void> AttendanceCard(@CurrentUser UserBean userBean,@RequestBody ClockCollectData clock) {
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
		 
		 AttendanceGroup attgro = attendancegroupmapper.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		 //pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		 
	     String putime = new SimpleDateFormat("yyyy-MM-dd").format(Double.valueOf(clock.getPunchtime()));//转换打卡时间格式
		 Long startDate = 0l;//打卡当天开始时间
	     Long endDate = 0l;//打卡当天结束时间
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
		 ShiftManagement shif = null;
		 if(clock.getShifid() > 0){//有无班次
			 shif = shiftmanagementmapper.selectByPrimaryKey(clock.getShifid());
		 }
		 
		 int dkmx = 0;
		 PunchCardDetails dkmc = punchcarddetailsmapper.SingleAttendanceDays(userid,startDate,endDate);//查询打卡当天是否有记录
		 
		 if(dkmc != null){//有记录就修改之前的
			//修改
			 dkmx = dkmc.getId();
			 PunchCardDetails pcd = new PunchCardDetails();
			 if(clock.getType() == 1){
				 if(clock.getDiffer() == 1){//打卡
					 if(!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null){
						 return ResultUtil.error("重复打卡");
					 }
				 }else{//更新打卡
					 pcd.setId(dkmc.getId());
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
					 punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
				 }
				 
			 }else if(clock.getType() == 2){
				 if(("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() == null){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else{

					if(clock.getDiffer() == 1){//打卡
						return ResultUtil.error("重复打卡");
					}else{//更新打卡
						pcd.setId(dkmc.getId());
						pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
						if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							if(time > 0){
								 pcd.setXbdk1jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
							 }
						}
						//班次为2次时,计算工作时长
						if(dkmc.getSbdk1() != null){
							Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
							pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
						}
						punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
					}
				 }
				 //班次为2次时,计算工作时长
				 if(dkmc.getSbdk1() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
					 pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
				 }
			 }else if(clock.getType() == 3){
				 if(("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() == null){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
						 }else{
							pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
							 }else{
								pcd.setSbdk2jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 4){
				 if(("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() == null){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
						 }
						 
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk2jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
							 }
						 }
						 //班次为4次时,计算工作时长
						 if(dkmc.getSbdk2() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为4次时,计算工作时长
				 if(dkmc.getSbdk2() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }else if(clock.getType() == 5){
				 if(("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() == null){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
							 }else{
								 pcd.setSbdk3jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 6){
				 if(("").equals(dkmc.getXbdk3()) || dkmc.getXbdk3() == null){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk3jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
							 }
						 }
						 //班次为6次时,计算工作时长
						 if(dkmc.getSbdk3() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为6次时,计算工作时长
				 if(dkmc.getSbdk3() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }
			 pcd.setId(dkmc.getId());
			 if(clock.getType() <= 6){
				 int update = punchcarddetailsmapper.updateByPrimaryKeySelective(pcd);
			 }
			 
		 }else{//没有数据就新增一条数据
			 //新增
			 if(clock.getDiffer() == 1){//打卡
				 PunchCardDetails pcd = new PunchCardDetails();
				 pcd.setUserid(userid);
				 pcd.setData(putime);//打卡日期(yyyy-MM-dd)
				 if(clock.getType() == 1){
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							 pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 2){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else if(clock.getType() == 3){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 4){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }else if(clock.getType() == 5){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 6){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }
				 if(shif != null){
					 pcd.setYdkcs(shif.getSxbcs()*2);//应打卡次数
				 }
				 pcd.setQyid(qyid);//企业id
				 pcd.setDksj(startDate);//打卡时间
				 
				 punchcarddetailsmapper.insertSelective(pcd);
				 
				 dkmx = pcd.getId();
			 }
		 }
		 
		 
		 
lal committed
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
//		 //打卡记录
//		 if(clock.getDiffer() == 2){//更新打卡 
//			PunchRecord punch = punchrecordmapper.selectPunchResults(startDate,endDate,userid,clock.getType());
//			if(punch != null){
//				PunchRecord pr = new PunchRecord();
//				pr.setId(punch.getId());
//				pr.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:补卡 4:请假)
//				pr.setSort(0);//序号(0:打卡无效:此记录已被更新)
//				punchrecordmapper.updateByPrimaryKeySelective(pr);
//			}else{
//				return ResultUtil.error("打卡失败");
//			}
//		 }
lal committed
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
		
		PunchRecord pre = new PunchRecord();
		pre.setDktime(Long.valueOf(clock.getPunchtime()));// 打卡时间
		if(clock.getPunchcardtype() == 1){
			pre.setLon(Double.valueOf(clock.getLon()));// 经度
			pre.setLat(Double.valueOf(clock.getLat()));// 纬度
			pre.setAddress(clock.getAddress());// 定位地址
		}
		
		Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
		if(("0").equals(clock.getPunchcardtime())){
			pre.setResults(0);// 打卡结果
		}else{
			if((clock.getType())%2 > 0){//上班
				if(time > 0){
					pre.setResults(Integer.valueOf(time.toString()));// 打卡结果
				}else{
					pre.setResults(0);// 打卡结果
				}
			}else{//下班
				if(time > 0){
					pre.setResults(0);// 打卡结果
				}else{
					pre.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
				}
			}
		}
		
		pre.setUserId(userid);// 用户id
		if((clock.getType())%2 > 0){
			pre.setType(1);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time > 0){
					pre.setStatus(3);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}else{
			pre.setType(2);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time < 0){
					pre.setStatus(4);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}
		pre.setSort(clock.getType());// 序号
		pre.setCardType(clock.getPunchcardtype());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
		if(clock.getPunchcardtype() == 2){
			pre.setMac(clock.getMac());// mac地址
			pre.setMacname(clock.getMacname());// WIFI名称
		}
		pre.setQyid(qyid);// 企业id
		String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
		pre.setAttdate(attdate_+" "+ClockInTool.dateToWeek2(putime));// 考勤日期
		
		long date = new Date().getTime();
		if(("0").equals(clock.getPunchcardtime())){
			pre.setAttime(date);// 考勤时间(应打卡时间)	
		}else{
			pre.setAttime(Long.valueOf(clock.getPunchcardtime()));// 考勤时间(应打卡时间)
		}
		
		pre.setDkmxid(dkmx);// 打卡明细id
		pre.setBcid(clock.getShifid());// 班次id
lal committed
1696
//		punchrecordmapper.insertSelective(pre);//新增打卡记录
lal committed
1697 1698 1699 1700 1701
			
		 
		 
		return ResultUtil.data(null,"打卡成功");
	 }
lal committed
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 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
	 
	 
	//考勤组绑定的打卡方式
	@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 {
		 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();
		 
		 Long startDate = 0l;
	     Long endDate = 0l;
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
		 KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(userBean.getEmpNum(),userBean.getOrgCode()); //考勤组信息
		 
lal committed
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 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821
		 if(attgro != null) {
			//APP获取当前天的考勤信息
			 AttendanceCardListDto attdate = MethodCall(userBean.getOrgCode(),userBean.getEmpNum(),attconditions.getDate());
				 
			   //外勤   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();
			    		akm.setName(kqjs.getName());// 打卡名称
			    		akm.setMac("");// wifi【wifi】
			    		akm.setAttrange(0);// 范围【地址】
			    		akm.setType(1);// 类型(1:考勤机;2:地址;3:WIFI)
			    		akm.setLongitude(0);// 经度【地址】
			    		akm.setLatitude(0);// 纬度【地址】
			    		akms.add(akm);
			    	}else if(abp.getType() == 2){
			    		PunchCardAddress kqdzs = punchcardaddressmapper.selectByPrimaryKey(abp.getDkfsid()); 
			    		AttClockMethod akm = AttClockMethod.builder().build();
			    		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());// 纬度【地址】
			    		akms.add(akm);
			    	}else{
			    		PunchCardWiFi kqwfs = punchcardwifimapper.selectByPrimaryKey(abp.getDkfsid()); 
			    		AttClockMethod akm = AttClockMethod.builder().build();
			    		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);// 纬度【地址】
			    		akms.add(akm);
			    	}
			    }
			    attdate.setMachine(akms);
			    
			  //打卡记录
		     List<KqglAssoDkjl> dajllist = kqglassodkjlmapper.getDetailedRecordClock(startDate,endDate,userBean.getEmpNum());
		     attdate.setAttpr(dajllist);
		     
		     
		    //当天第一次打卡 前一天晚走小时**************************************************
		     double latetime_ = 0;//前天晚走时长(分钟)
		     Long changed_time = 0l;//晚到后应打卡时间
		     
		     List<AttSchedule> ash = attdate.getAttsch();
		     KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, ash.get(0).getId()));
lal committed
1822
			 
lal committed
1823 1824 1825
			int dkcs_ = shif.getSxbcs();//上下班打卡次数
			int iswzwd = shif.getIsWzwd();//是否开启晚走晚到(0:否;1:是)
			
lal committed
1826
			//统一分钟数
lal committed
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854
			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
				sbwd1 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd1()) * 60));//上班晚到1
				xbwz2 = Double.valueOf(shif.getXbwz2()) * 60;//下班晚走2
				sbwd2 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd2()) * 60));//上班晚到2
				xbwz3 = Double.valueOf(shif.getXbwz3()) * 60;//下班晚走3
				sbwd3 = Integer.valueOf(String.valueOf(Double.valueOf(shif.getSbwd3()) * 60));//上班晚到3
				 
				 //获取前一天最后下班的时间
				 yesterdaymx = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, userBean.getEmpNum())
							.ge(KqglAssoDkmx::getDksj, startDateyesterday).le(KqglAssoDkmx::getDksj, endDateyesterday));
				 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
1855
				 }
lal committed
1856 1857
			 	 if(attdateyesterday.getAttsch().size() == 4 || attdateyesterday.getAttsch().size() == 6) {
			 		yesendtime2 = ashyes.get(3).getTime();
lal committed
1858
				 }
lal committed
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
			 	 if(attdateyesterday.getAttsch().size() == 6) {
			 		yesendtime3 = ashyes.get(5).getTime();
				  }
		
				 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
1875
				 }
lal committed
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
				 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
1888 1889
				 }
			 }
lal committed
1890 1891 1892 1893 1894 1895 1896 1897 1898
			 attdate.setLatetime(latetime_);
			 attdate.setChanged_time(changed_time);
		     
			return ResultUtil.data(attdate);
		 }else {
			 
			 AttendanceCardListDto attdate_ = AttendanceCardListDto.builder().build();
			 
			 return ResultUtil.data(attdate_,"未加入考勤组");
lal committed
1899 1900
		 }
	 }
lal committed
1901
	
ilal committed
1902
}