AttController.java 216 KB
Newer Older
yuquan.zhu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package cn.timer.api.controller.kqgl;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
lal committed
18
import org.springframework.beans.factory.annotation.Value;
yuquan.zhu committed
19 20 21
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
ilal committed
22
import org.springframework.transaction.annotation.Transactional;
yuquan.zhu committed
23 24
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
ilal committed
25
import org.springframework.validation.annotation.Validated;
yuquan.zhu committed
26 27 28 29 30 31 32 33 34 35 36 37
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
ilal committed
38 39
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
yuquan.zhu committed
40 41
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
42
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
yuquan.zhu committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

import cn.timer.api.bean.kqgl.AttCalendarAlarm;
import cn.timer.api.bean.kqgl.AttClockMethod;
import cn.timer.api.bean.kqgl.AttConditions;
import cn.timer.api.bean.kqgl.AttGroupBinPunchMode;
import cn.timer.api.bean.kqgl.AttLateLate;
import cn.timer.api.bean.kqgl.AttSchedule;
import cn.timer.api.bean.kqgl.AttScheduling;
import cn.timer.api.bean.kqgl.AttendanceAssistant;
import cn.timer.api.bean.kqgl.AttendanceCalendar;
import cn.timer.api.bean.kqgl.AttendanceCardList;
import cn.timer.api.bean.kqgl.AttendanceDetails;
import cn.timer.api.bean.kqgl.AttendanceGroup;
import cn.timer.api.bean.kqgl.AttendanceMachine;
import cn.timer.api.bean.kqgl.AttendanceReport;
import cn.timer.api.bean.kqgl.AttendanceWeeklySch;
import cn.timer.api.bean.kqgl.CalendarAlarm;
import cn.timer.api.bean.kqgl.ClockCollectData;
import cn.timer.api.bean.kqgl.CustomRosterSchedule;
import cn.timer.api.bean.kqgl.KqzAttendanceGroupSearch;
import cn.timer.api.bean.kqgl.PunchCardAddress;
import cn.timer.api.bean.kqgl.PunchCardDetails;
import cn.timer.api.bean.kqgl.PunchCardWiFi;
import cn.timer.api.bean.kqgl.PunchRecord;
import cn.timer.api.bean.kqgl.ReminderAuxiliary;
import cn.timer.api.bean.kqgl.Schedule;
import cn.timer.api.bean.kqgl.ScheduleAux;
import cn.timer.api.bean.kqgl.ShiftDetails;
import cn.timer.api.bean.kqgl.ShiftManagement;
import cn.timer.api.bean.kqgl.SpecialDate;
import cn.timer.api.bean.kqgl.SystemShift;
import cn.timer.api.bean.kqgl.UserAttendanceRel;
import cn.timer.api.bean.kqgl.UserEquiRelation;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.Initialization.StaticVariable;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.kqgl.AttGroupBinPunchModeMapper;
import cn.timer.api.dao.kqgl.AttendanceGroupMapper;
import cn.timer.api.dao.kqgl.AttendanceMachineMapper;
import cn.timer.api.dao.kqgl.AttendanceWeeklySchMapper;
import cn.timer.api.dao.kqgl.CalendarAlarmMapper;
import cn.timer.api.dao.kqgl.PunchCardAddressMapper;
import cn.timer.api.dao.kqgl.PunchCardDetailsMapper;
import cn.timer.api.dao.kqgl.PunchCardWiFiMapper;
import cn.timer.api.dao.kqgl.PunchRecordMapper;
import cn.timer.api.dao.kqgl.ScheduleMapper;
import cn.timer.api.dao.kqgl.ShiftManagementMapper;
import cn.timer.api.dao.kqgl.SpecialDateMapper;
import cn.timer.api.dao.kqgl.UserAttendanceRelMapper;
import cn.timer.api.dao.kqgl.UserEquiRelationMapper;
ilal committed
94
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
yuquan.zhu committed
95
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
ilal committed
96 97
import cn.timer.api.dto.kqmk.AttqueryCriteriaDto;
import cn.timer.api.dto.kqmk.KqglMainKqzDto;
yuquan.zhu committed
98 99 100 101 102 103 104 105 106 107 108
import cn.timer.api.utils.DateUtil;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author lalqq
 *	考勤
 */
ilal committed
109
@Api(tags = "3.0[2]考勤模块")
yuquan.zhu committed
110
@RestController
ilal committed
111 112
@Transactional
@RequestMapping(value = "/kqz", produces = { "application/json", "multipart/form-data" })
yuquan.zhu committed
113 114
public class AttController {
	
lal committed
115 116 117
	@Value("${config-8timer.machine8timerUrl}")
	public String mac_command; // 回调地址
	
Yl123 committed
118
	//班次
yuquan.zhu committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	@Autowired
	private ShiftManagementMapper shiftmanagementservice;
	//考勤机
	@Autowired
	private AttendanceMachineMapper attendancemachineservice;
	//考勤地址
	@Autowired
	private PunchCardAddressMapper punchcardaddressservice;
	//考勤WIFI
	@Autowired
	private PunchCardWiFiMapper punchcardwifiservice;
	//考勤组
	@Autowired
	private AttendanceGroupMapper attendancegroupservice;
	//考勤组绑定的打卡方式
	@Autowired
	private AttGroupBinPunchModeMapper attgroupbinpunchmodeservice;
	//用户和考勤组关系
	@Autowired
	private UserAttendanceRelMapper userattendancerelservice;
	//考勤周排班
	@Autowired
	private AttendanceWeeklySchMapper attendanceweeklyschservice;
	//排班明细
	@Autowired
	private ScheduleMapper scheduleservice;
	//打卡记录
	@Autowired
	private PunchRecordMapper punchrecordservice;
	//打卡明细表
	@Autowired
	private PunchCardDetailsMapper punchcarddetailsservice;
	//用户与设备关系表
	@Autowired
	private UserEquiRelationMapper userequirelationmapper;
	
	@Autowired
	private SpecialDateMapper specialdateservice;
	//日历提醒
	@Autowired
	private CalendarAlarmMapper calendaralarmservice;
	
	SimpleDateFormat mat = new SimpleDateFormat("yyyy-MM-dd");
	
	SimpleDateFormat famt = new SimpleDateFormat("yyyy-MM-dd");
	
	
	SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
	/*******班次管理--开始*********/
	/**
	 * 获取班次数据
	 */
	@GetMapping(value="/ShiftDataList")
	@ApiOperation(value = "获取班次数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 1)
	public Result<PageInfo<ShiftManagement>> getShiftDataList(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "9999") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			PageHelper.startPage(pageNum, pageSize);
			List<ShiftManagement> shiftList = shiftmanagementservice.selectByPrimaryByQyid(qyid);
			PageInfo<ShiftManagement> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
	
	/**
	 * 新增班次信息
	 */
	@PostMapping(value = "/Shif")
	@ApiOperation(value = "新增班次信息", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 2)
	public Result<ShiftManagement> ShiftInformation(@CurrentUser UserBean userBean,@RequestBody ShiftManagement shif) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			shif.setQyid(qyid);
			shif.setLusjTime(new Date().getTime());
			shif.setLuryid(userid);//录入人员
			if(shiftmanagementservice.insertSelective(shif)>0){
				return ResultUtil.data(shif, "新增班次成功");
			}else{
				return ResultUtil.error("新增班次失败");
			}
	}
	
	/**
	 * 删除班次信息
	 */
	@DeleteMapping(value = "/Shif/{id}")
	@ApiOperation(value = "删除班次信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 3)
	public Result<Integer> deleteShiftInformation(@PathVariable("id") Integer id) {
		if (shiftmanagementservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	
	
	/**
	 * 根据班次id获取班次信息
	 */
	@GetMapping(value="/Shifts/{id}")
	@ApiOperation(value = "获取班次信息-根据班次id", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 4)
	public Result<ShiftManagement> getShiftCenter(@PathVariable("id") Integer id) {
		ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(id);
		return ResultUtil.data(shifs);
	}
	
	/**
	 * 修改班次信息
	 */
	@PutMapping(value = "/Shif")
	@ApiOperation(value = "修改班次信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 5)
	public Result<ShiftManagement> updateShiftInformation(@CurrentUser UserBean userBean,@RequestBody ShiftManagement shif) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			shif.setQyid(qyid);//企业id
			shif.setLusjTime(new Date().getTime());//录入时间
			shif.setLuryid(userid);//录入人员
			if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
				return ResultUtil.data(shif,"修改班次信息成功");
			}
			return ResultUtil.error("修改班次信息失败");
	}
ilal committed
246
	/*******班次管理 结束*********/
yuquan.zhu committed
247 248
	
	
ilal committed
249
	/*********考勤机***********/
yuquan.zhu committed
250 251 252 253 254 255 256 257 258 259
	/*********打卡地址***********/
	/**
	 * 获取打卡地址数据
	 */
	@GetMapping(value="/PunchAddress")
	@ApiOperation(value = "获取打卡地址数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 9)
	public Result<PageInfo<PunchCardAddress>> getPunchCardAddress(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
260
			
yuquan.zhu committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
			PageHelper.startPage(pageNum, pageSize);
			List<PunchCardAddress> shiftList = punchcardaddressservice.selectByPrimaryByQyid(qyid);
			PageInfo<PunchCardAddress> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
	/*********打卡WIFI***********/
	/**
	 * 获取打卡WIFI数据
	 */
	@GetMapping(value="/PunchWIFI")
	@ApiOperation(value = "获取打卡WIFI数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 15)
	public Result<PageInfo<PunchCardWiFi>> getPunchCardWIFI(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
276
			
yuquan.zhu committed
277 278 279 280 281
			PageHelper.startPage(pageNum, pageSize);
			List<PunchCardWiFi> shiftList = punchcardwifiservice.selectByPrimaryByQyid(qyid);
			PageInfo<PunchCardWiFi> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
ilal committed
282 283

	/**************************************************************考勤组********************************************************************/
yuquan.zhu committed
284
	
ilal committed
285 286
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
yuquan.zhu committed
287 288
	
	/**
ilal committed
289
	 * 	查询列表-考勤组-分页【新】
yuquan.zhu committed
290
	 */
ilal committed
291 292 293 294 295 296 297 298 299 300 301 302 303
	@PostMapping(value = "/attendance_group")
	@ApiOperation(value = "34:查询列表-我审批的/抄送我的-分页", httpMethod = "POST", notes = "查询列表-我审批的-关键字、审批状态、发起时间-分页")
	@ApiOperationSupport(order = 34)
	public Result<Object> AttendanceGroup(@CurrentUser UserBean userBean, @Validated @RequestBody AttqueryCriteriaDto attquerycriteriadto){
			IPage<KqglMainKqzDto> page = new Page<KqglMainKqzDto>(
			attquerycriteriadto.getCurrentPage() == null ? 1 : attquerycriteriadto.getCurrentPage(),
			attquerycriteriadto.getTotalPage() == null ? 10 : attquerycriteriadto.getTotalPage());
			attquerycriteriadto.setOrgCode(userBean.getOrgCode());
			attquerycriteriadto.setEmpNum(userBean.getEmpNum());
			// 缺-部门id 搜索
			IPage<KqglMainKqzDto> pageAs = kqglmainkqzmapper.selectPageByQueryKqglMain(page, attquerycriteriadto);
			List<KqglMainKqzDto> listAs = pageAs.getRecords();
			return ResultUtil.data(pageAs, listAs, "操作成功!");
yuquan.zhu committed
304 305 306 307 308 309 310 311 312 313 314 315
	}
	
	/**
	 * 获取考勤组数据
	 */
	@GetMapping(value="/AttGroupList")
	@ApiOperation(value = "获取考勤组数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 21)
	public Result<PageInfo<AttendanceGroup>> getAttendanceGroupList(@CurrentUser UserBean userBean,
			@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】				
ilal committed
316
			
yuquan.zhu committed
317 318 319 320 321 322 323 324 325 326 327 328 329
			PageHelper.startPage(pageNum, pageSize);
			List<AttendanceGroup> attgrlist = attendancegroupservice.selectAttGroupListByQyid(qyid);
			PageInfo<AttendanceGroup> pageInfo = new PageInfo<>(attgrlist);
			return ResultUtil.data(pageInfo);
	}
	/**
	 * 获取考勤组数据-根据 模糊 + 高級查詢
	 */
	@PostMapping(value = "/AttGroupList/list")
	@ApiOperation(value = "获取考勤组数据-根据 模糊 + 高級查詢", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 22)
	public Result<List<AttendanceGroup>> getAttGroupListByQuery(@CurrentUser UserBean userBean,@RequestBody KqzAttendanceGroupSearch kqzattendancegroupsearch) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】	
ilal committed
330
			
yuquan.zhu committed
331
			kqzattendancegroupsearch.setQyid(qyid);
ilal committed
332
			
yuquan.zhu committed
333 334
			List<AttendanceGroup> attgrlist = attendancegroupservice.selectKqglMainKqzByQuery(kqzattendancegroupsearch);
	
ilal committed
335
			return ResultUtil.data(attgrlist);
yuquan.zhu committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
	}
	
	/**
	 * 获取修改的排班明细--【修改考勤组】--------------------------------------------------------------------------------------
	 */
	@PostMapping(value = "/AttGroupSchedulingList")
	@ApiOperation(value = "获取修改的排班明细", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 29)
	public Result<List<Schedule>> getAttGroupSchedulingList(@CurrentUser UserBean userBean,@RequestBody AttScheduling attscheduling) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			String str = sdf.format(d);
			
			String date = attscheduling.getDate();
			if(("").equals(date) || date == null){
				attscheduling.setDate(str);
			}
			
			attscheduling.setQyid(qyid);
			
			List<Schedule> schlist = scheduleservice.selectAttGroupScheduling(attscheduling);
	
			return ResultUtil.data(schlist);
	}
	
	
	/**
	 * 根据考勤组id获取班次信息--【修改考勤组】
	 */
	@GetMapping(value="/roster/{id}/{date}")
	@ApiOperation(value = "根据考勤组id获取班次信息", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 30)
	public Result<List<ShiftManagement>> getRosterList(@PathVariable("id") Integer id,@PathVariable("date") String date) {
		
		KqzAttendanceGroupSearch jycx = new KqzAttendanceGroupSearch();
		jycx.setOverall(date);
		jycx.setQyid(id);
		
		List<ShiftManagement> shifs = shiftmanagementservice.selectRosterByKqzid(jycx);
		return ResultUtil.data(shifs);
	}
	
	/**
	 * 修改考勤组排班(修改排班后,需判断是否有打卡记录,有则匹配当天修改后的班次,无则不需要修改)
	 */
	@SuppressWarnings({ "unused", "deprecation" })
	@PutMapping(value = "/attscheduling")
	@ApiOperationSupport(order = 31)
	@ApiOperation(value = "修改班次信息", httpMethod = "PUT", notes = "接口发布说明")
	public Result<List<Schedule>> updateAttscheduling(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
			int id = Integer.valueOf(attass.getAttgroupid());//修改数据id
			
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			AttendanceGroup qttgrop = attendancegroupservice.selectByPrimaryKey(Integer.valueOf(attass.getAttgroupid()));
			
			//记录排班(排班制)
			List<Schedule> schlist=new ArrayList<Schedule>();
			Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
			if(schedules.length>0 && attass.getAtttype() == 2){
				for(int p=0;p<schedules.length;p++){
					Schedule sch = new Schedule();
					sch.setUserid(schedules[p].getUserid());//用户id 
					sch.setData(schedules[p].getData());//排班日期   格式:yyyy-MM-dd
					sch.setBcid(schedules[p].getBcid());//班次id  0为休息
					sch.setKqzid(Integer.valueOf(attass.getAttgroupid()));//考勤组id
					schlist.add(sch);
					
					/*****************************/
					//转换日期
					String data = mat.format(new Date(schedules[p].getData().toString()));
					
					Long startDate = 0l;
					Long endDate = 0l;
					try {
						startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
						endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
					} catch (ParseException e) {
							e.printStackTrace();
					}
					
					//当天修改后的班次
					ShiftManagement banci = shiftmanagementservice.selectByPrimaryKey(schedules[p].getBcid());
					Long sbdk1 = 0l;
					Long xbdk1 = 0l;
					Long sbdk2 = 0l;
					Long xbdk2 = 0l;
					Long sbdk3 = 0l;
					Long xbdk3 = 0l;
					if(banci != null){
						if(banci.getSxbcs()== 1 || banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
ilal committed
431 432
							sbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk1(),2)+":00"));
							xbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk1(),2)+":00"));
yuquan.zhu committed
433 434
						}
						if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
ilal committed
435 436
							sbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk2(),2)+":00"));
							xbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk2(),2)+":00"));
yuquan.zhu committed
437 438
						}
						if(banci.getSxbcs()== 3){
ilal committed
439 440
							sbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk3(),2)+":00"));
							xbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk3(),2)+":00"));
yuquan.zhu committed
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 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 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
						}
					}
					//之前打卡的班次
					PunchRecord mapuca = punchrecordservice.MaintenancePunchCard(startDate,endDate,schedules[p].getUserid());
					
					
					if(mapuca != null && !(schedules[p].getBcid()).equals(mapuca.getBcid())){
						List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,schedules[p].getUserid());
						if(initial.size() > 0){
							RestMethod(initial,initial.get(0).getDkmxid());
						}
					}
					
					
					//当天的所有打卡记录
					List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,schedules[p].getUserid());
					PunchRecord minAttid = null;
					PunchRecord maxAttid = null;
					int dkmxid = 0;
					if(mapucalist.size() > 0){
						//最小值
				        minAttid = mapucalist.stream().min(Comparator.comparing(PunchRecord::getId)).get();
	//			        System.out.println(minAttid.getAttdate() +  "---min---" +minAttid.getId());
						//最大值
						maxAttid = mapucalist.stream().max(Comparator.comparing(PunchRecord::getId)).get();
	//			        System.out.println(maxAttid.getAttdate() +  "---max---" + maxAttid.getId());
						
						//对应打卡明细表id
						dkmxid = maxAttid.getDkmxid();
					}
					
					//当天有打卡记录且当天打卡班次和当前修改后的班次不匹配再进行重新维护
					if(mapuca != null && !(schedules[p].getBcid()).equals(mapuca.getBcid())){
						if(banci != null){//修改后有班次打卡
							if(banci.getSxbcs() == 1){//修改后一天打两次
								if(mapucalist.size() > 2){/////当天打卡多条的话 取最开始打的卡和最后打的卡 作为新一轮的上下班考勤
									for(PunchRecord pre : mapucalist){/********/
										if(pre.getId() != minAttid.getId() && pre.getId() != maxAttid.getId()){//去除最大和最小 其他均改为“打卡无效:此记录已被更新”
											PunchRecord record = new PunchRecord();
											record.setId(pre.getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											if((pre.getSort())%2 > 0){//上班
												Long time = (pre.getDktime() - sbdk1)/1000/60;
												if(time > 0){
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk1);//上班应打卡时间
											}else{//下班
												Long time = (pre.getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setResults(0);// 打卡结果
												}else{
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);//下班应打卡时间
											}
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}else{
											if(pre.getId() == minAttid.getId()){//上班
												PunchRecord record = new PunchRecord();
												record.setId(pre.getId());
												record.setType(1);//上班
												Long time = (pre.getDktime() - sbdk1)/1000/60;
												if(time > 0){
													record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk1);
												record.setBcid(banci.getId());//班次id
												punchrecordservice.updateByPrimaryKeySelective(record);
											}else if(pre.getId() == maxAttid.getId()){//下班
												PunchRecord record = new PunchRecord();
												record.setId(pre.getId());
												record.setType(2);//下班
												Long time = (pre.getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);
												record.setBcid(banci.getId());//班次id
												record.setSort(2);
												punchrecordservice.updateByPrimaryKeySelective(record);
											}
										}
									}
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									//
									PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//上班
									PunchCardDetails max = new PunchCardDetails();
									max.setId(dkmxid);//需修改的明细id
									max.setXbdk1(maxdata.getDktime());
									max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
									
									Long woktimes = (maxdata.getDktime() - mindata.getDktime())/1000/60;
									max.setGzsc(Double.valueOf(woktimes));
									
									punchcarddetailsservice.updateByPrimaryKeySelective(max);
								}else{////
									PunchRecord mindataone = null;
									//当天打卡记录为1条
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									//当天打卡记录为2条
									if(maxAttid != null && minAttid.getId() != maxAttid.getId()){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());
										record.setType(2);//下班
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);
										record.setBcid(banci.getId());//班次id
										record.setSort(2);
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										PunchCardDetails max = new PunchCardDetails();
										max.setId(dkmxid);//需修改的明细id
										max.setXbdk1(maxdata.getDktime());
										max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
										
										Long woktimes = (maxdata.getDktime() - mindataone.getDktime())/1000/60;
										max.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(max);
									}
								}
							}else if(banci.getSxbcs() == 2){//修改后一天打四次
								if(mapucalist.size() > 4){//当天打卡多次
									String[] str= new String[3];
									for(int y=0;y<mapucalist.size();y++){
										if(y == 0){//上班
											PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
	//										record.setType(1);//上班
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
											if(time > 0){
												record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk1);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										if(y == 1 || y == 2){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											
											if((mapucalist.get(y).getSort())%2 == 0){//下班
												Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);//下班应打卡时间
												
												str[0] = String.valueOf(mapucalist.get(y).getId());
											}else{//上班
												Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
												if(time > 0){
													record.setStatus(3);
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk2);//上班应打卡时间
												
												str[1] = String.valueOf(mapucalist.get(y).getId());
											}
											
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										
										
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
											PunchRecord record = new PunchRecord();
											
											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk2)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setSort(4);
											record.setAttime(xbdk2);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
											
											str[2] = String.valueOf(maxdata.getId());
										}
										
										if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											record.setResults(0);// 打卡结果
											record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
									}
									
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									
									for(int t=0;t<str.length;t++){
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(str[t]));//单条打卡明细
										
										PunchCardDetails dkmx = new PunchCardDetails();
										dkmx.setId(dkmxid);//需修改的明细id
										if(t == 0){
											dkmx.setXbdk1(dtdkmx.getDktime());
											dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
										}else if(t == 1){
											dkmx.setSbdk2(dtdkmx.getDktime());
											dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
										}else{
											dkmx.setXbdk2(dtdkmx.getDktime());
											dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
										}
										Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
										dkmx.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
									}
									 
								}else{//打卡小于4次
									PunchRecord mindataone = null;
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									
									PunchCardDetails pcd = new PunchCardDetails();
									if(mapucalist.size() >= 2){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());//当天一条记录的id
										record.setType(2);
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
										pcd.setXbdk1(dtdkmx.getDktime());
										pcd.setXbdk1jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 3){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(2).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
										pcd.setSbdk2(dtdkmx.getDktime());
										pcd.setSbdk2jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 4){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(maxAttid.getId());//当天一条记录的id
										record.setType(2);
										Long time = (maxAttid.getDktime() - xbdk2)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk2(dtdkmx.getDktime());
										pcd.setXbdk2jg(dtdkmx.getResults());
									}
									
									pcd.setId(dkmxid);
									punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
								}
							}else if(banci.getSxbcs() == 3){//修改后一天打六次
								if(mapucalist.size() > 6){//当天打卡多次
									String[] str= new String[5];
									for(int y=0;y<mapucalist.size();y++){
										if(y == 0){//上班
											PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
											if(time > 0){
												record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk1);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										if(y == 1 || y == 2 || y == 3 || y == 4){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											
											if((mapucalist.get(y).getSort())%2 == 0){//下班
												if(y == 1){
													Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
													if(time > 0){
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}else{
														record.setStatus(4);
														record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
													}
													record.setAttime(xbdk1);//下班应打卡时间
													str[0] = String.valueOf(mapucalist.get(y).getId());
												}
												
												if(y == 3){
													Long time = (mapucalist.get(y).getDktime() - xbdk2)/1000/60;
													if(time > 0){
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}else{
														record.setStatus(4);
														record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
													}
													record.setAttime(xbdk2);//下班应打卡时间
													str[2] = String.valueOf(mapucalist.get(y).getId());
												}
												
											}else{//上班
												if(y == 2){
													Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
													if(time > 0){
														record.setStatus(3);
														record.setResults(Integer.valueOf(time.toString()));// 打卡结果
													}else{
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}
													record.setAttime(sbdk2);//上班应打卡时间
													str[1] = String.valueOf(mapucalist.get(y).getId());
												}
												
												if(y == 4){
													Long time = (mapucalist.get(y).getDktime() - sbdk3)/1000/60;
													if(time > 0){
														record.setStatus(3);
														record.setResults(Integer.valueOf(time.toString()));// 打卡结果
													}else{
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}
													record.setAttime(sbdk3);//上班应打卡时间
													str[3] = String.valueOf(mapucalist.get(y).getId());
												}
											}
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										
										
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
											PunchRecord record = new PunchRecord();
											
											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk3)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setSort(6);
											record.setAttime(xbdk3);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
											
											str[4] = String.valueOf(maxdata.getId());
										}
										
										if(y == 5 || y > 5 && mapucalist.get(y).getId() != maxdata.getId()){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											record.setResults(0);// 打卡结果
											record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
									}
									
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									
									for(int t=0;t<str.length;t++){
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(str[t]));//单条打卡明细
										
										PunchCardDetails dkmx = new PunchCardDetails();
										dkmx.setId(dkmxid);//需修改的明细id
										if(t == 0){
											dkmx.setXbdk1(dtdkmx.getDktime());
											dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
										}else if(t == 1){
											dkmx.setSbdk2(dtdkmx.getDktime());
											dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
										}else if(t == 2){
											dkmx.setXbdk2(dtdkmx.getDktime());
											dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
										}else if(t == 3){
											dkmx.setSbdk3(dtdkmx.getDktime());
											dkmx.setSbdk3jg(dtdkmx.getResults());// 上班3打卡结果
										}else{
											dkmx.setXbdk3(dtdkmx.getDktime());
											dkmx.setXbdk3jg(dtdkmx.getResults());// 下班3打卡结果
										}
										Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
										dkmx.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
									}
								}else{
									/**aaa**/
									PunchRecord mindataone = null;
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									
									PunchCardDetails pcd = new PunchCardDetails();
									if(mapucalist.size() >= 2){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());//当天一条记录的id
										record.setType(2);
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
										pcd.setXbdk1(dtdkmx.getDktime());
										pcd.setXbdk1jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 3){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(2).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
										pcd.setSbdk2(dtdkmx.getDktime());
										pcd.setSbdk2jg(dtdkmx.getResults());
									}
									
									
									if(mapucalist.size() >= 4){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(3).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(3).getDktime() - xbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(xbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(3).getId());//单条打卡明细
										pcd.setXbdk2(dtdkmx.getDktime());
										pcd.setXbdk2jg(dtdkmx.getResults());
										
									}
									if(mapucalist.size() >= 5){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(4).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(4).getDktime() - sbdk3)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk3);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(4).getId());//单条打卡明细
										pcd.setSbdk3(dtdkmx.getDktime());
										pcd.setSbdk3jg(dtdkmx.getResults());
										
									}
									
									if(mapucalist.size() >= 6){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(maxAttid.getId());//当天一条记录的id
										record.setType(2);
										Long time = (maxAttid.getDktime() - xbdk3)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk3);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk3(dtdkmx.getDktime());
										pcd.setXbdk3jg(dtdkmx.getResults());
									}
									
									pcd.setId(dkmxid);
									punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
									/**bbb***/
								}
							}
						}else{////修改后班次为休息的
							RestMethod(mapucalist,dkmxid);
						}
					}
					
					/***********************/
				}
			}
			if(schlist.size()>0){
				//删除排班明细表(自由排班)
				scheduleservice.deleteByPrimaryBykqzid(id);
				scheduleservice.insertKqglAssoPbmxList(schlist);
				return ResultUtil.data(schlist,"修改考勤组排班成功");
			}
			
			return ResultUtil.error("修改考勤组排班失败");
	}
	
	/**
	 *	班次修改调用方法
	 */
	public void RestMethod(List<PunchRecord> mapucalist,int dkmxid){
		int q = 1;
		for(PunchRecord pres : mapucalist){
			PunchRecord pp = new PunchRecord();
			pp.setId(pres.getId());
			pp.setResults(0);//
			if(q%2 > 0){
				pp.setType(1);//
			}else{
				pp.setType(2);//
			}
			pp.setStatus(1);//
			pp.setSort(q);
			pp.setAttime(pres.getDktime());
			pp.setBcid(0);//
			punchrecordservice.updateByPrimaryKeySelective(pp);
			q++;
		}
		/*************/
		if(mapucalist.size() > 0){/*******修改打卡明细数据****/
			PunchCardDetails pcd = new PunchCardDetails();
			if(mapucalist.size() >= 1){
				pcd.setSbdk1(mapucalist.get(0).getDktime());
				pcd.setSbdk1jg(0);
			}
			if(mapucalist.size() >= 2){
				pcd.setXbdk1(mapucalist.get(1).getDktime());
				pcd.setXbdk1jg(0);
			}
			if(mapucalist.size() >= 3){
				pcd.setSbdk2(mapucalist.get(2).getDktime());
				pcd.setSbdk2jg(0);
			}
			if(mapucalist.size() >= 4){
				pcd.setXbdk2(mapucalist.get(3).getDktime());
				pcd.setXbdk2jg(0);
			}
			if(mapucalist.size() >= 5){
				pcd.setSbdk3(mapucalist.get(4).getDktime());
				pcd.setSbdk3jg(0);
			}
			if(mapucalist.size() >= 6){
				pcd.setXbdk3(mapucalist.get(5).getDktime());
				pcd.setXbdk3jg(0);
			}
			pcd.setId(dkmxid);
			punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
		}
	}
	
	/**
	 * 	根据考勤组id获取所有信息--【修改考勤组】
	 */
	@GetMapping(value="/AttendanceGroup/{id}")
	@ApiOperation(value = "根据考勤组id获取所有信息", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 32)
	public Result<AttendanceGroup> getAttendanceGroup(@PathVariable("id") Integer id) {
		
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		
		return ResultUtil.data(attgro);
	}
	
	/**
	 * 	获取当前考勤组所有人员
	 */
	@GetMapping(value="/AttUserGroupList/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 33)
	public Result<List<UserAttendanceRel>> getAttUserGroupList(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
		
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		List<UserAttendanceRel> userattgor = userattendancerelservice.selectAttendanceOfficerByKqzid(id,qyid);
		
		return ResultUtil.data(userattgor);
	}
	
	/**
	 * 	提醒人员
	 */
	@GetMapping(value="/AttReminderStaff/{id}")
	@ApiOperation(value = "提醒人员", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 34)
lal committed
1266
	public Result<List<YgglMainEmp>> getAttReminderStaff(@PathVariable("id") Integer id,@CurrentUser UserBean userBean) {
yuquan.zhu committed
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
		
		List<YgglMainEmp> yggl = new ArrayList<YgglMainEmp>();
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String txry = attgro.getTxry();
		
		if(txry != null && !("").equals(txry)){
			String[] coge=txry.split(";");
			String[] launchsArray=coge[0].split(",");
			launchsstr = txry.substring(0,txry.length() - 1);
			for(int i=0;i<launchsArray.length;i++){
//				System.out.println(launchsArray[i]);
lal committed
1279
				YgglMainEmp txyg = attendancegroupservice.selectByPrimaryByempNum(Integer.valueOf(launchsArray[i]),userBean.getOrgCode());
yuquan.zhu committed
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
				
				YgglMainEmp txyy = YgglMainEmp.builder().build();///
				txyy.setId(txyg.getId());
				txyy.setName(txyg.getName());
				txyy.setEmpNum(txyg.getEmpNum());
				yggl.add(txyy);
			}
		}
		return ResultUtil.data(yggl);
	}
	
	/**
	 * 提示方式
	 */
	@GetMapping(value="/PromptingMode/{id}")
	@ApiOperation(value = "提示方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 35)
	public Result<List<KqzAttendanceGroupSearch>> getAttPromptingMode(@PathVariable("id") Integer id) {
		
		List<KqzAttendanceGroupSearch> tsfslist = new ArrayList<KqzAttendanceGroupSearch>();
		
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String tsfs = attgro.getTsfs();
		
		if(tsfs != null && !("").equals(tsfs)){
			String[] coge=tsfs.split(";");
			String[] launchsArray=coge[0].split(",");
			launchsstr = tsfs.substring(0,tsfs.length() - 1);
			for(int i=0;i<launchsArray.length;i++){
				System.out.println(launchsArray[i]);
				KqzAttendanceGroupSearch xtxt = new KqzAttendanceGroupSearch();
				xtxt.setOverall(launchsArray[i]);
				tsfslist.add(xtxt);
			}
		}
		
		return ResultUtil.data(tsfslist);
	}
	
	/**
	 * ??????
	 */
	@GetMapping(value="/WeeklyScheduling/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 36)
	public Result<List<AttendanceWeeklySch>> getAttWeeklyScheduling(@PathVariable("id") Integer id) {
		
		List<AttendanceWeeklySch> atwesclist = attendanceweeklyschservice.selectAttWeeklySchedulingByKqzid(id);
		
		
		return ResultUtil.data(atwesclist);
	}
	
	/**
	 * 考勤组绑定的打卡方式
	 */
	@GetMapping(value="/Attendancemethod/{id}")
	@ApiOperation(value = "考勤组绑定的打卡方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 37)
	public Result<List<AttGroupBinPunchMode>> getAttendancemethodList(@PathVariable("id") Integer id) {
		
		List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodeservice.selectByPrimaryByKqzId(id);
		
		return ResultUtil.data(attmetlist);
	}
	
	/**
	 * 固定排班周
	 */
	@GetMapping(value="/AttendanceWeeklyScheduling/{id}")
	@ApiOperation(value = "固定排班周", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 38)
	public Result<List<AttendanceWeeklySch>> AttendanceWeeklySchedulingList(@PathVariable("id") Integer id) {
		
		List<AttendanceWeeklySch> attweeklist = attendanceweeklyschservice.selectAttWeeklySchByKqzid(id);
		
		return ResultUtil.data(attweeklist);
	}
	
	/**
	 * 固定排班特殊日期
	 */
	@GetMapping(value="/AttSpecialDates/{id}")
	@ApiOperation(value = "固定排班特殊日期", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 39)
	public Result<List<SpecialDate>> AttSpecialDatesList(@PathVariable("id") Integer id) {
		
		List<SpecialDate> tesulist = specialdateservice.selectSpecialDatesByKqzid(id);
		
		return ResultUtil.data(tesulist);
	}
	
	
	/**
	 *	 修改考勤基本信息
	 */
	@PutMapping(value = "/BasicAttendanceInformation")
	@ApiOperation(value = "修改考勤信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 40)
	public Result<Void> BasicAttendanceInformation(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			int attgrpid = Integer.valueOf(attass.getAttgroupid());//考勤组ID
			
			AttendanceGroup attgro = new AttendanceGroup();
			attgro.setId(attgrpid);//修改考勤组id
			attgro.setName(attass.getName());//名称
			attgro.setKqbz(attass.getRemarks());//考勤备注
			attgro.setPbfs(attass.getAtttype());//排班方式 // 考勤类型:1-固定排班、2-排班制、3-自由工时 *
			attgro.setQyid(qyid);//企业id
			
			attgro.setIsWq(attass.getFieldpersonnel());//外勤:0-关  1-开
			
			if(attass.getAtttype() == 1){
				attgro.setIsFdjjr(attass.getLegalholidays());//是否开启法定节假日休息(固定排班)
			}
			if(attass.getAtttype() == 2){
				String[] attShifts = attass.getAttShifts();
				String sybc=String.join(",",attShifts);
				attgro.setSybc(sybc);
				attgro.setIsDqtx(attass.getAttRemind());//是否开启到期提醒([排班制专用]0:否;1:是)
				
				attgro.setIsXzbcdk(attass.getOptscheduling());//未排班时,员工可选择班次打卡
				
				 String[] coge=attass.getAttRemindUserids();
				 String str=String.join(",",coge);
				attgro.setTxry(str);//提醒人员([排班制专用]员工id以[“,”]连接  json数组)
				attgro.setTxfs(attass.getAdvanceDays());//提醒方式([排班制专用]提前15天、7天、3天、1天)
				attgro.setTxxhts(attass.getRemCycleDays());//提醒循环天数([排班制专用])
				attgro.setTxsjTime(attass.getReminderTime());//提醒时间([排班制专用])
				 String[] rem=attass.getPromptingMode();
				 String strrem=String.join(",",rem);
				attgro.setTsfs(strrem);//提示方式([排班制专用]PC端、APP客户端、短信、邮件 以[“,”]连接  json数组)
				attgro.setIsWpbsdk(attass.getAttRemind());//是否开启未排班时打卡([排班制专用]0:否;1:是;未排班时,员工可以选择班次打卡)
			}
			if(attass.getAtttype() == 3){
				attgro.setKqkssjTime(attass.getNewAttTime());//考勤开始时间(自由工时专用)
				attgro.setZsgzsc(attass.getLeastworkTime());//至少工作时长(自由工时专用)
				attgro.setZcgzsc(attass.getNormalWorkTime());//正常工作时长(自由工时专用)
				attgro.setJbzdsc(attass.getMaxOvertimeTime());//加班最大时长(自由工时专用)
			}
lal committed
1423
			attgro.setOvertimeRulesId(attass.getOvertimeRulesId());//加班规则ID
yuquan.zhu committed
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
			attendancegroupservice.updateByPrimaryKeySelective(attgro);
			
			/*********/
			attgroupbinpunchmodeservice.deleteByPrimaryBykqzid(attgrpid);
			/**********/
			List<AttGroupBinPunchMode> kqzdkfslist=new ArrayList<AttGroupBinPunchMode>();
			//考勤机
			String[] attmac = attass.getAttmachines();
			if(attmac.length>0){
				for (int i = 0; i < attmac.length; i++) {
					AttGroupBinPunchMode attgbpmac = new AttGroupBinPunchMode();
					attgbpmac.setDkfsid(Integer.valueOf(attmac[i]));// 考勤机、地址、WIFI的id
					attgbpmac.setKqzId(attgrpid);// 考勤组ID
					attgbpmac.setType(1);// 1:考勤机;2:地址;3:WIFI
					attgbpmac.setQyid(qyid);// 企业id
					attgbpmac.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpmac);
				}
			}
			//考勤地址
			String[] atad = attass.getAttadds();
			if(atad.length > 0){
				for(int a=0;a<atad.length;a++){
					AttGroupBinPunchMode attgbpadd = new AttGroupBinPunchMode();
					attgbpadd.setDkfsid(Integer.valueOf(atad[a]));// 考勤机、地址、WIFI的id
					attgbpadd.setKqzId(attgrpid);// 考勤组ID
					attgbpadd.setType(2);// 1:考勤机;2:地址;3:WIFI
					attgbpadd.setQyid(qyid);// 企业id
					attgbpadd.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpadd);
				}
			}
			//考勤WIFI
			String[] atwf = attass.getAttwifis();
			if(atwf.length > 0){
				for(int f=0;f<atwf.length;f++){
					AttGroupBinPunchMode attgbpwf = new AttGroupBinPunchMode();
					attgbpwf.setDkfsid(Integer.valueOf(atwf[f]));// 考勤机、地址、WIFI的id
					attgbpwf.setKqzId(attgrpid);// 考勤组ID
					attgbpwf.setType(3);// 1:考勤机;2:地址;3:WIFI
					attgbpwf.setQyid(qyid);// 企业id
					attgbpwf.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpwf);
				}
			}
			if(kqzdkfslist.size()>0){
				attgroupbinpunchmodeservice.insertKqglAssokqzdKfsList(kqzdkfslist);
			}
			//用户与设备关系(考勤机id-->用户id)
			
			
			//用户和考勤组关系
			/***/
			userattendancerelservice.deleteByPrimaryBykqzid(attgrpid);
			/**/
			List<UserAttendanceRel> yhkqzlist=new ArrayList<UserAttendanceRel>();
			String[] attser = attass.getAttuserids();
			if(attser.length>0){
				
				String user_id = "";
				String user_name = "";
				String DevId = "";
				
				for(int u=0;u<attser.length;u++){
					
					if(attass.getAtttype() == 2){//排班制     考勤组与用户、用户排班
						scheduleservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					}
					userattendancerelservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					
					UserAttendanceRel kquser = new UserAttendanceRel();
					kquser.setKqzid(attgrpid);
					kquser.setUserid(Integer.valueOf(attser[u]));
					kquser.setQyid(qyid);
					yhkqzlist.add(kquser);
					
					
					/***********************************录入相应的考勤机(修改)**************************************************************/
					List<AttGroupBinPunchMode> kqjs = attgroupbinpunchmodeservice.selectMachineByKqzId(attgrpid);//该考勤组所绑定的考勤机
					
					for(AttGroupBinPunchMode abp:kqjs) {
						AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid());//查询考勤机“序列号”
						UserEquiRelation kqjry = userequirelationmapper.selectByuserIdkqjid(Integer.valueOf(attser[u]), kqj.getId());
						if(kqjry == null) {
							//用户与设备关系(考勤机id-->用户id)
							UserEquiRelation uskqj = new UserEquiRelation();
							uskqj.setUserId(Integer.valueOf(attser[u]));//用户id
							uskqj.setKqjid(kqj.getId());//设备id
							uskqj.setType(1);//类型(类型 1:考勤机)
							UserEquiRelation isgly = userequirelationmapper.selectByuserId(Integer.valueOf(attser[u]));
							if(isgly != null) {
								uskqj.setIsGly(isgly.getIsGly());
							}else {
								uskqj.setIsGly(0);
							}
							userequirelationmapper.insert(uskqj);
						}
lal committed
1521 1522
						
						YgglMainEmp yggluser = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()).eq(YgglMainEmp::getEmpNum, attser[u]));
lal committed
1523
						String url = mac_command+"/addUserName";
yuquan.zhu committed
1524 1525
				        HttpHeaders headers = new HttpHeaders();
				        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
lal committed
1526 1527 1528
				        params.add("devId", kqj.getCode());
				        params.add("userId", attser[u]);
				        params.add("userName", yggluser.getName());
yuquan.zhu committed
1529 1530 1531
				        RestTemplate restTemplate = new RestTemplate();
				        HttpEntity httpEntity = new HttpEntity(params, headers);
				        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
lal committed
1532 1533 1534
				        System.err.print(request.getBody());
						
						
yuquan.zhu committed
1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
					}
					/*****************************************************************************/
				}
			}
			if(yhkqzlist.size()>0){
				userattendancerelservice.insertKqglAssoKqzdkfsList(yhkqzlist);
			}
			
			//固定排版周记录  attendanceweeklyschservice
			/*****/
			attendanceweeklyschservice.deleteByPrimaryBykqzid(attgrpid);
			/****/
			List<AttendanceWeeklySch> attweeklist=new ArrayList<AttendanceWeeklySch>();
			String[] weektime = attass.getAttWeekdays();//周工作日【固定排班】
			String[] weekshif = attass.getAttWeekdaysShifts();//周工作日班次【固定排班】
			if(weektime.length>0 && weekshif.length>0 && attass.getAtttype() == 1){
				for(int h=0;h<weektime.length;h++){
					AttendanceWeeklySch attweek = new AttendanceWeeklySch();
					attweek.setKqzid(attgrpid);
					attweek.setType(Integer.valueOf(weektime[h]));
					attweek.setBcid(Integer.valueOf(weekshif[h]));
					attweeklist.add(attweek);
				}
			}
			//自由工时 周排班
			String[] attFrWorkdays = attass.getAttFreeWorkdays();// 周工作日【自由工时】
			if(attFrWorkdays.length>0 && attass.getAtttype() == 3){
				for(int w=0;w<attFrWorkdays.length;w++){
					AttendanceWeeklySch attfrwor = new AttendanceWeeklySch();
					attfrwor.setKqzid(attgrpid);
					attfrwor.setType(Integer.valueOf(attFrWorkdays[w]));
					attfrwor.setBcid(0);
					attweeklist.add(attfrwor);
				}
			}
			if(attweeklist.size()>0){
				attendanceweeklyschservice.insertKqglAssoZhoupaibanList(attweeklist);
			}
			
			/***********/
			specialdateservice.deleteByPrimaryBykqzid(attgrpid);
			/**********/
			//特殊日期--必须打卡、不用打卡日期
			List<SpecialDate> speclist=new ArrayList<SpecialDate>();
			String[] attmuspudata = attass.getAttMustPunchData();// 必须打卡的日期【固定排班】
			String[] attmuspushifid = attass.getAttMustPunchShifid();// 必须打卡的班次id【固定排班】
			String[] attnonpudata = attass.getAttNonPunchData();// 不用打卡的日期【固定排班】
			if(attmuspudata.length>0 && attmuspushifid.length>0 && attass.getAtttype() == 1){
				for(int m=0;m<attmuspudata.length;m++){
					SpecialDate mut = new SpecialDate();
					mut.setKqzid(attgrpid);//考勤组id
					mut.setTsrq(attmuspudata[m]);//日期
					mut.setBcid(Integer.valueOf(attmuspushifid[m]));//班次id
					long date = new Date().getTime();
					mut.setLusjTime(date);//录入时间
					mut.setLuryid(180658);// 录入人员***********
					mut.setType(1);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(mut);
				}
			}
			if(attnonpudata.length>0 && attass.getAtttype() == 1){
				for(int n=0;n<attnonpudata.length;n++){
					SpecialDate non = new SpecialDate();
					non.setKqzid(attgrpid);//考勤组id
					non.setTsrq(attnonpudata[n]);//日期
					non.setBcid(0);//班次id
					long date = new Date().getTime();
					non.setLusjTime(date);//录入时间
					non.setLuryid(180658);// 录入人员***********
					non.setType(2);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(non);
				}
			}
			if(speclist.size()>0){
				specialdateservice.insertKqglAssoTeshuList(speclist);
			}
			
			/**********/
			scheduleservice.deleteByPrimaryBykqzid(attgrpid);
			/***********/
			//记录排班(排班制)
			List<Schedule> schlist=new ArrayList<Schedule>();
			Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
			if(schedules.length>0 && attass.getAtttype() == 2){
				for(int p=0;p<schedules.length;p++){
					Schedule sch = new Schedule();
					sch.setUserid(schedules[p].getUserid());
					sch.setData(schedules[p].getData());
					sch.setBcid(schedules[p].getBcid());
					sch.setKqzid(attgrpid);
					schlist.add(sch);
				}
			}
			if(schlist.size()>0){
				scheduleservice.insertKqglAssoPbmxList(schlist);
			}
ilal committed
1631 1632 1633
			
			
	//		if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
yuquan.zhu committed
1634
				return ResultUtil.data(null,"修改考勤组信息成功");
ilal committed
1635 1636
	//		}
	//		return ResultUtil.error("修改考勤组信息失败");
yuquan.zhu committed
1637 1638 1639 1640
	}
	
	/*******考勤组--结束*********/

ilal committed
1641 1642 1643 1644 1645 1646
	
	/***********APP--调用接口开始*****************/
	
	
//	@GetMapping(value="/attendancereport")
//	@ApiOperation(value = "获取考勤报表数据", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
1647 1648 1649 1650 1651 1652 1653
	/**
	 * 获取考勤报表数据
	 */
	@PostMapping(value = "/attendancereport")
	@ApiOperation(value = "获取考勤报表数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 41)
	public Result<List<AttendanceReport>> getAttendanceReport(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
ilal committed
1654 1655
		
		
yuquan.zhu committed
1656 1657
			//考勤报表列表
			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
ilal committed
1658
			
yuquan.zhu committed
1659
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1660 1661
			int userid = userBean.getEmpNum();//用户id	
			
yuquan.zhu committed
1662 1663 1664 1665
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH) + 1;
			int date = cal.get(Calendar.DATE);
ilal committed
1666
			
yuquan.zhu committed
1667 1668 1669
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    String str = sdf.format(d);
ilal committed
1670
			
yuquan.zhu committed
1671 1672
			Long startDate = 0l;
			Long endDate = 0l;
ilal committed
1673
			
yuquan.zhu committed
1674 1675
			if(!("").equals(attendancedetails.getStart())){
			   try {
ilal committed
1676
				   String sdaet = getMinMonthDate(attendancedetails.getStart());
yuquan.zhu committed
1677 1678
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
ilal committed
1679
				   String edate = getMaxMonthDate(attendancedetails.getEnd());
yuquan.zhu committed
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
				   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else{
				try {
					Calendar c = Calendar.getInstance();    
					c.add(Calendar.MONTH, 0);
					c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
					String first = mat.format(c.getTime());
					startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
					//获取当前月最后一天
					Calendar ca = Calendar.getInstance();    
					ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
					String last = mat.format(ca.getTime());
					endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
ilal committed
1700 1701
			
			
yuquan.zhu committed
1702
			List<YgglMainEmp> attoff = attendancegroupservice.selectAttendanceOfficer(String.valueOf(qyid),attendancedetails.getText());//获取公司人员
ilal committed
1703
			
yuquan.zhu committed
1704
			for(YgglMainEmp kqry : attoff){
ilal committed
1705
				
yuquan.zhu committed
1706
				int gzsc = punchcarddetailsservice.selectWorkingHours(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
ilal committed
1707
				
yuquan.zhu committed
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,Integer.valueOf(kqry.getEmpNum()));
				int latenum = 0;// 迟到次数
				int latehours = 0;// 迟到时长
				int leanum = 0;// 早退次数
				int leahours = 0;// 早退时长
				if(initial.size() > 0){
					for(PunchRecord prd : initial){
						if(prd.getType() == 1 && prd.getResults() > 0){
							latenum++;
							latehours += prd.getResults();
						}
						if(prd.getType() == 2 && prd.getResults() > 0){
							leanum++;
							leahours += prd.getResults();
						}
					}
				}
ilal committed
1725
				
yuquan.zhu committed
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
				AttendanceReport apr = new AttendanceReport();
				apr.setId(Integer.valueOf(kqry.getEmpNum()));
				apr.setName(kqry.getName());//姓名
				apr.setJobnumber(kqry.getEmpNum());//工号
				apr.setWorkhours(gzsc);//工作时长
				
				apr.setLatenum(latenum);//
				apr.setLatehours(latehours);//
				apr.setLeanum(leanum);//
				apr.setLeahours(leahours);//
ilal committed
1736
				/**********/
Yl123 committed
1737
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
yuquan.zhu committed
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
				//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
				if(attgro != null){//该员工是否加入到考勤组
					if(attgro.getPbfs() == 1){
						//当前月     必须打卡日期
						List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						int bxdk = bxdklist.size();
						//当前月     无需打卡日期
						List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						String[] appmaps= new String[wxdk.size()];
						int d1 = 0;
						for(SpecialDate spe:wxdk){
							appmaps[d1] = spe.getTsrq();
							d1++;
						}
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						int q = 0;
ilal committed
1776
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
							 try {
								Date date1 = sdf1.parse(yemo + "-" + i);
								for(int u=0;u<week.length;u++){
									if(sdf2.format(date1).equals(week[u])){
										
										q++;
										
										y++;
										if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
											y = y-1;
										}
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
ilal committed
1795
						 int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
yuquan.zhu committed
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y+bxdk);//应出勤
						/***********/
					}else if(attgro.getPbfs() == 2){
						List<Schedule> ycqs = scheduleservice.getAttendanceShouldList(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
						int xiuxi = 0;
						int shangban = 0;
						for(Schedule sc : ycqs){
							if(sc.getBcid().equals(0)){
								xiuxi++;
							}else{
								shangban++;
							}
						}
ilal committed
1810
	//					System.out.println(xiuxi);
yuquan.zhu committed
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
						apr.setRestday(xiuxi);//休息天数
						apr.setAnswerday(shangban);//应出勤
					}else{
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
ilal committed
1837
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
							 try {
								Date date1 = sdf1.parse(yemo + "-" + i);
								for(int u=0;u<week.length;u++){
									if(sdf2.format(date1).equals(week[u])){
										y++;
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
ilal committed
1850
						 int xiuxi = getDaysByYearMonth(year,month) - y;
yuquan.zhu committed
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y);//应出勤
					}
				    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate);//打卡记录
				    apr.setActualday(attendance.size());//已出勤
					if(apr.getAnswerday() > 0){
						BigDecimal g = new BigDecimal(apr.getAnswerday());  
						BigDecimal h = new BigDecimal(apr.getActualday()); 
						int lack = g.subtract(h).intValue();  
						apr.setMinerday(lack);//缺勤
					}
		            int sbqk = 0;
		            int xbqk = 0;
		            for(PunchCardDetails pcd:attendance){
		            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk1() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk1() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk2() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk2() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk3() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk3() == null){
		            			xbqk++;
		            		}
		            	}
		            }
		            apr.setGoworkmissingcard(sbqk);//上班缺卡
		            apr.setOffworkmissingcard(xbqk);//下班缺卡
				}
ilal committed
1893 1894 1895 1896
				/**********/
				
				
				
yuquan.zhu committed
1897 1898
				attrep.add(apr);
			}
ilal committed
1899 1900
			
			
yuquan.zhu committed
1901 1902 1903
			return ResultUtil.data(attrep);
	}
	
ilal committed
1904 1905 1906 1907 1908
	
	
	
	
	
yuquan.zhu committed
1909 1910 1911 1912 1913 1914 1915 1916
	/**
	 * 获取考勤详情
	 */
	@GetMapping(value="/attendancedetails")
	@ApiOperation(value = "获取考勤详情数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 42)
	public Result<List<PunchCardDetails>> getAttendanceDetails(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1917 1918
			int userid = userBean.getEmpNum();//用户id	
			
yuquan.zhu committed
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934
			Long starttime = 0l;
			Long endtime = 0l;
			try {
				Calendar c = Calendar.getInstance();    
				c.add(Calendar.MONTH, 0);
				c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
				String first = mat.format(c.getTime());
				starttime = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
				//获取当前月最后一天
				Calendar ca = Calendar.getInstance();    
				ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
				String last = mat.format(ca.getTime());
				endtime = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
ilal committed
1935
			
yuquan.zhu committed
1936
			List<PunchCardDetails> attdetails = punchcarddetailsservice.SelectAttendanceDetails(qyid,starttime,endtime);
ilal committed
1937 1938
			
			
yuquan.zhu committed
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
			return ResultUtil.data(attdetails);
	}
	
	/**
	 * 获取考勤详情-根据 模糊 + 高級查詢
	 */
	@PostMapping(value = "/attfuzzyquerygroup/list")
	@ApiOperation(value = " 获取考勤详情-根据 模糊 + 高級查詢", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 43)
	public Result<List<PunchCardDetails>> getAttFuzzyGroupListByQuery(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1950
			int userid = userBean.getEmpNum();//用户id	
yuquan.zhu committed
1951
			attendancedetails.setQyid(qyid);
ilal committed
1952
			
yuquan.zhu committed
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
			Long starttime = 0l;
			Long endtime = 0l;
			try {
				if(!("").equals(attendancedetails.getStart())){
					starttime = DateUtil.getStartTime(0,DateUtil.getStringTime(attendancedetails.getStart(),"yyyy-MM-dd")).getTime();
					endtime = DateUtil.getnowEndTime(23,DateUtil.getStringTime(attendancedetails.getEnd(),"yyyy-MM-dd")).getTime();
					attendancedetails.setStart(String.valueOf(starttime));
					attendancedetails.setEnd(String.valueOf(endtime));
				}else{
					attendancedetails.setStart("");
					attendancedetails.setEnd("");
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
ilal committed
1968 1969
			
			
yuquan.zhu committed
1970
			List<PunchCardDetails> kqxqlist = punchcarddetailsservice.QueryAttendanceDetails(attendancedetails);
ilal committed
1971
	
yuquan.zhu committed
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
			return ResultUtil.data(kqxqlist);
	}
	
	/**
	 * 获取考勤原始记录
	 */
	@GetMapping(value="/AttendanceCalendar")
	@ApiOperation(value = "获取考勤原始记录数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 44)
	public Result<List<PunchRecord>> getAttendanceCalendarByCondition(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1983 1984
			int userid = userBean.getEmpNum();//用户id
			
yuquan.zhu committed
1985
			List<PunchRecord> origattreclist = punchrecordservice.selectOriginalAttendanceRecord(qyid);
ilal committed
1986
	
yuquan.zhu committed
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
			return ResultUtil.data(origattreclist);
	}
	/**
	 * 获取考勤原始记录-根据 模糊 + 高級查詢
	 */
	@PostMapping(value = "/FuzzyOriginalAttendance/list")
	@ApiOperation(value = "获取考勤原始记录   模糊 + 高級查詢", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 45)
	public Result<List<PunchRecord>> getFuzzyCheckOriginalAttendanceRecord(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1997
			int userid = userBean.getEmpNum();//用户id
yuquan.zhu committed
1998
			attendancedetails.setQyid(qyid);
ilal committed
1999
			
yuquan.zhu committed
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
			Long starttime = 0l;
			Long endtime = 0l;
			try {
				if(!("").equals(attendancedetails.getStart())){
					starttime = DateUtil.getStartTime(0,DateUtil.getStringTime(attendancedetails.getStart(),"yyyy-MM-dd")).getTime();
					endtime = DateUtil.getnowEndTime(23,DateUtil.getStringTime(attendancedetails.getEnd(),"yyyy-MM-dd")).getTime();
					attendancedetails.setStart(String.valueOf(starttime));
					attendancedetails.setEnd(String.valueOf(endtime));
				}else{
					attendancedetails.setStart("");
					attendancedetails.setEnd("");
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
ilal committed
2015
			
yuquan.zhu committed
2016
			List<PunchRecord> original = punchrecordservice.selFuzzyOriginalAttendance(attendancedetails);
ilal committed
2017
	
yuquan.zhu committed
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028
			return ResultUtil.data(original);
	}
	
	
	/**
	 * 获取查看考勤明细
	 */
	@GetMapping(value="/AttendanceDetails/{userid}/{detailtime}")
	@ApiOperation(value = "获取查看考勤明细", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 46)
	public Result<List<PunchRecord>> getAttendanceDetailsList(@PathVariable("userid") Integer userid,@PathVariable("detailtime") String detailtime) {
ilal committed
2029
		
yuquan.zhu committed
2030 2031 2032 2033 2034 2035 2036
		Long starttime = 0l;
		Long endtime = 0l;
		try {
			if(!("").equals(detailtime)){
				starttime = DateUtil.getStartTime(0,DateUtil.getStringTime(detailtime,"yyyy-MM-dd")).getTime();
				endtime = DateUtil.getnowEndTime(23,DateUtil.getStringTime(detailtime,"yyyy-MM-dd")).getTime();
			}else{
ilal committed
2037 2038
				//attendancedetails.setStart("");
				//attendancedetails.setEnd("");
yuquan.zhu committed
2039 2040 2041 2042
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
ilal committed
2043
		
yuquan.zhu committed
2044
		List<PunchRecord> detail = punchrecordservice.ViewAttendanceDetails(starttime,endtime,userid);
ilal committed
2045

yuquan.zhu committed
2046 2047 2048 2049 2050 2051
		return ResultUtil.data(detail);
	}
	
	/**
	 * 获取考勤日历出勤数据
	 */
ilal committed
2052 2053
//	@GetMapping(value = "/AttOriginalRecord")
//	@ApiOperation(value = "获取考勤日历数据", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
2054 2055 2056 2057 2058
	@PostMapping(value = "/AttOriginalRecord")
	@ApiOperation(value = "获取考勤日历出勤数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 47)
	public Result<AttendanceCalendar> getAttOriginalRecord(@CurrentUser UserBean userBean,@RequestBody AttConditions atttions) {
			AttendanceCalendar attcal = new AttendanceCalendar();//考勤日历显示数据
ilal committed
2059
			
yuquan.zhu committed
2060 2061
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
ilal committed
2062
			
yuquan.zhu committed
2063
			String str = null;
ilal committed
2064
			
yuquan.zhu committed
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083
			int year = 0;
			int month = 0;
			int date = 0;
			if(!("").equals(atttions.getDate())){
				String dati[]=atttions.getDate().split("-");
				year = Integer.valueOf(dati[0]);
				month = Integer.valueOf(dati[1]);
				date = Integer.valueOf(dati[2]);
				str = atttions.getDate();
			}else{
				Calendar cal = Calendar.getInstance();
				year = cal.get(Calendar.YEAR);
				month = cal.get(Calendar.MONTH) + 1;
				date = cal.get(Calendar.DATE);
				
				Date d = new Date();
			    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			    str = sdf.format(d);
			}
ilal committed
2084
			
yuquan.zhu committed
2085 2086
			Long startDate = 0l;
			Long endDate = 0l;
ilal committed
2087
			
yuquan.zhu committed
2088 2089
			if(!("").equals(atttions.getDate())){
			   try {
ilal committed
2090
				   String sdaet = getMinMonthDate(str);
yuquan.zhu committed
2091
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
ilal committed
2092 2093
				       
				   String edate = getMaxMonthDate(str);
yuquan.zhu committed
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
				   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else{
				try {
					Calendar c = Calendar.getInstance();    
					c.add(Calendar.MONTH, 0);
					c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
					String first = mat.format(c.getTime());
					startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
					//获取当前月最后一天
					Calendar ca = Calendar.getInstance();    
					ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
					String last = mat.format(ca.getTime());
					endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
ilal committed
2114
			
Yl123 committed
2115
			AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
2116 2117
			//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
			if(attgro != null){//该员工是否加入到考勤组
ilal committed
2118
				
yuquan.zhu committed
2119
				if(attgro.getPbfs() == 1){
ilal committed
2120
					
yuquan.zhu committed
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131
					//当前月     必须打卡日期
					List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
					int bxdk = bxdklist.size();
					//当前月     无需打卡日期
					List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
					String[] appmaps= new String[wxdk.size()];
					int d = 0;
					for(SpecialDate spe:wxdk){
						appmaps[d] = spe.getTsrq();
						d++;
					}
ilal committed
2132
					
yuquan.zhu committed
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid);
					String[] week= new String[atwek.size()];
					int e = 0;
					for(AttendanceWeeklySch awek : atwek){
						week[e] = awek.getWekmc();
						e++;
					}
					String yemo = year + "-" + month;
					String datetime = year + "-" + month + "-" + date;
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
					sdf1.setLenient(false);
					SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date parse = sdf.parse(datetime);
						Calendar lastDate = Calendar.getInstance();
						 lastDate.setTime(parse);
						 lastDate.set(Calendar.DATE, 1);
						 lastDate.add(Calendar.MONTH, 1);
						 lastDate.add(Calendar.DATE, -1);
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					int y = 0;
ilal committed
2157
					 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172
						 try {
							Date date1 = sdf1.parse(yemo + "-" + i);
							for(int u=0;u<week.length;u++){
								if(sdf2.format(date1).equals(week[u])){
	//								System.out.println(sdf1.format(date1) + " : " + sdf2.format(date1)+"---"+i);
									y++;
									if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
										y = y-1;
									}
								}
							}
						} catch (ParseException c) {
							c.printStackTrace();
						}
					 }
ilal committed
2173
					 
yuquan.zhu committed
2174
					 attcal.setAttshouldmade(y+bxdk);//应出勤
ilal committed
2175 2176
					/***********/
					
yuquan.zhu committed
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186
				}else if(attgro.getPbfs() == 2){
					List<Schedule> ycqs = scheduleservice.getAttendanceShouldList(userid,startDate,endDate);
					int shangban = 0;
					for(Schedule sc : ycqs){
						if(!sc.getBcid().equals(0)){
							shangban++;
						}
					}
					attcal.setAttshouldmade(shangban);//应出勤
				}else{
ilal committed
2187
					
yuquan.zhu committed
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid);
					String[] week= new String[atwek.size()];
					int e = 0;
					for(AttendanceWeeklySch awek : atwek){
						week[e] = awek.getWekmc();
						e++;
					}
					String yemo = year + "-" + month;
					String datetime = year + "-" + month + "-" + date;
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
					sdf1.setLenient(false);
					SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date parse = sdf.parse(datetime);
						Calendar lastDate = Calendar.getInstance();
						 lastDate.setTime(parse);
						 lastDate.set(Calendar.DATE, 1);
						 lastDate.add(Calendar.MONTH, 1);
						 lastDate.add(Calendar.DATE, -1);
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					int y = 0;
ilal committed
2212
					 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223
						 try {
							Date date1 = sdf1.parse(yemo + "-" + i);
							for(int u=0;u<week.length;u++){
								if(sdf2.format(date1).equals(week[u])){
									y++;
								}
							}
						} catch (ParseException c) {
							c.printStackTrace();
						}
					 }
ilal committed
2224
					 
yuquan.zhu committed
2225 2226
					 attcal.setAttshouldmade(y);//应出勤
				}
ilal committed
2227
				
yuquan.zhu committed
2228 2229
			    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(userid, startDate, endDate);//打卡记录
				attcal.setAttendance(attendance.size());//已出勤
ilal committed
2230 2231
				
				
yuquan.zhu committed
2232 2233 2234 2235 2236 2237
				if(attcal.getAttshouldmade() != null){
					BigDecimal g = new BigDecimal(attcal.getAttshouldmade());  
					BigDecimal h = new BigDecimal(attcal.getAttendance()); 
					int lack = g.subtract(h).intValue();  
					attcal.setAbsenceduty(lack);//缺勤
				}
ilal committed
2238 2239
	            
	            
yuquan.zhu committed
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269
	            int sbqk = 0;
	            int xbqk = 0;
	            for(PunchCardDetails pcd:attendance){
	            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
	            		if(pcd.getSbdk1() == null){
	            			sbqk++;
	            		}
	            		if(pcd.getXbdk1() == null){
	            			xbqk++;
	            		}
	            	}
	            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
	            		if(pcd.getSbdk2() == null){
	            			sbqk++;
	            		}
	            		if(pcd.getXbdk2() == null){
	            			xbqk++;
	            		}
	            	}
	            	if(pcd.getYdkcs() == 6){
	            		if(pcd.getSbdk3() == null){
	            			sbqk++;
	            		}
	            		if(pcd.getXbdk3() == null){
	            			xbqk++;
	            		}
	            	}
	            }
	            attcal.setGomiscard(sbqk);//上班缺卡
	            attcal.setOffmiscard(xbqk);//下班缺卡
ilal committed
2270 2271 2272
	            
	           
			
yuquan.zhu committed
2273 2274
			}
			return ResultUtil.data(attcal);
ilal committed
2275

yuquan.zhu committed
2276 2277
	}
	
ilal committed
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295
	/***********APP--调用接口结束*****************/
	
	/**
	 * 根据 年、月 获取对应的月份 的 天数
     */
	 public static int getDaysByYearMonth(int year, int month)
	 {
	     Calendar a = Calendar.getInstance();
	     a.set(Calendar.YEAR, year);
	     a.set(Calendar.MONTH, month - 1);
	     a.set(Calendar.DATE, 1);
	     a.roll(Calendar.DATE, -1);
	     int maxDate = a.get(Calendar.DATE);
	     return maxDate;
	 }
	
	
	
yuquan.zhu committed
2296 2297 2298
	/**
	 * 	获取考勤日历显示出勤详细数据
	 */
ilal committed
2299
	@SuppressWarnings("deprecation")
yuquan.zhu committed
2300 2301 2302 2303 2304 2305
	@PostMapping(value = "/SpecificAttendance")
	@ApiOperation(value = "获取考勤日历显示出勤详细数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 48)
	public Result<List<ScheduleAux>> getSpecificAttendance(@CurrentUser UserBean userBean,@RequestBody AttConditions attconditions) {
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		int userid = userBean.getEmpNum();//用户id	
ilal committed
2306
		
yuquan.zhu committed
2307 2308 2309
		Date dno = new Date();
	    SimpleDateFormat sdfno = new SimpleDateFormat("yyyy-MM-dd");
	    String now = sdfno.format(dno);
ilal committed
2310 2311 2312
		
//		int userid =  600135;//马丹丹//600126;//肖丽思
		
yuquan.zhu committed
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
		String str = null;
		int year = 0;
		int month = 0;
		int date = 0;
		if(!("").equals(attconditions.getDate())){
			String dati[]=attconditions.getDate().split("-");
			year = Integer.valueOf(dati[0]);
			month = Integer.valueOf(dati[1]);
			date = Integer.valueOf(dati[2]);
			str = attconditions.getDate();
		}else{
			Calendar cal = Calendar.getInstance();
			year = cal.get(Calendar.YEAR);
			month = cal.get(Calendar.MONTH) + 1;
			date = cal.get(Calendar.DATE);
			
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    str = sdf.format(d);
		}
ilal committed
2333
		 
yuquan.zhu committed
2334 2335
		 Long startDate = 0l;
	     Long endDate = 0l;
ilal committed
2336
		 
yuquan.zhu committed
2337 2338
		 if(!("").equals(attconditions.getDate())){
		   try {
ilal committed
2339
			   String sdaet = getMinMonthDate(str);
yuquan.zhu committed
2340 2341
			   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
			       
ilal committed
2342
			   String edate = getMaxMonthDate(str);
yuquan.zhu committed
2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
			   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}else{
			try {
				Calendar c = Calendar.getInstance();    
				c.add(Calendar.MONTH, 0);
				c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
				String first = mat.format(c.getTime());
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
				//获取当前月最后一天
				Calendar ca = Calendar.getInstance();    
				ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
				String last = mat.format(ca.getTime());
				endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
ilal committed
2363
		
Yl123 committed
2364
		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
ilal committed
2365
		
yuquan.zhu committed
2366 2367
		//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		if(attgro != null){//该员工是否加入到考勤组
ilal committed
2368
			 
yuquan.zhu committed
2369 2370
			if(attgro.getPbfs() == 1){//固定排班
				String yemo = year + "-" + month;
ilal committed
2371
				
yuquan.zhu committed
2372 2373
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2374
				
yuquan.zhu committed
2375
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
ilal committed
2376 2377
				
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					ScheduleAux ss = new ScheduleAux();
					ss.setId(0);
					ss.setUserid(userid);
					ss.setData(famt.format(da));
					ss.setBcid(0);
					ss.setKqzid(0);
ilal committed
2390
					
yuquan.zhu committed
2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
ilal committed
2417 2418
					
					
yuquan.zhu committed
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452
					//考勤打卡原始记录
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
					
ilal committed
2453
					int week = Integer.valueOf(dateToWeek(famt.format(da)));//2
yuquan.zhu committed
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496
				    AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
				    
				    if(atwek != null){//有固定周排班
			    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), famt.format(da));//查询打卡当天是否在特殊休息日期里面存在
			    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}else{//今天上班
				    		ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
				    		if(bcz != null){
				    			GetScheduleAux(bcz,ss,famt.format(da));
				    		}
			    		}
			    	}else{
			    		//必须打卡
			    		SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), famt.format(da));//判断特殊日期
			    		if(tsri != null){
			    			ShiftManagement tsrq = shiftmanagementservice.selectByPrimaryKey(tsri.getBcid());
			    			if(tsrq!=null){
			    				GetScheduleAux(tsrq,ss,famt.format(da));
			    			}
			    		}else{
			    			//休息
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}
			    	}
					dss.add(ss);
				}
ilal committed
2497
				
yuquan.zhu committed
2498
				return ResultUtil.data(dss);
ilal committed
2499 2500
				
				
yuquan.zhu committed
2501
			}else if(attgro.getPbfs() == 2){//自由排班
ilal committed
2502
				
yuquan.zhu committed
2503 2504 2505 2506
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<ScheduleAux> callist = scheduleservice.getCalendarAttendance(userid);//排班详细数据
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2507
				
yuquan.zhu committed
2508
				String[] array1 = new String[callist.size()];
ilal committed
2509
				
yuquan.zhu committed
2510
				String[] erinnern1 = new String[rltilist.size()];
ilal committed
2511
				
yuquan.zhu committed
2512
				int r = 0;
ilal committed
2513
				
yuquan.zhu committed
2514 2515 2516 2517 2518 2519 2520 2521 2522
				for(ScheduleAux sdu : callist){//2019-11-01
					ScheduleAux ss = new ScheduleAux();
					ss.setId(sdu.getId());
					ss.setUserid(sdu.getUserid());
					ss.setData(sdu.getData());
					ss.setBcid(sdu.getBcid());
					ss.setKqzid(sdu.getKqzid());
					array1[r] = sdu.getData();
					r++;
ilal committed
2523
					
yuquan.zhu committed
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					int q = 0; 
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = sdu.getData();//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						
						System.out.println(q+"--"+punchtime);
						
						erinnern1[q] = punchtime;
						q++;
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
ilal committed
2559
//						String schetime = mat.format(new Date(sdu.getData().toString()));//排班详细数据日期
yuquan.zhu committed
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589
						String schetime = sdu.getData();//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
ilal committed
2590 2591
					
					
yuquan.zhu committed
2592
					ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(sdu.getBcid());
ilal committed
2593 2594
					
					/*********/
yuquan.zhu committed
2595 2596 2597 2598 2599 2600 2601 2602
					List<AttSchedule> atts = new ArrayList<AttSchedule>();
					if(shifs != null){
						if(shifs.getSxbcs() == 1 || shifs.getSxbcs() == 2 || shifs.getSxbcs() == 3){//1次上下班
							for(int o=0;o<2;o++){
								if(o==0){
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(1);
ilal committed
2603 2604 2605
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk1(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks1(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs1(),2)+":00")));
yuquan.zhu committed
2606 2607 2608 2609 2610
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(2);
ilal committed
2611 2612 2613
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk1(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks1(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs1(),2)+":00")));
yuquan.zhu committed
2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624
									atts.add(as);
								}
							}
							ss.setAttsch(atts);
						}
						if(shifs.getSxbcs() == 2 || shifs.getSxbcs() == 3){//2次上下班
							for(int o=0;o<2;o++){
								if(o==0){
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(3);
ilal committed
2625 2626 2627
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk2(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks2(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs2(),2)+":00")));
yuquan.zhu committed
2628 2629 2630 2631 2632
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(4);
ilal committed
2633 2634 2635
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk2(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks2(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs2(),2)+":00")));
yuquan.zhu committed
2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
									atts.add(as);
								}
							}
							ss.setAttsch(atts);
						}
						if(shifs.getSxbcs() == 3){//3次上下班
							for(int o=0;o<2;o++){
								if(o==0){
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(5);
ilal committed
2647 2648 2649
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk3(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks3(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs3(),2)+":00")));
yuquan.zhu committed
2650 2651 2652 2653 2654
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(6);
ilal committed
2655 2656 2657
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk3(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks3(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs3(),2)+":00")));
yuquan.zhu committed
2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673
									atts.add(as);
								}
							}
							ss.setAttsch(atts);
						}
					}else{
						List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
		    			AttSchedule as = new AttSchedule();
		    			as.setId(0);
			    		as.setSort(0);//0:表示今天为休息日
			    		as.setTime(0l);
			    		as.setStarttime(0l);
			    		as.setEndtime(0l);
			    		atts1.add(as);
			    		ss.setAttsch(atts1);
					}
ilal committed
2674 2675
					/*******/
					
yuquan.zhu committed
2676 2677
					dss.add(ss);
				}
ilal committed
2678
				
yuquan.zhu committed
2679
				String yemo = year + "-" + month;
ilal committed
2680
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2681 2682 2683 2684 2685 2686
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
ilal committed
2687 2688 2689 2690
					
					
					
					
yuquan.zhu committed
2691
				}
ilal committed
2692 2693 2694 2695 2696 2697 2698
				
				
				
//				String[] array1 = {"2019-11-10","2019-11-12","2019-11-13"};  
//		        String[] array2 = {"2019-11-10","2019-11-14"};  
		        
				List<String> erilist = compare(array1,erinnern1);  //缺少的天数
yuquan.zhu committed
2699 2700
		        String[] eris=erilist.toArray(new String[erilist.size()]);//缺少的具体天数(yyyy-mm-dd)
		        
ilal committed
2701
		        String[] eridadys = array_unique(eris);
yuquan.zhu committed
2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737
		        
				for(int f=0;f<eridadys.length;f++){
					ScheduleAux ss = new ScheduleAux();
					ss.setId(0);
					ss.setUserid(userid);
					ss.setData(eridadys[f]);
					ss.setBcid(0);
					ss.setKqzid(0);
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = eridadys[f];//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					dss.add(ss);
				}
ilal committed
2738 2739 2740 2741 2742
				
				
				
				
				
yuquan.zhu committed
2743 2744 2745 2746 2747 2748
				//打卡记录
				List<PunchCardDetails> nosch = punchcarddetailsservice.selectNoScheduling(startDate,endDate,userid);//休息打卡和无排班打卡
				String[] array2 = new String[nosch.size()];
				for(int y=0;y<nosch.size();y++){//排班明细
					array2[y] = nosch.get(y).getData();
				}
ilal committed
2749 2750
				
				List<String> list = compare(array1,array2);  
yuquan.zhu committed
2751 2752 2753 2754 2755 2756 2757 2758
		        String[] dadys=list.toArray(new String[list.size()]);
				for(int g=0;g<dadys.length;g++){
					ScheduleAux ss = new ScheduleAux();
					ss.setId(0);
					ss.setUserid(userid);
					ss.setData(dadys[g]);
					ss.setBcid(0);
					ss.setKqzid(0);
ilal committed
2759
					
yuquan.zhu committed
2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
						String schetime = dadys[g];//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
					dss.add(ss);
				}
ilal committed
2794
				
yuquan.zhu committed
2795 2796 2797 2798
				return ResultUtil.data(dss);
				
			}else{//自由工时
				String yemo = year + "-" + month;
ilal committed
2799
				
yuquan.zhu committed
2800
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
ilal committed
2801
				
yuquan.zhu committed
2802 2803
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2804
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					ScheduleAux ss = new ScheduleAux();
					ss.setId(0);
					ss.setUserid(userid);
					ss.setData(famt.format(da));
					ss.setBcid(0);
					ss.setKqzid(0);
ilal committed
2817
					
yuquan.zhu committed
2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
ilal committed
2877 2878
					
					int week = Integer.valueOf(dateToWeek(famt.format(da)));//2
yuquan.zhu committed
2879
					AttendanceWeeklySch atwek = attendanceweeklyschservice.selectFreeWorkingHours(attgro.getId(),week);//自由工时
ilal committed
2880 2881
				    
						
yuquan.zhu committed
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909
				    if(atwek != null){//有固定周排班
			    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), famt.format(da));//查询打卡当天是否在特殊休息日期里面存在
			    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}
			    	}else{
			    		//必须打卡
			    		SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), famt.format(da));//判断特殊日期
			    		if(tsri == null){
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}
			    	}
ilal committed
2910
					
yuquan.zhu committed
2911 2912
					dss.add(ss);
				}
ilal committed
2913 2914 2915
				
				
				
yuquan.zhu committed
2916 2917 2918
				return ResultUtil.data(dss);
			}
		}
ilal committed
2919
		
yuquan.zhu committed
2920 2921 2922
		return ResultUtil.data(null);
	}
	 
ilal committed
2923 2924
//	 @GetMapping(value = "/ClockData")
//	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
2925 2926 2927 2928 2929 2930 2931
	/**
	 * 获取考勤打卡数据------APP打卡
	 */
	 @PostMapping(value = "/ClockData")
	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 49)
	 public Result<AttendanceCardList> getAttClockData(@CurrentUser UserBean userBean,@RequestBody AttConditions attconditions) {
ilal committed
2932
		 
yuquan.zhu committed
2933
		 AttendanceCardList attcar = new AttendanceCardList();
ilal committed
2934
		 
yuquan.zhu committed
2935 2936 2937 2938 2939 2940 2941 2942
		 String str = null;
		 if(!("").equals(attconditions.getDate())){
			 str = attconditions.getDate();
		 }else{
			 Date d = new Date();
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 str = sdf.format(d);
		 }
ilal committed
2943
		 
yuquan.zhu committed
2944 2945 2946 2947 2948 2949 2950 2951
		 Long startDate = 0l;
	     Long endDate = 0l;
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
ilal committed
2952 2953 2954 2955
		 
					 
				 
				 
yuquan.zhu committed
2956 2957
				 int qyid = userBean.getOrgCode();//坏小孩【企业id】
				 int userid = userBean.getEmpNum();//用户id	
ilal committed
2958 2959 2960 2961 2962 2963 2964
				 
		//		 QueryWrapper<YgglAttaHtxxb> queryWrapper = new QueryWrapper<>();
		//		 queryWrapper.eq("org_code",qyid).eq("emp_num", userid);
				 
				 
			     
			     
Yl123 committed
2965
			     AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
ilal committed
2966
			     
yuquan.zhu committed
2967 2968 2969 2970 2971
			     //pbfs:排班方式 1:固定排班;2:自由排班;3:自由工时
				 if(attgro != null){//判断当前用户是否加入到考勤组
					 //排班制
				     Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
				     //固定排班
ilal committed
2972
				     int week = Integer.valueOf(dateToWeek(str));//4
yuquan.zhu committed
2973 2974 2975
				     AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
					 
				    if(attgro.getPbfs() == 1){//固定排班
ilal committed
2976 2977
		//		    	int week = Integer.valueOf(dateToWeek(str));//4
		//		    	AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);
yuquan.zhu committed
2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026
				    	if(atwek != null){//有固定周排班
				    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), str);//查询打卡当天是否在特殊休息日期里面存在
				    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
				    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts.add(as);
					    		attcar.setAttsch(atts);
				    		}else{//今天上班
					    		ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
					    		if(bcz != null){
					    			Getshiftinformationbatch(bcz,attcar,str);
					    		}
				    		}
				    	}else{
				    		//必须打卡
				    		SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), str);//判断特殊日期
				    		if(tsri != null){
				    			ShiftManagement tsrq = shiftmanagementservice.selectByPrimaryKey(tsri.getBcid());
				    			if(tsrq!=null){
				    				Getshiftinformationbatch(tsrq,attcar,str);
				    			}
				    		}else{
				    			//休息
				    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts.add(as);
					    		attcar.setAttsch(atts);
				    		}
				    	}
				    	
					}else if(attgro.getPbfs() == 2){//自由排班
						
						//未排班时,员工可选择班次打卡
					    if(attgro.getIsXzbcdk() == 1){
					    	attcar.setOptscheduling(true);	
					    }else{
					    	attcar.setOptscheduling(false);
					    }
						
ilal committed
3027
		//				Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
yuquan.zhu committed
3028 3029 3030 3031 3032 3033 3034 3035 3036
						if(jrpb != null){
							List<AttSchedule> atts = new ArrayList<AttSchedule>();
							if(jrpb.getBcid() != 0){//有班次时("Bcid"不为0时)
								if(jrpb.getSxbcs() == 1 || jrpb.getSxbcs() == 2 || jrpb.getSxbcs() == 3){//1次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(1);
ilal committed
3037 3038 3039
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs1(),2)+":00")));
yuquan.zhu committed
3040 3041 3042 3043 3044
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(2);
ilal committed
3045 3046 3047
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs1(),2)+":00")));
yuquan.zhu committed
3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 2 || jrpb.getSxbcs() == 3){//2次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(3);
ilal committed
3059 3060 3061
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs2(),2)+":00")));
yuquan.zhu committed
3062 3063 3064 3065 3066
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(4);
ilal committed
3067 3068 3069
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs2(),2)+":00")));
yuquan.zhu committed
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 3){//3次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(5);
ilal committed
3081 3082 3083
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs3(),2)+":00")));
yuquan.zhu committed
3084 3085 3086 3087 3088
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(6);
ilal committed
3089 3090 3091
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs3(),2)+":00")));
yuquan.zhu committed
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
							}else{//当天排班为休息
								List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts1.add(as);
					    		attcar.setAttsch(atts1);
							}
						}else{//当天考勤组为给排班
							List<ShiftManagement> shifs = shiftmanagementservice.selectByPrimaryByQyid(qyid);
							List<SystemShift> akms = new ArrayList<SystemShift>();
							for(ShiftManagement ah:shifs){
								 SystemShift sys = new SystemShift();
								 sys.setId(ah.getId());
								 
								 String name = ah.getName();
								 String context = "";
								 if(ah.getSxbcs() == 1 || ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
ilal committed
3118
									 context = dealDateFormat(ah.getSbdk1(),2) + "-" + dealDateFormat(ah.getXbdk1(),2);
yuquan.zhu committed
3119 3120
								 }
								 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
ilal committed
3121
									 context = context +" "+ dealDateFormat(ah.getSbdk2(),2) + "-" + dealDateFormat(ah.getXbdk2(),2);
yuquan.zhu committed
3122 3123
								 }
								 if(ah.getSxbcs() == 3){
ilal committed
3124
									 context = context +" "+ dealDateFormat(ah.getSbdk3(),2) + "-" + dealDateFormat(ah.getXbdk3(),2);
yuquan.zhu committed
3125 3126 3127 3128 3129 3130 3131 3132 3133
								 }
								 sys.setContext(name+ " " + context);
								 
								 akms.add(sys);
						   }
						   attcar.setSsfh(akms);//无排班时 获取的系统班次
						}
				    	
					}else{//自由工时
ilal committed
3134 3135
						//int week = Integer.valueOf(dateToWeek(str));//4
						
yuquan.zhu committed
3136 3137 3138
						AttendanceWeeklySch wekz = attendanceweeklyschservice.WeeklyFreeRoster(attgro.getId(),week);
						if(wekz != null){//
							String dada = str+" "+attgro.getKqkssjTime()+":00";
ilal committed
3139
							attcar.setStapclotime(Long.valueOf(dateToStamp(dada)));
yuquan.zhu committed
3140 3141 3142 3143 3144
						}
						
						if(!("").equals(attgro.getJbzdsc())){
							attcar.setCanpunchworkdate(Double.valueOf(attgro.getJbzdsc()));//上班打卡后多久大下班卡
						}
ilal committed
3145 3146
						
						
yuquan.zhu committed
3147 3148 3149 3150 3151 3152 3153 3154
					}
				    if(jrpb != null || atwek != null){
				    	ShiftManagement shif = null;
				    	if(attgro.getPbfs() == 1){
				    		shif = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
				    	}else if(attgro.getPbfs() == 2){
				    		shif = shiftmanagementservice.selectByPrimaryKey(jrpb.getBcid());
				    	}
ilal committed
3155
				    	
yuquan.zhu committed
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257
				    	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 = new AttLateLate();
				    			ala.setLatewalk(shif.getXbwz1());
				    			ala.setArrivelate(shif.getSbwd1());
				    			atwzwd.add(ala);
				    			if(p == 4 || p == 6){
				    				AttLateLate alat = new AttLateLate();
				    				alat.setLatewalk(shif.getXbwz2());
				    				alat.setArrivelate(shif.getSbwd2());
				    				atwzwd.add(alat);
				    			}
				    			if(p == 6){
				    				AttLateLate alas = new AttLateLate();
				    				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:自由工时
				    
				    //外勤   true:开   false:关
				    if(attgro.getIsWq() == 1) {
				    	attcar.setFieldpersonnel(true);
				    }else {
				    	attcar.setFieldpersonnel(false);
				    }
				    
				    
					//打卡方式
				    List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodeservice.selectByPrimaryByKqzId(attgro.getId());
				    for(AttGroupBinPunchMode agbp:attmetlist){
				    	//类型(1:考勤机;2:地址;3:WIFI)
				    	if(agbp.getType() == 1){
				    		attcar.setAttmachine(true);
				    	}else if(agbp.getType() == 2){
				    		attcar.setAttaddress(true);
				    	}else{
				    		attcar.setAttwifi(true);
				    	}
				    }
				    
				    //详细打卡方式
				    List<AttClockMethod> akms = new ArrayList<AttClockMethod>();
				    
				    for(AttGroupBinPunchMode abp:attmetlist){
				    	if(abp.getType() == 1){
				    		AttendanceMachine kqjs = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqjs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(1);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
				    		akms.add(akm);
				    	}else if(abp.getType() == 2){
				    		PunchCardAddress kqdzs = punchcardaddressservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqdzs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(kqdzs.getDkfw());// 范围【地址】
				    		akm.setType(2);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(kqdzs.getLon());// 经度【地址】
				    		akm.setLatitude(kqdzs.getLat());// 纬度【地址】
				    		akms.add(akm);
				    	}else{
				    		PunchCardWiFi kqwfs = punchcardwifiservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqwfs.getName());// 打卡名称
				    		akm.setMac(kqwfs.getMac());// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(3);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
				    		akms.add(akm);
				    	}
				    }
				    attcar.setMachine(akms);
				    
				    
				 }else{
ilal committed
3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282
					 //无排班
					 //系统班次
		//			 List<ShiftManagement> shifs = shiftmanagementservice.selectByPrimaryByQyid(qyid);
		//			 List<SystemShift> akms = new ArrayList<SystemShift>();
		//			 for(ShiftManagement ah:shifs){
		//				 SystemShift sys = new SystemShift();
		//				 sys.setId(ah.getId());
		//				 
		//				 String name = ah.getName();
		//				 String context = "";
		//				 if(ah.getSxbcs() == 1 || ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
		//					 context = dealDateFormat(ah.getSbdk1(),2) + "-" + dealDateFormat(ah.getXbdk1(),2);
		//				 }
		//				 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
		//					 context = context +" "+ dealDateFormat(ah.getSbdk2(),2) + "-" + dealDateFormat(ah.getXbdk2(),2);
		//				 }
		//				 if(ah.getSxbcs() == 3){
		//					 context = context +" "+ dealDateFormat(ah.getSbdk3(),2) + "-" + dealDateFormat(ah.getXbdk3(),2);
		//				 }
		//				 sys.setContext(name+ " " + context);
		//				 
		//				 akms.add(sys);
		//			 }
		//			 attcar.setSsfh(akms);//无排班时 获取的系统班次
					 
yuquan.zhu committed
3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293
					 attcar.setAttgrouptype(0);//1:固定排班;2:自由排班;3:自由工时
				 }
				 
				//打卡记录
			    List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
			    attcar.setAttpr(dajllist);
				 
				 return ResultUtil.data(attcar);
				 
	 }
	
ilal committed
3294 3295 3296
	 /**
	  * ??????
	  */
yuquan.zhu committed
3297 3298 3299 3300 3301 3302 3303 3304
	 public void GetScheduleAux(ShiftManagement shiftm,ScheduleAux attcar,String str){
		 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 = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(1);
ilal committed
3305 3306 3307
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs1(),2)+":00")));
yuquan.zhu committed
3308 3309 3310 3311 3312
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
ilal committed
3313 3314 3315
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs1(),2)+":00")));
yuquan.zhu committed
3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//2次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(3);
ilal committed
3327 3328 3329
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs2(),2)+":00")));
yuquan.zhu committed
3330 3331 3332 3333 3334
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
ilal committed
3335 3336 3337
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs2(),2)+":00")));
yuquan.zhu committed
3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(5);
ilal committed
3349 3350 3351
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs3(),2)+":00")));
yuquan.zhu committed
3352 3353 3354 3355 3356
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
ilal committed
3357 3358 3359
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs3(),2)+":00")));
yuquan.zhu committed
3360 3361 3362 3363 3364 3365 3366 3367
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
	 

ilal committed
3368 3369 3370
	 /**
	  * ??????
	  */
yuquan.zhu committed
3371 3372 3373 3374 3375 3376 3377 3378
	 public void Getshiftinformationbatch(ShiftManagement shiftm,AttendanceCardList attcar,String str){
		 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 = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(1);
ilal committed
3379 3380 3381
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs1(),2)+":00")));
yuquan.zhu committed
3382 3383 3384 3385 3386
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
ilal committed
3387 3388 3389
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs1(),2)+":00")));
yuquan.zhu committed
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 2 || shiftm.getSxbcs() == 3){//2次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(3);
ilal committed
3401 3402 3403
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs2(),2)+":00")));
yuquan.zhu committed
3404 3405 3406 3407 3408
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
ilal committed
3409 3410 3411
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs2(),2)+":00")));
yuquan.zhu committed
3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(5);
ilal committed
3423 3424 3425
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs3(),2)+":00")));
yuquan.zhu committed
3426 3427 3428 3429 3430
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
ilal committed
3431 3432 3433
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs3(),2)+":00")));
yuquan.zhu committed
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
	 
	 /**
	   * 根据班次id获取班次信息
	   */
	 @GetMapping(value="/shiftdetails/{id}")
	 @ApiOperation(value = "获取班次详细数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
	 @ApiOperationSupport(order = 50)
	 public Result<ShiftDetails> getShiftDetails(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
	     
	     int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
		 
		 Date d = new Date();
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		 String str = sdf.format(d);
		 
		 Long startDate = 0l;
	     Long endDate = 0l;
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
Yl123 committed
3465
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503
		 Schedule ispbmx = scheduleservice.getCustomRoster(userid,str);//
		 if(ispbmx != null && attgro != null){//新增
			 Schedule ahe = new Schedule();
			 ahe.setId(ispbmx.getId());
			 ahe.setBcid(id);
			 scheduleservice.updateByPrimaryKeySelective(ahe);
		 }else if(ispbmx == null && attgro != null){//修改
			 CustomRosterSchedule ahe = new CustomRosterSchedule();
			 ahe.setUserid(userid);
			 ahe.setData(str);
			 ahe.setBcid(id);
			 ahe.setKqzid(attgro.getId());
			 scheduleservice.insertCustomRoster(ahe);
		 }
		 
		 /*****************************/
			//转换日期
			String data = str;
			
			Long startCorrDate = 0l;
			Long endCorrDate = 0l;
			try {
				startCorrDate = DateUtil.getStartTime(0,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
				endCorrDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
					e.printStackTrace();
			}
			
			//当天修改后的班次
			ShiftManagement banci = shiftmanagementservice.selectByPrimaryKey(id);
			Long sbdk1 = 0l;
			Long xbdk1 = 0l;
			Long sbdk2 = 0l;
			Long xbdk2 = 0l;
			Long sbdk3 = 0l;
			Long xbdk3 = 0l;
			if(banci != null){
				if(banci.getSxbcs()== 1 || banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
ilal committed
3504 3505
					sbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk1(),2)+":00"));
					xbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk1(),2)+":00"));
yuquan.zhu committed
3506 3507
				}
				if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
ilal committed
3508 3509
					sbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk2(),2)+":00"));
					xbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk2(),2)+":00"));
yuquan.zhu committed
3510 3511
				}
				if(banci.getSxbcs()== 3){
ilal committed
3512 3513
					sbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk3(),2)+":00"));
					xbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk3(),2)+":00"));
yuquan.zhu committed
3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533
				}
			}
			//之前打卡的班次
			PunchRecord mapuca = punchrecordservice.MaintenancePunchCard(startCorrDate,endCorrDate,userid);
			
			if(mapuca != null && !id.equals(mapuca.getBcid())){
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid);
				if(initial.size() > 0){
					RestMethod(initial,initial.get(0).getDkmxid());
				}
			}
			
			//当天的所有打卡记录
			List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid);
			PunchRecord minAttid = null;
			PunchRecord maxAttid = null;
			int dkmxid = 0;
			if(mapucalist.size() > 0){
				//最小值
		        minAttid = mapucalist.stream().min(Comparator.comparing(PunchRecord::getId)).get();
ilal committed
3534
//		        System.out.println(minAttid.getAttdate() +  "---min---" +minAttid.getId());
yuquan.zhu committed
3535 3536
				//最大值
				maxAttid = mapucalist.stream().max(Comparator.comparing(PunchRecord::getId)).get();
ilal committed
3537 3538
//		        System.out.println(maxAttid.getAttdate() +  "---max---" + maxAttid.getId());
				
yuquan.zhu committed
3539 3540 3541
				//对应打卡明细表id
				dkmxid = maxAttid.getDkmxid();
			}
ilal committed
3542
			
yuquan.zhu committed
3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236
			//当天有打卡记录且当天打卡班次和当前修改后的班次不匹配再进行重新维护
			if(mapuca != null && !id.equals(mapuca.getBcid())){
				if(banci != null){//修改后有班次打卡
					if(banci.getSxbcs() == 1){//修改后一天打两次
						if(mapucalist.size() > 2){/////当天打卡多条的话 取最开始打的卡和最后打的卡 作为新一轮的上下班考勤
							for(PunchRecord pre : mapucalist){/********/
								if(pre.getId() != minAttid.getId() && pre.getId() != maxAttid.getId()){//去除最大和最小 其他均改为“打卡无效:此记录已被更新”
									PunchRecord record = new PunchRecord();
									record.setId(pre.getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									if((pre.getSort())%2 > 0){//上班
										Long time = (pre.getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//上班应打卡时间
									}else{//下班
										Long time = (pre.getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setResults(0);// 打卡结果
										}else{
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//下班应打卡时间
									}
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}else{
									if(pre.getId() == minAttid.getId()){//上班
										PunchRecord record = new PunchRecord();
										record.setId(pre.getId());
										record.setType(1);//上班
										Long time = (pre.getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
									}else if(pre.getId() == maxAttid.getId()){//下班
										PunchRecord record = new PunchRecord();
										record.setId(pre.getId());
										record.setType(2);//下班
										Long time = (pre.getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);
										record.setBcid(banci.getId());//班次id
										record.setSort(2);
										punchrecordservice.updateByPrimaryKeySelective(record);
									}
								}
							}
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							//
							PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//上班
							PunchCardDetails max = new PunchCardDetails();
							max.setId(dkmxid);//需修改的明细id
							max.setXbdk1(maxdata.getDktime());
							max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
							
							Long woktimes = (maxdata.getDktime() - mindata.getDktime())/1000/60;
							max.setGzsc(Double.valueOf(woktimes));
							
							punchcarddetailsservice.updateByPrimaryKeySelective(max);
						}else{////
							PunchRecord mindataone = null;
							//当天打卡记录为1条
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							//当天打卡记录为2条
							if(maxAttid != null && minAttid.getId() != maxAttid.getId()){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());
								record.setType(2);//下班
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);
								record.setBcid(banci.getId());//班次id
								record.setSort(2);
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								PunchCardDetails max = new PunchCardDetails();
								max.setId(dkmxid);//需修改的明细id
								max.setXbdk1(maxdata.getDktime());
								max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
								
								Long woktimes = (maxdata.getDktime() - mindataone.getDktime())/1000/60;
								max.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(max);
							}
						}
					}else if(banci.getSxbcs() == 2){//修改后一天打四次
						if(mapucalist.size() > 4){//当天打卡多次
							String[] scstr= new String[3];
							for(int y=0;y<mapucalist.size();y++){
								if(y == 0){//上班
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
//									record.setType(1);//上班
									Long time = (mindata.getDktime() - sbdk1)/1000/60;
									if(time > 0){
										record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
										record.setResults(Integer.valueOf(time.toString()));// 打卡结果
									}else{
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}
									record.setAttime(sbdk1);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								if(y == 1 || y == 2){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									
									if((mapucalist.get(y).getSort())%2 == 0){//下班
										Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//下班应打卡时间
										
										scstr[0] = String.valueOf(mapucalist.get(y).getId());
									}else{//上班
										Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//上班应打卡时间
										
										scstr[1] = String.valueOf(mapucalist.get(y).getId());
									}
									
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								
								
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								if(mapucalist.get(y).getId() == maxdata.getId()){//下班
									PunchRecord record = new PunchRecord();
									
									record.setId(maxdata.getId());
									record.setType(2);//下班
									Long time = (maxdata.getDktime() - xbdk2)/1000/60;
									if(time > 0){
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}else{
										record.setStatus(4);
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
									record.setSort(4);
									record.setAttime(xbdk2);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
									
									scstr[2] = String.valueOf(maxdata.getId());
								}
								
								if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									record.setResults(0);// 打卡结果
									record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
							}
							
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							
							for(int t=0;t<scstr.length;t++){
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(scstr[t]));//单条打卡明细
								
								PunchCardDetails dkmx = new PunchCardDetails();
								dkmx.setId(dkmxid);//需修改的明细id
								if(t == 0){
									dkmx.setXbdk1(dtdkmx.getDktime());
									dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
								}else if(t == 1){
									dkmx.setSbdk2(dtdkmx.getDktime());
									dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
								}else{
									dkmx.setXbdk2(dtdkmx.getDktime());
									dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
								}
								Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
								dkmx.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
							}
							 
						}else{//打卡小于4次
							PunchRecord mindataone = null;
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							
							PunchCardDetails pcd = new PunchCardDetails();
							if(mapucalist.size() >= 2){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());//当天一条记录的id
								record.setType(2);
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
								pcd.setXbdk1(dtdkmx.getDktime());
								pcd.setXbdk1jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 3){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(2).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
								pcd.setSbdk2(dtdkmx.getDktime());
								pcd.setSbdk2jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 4){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(maxAttid.getId());//当天一条记录的id
								record.setType(2);
								Long time = (maxAttid.getDktime() - xbdk2)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
								pcd.setXbdk2(dtdkmx.getDktime());
								pcd.setXbdk2jg(dtdkmx.getResults());
							}
							
							pcd.setId(dkmxid);
							punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
						}
					}else if(banci.getSxbcs() == 3){//修改后一天打六次
						if(mapucalist.size() > 6){//当天打卡多次
							String[] lcstr= new String[5];
							for(int y=0;y<mapucalist.size();y++){
								if(y == 0){//上班
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									Long time = (mindata.getDktime() - sbdk1)/1000/60;
									if(time > 0){
										record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
										record.setResults(Integer.valueOf(time.toString()));// 打卡结果
									}else{
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}
									record.setAttime(sbdk1);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								if(y == 1 || y == 2 || y == 3 || y == 4){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									
									if((mapucalist.get(y).getSort())%2 == 0){//下班
										if(y == 1){
											Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setAttime(xbdk1);//下班应打卡时间
											lcstr[0] = String.valueOf(mapucalist.get(y).getId());
										}
										
										if(y == 3){
											Long time = (mapucalist.get(y).getDktime() - xbdk2)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setAttime(xbdk2);//下班应打卡时间
											lcstr[2] = String.valueOf(mapucalist.get(y).getId());
										}
										
									}else{//上班
										if(y == 2){
											Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
											if(time > 0){
												record.setStatus(3);
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk2);//上班应打卡时间
											lcstr[1] = String.valueOf(mapucalist.get(y).getId());
										}
										
										if(y == 4){
											Long time = (mapucalist.get(y).getDktime() - sbdk3)/1000/60;
											if(time > 0){
												record.setStatus(3);
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk3);//上班应打卡时间
											lcstr[3] = String.valueOf(mapucalist.get(y).getId());
										}
									}
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								
								
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								if(mapucalist.get(y).getId() == maxdata.getId()){//下班
									PunchRecord record = new PunchRecord();
									
									record.setId(maxdata.getId());
									record.setType(2);//下班
									Long time = (maxdata.getDktime() - xbdk3)/1000/60;
									if(time > 0){
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}else{
										record.setStatus(4);
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
									record.setSort(6);
									record.setAttime(xbdk3);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
									
									lcstr[4] = String.valueOf(maxdata.getId());
								}
								
								if(y == 5 || y > 5 && mapucalist.get(y).getId() != maxdata.getId()){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									record.setResults(0);// 打卡结果
									record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
							}
							
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							
							for(int t=0;t<lcstr.length;t++){
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(lcstr[t]));//单条打卡明细
								
								PunchCardDetails dkmx = new PunchCardDetails();
								dkmx.setId(dkmxid);//需修改的明细id
								if(t == 0){
									dkmx.setXbdk1(dtdkmx.getDktime());
									dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
								}else if(t == 1){
									dkmx.setSbdk2(dtdkmx.getDktime());
									dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
								}else if(t == 2){
									dkmx.setXbdk2(dtdkmx.getDktime());
									dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
								}else if(t == 3){
									dkmx.setSbdk3(dtdkmx.getDktime());
									dkmx.setSbdk3jg(dtdkmx.getResults());// 上班3打卡结果
								}else{
									dkmx.setXbdk3(dtdkmx.getDktime());
									dkmx.setXbdk3jg(dtdkmx.getResults());// 下班3打卡结果
								}
								Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
								dkmx.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
							}
						}else{
							/**aaa**/
							PunchRecord mindataone = null;
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							
							PunchCardDetails pcd = new PunchCardDetails();
							if(mapucalist.size() >= 2){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());//当天一条记录的id
								record.setType(2);
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
								pcd.setXbdk1(dtdkmx.getDktime());
								pcd.setXbdk1jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 3){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(2).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
								pcd.setSbdk2(dtdkmx.getDktime());
								pcd.setSbdk2jg(dtdkmx.getResults());
							}
							
							
							if(mapucalist.size() >= 4){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(3).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(3).getDktime() - xbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(xbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(3).getId());//单条打卡明细
								pcd.setXbdk2(dtdkmx.getDktime());
								pcd.setXbdk2jg(dtdkmx.getResults());
								
							}
							if(mapucalist.size() >= 5){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(4).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(4).getDktime() - sbdk3)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk3);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(4).getId());//单条打卡明细
								pcd.setSbdk3(dtdkmx.getDktime());
								pcd.setSbdk3jg(dtdkmx.getResults());
								
							}
							
							if(mapucalist.size() >= 6){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(maxAttid.getId());//当天一条记录的id
								record.setType(2);
								Long time = (maxAttid.getDktime() - xbdk3)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk3);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
								pcd.setXbdk3(dtdkmx.getDktime());
								pcd.setXbdk3jg(dtdkmx.getResults());
							}
							
							pcd.setId(dkmxid);
							punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
							/**bbb***/
						}
					}
				}else{////修改后班次为休息的
					RestMethod(mapucalist,dkmxid);
				}
			}
ilal committed
4237 4238 4239 4240
			
			/***********************/
		 
		 
yuquan.zhu committed
4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251
		 ShiftDetails shde = new ShiftDetails();
		 
		 ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(id);
		 if(shifs != null){
			 List<AttSchedule> atts = new ArrayList<AttSchedule>();
		    	if(shifs.getSxbcs() == 1 || shifs.getSxbcs() == 2 || shifs.getSxbcs() == 3){//1次上下班
		    		for(int o=0;o<2;o++){
		    			if(o==0){
			    			AttSchedule as = new AttSchedule();
			    			as.setId(shifs.getId());
				    		as.setSort(1);
ilal committed
4252 4253 4254
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk1(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks1(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs1(),2)+":00")));
yuquan.zhu committed
4255 4256 4257 4258 4259
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(2);
ilal committed
4260 4261 4262
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk1(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks1(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs1(),2)+":00")));
yuquan.zhu committed
4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273
				    		atts.add(as);
		    			}
		    		}
		    		shde.setAttsch(atts);
		    	}
		    	if(shifs.getSxbcs() == 2 || shifs.getSxbcs() == 3){//2次上下班
		    		for(int o=0;o<2;o++){
		    			if(o==0){
			    			AttSchedule as = new AttSchedule();
			    			as.setId(shifs.getId());
				    		as.setSort(3);
ilal committed
4274 4275 4276
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk2(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks2(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs2(),2)+":00")));
yuquan.zhu committed
4277 4278 4279 4280 4281
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(4);
ilal committed
4282 4283 4284
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk2(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks2(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs2(),2)+":00")));
yuquan.zhu committed
4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295
				    		atts.add(as);
		    			}
		    		}
		    		shde.setAttsch(atts);
		    	}
		    	if(shifs.getSxbcs() == 3){//3次上下班
		    		for(int o=0;o<2;o++){
		    			if(o==0){
			    			AttSchedule as = new AttSchedule();
			    			as.setId(shifs.getId());
				    		as.setSort(5);
ilal committed
4296 4297 4298
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk3(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks3(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs3(),2)+":00")));
yuquan.zhu committed
4299 4300 4301 4302 4303
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(6);
ilal committed
4304 4305 4306
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk3(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks3(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs3(),2)+":00")));
yuquan.zhu committed
4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363
				    		atts.add(as);
		    			}
		    		}
		    		shde.setAttsch(atts);
		    	}
			    	
	    		if(shifs.getIsXbdk() == 1){
	    			shde.setNoclockout(true);// 下班不用打卡
	    		}else{
	    			shde.setNoclockout(false);// 下班不用打卡
	    		}
	    		shde.setAllowlate(shifs.getYxcdfzs());// 允许迟到分钟数
	    		shde.setSeriouslate(shifs.getYzcdfzs());// 严重迟到分钟数
	    		shde.setAbsenteeismlate(shifs.getKgcdfzs());// 旷工迟到分钟数
	    		if(shifs.getIsWzwd() == 1){
	    			shde.setIslatelate(true);// 晚走晚到
	    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
	    			int p = 0;
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1())){p = 2;}
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1()) && !("").equals(shifs.getXbwz2()) && !("").equals(shifs.getSbwd2())){p = 4;}
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1()) && !("").equals(shifs.getXbwz2()) && !("").equals(shifs.getSbwd2()) && !("").equals(shifs.getXbwz3()) && !("").equals(shifs.getSbwd3())){p = 6;}
	    			AttLateLate ala = new AttLateLate();
	    			ala.setLatewalk(shifs.getXbwz1());
	    			ala.setArrivelate(shifs.getSbwd1());
	    			atwzwd.add(ala);
	    			if(p == 4 || p == 6){
	    				AttLateLate alat = new AttLateLate();
	    				alat.setLatewalk(shifs.getXbwz2());
	    				alat.setArrivelate(shifs.getSbwd2());
	    				atwzwd.add(alat);
	    			}
	    			if(p == 6){
	    				AttLateLate alas = new AttLateLate();
	    				alas.setLatewalk(shifs.getXbwz3());
	    				alas.setArrivelate(shifs.getSbwd3());
	    				atwzwd.add(alas);
	    			}
	    			shde.setAttlat(atwzwd);
	    		}else{
	    			shde.setIslatelate(false);// 晚走晚到
	    		}
		 }
		//打卡记录
	    List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
	    shde.setAttpr(dajllist);
		 
		return ResultUtil.data(shde);
	 }
	
	 /**
	 * @param clock
	 * @return 日历提醒
	 */
	 @PostMapping(value = "/Attendancecalendar")
	 @ApiOperation(value = "日历提醒", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 51)
	 public Result<CalendarAlarm> AttendanceCalendar(@CurrentUser UserBean userBean,@RequestBody ReminderAuxiliary remind) {
ilal committed
4364
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
yuquan.zhu committed
4365
		 int userid = userBean.getEmpNum();//用户id	
ilal committed
4366
		
yuquan.zhu committed
4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401
		CalendarAlarm cal = new CalendarAlarm();
		cal.setUserid(userid);// 用户id
		try {
			cal.setRemindtime(DateUtil.getStringTime(remind.getRemindtime(),"yyyy-MM-dd"));// 提醒时间
		} catch (ParseException e) {
			e.printStackTrace();
		}
		cal.setContent(remind.getContent());// 内容
		
		if(remind.getType().equals(1)){//新增
			cal.setState(0);// 状态(0:未完成,1:已完成,2:已过期)
			cal.setAddtime(new Date().getTime());// 添加时间
			if(calendaralarmservice.insertSelective(cal)>0){
				return ResultUtil.data(cal,"新增成功");
			}else{
				return ResultUtil.error("新增失败");
			}
		}else if(remind.getType().equals(2)){
			cal.setId(remind.getId());//
			if (calendaralarmservice.updateByPrimaryKeySelective(cal) > 0) {
				return ResultUtil.data(cal,"修改成功");
			}else {
				return ResultUtil.error("修改失败");	
			}
		}else{
			cal.setState(1);// 状态(0:未完成,1:已完成,2:已过期)
			cal.setId(remind.getId());//
			if (calendaralarmservice.updateByPrimaryKeySelective(cal) > 0) {
				return ResultUtil.data(cal,"标记成功");
			}else {
				return ResultUtil.error("标记失败");	
			}
		}
	 }
	 
ilal committed
4402
	 
yuquan.zhu committed
4403 4404 4405 4406 4407 4408 4409
	/**
	 * 	删除日历提醒信息
	 */
	@DeleteMapping(value = "/CalendarAlarm/{id}")
	@ApiOperation(value = "删除日历提醒信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 52)
	public Result<Integer> deleteCalendarAlarm(@PathVariable("id") Integer id) {
ilal committed
4410
		
yuquan.zhu committed
4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425
		if (calendaralarmservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	 
	 /**
	  * 	考勤打卡------APP打卡
	  */
	 @PostMapping(value = "/AttendanceCard")
	 @ApiOperation(value = "考勤打卡------APP打卡", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 53)
	 public Result<Void> AttendanceCard(@CurrentUser UserBean userBean,@RequestBody ClockCollectData clock) {
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
ilal committed
4426
		 
Yl123 committed
4427
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
4428
		 //pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
ilal committed
4429
		 
yuquan.zhu committed
4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738
	     String putime = new SimpleDateFormat("yyyy-MM-dd").format(Double.valueOf(clock.getPunchtime()));//转换打卡时间格式
		 Long startDate = 0l;//打卡当天开始时间
	     Long endDate = 0l;//打卡当天结束时间
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
		 ShiftManagement shif = null;
		 if(clock.getShifid() > 0){//有无班次
			 shif = shiftmanagementservice.selectByPrimaryKey(clock.getShifid());
		 }
		 
		 int dkmx = 0;
		 PunchCardDetails dkmc = punchcarddetailsservice.SingleAttendanceDays(userid,startDate,endDate);//查询打卡当天是否有记录
		 
		 if(dkmc != null){//有记录就修改之前的
			//修改
			 dkmx = dkmc.getId();
			 PunchCardDetails pcd = new PunchCardDetails();
			 if(clock.getType() == 1){
				 if(clock.getDiffer() == 1){//打卡
					 if(!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null){
						 return ResultUtil.error("重复打卡");
					 }
				 }else{//更新打卡
					 pcd.setId(dkmc.getId());
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
					 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
				 }
				 
			 }else if(clock.getType() == 2){
				 if(("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() == null){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else{

					if(clock.getDiffer() == 1){//打卡
						return ResultUtil.error("重复打卡");
					}else{//更新打卡
						pcd.setId(dkmc.getId());
						pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
						if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							if(time > 0){
								 pcd.setXbdk1jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
							 }
						}
						//班次为2次时,计算工作时长
						if(dkmc.getSbdk1() != null){
							Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
							pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
						}
						punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					}
				 }
				 //班次为2次时,计算工作时长
				 if(dkmc.getSbdk1() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
					 pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
				 }
			 }else if(clock.getType() == 3){
				 if(("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() == null){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
						 }else{
							pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
							 }else{
								pcd.setSbdk2jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 4){
				 if(("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() == null){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
						 }
						 
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk2jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
							 }
						 }
						 //班次为4次时,计算工作时长
						 if(dkmc.getSbdk2() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为4次时,计算工作时长
				 if(dkmc.getSbdk2() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }else if(clock.getType() == 5){
				 if(("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() == null){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
							 }else{
								 pcd.setSbdk3jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 6){
				 if(("").equals(dkmc.getXbdk3()) || dkmc.getXbdk3() == null){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk3jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
							 }
						 }
						 //班次为6次时,计算工作时长
						 if(dkmc.getSbdk3() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为6次时,计算工作时长
				 if(dkmc.getSbdk3() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }
			 pcd.setId(dkmc.getId());
			 if(clock.getType() <= 6){
				 int update = punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
			 }
			 
		 }else{//没有数据就新增一条数据
			 //新增
			 if(clock.getDiffer() == 1){//打卡
				 PunchCardDetails pcd = new PunchCardDetails();
				 pcd.setUserid(userid);
				 pcd.setData(putime);//打卡日期(yyyy-MM-dd)
				 if(clock.getType() == 1){
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							 pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 2){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else if(clock.getType() == 3){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 4){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }else if(clock.getType() == 5){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 6){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }
				 if(shif != null){
					 pcd.setYdkcs(shif.getSxbcs()*2);//应打卡次数
				 }
				 pcd.setQyid(qyid);//企业id
				 pcd.setDksj(startDate);//打卡时间
				 
				 punchcarddetailsservice.insertSelective(pcd);
				 
				 dkmx = pcd.getId();
			 }
		 }
ilal committed
4739 4740 4741
		 
		 
		 
yuquan.zhu committed
4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754
		 //打卡记录
		 if(clock.getDiffer() == 2){//更新打卡 
			PunchRecord punch = punchrecordservice.selectPunchResults(startDate,endDate,userid,clock.getType());
			if(punch != null){
				PunchRecord pr = new PunchRecord();
				pr.setId(punch.getId());
				pr.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:补卡 4:请假)
				pr.setSort(0);//序号(0:打卡无效:此记录已被更新)
				punchrecordservice.updateByPrimaryKeySelective(pr);
			}else{
				return ResultUtil.error("打卡失败");
			}
		 }
ilal committed
4755
		
yuquan.zhu committed
4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817
		PunchRecord pre = new PunchRecord();
		pre.setDktime(Long.valueOf(clock.getPunchtime()));// 打卡时间
		if(clock.getPunchcardtype() == 1){
			pre.setLon(Double.valueOf(clock.getLon()));// 经度
			pre.setLat(Double.valueOf(clock.getLat()));// 纬度
			pre.setAddress(clock.getAddress());// 定位地址
		}
		
		Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
		if(("0").equals(clock.getPunchcardtime())){
			pre.setResults(0);// 打卡结果
		}else{
			if((clock.getType())%2 > 0){//上班
				if(time > 0){
					pre.setResults(Integer.valueOf(time.toString()));// 打卡结果
				}else{
					pre.setResults(0);// 打卡结果
				}
			}else{//下班
				if(time > 0){
					pre.setResults(0);// 打卡结果
				}else{
					pre.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
				}
			}
		}
		
		pre.setUserId(userid);// 用户id
		if((clock.getType())%2 > 0){
			pre.setType(1);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time > 0){
					pre.setStatus(3);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}else{
			pre.setType(2);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time < 0){
					pre.setStatus(4);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}
		pre.setSort(clock.getType());// 序号
		pre.setCardType(clock.getPunchcardtype());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
		if(clock.getPunchcardtype() == 2){
			pre.setMac(clock.getMac());// mac地址
			pre.setMacname(clock.getMacname());// WIFI名称
		}
		pre.setQyid(qyid);// 企业id
		String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
ilal committed
4818
		pre.setAttdate(attdate_+" "+dateToWeek2(putime));// 考勤日期
yuquan.zhu committed
4819 4820 4821 4822 4823 4824 4825
		
		long date = new Date().getTime();
		if(("0").equals(clock.getPunchcardtime())){
			pre.setAttime(date);// 考勤时间(应打卡时间)	
		}else{
			pre.setAttime(Long.valueOf(clock.getPunchcardtime()));// 考勤时间(应打卡时间)
		}
ilal committed
4826
		
yuquan.zhu committed
4827 4828 4829
		pre.setDkmxid(dkmx);// 打卡明细id
		pre.setBcid(clock.getShifid());// 班次id
		punchrecordservice.insertSelective(pre);//新增打卡记录
ilal committed
4830 4831 4832 4833
			
		 
		 
//		if(shiftmanagementservice.insertSelective(shif)>0){
yuquan.zhu committed
4834
			return ResultUtil.data(null,"打卡成功");
ilal committed
4835 4836 4837
//		}else{
//			return ResultUtil.error("新增班次失败");
//		}
yuquan.zhu committed
4838 4839
	 }
	
ilal committed
4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986
	 /************************************************************************************************************************************/
	 /***************************************************工具方法区***************************************************************************/
	 /************************************************************************************************************************************/
	 /**
	 * 时间转换时间戳
	 */
	public static String dateToStamp(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
		try {
			date = simpleDateFormat.parse(s);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }
	
	/**
	 * 2019-10-24T00:30:23.000Z 转化时间
	 */
	public String dealDateFormat(String oldDateStr,int num) {
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); // yyyy-MM-dd'T'HH:mm:ss.SSSZ
			Date date = null;
			try {
				date = df.parse(oldDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			SimpleDateFormat df1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
			Date date1 = null;
			try {
				date1 = df1.parse(date.toString());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			DateFormat df2 = null;
			if(num == 1){
				df2 = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss");
			}else if(num == 2){
				df2 = new SimpleDateFormat("HH:mm");
			}
			
			return df2.format(date1);
	}
	/**
     * 根据日期获取 星期 (2019-05-06 ——> 星期一)
     * @param datetime
     * @return
     */
    public static String dateToWeek(String datetime) {

        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
//        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"};
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = f.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //一周的第几天
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }
    
    public static String dateToWeek2(String datetime) {

        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
//        String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"};
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = f.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //一周的第几天
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }
	
    
    /**
	 * 获取月份起始日期
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public String getMinMonthDate(String date) throws ParseException {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(famt.parse(date));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return famt.format(calendar.getTime());
	}

	/**
	 * 获取月份最后日期
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public String getMaxMonthDate(String date) throws ParseException {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(famt.parse(date));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return famt.format(calendar.getTime());
	}
	
	/**
	 * 对比两个字符串数组
	 * @param t1
	 * @param t2
	 * @return
	 */
	public static <T> List<T> compare(T[] t1, T[] t2) {    
	      List<T> list1 = Arrays.asList(t1); //将t1数组转成list数组   
	      List<T> list2 = new ArrayList<T>();//用来存放2个数组中不相同的元素    
	      for (T t : t2) {    
	          if (!list1.contains(t)) {    
	              list2.add(t);    
	          }    
	      }    
	      return list2;    
	  }
	
	public static String[] array_unique(String[] ss) {
		Set<String> set=new HashSet<String>(Arrays.asList(ss));
		return set.toArray(new String[set.size()]);
		//或者return new HashSet<String>(Arrays.asList(ss)).toArray(new String[0]);
	}
	
	
yuquan.zhu committed
4987 4988 4989
	/**
	 * 	考勤机一键同步
	 */
lal committed
4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010
//	@GetMapping(value="/synchroni/{id}")
//	@ApiOperation(value = "考勤机一键同步", httpMethod = "GET", notes = "接口发布说明")
//	@ApiOperationSupport(order = 54)
//	public Result<AttemacDto> synchroni(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
//		Integer orgCode = userBean.getOrgCode();
//		
//		List<UserAttendanceRel> member = userattendancerelservice.selectAttNotMember(id,orgCode);
//		
//		AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(id);//查询考勤机“序列号”
//		
//		for(UserAttendanceRel usmer:member) {
//			
//			YgglMainEmp user = new LambdaQueryChainWrapper<YgglMainEmp>(ygglmainempmapper).eq(YgglMainEmp::getEmpNum, usmer.getUserid())
//					.eq(YgglMainEmp::getOrgCode, orgCode).one();
//			
//			JSONObject vResultJson = new JSONObject();
//			vResultJson.put("user_id", usmer.getUserid());
//			vResultJson.put("user_name", user.getName());
//			vResultJson.put("user_privilege", "USER");
//			String sFinal = vResultJson.toString();
//			
lal committed
5011
//			String url = mac_command;
lal committed
5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036
//	        HttpHeaders headers = new HttpHeaders();
//	        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
//	        params.add("cmd", "SET_USER_INFO");
//	        params.add("devid", kqj.getCode());
//	        params.add("json", sFinal);
//	        RestTemplate restTemplate = new RestTemplate();
//	        HttpEntity httpEntity = new HttpEntity(params, headers);
//	        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
//	        
//	        
//	        
//	      //用户与设备关系(考勤机id-->用户id)
//			UserEquiRelation uskqj = new UserEquiRelation();
//			uskqj.setUserId(usmer.getUserid());//用户id
//			uskqj.setKqjid(kqj.getId());//设备id
//			uskqj.setType(1);//类型(类型 1:考勤机)
//			uskqj.setIsGly(0);
//			
//			userequirelationmapper.insert(uskqj);
//	        
//		}
//		
//		return ResultUtil.success("成功");
//	}
//	
yuquan.zhu committed
5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064
	/**
	 * 	获取报表汇总
	 */
	@PostMapping(value = "/reportsummary")
	@ApiOperation(value = "获取报表汇总", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 56)
	public Result<List<AttendanceReport>> ReportSummary(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
		
			//考勤报表列表
			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
			
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH) + 1;
			int date = cal.get(Calendar.DATE);
			
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    String str = sdf.format(d);
			
			Long startDate = 0l;
			Long endDate = 0l;
			
			if(!("").equals(attendancedetails.getStart())){
			   try {
ilal committed
5065
				   String sdaet = getMinMonthDate(attendancedetails.getStart());
yuquan.zhu committed
5066 5067
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
ilal committed
5068
				   String edate = getMaxMonthDate(attendancedetails.getEnd());
yuquan.zhu committed
5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125
				   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else{
				try {
					Calendar c = Calendar.getInstance();    
					c.add(Calendar.MONTH, 0);
					c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
					String first = mat.format(c.getTime());
					startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
					//获取当前月最后一天
					Calendar ca = Calendar.getInstance();    
					ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
					String last = mat.format(ca.getTime());
					endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			
			
			List<YgglMainEmp> attoff = attendancegroupservice.selectAttendanceOfficer(String.valueOf(qyid),attendancedetails.getText());//获取公司人员
			
			for(YgglMainEmp kqry : attoff){
				
				int gzsc = punchcarddetailsservice.selectWorkingHours(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
				
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,Integer.valueOf(kqry.getEmpNum()));
				int latenum = 0;// 迟到次数
				int latehours = 0;// 迟到时长
				int leanum = 0;// 早退次数
				int leahours = 0;// 早退时长
				if(initial.size() > 0){
					for(PunchRecord prd : initial){
						if(prd.getType() == 1 && prd.getResults() > 0){
							latenum++;
							latehours += prd.getResults();
						}
						if(prd.getType() == 2 && prd.getResults() > 0){
							leanum++;
							leahours += prd.getResults();
						}
					}
				}
				
				AttendanceReport apr = new AttendanceReport();
				apr.setId(Integer.valueOf(kqry.getEmpNum()));
				apr.setName(kqry.getName());//姓名
				apr.setJobnumber(kqry.getEmpNum());//工号
				apr.setWorkhours(gzsc);//工作时长
				
				apr.setLatenum(latenum);//
				apr.setLatehours(latehours);//
				apr.setLeanum(leanum);//
				apr.setLeahours(leahours);//
				/**********/
Yl123 committed
5126
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
yuquan.zhu committed
5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164
				//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
				if(attgro != null){//该员工是否加入到考勤组
					if(attgro.getPbfs() == 1){
						//当前月     必须打卡日期
						List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						int bxdk = bxdklist.size();
						//当前月     无需打卡日期
						List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						String[] appmaps= new String[wxdk.size()];
						int d1 = 0;
						for(SpecialDate spe:wxdk){
							appmaps[d1] = spe.getTsrq();
							d1++;
						}
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						int q = 0;
ilal committed
5165
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183
							 try {
								Date date1 = sdf1.parse(yemo + "-" + i);
								for(int u=0;u<week.length;u++){
									if(sdf2.format(date1).equals(week[u])){
										
										q++;
										
										y++;
										if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
											y = y-1;
										}
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
ilal committed
5184
						 int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
yuquan.zhu committed
5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y+bxdk);//应出勤
						/***********/
					}else if(attgro.getPbfs() == 2){
						List<Schedule> ycqs = scheduleservice.getAttendanceShouldList(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
						int xiuxi = 0;
						int shangban = 0;
						for(Schedule sc : ycqs){
							if(sc.getBcid().equals(0)){
								xiuxi++;
							}else{
								shangban++;
							}
						}
	//					System.out.println(xiuxi);
						apr.setRestday(xiuxi);//休息天数
						apr.setAnswerday(shangban);//应出勤
					}else{
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
ilal committed
5226
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238
							 try {
								Date date1 = sdf1.parse(yemo + "-" + i);
								for(int u=0;u<week.length;u++){
									if(sdf2.format(date1).equals(week[u])){
										y++;
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
ilal committed
5239
						 int xiuxi = getDaysByYearMonth(year,month) - y;
yuquan.zhu committed
5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y);//应出勤
					}
				    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate);//打卡记录
				    apr.setActualday(attendance.size());//已出勤
					if(apr.getAnswerday() > 0){
						BigDecimal g = new BigDecimal(apr.getAnswerday());  
						BigDecimal h = new BigDecimal(apr.getActualday()); 
						int lack = g.subtract(h).intValue();  
						apr.setMinerday(lack);//缺勤
					}
		            int sbqk = 0;
		            int xbqk = 0;
		            for(PunchCardDetails pcd:attendance){
		            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk1() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk1() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk2() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk2() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk3() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk3() == null){
		            			xbqk++;
		            		}
		            	}
		            }
		            apr.setGoworkmissingcard(sbqk);//上班缺卡
		            apr.setOffworkmissingcard(xbqk);//下班缺卡
				}
ilal committed
5282 5283 5284 5285
				/**********/
				
				
				
yuquan.zhu committed
5286 5287
				attrep.add(apr);
			}
ilal committed
5288 5289 5290
			
			
//			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
yuquan.zhu committed
5291 5292 5293 5294
			int attshouldmade = 0;//应出勤
			for(AttendanceReport reps:attrep) {
				System.out.println(reps.getAnswerday());
			}
ilal committed
5295 5296 5297
			
			
			
yuquan.zhu committed
5298 5299 5300
			return ResultUtil.data(attrep);
	}
}