AttController.java 209 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
	@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");
lal committed
167

yuquan.zhu committed
168 169
	
	
ilal committed
170
	/*********考勤机***********/
yuquan.zhu committed
171 172 173 174 175 176 177 178 179 180
	/*********打卡地址***********/
	/**
	 * 获取打卡地址数据
	 */
	@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
181
			
yuquan.zhu committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
			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
197
			
yuquan.zhu committed
198 199 200 201 202
			PageHelper.startPage(pageNum, pageSize);
			List<PunchCardWiFi> shiftList = punchcardwifiservice.selectByPrimaryByQyid(qyid);
			PageInfo<PunchCardWiFi> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
ilal committed
203 204

	/**************************************************************考勤组********************************************************************/
yuquan.zhu committed
205
	
ilal committed
206 207
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
yuquan.zhu committed
208 209
	
	/**
ilal committed
210
	 * 	查询列表-考勤组-分页【新】
yuquan.zhu committed
211
	 */
ilal committed
212
	@PostMapping(value = "/attendance_group")
lal committed
213
	@ApiOperation(value = "34:查询列表-考勤组-分页-分页", httpMethod = "POST", notes = "查询列表-考勤组-分页-分页")
ilal committed
214 215 216 217 218 219 220 221 222 223 224
	@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
225 226 227 228 229 230 231 232 233 234 235 236
	}
	
	/**
	 * 获取考勤组数据
	 */
	@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
237
			
yuquan.zhu committed
238 239 240 241 242 243 244 245 246 247 248 249 250
			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
251
			
yuquan.zhu committed
252
			kqzattendancegroupsearch.setQyid(qyid);
ilal committed
253
			
yuquan.zhu committed
254 255
			List<AttendanceGroup> attgrlist = attendancegroupservice.selectKqglMainKqzByQuery(kqzattendancegroupsearch);
	
ilal committed
256
			return ResultUtil.data(attgrlist);
yuquan.zhu committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
	}
	
	/**
	 * 获取修改的排班明细--【修改考勤组】--------------------------------------------------------------------------------------
	 */
	@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){
lal committed
352 353
							sbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk1()+":00"));
							xbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk1()+":00"));
yuquan.zhu committed
354 355
						}
						if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
lal committed
356 357
							sbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk2()+":00"));
							xbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk2()+":00"));
yuquan.zhu committed
358 359
						}
						if(banci.getSxbcs()== 3){
lal committed
360 361
							sbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk3()+":00"));
							xbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk3()+":00"));
yuquan.zhu committed
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 431 432 433 434 435 436 437 438 439 440 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
						}
					}
					//之前打卡的班次
					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
1187
	public Result<List<YgglMainEmp>> getAttReminderStaff(@PathVariable("id") Integer id,@CurrentUser UserBean userBean) {
yuquan.zhu committed
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
		
		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
1200
				YgglMainEmp txyg = attendancegroupservice.selectByPrimaryByempNum(Integer.valueOf(launchsArray[i]),userBean.getOrgCode());
yuquan.zhu committed
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 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 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
				
				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
1344
			attgro.setOvertimeRulesId(attass.getOvertimeRulesId());//加班规则ID
yuquan.zhu committed
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 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
			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
1442 1443
						
						YgglMainEmp yggluser = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()).eq(YgglMainEmp::getEmpNum, attser[u]));
lal committed
1444
						String url = mac_command+"/addUserName";
yuquan.zhu committed
1445 1446
				        HttpHeaders headers = new HttpHeaders();
				        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
lal committed
1447 1448 1449
				        params.add("devId", kqj.getCode());
				        params.add("userId", attser[u]);
				        params.add("userName", yggluser.getName());
yuquan.zhu committed
1450 1451 1452
				        RestTemplate restTemplate = new RestTemplate();
				        HttpEntity httpEntity = new HttpEntity(params, headers);
				        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
lal committed
1453 1454 1455
				        System.err.print(request.getBody());
						
						
yuquan.zhu committed
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 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
					}
					/*****************************************************************************/
				}
			}
			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
1552 1553 1554
			
			
	//		if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
yuquan.zhu committed
1555
				return ResultUtil.data(null,"修改考勤组信息成功");
ilal committed
1556 1557
	//		}
	//		return ResultUtil.error("修改考勤组信息失败");
yuquan.zhu committed
1558 1559 1560 1561
	}
	
	/*******考勤组--结束*********/

ilal committed
1562 1563 1564 1565 1566 1567
	
	/***********APP--调用接口开始*****************/
	
	
//	@GetMapping(value="/attendancereport")
//	@ApiOperation(value = "获取考勤报表数据", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
1568 1569 1570 1571 1572 1573 1574
	/**
	 * 获取考勤报表数据
	 */
	@PostMapping(value = "/attendancereport")
	@ApiOperation(value = "获取考勤报表数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 41)
	public Result<List<AttendanceReport>> getAttendanceReport(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
ilal committed
1575 1576
		
		
yuquan.zhu committed
1577 1578
			//考勤报表列表
			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
ilal committed
1579
			
yuquan.zhu committed
1580
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
ilal committed
1581 1582
			int userid = userBean.getEmpNum();//用户id	
			
yuquan.zhu committed
1583 1584 1585 1586
			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
1587
			
yuquan.zhu committed
1588 1589 1590
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    String str = sdf.format(d);
ilal committed
1591
			
yuquan.zhu committed
1592 1593
			Long startDate = 0l;
			Long endDate = 0l;
ilal committed
1594
			
yuquan.zhu committed
1595 1596
			if(!("").equals(attendancedetails.getStart())){
			   try {
lal committed
1597
				   String sdaet = ClockInTool.getMinMonthDate(attendancedetails.getStart());
yuquan.zhu committed
1598 1599
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
lal committed
1600
				   String edate = ClockInTool.getMaxMonthDate(attendancedetails.getEnd());
yuquan.zhu committed
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620
				   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
1621 1622
			
			
yuquan.zhu committed
1623
			List<YgglMainEmp> attoff = attendancegroupservice.selectAttendanceOfficer(String.valueOf(qyid),attendancedetails.getText());//获取公司人员
ilal committed
1624
			
yuquan.zhu committed
1625
			for(YgglMainEmp kqry : attoff){
ilal committed
1626
				
yuquan.zhu committed
1627
				int gzsc = punchcarddetailsservice.selectWorkingHours(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
ilal committed
1628
				
yuquan.zhu committed
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
				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
1646
				
yuquan.zhu committed
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
				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
1657
				/**********/
Yl123 committed
1658
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
yuquan.zhu committed
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
				//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++;
						}
lal committed
1673
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),kqry.getOrgCode());
yuquan.zhu committed
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
						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
1697
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
							 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
1716
						 int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
yuquan.zhu committed
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730
						 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
1731
	//					System.out.println(xiuxi);
yuquan.zhu committed
1732 1733 1734
						apr.setRestday(xiuxi);//休息天数
						apr.setAnswerday(shangban);//应出勤
					}else{
lal committed
1735
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),kqry.getOrgCode());
yuquan.zhu committed
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
						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
1758
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
							 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
1771
						 int xiuxi = getDaysByYearMonth(year,month) - y;
yuquan.zhu committed
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
						 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
1814 1815 1816 1817
				/**********/
				
				
				
yuquan.zhu committed
1818 1819
				attrep.add(apr);
			}
ilal committed
1820 1821
			
			
yuquan.zhu committed
1822 1823 1824
			return ResultUtil.data(attrep);
	}
	
ilal committed
1825 1826 1827 1828 1829
	
	
	
	
	
yuquan.zhu committed
1830 1831 1832 1833 1834 1835 1836 1837
	/**
	 * 获取考勤详情
	 */
	@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
1838 1839
			int userid = userBean.getEmpNum();//用户id	
			
yuquan.zhu committed
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855
			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
1856
			
yuquan.zhu committed
1857
			List<PunchCardDetails> attdetails = punchcarddetailsservice.SelectAttendanceDetails(qyid,starttime,endtime);
ilal committed
1858 1859
			
			
yuquan.zhu committed
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870
			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
1871
			int userid = userBean.getEmpNum();//用户id	
yuquan.zhu committed
1872
			attendancedetails.setQyid(qyid);
ilal committed
1873
			
yuquan.zhu committed
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
			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
1889 1890
			
			
yuquan.zhu committed
1891
			List<PunchCardDetails> kqxqlist = punchcarddetailsservice.QueryAttendanceDetails(attendancedetails);
ilal committed
1892
	
yuquan.zhu committed
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
			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
1904 1905
			int userid = userBean.getEmpNum();//用户id
			
yuquan.zhu committed
1906
			List<PunchRecord> origattreclist = punchrecordservice.selectOriginalAttendanceRecord(qyid);
ilal committed
1907
	
yuquan.zhu committed
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
			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
1918
			int userid = userBean.getEmpNum();//用户id
yuquan.zhu committed
1919
			attendancedetails.setQyid(qyid);
ilal committed
1920
			
yuquan.zhu committed
1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
			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
1936
			
yuquan.zhu committed
1937
			List<PunchRecord> original = punchrecordservice.selFuzzyOriginalAttendance(attendancedetails);
ilal committed
1938
	
yuquan.zhu committed
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
			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
1950
		
yuquan.zhu committed
1951 1952 1953 1954 1955 1956 1957
		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
1958 1959
				//attendancedetails.setStart("");
				//attendancedetails.setEnd("");
yuquan.zhu committed
1960 1961 1962 1963
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
ilal committed
1964
		
yuquan.zhu committed
1965
		List<PunchRecord> detail = punchrecordservice.ViewAttendanceDetails(starttime,endtime,userid);
ilal committed
1966

yuquan.zhu committed
1967 1968 1969 1970 1971 1972
		return ResultUtil.data(detail);
	}
	
	/**
	 * 获取考勤日历出勤数据
	 */
ilal committed
1973 1974
//	@GetMapping(value = "/AttOriginalRecord")
//	@ApiOperation(value = "获取考勤日历数据", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
1975 1976 1977 1978 1979
	@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
1980
			
yuquan.zhu committed
1981 1982
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
ilal committed
1983
			
yuquan.zhu committed
1984
			String str = null;
ilal committed
1985
			
yuquan.zhu committed
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
			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
2005
			
yuquan.zhu committed
2006 2007
			Long startDate = 0l;
			Long endDate = 0l;
ilal committed
2008
			
yuquan.zhu committed
2009 2010
			if(!("").equals(atttions.getDate())){
			   try {
lal committed
2011
				   String sdaet = ClockInTool.getMinMonthDate(str);
yuquan.zhu committed
2012
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
ilal committed
2013
				       
lal committed
2014
				   String edate = ClockInTool.getMaxMonthDate(str);
yuquan.zhu committed
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
				   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
2035
			
Yl123 committed
2036
			AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
2037 2038
			//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
			if(attgro != null){//该员工是否加入到考勤组
ilal committed
2039
				
yuquan.zhu committed
2040
				if(attgro.getPbfs() == 1){
ilal committed
2041
					
yuquan.zhu committed
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052
					//当前月     必须打卡日期
					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
2053
					
lal committed
2054
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid,qyid);
yuquan.zhu committed
2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
					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
2078
					 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
						 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
2094
					 
yuquan.zhu committed
2095
					 attcal.setAttshouldmade(y+bxdk);//应出勤
ilal committed
2096 2097
					/***********/
					
yuquan.zhu committed
2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
				}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
2108
					
lal committed
2109
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid,qyid);
yuquan.zhu committed
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
					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
2133
					 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144
						 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
2145
					 
yuquan.zhu committed
2146 2147
					 attcal.setAttshouldmade(y);//应出勤
				}
ilal committed
2148
				
yuquan.zhu committed
2149 2150
			    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(userid, startDate, endDate);//打卡记录
				attcal.setAttendance(attendance.size());//已出勤
ilal committed
2151 2152
				
				
yuquan.zhu committed
2153 2154 2155 2156 2157 2158
				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
2159 2160
	            
	            
yuquan.zhu committed
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
	            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
2191 2192 2193
	            
	           
			
yuquan.zhu committed
2194 2195
			}
			return ResultUtil.data(attcal);
ilal committed
2196

yuquan.zhu committed
2197 2198
	}
	
lal committed
2199 2200 2201
	/********************************************************************************************************************************************************************************************************************************************************************************/
	/****************************************************************************	APP--调用接口结束	*****************************************************************************************************************************************************************************/
	/********************************************************************************************************************************************************************************************************************************************************************************/
ilal committed
2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218
	
	/**
	 * 根据 年、月 获取对应的月份 的 天数
     */
	 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
2219 2220 2221
	/**
	 * 	获取考勤日历显示出勤详细数据
	 */
ilal committed
2222
	@SuppressWarnings("deprecation")
yuquan.zhu committed
2223 2224 2225 2226 2227 2228
	@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
2229
		
yuquan.zhu committed
2230 2231 2232
		Date dno = new Date();
	    SimpleDateFormat sdfno = new SimpleDateFormat("yyyy-MM-dd");
	    String now = sdfno.format(dno);
ilal committed
2233 2234 2235
		
//		int userid =  600135;//马丹丹//600126;//肖丽思
		
yuquan.zhu committed
2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255
		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
2256
		 
yuquan.zhu committed
2257 2258
		 Long startDate = 0l;
	     Long endDate = 0l;
ilal committed
2259
		 
yuquan.zhu committed
2260 2261
		 if(!("").equals(attconditions.getDate())){
		   try {
lal committed
2262
			   String sdaet = ClockInTool.getMinMonthDate(str);
yuquan.zhu committed
2263 2264
			   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
			       
lal committed
2265
			   String edate = ClockInTool.getMaxMonthDate(str);
yuquan.zhu committed
2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285
			   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
2286
		
Yl123 committed
2287
		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
ilal committed
2288
		
yuquan.zhu committed
2289 2290
		//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		if(attgro != null){//该员工是否加入到考勤组
ilal committed
2291
			 
yuquan.zhu committed
2292 2293
			if(attgro.getPbfs() == 1){//固定排班
				String yemo = year + "-" + month;
ilal committed
2294
				
yuquan.zhu committed
2295 2296
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2297
				
yuquan.zhu committed
2298
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
ilal committed
2299 2300
				
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312
					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
2313
					
yuquan.zhu committed
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339
					//日历提醒事务
					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
2340 2341
					
					
yuquan.zhu committed
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375
					//考勤打卡原始记录
					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);
						}
					}
					
lal committed
2376
					int week = Integer.valueOf(ClockInTool.dateToWeek(famt.format(da)));//2
yuquan.zhu committed
2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 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 2417 2418 2419
				    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
2420
				
yuquan.zhu committed
2421
				return ResultUtil.data(dss);
ilal committed
2422 2423
				
				
yuquan.zhu committed
2424
			}else if(attgro.getPbfs() == 2){//自由排班
ilal committed
2425
				
yuquan.zhu committed
2426 2427 2428 2429
				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
2430
				
yuquan.zhu committed
2431
				String[] array1 = new String[callist.size()];
ilal committed
2432
				
yuquan.zhu committed
2433
				String[] erinnern1 = new String[rltilist.size()];
ilal committed
2434
				
yuquan.zhu committed
2435
				int r = 0;
ilal committed
2436
				
yuquan.zhu committed
2437 2438 2439 2440 2441 2442 2443 2444 2445
				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
2446
					
yuquan.zhu committed
2447 2448 2449 2450 2451 2452 2453 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
					//日历提醒事务
					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
2482
//						String schetime = mat.format(new Date(sdu.getData().toString()));//排班详细数据日期
yuquan.zhu committed
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
						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
2513 2514
					
					
yuquan.zhu committed
2515
					ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(sdu.getBcid());
ilal committed
2516 2517
					
					/*********/
yuquan.zhu committed
2518 2519 2520 2521 2522 2523 2524 2525
					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);
lal committed
2526 2527 2528
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk1()+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks1()+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs1()+":00")));
yuquan.zhu committed
2529 2530 2531 2532 2533
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(2);
lal committed
2534 2535 2536
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk1()+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks1()+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs1()+":00")));
yuquan.zhu committed
2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547
									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);
lal committed
2548 2549 2550
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk2()+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks2()+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs2()+":00")));
yuquan.zhu committed
2551 2552 2553 2554 2555
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(4);
lal committed
2556 2557 2558
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk2()+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks2()+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs2()+":00")));
yuquan.zhu committed
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569
									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);
lal committed
2570 2571 2572
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk3()+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks3()+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs3()+":00")));
yuquan.zhu committed
2573 2574 2575 2576 2577
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(6);
lal committed
2578 2579 2580
									as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk3()+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks3()+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs3()+":00")));
yuquan.zhu committed
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
									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
2597 2598
					/*******/
					
yuquan.zhu committed
2599 2600
					dss.add(ss);
				}
ilal committed
2601
				
yuquan.zhu committed
2602
				String yemo = year + "-" + month;
ilal committed
2603
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2604 2605 2606 2607 2608 2609
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
ilal committed
2610 2611 2612 2613
					
					
					
					
yuquan.zhu committed
2614
				}
ilal committed
2615 2616 2617 2618 2619 2620 2621
				
				
				
//				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
2622 2623
		        String[] eris=erilist.toArray(new String[erilist.size()]);//缺少的具体天数(yyyy-mm-dd)
		        
ilal committed
2624
		        String[] eridadys = array_unique(eris);
yuquan.zhu committed
2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660
		        
				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
2661 2662 2663 2664 2665
				
				
				
				
				
yuquan.zhu committed
2666 2667 2668 2669 2670 2671
				//打卡记录
				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
2672 2673
				
				List<String> list = compare(array1,array2);  
yuquan.zhu committed
2674 2675 2676 2677 2678 2679 2680 2681
		        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
2682
					
yuquan.zhu committed
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
					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
2717
				
yuquan.zhu committed
2718 2719 2720 2721
				return ResultUtil.data(dss);
				
			}else{//自由工时
				String yemo = year + "-" + month;
ilal committed
2722
				
yuquan.zhu committed
2723
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
ilal committed
2724
				
yuquan.zhu committed
2725 2726
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2727
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739
					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
2740
					
yuquan.zhu committed
2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 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 2794 2795 2796 2797 2798 2799
					//日历提醒事务
					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
2800
					
lal committed
2801
					int week = Integer.valueOf(ClockInTool.dateToWeek(famt.format(da)));//2
yuquan.zhu committed
2802
					AttendanceWeeklySch atwek = attendanceweeklyschservice.selectFreeWorkingHours(attgro.getId(),week);//自由工时
ilal committed
2803 2804
				    
						
yuquan.zhu committed
2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832
				    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
2833
					
yuquan.zhu committed
2834 2835
					dss.add(ss);
				}
ilal committed
2836 2837 2838
				
				
				
yuquan.zhu committed
2839 2840 2841
				return ResultUtil.data(dss);
			}
		}
ilal committed
2842
		
yuquan.zhu committed
2843 2844 2845
		return ResultUtil.data(null);
	}
	 
ilal committed
2846 2847
//	 @GetMapping(value = "/ClockData")
//	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
2848 2849 2850 2851 2852 2853 2854
	/**
	 * 获取考勤打卡数据------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
2855
		 
yuquan.zhu committed
2856
		 AttendanceCardList attcar = new AttendanceCardList();
ilal committed
2857
		 
yuquan.zhu committed
2858 2859 2860 2861 2862 2863 2864 2865
		 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
2866
		 
yuquan.zhu committed
2867 2868 2869 2870 2871 2872 2873 2874
		 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();
		 }
lal committed
2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886
			 int qyid = userBean.getOrgCode();//坏小孩【企业id】
			 int userid = userBean.getEmpNum();//用户id	
		     
		     AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		     
		     //pbfs:排班方式 1:固定排班;2:自由排班;3:自由工时
			 if(attgro != null){//判断当前用户是否加入到考勤组
				 //排班制
			     Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
			     //固定排班
			     int week = Integer.valueOf(ClockInTool.dateToWeek(str));//4
			     AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
ilal committed
2887
				 
lal committed
2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906
			    if(attgro.getPbfs() == 1){//固定排班
	//		    	int week = Integer.valueOf(ClockInTool.dateToWeek(str));//4
	//		    	AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);
			    	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);
yuquan.zhu committed
2907
				    		}
lal committed
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961
			    		}
			    	}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);
				    }
					
	//				Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
					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);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbdk1()+":00")));
										as.setStarttime(("").equals(jrpb.getSbqjks1())? 0 :Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjks1()+":00")));
										as.setEndtime(("").equals(jrpb.getSbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjjs1()+":00")));
										atts.add(as);
									}else{
										AttSchedule as = new AttSchedule();
										as.setId(jrpb.getBcid());
										as.setSort(2);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbdk1()+":00")));
										as.setStarttime(("").equals(jrpb.getXbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjks1()+":00")));
										as.setEndtime(("").equals(jrpb.getXbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjjs1()+":00")));
										atts.add(as);
yuquan.zhu committed
2962 2963
									}
								}
lal committed
2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983
								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);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbdk2()+":00")));
										as.setStarttime(("").equals(jrpb.getSbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjks2()+":00")));
										as.setEndtime(("").equals(jrpb.getSbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjjs2()+":00")));
										atts.add(as);
									}else{
										AttSchedule as = new AttSchedule();
										as.setId(jrpb.getBcid());
										as.setSort(4);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbdk2()+":00")));
										as.setStarttime(("").equals(jrpb.getXbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjks2()+":00")));
										as.setEndtime(("").equals(jrpb.getXbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjjs2()+":00")));
										atts.add(as);
yuquan.zhu committed
2984 2985
									}
								}
lal committed
2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005
								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);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbdk3()+":00")));
										as.setStarttime(("").equals(jrpb.getSbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjks3()+":00")));
										as.setEndtime(("").equals(jrpb.getSbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getSbqjjs3()+":00")));
										atts.add(as);
									}else{
										AttSchedule as = new AttSchedule();
										as.setId(jrpb.getBcid());
										as.setSort(6);
										as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbdk3()+":00")));
										as.setStarttime(("").equals(jrpb.getXbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjks3()+":00")));
										as.setEndtime(("").equals(jrpb.getXbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+jrpb.getXbqjjs3()+":00")));
										atts.add(as);
yuquan.zhu committed
3006 3007
									}
								}
lal committed
3008
								attcar.setAttsch(atts);
yuquan.zhu committed
3009
							}
lal committed
3010 3011 3012 3013 3014 3015 3016 3017 3018 3019
						}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);
yuquan.zhu committed
3020
						}
lal committed
3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043
					}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){
								 context = ah.getSbdk1() + "-" + ah.getXbdk1();
							 }
							 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
								 context = context +" "+ ah.getSbdk2() + "-" + ah.getXbdk2();
							 }
							 if(ah.getSxbcs() == 3){
								 context = context +" "+ ah.getSbdk3() + "-" + ah.getXbdk3();
							 }
							 sys.setContext(name+ " " + context);
							 
							 akms.add(sys);
					   }
					   attcar.setSsfh(akms);//无排班时 获取的系统班次
yuquan.zhu committed
3044
					}
lal committed
3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 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 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 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
			    	
				}else{//自由工时
					//int week = Integer.valueOf(ClockInTool.dateToWeek(str));//4
					
					AttendanceWeeklySch wekz = attendanceweeklyschservice.WeeklyFreeRoster(attgro.getId(),week);
					if(wekz != null){//
						String dada = str+" "+attgro.getKqkssjTime()+":00";
						attcar.setStapclotime(Long.valueOf(ClockInTool.dateToStamp(dada)));
					}
					
					if(!("").equals(attgro.getJbzdsc())){
						attcar.setCanpunchworkdate(Double.valueOf(attgro.getJbzdsc()));//上班打卡后多久大下班卡
					}
					
					
				}
			    if(jrpb != null || atwek != null){
			    	ShiftManagement shif = null;
			    	if(attgro.getPbfs() == 1){
			    		shif = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
			    	}else if(attgro.getPbfs() == 2){
			    		shif = shiftmanagementservice.selectByPrimaryKey(jrpb.getBcid());
			    	}
			    	
			    	if(shif != null){
			    		if(shif.getIsXbdk() == 1){
			    			attcar.setNoclockout(true);// 下班不用打卡
			    		}else{
			    			attcar.setNoclockout(false);// 下班不用打卡
			    		}
			    		attcar.setAllowlate(shif.getYxcdfzs());// 允许迟到分钟数
			    		attcar.setSeriouslate(shif.getYzcdfzs());// 严重迟到分钟数
			    		attcar.setAbsenteeismlate(shif.getKgcdfzs());// 旷工迟到分钟数
			    		if(shif.getIsWzwd() == 1){
			    			attcar.setIslatelate(true);// 晚走晚到
			    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
			    			int p = 0;
			    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1())){p = 2;}
			    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2())){p = 4;}
			    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2()) && !("").equals(shif.getXbwz3()) && !("").equals(shif.getSbwd3())){p = 6;}
			    			AttLateLate ala = 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{
				 //无排班
				 //系统班次
	//			 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 = ClockInTool.dealDateFormat(ah.getSbdk1(),2) + "-" + ClockInTool.dealDateFormat(ah.getXbdk1(),2);
	//				 }
	//				 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
	//					 context = context +" "+ ClockInTool.dealDateFormat(ah.getSbdk2(),2) + "-" + ClockInTool.dealDateFormat(ah.getXbdk2(),2);
	//				 }
	//				 if(ah.getSxbcs() == 3){
	//					 context = context +" "+ ClockInTool.dealDateFormat(ah.getSbdk3(),2) + "-" + ClockInTool.dealDateFormat(ah.getXbdk3(),2);
	//				 }
	//				 sys.setContext(name+ " " + context);
	//				 
	//				 akms.add(sys);
	//			 }
	//			 attcar.setSsfh(akms);//无排班时 获取的系统班次
yuquan.zhu committed
3195
				 
lal committed
3196 3197 3198 3199 3200 3201 3202 3203
				 attcar.setAttgrouptype(0);//1:固定排班;2:自由排班;3:自由工时
			 }
			 
			//打卡记录
		    List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
		    attcar.setAttpr(dajllist);
			 
			 return ResultUtil.data(attcar);
yuquan.zhu committed
3204 3205 3206
				 
	 }
	
ilal committed
3207 3208 3209
	 /**
	  * ??????
	  */
yuquan.zhu committed
3210 3211 3212 3213 3214 3215 3216 3217
	 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);
lal committed
3218 3219 3220
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk1()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks1()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs1()+":00")));
yuquan.zhu committed
3221 3222 3223 3224 3225
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
lal committed
3226 3227 3228
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk1()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks1()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs1()+":00")));
yuquan.zhu committed
3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239
			    		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);
lal committed
3240 3241 3242
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk2()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks2()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs2()+":00")));
yuquan.zhu committed
3243 3244 3245 3246 3247
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
lal committed
3248 3249 3250
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk2()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks2()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs2()+":00")));
yuquan.zhu committed
3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261
			    		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);
lal committed
3262 3263 3264
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk3()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks3()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs3()+":00")));
yuquan.zhu committed
3265 3266 3267 3268 3269
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
lal committed
3270 3271 3272
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk3()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks3()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs3()+":00")));
yuquan.zhu committed
3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
	 

	 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);
lal committed
3289 3290 3291
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk1()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks1()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs1()+":00")));
yuquan.zhu committed
3292 3293 3294 3295 3296
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
lal committed
3297 3298 3299
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk1()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks1()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs1()+":00")));
yuquan.zhu committed
3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310
			    		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);
lal committed
3311 3312 3313
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk2()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks2()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs2()+":00")));
yuquan.zhu committed
3314 3315 3316 3317 3318
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
lal committed
3319 3320 3321
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk2()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks2()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs2()+":00")));
yuquan.zhu committed
3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332
			    		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);
lal committed
3333 3334 3335
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbdk3()+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjks3()+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getSbqjjs3()+":00")));
yuquan.zhu committed
3336 3337 3338 3339 3340
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
lal committed
3341 3342 3343
			    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbdk3()+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjks3()+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shiftm.getXbqjjs3()+":00")));
yuquan.zhu committed
3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374
			    		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
3375
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413
		 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){
lal committed
3414 3415
					sbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk1()+":00"));
					xbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk1()+":00"));
yuquan.zhu committed
3416 3417
				}
				if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
lal committed
3418 3419
					sbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk2()+":00"));
					xbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk2()+":00"));
yuquan.zhu committed
3420 3421
				}
				if(banci.getSxbcs()== 3){
lal committed
3422 3423
					sbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk3()+":00"));
					xbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk3()+":00"));
yuquan.zhu committed
3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443
				}
			}
			//之前打卡的班次
			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
3444
//		        System.out.println(minAttid.getAttdate() +  "---min---" +minAttid.getId());
yuquan.zhu committed
3445 3446
				//最大值
				maxAttid = mapucalist.stream().max(Comparator.comparing(PunchRecord::getId)).get();
ilal committed
3447 3448
//		        System.out.println(maxAttid.getAttdate() +  "---max---" + maxAttid.getId());
				
yuquan.zhu committed
3449 3450 3451
				//对应打卡明细表id
				dkmxid = maxAttid.getDkmxid();
			}
ilal committed
3452
			
yuquan.zhu committed
3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 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 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 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
			//当天有打卡记录且当天打卡班次和当前修改后的班次不匹配再进行重新维护
			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
4147 4148 4149 4150
			
			/***********************/
		 
		 
yuquan.zhu committed
4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161
		 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);
lal committed
4162 4163 4164
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk1()+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks1()+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs1()+":00")));
yuquan.zhu committed
4165 4166 4167 4168 4169
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(2);
lal committed
4170 4171 4172
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk1()+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks1()+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs1()+":00")));
yuquan.zhu committed
4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183
				    		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);
lal committed
4184 4185 4186
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk2()+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks2()+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs2()+":00")));
yuquan.zhu committed
4187 4188 4189 4190 4191
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(4);
lal committed
4192 4193 4194
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk2()+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks2()+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs2()+":00")));
yuquan.zhu committed
4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205
				    		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);
lal committed
4206 4207 4208
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbdk3()+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjks3()+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getSbqjjs3()+":00")));
yuquan.zhu committed
4209 4210 4211 4212 4213
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(6);
lal committed
4214 4215 4216
				    		as.setTime(Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbdk3()+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjks3()+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(ClockInTool.dateToStamp(str+" "+shifs.getXbqjjs3()+":00")));
yuquan.zhu committed
4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273
				    		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
4274
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
yuquan.zhu committed
4275
		 int userid = userBean.getEmpNum();//用户id	
ilal committed
4276
		
yuquan.zhu committed
4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311
		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
4312
	 
yuquan.zhu committed
4313 4314 4315 4316 4317 4318 4319
	/**
	 * 	删除日历提醒信息
	 */
	@DeleteMapping(value = "/CalendarAlarm/{id}")
	@ApiOperation(value = "删除日历提醒信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 52)
	public Result<Integer> deleteCalendarAlarm(@PathVariable("id") Integer id) {
ilal committed
4320
		
yuquan.zhu committed
4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335
		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
4336
		 
Yl123 committed
4337
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
yuquan.zhu committed
4338
		 //pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
ilal committed
4339
		 
yuquan.zhu committed
4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 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 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 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
	     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
4649 4650 4651
		 
		 
		 
yuquan.zhu committed
4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664
		 //打卡记录
		 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
4665
		
yuquan.zhu committed
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
		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));//转换打卡时间格式
lal committed
4728
		pre.setAttdate(attdate_+" "+ClockInTool.dateToWeek2(putime));// 考勤日期
yuquan.zhu committed
4729 4730 4731 4732 4733 4734 4735
		
		long date = new Date().getTime();
		if(("0").equals(clock.getPunchcardtime())){
			pre.setAttime(date);// 考勤时间(应打卡时间)	
		}else{
			pre.setAttime(Long.valueOf(clock.getPunchcardtime()));// 考勤时间(应打卡时间)
		}
ilal committed
4736
		
yuquan.zhu committed
4737 4738 4739
		pre.setDkmxid(dkmx);// 打卡明细id
		pre.setBcid(clock.getShifid());// 班次id
		punchrecordservice.insertSelective(pre);//新增打卡记录
ilal committed
4740 4741 4742 4743
			
		 
		 
//		if(shiftmanagementservice.insertSelective(shif)>0){
yuquan.zhu committed
4744
			return ResultUtil.data(null,"打卡成功");
ilal committed
4745 4746 4747
//		}else{
//			return ResultUtil.error("新增班次失败");
//		}
yuquan.zhu committed
4748 4749
	 }
	
ilal committed
4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777
	 /************************************************************************************************************************************/
	 /***************************************************工具方法区***************************************************************************/
	 /************************************************************************************************************************************/
	
	/**
	 * 对比两个字符串数组
	 * @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
4778 4779 4780
	/**
	 * 	考勤机一键同步
	 */
lal committed
4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801
//	@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
4802
//			String url = mac_command;
lal committed
4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827
//	        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
4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855
	/**
	 * 	获取报表汇总
	 */
	@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 {
lal committed
4856
				   String sdaet = ClockInTool.getMinMonthDate(attendancedetails.getStart());
yuquan.zhu committed
4857 4858
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
lal committed
4859
				   String edate = ClockInTool.getMaxMonthDate(attendancedetails.getEnd());
yuquan.zhu committed
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
				   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
4917
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
yuquan.zhu committed
4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931
				//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++;
						}
lal committed
4932
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),qyid);
yuquan.zhu committed
4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955
						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
4956
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974
							 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
4975
						 int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
yuquan.zhu committed
4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993
						 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{
lal committed
4994
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),qyid);
yuquan.zhu committed
4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016
						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
5017
						 for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029
							 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
5030
						 int xiuxi = getDaysByYearMonth(year,month) - y;
yuquan.zhu committed
5031 5032 5033 5034 5035 5036 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 5065 5066 5067 5068 5069 5070 5071 5072
						 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
5073 5074 5075 5076
				/**********/
				
				
				
yuquan.zhu committed
5077 5078
				attrep.add(apr);
			}
ilal committed
5079 5080 5081
			
			
//			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
yuquan.zhu committed
5082 5083 5084 5085
			int attshouldmade = 0;//应出勤
			for(AttendanceReport reps:attrep) {
				System.out.println(reps.getAnswerday());
			}
ilal committed
5086 5087 5088
			
			
			
yuquan.zhu committed
5089 5090 5091
			return ResultUtil.data(attrep);
	}
}