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

import java.math.BigDecimal;
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.Set;
14
import java.util.concurrent.locks.ReentrantLock;
yuquan.zhu committed
15

16 17
import cn.timer.api.service.KqglAssoDkjlService;
import lombok.extern.slf4j.Slf4j;
yuquan.zhu committed
18
import org.springframework.beans.factory.annotation.Autowired;
lal committed
19
import org.springframework.beans.factory.annotation.Value;
yuquan.zhu committed
20 21 22
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
ilal committed
23
import org.springframework.transaction.annotation.Transactional;
yuquan.zhu committed
24 25
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
ilal committed
26
import org.springframework.validation.annotation.Validated;
yuquan.zhu committed
27 28 29 30 31 32 33 34 35 36 37 38
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
39 40
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
yuquan.zhu committed
41 42
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
43
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
yuquan.zhu committed
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

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;
ilal committed
77
import cn.timer.api.bean.kqmk.KqglAssoPbmx;
ilal committed
78
import cn.timer.api.bean.kqmk.KqglAssoYhkqz;
ilal committed
79
import cn.timer.api.bean.kqmk.KqglAssoYhsb;
yuquan.zhu committed
80 81 82
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
lal committed
83
import cn.timer.api.controller.kqgl.atttimer.RealTimeUpdate;
yuquan.zhu committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97
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
98
import cn.timer.api.dao.kqmk.KqglAssoPbmxMapper;
ilal committed
99
import cn.timer.api.dao.kqmk.KqglMainKqzMapper;
yuquan.zhu committed
100
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
ilal committed
101
import cn.timer.api.dto.kqmk.AttqueryCriteriaDto;
ilal committed
102
import cn.timer.api.dto.kqmk.KqglAssoPbmxDto;
ilal committed
103
import cn.timer.api.dto.kqmk.KqglMainKqzDto;
ilal committed
104
import cn.timer.api.dto.kqmk.ResttryfixdayDto;
yuquan.zhu committed
105 106 107 108 109 110 111 112 113 114 115
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
 *	考勤
 */
116
@Slf4j
ilal committed
117
@Api(tags = "3.0[2]考勤模块")
yuquan.zhu committed
118
@RestController
ilal committed
119 120
@Transactional
@RequestMapping(value = "/kqz", produces = { "application/json", "multipart/form-data" })
yuquan.zhu committed
121
public class AttController {
122

lal committed
123 124
	@Value("${config-8timer.machine8timerUrl}")
	public String mac_command; // 回调地址
125

Yl123 committed
126
	//班次
yuquan.zhu committed
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
	@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;
162

yuquan.zhu committed
163 164 165 166 167
	@Autowired
	private SpecialDateMapper specialdateservice;
	//日历提醒
	@Autowired
	private CalendarAlarmMapper calendaralarmservice;
168 169


yuquan.zhu committed
170
	SimpleDateFormat mat = new SimpleDateFormat("yyyy-MM-dd");
171

yuquan.zhu committed
172
	SimpleDateFormat famt = new SimpleDateFormat("yyyy-MM-dd");
173 174


yuquan.zhu committed
175
	SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
lal committed
176

177 178 179 180
	private static ReentrantLock lock= new ReentrantLock();//出现一个页面多次访问一个接口



ilal committed
181
	/*********考勤机***********/
yuquan.zhu committed
182 183 184 185 186 187 188 189
	/*********打卡地址***********/
	/**
	 * 获取打卡地址数据
	 */
	@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,
190 191 192 193 194 195 196
																  @ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
		int qyid = userBean.getOrgCode();//坏小孩【企业id】

		PageHelper.startPage(pageNum, pageSize);
		List<PunchCardAddress> shiftList = punchcardaddressservice.selectByPrimaryByQyid(qyid);
		PageInfo<PunchCardAddress> pageInfo = new PageInfo<>(shiftList);
		return ResultUtil.data(pageInfo);
yuquan.zhu committed
197 198 199 200 201 202 203 204 205
	}
	/*********打卡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,
206 207 208 209 210 211 212
															@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
		int qyid = userBean.getOrgCode();//坏小孩【企业id】

		PageHelper.startPage(pageNum, pageSize);
		List<PunchCardWiFi> shiftList = punchcardwifiservice.selectByPrimaryByQyid(qyid);
		PageInfo<PunchCardWiFi> pageInfo = new PageInfo<>(shiftList);
		return ResultUtil.data(pageInfo);
yuquan.zhu committed
213
	}
ilal committed
214 215

	/**************************************************************考勤组********************************************************************/
216

ilal committed
217 218
	@Autowired
	private KqglMainKqzMapper kqglmainkqzmapper;
219

yuquan.zhu committed
220
	/**
ilal committed
221
	 * 	查询列表-考勤组-分页【新】
yuquan.zhu committed
222
	 */
ilal committed
223
	@PostMapping(value = "/attendance_group")
lal committed
224
	@ApiOperation(value = "34:查询列表-考勤组-分页-分页", httpMethod = "POST", notes = "查询列表-考勤组-分页-分页")
ilal committed
225 226
	@ApiOperationSupport(order = 34)
	public Result<Object> AttendanceGroup(@CurrentUser UserBean userBean, @Validated @RequestBody AttqueryCriteriaDto attquerycriteriadto){
227 228 229 230 231 232 233 234 235
		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
236
	}
237

yuquan.zhu committed
238 239 240 241 242 243 244
	/**
	 * 获取考勤组数据
	 */
	@GetMapping(value="/AttGroupList")
	@ApiOperation(value = "获取考勤组数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 21)
	public Result<PageInfo<AttendanceGroup>> getAttendanceGroupList(@CurrentUser UserBean userBean,
245 246 247 248 249 250 251 252
																	@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】

		PageHelper.startPage(pageNum, pageSize);
		List<AttendanceGroup> attgrlist = attendancegroupservice.selectAttGroupListByQyid(qyid);
		PageInfo<AttendanceGroup> pageInfo = new PageInfo<>(attgrlist);
		return ResultUtil.data(pageInfo);
yuquan.zhu committed
253 254 255 256 257 258 259 260
	}
	/**
	 * 获取考勤组数据-根据 模糊 + 高級查詢
	 */
	@PostMapping(value = "/AttGroupList/list")
	@ApiOperation(value = "获取考勤组数据-根据 模糊 + 高級查詢", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 22)
	public Result<List<AttendanceGroup>> getAttGroupListByQuery(@CurrentUser UserBean userBean,@RequestBody KqzAttendanceGroupSearch kqzattendancegroupsearch) {
261 262 263 264 265 266 267
		int qyid = userBean.getOrgCode();//坏小孩【企业id】

		kqzattendancegroupsearch.setQyid(qyid);

		List<AttendanceGroup> attgrlist = attendancegroupservice.selectKqglMainKqzByQuery(kqzattendancegroupsearch);

		return ResultUtil.data(attgrlist);
yuquan.zhu committed
268
	}
269

yuquan.zhu committed
270 271 272 273 274 275 276
	/**
	 * 获取修改的排班明细--【修改考勤组】--------------------------------------------------------------------------------------
	 */
	@PostMapping(value = "/AttGroupSchedulingList")
	@ApiOperation(value = "获取修改的排班明细", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 29)
	public Result<List<Schedule>> getAttGroupSchedulingList(@CurrentUser UserBean userBean,@RequestBody AttScheduling attscheduling) {
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
		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);
292 293


294 295 296 297 298 299 300
		List<KqglAssoYhkqz> kqzs = KqglAssoYhkqz.builder().build().selectList(new QueryWrapper<KqglAssoYhkqz>().lambda().eq(KqglAssoYhkqz::getKqzid, attscheduling.getKqzid()));
		for(KqglAssoYhkqz yhr : kqzs) {
			Schedule sch = new Schedule();
			sch.setUserid(yhr.getUserid());
			YgglMainEmp yhna = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, yhr.getUserid()));
			if(yhna !=null){
				sch.setUsername(yhna.getName());
ilal committed
301
			}
302 303 304 305 306 307 308

			sch.setKqzid(attscheduling.getKqzid());
			schlist.add(sch);

		}

		return ResultUtil.data(schlist);
yuquan.zhu committed
309
	}
310 311


yuquan.zhu committed
312 313 314 315 316 317 318
	/**
	 * 根据考勤组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) {
319

yuquan.zhu committed
320 321 322
		KqzAttendanceGroupSearch jycx = new KqzAttendanceGroupSearch();
		jycx.setOverall(date);
		jycx.setQyid(id);
323

yuquan.zhu committed
324 325 326
		List<ShiftManagement> shifs = shiftmanagementservice.selectRosterByKqzid(jycx);
		return ResultUtil.data(shifs);
	}
327 328


ilal committed
329 330
	@Autowired
	private KqglAssoPbmxMapper kqglassopbmxmapper;
331

yuquan.zhu committed
332 333 334 335 336 337 338 339
	/**
	 * 修改考勤组排班(修改排班后,需判断是否有打卡记录,有则匹配当天修改后的班次,无则不需要修改)
	 */
	@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) {
340
		long startTime = System.currentTimeMillis();
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
		int id = Integer.valueOf(attass.getAttgroupid());//修改数据id

		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		int userid = userBean.getEmpNum();//用户id

		String dastr = new SimpleDateFormat("yyyy-MM").format(new Date()).toString();//

		AttendanceGroup qttgrop = attendancegroupservice.selectByPrimaryKey(Integer.valueOf(attass.getAttgroupid()));
		boolean xiugai = true;
		//记录排班(排班制)
		List<Schedule> schlist=new ArrayList<Schedule>();
		Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
		String date_scmx = null;

		if(schedules.length>0 && attass.getAtttype() == 2){

			date_scmx = ClockInTool.SunNovCSTYM(schedules[0].getData());

			String date = String.valueOf(schedules[0].getData());
			Date dt=new Date(date);
			SimpleDateFormat famt = new SimpleDateFormat("yyyy-MM");
			System.out.println(famt.format(dt));

			if(!(famt.format(dt)).equals(dastr)) {

				xiugai = false;
				for(int p=0;p<schedules.length;p++){
ilal committed
368
//						scheduleservice.deleteByPrimaryBykqzid(Integer.valueOf(attass.getAttgroupid()),ClockInTool.SunNovCST(String.valueOf(schedules[p].getData())));
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

					KqglAssoPbmx.builder().build().delete(new QueryWrapper<KqglAssoPbmx>().lambda().eq(KqglAssoPbmx::getUserid, schedules[p].getUserid()).eq(KqglAssoPbmx::getData, ClockInTool.SunNovCST(String.valueOf(schedules[p].getData())))
							.eq(KqglAssoPbmx::getKqzid, Integer.valueOf(attass.getAttgroupid())));

					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);
				}
				if(schlist.size()>0){
					scheduleservice.insertKqglAssoPbmxList(schlist);
				}
			}else {
				xiugai = true;
				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();
yuquan.zhu committed
404
					}
405 406 407 408 409 410 411 412 413 414 415 416 417

					//当天修改后的班次
					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){
							sbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk1()+":00"));
							xbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk1()+":00"));
yuquan.zhu committed
418
						}
419 420 421
						if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
							sbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk2()+":00"));
							xbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk2()+":00"));
yuquan.zhu committed
422
						}
423 424 425
						if(banci.getSxbcs()== 3){
							sbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk3()+":00"));
							xbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk3()+":00"));
yuquan.zhu committed
426
						}
427 428 429 430 431 432 433 434 435
					}
					//之前打卡的班次
					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(),qyid);
						if(initial.size() > 0){
							RestMethod(initial,initial.get(0).getDkmxid());
yuquan.zhu committed
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
					}


					//当天的所有打卡记录
					List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,schedules[p].getUserid(),qyid);
					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);// 打卡结果
yuquan.zhu committed
474
												}
475 476 477 478 479 480 481
												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())));// 打卡结果
yuquan.zhu committed
482
												}
483
												record.setAttime(xbdk1);//下班应打卡时间
yuquan.zhu committed
484
											}
ilal committed
485 486
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
487 488
										}else{
											if(pre.getId() == minAttid.getId()){//上班
yuquan.zhu committed
489
												PunchRecord record = new PunchRecord();
490 491 492
												record.setId(pre.getId());
												record.setType(1);//上班
												Long time = (pre.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
493 494 495 496 497 498 499 500 501 502
												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);
503
											}else if(pre.getId() == maxAttid.getId()){//下班
ilal committed
504
												PunchRecord record = new PunchRecord();
505
												record.setId(pre.getId());
yuquan.zhu committed
506
												record.setType(2);//下班
507
												Long time = (pre.getDktime() - xbdk1)/1000/60;
yuquan.zhu committed
508 509 510 511 512 513 514
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
515
												record.setAttime(xbdk1);
yuquan.zhu committed
516
												record.setBcid(banci.getId());//班次id
517
												record.setSort(2);
yuquan.zhu committed
518 519 520
												punchrecordservice.updateByPrimaryKeySelective(record);
											}
										}
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
									}
									//修改打卡明细
									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);// 打卡结果
yuquan.zhu committed
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
										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())));// 打卡结果
ilal committed
592
										}
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
										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());//上班
yuquan.zhu committed
616
											PunchRecord record = new PunchRecord();
617 618 619
											record.setId(mapucalist.get(y).getId());
											//										record.setType(1);//上班
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
620 621 622 623 624 625 626
											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);// 打卡结果
											}
627
											record.setAttime(sbdk1);
yuquan.zhu committed
628 629 630
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
631
										if(y == 1 || y == 2){
yuquan.zhu committed
632
											PunchRecord record = new PunchRecord();
633 634 635 636
											record.setId(mapucalist.get(y).getId());

											if((mapucalist.get(y).getSort())%2 == 0){//下班
												Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
yuquan.zhu committed
637 638 639
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
640 641 642
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
yuquan.zhu committed
643
												}
644 645 646 647 648
												record.setAttime(xbdk1);//下班应打卡时间

												str[0] = String.valueOf(mapucalist.get(y).getId());
											}else{//上班
												Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
yuquan.zhu committed
649
												if(time > 0){
650 651 652
													record.setStatus(3);
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
yuquan.zhu committed
653 654 655
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}
656 657 658
												record.setAttime(sbdk2);//上班应打卡时间

												str[1] = String.valueOf(mapucalist.get(y).getId());
ilal committed
659
											}
660

yuquan.zhu committed
661 662 663
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
664 665 666 667


										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
yuquan.zhu committed
668
											PunchRecord record = new PunchRecord();
669 670 671 672

											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk2)/1000/60;
yuquan.zhu committed
673 674 675 676 677 678 679
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
680 681
											record.setSort(4);
											record.setAttime(xbdk2);
yuquan.zhu committed
682 683
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
684 685

											str[2] = String.valueOf(maxdata.getId());
yuquan.zhu committed
686
										}
687 688

										if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
yuquan.zhu committed
689
											PunchRecord record = new PunchRecord();
690 691 692 693 694
											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());//上班应打卡时间
yuquan.zhu committed
695 696 697
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
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
									}

									//修改打卡明细
									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());//上班
yuquan.zhu committed
843
											PunchRecord record = new PunchRecord();
844 845
											record.setId(mapucalist.get(y).getId());
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
846 847 848 849 850 851 852
											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);// 打卡结果
											}
853
											record.setAttime(sbdk1);
yuquan.zhu committed
854 855 856
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
857
										if(y == 1 || y == 2 || y == 3 || y == 4){
yuquan.zhu committed
858
											PunchRecord record = new PunchRecord();
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
											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());
												}
yuquan.zhu committed
914 915 916 917
											}
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
918 919 920 921


										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
yuquan.zhu committed
922
											PunchRecord record = new PunchRecord();
923 924 925 926

											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk3)/1000/60;
yuquan.zhu committed
927 928 929 930 931 932 933
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
											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());//上班应打卡时间
yuquan.zhu committed
949 950 951 952
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
									}
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

									//修改打卡明细
									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);
						}
					}

					/***********************/
				}
			}//判断新增或修改
		}
1156 1157
		long endTime = System.currentTimeMillis();
		log.info("=======================================执行时长(毫秒):{}",endTime-startTime);
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
		if(schlist.size()>0 && xiugai){
			//删除排班明细表(自由排班)
//				scheduleservice.deleteByPrimaryBykqzid(id);

			scheduleservice.deleteByPrimaryBykqzid(id,date_scmx);

			scheduleservice.insertKqglAssoPbmxList(schlist);
			return ResultUtil.data(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获取所有信息--【修改考勤组】
yuquan.zhu committed
1226 1227 1228 1229 1230
	 */
	@GetMapping(value="/AttendanceGroup/{id}")
	@ApiOperation(value = "根据考勤组id获取所有信息", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 32)
	public Result<AttendanceGroup> getAttendanceGroup(@PathVariable("id") Integer id) {
1231

yuquan.zhu committed
1232
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
1233

yuquan.zhu committed
1234 1235
		return ResultUtil.data(attgro);
	}
1236

yuquan.zhu committed
1237 1238 1239 1240 1241 1242 1243
	/**
	 * 	获取当前考勤组所有人员
	 */
	@GetMapping(value="/AttUserGroupList/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 33)
	public Result<List<UserAttendanceRel>> getAttUserGroupList(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
1244
		lock.lock();
yuquan.zhu committed
1245 1246
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		List<UserAttendanceRel> userattgor = userattendancerelservice.selectAttendanceOfficerByKqzid(id,qyid);
1247
		lock.unlock();
yuquan.zhu committed
1248 1249
		return ResultUtil.data(userattgor);
	}
1250

yuquan.zhu committed
1251 1252 1253 1254 1255 1256
	/**
	 * 	提醒人员
	 */
	@GetMapping(value="/AttReminderStaff/{id}")
	@ApiOperation(value = "提醒人员", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 34)
lal committed
1257
	public Result<List<YgglMainEmp>> getAttReminderStaff(@PathVariable("id") Integer id,@CurrentUser UserBean userBean) {
1258
		lock.lock();
yuquan.zhu committed
1259 1260 1261 1262
		List<YgglMainEmp> yggl = new ArrayList<YgglMainEmp>();
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String txry = attgro.getTxry();
1263

yuquan.zhu committed
1264 1265 1266 1267 1268 1269
		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
1270
				YgglMainEmp txyg = attendancegroupservice.selectByPrimaryByempNum(Integer.valueOf(launchsArray[i]),userBean.getOrgCode());
1271

yuquan.zhu committed
1272 1273 1274 1275 1276 1277 1278
				YgglMainEmp txyy = YgglMainEmp.builder().build();///
				txyy.setId(txyg.getId());
				txyy.setName(txyg.getName());
				txyy.setEmpNum(txyg.getEmpNum());
				yggl.add(txyy);
			}
		}
1279
		lock.unlock();
yuquan.zhu committed
1280 1281
		return ResultUtil.data(yggl);
	}
1282

yuquan.zhu committed
1283 1284 1285 1286 1287 1288 1289
	/**
	 * 提示方式
	 */
	@GetMapping(value="/PromptingMode/{id}")
	@ApiOperation(value = "提示方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 35)
	public Result<List<KqzAttendanceGroupSearch>> getAttPromptingMode(@PathVariable("id") Integer id) {
1290

yuquan.zhu committed
1291
		List<KqzAttendanceGroupSearch> tsfslist = new ArrayList<KqzAttendanceGroupSearch>();
1292

yuquan.zhu committed
1293 1294 1295
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String tsfs = attgro.getTsfs();
1296

yuquan.zhu committed
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
		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);
			}
		}
1308

yuquan.zhu committed
1309 1310
		return ResultUtil.data(tsfslist);
	}
1311

yuquan.zhu committed
1312 1313 1314 1315 1316 1317 1318
	/**
	 * ??????
	 */
	@GetMapping(value="/WeeklyScheduling/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 36)
	public Result<List<AttendanceWeeklySch>> getAttWeeklyScheduling(@PathVariable("id") Integer id) {
1319

yuquan.zhu committed
1320
		List<AttendanceWeeklySch> atwesclist = attendanceweeklyschservice.selectAttWeeklySchedulingByKqzid(id);
1321 1322


yuquan.zhu committed
1323 1324
		return ResultUtil.data(atwesclist);
	}
1325

yuquan.zhu committed
1326 1327 1328 1329 1330 1331 1332
	/**
	 * 考勤组绑定的打卡方式
	 */
	@GetMapping(value="/Attendancemethod/{id}")
	@ApiOperation(value = "考勤组绑定的打卡方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 37)
	public Result<List<AttGroupBinPunchMode>> getAttendancemethodList(@PathVariable("id") Integer id) {
1333

yuquan.zhu committed
1334
		List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodeservice.selectByPrimaryByKqzId(id);
1335

yuquan.zhu committed
1336 1337
		return ResultUtil.data(attmetlist);
	}
1338

yuquan.zhu committed
1339 1340 1341 1342 1343 1344 1345
	/**
	 * 固定排班周
	 */
	@GetMapping(value="/AttendanceWeeklyScheduling/{id}")
	@ApiOperation(value = "固定排班周", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 38)
	public Result<List<AttendanceWeeklySch>> AttendanceWeeklySchedulingList(@PathVariable("id") Integer id) {
1346

yuquan.zhu committed
1347
		List<AttendanceWeeklySch> attweeklist = attendanceweeklyschservice.selectAttWeeklySchByKqzid(id);
1348

yuquan.zhu committed
1349 1350
		return ResultUtil.data(attweeklist);
	}
1351

yuquan.zhu committed
1352 1353 1354 1355 1356 1357 1358
	/**
	 * 固定排班特殊日期
	 */
	@GetMapping(value="/AttSpecialDates/{id}")
	@ApiOperation(value = "固定排班特殊日期", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 39)
	public Result<List<SpecialDate>> AttSpecialDatesList(@PathVariable("id") Integer id) {
1359

yuquan.zhu committed
1360
		List<SpecialDate> tesulist = specialdateservice.selectSpecialDatesByKqzid(id);
1361

yuquan.zhu committed
1362 1363
		return ResultUtil.data(tesulist);
	}
1364

lal committed
1365 1366
	@Autowired
	private RealTimeUpdate realtimeupdate;
1367

yuquan.zhu committed
1368 1369 1370 1371 1372 1373 1374
	/**
	 *	 修改考勤基本信息
	 */
	@PutMapping(value = "/BasicAttendanceInformation")
	@ApiOperation(value = "修改考勤信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 40)
	public Result<Void> BasicAttendanceInformation(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
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
		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-开

		attgro.setRestdayclock(attass.getRestdayclock());//休息日打卡

		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());//加班最大时长(自由工时专用)
		}
		attgro.setOvertimeRulesId(attass.getOvertimeRulesId());//加班规则ID
		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);
yuquan.zhu committed
1437
			}
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
		}
		//考勤地址
		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);
yuquan.zhu committed
1450
			}
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
		}
		//考勤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);
yuquan.zhu committed
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
		}
		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){//排班制     考勤组与用户、用户排班
					Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
					if(schedules.length>0) {
						String date = ClockInTool.SunNovCSTYM(schedules[0].getData());

						scheduleservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]),attgrpid,date);
yuquan.zhu committed
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
//						scheduleservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
				}
				userattendancerelservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]),qyid);

				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());//查询考勤机“序列号”

					YgglMainEmp yggluser = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()).eq(YgglMainEmp::getEmpNum, attser[u]));
					String url = mac_command+"/addUserName";
					HttpHeaders headers = new HttpHeaders();
					MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
					params.add("devId", kqj.getCode());
					params.add("userId", attser[u]);
					params.add("userName", yggluser.getName());
					RestTemplate restTemplate = new RestTemplate();
					HttpEntity httpEntity = new HttpEntity(params, headers);
					ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
					System.err.print(request.getBody());

					UserEquiRelation kqjry = userequirelationmapper.selectByuserIdkqjid(Integer.valueOf(attser[u]), kqj.getId());
					if(kqjry == null) {
						KqglAssoYhsb.builder().build().delete(new QueryWrapper<KqglAssoYhsb>().lambda().eq(KqglAssoYhsb::getUserId, attser[u]).eq(KqglAssoYhsb::getKqjid, kqj.getId()));
						//用户与设备关系(考勤机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);
yuquan.zhu committed
1534
						}
1535
						userequirelationmapper.insert(uskqj);
yuquan.zhu committed
1536 1537
					}
				}
1538
				/*****************************************************************************/
yuquan.zhu committed
1539
			}
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
		}
		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);
yuquan.zhu committed
1559
			}
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
		}
		//自由工时 周排班
		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);
yuquan.zhu committed
1570
			}
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
		}
		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【固定排班】
ilal committed
1583
//			String[] attnonpudata = attass.getAttNonPunchData();// 不用打卡的日期【固定排班】
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597

		ResttryfixdayDto[] 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);
yuquan.zhu committed
1598
			}
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
		}
		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].getDate());//日期
				non.setBcid(0);//班次id
				long date = new Date().getTime();
				non.setLusjTime(date);//录入时间
				non.setLuryid(180658);// 录入人员***********
				non.setType(2);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
				non.setLegalday(attnonpudata[n].getWhether());
				speclist.add(non);
yuquan.zhu committed
1612
			}
1613 1614
		}
		if(speclist.size()>0){
1615 1616 1617
			for (SpecialDate specialDate:speclist) {
				specialdateservice.insert(specialDate);
			}
1618 1619 1620
		}

		/**********/
ilal committed
1621
//			scheduleservice.deleteByPrimaryBykqzid(attgrpid);
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638
		/***********/
		//记录排班(排班制)
		List<Schedule> schlist=new ArrayList<Schedule>();
		Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
		if(schedules.length>0 && attass.getAtttype() == 2){

			String date = ClockInTool.SunNovCSTYM(schedules[0].getData());

			scheduleservice.deleteByPrimaryBykqzid(attgrpid,date);

			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);
yuquan.zhu committed
1639
			}
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
		}
		if(schlist.size()>0){
			scheduleservice.insertKqglAssoPbmxList(schlist);
		}


		try {
			realtimeupdate.AttendanceTask(userBean.getOrgCode(), attgrpid, 1,null);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		//		if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
		return ResultUtil.data(null,"修改考勤组信息成功");
		//		}
		//		return ResultUtil.error("修改考勤组信息失败");
yuquan.zhu committed
1656
	}
1657

yuquan.zhu committed
1658 1659
	/*******考勤组--结束*********/

1660

ilal committed
1661
	/***********APP--调用接口开始*****************/
1662 1663


ilal committed
1664 1665
//	@GetMapping(value="/attendancereport")
//	@ApiOperation(value = "获取考勤报表数据", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
1666 1667 1668 1669 1670 1671 1672
	/**
	 * 获取考勤报表数据
	 */
	@PostMapping(value = "/attendancereport")
	@ApiOperation(value = "获取考勤报表数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 41)
	public Result<List<AttendanceReport>> getAttendanceReport(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701


		//考勤报表列表
		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 {
				String sdaet = ClockInTool.getMinMonthDate(attendancedetails.getStart());
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();

				String edate = ClockInTool.getMaxMonthDate(attendancedetails.getEnd());
				endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
yuquan.zhu committed
1702
			}
1703
		}else{
yuquan.zhu committed
1704
			try {
1705
				Calendar c = Calendar.getInstance();
yuquan.zhu committed
1706
				c.add(Calendar.MONTH, 0);
1707
				c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
yuquan.zhu committed
1708
				String first = mat.format(c.getTime());
1709
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
yuquan.zhu committed
1710
				//获取当前月最后一天
1711 1712
				Calendar ca = Calendar.getInstance();
				ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
yuquan.zhu committed
1713
				String last = mat.format(ca.getTime());
1714
				endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
yuquan.zhu committed
1715 1716 1717 1718
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
ilal committed
1719

1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741

		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()),qyid);
			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();
					}
yuquan.zhu committed
1742 1743
				}
			}
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756

			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);//
			/**********/
			AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
yuquan.zhu committed
1757 1758 1759 1760 1761 1762 1763 1764 1765
			//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()];
1766
					int d1 = 0;
yuquan.zhu committed
1767
					for(SpecialDate spe:wxdk){
1768 1769
						appmaps[d1] = spe.getTsrq();
						d1++;
yuquan.zhu committed
1770
					}
1771
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),kqry.getOrgCode());
yuquan.zhu committed
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
					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();
1786 1787 1788 1789
						lastDate.setTime(parse);
						lastDate.set(Calendar.DATE, 1);
						lastDate.add(Calendar.MONTH, 1);
						lastDate.add(Calendar.DATE, -1);
yuquan.zhu committed
1790 1791 1792 1793
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					int y = 0;
1794 1795 1796
					int q = 0;
					for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
						try {
yuquan.zhu committed
1797 1798 1799
							Date date1 = sdf1.parse(yemo + "-" + i);
							for(int u=0;u<week.length;u++){
								if(sdf2.format(date1).equals(week[u])){
1800 1801 1802

									q++;

yuquan.zhu committed
1803 1804 1805 1806 1807 1808 1809 1810 1811
									y++;
									if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
										y = y-1;
									}
								}
							}
						} catch (ParseException c) {
							c.printStackTrace();
						}
1812 1813 1814 1815 1816
					}

					int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
					apr.setRestday(xiuxi);//休息天数
					apr.setAnswerday(y+bxdk);//应出勤
ilal committed
1817
					/***********/
yuquan.zhu committed
1818
				}else if(attgro.getPbfs() == 2){
1819 1820
					List<Schedule> ycqs = scheduleservice.getAttendanceShouldList(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
					int xiuxi = 0;
yuquan.zhu committed
1821 1822
					int shangban = 0;
					for(Schedule sc : ycqs){
1823 1824 1825
						if(sc.getBcid().equals(0)){
							xiuxi++;
						}else{
yuquan.zhu committed
1826 1827 1828
							shangban++;
						}
					}
1829 1830 1831
					//					System.out.println(xiuxi);
					apr.setRestday(xiuxi);//休息天数
					apr.setAnswerday(shangban);//应出勤
yuquan.zhu committed
1832
				}else{
1833
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),kqry.getOrgCode());
yuquan.zhu committed
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
					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();
1848 1849 1850 1851
						lastDate.setTime(parse);
						lastDate.set(Calendar.DATE, 1);
						lastDate.add(Calendar.MONTH, 1);
						lastDate.add(Calendar.DATE, -1);
yuquan.zhu committed
1852 1853 1854 1855
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					int y = 0;
1856 1857
					for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
						try {
yuquan.zhu committed
1858 1859 1860 1861 1862 1863 1864 1865 1866
							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();
						}
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
					}

					int xiuxi = getDaysByYearMonth(year,month) - y;
					apr.setRestday(xiuxi);//休息天数
					apr.setAnswerday(y);//应出勤
				}
				List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate,qyid);//打卡记录
				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);//缺勤
yuquan.zhu committed
1880
				}
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
				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++;
						}
					}
yuquan.zhu committed
1908
				}
1909 1910
				apr.setGoworkmissingcard(sbqk);//上班缺卡
				apr.setOffworkmissingcard(xbqk);//下班缺卡
yuquan.zhu committed
1911
			}
1912 1913 1914
			/**********/


ilal committed
1915

1916 1917 1918 1919 1920
			attrep.add(apr);
		}


		return ResultUtil.data(attrep);
yuquan.zhu committed
1921
	}
1922 1923 1924 1925 1926 1927






yuquan.zhu committed
1928
	/**
1929
	 * 获取考勤详情
yuquan.zhu committed
1930
	 */
1931 1932 1933 1934
	@GetMapping(value="/attendancedetails")
	@ApiOperation(value = "获取考勤详情数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 42)
	public Result<List<PunchCardDetails>> getAttendanceDetails(@CurrentUser UserBean userBean) {
yuquan.zhu committed
1935
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
		int userid = userBean.getEmpNum();//用户id

		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();
yuquan.zhu committed
1953
		}
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982

		List<PunchCardDetails> attdetails = punchcarddetailsservice.SelectAttendanceDetails(qyid,starttime,endtime);


		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】
		int userid = userBean.getEmpNum();//用户id
		attendancedetails.setQyid(qyid);

		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("");
yuquan.zhu committed
1983
			}
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 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 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 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 2340 2341 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 2376 2377 2378 2379 2380 2381
		} catch (ParseException e) {
			e.printStackTrace();
		}


		List<PunchCardDetails> kqxqlist = punchcarddetailsservice.QueryAttendanceDetails(attendancedetails);

		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】
		int userid = userBean.getEmpNum();//用户id

		List<PunchRecord> origattreclist = punchrecordservice.selectOriginalAttendanceRecord(qyid);

		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】
		int userid = userBean.getEmpNum();//用户id
		attendancedetails.setQyid(qyid);

		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();
		}

		List<PunchRecord> original = punchrecordservice.selFuzzyOriginalAttendance(attendancedetails);

		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) {

		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{
				//attendancedetails.setStart("");
				//attendancedetails.setEnd("");
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

		List<PunchRecord> detail = punchrecordservice.ViewAttendanceDetails(starttime,endtime,userid);

		return ResultUtil.data(detail);
	}

	/**
	 * 获取考勤日历出勤数据
	 */
//	@GetMapping(value = "/AttOriginalRecord")
//	@ApiOperation(value = "获取考勤日历数据", httpMethod = "GET", notes = "接口发布说明")
	@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();//考勤日历显示数据

		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		int userid = userBean.getEmpNum();//用户id

		String str = null;

		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);
		}

		Long startDate = 0l;
		Long endDate = 0l;

		if(!("").equals(atttions.getDate())){
			try {
				String sdaet = ClockInTool.getMinMonthDate(str);
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();

				String edate = ClockInTool.getMaxMonthDate(str);
				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();
			}
		}

		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		//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 d = 0;
				for(SpecialDate spe:wxdk){
					appmaps[d] = spe.getTsrq();
					d++;
				}

				List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid,qyid);
				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;
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
					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();
					}
				}

				attcal.setAttshouldmade(y+bxdk);//应出勤
				/***********/

			}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{

				List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(userid,qyid);
				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;
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
					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();
					}
				}

				attcal.setAttshouldmade(y);//应出勤
			}

			List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(userid, startDate, endDate,qyid);//打卡记录
			attcal.setAttendance(attendance.size());//已出勤


			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);//缺勤
			}


			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);//下班缺卡



		}
		return ResultUtil.data(attcal);

	}

	/********************************************************************************************************************************************************************************************************************************************************************************/
	/****************************************************************************	APP--调用接口结束	*****************************************************************************************************************************************************************************/
	/********************************************************************************************************************************************************************************************************************************************************************************/

	/**
	 * 根据 年、月 获取对应的月份 的 天数
	 */
	public static int getDaysByYearMonth(int year, int month)
	{
		Calendar a = Calendar.getInstance();
		a.set(Calendar.YEAR, year);
		a.set(Calendar.MONTH, month - 1);
		a.set(Calendar.DATE, 1);
		a.roll(Calendar.DATE, -1);
		int maxDate = a.get(Calendar.DATE);
		return maxDate;
	}



	/**
	 * 	获取考勤日历显示出勤详细数据
	 */
	@SuppressWarnings("deprecation")
	@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

		Date dno = new Date();
		SimpleDateFormat sdfno = new SimpleDateFormat("yyyy-MM-dd");
		String now = sdfno.format(dno);

//		int userid =  600135;//马丹丹//600126;//肖丽思

		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);
		}

		Long startDate = 0l;
		Long endDate = 0l;

		if(!("").equals(attconditions.getDate())){
			try {
				String sdaet = ClockInTool.getMinMonthDate(str);
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();

				String edate = ClockInTool.getMaxMonthDate(str);
				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();
yuquan.zhu committed
2382 2383
			}
		}
2384

Yl123 committed
2385
		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
2386

yuquan.zhu committed
2387 2388
		//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		if(attgro != null){//该员工是否加入到考勤组
2389

yuquan.zhu committed
2390 2391
			if(attgro.getPbfs() == 1){//固定排班
				String yemo = year + "-" + month;
2392

yuquan.zhu committed
2393 2394
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
2395

yuquan.zhu committed
2396
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
2397

ilal committed
2398
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
					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);
2411

yuquan.zhu committed
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437
					//日历提醒事务
					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);
						}
					}
2438 2439


yuquan.zhu committed
2440 2441 2442 2443 2444 2445 2446 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
					//考勤打卡原始记录
					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);
						}
					}
2473

lal committed
2474
					int week = Integer.valueOf(ClockInTool.dateToWeek(famt.format(da)));//2
2475 2476 2477 2478 2479 2480 2481 2482 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 2513 2514 2515
					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);
						}
					}
yuquan.zhu committed
2516 2517
					dss.add(ss);
				}
2518

yuquan.zhu committed
2519
				return ResultUtil.data(dss);
2520 2521


yuquan.zhu committed
2522
			}else if(attgro.getPbfs() == 2){//自由排班
2523

yuquan.zhu committed
2524 2525 2526 2527
				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);//打卡数据
2528

yuquan.zhu committed
2529
				String[] array1 = new String[callist.size()];
2530

yuquan.zhu committed
2531
				String[] erinnern1 = new String[rltilist.size()];
2532

yuquan.zhu committed
2533
				int r = 0;
2534

yuquan.zhu committed
2535 2536 2537 2538 2539 2540 2541 2542 2543
				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++;
2544

yuquan.zhu committed
2545 2546
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
2547
					int q = 0;
yuquan.zhu committed
2548 2549 2550
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = sdu.getData();//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
2551

yuquan.zhu committed
2552
						System.out.println(q+"--"+punchtime);
2553

yuquan.zhu committed
2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576
						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);
						}
					}
2577

yuquan.zhu committed
2578 2579
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
ilal committed
2580
//						String schetime = mat.format(new Date(sdu.getData().toString()));//排班详细数据日期
yuquan.zhu committed
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610
						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);
						}
					}
2611 2612


yuquan.zhu committed
2613
					ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(sdu.getBcid());
2614

ilal committed
2615
					/*********/
yuquan.zhu committed
2616 2617 2618 2619 2620 2621 2622 2623
					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
2624 2625 2626
									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
2627 2628 2629 2630 2631
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(2);
lal committed
2632 2633 2634
									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
2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645
									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
2646 2647 2648
									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
2649 2650 2651 2652 2653
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(4);
lal committed
2654 2655 2656
									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
2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667
									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
2668 2669 2670
									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
2671 2672 2673 2674 2675
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(6);
lal committed
2676 2677 2678
									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
2679 2680 2681 2682 2683 2684 2685
									atts.add(as);
								}
							}
							ss.setAttsch(atts);
						}
					}else{
						List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
2686 2687 2688 2689 2690 2691 2692 2693
						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);
yuquan.zhu committed
2694
					}
ilal committed
2695
					/*******/
2696

yuquan.zhu committed
2697 2698
					dss.add(ss);
				}
2699

yuquan.zhu committed
2700
				String yemo = year + "-" + month;
ilal committed
2701
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2702 2703 2704 2705 2706 2707
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
2708 2709 2710 2711




yuquan.zhu committed
2712
				}
2713 2714 2715 2716 2717 2718



//				String[] array1 = {"2019-11-10","2019-11-12","2019-11-13"};
//		        String[] array2 = {"2019-11-10","2019-11-14"};

ilal committed
2719
				List<String> erilist = compare(array1,erinnern1);  //缺少的天数
2720 2721 2722 2723
				String[] eris=erilist.toArray(new String[erilist.size()]);//缺少的具体天数(yyyy-mm-dd)

				String[] eridadys = array_unique(eris);

yuquan.zhu committed
2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758
				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);
				}
2759 2760 2761 2762 2763





yuquan.zhu committed
2764 2765 2766 2767 2768 2769
				//打卡记录
				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();
				}
2770 2771 2772

				List<String> list = compare(array1,array2);
				String[] dadys=list.toArray(new String[list.size()]);
yuquan.zhu committed
2773 2774 2775 2776 2777 2778 2779
				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);
2780

yuquan.zhu committed
2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814
					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);
				}
2815

yuquan.zhu committed
2816
				return ResultUtil.data(dss);
2817

yuquan.zhu committed
2818 2819
			}else{//自由工时
				String yemo = year + "-" + month;
2820

yuquan.zhu committed
2821
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
2822

yuquan.zhu committed
2823 2824
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
ilal committed
2825
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
yuquan.zhu committed
2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837
					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);
2838

yuquan.zhu committed
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864
					//日历提醒事务
					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);
						}
					}
2865

yuquan.zhu committed
2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897
					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);
						}
					}
2898

lal committed
2899
					int week = Integer.valueOf(ClockInTool.dateToWeek(famt.format(da)));//2
yuquan.zhu committed
2900
					AttendanceWeeklySch atwek = attendanceweeklyschservice.selectFreeWorkingHours(attgro.getId(),week);//自由工时
2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931


					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);
						}
					}

yuquan.zhu committed
2932 2933
					dss.add(ss);
				}
2934 2935 2936



yuquan.zhu committed
2937 2938 2939
				return ResultUtil.data(dss);
			}
		}
2940

yuquan.zhu committed
2941 2942
		return ResultUtil.data(null);
	}
2943

ilal committed
2944 2945
//	 @GetMapping(value = "/ClockData")
//	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
yuquan.zhu committed
2946 2947 2948
	/**
	 * 获取考勤打卡数据------APP打卡
	 */
2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
	@PostMapping(value = "/ClockData")
	@ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 49)
	public Result<AttendanceCardList> getAttClockData(@CurrentUser UserBean userBean,@RequestBody AttConditions attconditions) {

		AttendanceCardList attcar = new AttendanceCardList();

		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);
		}

		Long startDate = 0l;
		Long endDate = 0l;
		try {
yuquan.zhu committed
2968 2969
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991
		} catch (ParseException e) {
			e.printStackTrace();
		}
		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);//固定周排班

			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【特殊日期--休息】
lal committed
2992
						List<AttSchedule> atts = new ArrayList<AttSchedule>();
2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059
						AttSchedule as = new AttSchedule();
						as.setId(0);
						as.setSort(0);//0:表示今天为休息日
						as.setTime(0l);
						as.setStarttime(0l);
						as.setEndtime(0l);
						atts.add(as);
						attcar.setAttsch(atts);
					}else{//今天上班
						ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
						if(bcz != null){
							Getshiftinformationbatch(bcz,attcar,str);
						}
					}
				}else{
					//必须打卡
					SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), str);//判断特殊日期
					if(tsri != null){
						ShiftManagement tsrq = shiftmanagementservice.selectByPrimaryKey(tsri.getBcid());
						if(tsrq!=null){
							Getshiftinformationbatch(tsrq,attcar,str);
						}
					}else{
						//休息
						List<AttSchedule> atts = new ArrayList<AttSchedule>();
						AttSchedule as = new AttSchedule();
						as.setId(0);
						as.setSort(0);//0:表示今天为休息日
						as.setTime(0l);
						as.setStarttime(0l);
						as.setEndtime(0l);
						atts.add(as);
						attcar.setAttsch(atts);
					}
				}

			}else if(attgro.getPbfs() == 2){//自由排班

				//未排班时,员工可选择班次打卡
				if(attgro.getIsXzbcdk() == 1){
					attcar.setOptscheduling(true);
				}else{
					attcar.setOptscheduling(false);
				}

				//				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
3060
								}
lal committed
3061
							}
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081
							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
3082
								}
lal committed
3083
							}
3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103
							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
3104 3105
								}
							}
3106
							attcar.setAttsch(atts);
yuquan.zhu committed
3107
						}
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
					}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
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
				}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);//无排班时 获取的系统班次
				}

			}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);// 下班不用打卡
lal committed
3172
					}
3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201
					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);// 晚走晚到
lal committed
3202 3203
					}
				}
yuquan.zhu committed
3204
			}
3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349

			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);//无排班时 获取的系统班次

			attcar.setAttgrouptype(0);//1:固定排班;2:自由排班;3:自由工时
		}

		//打卡记录
		List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
		attcar.setAttpr(dajllist);

		return ResultUtil.data(attcar);

	}

	/**
	 * ??????
	 */
	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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(2);
					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")));
					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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(4);
					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")));
					atts.add(as);
yuquan.zhu committed
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 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
			}
			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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(6);
					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")));
					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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(2);
					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")));
					atts.add(as);
yuquan.zhu committed
3399
				}
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420
			}
			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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(4);
					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")));
					atts.add(as);
yuquan.zhu committed
3421 3422
				}
			}
3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442
			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);
					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")));
					atts.add(as);
				}else{
					AttSchedule as = new AttSchedule();
					as.setId(shiftm.getId());
					as.setSort(6);
					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")));
					atts.add(as);
yuquan.zhu committed
3443 3444
				}
			}
3445 3446 3447 3448 3449 3450 3451 3452 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
			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();
		}

		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		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){
				sbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk1()+":00"));
				xbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk1()+":00"));
			}
			if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
				sbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk2()+":00"));
				xbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk2()+":00"));
			}
			if(banci.getSxbcs()== 3){
				sbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk3()+":00"));
				xbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk3()+":00"));
			}
		}
		//之前打卡的班次
		PunchRecord mapuca = punchrecordservice.MaintenancePunchCard(startCorrDate,endCorrDate,userid);

		if(mapuca != null && !id.equals(mapuca.getBcid())){
			List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid,qyid);
			if(initial.size() > 0){
				RestMethod(initial,initial.get(0).getDkmxid());
			}
		}

		//当天的所有打卡记录
		List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid,qyid);
		PunchRecord minAttid = null;
		PunchRecord maxAttid = null;
		int dkmxid = 0;
		if(mapucalist.size() > 0){
			//最小值
			minAttid = mapucalist.stream().min(Comparator.comparing(PunchRecord::getId)).get();
ilal committed
3542
//		        System.out.println(minAttid.getAttdate() +  "---min---" +minAttid.getId());
3543 3544
			//最大值
			maxAttid = mapucalist.stream().max(Comparator.comparing(PunchRecord::getId)).get();
ilal committed
3545
//		        System.out.println(maxAttid.getAttdate() +  "---max---" + maxAttid.getId());
3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557

			//对应打卡明细表id
			dkmxid = maxAttid.getDkmxid();
		}

		//当天有打卡记录且当天打卡班次和当前修改后的班次不匹配再进行重新维护
		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()){//去除最大和最小 其他均改为“打卡无效:此记录已被更新”
yuquan.zhu committed
3558
								PunchRecord record = new PunchRecord();
3559 3560 3561 3562 3563
								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;
yuquan.zhu committed
3564 3565 3566 3567 3568
									if(time > 0){
										record.setResults(Integer.valueOf(time.toString()));// 打卡结果
									}else{
										record.setResults(0);// 打卡结果
									}
3569 3570 3571
									record.setAttime(sbdk1);//上班应打卡时间
								}else{//下班
									Long time = (pre.getDktime() - xbdk1)/1000/60;
yuquan.zhu committed
3572 3573 3574 3575 3576
									if(time > 0){
										record.setResults(0);// 打卡结果
									}else{
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
3577
									record.setAttime(xbdk1);//下班应打卡时间
yuquan.zhu committed
3578 3579 3580
								}
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
3581 3582
							}else{
								if(pre.getId() == minAttid.getId()){//上班
yuquan.zhu committed
3583
									PunchRecord record = new PunchRecord();
3584 3585 3586
									record.setId(pre.getId());
									record.setType(1);//上班
									Long time = (pre.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
3587 3588 3589 3590 3591 3592 3593 3594 3595 3596
									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);
3597
								}else if(pre.getId() == maxAttid.getId()){//下班
yuquan.zhu committed
3598
									PunchRecord record = new PunchRecord();
3599
									record.setId(pre.getId());
yuquan.zhu committed
3600
									record.setType(2);//下班
3601
									Long time = (pre.getDktime() - xbdk1)/1000/60;
yuquan.zhu committed
3602 3603 3604 3605 3606 3607 3608
									if(time > 0){
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}else{
										record.setStatus(4);
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
3609
									record.setAttime(xbdk1);
yuquan.zhu committed
3610
									record.setBcid(banci.getId());//班次id
3611
									record.setSort(2);
yuquan.zhu committed
3612 3613 3614
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
							}
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
						}
						//修改打卡明细
						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);// 打卡结果
yuquan.zhu committed
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
							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());//上班
yuquan.zhu committed
3710
								PunchRecord record = new PunchRecord();
3711 3712 3713
								record.setId(mapucalist.get(y).getId());
//									record.setType(1);//上班
								Long time = (mindata.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
3714 3715 3716 3717 3718 3719 3720
								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);// 打卡结果
								}
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
								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());
								}

yuquan.zhu committed
3755 3756 3757
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
							}
3758 3759 3760 3761


							PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
							if(mapucalist.get(y).getId() == maxdata.getId()){//下班
yuquan.zhu committed
3762
								PunchRecord record = new PunchRecord();
3763 3764 3765 3766

								record.setId(maxdata.getId());
								record.setType(2);//下班
								Long time = (maxdata.getDktime() - xbdk2)/1000/60;
yuquan.zhu committed
3767 3768 3769 3770 3771 3772 3773
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
3774 3775
								record.setSort(4);
								record.setAttime(xbdk2);
yuquan.zhu committed
3776 3777
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
3778 3779

								scstr[2] = String.valueOf(maxdata.getId());
yuquan.zhu committed
3780
							}
3781 3782

							if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
yuquan.zhu committed
3783
								PunchRecord record = new PunchRecord();
3784 3785 3786 3787 3788
								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());//上班应打卡时间
yuquan.zhu committed
3789 3790 3791
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
							}
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
						}

						//修改打卡明细
						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());//上班
yuquan.zhu committed
3937
								PunchRecord record = new PunchRecord();
3938 3939
								record.setId(mapucalist.get(y).getId());
								Long time = (mindata.getDktime() - sbdk1)/1000/60;
yuquan.zhu committed
3940 3941 3942 3943 3944 3945 3946
								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);// 打卡结果
								}
3947
								record.setAttime(sbdk1);
yuquan.zhu committed
3948 3949 3950
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
							}
3951
							if(y == 1 || y == 2 || y == 3 || y == 4){
yuquan.zhu committed
3952
								PunchRecord record = new PunchRecord();
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
								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());
									}
yuquan.zhu committed
4008 4009 4010 4011
								}
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
							}
4012 4013 4014 4015


							PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
							if(mapucalist.get(y).getId() == maxdata.getId()){//下班
yuquan.zhu committed
4016
								PunchRecord record = new PunchRecord();
4017 4018 4019 4020

								record.setId(maxdata.getId());
								record.setType(2);//下班
								Long time = (maxdata.getDktime() - xbdk3)/1000/60;
yuquan.zhu committed
4021 4022 4023 4024 4025 4026 4027
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042
								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());//上班应打卡时间
yuquan.zhu committed
4043 4044 4045 4046
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
							}
						}
4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 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 4274 4275 4276 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 4312 4313 4314 4315

						//修改打卡明细
						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);
			}
		}

		/***********************/


		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);
						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")));
						atts.add(as);
					}else{
						AttSchedule as = new AttSchedule();
						as.setId(shifs.getId());
						as.setSort(2);
						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")));
						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);
						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")));
						atts.add(as);
					}else{
						AttSchedule as = new AttSchedule();
						as.setId(shifs.getId());
						as.setSort(4);
						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")));
						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);
						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")));
						atts.add(as);
					}else{
						AttSchedule as = new AttSchedule();
						as.setId(shifs.getId());
						as.setSort(6);
						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")));
						atts.add(as);
yuquan.zhu committed
4316 4317
					}
				}
4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354
				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);// 晚走晚到
yuquan.zhu committed
4355
			}
4356
		}
yuquan.zhu committed
4357
		//打卡记录
4358 4359 4360
		List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
		shde.setAttpr(dajllist);

yuquan.zhu committed
4361
		return ResultUtil.data(shde);
4362 4363 4364
	}

	/**
4365
	 * @param remind
yuquan.zhu committed
4366 4367
	 * @return 日历提醒
	 */
4368 4369 4370 4371 4372 4373 4374
	@PostMapping(value = "/Attendancecalendar")
	@ApiOperation(value = "日历提醒", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 51)
	public Result<CalendarAlarm> AttendanceCalendar(@CurrentUser UserBean userBean,@RequestBody ReminderAuxiliary remind) {
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		int userid = userBean.getEmpNum();//用户id

yuquan.zhu committed
4375 4376 4377 4378 4379 4380 4381 4382
		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());// 内容
4383

yuquan.zhu committed
4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396
		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 {
4397
				return ResultUtil.error("修改失败");
yuquan.zhu committed
4398 4399 4400 4401 4402 4403 4404
			}
		}else{
			cal.setState(1);// 状态(0:未完成,1:已完成,2:已过期)
			cal.setId(remind.getId());//
			if (calendaralarmservice.updateByPrimaryKeySelective(cal) > 0) {
				return ResultUtil.data(cal,"标记成功");
			}else {
4405
				return ResultUtil.error("标记失败");
yuquan.zhu committed
4406 4407
			}
		}
4408 4409 4410
	}


yuquan.zhu committed
4411 4412 4413 4414 4415 4416 4417
	/**
	 * 	删除日历提醒信息
	 */
	@DeleteMapping(value = "/CalendarAlarm/{id}")
	@ApiOperation(value = "删除日历提醒信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 52)
	public Result<Integer> deleteCalendarAlarm(@PathVariable("id") Integer id) {
4418

yuquan.zhu committed
4419 4420 4421 4422 4423
		if (calendaralarmservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441

	/**
	 * 	考勤打卡------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

		AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid,qyid); //考勤组信息
		//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时

		String putime = new SimpleDateFormat("yyyy-MM-dd").format(Double.valueOf(clock.getPunchtime()));//转换打卡时间格式
		Long startDate = 0l;//打卡当天开始时间
		Long endDate = 0l;//打卡当天结束时间
		try {
yuquan.zhu committed
4442 4443
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456
		} 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){//有记录就修改之前的
yuquan.zhu committed
4457
			//修改
4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470
			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){
yuquan.zhu committed
4471
							pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
4472
						}else{
yuquan.zhu committed
4473
							pcd.setSbdk1jg(0);// 打卡结果
4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486
						}
					}
					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{
yuquan.zhu committed
4487
							pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
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
						}
					}
				}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打卡结果
						}
yuquan.zhu committed
4556

4557 4558
					}
				}else{
yuquan.zhu committed
4559 4560
					if(clock.getDiffer() == 1){//打卡
						return ResultUtil.error("重复打卡");
4561
					}else{
yuquan.zhu committed
4562
						pcd.setId(dkmc.getId());
4563
						pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
yuquan.zhu committed
4564 4565 4566
						if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							if(time > 0){
4567 4568 4569 4570
								pcd.setXbdk2jg(0);// 打卡结果
							}else{
								pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
							}
yuquan.zhu committed
4571
						}
4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650
						//班次为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);
yuquan.zhu committed
4651 4652 4653
						}
						punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					}
4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701
				}
				//班次为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{
yuquan.zhu committed
4702
							pcd.setSbdk2jg(0);// 打卡结果
4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751
						}
					}
				}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();
			}
		}



		//打卡记录
		if(clock.getDiffer() == 2){//更新打卡
yuquan.zhu committed
4752 4753 4754 4755 4756 4757 4758 4759 4760 4761
			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("打卡失败");
			}
4762 4763
		}

yuquan.zhu committed
4764 4765 4766 4767 4768 4769 4770
		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());// 定位地址
		}
4771

yuquan.zhu committed
4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789
		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())));// 打卡结果
				}
			}
		}
4790

yuquan.zhu committed
4791 4792 4793
		pre.setUserId(userid);// 用户id
		if((clock.getType())%2 > 0){
			pre.setType(1);// 类型(类型 0:无排班打卡 1:上班 2:下班)
4794

yuquan.zhu committed
4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825
			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
4826
		pre.setAttdate(attdate_+" "+ClockInTool.dateToWeek2(putime));// 考勤日期
4827

yuquan.zhu committed
4828 4829
		long date = new Date().getTime();
		if(("0").equals(clock.getPunchcardtime())){
4830
			pre.setAttime(date);// 考勤时间(应打卡时间)
yuquan.zhu committed
4831 4832 4833
		}else{
			pre.setAttime(Long.valueOf(clock.getPunchcardtime()));// 考勤时间(应打卡时间)
		}
4834

yuquan.zhu committed
4835 4836 4837
		pre.setDkmxid(dkmx);// 打卡明细id
		pre.setBcid(clock.getShifid());// 班次id
		punchrecordservice.insertSelective(pre);//新增打卡记录
4838 4839 4840



ilal committed
4841
//		if(shiftmanagementservice.insertSelective(shif)>0){
4842
		return ResultUtil.data(null,"打卡成功");
ilal committed
4843 4844 4845
//		}else{
//			return ResultUtil.error("新增班次失败");
//		}
4846 4847 4848 4849 4850 4851
	}

	/************************************************************************************************************************************/
	/***************************************************工具方法区***************************************************************************/
	/************************************************************************************************************************************/

ilal committed
4852 4853 4854 4855 4856 4857
	/**
	 * 对比两个字符串数组
	 * @param t1
	 * @param t2
	 * @return
	 */
4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868
	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;
	}

ilal committed
4869 4870 4871 4872 4873
	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]);
	}
4874 4875


yuquan.zhu committed
4876 4877 4878
	/**
	 * 	考勤机一键同步
	 */
lal committed
4879 4880 4881 4882 4883
//	@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();
4884
//
lal committed
4885
//		List<UserAttendanceRel> member = userattendancerelservice.selectAttNotMember(id,orgCode);
4886
//
lal committed
4887
//		AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(id);//查询考勤机“序列号”
4888
//
lal committed
4889
//		for(UserAttendanceRel usmer:member) {
4890
//
lal committed
4891 4892
//			YgglMainEmp user = new LambdaQueryChainWrapper<YgglMainEmp>(ygglmainempmapper).eq(YgglMainEmp::getEmpNum, usmer.getUserid())
//					.eq(YgglMainEmp::getOrgCode, orgCode).one();
4893
//
lal committed
4894 4895 4896 4897 4898
//			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();
4899
//
lal committed
4900
//			String url = mac_command;
lal committed
4901 4902 4903 4904 4905 4906 4907 4908
//	        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);
4909 4910 4911
//
//
//
lal committed
4912 4913 4914 4915 4916 4917
//	      //用户与设备关系(考勤机id-->用户id)
//			UserEquiRelation uskqj = new UserEquiRelation();
//			uskqj.setUserId(usmer.getUserid());//用户id
//			uskqj.setKqjid(kqj.getId());//设备id
//			uskqj.setType(1);//类型(类型 1:考勤机)
//			uskqj.setIsGly(0);
4918
//
lal committed
4919
//			userequirelationmapper.insert(uskqj);
4920
//
lal committed
4921
//		}
4922
//
lal committed
4923 4924
//		return ResultUtil.success("成功");
//	}
4925
//
yuquan.zhu committed
4926 4927 4928 4929 4930 4931 4932
	/**
	 * 	获取报表汇总
	 */
	@PostMapping(value = "/reportsummary")
	@ApiOperation(value = "获取报表汇总", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 56)
	public Result<List<AttendanceReport>> ReportSummary(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960

		//考勤报表列表
		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 {
				String sdaet = ClockInTool.getMinMonthDate(attendancedetails.getStart());
				startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();

				String edate = ClockInTool.getMaxMonthDate(attendancedetails.getEnd());
				endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
yuquan.zhu committed
4961
			}
4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999
		}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()),qyid);
			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();
yuquan.zhu committed
5000 5001
					}
				}
5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054
			}

			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);//
			/**********/
			AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum()),qyid); //考勤组信息
			//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
			if(attgro != null){//该员工是否加入到考勤组
				if(attgro.getPbfs() == 1){
					//当前月     必须打卡日期
					List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
					int bxdk = bxdklist.size();
					//当前月     无需打卡日期
					List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
					String[] appmaps= new String[wxdk.size()];
					int d1 = 0;
					for(SpecialDate spe:wxdk){
						appmaps[d1] = spe.getTsrq();
						d1++;
					}
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),qyid);
					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;
					for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
5055
						try {
5056 5057 5058 5059 5060 5061 5062 5063 5064
							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;
yuquan.zhu committed
5065 5066 5067
									}
								}
							}
5068 5069
						} catch (ParseException c) {
							c.printStackTrace();
yuquan.zhu committed
5070
						}
5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085
					}

					int xiuxi = getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
					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++;
yuquan.zhu committed
5086
						}
5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115
					}
					//					System.out.println(xiuxi);
					apr.setRestday(xiuxi);//休息天数
					apr.setAnswerday(shangban);//应出勤
				}else{
					List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()),qyid);
					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;
					for(int i = 1; i <= getDaysByYearMonth(year,month); i++){
yuquan.zhu committed
5116
						try {
5117 5118 5119 5120
							Date date1 = sdf1.parse(yemo + "-" + i);
							for(int u=0;u<week.length;u++){
								if(sdf2.format(date1).equals(week[u])){
									y++;
yuquan.zhu committed
5121 5122
								}
							}
5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157
						} catch (ParseException c) {
							c.printStackTrace();
						}
					}

					int xiuxi = getDaysByYearMonth(year,month) - y;
					apr.setRestday(xiuxi);//休息天数
					apr.setAnswerday(y);//应出勤
				}
				List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate,qyid);//打卡记录
				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++;
						}
yuquan.zhu committed
5158
					}
5159 5160 5161 5162 5163 5164 5165
					if(pcd.getYdkcs() == 6){
						if(pcd.getSbdk3() == null){
							sbqk++;
						}
						if(pcd.getXbdk3() == null){
							xbqk++;
						}
yuquan.zhu committed
5166 5167
					}
				}
5168 5169
				apr.setGoworkmissingcard(sbqk);//上班缺卡
				apr.setOffworkmissingcard(xbqk);//下班缺卡
yuquan.zhu committed
5170
			}
5171 5172 5173 5174 5175 5176 5177 5178
			/**********/



			attrep.add(apr);
		}


ilal committed
5179
//			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
5180 5181 5182 5183 5184 5185 5186 5187
		int attshouldmade = 0;//应出勤
		for(AttendanceReport reps:attrep) {
			System.out.println(reps.getAnswerday());
		}



		return ResultUtil.data(attrep);
yuquan.zhu committed
5188
	}
5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070



	@Autowired
	private KqglAssoDkjlService kqglAssoDkjlService;

	/**
	 * 修改考勤组排班(修改排班后,需判断是否有打卡记录,有则匹配当天修改后的班次,无则不需要修改)
	 * 接口优化
	 */
	@SuppressWarnings({ "unused", "deprecation" })
	@PutMapping(value = "/v2.0/attscheduling")
	@ApiOperationSupport(order = 57)
	@ApiOperation(value = "修改班次信息", httpMethod = "PUT", notes = "接口发布说明")
	public Result<List<Schedule>> updateAttschedulingv2(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
		long startTime = System.currentTimeMillis();
		int id = Integer.valueOf(attass.getAttgroupid());//修改数据id

		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		int userid = userBean.getEmpNum();//用户id

		String dastr = new SimpleDateFormat("yyyy-MM").format(new Date()).toString();//

		AttendanceGroup qttgrop = attendancegroupservice.selectByPrimaryKey(Integer.valueOf(attass.getAttgroupid()));
		boolean xiugai = true;
		//记录排班(排班制)
		List<Schedule> schlist=new ArrayList<Schedule>();
		Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
		String date_scmx = null;

		if(schedules.length>0 && attass.getAtttype() == 2){

			date_scmx = ClockInTool.SunNovCSTYM(schedules[0].getData());

			String date = String.valueOf(schedules[0].getData());
			Date dt=new Date(date);
			SimpleDateFormat famt = new SimpleDateFormat("yyyy-MM");
			System.out.println(famt.format(dt));

			if(!(famt.format(dt)).equals(dastr)) {

				xiugai = false;
				for(int p=0;p<schedules.length;p++){
//						scheduleservice.deleteByPrimaryBykqzid(Integer.valueOf(attass.getAttgroupid()),ClockInTool.SunNovCST(String.valueOf(schedules[p].getData())));

					KqglAssoPbmx.builder().build().delete(new QueryWrapper<KqglAssoPbmx>().lambda().eq(KqglAssoPbmx::getUserid, schedules[p].getUserid()).eq(KqglAssoPbmx::getData, ClockInTool.SunNovCST(String.valueOf(schedules[p].getData())))
							.eq(KqglAssoPbmx::getKqzid, Integer.valueOf(attass.getAttgroupid())));

					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);
				}
				if(schlist.size()>0){
					scheduleservice.insertKqglAssoPbmxList(schlist);
				}
			}else {
				xiugai = true;
				List<PunchRecord> punchRecordList = new ArrayList<>();
				List<PunchCardDetails> punchCardDetailsList = new ArrayList<>();
				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){
							sbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk1()+":00"));
							xbdk1 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk1()+":00"));
						}
						if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
							sbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk2()+":00"));
							xbdk2 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk2()+":00"));
						}
						if(banci.getSxbcs()== 3){
							sbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getSbdk3()+":00"));
							xbdk3 = Long.valueOf(ClockInTool.dateToStamp(data+" "+banci.getXbdk3()+":00"));
						}
					}
					//之前打卡的班次
					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(),qyid);
						if(initial.size() > 0){
							RestMethod(initial,initial.get(0).getDkmxid());
						}
					}


					//当天的所有打卡记录
					List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,schedules[p].getUserid(),qyid);
					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
											punchRecordList.add(record);
											//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
												punchRecordList.add(record);
												//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);
												punchRecordList.add(record);
												//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));
									punchCardDetailsList.add(max);
									//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
										punchRecordList.add(record);
										//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"));
										punchCardDetailsList.add(dan);
//										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);
										punchRecordList.add(record);
										punchRecordList.add(record);
										//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));
										punchCardDetailsList.add(max);

//										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
											punchRecordList.add(record);
											//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
											punchRecordList.add(record);
											//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
											punchRecordList.add(record);
											//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
											punchRecordList.add(record);
											//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));

										punchCardDetailsList.add(dkmx);
//										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
										punchRecordList.add(record);
//										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"));
										punchCardDetailsList.add(dan);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk2(dtdkmx.getDktime());
										pcd.setXbdk2jg(dtdkmx.getResults());
									}

									pcd.setId(dkmxid);
									punchCardDetailsList.add(pcd);
//									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
											punchRecordList.add(record);
//											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
											punchRecordList.add(record);
//											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
											punchRecordList.add(record);
//											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
											punchRecordList.add(record);
//											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));
										punchCardDetailsList.add(dkmx);
//										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
										punchRecordList.add(record);
//										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"));
										punchCardDetailsList.add(dan);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										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
										punchRecordList.add(record);
//										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk3(dtdkmx.getDktime());
										pcd.setXbdk3jg(dtdkmx.getResults());
									}

									pcd.setId(dkmxid);
									punchCardDetailsList.add(pcd);
//									punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
									/**bbb***/
								}
							}
						}else{////修改后班次为休息的
							RestMethod(mapucalist,dkmxid);
						}
					}

					/***********************/
				}
				// 打卡记录修改批处理
				kqglAssoDkjlService.updateKqglAssoDkjlById(punchRecordList);
				// 打卡明细修改批处理
				kqglAssoDkjlService.updateKqglAssoDkmxById(punchCardDetailsList);
			}//判断新增或修改
		}
		long endTime = System.currentTimeMillis();
		log.info("=======================================执行时长(毫秒):{}",endTime-startTime);
		if(schlist.size()>0 && xiugai){
			//删除排班明细表(自由排班)
//				scheduleservice.deleteByPrimaryBykqzid(id);

			scheduleservice.deleteByPrimaryBykqzid(id,date_scmx);

			scheduleservice.insertKqglAssoPbmxList(schlist);
			return ResultUtil.data(schlist,"修改考勤组排班成功");
		}
		return ResultUtil.data(schlist,"修改考勤组排班成功");
//			return ResultUtil.error("修改考勤组排班失败");
	}
yuquan.zhu committed
6071
}