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

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

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

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

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

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

lal committed
53 54 55
	@Autowired
	private KqglAssoLeaveBalanceMapper kqglassoleavebalancemapper;
	
lal committed
56 57 58 59 60
	/**
	 * 考勤请假审批
	 */
	@Override
	public boolean attleaveapproval(AttLeaveApprovalDto leaveappr) {
lal committed
61 62
		String startdate = new SimpleDateFormat("yyyy-MM-dd").format(leaveappr.getStarttime());
		String enddate = new SimpleDateFormat("yyyy-MM-dd").format(leaveappr.getEndtime());
lal committed
63
		String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
64 65 66
		for(String num : days) {
			//记入打卡月汇总关联表
			KqglAssoRelationSummary.builder().userId(leaveappr.getUserid()).appTime(num).approvalId(leaveappr.getLeaveid()).approvalType(2).duration(leaveappr.getDuration())
lal committed
67
				.leaveTypeId(leaveappr.getLeavetype()).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(leaveappr.getStarttime()))
lal committed
68
				.endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(leaveappr.getEndtime())).orgCode(leaveappr.getOrgcode()).build().insert();
lal committed
69
		}
lal committed
70
		YgglMainEmp emp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, leaveappr.getUserid()).eq(YgglMainEmp::getOrgCode, leaveappr.getOrgcode()));
lal committed
71
		
lal committed
72
		int modifynumber = 1;
lal committed
73
		KqglAssoLeaveBalance balan = kqglassoleavebalancemapper.selectOne(new QueryWrapper<KqglAssoLeaveBalance>().lambda().eq(KqglAssoLeaveBalance::getUserid, leaveappr.getUserid()).eq(KqglAssoLeaveBalance::getOrgCode, leaveappr.getOrgcode())
lal committed
74 75 76 77
				.orderByDesc(KqglAssoLeaveBalance :: getModifyNumber).last("LIMIT 1"));
		if(balan != null) {
			modifynumber = balan.getModifyNumber()+1;
		}
lal committed
78 79 80 81 82 83 84 85
		
		String mse = "考勤请假审批";
		KqglAssoLeaveRulesT rult = KqglAssoLeaveRulesT.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRulesT>().lambda().eq(KqglAssoLeaveRulesT::getId, leaveappr.getLeavetype()));
		if(rult != null) {
			mse = "考勤"+rult.getName()+"审批";
		}
		
		
lal committed
86
		KqglAssoLeaveBalance.builder().leaveRulesId(leaveappr.getLeavetype()).userid(leaveappr.getUserid()).modifyAction(2).balanceDays("-"+leaveappr.getDuration())
lal committed
87
		.reason(mse).modifyUserid(emp.getEmpNum()).modifyTimer(new Date().getTime()).orgCode(emp.getOrgCode()).isAutomatic(1).modifyNumber(modifynumber).build().insert();//员工假期余额
lal committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
		
		
		//查询员工假期余额表中所对应的假期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
103 104 105 106 107 108 109 110
		return true;
	}

	/**
	 * 考勤加班审批
	 */
	@Override
	public boolean attovertimeapproval(AttOvertimeApprovalDto overappr) {
lal committed
111 112
		String startdate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getStarttime());
		String enddate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getEndtime());
lal committed
113
		String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
114 115 116 117
		for(String num : days) {
			
			//记入打卡月汇总关联表
			KqglAssoRelationSummary.builder().userId(overappr.getUserid()).appTime(num).approvalId(overappr.getOvertimeid()).approvalType(1).duration(overappr.getDuration())
lal committed
118
				.overtimeTypeId(overappr.getOvertimetype()).compensateId(overappr.getCompensate()).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getStarttime()))
lal committed
119
				.endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getEndtime())).orgCode(overappr.getOrgcode()).build().insert();
lal committed
120
		}
lal committed
121
		
lal committed
122
		YgglMainEmp emp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, overappr.getUserid()).eq(YgglMainEmp::getOrgCode, overappr.getOrgcode()));
lal committed
123 124 125 126
		
		//查询当前公司调休的id
		KqglAssoLeaveRules learul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getOrgCode, emp.getOrgCode()).eq(KqglAssoLeaveRules::getRulesType, 2));
		
lal committed
127 128
		//
		if(overappr.getCompensate() == 1 || overappr.getCompensate() == 3) {
lal committed
129
			
lal committed
130 131
			double duration = 0l;//
			
lal committed
132
			int modifynumber = 1;
lal committed
133
			KqglAssoLeaveBalance balan = kqglassoleavebalancemapper.selectOne(new QueryWrapper<KqglAssoLeaveBalance>().lambda().eq(KqglAssoLeaveBalance::getUserid, overappr.getUserid()).eq(KqglAssoLeaveBalance::getOrgCode, overappr.getOrgcode())
lal committed
134 135 136 137 138
					.orderByDesc(KqglAssoLeaveBalance :: getModifyNumber).last("LIMIT 1"));
			if(balan != null) {
				modifynumber = balan.getModifyNumber()+1;
			}
			
lal committed
139
			
lal committed
140 141 142 143 144 145 146 147 148
			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) {
lal committed
149
								if(rul.getWork() == 1) {//1:调休  2:加班费  3:调休/加班费
lal committed
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
									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();
								}
							}
						}
					}
				}
			}
lal committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
				
			//调休单位是“天”时    按照=》加班时长/班次的工作时长=调休天数
			if(learul.getCompany() == 1) {
				try {
					AttendanceCardListDto attdate = MethodCall(overappr.getOrgcode(),overappr.getUserid(),startdate);//获取当天打卡班次信息
					
					long starttime1 = 0,endtime1 = 0,starttime2 = 0,endtime2 = 0,starttime3 = 0,endtime3 = 0; 
					double time1 = 0,time2 = 0,time3 = 0;
					
					BigDecimal num0 = new BigDecimal(60);
					if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {//班次不为空
						List<AttSchedule> ash = attdate.getAttsch();//获取当天应打卡时间
						if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
							 starttime1 = ash.get(0).getTime();
							 endtime1 = ash.get(1).getTime();
							 
							 BigDecimal num = new BigDecimal((endtime1 - starttime1)/1000/60);
							 time1 = num.divide(num0,2,BigDecimal.ROUND_HALF_UP).doubleValue();
						 }
					 	if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
					 		starttime2 = ash.get(2).getTime();
						    endtime2 = ash.get(3).getTime();
						    
						    BigDecimal num = new BigDecimal((endtime2 - starttime2)/1000/60);
							time2 = num.divide(num0,2,BigDecimal.ROUND_HALF_UP).doubleValue();
						}
					 	if(attdate.getAttsch().size() == 6) {
					 		starttime3 = ash.get(4).getTime();
							endtime3 = ash.get(5).getTime();
							
							BigDecimal num = new BigDecimal((endtime3 - starttime3)/1000/60);
							time3 = num.divide(num0,2,BigDecimal.ROUND_HALF_UP).doubleValue();
						 }
					}
					
					BigDecimal num1 = new BigDecimal(time1);
					BigDecimal num2 = new BigDecimal(time2);
					BigDecimal num3 = num1.add(num2);
					BigDecimal num4 = new BigDecimal(time3);
					double shift_duration = ClockInTool.round(num3.add(num4).doubleValue());//班次时长
					
lal committed
216 217 218
					if(shift_duration > 0) {
						BigDecimal num5 = new BigDecimal(duration);
						BigDecimal num6 = new BigDecimal(shift_duration);
lal committed
219

lal committed
220 221 222
						//加班时长/班次的工作时长=调休天数
						duration = num5.divide(num6,2,BigDecimal.ROUND_HALF_UP).doubleValue();
					}
lal committed
223 224 225 226 227 228
					
				} catch (ParseException e) {
					e.printStackTrace();
				}
				
			}
lal committed
229 230
			
			KqglAssoLeaveBalance.builder().leaveRulesId(learul.getId()).userid(overappr.getUserid()).modifyAction(2).balanceDays("+"+duration)
lal committed
231
			.reason("考勤加班审批").modifyUserid(emp.getEmpNum()).modifyTimer(overappr.getStarttime()).orgCode(emp.getOrgCode()).isAutomatic(1).modifyNumber(modifynumber).build().insert();//员工假期余额
lal committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
			
			
			//查询员工假期余额表中所对应的假期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
247 248
		}
		
lal committed
249 250 251 252 253 254 255 256
		return true;
	}

	/**
	 * 考勤出差外出审批
	 */
	@Override
	public boolean attevectionapproval(AttEvectionApprovalDto evecappr) {
lal committed
257 258 259
		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
260
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
261 262
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
263
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(3).duration(evecappr.getDuration())
lal committed
264 265
					.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
266 267 268 269
			}
		}else {	//外出
			String startdate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getStarttime());
			String enddate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getEndtime());
lal committed
270
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
271 272
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
273
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(4).duration(evecappr.getDuration())
lal committed
274 275
					.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
276 277
			}
		}
lal committed
278 279 280
		return true;
	}

lal committed
281 282 283
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
	
lal committed
284 285 286 287 288
	/**
	 * 考勤补卡审批
	 */
	@Override
	public boolean attrepairapproval(AttRepairApprovalDto repaappr) {
lal committed
289
		String cardrepltime = new SimpleDateFormat("yyyy-MM-dd").format(repaappr.getCardrepltime());//补卡时间
lal committed
290 291 292
		
		boolean isRange = true;
		
lal committed
293 294 295 296 297 298
		int atttype = 0;//类型(0:无排班打卡 1:上班 2:下班)
		int results = 0;//打卡结果
		int type = 0;
		long attime = 0l;//应打卡时间戳
		int dkmxid = 0;//打卡明细ID
		
lal committed
299 300 301 302 303 304 305 306 307
		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
308
		//记入打卡月汇总关联表
lal committed
309 310
		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
311
		int shifid = 0;
lal committed
312 313 314
		try {
			KqglMainKqz attgro = kqglmainkqzmapper.getAttendanceGroupInformationByUserid(repaappr.getUserid(),repaappr.getOrgcode()); //考勤组信息
			if(attgro != null) {
lal committed
315
				AttendanceCardListDto attdate = MethodCall(repaappr.getOrgcode(),repaappr.getUserid(),cardrepltime);//获取当天打卡班次信息
lal committed
316 317 318
				
				if(EmptyUtil.isNotEmpty(attdate.getAttsch())) {//班次不为空
					List<AttSchedule> ash = attdate.getAttsch();//获取当天应打卡时间
lal committed
319
					shifid = ash.get(0).getId();//班次id
lal committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
					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
335 336 337 338
		    		if(ash.get(0).getId() != 0) { //有排班  非休息
		    			
		    			KqglAssoBcsz shif = KqglAssoBcsz.builder().build().selectOne(new QueryWrapper<KqglAssoBcsz>().lambda().eq(KqglAssoBcsz::getId, shifid));
		    			
lal committed
339 340 341
		    			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
342
		    				dkmxid = dkmc.getId();
lal committed
343
		    				if(attdate.getAttsch().size() == 2) {//一套班次
lal committed
344
		    					if(repaappr.getCardreplperiod() == 1 && dkmc.getSbdk1() == null) {//上班
lal committed
345 346 347 348 349 350 351 352 353 354 355
		    						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
356
		    						int sbdkjg = 0;
lal committed
357 358 359 360 361 362 363 364 365 366 367
		    						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
368
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk1(repaappr.getCardrepltime()).sbdk1jg(sbdkjg).dktj1(1).gzsc(gzsctime).build().updateById();
lal committed
369 370
		    						}
		    						
lal committed
371 372 373 374
		    						atttype = 1;
		    						results = sbdkjg;
		    						attime = starttime1;
		    					}else if(repaappr.getCardreplperiod() == 2 && dkmc.getXbdk1() == null) {//下班
lal committed
375 376 377 378 379 380 381 382 383 384
		    						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
385
		    						int xbdk1jg = 0;
lal committed
386
		    						if(isRange) {
lal committed
387
		    							
lal committed
388 389 390 391 392 393 394 395 396
		    							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
397
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk1(repaappr.getCardrepltime()).xbdk1jg(xbdk1jg).dktj2(1).gzsc(gzsctime).build().updateById();
lal committed
398
		    						}
lal committed
399 400 401 402
		    						
		    						atttype = 2;
		    						results = xbdk1jg;
		    						attime = endtime1;
lal committed
403 404 405 406
		    					}
		    				}else if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb1 = verification_range(starttime1ks,starttime1js,repaappr.getCardrepltime());
lal committed
407
		    						if(sb1 && dkmc.getSbdk1() == null) {
lal committed
408
		    							int sbdkjg = 0;
lal committed
409 410 411 412 413 414
			    						Long time = (repaappr.getCardrepltime() - starttime1)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
415
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk1(repaappr.getCardrepltime()).sbdk1jg(sbdkjg).dktj1(1).gzsc(gzsctime).build().updateById();
lal committed
416 417 418 419
		    							
		    							atttype = 1;
		    							results = sbdkjg;
		    							attime = starttime1;
lal committed
420 421 422
		    						}
		    						
		    						boolean sb2 = verification_range(starttime2ks,starttime2js,repaappr.getCardrepltime());
lal committed
423
		    						if(sb2 && dkmc.getSbdk2() == null) {
lal committed
424
		    							int sbdkjg = 0;
lal committed
425 426 427 428 429 430
			    						Long time = (repaappr.getCardrepltime() - starttime2)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
431
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk2(repaappr.getCardrepltime()).sbdk2jg(sbdkjg).dktj3(1).gzsc(gzsctime).build().updateById();
lal committed
432 433 434 435
		    							
		    							atttype = 3;
		    							results = sbdkjg;
		    							attime = starttime2;
lal committed
436 437 438 439
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb1 = verification_range(endtime1ks,endtime1js,repaappr.getCardrepltime());
lal committed
440
		    						if(xb1 && dkmc.getXbdk1() == null) {
lal committed
441
		    							int xbdk1jg = 0;
lal committed
442 443 444 445 446 447
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
448
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk1(repaappr.getCardrepltime()).xbdk1jg(xbdk1jg).dktj2(1).gzsc(gzsctime).build().updateById();
lal committed
449 450 451 452
										 
										 atttype = 2;
										 results = xbdk1jg;
										 attime = endtime1;
lal committed
453 454 455
		    						}
		    						
		    						boolean xb2 = verification_range(endtime2ks,endtime2js,repaappr.getCardrepltime());
lal committed
456
		    						if(xb2 && dkmc.getXbdk2() == null) {
lal committed
457
		    							int xbdk2jg = 0;
lal committed
458 459 460 461 462 463
		    							Long time = (repaappr.getCardrepltime() - endtime2)/1000/60;
										 if(time > 0){}else{
											 xbdk2jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
464
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk2(repaappr.getCardrepltime()).xbdk2jg(xbdk2jg).dktj4(1).gzsc(gzsctime).build().updateById();
lal committed
465 466 467 468
										 
										 atttype = 4;
										 results = xbdk2jg;
										 attime = endtime2;
lal committed
469 470 471 472 473 474
		    						}
		    						
		    					}
		    				}else if(attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb3 = verification_range(starttime3ks,starttime3js,repaappr.getCardrepltime());
lal committed
475
		    						if(sb3 && dkmc.getSbdk3() == null) {
lal committed
476
		    							int sbdkjg = 0;
lal committed
477 478 479 480 481 482
			    						Long time = (repaappr.getCardrepltime() - starttime3)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
483
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk3(repaappr.getCardrepltime()).sbdk3jg(sbdkjg).dktj5(1).gzsc(gzsctime).build().updateById();
lal committed
484 485 486
		    							 atttype = 5;
		    							 results = sbdkjg;
		    							 attime = starttime3;
lal committed
487 488 489 490
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb3 = verification_range(endtime3ks,endtime3js,repaappr.getCardrepltime());
lal committed
491
		    						if(xb3 && dkmc.getXbdk3() == null) {
lal committed
492
		    							int xbdk3jg = 0;
lal committed
493 494 495 496 497 498
		    							Long time = (repaappr.getCardrepltime() - endtime3)/1000/60;
										 if(time > 0){}else{
											 xbdk3jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
499
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk3(repaappr.getCardrepltime()).xbdk3jg(xbdk3jg).dktj6(1).gzsc(gzsctime).build().updateById();
lal committed
500 501 502
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
lal committed
503 504 505 506 507
		    						}
		    						
		    					}
		    				}
		    				
lal committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
		    			}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
528
		    						int sbdkjg = 0;
lal committed
529 530 531 532 533 534 535 536
		    						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
537 538
										 pcd.setDktj1(1);
										 
lal committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
										 
										 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
559
		    						int xbdk1jg = 0;
lal committed
560 561 562 563 564 565 566 567 568
		    						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
569
										 pcd.setDktj2(1);
lal committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583
										 
										 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
584
		    							int sbdkjg = 0;
lal committed
585 586 587 588 589 590 591
			    						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
592
										 pcd.setDktj1(1);
lal committed
593 594 595 596 597 598 599 600 601 602 603 604
										 
										 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
605
		    							int sbdkjg = 0;
lal committed
606 607 608 609 610 611 612
			    						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
613
										 pcd.setDktj3(1);
lal committed
614 615 616 617 618 619 620 621 622 623 624 625 626
										 
										 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
627
		    							int xbdk1jg = 0;
lal committed
628 629 630 631 632 633 634
		    							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
635
										 pcd.setDktj2(1);
lal committed
636 637 638 639 640 641 642 643 644 645 646 647
										 
										 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
648
		    							int xbdk2jg = 0;
lal committed
649 650 651 652 653 654
		    							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
655
										 pcd.setDktj4(1);
lal committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
										 
										 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
671
		    							int sbdkjg = 0;
lal committed
672 673 674 675 676 677 678
			    						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
679
										 pcd.setDktj5(1);
lal committed
680 681 682 683 684 685 686 687 688 689 690 691 692
										 
										 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
693
		    							int xbdk3jg = 0;
lal committed
694 695 696 697 698 699 700 701
		    							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
702
										 pcd.setDktj6(1);
lal committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
		    						}
		    						
		    					}
		    				}
		    				
		    				dkmxid = pcd.getId();
		    			}
		    			
lal committed
719 720 721 722
		    			//0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休 
		    			//9:管理员改为正常 10:管理员改为迟到 11:管理员改为早退  12:补卡通过/正常 13:补卡通过/迟到 14:补卡通过/早退
		    			int status = 2;
		    			
lal committed
723 724
		    			if((atttype)%2 > 0){
		    				type = 1;
lal committed
725 726 727 728 729 730
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 13;
		    				}
lal committed
731 732
		    			}else {
		    				type = 2;
lal committed
733 734 735 736 737 738
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 14;
		    				}
lal committed
739 740
		    			}
		    			
lal committed
741 742 743 744 745
		    			Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(cardrepltime,"yyyy-MM-dd")).getTime();
		    			String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
		    			
		    			//attime  应打卡时间
		    			
lal committed
746
		    			KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(repaappr.getCardrepltime()).results(results).userId(repaappr.getUserid()).type(type).status(status).sort(atttype)
lal committed
747 748 749 750 751 752 753 754
								.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
755 756 757 758 759 760 761 762
		    		}
				}
			}
			
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
lal committed
763 764
		
		
lal committed
765 766
		return true;
	}
lal committed
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
	
	
	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
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
	
	@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){//自由排班
				//未排班时,员工可选择班次打卡
lal committed
845 846 847 848 849
//			    if(attgro.getIsXzbcdk() == 1){
//			    	attcar.setOptscheduling(true);	
//			    }else{
//			    	attcar.setOptscheduling(false);
//			    }
lal committed
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 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 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
				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
1042 1043

}