KqglServiceImpl.java 47 KB
Newer Older
lal committed
1 2
package cn.timer.api.controller.kqgl.service;

lal committed
3
import java.text.ParseException;
lal committed
4
import java.text.SimpleDateFormat;
lal committed
5
import java.util.ArrayList;
lal committed
6
import java.util.Date;
lal committed
7
import java.util.List;
lal committed
8 9

import org.springframework.beans.factory.annotation.Autowired;
lal committed
10 11
import org.springframework.stereotype.Service;

lal committed
12 13
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

lal committed
14 15
import cn.timer.api.bean.kqmk.KqglAssoBcsz;
import cn.timer.api.bean.kqmk.KqglAssoDkjl;
lal committed
16
import cn.timer.api.bean.kqmk.KqglAssoDkmx;
lal committed
17
import cn.timer.api.bean.kqmk.KqglAssoLeaveBalance;
lal committed
18
import cn.timer.api.bean.kqmk.KqglAssoLeaveEmployeeBalance;
lal committed
19
import cn.timer.api.bean.kqmk.KqglAssoLeaveRules;
lal committed
20 21
import cn.timer.api.bean.kqmk.KqglAssoOvertimeRange;
import cn.timer.api.bean.kqmk.KqglAssoOvertimeRules;
lal committed
22
import cn.timer.api.bean.kqmk.KqglAssoRelationSummary;
lal committed
23
import cn.timer.api.bean.kqmk.KqglAssoTeshu;
lal committed
24
import cn.timer.api.bean.kqmk.KqglAssoYhkqz;
lal committed
25
import cn.timer.api.bean.kqmk.KqglAssoZhoupaiban;
lal committed
26
import cn.timer.api.bean.kqmk.KqglMainKqz;
lal committed
27
import cn.timer.api.bean.yggl.YgglMainEmp;
lal committed
28
import cn.timer.api.config.exception.CustomException;
lal committed
29
import cn.timer.api.controller.kqgl.ClockInTool;
lal committed
30
import cn.timer.api.controller.kqgl.EmptyUtil;
lal committed
31
import cn.timer.api.dao.kqmk.KqglAssoLeaveBalanceMapper;
lal committed
32
import cn.timer.api.dao.kqmk.KqglAssoPbmxMapper;
lal committed
33
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
lal committed
34
import cn.timer.api.dto.kqmk.AttEvectionApprovalDto;
lal committed
35
import cn.timer.api.dto.kqmk.AttLateLate;
lal committed
36 37 38
import cn.timer.api.dto.kqmk.AttLeaveApprovalDto;
import cn.timer.api.dto.kqmk.AttOvertimeApprovalDto;
import cn.timer.api.dto.kqmk.AttRepairApprovalDto;
lal committed
39 40
import cn.timer.api.dto.kqmk.AttSchedule;
import cn.timer.api.dto.kqmk.AttendanceCardListDto;
lal committed
41
import cn.timer.api.dto.kqmk.KqglAssoPbmxDto;
lal committed
42
import cn.timer.api.utils.DateUtil;
lal committed
43

lal committed
44 45 46 47
/**
 * @author lal
 *	记录用户假期审批流程  对应减去剩余余额
 */
lal committed
48 49 50
@Service
public class KqglServiceImpl implements KqglService {

lal committed
51 52 53
	@Autowired
	private KqglAssoLeaveBalanceMapper kqglassoleavebalancemapper;
	
lal committed
54 55 56 57 58
	/**
	 * 考勤请假审批
	 */
	@Override
	public boolean attleaveapproval(AttLeaveApprovalDto leaveappr) {
lal committed
59 60
		String startdate = new SimpleDateFormat("yyyy-MM-dd").format(leaveappr.getStarttime());
		String enddate = new SimpleDateFormat("yyyy-MM-dd").format(leaveappr.getEndtime());
lal committed
61
		String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
62 63 64
		for(String num : days) {
			//记入打卡月汇总关联表
			KqglAssoRelationSummary.builder().userId(leaveappr.getUserid()).appTime(num).approvalId(leaveappr.getLeaveid()).approvalType(2).duration(leaveappr.getDuration())
lal committed
65
				.leaveTypeId(leaveappr.getLeavetype()).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(leaveappr.getStarttime()))
lal committed
66
				.endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(leaveappr.getEndtime())).orgCode(leaveappr.getOrgcode()).build().insert();
lal committed
67
		}
lal committed
68
		YgglMainEmp emp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, leaveappr.getUserid()).eq(YgglMainEmp::getOrgCode, leaveappr.getOrgcode()));
lal committed
69
		
lal committed
70
		int modifynumber = 1;
lal committed
71
		KqglAssoLeaveBalance balan = kqglassoleavebalancemapper.selectOne(new QueryWrapper<KqglAssoLeaveBalance>().lambda().eq(KqglAssoLeaveBalance::getUserid, leaveappr.getUserid()).eq(KqglAssoLeaveBalance::getOrgCode, leaveappr.getOrgcode())
lal committed
72 73 74 75 76 77
				.orderByDesc(KqglAssoLeaveBalance :: getModifyNumber).last("LIMIT 1"));
		if(balan != null) {
			modifynumber = balan.getModifyNumber()+1;
		}
		KqglAssoLeaveBalance.builder().leaveRulesId(leaveappr.getLeavetype()).userid(leaveappr.getUserid()).modifyAction(2).balanceDays("-"+leaveappr.getDuration())
		.reason("系统按照规则自动").modifyUserid(emp.getEmpNum()).modifyTimer(new Date().getTime()).orgCode(emp.getOrgCode()).isAutomatic(1).modifyNumber(modifynumber).build().insert();//员工假期余额
lal committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
		
		
		//查询员工假期余额表中所对应的假期id
		KqglAssoLeaveEmployeeBalance emba = KqglAssoLeaveEmployeeBalance.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveEmployeeBalance>().lambda().eq(KqglAssoLeaveEmployeeBalance::getLeaveRulesId, leaveappr.getLeavetype())
				.eq(KqglAssoLeaveEmployeeBalance::getUserid, leaveappr.getUserid()).eq(KqglAssoLeaveEmployeeBalance::getOrgCode, leaveappr.getOrgcode()));
		
		//获取最后得到的最终余额
		double balance_days = kqglassoleavebalancemapper.Sumbalancedays(leaveappr.getUserid(), leaveappr.getOrgcode(),leaveappr.getLeavetype());
		if(emba != null && balance_days > 0) {
			if(emba.getBalanceDays() != -1) {//确认为限制余额的
				//修改最终的余额数
				KqglAssoLeaveEmployeeBalance.builder().id(emba.getId()).balanceDays(balance_days).build().updateById();
			}
		}
		
lal committed
93 94 95 96 97 98 99 100
		return true;
	}

	/**
	 * 考勤加班审批
	 */
	@Override
	public boolean attovertimeapproval(AttOvertimeApprovalDto overappr) {
lal committed
101 102
		String startdate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getStarttime());
		String enddate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getEndtime());
lal committed
103
		String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
104 105 106 107
		for(String num : days) {
			
			//记入打卡月汇总关联表
			KqglAssoRelationSummary.builder().userId(overappr.getUserid()).appTime(num).approvalId(overappr.getOvertimeid()).approvalType(1).duration(overappr.getDuration())
lal committed
108
				.overtimeTypeId(overappr.getOvertimetype()).compensateId(overappr.getCompensate()).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getStarttime()))
lal committed
109
				.endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getEndtime())).orgCode(overappr.getOrgcode()).build().insert();
lal committed
110
		}
lal committed
111
		
lal committed
112
		YgglMainEmp emp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, overappr.getUserid()).eq(YgglMainEmp::getOrgCode, overappr.getOrgcode()));
lal committed
113 114 115 116 117 118
		
		//查询当前公司调休的id
		KqglAssoLeaveRules learul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getOrgCode, emp.getOrgCode()).eq(KqglAssoLeaveRules::getRulesType, 2));
		
		if(overappr.getCompensate() == 1) {
			
lal committed
119 120
			double duration = 0l;//
			
lal committed
121
			int modifynumber = 1;
lal committed
122
			KqglAssoLeaveBalance balan = kqglassoleavebalancemapper.selectOne(new QueryWrapper<KqglAssoLeaveBalance>().lambda().eq(KqglAssoLeaveBalance::getUserid, overappr.getUserid()).eq(KqglAssoLeaveBalance::getOrgCode, overappr.getOrgcode())
lal committed
123 124 125 126 127
					.orderByDesc(KqglAssoLeaveBalance :: getModifyNumber).last("LIMIT 1"));
			if(balan != null) {
				modifynumber = balan.getModifyNumber()+1;
			}
			
lal committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
			KqglAssoYhkqz yhd = KqglAssoYhkqz.builder().build().selectOne(new QueryWrapper<KqglAssoYhkqz>().lambda().eq(KqglAssoYhkqz::getUserid, overappr.getUserid()).eq(KqglAssoYhkqz::getQyid, overappr.getOrgcode()));
			if(yhd != null) {
				KqglAssoOvertimeRange timeran = KqglAssoOvertimeRange.builder().build().selectOne(new QueryWrapper<KqglAssoOvertimeRange>().lambda().eq(KqglAssoOvertimeRange::getAttgroupId, yhd.getKqzid()));
				if(timeran != null) {
					KqglAssoOvertimeRules rul = KqglAssoOvertimeRules.builder().build().selectOne(new QueryWrapper<KqglAssoOvertimeRules>().lambda().eq(KqglAssoOvertimeRules::getId, timeran.getOvertimeRulesId()));
					if(rul != null) {
						//1:工作日加班;2:休息日加班;3:节假日加班
						if(overappr.getOvertimetype() == 1) {
							if(rul.getIsWorkovertime() == 1) {
								if(rul.getWork() == 1) {
									duration = Double.valueOf(rul.getWorkOne()) * overappr.getDuration();
								}else if(rul.getWork() == 3) {
									duration = Double.valueOf(rul.getWorkThree()) * overappr.getDuration();
								}
							}
						}else if(overappr.getOvertimetype() == 2) {
							if(rul.getIsRestovertime() == 1) {
								if(rul.getRest() == 1) {
									duration = Double.valueOf(rul.getRestOne()) * overappr.getDuration();
								}else if(rul.getRest() == 3) {
									duration = Double.valueOf(rul.getRestThree()) * overappr.getDuration();
								}
							}
						}else {
							if(rul.getIsHolidays() == 1) {
								if(rul.getHolidays() == 1) {
									duration = Double.valueOf(rul.getHolidaysOne()) * overappr.getDuration();
								}else if(rul.getHolidays() == 3) {
									duration = Double.valueOf(rul.getHolidaysThree()) * overappr.getDuration();
								}
							}
						}
					}
				}
			}
			
			KqglAssoLeaveBalance.builder().leaveRulesId(learul.getId()).userid(overappr.getUserid()).modifyAction(2).balanceDays("+"+duration)
			.reason("系统按照审批自动(加班)").modifyUserid(emp.getEmpNum()).modifyTimer(overappr.getStarttime()).orgCode(emp.getOrgCode()).isAutomatic(1).modifyNumber(modifynumber).build().insert();//员工假期余额
			
			
			//查询员工假期余额表中所对应的假期id
			KqglAssoLeaveEmployeeBalance emba = KqglAssoLeaveEmployeeBalance.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveEmployeeBalance>().lambda().eq(KqglAssoLeaveEmployeeBalance::getLeaveRulesId, learul.getId())
					.eq(KqglAssoLeaveEmployeeBalance::getUserid, overappr.getUserid()).eq(KqglAssoLeaveEmployeeBalance::getOrgCode, overappr.getOrgcode()));
			
			//获取最后得到的最终余额
			double balance_days = kqglassoleavebalancemapper.Sumbalancedays(overappr.getUserid(), overappr.getOrgcode(),learul.getId());
			if(emba != null && balance_days > 0) {
				if(emba.getBalanceDays() != -1) {//确认为限制余额的
					//修改最终的余额数
					KqglAssoLeaveEmployeeBalance.builder().id(emba.getId()).balanceDays(balance_days).build().updateById();
				}
			}
			
lal committed
181 182
		}
		
lal committed
183 184 185 186 187 188 189 190
		return true;
	}

	/**
	 * 考勤出差外出审批
	 */
	@Override
	public boolean attevectionapproval(AttEvectionApprovalDto evecappr) {
lal committed
191 192 193
		if(evecappr.getEvectiontype() == 1) {	//出差
			String startdate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getStarttime());
			String enddate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getEndtime());
lal committed
194
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
195 196
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
197
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(3).duration(evecappr.getDuration())
lal committed
198 199
					.startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getStarttime())).endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getEndtime()))
					.orgCode(evecappr.getOrgcode()).build().insert();
lal committed
200 201 202 203
			}
		}else {	//外出
			String startdate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getStarttime());
			String enddate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getEndtime());
lal committed
204
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
205 206
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
207
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(4).duration(evecappr.getDuration())
lal committed
208 209
					.startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getStarttime())).endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getEndtime()))
					.orgCode(evecappr.getOrgcode()).build().insert();
lal committed
210 211
			}
		}
lal committed
212 213 214
		return true;
	}

lal committed
215 216 217
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
	
lal committed
218 219 220 221 222
	/**
	 * 考勤补卡审批
	 */
	@Override
	public boolean attrepairapproval(AttRepairApprovalDto repaappr) {
lal committed
223
		String cardrepltime = new SimpleDateFormat("yyyy-MM-dd").format(repaappr.getCardrepltime());//补卡时间
lal committed
224 225 226
		
		boolean isRange = true;
		
lal committed
227 228 229 230 231 232
		int atttype = 0;//类型(0:无排班打卡 1:上班 2:下班)
		int results = 0;//打卡结果
		int type = 0;
		long attime = 0l;//应打卡时间戳
		int dkmxid = 0;//打卡明细ID
		
lal committed
233 234 235 236 237 238 239 240 241
		Long start_time = null;
		Long end_time = null;
		try {
			start_time = DateUtil.getStartTime(0,DateUtil.getStringTime(cardrepltime,"yyyy-MM-dd")).getTime();
			end_time = DateUtil.getnowEndTime(23,DateUtil.getStringTime(cardrepltime,"yyyy-MM-dd")).getTime();
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		
lal committed
242
		//记入打卡月汇总关联表
lal committed
243 244
		KqglAssoRelationSummary.builder().userId(repaappr.getUserid()).appTime(cardrepltime).approvalId(repaappr.getRepairid()).approvalType(5).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(repaappr.getCardrepltime())).orgCode(repaappr.getOrgcode()).build().insert();
		
lal committed
245
		int shifid = 0;
lal committed
246 247 248
		try {
			KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(repaappr.getUserid(),repaappr.getOrgcode()); //考勤组信息
			if(attgro != null) {
lal committed
249
				AttendanceCardListDto attdate = MethodCall(repaappr.getOrgcode(),repaappr.getUserid(),cardrepltime);//获取当天打卡班次信息
lal committed
250 251 252
				
				if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {//班次不为空
					List<AttSchedule> ash = attdate.getAttsch();//获取当天应打卡时间
lal committed
253
					shifid = ash.get(0).getId();//班次id
lal committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
					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() == 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
269 270 271 272
		    		if(ash.get(0).getId() != 0) { //有排班  非休息
		    			
		    			KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, shifid));
		    			
lal committed
273 274 275
		    			KqglAssoDkmx dkmc = KqglAssoDkmx.builder().build().selectOne(new QueryWrapper<KqglAssoDkmx>().lambda().eq(KqglAssoDkmx::getUserid, repaappr.getUserid()).eq(KqglAssoDkmx::getQyid, repaappr.getOrgcode())
								.ge(KqglAssoDkmx::getDksj, start_time).le(KqglAssoDkmx::getDksj, end_time));//获取补卡当天是否有打卡记录
		    			if(dkmc != null) {
lal committed
276
		    				dkmxid = dkmc.getId();
lal committed
277
		    				if(attdate.getAttsch().size() == 2) {//一套班次
lal committed
278
		    					if(repaappr.getCardreplperiod() == 1 && dkmc.getSbdk1() == null) {//上班
lal committed
279 280 281 282 283 284 285 286 287 288 289
		    						if(starttime1ks > 0 && starttime1js > 0) {
//		    							boolean sb1 = verification_range(starttime1ks,starttime1js,repaappr.getCardrepltime());
		    							 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks);//应打卡开始时间
		    							 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js);//应打卡结束时间
		    							 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repaappr.getCardrepltime());//打卡时间
		    							 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
		    							 if (!effectiveDate) {
		    								 System.out.println("当前打卡时间不在范围内");
		    								 isRange = false;
		    							 }
		    						}
lal committed
290
		    						int sbdkjg = 0;
lal committed
291 292 293 294 295 296 297 298 299 300 301
		    						if(isRange) {
			    						Long time = (repaappr.getCardrepltime() - starttime1)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 
										 Double gzsctime = null;//工作时长
										 if(dkmc.getXbdk1() != null){
											 Long time1 = (repaappr.getCardrepltime() - dkmc.getXbdk1())/1000/60;
											 gzsctime = Math.abs(Double.valueOf(time1.toString()));//只打一次卡时计算工作时长
										 }
lal committed
302
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk1(repaappr.getCardrepltime()).sbdk1jg(sbdkjg).dktj1(1).gzsc(gzsctime).build().updateById();
lal committed
303 304
		    						}
		    						
lal committed
305 306 307 308
		    						atttype = 1;
		    						results = sbdkjg;
		    						attime = starttime1;
		    					}else if(repaappr.getCardreplperiod() == 2 && dkmc.getXbdk1() == null) {//下班
lal committed
309 310 311 312 313 314 315 316 317 318
		    						if(endtime1ks > 0 && endtime1js > 0) {
		    							 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks);//应打卡开始时间
		    							 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js);//应打卡结束时间
		    							 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repaappr.getCardrepltime());//打卡时间
		    							 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
		    							 if (!effectiveDate) {
		    								 System.out.println("当前打卡时间不在范围内");
		    								 isRange = false;
		    							 }
		    						}
lal committed
319
		    						int xbdk1jg = 0;
lal committed
320
		    						if(isRange) {
lal committed
321
		    							
lal committed
322 323 324 325 326 327 328 329 330
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长
										 if(dkmc.getSbdk1() != null) {
											 Long time1 = (repaappr.getCardrepltime() - dkmc.getSbdk1())/1000/60;
											 gzsctime = Math.abs(Double.valueOf(time1.toString()));
										 }
lal committed
331
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk1(repaappr.getCardrepltime()).xbdk1jg(xbdk1jg).dktj2(1).gzsc(gzsctime).build().updateById();
lal committed
332
		    						}
lal committed
333 334 335 336
		    						
		    						atttype = 2;
		    						results = xbdk1jg;
		    						attime = endtime1;
lal committed
337 338 339 340
		    					}
		    				}else if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb1 = verification_range(starttime1ks,starttime1js,repaappr.getCardrepltime());
lal committed
341
		    						if(sb1 && dkmc.getSbdk1() == null) {
lal committed
342
		    							int sbdkjg = 0;
lal committed
343 344 345 346 347 348
			    						Long time = (repaappr.getCardrepltime() - starttime1)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
349
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk1(repaappr.getCardrepltime()).sbdk1jg(sbdkjg).dktj1(1).gzsc(gzsctime).build().updateById();
lal committed
350 351 352 353
		    							
		    							atttype = 1;
		    							results = sbdkjg;
		    							attime = starttime1;
lal committed
354 355 356
		    						}
		    						
		    						boolean sb2 = verification_range(starttime2ks,starttime2js,repaappr.getCardrepltime());
lal committed
357
		    						if(sb2 && dkmc.getSbdk2() == null) {
lal committed
358
		    							int sbdkjg = 0;
lal committed
359 360 361 362 363 364
			    						Long time = (repaappr.getCardrepltime() - starttime2)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
365
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk2(repaappr.getCardrepltime()).sbdk2jg(sbdkjg).dktj3(1).gzsc(gzsctime).build().updateById();
lal committed
366 367 368 369
		    							
		    							atttype = 3;
		    							results = sbdkjg;
		    							attime = starttime2;
lal committed
370 371 372 373
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb1 = verification_range(endtime1ks,endtime1js,repaappr.getCardrepltime());
lal committed
374
		    						if(xb1 && dkmc.getXbdk1() == null) {
lal committed
375
		    							int xbdk1jg = 0;
lal committed
376 377 378 379 380 381
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
382
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk1(repaappr.getCardrepltime()).xbdk1jg(xbdk1jg).dktj2(1).gzsc(gzsctime).build().updateById();
lal committed
383 384 385 386
										 
										 atttype = 2;
										 results = xbdk1jg;
										 attime = endtime1;
lal committed
387 388 389
		    						}
		    						
		    						boolean xb2 = verification_range(endtime2ks,endtime2js,repaappr.getCardrepltime());
lal committed
390
		    						if(xb2 && dkmc.getXbdk2() == null) {
lal committed
391
		    							int xbdk2jg = 0;
lal committed
392 393 394 395 396 397
		    							Long time = (repaappr.getCardrepltime() - endtime2)/1000/60;
										 if(time > 0){}else{
											 xbdk2jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
398
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk2(repaappr.getCardrepltime()).xbdk2jg(xbdk2jg).dktj4(1).gzsc(gzsctime).build().updateById();
lal committed
399 400 401 402
										 
										 atttype = 4;
										 results = xbdk2jg;
										 attime = endtime2;
lal committed
403 404 405 406 407 408
		    						}
		    						
		    					}
		    				}else if(attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb3 = verification_range(starttime3ks,starttime3js,repaappr.getCardrepltime());
lal committed
409
		    						if(sb3 && dkmc.getSbdk3() == null) {
lal committed
410
		    							int sbdkjg = 0;
lal committed
411 412 413 414 415 416
			    						Long time = (repaappr.getCardrepltime() - starttime3)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
417
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk3(repaappr.getCardrepltime()).sbdk3jg(sbdkjg).dktj5(1).gzsc(gzsctime).build().updateById();
lal committed
418 419 420
		    							 atttype = 5;
		    							 results = sbdkjg;
		    							 attime = starttime3;
lal committed
421 422 423 424
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb3 = verification_range(endtime3ks,endtime3js,repaappr.getCardrepltime());
lal committed
425
		    						if(xb3 && dkmc.getXbdk3() == null) {
lal committed
426
		    							int xbdk3jg = 0;
lal committed
427 428 429 430 431 432
		    							Long time = (repaappr.getCardrepltime() - endtime3)/1000/60;
										 if(time > 0){}else{
											 xbdk3jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
433
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk3(repaappr.getCardrepltime()).xbdk3jg(xbdk3jg).dktj6(1).gzsc(gzsctime).build().updateById();
lal committed
434 435 436
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
lal committed
437 438 439 440 441
		    						}
		    						
		    					}
		    				}
		    				
lal committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
		    			}else {//补卡当天无打卡记录时
		    				
		    				KqglAssoDkmx pcd = KqglAssoDkmx.builder().userid(repaappr.getUserid()).data(cardrepltime).qyid(repaappr.getOrgcode()).dksj(start_time).ydkcs(shif.getSxbcs()*2)
		    						.gzsc(0d).build();
		    				
//		    				int yzcd = shif.getYzcdfzs();//严重迟到分钟数
//							int kgcdfzs  = shif.getKgcdfzs();//旷工迟到分钟数 
		    				
		    				if(attdate.getAttsch().size() == 2) {//一套班次
		    					if(repaappr.getCardreplperiod() == 1) {//上班
		    						if(starttime1ks > 0 && starttime1js > 0) {
		    							 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1ks);//应打卡开始时间
		    							 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(starttime1js);//应打卡结束时间
		    							 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repaappr.getCardrepltime());//打卡时间
		    							 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
		    							 if (!effectiveDate) {
		    								 System.out.println("当前打卡时间不在范围内");
		    								 isRange = false;
		    							 }
		    						}
lal committed
462
		    						int sbdkjg = 0;
lal committed
463 464 465 466 467 468 469 470
		    						if(isRange) {
			    						Long time = (repaappr.getCardrepltime() - starttime1)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 
										 pcd.setSbdk1(repaappr.getCardrepltime());
										 pcd.setSbdk1jg(sbdkjg);
lal committed
471 472
										 pcd.setDktj1(1);
										 
lal committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
		    						}
		    						
		    						atttype = 1;
		    						results = sbdkjg;
		    						attime = starttime1;
		    					}else if(repaappr.getCardreplperiod() == 2) {//下班
		    						if(endtime1ks > 0 && endtime1js > 0) {
		    							 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1ks);//应打卡开始时间
		    							 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(endtime1js);//应打卡结束时间
		    							 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repaappr.getCardrepltime());//打卡时间
		    							 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
		    							 if (!effectiveDate) {
		    								 System.out.println("当前打卡时间不在范围内");
		    								 isRange = false;
		    							 }
		    						}
lal committed
493
		    						int xbdk1jg = 0;
lal committed
494 495 496 497 498 499 500 501 502
		    						if(isRange) {
		    							
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 
										 pcd.setXbdk1(repaappr.getCardrepltime());
										 pcd.setXbdk1jg(xbdk1jg);
lal committed
503
										 pcd.setDktj2(1);
lal committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
		    						}
		    						
		    						atttype = 2;
		    						results = xbdk1jg;
		    						attime = endtime1;
		    					}
		    				}else if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb1 = verification_range(starttime1ks,starttime1js,repaappr.getCardrepltime());
		    						if(sb1) {
lal committed
518
		    							int sbdkjg = 0;
lal committed
519 520 521 522 523 524 525
			    						Long time = (repaappr.getCardrepltime() - starttime1)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }

										 pcd.setSbdk1(repaappr.getCardrepltime());
										 pcd.setSbdk1jg(sbdkjg);
lal committed
526
										 pcd.setDktj1(1);
lal committed
527 528 529 530 531 532 533 534 535 536 537 538
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
		    							
		    							atttype = 1;
		    							results = sbdkjg;
		    							attime = starttime1;
		    						}
		    						
		    						boolean sb2 = verification_range(starttime2ks,starttime2js,repaappr.getCardrepltime());
		    						if(sb2) {
lal committed
539
		    							int sbdkjg = 0;
lal committed
540 541 542 543 544 545 546
			    						Long time = (repaappr.getCardrepltime() - starttime2)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }

										 pcd.setSbdk2(repaappr.getCardrepltime());
										 pcd.setSbdk2jg(sbdkjg);
lal committed
547
										 pcd.setDktj3(1);
lal committed
548 549 550 551 552 553 554 555 556 557 558 559 560
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
		    							
		    							atttype = 3;
		    							results = sbdkjg;
		    							attime = starttime2;
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb1 = verification_range(endtime1ks,endtime1js,repaappr.getCardrepltime());
		    						if(xb1) {
lal committed
561
		    							int xbdk1jg = 0;
lal committed
562 563 564 565 566 567 568
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }

										 pcd.setXbdk1(repaappr.getCardrepltime());
										 pcd.setXbdk1jg(xbdk1jg);
lal committed
569
										 pcd.setDktj2(1);
lal committed
570 571 572 573 574 575 576 577 578 579 580 581
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 2;
										 results = xbdk1jg;
										 attime = endtime1;
		    						}
		    						
		    						boolean xb2 = verification_range(endtime2ks,endtime2js,repaappr.getCardrepltime());
		    						if(xb2) {
lal committed
582
		    							int xbdk2jg = 0;
lal committed
583 584 585 586 587 588
		    							Long time = (repaappr.getCardrepltime() - endtime2)/1000/60;
										 if(time > 0){}else{
											 xbdk2jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 pcd.setXbdk2(repaappr.getCardrepltime());
										 pcd.setXbdk2jg(xbdk2jg);
lal committed
589
										 pcd.setDktj4(1);
lal committed
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 4;
										 results = xbdk2jg;
										 attime = endtime2;
		    						}
		    						
		    					}
		    				}else if(attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb3 = verification_range(starttime3ks,starttime3js,repaappr.getCardrepltime());
		    						if(sb3) {
lal committed
605
		    							int sbdkjg = 0;
lal committed
606 607 608 609 610 611 612
			    						Long time = (repaappr.getCardrepltime() - starttime3)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										
										 pcd.setSbdk3(repaappr.getCardrepltime());
										 pcd.setSbdk3jg(sbdkjg);
lal committed
613
										 pcd.setDktj5(1);
lal committed
614 615 616 617 618 619 620 621 622 623 624 625 626
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
		    							 atttype = 5;
		    							 results = sbdkjg;
		    							 attime = starttime3;
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb3 = verification_range(endtime3ks,endtime3js,repaappr.getCardrepltime());
		    						if(xb3) {
lal committed
627
		    							int xbdk3jg = 0;
lal committed
628 629 630 631 632 633 634 635
		    							Long time = (repaappr.getCardrepltime() - endtime3)/1000/60;
										 if(time > 0){}else{
											 xbdk3jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 
										 
										 pcd.setXbdk3(repaappr.getCardrepltime());
										 pcd.setXbdk3jg(xbdk3jg);
lal committed
636
										 pcd.setDktj6(1);
lal committed
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
		    						}
		    						
		    					}
		    				}
		    				
		    				dkmxid = pcd.getId();
		    			}
		    			
		    			if((atttype)%2 > 0){
		    				type = 1;
		    			}else {
		    				type = 2;
lal committed
657 658
		    			}
		    			
lal committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672
		    			Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(cardrepltime,"yyyy-MM-dd")).getTime();
		    			String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
		    			
		    			//attime  应打卡时间
		    			
		    			KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(repaappr.getCardrepltime()).results(results).userId(repaappr.getUserid()).type(type).status(5).sort(atttype)
								.cardType(0).qyid(repaappr.getOrgcode()).attdate(attdate_+" "+ClockInTool.dateToWeek2(cardrepltime)).attime(attime).dkmxid(dkmxid).bcid(shifid).remarks("审批补卡通过打卡").punchmode(0)
								.punchequipment("").commentary("成功打卡").build();
						
						if (!pre.insert()) {
							throw new CustomException("打卡记录-新增异常-2");
						 }
		    			
		    			
lal committed
673 674 675 676 677 678 679 680
		    		}
				}
			}
			
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
lal committed
681 682
		
		
lal committed
683 684
		return true;
	}
lal committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
	
	
	public boolean verification_range(long punchstart,long punchend,long time_) {
		 boolean isRange = true;
		 String staputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchstart);//应打卡开始时间
		 String entputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(punchend);//应打卡结束时间
		 String DKputime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(time_);//打卡时间
		 boolean effectiveDate = ClockInTool.hourMinuteBetween(DKputime, staputime, entputime,"yyyy-MM-dd HH:mm");
		 if (!effectiveDate) {
			 System.out.println("当前打卡时间不在范围内");
			 isRange = false;
		 }
		 
		 return isRange;
	}
lal committed
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 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 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
	
	@Autowired
	private KqglAssoPbmxMapper kqglassopbmxmapper;
	
	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);
		 }
//		 Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
//	     Long endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
		 
	     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){//自由排班
				//未排班时,员工可选择班次打卡
			    if(attgro.getIsXzbcdk() == 1){
			    	attcar.setOptscheduling(true);	
			    }else{
			    	attcar.setOptscheduling(false);
			    }
				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:自由工时
		 }
		 return attcar;
	 }
	
	
	public void Getshiftinformationbatch(KqglAssoBcsz shiftm,AttendanceCardListDto attcar,String str){
		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:是)
		
		//次日专用
		String next_day = ClockInTool.requires_extra_times(str,1,2,1);
		
		 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){
			    		AttSchedule as = AttSchedule.builder().id(shiftm.getId()).sort(1).time(Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbdk1()+":00").replaceAll("\r|\n", ""))))
			    				.starttime(("").equals(shiftm.getSbqjks1()) || shiftm.getSbqjks1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjks1()+":00").replaceAll("\r|\n", ""))))
			    				.endtime(("").equals(shiftm.getSbqjjs1()) || shiftm.getSbqjjs1() == null ? 0 : Long.valueOf(ClockInTool.dateToStamp((str+" "+shiftm.getSbqjjs1()+":00").replaceAll("\r|\n", ""))))
			    				.nextday(0).build();
			    		
			    		atts.add(as);
	    			}else{
	    				//次日
	    				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);
	    				}
			    		
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//2次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
	    				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);
	    				}
			    		
	    			}else{
	    				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);
	    				}
			    		
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
	    				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);
	    				}
			    		
	    			}else{
	    				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);
	    				}
			    		
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
lal committed
960 961

}