KqglServiceImpl.java 52.6 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;
ilal committed
11
import org.springframework.beans.factory.annotation.Value;
lal committed
12 13
import org.springframework.stereotype.Service;

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

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

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

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

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

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

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

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

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

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

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

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

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

lal committed
512
										 KqglAssoDkmx.builder().id(dkmc.getId()).xbdk3(repaappr.getCardrepltime()).xbdk3jg(xbdk3jg).dktj6(1).gzsc(gzsctime).build().updateById();
lal committed
513 514 515
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
lal committed
516 517 518 519 520
		    						}
		    						
		    					}
		    				}
		    				
lal committed
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
		    			}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) {
ilal committed
537
		    								 Logoutput("当前打卡时间不在范围内");
lal committed
538 539 540
		    								 isRange = false;
		    							 }
		    						}
lal committed
541
		    						int sbdkjg = 0;
lal committed
542 543 544 545 546 547 548 549
		    						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
550 551
										 pcd.setDktj1(1);
										 
lal committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
										 
										 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) {
ilal committed
568
		    								 Logoutput("当前打卡时间不在范围内");
lal committed
569 570 571
		    								 isRange = false;
		    							 }
		    						}
lal committed
572
		    						int xbdk1jg = 0;
lal committed
573 574 575 576 577 578 579 580 581
		    						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
582
										 pcd.setDktj2(1);
lal committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596
										 
										 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
597
		    							int sbdkjg = 0;
lal committed
598 599 600 601 602 603 604
			    						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
605
										 pcd.setDktj1(1);
lal committed
606 607 608 609 610 611 612 613 614 615 616 617
										 
										 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
618
		    							int sbdkjg = 0;
lal committed
619 620 621 622 623 624 625
			    						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
626
										 pcd.setDktj3(1);
lal committed
627 628 629 630 631 632 633 634 635 636 637 638 639
										 
										 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
640
		    							int xbdk1jg = 0;
lal committed
641 642 643 644 645 646 647
		    							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
648
										 pcd.setDktj2(1);
lal committed
649 650 651 652 653 654 655 656 657 658 659 660
										 
										 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
661
		    							int xbdk2jg = 0;
lal committed
662 663 664 665 666 667
		    							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
668
										 pcd.setDktj4(1);
lal committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
										 
										 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
684
		    							int sbdkjg = 0;
lal committed
685 686 687 688 689 690 691
			    						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
692
										 pcd.setDktj5(1);
lal committed
693 694 695 696 697 698 699 700 701 702 703 704 705
										 
										 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
706
		    							int xbdk3jg = 0;
lal committed
707 708 709 710 711 712 713 714
		    							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
715
										 pcd.setDktj6(1);
lal committed
716 717 718 719 720 721 722 723 724 725 726 727
										 
										 if (!pcd.insert()) {
											throw new CustomException("打卡明细-新增异常-1");
										 }
										 
										 atttype = 6;
										 results = xbdk3jg;
										 attime = endtime3;
		    						}
		    						
		    					}
		    				}
ilal committed
728 729 730 731 732
		    				if(isRange) {
		    					dkmxid = pcd.getId();
		    				}else {
		    					throw new CustomException("当前时间,没有考勤异常无需补卡");
		    				}
lal committed
733 734 735
		    				
		    			}
		    			
lal committed
736 737 738 739
		    			//0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休 
		    			//9:管理员改为正常 10:管理员改为迟到 11:管理员改为早退  12:补卡通过/正常 13:补卡通过/迟到 14:补卡通过/早退
		    			int status = 2;
		    			
lal committed
740 741
		    			if((atttype)%2 > 0){
		    				type = 1;
lal committed
742 743 744 745 746 747
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 13;
		    				}
lal committed
748 749
		    			}else {
		    				type = 2;
lal committed
750 751 752 753 754 755
		    				
		    				if(results == 0) {
		    					status = 12;
		    				}else {
		    					status = 14;
		    				}
lal committed
756 757
		    			}
		    			
lal committed
758 759 760 761 762
		    			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
763 764 765
		    			double gzsc = 0;
		    			
		    			long rest_time = 0;
ilal committed
766
		    			if(shif.getStartTime() != null && !("").equals(shif.getStartTime()) && shif.getEndTime() != null && !("").equals(shif.getEndTime())) {
ilal committed
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
		    				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
798
		    			KqglAssoDkjl pre = KqglAssoDkjl.builder().dktime(repaappr.getCardrepltime()).results(results).userId(repaappr.getUserid()).type(type).status(status).sort(atttype)
lal committed
799 800 801 802 803 804 805 806
								.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
807 808 809 810 811 812 813 814
		    		}
				}
			}
			
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
lal committed
815 816
		
		
lal committed
817 818
		return true;
	}
lal committed
819 820 821 822 823 824 825 826 827
	
	
	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) {
ilal committed
828
			 Logoutput("当前打卡时间不在范围内");
lal committed
829 830 831 832 833
			 isRange = false;
		 }
		 
		 return isRange;
	}
lal committed
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
	
	@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
897 898 899 900 901
//			    if(attgro.getIsXzbcdk() == 1){
//			    	attcar.setOptscheduling(true);	
//			    }else{
//			    	attcar.setOptscheduling(false);
//			    }
lal committed
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 1093
				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
1094

ilal committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
	@Value("${config-8timer.environmental-science}")
	public String environmental_science;
	
	public void Logoutput(String science) {
		
		if(!("pro").equals(environmental_science)) {
			
			System.out.println(science);
		}else {
			System.out.println("");
		}
		
	}
lal committed
1108
}