KqglServiceImpl.java 52.3 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;
ilal committed
35
import cn.timer.api.dao.kqmk.KqglAssoRelationSummaryMapper;
lal committed
36
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
lal committed
37
import cn.timer.api.dto.kqmk.AttEvectionApprovalDto;
lal committed
38
import cn.timer.api.dto.kqmk.AttLateLate;
lal committed
39 40 41
import cn.timer.api.dto.kqmk.AttLeaveApprovalDto;
import cn.timer.api.dto.kqmk.AttOvertimeApprovalDto;
import cn.timer.api.dto.kqmk.AttRepairApprovalDto;
lal committed
42 43
import cn.timer.api.dto.kqmk.AttSchedule;
import cn.timer.api.dto.kqmk.AttendanceCardListDto;
lal committed
44
import cn.timer.api.dto.kqmk.KqglAssoPbmxDto;
lal committed
45
import cn.timer.api.utils.DateUtil;
ilal committed
46
import cn.timer.api.utils.ResultUtil;
lal committed
47

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

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

	/**
	 * 考勤加班审批
	 */
	@Override
	public boolean attovertimeapproval(AttOvertimeApprovalDto overappr) {
lal committed
115 116
		String startdate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getStarttime());
		String enddate = new SimpleDateFormat("yyyy-MM-dd").format(overappr.getEndtime());
lal committed
117
		String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
118
		int i = 1;
lal committed
119 120 121
		for(String num : days) {
			//记入打卡月汇总关联表
			KqglAssoRelationSummary.builder().userId(overappr.getUserid()).appTime(num).approvalId(overappr.getOvertimeid()).approvalType(1).duration(overappr.getDuration())
lal committed
122
				.overtimeTypeId(overappr.getOvertimetype()).compensateId(overappr.getCompensate()).startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getStarttime()))
lal committed
123 124
				.endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(overappr.getEndtime())).ordernum(i).orgCode(overappr.getOrgcode()).totals(days.length).build().insert();
			i++;
lal committed
125
		}
lal committed
126
		
lal committed
127
		YgglMainEmp emp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, overappr.getUserid()).eq(YgglMainEmp::getOrgCode, overappr.getOrgcode()));
lal committed
128 129 130 131
		
		//查询当前公司调休的id
		KqglAssoLeaveRules learul = KqglAssoLeaveRules.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getOrgCode, emp.getOrgCode()).eq(KqglAssoLeaveRules::getRulesType, 2));
		
lal committed
132 133
		//
		if(overappr.getCompensate() == 1 || overappr.getCompensate() == 3) {
lal committed
134
			
lal committed
135 136
			double duration = 0l;//
			
lal committed
137
			int modifynumber = 1;
lal committed
138
			KqglAssoLeaveBalance balan = kqglassoleavebalancemapper.selectOne(new QueryWrapper<KqglAssoLeaveBalance>().lambda().eq(KqglAssoLeaveBalance::getUserid, overappr.getUserid()).eq(KqglAssoLeaveBalance::getOrgCode, overappr.getOrgcode())
lal committed
139 140 141 142 143
					.orderByDesc(KqglAssoLeaveBalance :: getModifyNumber).last("LIMIT 1"));
			if(balan != null) {
				modifynumber = balan.getModifyNumber()+1;
			}
			
lal committed
144
			
lal committed
145 146 147 148 149 150 151 152 153
			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
154
								if(rul.getWork() == 1) {//1:调休  2:加班费  3:调休/加班费
lal committed
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
									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
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 216 217 218 219 220
				
			//调休单位是“天”时    按照=》加班时长/班次的工作时长=调休天数
			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
221 222 223
					if(shift_duration > 0) {
						BigDecimal num5 = new BigDecimal(duration);
						BigDecimal num6 = new BigDecimal(shift_duration);
lal committed
224

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

	/**
	 * 考勤出差外出审批
	 */
	@Override
	public boolean attevectionapproval(AttEvectionApprovalDto evecappr) {
lal committed
262 263 264
		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
265
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
266
			int i = 1;
lal committed
267 268
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
269
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(3).duration(evecappr.getDuration())
lal committed
270
					.startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getStarttime())).endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getEndtime()))
lal committed
271 272
					.orgCode(evecappr.getOrgcode()).ordernum(i).totals(days.length).build().insert();
				i++;
lal committed
273 274 275 276
			}
		}else {	//外出
			String startdate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getStarttime());
			String enddate = new SimpleDateFormat("yyyy-MM-dd").format(evecappr.getEndtime());
lal committed
277
			String[] days=ClockInTool.listToString(ClockInTool.getDays(startdate,enddate)).split(",");
lal committed
278
			int i = 1;
lal committed
279 280
			for(String num : days) {
				//记入打卡月汇总关联表
lal committed
281
				KqglAssoRelationSummary.builder().userId(evecappr.getUserid()).appTime(num).approvalId(evecappr.getEvectionid()).approvalType(4).duration(evecappr.getDuration())
lal committed
282
					.startTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getStarttime())).endTime(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss").format(evecappr.getEndtime()))
lal committed
283 284
					.orgCode(evecappr.getOrgcode()).ordernum(i).totals(days.length).build().insert();
				i++;
lal committed
285 286
			}
		}
lal committed
287 288 289
		return true;
	}

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

lal committed
427
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk1(repaappr.getCardrepltime()).sbdk1jg(sbdkjg).dktj1(1).gzsc(gzsctime).build().updateById();
lal committed
428 429 430 431
		    							
		    							atttype = 1;
		    							results = sbdkjg;
		    							attime = starttime1;
lal committed
432 433 434
		    						}
		    						
		    						boolean sb2 = verification_range(starttime2ks,starttime2js,repaappr.getCardrepltime());
lal committed
435
		    						if(sb2 && dkmc.getSbdk2() == null) {
lal committed
436
		    							int sbdkjg = 0;
lal committed
437 438 439 440 441 442
			    						Long time = (repaappr.getCardrepltime() - starttime2)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
443
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk2(repaappr.getCardrepltime()).sbdk2jg(sbdkjg).dktj3(1).gzsc(gzsctime).build().updateById();
lal committed
444 445 446 447
		    							
		    							atttype = 3;
		    							results = sbdkjg;
		    							attime = starttime2;
lal committed
448 449 450 451
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb1 = verification_range(endtime1ks,endtime1js,repaappr.getCardrepltime());
lal committed
452
		    						if(xb1 && dkmc.getXbdk1() == null) {
lal committed
453
		    							int xbdk1jg = 0;
lal committed
454 455 456 457 458 459
		    							Long time = (repaappr.getCardrepltime() - endtime1)/1000/60;
										 if(time > 0){}else{
											 xbdk1jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
460
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk1(repaappr.getCardrepltime()).xbdk1jg(xbdk1jg).dktj2(1).gzsc(gzsctime).build().updateById();
lal committed
461 462 463 464
										 
										 atttype = 2;
										 results = xbdk1jg;
										 attime = endtime1;
lal committed
465 466 467
		    						}
		    						
		    						boolean xb2 = verification_range(endtime2ks,endtime2js,repaappr.getCardrepltime());
lal committed
468
		    						if(xb2 && dkmc.getXbdk2() == null) {
lal committed
469
		    							int xbdk2jg = 0;
lal committed
470 471 472 473 474 475
		    							Long time = (repaappr.getCardrepltime() - endtime2)/1000/60;
										 if(time > 0){}else{
											 xbdk2jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
476
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk2(repaappr.getCardrepltime()).xbdk2jg(xbdk2jg).dktj4(1).gzsc(gzsctime).build().updateById();
lal committed
477 478 479 480
										 
										 atttype = 4;
										 results = xbdk2jg;
										 attime = endtime2;
lal committed
481 482 483 484 485 486
		    						}
		    						
		    					}
		    				}else if(attdate.getAttsch().size() == 6) {
		    					if(repaappr.getCardreplperiod() == 1) {
		    						boolean sb3 = verification_range(starttime3ks,starttime3js,repaappr.getCardrepltime());
lal committed
487
		    						if(sb3 && dkmc.getSbdk3() == null) {
lal committed
488
		    							int sbdkjg = 0;
lal committed
489 490 491 492 493 494
			    						Long time = (repaappr.getCardrepltime() - starttime3)/1000/60;
										 if(time > 0){//上班1打卡结果
											 sbdkjg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
495
		    							KqglAssoDkmx.builder().id(dkmc.getId()).sbdk3(repaappr.getCardrepltime()).sbdk3jg(sbdkjg).dktj5(1).gzsc(gzsctime).build().updateById();
lal committed
496 497 498
		    							 atttype = 5;
		    							 results = sbdkjg;
		    							 attime = starttime3;
lal committed
499 500 501 502
		    						}
		    						
		    					}else if(repaappr.getCardreplperiod() == 2) {
		    						boolean xb3 = verification_range(endtime3ks,endtime3js,repaappr.getCardrepltime());
lal committed
503
		    						if(xb3 && dkmc.getXbdk3() == null) {
lal committed
504
		    							int xbdk3jg = 0;
lal committed
505 506 507 508 509 510
		    							Long time = (repaappr.getCardrepltime() - endtime3)/1000/60;
										 if(time > 0){}else{
											 xbdk3jg = Math.abs(Integer.valueOf(time.toString()));
										 }
										 Double gzsctime = null;//工作时长

lal committed
511
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk3(repaappr.getCardrepltime()).xbdk3jg(xbdk3jg).dktj6(1).gzsc(gzsctime).build().updateById();
lal committed
512 513 514
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
lal committed
515 516 517 518 519
		    						}
		    						
		    					}
		    				}
		    				
lal committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
		    			}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
540
		    						int sbdkjg = 0;
lal committed
541 542 543 544 545 546 547 548
		    						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
549 550
										 pcd.setDktj1(1);
										 
lal committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
										 
										 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
571
		    						int xbdk1jg = 0;
lal committed
572 573 574 575 576 577 578 579 580
		    						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
581
										 pcd.setDktj2(1);
lal committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595
										 
										 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
596
		    							int sbdkjg = 0;
lal committed
597 598 599 600 601 602 603
			    						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
604
										 pcd.setDktj1(1);
lal committed
605 606 607 608 609 610 611 612 613 614 615 616
										 
										 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
617
		    							int sbdkjg = 0;
lal committed
618 619 620 621 622 623 624
			    						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
625
										 pcd.setDktj3(1);
lal committed
626 627 628 629 630 631 632 633 634 635 636 637 638
										 
										 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
639
		    							int xbdk1jg = 0;
lal committed
640 641 642 643 644 645 646
		    							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
647
										 pcd.setDktj2(1);
lal committed
648 649 650 651 652 653 654 655 656 657 658 659
										 
										 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
660
		    							int xbdk2jg = 0;
lal committed
661 662 663 664 665 666
		    							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
667
										 pcd.setDktj4(1);
lal committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
										 
										 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
683
		    							int sbdkjg = 0;
lal committed
684 685 686 687 688 689 690
			    						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
691
										 pcd.setDktj5(1);
lal committed
692 693 694 695 696 697 698 699 700 701 702 703 704
										 
										 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
705
		    							int xbdk3jg = 0;
lal committed
706 707 708 709 710 711 712 713
		    							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
714
										 pcd.setDktj6(1);
lal committed
715 716 717 718 719 720 721 722 723 724 725 726
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
		    						}
		    						
		    					}
		    				}
ilal committed
727 728 729 730 731
		    				if(isRange) {
		    					dkmxid = pcd.getId();
		    				}else {
		    					throw new CustomException("当前时间,没有考勤异常无需补卡");
		    				}
lal committed
732 733 734
		    				
		    			}
		    			
lal committed
735 736 737 738
		    			//0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休 
		    			//9:管理员改为正常 10:管理员改为迟到 11:管理员改为早退  12:补卡通过/正常 13:补卡通过/迟到 14:补卡通过/早退
		    			int status = 2;
		    			
lal committed
739 740
		    			if((atttype)%2 > 0){
		    				type = 1;
lal committed
741 742 743 744 745 746
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 13;
		    				}
lal committed
747 748
		    			}else {
		    				type = 2;
lal committed
749 750 751 752 753 754
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 14;
		    				}
lal committed
755 756
		    			}
		    			
lal committed
757 758 759 760 761
		    			Long startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(cardrepltime,"yyyy-MM-dd")).getTime();
		    			String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
		    			
		    			//attime  应打卡时间
		    			
ilal committed
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
		    			double gzsc = 0;
		    			
		    			long rest_time = 0;
		    			if(shif.getStartTime() != null && shif.getEndTime() != null) {
		    				long kaishixiuxi = Long.valueOf(ClockInTool.dateToStamp(cardrepltime + " " +shif.getStartTime()+":00"));
		    			    long jieshuxiuxi = Long.valueOf(ClockInTool.dateToStamp(cardrepltime + " " +shif.getEndTime()+":00"));
		    			    rest_time = (jieshuxiuxi - kaishixiuxi)/1000/60;//休息时间
		    			}
		    			
		    			//请假时长
		    			KqglAssoRelationSummary qjsc = kqglassorelationsummarymapper.Businessdayclockin(repaappr.getUserid(), 2, cardrepltime, repaappr.getOrgcode());
		    			
		    			//计算工作时长
		    			KqglAssoDkmx dkgzsc = KqglAssoDkmx.builder().id(dkmxid).build().selectById();
		    			if(dkgzsc.getYdkcs() == 2 || dkgzsc.getYdkcs() == 4 || dkgzsc.getYdkcs() == 6) {
		    				if(dkgzsc.getSbdk1() != null && dkgzsc.getXbdk1() != null) {
		    					gzsc = gzsc + (dkgzsc.getXbdk1() - dkgzsc.getSbdk1())/1000/60;
		    				}
		    			}
		    			if(dkgzsc.getYdkcs() == 4 || dkgzsc.getYdkcs() == 6) {
		    				if(dkgzsc.getSbdk2() != null && dkgzsc.getXbdk2() != null) {
		    					gzsc = gzsc + (dkgzsc.getXbdk2() - dkgzsc.getSbdk2())/1000/60;
		    				}
		    			}
		    			if(dkgzsc.getYdkcs() == 6) {
		    				if(dkgzsc.getSbdk3() != null && dkgzsc.getXbdk3() != null) {
		    					gzsc = gzsc + (dkgzsc.getXbdk3() - dkgzsc.getSbdk3())/1000/60;
		    				}
		    			}
		    			gzsc = gzsc - rest_time - qjsc.getDuration();
		    			
		    			KqglAssoDkmx.builder().id(dkmxid).gzsc(gzsc).build().updateById();
		    			
		    			
		    			
lal committed
797
		    			KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(repaappr.getCardrepltime()).results(results).userId(repaappr.getUserid()).type(type).status(status).sort(atttype)
lal committed
798 799 800 801 802 803 804 805
								.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
806 807 808 809 810 811 812 813
		    		}
				}
			}
			
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
lal committed
814 815
		
		
lal committed
816 817
		return true;
	}
lal committed
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
	
	
	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
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
	
	@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
896 897 898 899 900
//			    if(attgro.getIsXzbcdk() == 1){
//			    	attcar.setOptscheduling(true);	
//			    }else{
//			    	attcar.setOptscheduling(false);
//			    }
lal committed
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 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
				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
1093 1094

}