package cn.timer.api.controller.kqgl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
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.RestClientException;
import org.springframework.web.client.RestTemplate;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.hutool.json.JSONObject;
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.KqglAssoKqjgly;
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.TBlFkcmdTrans;
import cn.timer.api.bean.kqgl.TBlFkcmdTransCmdParam;
import cn.timer.api.bean.kqgl.UserAttendanceRel;
import cn.timer.api.bean.kqgl.UserEquiRelation;
import cn.timer.api.bean.kqjg.KqjgRealtimeEnrollData;
import cn.timer.api.bean.xcgl.XcglAdminXzz;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.Initialization.StaticVariable;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.kqgl.AttGroupBinPunchModeMapper;
import cn.timer.api.dao.kqgl.AttendanceGroupMapper;
import cn.timer.api.dao.kqgl.AttendanceMachineMapper;
import cn.timer.api.dao.kqgl.AttendanceWeeklySchMapper;
import cn.timer.api.dao.kqgl.CalendarAlarmMapper;
import cn.timer.api.dao.kqgl.KqglAssoKqjglyMapper;
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;
import cn.timer.api.dao.kqjg.KqjgRealtimeEnrollDataMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
import cn.timer.api.dto.kqgl.AttemacDto;
import cn.timer.api.dto.kqgl.AttendanceMachineDto;
import cn.timer.api.dto.kqgl.MachinememberDto;
import cn.timer.api.utils.DateUtil;
import cn.timer.api.utils.ResponseResult;
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.ApiOperationSupport;
import io.swagger.annotations.ApiParam;

/**
 * @author lalqq
 *	考勤
 */
@SuppressWarnings("all")
@Api(tags = "AttsApi")
@RestController
@RequestMapping(value = "/kqz", produces = { "application/json" })
public class AttController {
	
	//班次
	@Autowired
	private ShiftManagementMapper shiftmanagementservice;
	//考勤机
	@Autowired
	private AttendanceMachineMapper attendancemachineservice;
	//考勤地址
	@Autowired
	private PunchCardAddressMapper punchcardaddressservice;
	//考勤WIFI
	@Autowired
	private PunchCardWiFiMapper punchcardwifiservice;
	//考勤组
	@Autowired
	private AttendanceGroupMapper attendancegroupservice;
	//考勤组绑定的打卡方式
	@Autowired
	private AttGroupBinPunchModeMapper attgroupbinpunchmodeservice;
	//用户和考勤组关系
	@Autowired
	private UserAttendanceRelMapper userattendancerelservice;
	//考勤周排班
	@Autowired
	private AttendanceWeeklySchMapper attendanceweeklyschservice;
	//排班明细
	@Autowired
	private ScheduleMapper scheduleservice;
	//打卡记录
	@Autowired
	private PunchRecordMapper punchrecordservice;
	//打卡明细表
	@Autowired
	private PunchCardDetailsMapper punchcarddetailsservice;
	
	
	//用户与设备关系表
	@Autowired
	private UserEquiRelationMapper userequirelationmapper;
	
	
	@Autowired
	private YgglMainEmpMapper ygglmainempmapper;
	
	@Autowired
	private KqglAssoKqjglyMapper kqglassokqjglymapper;
	
	@Autowired
	private KqjgRealtimeEnrollDataMapper kqjgrealtimeenrolldatamapper;
	
	//员工
//	@Autowired
//	private YgglEmpInfoMapper ygglEmpInfoService;//员工信息

	@Autowired
	private SpecialDateMapper specialdateservice;
	//日历提醒
	@Autowired
	private CalendarAlarmMapper calendaralarmservice;
	
	SimpleDateFormat mat = new SimpleDateFormat("yyyy-MM-dd");
	
	SimpleDateFormat famt = new SimpleDateFormat("yyyy-MM-dd");
	
	
	SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
	/*******班次管理--开始*********/
	/**
	 * 获取班次数据
	 */
	@GetMapping(value="/ShiftDataList")
	@ApiOperation(value = "获取班次数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 1)
	public Result<PageInfo<ShiftManagement>> getShiftDataList(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "9999") Integer pageSize) {
		
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			PageHelper.startPage(pageNum, pageSize);
			List<ShiftManagement> shiftList = shiftmanagementservice.selectByPrimaryByQyid(qyid);
			PageInfo<ShiftManagement> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
	
	/**
	 * 新增班次信息
	 */
	@PostMapping(value = "/Shif")
	@ApiOperation(value = "新增班次信息", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 2)
	public Result<ShiftManagement> ShiftInformation(@CurrentUser UserBean userBean,@RequestBody ShiftManagement shif) {
//		int qyid = 2000021;//坏小孩123【企业id】
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			shif.setQyid(qyid);
			shif.setLusjTime(new Date().getTime());
			shif.setLuryid(userid);//录入人员
			if(shiftmanagementservice.insertSelective(shif)>0){
				return ResultUtil.data(shif, "新增班次成功");
			}else{
				return ResultUtil.error("新增班次失败");
			}
	}
	
	/**
	 * 删除班次信息
	 */
	@DeleteMapping(value = "/Shif/{id}")
	@ApiOperation(value = "删除班次信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 3)
	public Result<Integer> deleteShiftInformation(@PathVariable("id") Integer id) {
		if (shiftmanagementservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	
	
	/**
	 * 根据班次id获取班次信息
	 */
	@GetMapping(value="/Shifts/{id}")
	@ApiOperation(value = "获取班次信息-根据班次id", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 4)
	public Result<ShiftManagement> getShiftCenter(@PathVariable("id") Integer id) {
		ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(id);
		return ResultUtil.data(shifs);
	}
	
	/**
	 * 修改班次信息
	 */
	@PutMapping(value = "/Shif")
	@ApiOperation(value = "修改班次信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 5)
	public Result<ShiftManagement> updateShiftInformation(@CurrentUser UserBean userBean,@RequestBody ShiftManagement shif) {
		int id = 0;//修改数据id
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			shif.setQyid(qyid);//企业id
			shif.setLusjTime(new Date().getTime());//录入时间
			shif.setLuryid(userid);//录入人员
			if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
				return ResultUtil.data(shif,"修改班次信息成功");
			}
			return ResultUtil.error("修改班次信息失败");
	}
	/*******班次管理--结束*********/
	/****************************************************/
	
	
	/****************************************************/
	/*******打卡设置--结束*********/
	
	/*********考勤机***********/
	/**
	 * 获取考勤机数据
	 */
	@GetMapping(value="/AttMachine")
	@ApiOperation(value = "获取考勤机数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 6)
	public Result<List<AttendanceMachine>> getAttMachineEquipment(@CurrentUser UserBean userBean) {
//		int qyid = 2000021;//坏小孩【企业id】
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			List<AttendanceMachine> attendanList = attendancemachineservice.selectByPrimaryByQyid(qyid);
			return ResultUtil.data(attendanList);
	}
	
	/**
	 * 修改考勤机信息
	 */
	/*
	 * @PutMapping(value = "/AttMachine/{name}/{id}")
	 * 
	 * @ApiOperation(value = "修改考勤机信息", httpMethod = "PUT", notes = "接口发布说明") public
	 * Result<Void> updateAttMachineEquipment(@PathVariable("name") String
	 * name,@PathVariable("id") Integer id) { if
	 * (attendancemachineservice.updateByPrimaryByid(name,id) > 0) { return
	 * ResultUtil.data("修改考勤机信息成功",""); } return ResultUtil.error("修改考勤机信息失败"); }
	 */
	
	/**
	 * 获取考勤机所在考勤组数据
	 */
	@GetMapping(value="/AttMachineGroup/{id}")
	@ApiOperation(value = "获取考勤机所在考勤组数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 7)
	public Result<List<AttendanceGroup>> getAttMachineGroup(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			List<AttendanceGroup> attownlist = attendancegroupservice.selectByPrimaryAttOwn(qyid,id);
			return ResultUtil.data(attownlist);
	}
	
	/**
	 * 获取考勤机数据-根据 组织机构代码
	 */
	@GetMapping(value="/AttGroupMachine")
	@ApiOperation(value = "获取考勤机数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 8)
	public Result<List<AttendanceGroup>> getAttGroupMachineList(@CurrentUser UserBean userBean) {
		
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			List<AttendanceGroup> attmacList = attendancegroupservice.selectAttGroupMachineByQyid(qyid);
			return ResultUtil.data(attmacList);
	}
	/*********打卡地址***********/
	/**
	 * 获取打卡地址数据
	 */
	@GetMapping(value="/PunchAddress")
	@ApiOperation(value = "获取打卡地址数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 9)
	public Result<PageInfo<PunchCardAddress>> getPunchCardAddress(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			PageHelper.startPage(pageNum, pageSize);
			List<PunchCardAddress> shiftList = punchcardaddressservice.selectByPrimaryByQyid(qyid);
			PageInfo<PunchCardAddress> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
	
	/**
	 * 根据打卡地址id获取打卡地址信息
	 */
	@GetMapping(value="/PuAddress/{id}")
	@ApiOperation(value = "获取打卡地址信息-根据打卡地址id", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 10)
	public Result<PunchCardAddress> getPunchAddressByid(@PathVariable("id") Integer id) {
		
		PunchCardAddress adres = punchcardaddressservice.selectByPrimaryKey(id);
		return ResultUtil.data(adres);
	}
	
	/**
	 * 新增打卡地址信息
	 */
	@PostMapping(value = "/PunchAddress")
	@ApiOperation(value = "新增打卡地址信息", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 11)
	public Result<PunchCardAddress> PunchCardAddress(@CurrentUser UserBean userBean,@RequestBody PunchCardAddress punchades) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			punchades.setQyid(qyid);//企业id
			punchades.setLusjTime(new Date().getTime());//录入时间
			punchades.setLuryid(userid);//录入人员
			
			if(punchcardaddressservice.insertSelective(punchades)>0){
				return ResultUtil.data(punchades,"新增打卡地址成功");
			}else{
				return ResultUtil.error("新增打卡地址失败");
			}
	}
	
	/**
	 * 删除打卡地址信息
	 */
	@DeleteMapping(value = "/PunchAddress/{id}")
	@ApiOperation(value = "删除打卡地址信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 12)
	public Result<Integer> deletePunchCardAddress(@PathVariable("id") Integer id) {
		
		if (punchcardaddressservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	
	/**
	 * 修改打卡地址信息
	 */
	@PutMapping(value = "/PunchAddress")
	@ApiOperation(value = "修改打卡地址信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 13)
	public Result<PunchCardAddress> updatePunchCardAddress(@CurrentUser UserBean userBean,@RequestBody PunchCardAddress punchades) {
		
		int id = 0;//修改数据id
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			punchades.setQyid(qyid);
			punchades.setLusjTime(new Date().getTime());
			punchades.setLuryid(userid);
			
			if (punchcardaddressservice.updateByPrimaryKeySelective(punchades) > 0) {
				return ResultUtil.data(punchades,"修改打卡地址信息成功");
			}
			return ResultUtil.error("修改打卡地址信息失败");
	}
	
	/**
	 * 获取打卡地址所在考勤组数据
	 */
	@GetMapping(value="/PunchAddressGroup/{id}")
	@ApiOperation(value = "获取打卡地址所在考勤组数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 14)
	public Result<List<AttendanceGroup>> getPunchAddressGroup(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
		
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			List<AttendanceGroup> attaddressownlist = attendancegroupservice.selectByPrimaryAttAddressOwn(qyid,id);
			return ResultUtil.data(attaddressownlist);
	}
	
	/*********打卡WIFI***********/
	/**
	 * 获取打卡WIFI数据
	 */
	@GetMapping(value="/PunchWIFI")
	@ApiOperation(value = "获取打卡WIFI数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 15)
	public Result<PageInfo<PunchCardWiFi>> getPunchCardWIFI(@CurrentUser UserBean userBean,@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id
			
			PageHelper.startPage(pageNum, pageSize);
			List<PunchCardWiFi> shiftList = punchcardwifiservice.selectByPrimaryByQyid(qyid);
			PageInfo<PunchCardWiFi> pageInfo = new PageInfo<>(shiftList);
			return ResultUtil.data(pageInfo);
	}
	
	/**
	 * 根据打卡WIFIid获取打卡WIFI信息
	 */
	@GetMapping(value="/PuWIFI/{id}")
	@ApiOperation(value = "获取打卡WIFI信息-根据打卡WIFIid", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 16)
	public Result<PunchCardWiFi> getPunchWIFIByid(@PathVariable("id") Integer id) {
		
		PunchCardWiFi puwifi = punchcardwifiservice.selectByPrimaryKey(id);
		return ResultUtil.data(puwifi);
	}
	
	/**
	 * 新增打卡WIFI信息
	 */
	@PostMapping(value = "/PunchWIFI")
	@ApiOperation(value = "新增打卡WIFI信息", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 17)
	public Result<PunchCardWiFi> PunchCardWIFI(@CurrentUser UserBean userBean,@RequestBody PunchCardWiFi punchwifi) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id		
			
			punchwifi.setQyid(qyid);//企业id
			punchwifi.setLusjTime(new Date().getTime());//录入时间
			punchwifi.setLuryid(userid);//录入人员
			
			if(punchcardwifiservice.insertSelective(punchwifi)>0){
				return ResultUtil.data(punchwifi,"新增打卡WIFI成功");
			}else{
				return ResultUtil.error("新增打卡WIFI失败");
			}
	}
	
	/**
	 * 删除打卡WIFI信息
	 */
	@DeleteMapping(value = "/PunchWIFI/{id}")
	@ApiOperation(value = "删除打卡WIFI信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 18)
	public Result<Integer> deletePunchCardWIFI(@PathVariable("id") Integer id) {
		
		if (punchcardwifiservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	
	/**
	 * 修改打卡地址信息
	 */
	@PutMapping(value = "/PunchWIFI")
	@ApiOperation(value = "修改打卡地址信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 19)
	public Result<PunchCardWiFi> updatePunchCardWIFI(@CurrentUser UserBean userBean,@RequestBody PunchCardWiFi punchwifi) {
		
		int id = 0;//修改数据id
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id		
			
			punchwifi.setQyid(qyid);
			punchwifi.setLusjTime(new Date().getTime());
			punchwifi.setLuryid(userid);
			
			if (punchcardwifiservice.updateByPrimaryKeySelective(punchwifi) > 0) {
				return ResultUtil.data(punchwifi,"修改打卡WIFI信息成功");
			}
			return ResultUtil.error("修改打卡WIFI信息失败");
	}
	
	/**
	 * 获取打卡WIFI所在考勤组数据
	 */
	@GetMapping(value="/PunchWIFIGroup/{id}")
	@ApiOperation(value = "获取打卡WIFI所在考勤组数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 20)
	public Result<List<AttendanceGroup>> getPunchWIFIGroup(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】		
			
			List<AttendanceGroup> attwifiownlist = attendancegroupservice.selectByPrimaryAttWIFIOwn(qyid,id);
			return ResultUtil.data(attwifiownlist);
	}
	
	/*******打卡设置--结束*********/
	/****************************************************/
	
	/****************************************************/
	/*******考勤组--开始*********/
	
	/**
	 * 获取考勤组数据
	 */
	@GetMapping(value="/AttGroupList")
	@ApiOperation(value = "获取考勤组数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 21)
	public Result<PageInfo<AttendanceGroup>> getAttendanceGroupList(@CurrentUser UserBean userBean,
			@ApiParam("当前页") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
			@ApiParam("每页条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】				
			
			PageHelper.startPage(pageNum, pageSize);
			List<AttendanceGroup> attgrlist = attendancegroupservice.selectAttGroupListByQyid(qyid);
			PageInfo<AttendanceGroup> pageInfo = new PageInfo<>(attgrlist);
			return ResultUtil.data(pageInfo);
	}

	/**
	 * 获取考勤组数据-根据 模糊 + 高級查詢
	 */
	@PostMapping(value = "/AttGroupList/list")
	@ApiOperation(value = "获取考勤组数据-根据 模糊 + 高級查詢", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 22)
	public Result<List<AttendanceGroup>> getAttGroupListByQuery(@CurrentUser UserBean userBean,@RequestBody KqzAttendanceGroupSearch kqzattendancegroupsearch) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】	
			
			kqzattendancegroupsearch.setQyid(qyid);
			
			List<AttendanceGroup> attgrlist = attendancegroupservice.selectKqglMainKqzByQuery(kqzattendancegroupsearch);
	
			return ResultUtil.data(attgrlist);
	}
	
	
	
	/**
	 * 获取打卡地址数据
	 */
	@GetMapping(value="/InGroupPunchAddress")
	@ApiOperation(value = "获取打卡地址数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 23)
	public Result<List<PunchCardAddress>> getInGroupPunchAddress(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】			
			
			List<PunchCardAddress> shiftList = punchcardaddressservice.selectByPrimaryByQyid(qyid);
			return ResultUtil.data(shiftList);
	}
	
	/**
	 * 获取打卡WIFI数据
	 */
	@GetMapping(value="/InGroupPunchWIFI")
	@ApiOperation(value = "获取打卡WIFI数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 24)
	public Result<List<PunchCardWiFi>> getInGroupPunchWIFI(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			
			List<PunchCardWiFi> shiftList = punchcardwifiservice.selectByPrimaryByQyid(qyid);
			return ResultUtil.data(shiftList);
	}
	
	/**
	 * 获取班次 
	 */
	@GetMapping(value="/AttShift")
	@ApiOperation(value = "获取班次-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 25)
	public Result<List<ShiftManagement>> getAttShiftList(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】		
			
			List<ShiftManagement> attshiftList = shiftmanagementservice.selectByPrimaryByQyid(qyid);
			return ResultUtil.data(attshiftList);
	}
	
	
	
	/**
	 * 获取员工数据
	 */
	@GetMapping(value="/Employee")
	@ApiOperation(value = "获取员工数据-根据 组织机构代码", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 26)
	public Result<List<YgglMainEmp>> getEmployeeData(@CurrentUser UserBean userBean) {
		
			int qyid = userBean.getOrgCode();//坏小孩【企业id】				
			
			List<YgglMainEmp> yggl = attendancegroupservice.EmployeeListByorgCode(String.valueOf(qyid));
			
			return ResultUtil.data(yggl);
			
	}
	
	
	/**
	 *	 删除考勤组
	 */
	@DeleteMapping(value = "/AttendanceGroup/{id}")
	@ApiOperation(value = "删除考勤组", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 27)
	public Result<Integer> DelAttendanceGroup(@PathVariable("id") Integer id) {
		//删除组
		if (attendancegroupservice.deleteByPrimaryKey(id) > 0) {
			
			/**********************************************************/
			//删除考勤机里的人员
			
//			List<UserAttendanceRel> attusers = userattendancerelservice.selectAttendanceOfficerByKqzid(id);//该考勤组人数
//			
//			List<AttGroupBinPunchMode> kqjs = attgroupbinpunchmodeservice.selectMachineByKqzId(id);//该考勤组所绑定的考勤机
//			
//			String DevId = "";
//			for(AttGroupBinPunchMode abp:kqjs) {
//				AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid());//查询考勤机“序列号”
//				
//				DevId = kqj.getCode();
//				
//				for(UserAttendanceRel user:attusers) {
//					String user_id = user.getEmpnum();//"1692";//要删除的考勤组里面用户ID
//					
//					byte[] bytCmd=new byte[0];
//					byte[] cmdbytCmd=new byte[0];
//					JSONObject vResultJson = new JSONObject();
//					vResultJson.put("user_id", user_id);
//					String sFinal = vResultJson.toString();
//					
//					String url = StaticVariable.mac_command;
//			        HttpHeaders headers = new HttpHeaders();
//			        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
//			        params.add("cmd", "DELETE_USER");
//			        params.add("devid", DevId);
//			        params.add("json", sFinal);
//			        RestTemplate restTemplate = new RestTemplate();
//			        HttpEntity httpEntity = new HttpEntity(params, headers);
//			        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
//
//					System.out.println("=============考勤机删除===============");
//				}
//			}
			
			/**********************************************************/
			
//			userequirelationmapper.deleteBykqzid(id);
			
			//删除考勤组绑定的打卡方式
			attgroupbinpunchmodeservice.deleteByPrimaryBykqzid(id);
			//删除用户和考勤组关系表
			userattendancerelservice.deleteByPrimaryBykqzid(id);
			//删除特殊日期表
			specialdateservice.deleteByPrimaryBykqzid(id);
			//删除排班明细表(自由排班)
			scheduleservice.deleteByPrimaryBykqzid(id);
			//删除考勤周排班
			attendanceweeklyschservice.deleteByPrimaryBykqzid(id);
			
			return ResultUtil.data(id,"删除成功");
		}
		
		
		return ResultUtil.error("删除失败");
	}
	
	/**
	 * 	新建考勤组
	 */
	@PostMapping(value = "/AttendanceGroup")
	@ApiOperation(value = "新增考勤组数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 28)
	public Result<Void> AttendanceGroupList(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id		
			
			AttendanceGroup attgro = new AttendanceGroup();
			attgro.setName(attass.getName());//名称
			attgro.setKqbz(attass.getRemarks());//考勤备注
			attgro.setPbfs(attass.getAtttype());//排班方式 // 考勤类型:1-固定排班、2-排班制、3-自由工时 *
			attgro.setQyid(qyid);//企业id
			attgro.setIsWq(attass.getFieldpersonnel());//外勤:0-关  1-开
			
			if(attass.getAtttype() == 1){
				attgro.setIsFdjjr(attass.getLegalholidays());//是否开启法定节假日休息(固定排班)
			}
			if(attass.getAtttype() == 2){
				
				attgro.setIsXzbcdk(attass.getOptscheduling());//未排班时,员工可选择班次打卡
				
				String[] attShifts = attass.getAttShifts();
				String sybc=String.join(",",attShifts);
				attgro.setSybc(sybc);
				
				attgro.setIsDqtx(attass.getAttRemind());//是否开启到期提醒([排班制专用]0:否;1:是)
				 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());//加班最大时长(自由工时专用)
			}
			attendancegroupservice.insertSelective(attgro);
			int attid = attgro.getId();//考勤组ID
			//System.out.println(attid);
			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(attid);// 考勤组ID
					attgbpmac.setType(1);// 1:考勤机;2:地址;3:WIFI
					attgbpmac.setQyid(qyid);// 企业id
					attgbpmac.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpmac);
				}
			}
			//考勤地址
			String[] atad = attass.getAttadds();
			if(atad.length > 0){
				for(int a=0;a<atad.length;a++){
					AttGroupBinPunchMode attgbpadd = new AttGroupBinPunchMode();
					attgbpadd.setDkfsid(Integer.valueOf(atad[a]));// 考勤机、地址、WIFI的id
					attgbpadd.setKqzId(attid);// 考勤组ID
					attgbpadd.setType(2);// 1:考勤机;2:地址;3:WIFI
					attgbpadd.setQyid(qyid);// 企业id
					attgbpadd.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpadd);
				}
			}
			//考勤WIFI
			String[] atwf = attass.getAttwifis();
			if(atwf.length > 0){
				for(int f=0;f<atwf.length;f++){
					AttGroupBinPunchMode attgbpwf = new AttGroupBinPunchMode();
					attgbpwf.setDkfsid(Integer.valueOf(atwf[f]));// 考勤机、地址、WIFI的id
					attgbpwf.setKqzId(attid);// 考勤组ID
					attgbpwf.setType(3);// 1:考勤机;2:地址;3:WIFI
					attgbpwf.setQyid(qyid);// 企业id
					attgbpwf.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpwf);
				}
			}
			if(kqzdkfslist.size()>0){
				attgroupbinpunchmodeservice.insertKqglAssokqzdKfsList(kqzdkfslist);
			}
			
			//用户和考勤组关系****************************************************************
			List<UserAttendanceRel> yhkqzlist=new ArrayList<UserAttendanceRel>();
			String[] attser = attass.getAttuserids();
			if(attser.length>0){
				
				String user_id = "";
				String user_name = "";
				String DevId = "";
				byte[] bytCmd=new byte[0];
				byte[] cmdbytCmd=new byte[0];
				
				for(int u=0;u<attser.length;u++){
					
					if(attass.getAtttype() == 2){//排班制     考勤组与用户、用户排班
						scheduleservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					}
					userattendancerelservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					
					UserAttendanceRel kquser = new UserAttendanceRel();
					kquser.setKqzid(attid);
					kquser.setUserid(Integer.valueOf(attser[u]));
					kquser.setQyid(qyid);
					yhkqzlist.add(kquser);
					
					
					/***********************************录入相应的考勤机**************************************************************/
					List<AttGroupBinPunchMode> kqjs = attgroupbinpunchmodeservice.selectMachineByKqzId(attid);//该考勤组所绑定的考勤机
					
					for(AttGroupBinPunchMode abp:kqjs) {
						AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid());//查询考勤机“序列号”
//						userequirelationmapper.delAttmacrelpers(Integer.valueOf(attser[u]), kqj.getId());
						UserEquiRelation kqjry = userequirelationmapper.selectByuserIdkqjid(Integer.valueOf(attser[u]), kqj.getId());
						if(kqjry == null) {
							//用户与设备关系(考勤机id-->用户id)
							UserEquiRelation uskqj = new UserEquiRelation();
							uskqj.setUserId(Integer.valueOf(attser[u]));//用户id
							uskqj.setKqjid(kqj.getId());//设备id
							uskqj.setType(1);//类型(类型 1:考勤机)
							UserEquiRelation isgly = userequirelationmapper.selectByuserId(Integer.valueOf(attser[u]));
							if(isgly != null) {
								uskqj.setIsGly(isgly.getIsGly());
							}else {
								uskqj.setIsGly(0);
							}
							userequirelationmapper.insert(uskqj);
						}
						Integer orgCode = userBean.getOrgCode();
						QueryWrapper<YgglMainEmp> queryWrapper = new QueryWrapper<>();
						queryWrapper.eq("org_code", orgCode).eq("emp_num", attser[u]);
						YgglMainEmp yggluser = YgglMainEmp.builder().build().selectOne(queryWrapper);
						user_id=attser[u];//
						user_name=yggluser.getName();//
						DevId=kqj.getCode();//考勤机--设备编码
						if(user_id == null || DevId == null){
							try {
								throw new Exception("User_ID or DevId is null");
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
						if(user_name == null){
							user_name = "";
						}
						JSONObject vResultJson = new JSONObject();
						vResultJson.put("user_id", user_id);
						vResultJson.put("user_name", user_name);
						vResultJson.put("user_privilege", "USER");
						String sFinal = vResultJson.toString();
						String url = StaticVariable.mac_command;
				        HttpHeaders headers = new HttpHeaders();
				        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
				        params.add("cmd", "SET_USER_INFO");
				        params.add("devid", DevId);
				        params.add("json", sFinal);
				        RestTemplate restTemplate = new RestTemplate();
				        HttpEntity httpEntity = new HttpEntity(params, headers);
				        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
						System.out.println("============新增===============");
					}
					/*****************************************************************************/
				}
			}
			if(yhkqzlist.size()>0){
				userattendancerelservice.insertKqglAssoKqzdkfsList(yhkqzlist);
			}
			
			
			//固定排版周记录  attendanceweeklyschservice
			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(attid);
					attweek.setType(Integer.valueOf(weektime[h]));
					attweek.setBcid(Integer.valueOf(weekshif[h]));
					attweeklist.add(attweek);
				}
			}
			//自由工时 周排班
			String[] attFrWorkdays = attass.getAttFreeWorkdays();// 周工作日【自由工时】
			if(attFrWorkdays.length>0 && attass.getAtttype() == 3){
				for(int w=0;w<attFrWorkdays.length;w++){
					AttendanceWeeklySch attfrwor = new AttendanceWeeklySch();
					attfrwor.setKqzid(attid);
					attfrwor.setType(Integer.valueOf(attFrWorkdays[w]));
					attfrwor.setBcid(0);
					attweeklist.add(attfrwor);
				}
			}
			
			if(attweeklist.size()>0){
				attendanceweeklyschservice.insertKqglAssoZhoupaibanList(attweeklist);
			}
			
			
			//特殊日期--必须打卡、不用打卡日期
			List<SpecialDate> speclist=new ArrayList<SpecialDate>();
			String[] attmuspudata = attass.getAttMustPunchData();// 必须打卡的日期【固定排班】
			String[] attmuspushifid = attass.getAttMustPunchShifid();// 必须打卡的班次id【固定排班】
			String[] attnonpudata = attass.getAttNonPunchData();// 不用打卡的日期【固定排班】
			if(attmuspudata.length>0 && attmuspushifid.length>0 && attass.getAtttype() == 1){
				for(int m=0;m<attmuspudata.length;m++){
					SpecialDate mut = new SpecialDate();
					mut.setKqzid(attid);//考勤组id
					mut.setTsrq(attmuspudata[m]);//日期
					mut.setBcid(Integer.valueOf(attmuspushifid[m]));//班次id
					long date = new Date().getTime();
					mut.setLusjTime(date);//录入时间
					mut.setLuryid(180658);// 录入人员***********
					mut.setType(1);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(mut);
				}
			}
			if(attnonpudata.length>0 && attass.getAtttype() == 1){
				for(int n=0;n<attnonpudata.length;n++){
					SpecialDate non = new SpecialDate();
					non.setKqzid(attid);//考勤组id
					non.setTsrq(attnonpudata[n]);//日期
					non.setBcid(0);//班次id
					long date = new Date().getTime();
					non.setLusjTime(date);//录入时间
					non.setLuryid(180658);// 录入人员***********
					non.setType(2);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(non);
				}
			}
			
			if(speclist.size()>0){
				specialdateservice.insertKqglAssoTeshuList(speclist);
			}
			
			
			//记录排班(排班制)
			List<Schedule> schlist=new ArrayList<Schedule>();
			Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
			if(schedules.length>0 && attass.getAtttype() == 2){
				for(int p=0;p<schedules.length;p++){
					Schedule sch = new Schedule();
					sch.setUserid(schedules[p].getUserid());
					sch.setData(schedules[p].getData());
					sch.setBcid(schedules[p].getBcid());
					sch.setKqzid(attid);
					schlist.add(sch);
				}
			}
			if(schlist.size()>0){
				scheduleservice.insertKqglAssoPbmxList(schlist);
			}
			
			return ResultUtil.data(null,"新增打卡WIFI成功");
			
			//return ResultUtil.error("新增考勤组失败");
	}
	
	
	public static byte[] CreateBSCommBufferFromString(String sCmdParam,byte[] bytCmd) {
		try{
			if (sCmdParam.length() == 0){
				return bytCmd;
			}
			byte[] bytText = sCmdParam.getBytes("UTF-8");
			byte[] bytTextLen = int2byte(bytText.length + 1);
			bytCmd=new byte[4 + bytText.length + 1];
			System.arraycopy(bytTextLen,0,bytCmd,0,bytTextLen.length);
			System.arraycopy(bytText,0,bytCmd,4,bytText.length);
			bytCmd[4 + bytText.length] = 0;
			return bytCmd;
		}catch(Exception e){
			e.printStackTrace();
			bytCmd=new byte[0];
			return bytCmd;
		}
	}
	
	public static byte[] int2byte(int res) {  
		byte[] targets = new byte[4];  
		targets[0] = (byte) (res & 0xff);
		targets[1] = (byte) ((res >> 8) & 0xff);
		targets[2] = (byte) ((res >> 16) & 0xff);
		targets[3] = (byte) (res >>> 24);
		return targets;   
	}
	
	public static byte[] ConcateByteArray(byte[] abytDest, byte[] abytSrc) {
        int len_dest = abytDest.length + abytSrc.length;
        if (abytSrc.length == 0)
            return abytDest;
        byte[] bytTmp = new byte[len_dest];
        System.arraycopy(abytDest, 0, bytTmp, 0, abytDest.length);
        System.arraycopy(abytSrc, 0, bytTmp, abytDest.length, abytSrc.length);
        return bytTmp;
	}
	
	public String MakeCmd(String Cmd,String mDevId,byte[] mParam) throws Exception{
        String mTransID;
        mTransID = GetNewTransId();
        if(mDevId == null) throw new Exception("DevId is null!");
        switch (Cmd){
            case "GET_USER_ID_LIST": break;
        }
        try{
        	attendancegroupservice.deleteTBlFkcmdTransCmdParamByTransId(mTransID);
        	attendancegroupservice.deleteTBlFkcmdTransCmdResultByTransId(mTransID);
        	if(mParam != null && mParam.length > 0){
        		TBlFkcmdTransCmdParam param=new TBlFkcmdTransCmdParam();
        		param.setTransId(mTransID);
        		param.setCmdParam(mParam);
        		param.setDeviceId(mDevId);
        		attendancegroupservice.insertTBlFkcmdTransCmdParam(param);
        	}
        	TBlFkcmdTrans fkcmdTrans=new TBlFkcmdTrans();
        	fkcmdTrans.setTransId(mTransID);
        	fkcmdTrans.setDeviceId(mDevId);
        	fkcmdTrans.setCmdCode(Cmd);
        	fkcmdTrans.setStatus("WAIT");
        	fkcmdTrans.setUpdateTime(TimeToString(new Date()));
        	attendancegroupservice.insertTBlFkcmdTrans(fkcmdTrans);
        } catch (Exception e) {
        	e.printStackTrace();
//        	log.error(e.getMessage(),e);
        }
        return mTransID;
    }
	
	public String GetNewTransId(){
        int nTransId;
        String sTransId = attendancegroupservice.selectTBlFkcmdTransNum();
        if (sTransId == ""||sTransId==null){
        	sTransId = "200";
        }
        nTransId = Integer.parseInt(sTransId) + 1;
        return String.valueOf(nTransId);
    }
	
	 public static String TimeToString(Date date) {
	        String strRet;
	        try
	        {
	        	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	            strRet = sdf.format(date);
	            return strRet;
	        }
	        catch (Exception e)
	        {
	            return "1970-1-1 1:0:0";
	        }
		}
	
	
	/**
	 * 获取修改的排班明细--【修改考勤组】--------------------------------------------------------------------------------------
	 */
	@PostMapping(value = "/AttGroupSchedulingList")
	@ApiOperation(value = "获取修改的排班明细", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 29)
	public Result<List<Schedule>> getAttGroupSchedulingList(@CurrentUser UserBean userBean,@RequestBody AttScheduling attscheduling) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			String str = sdf.format(d);
			
			String date = attscheduling.getDate();
			if(("").equals(date) || date == null){
				attscheduling.setDate(str);
			}
			
			attscheduling.setQyid(qyid);
			
			List<Schedule> schlist = scheduleservice.selectAttGroupScheduling(attscheduling);
	
			return ResultUtil.data(schlist);
	}
	
	
	/**
	 * 根据考勤组id获取班次信息--【修改考勤组】
	 */
	@GetMapping(value="/roster/{id}/{date}")
	@ApiOperation(value = "根据考勤组id获取班次信息", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 30)
	public Result<List<ShiftManagement>> getRosterList(@PathVariable("id") Integer id,@PathVariable("date") String date) {
		
		KqzAttendanceGroupSearch jycx = new KqzAttendanceGroupSearch();
		jycx.setOverall(date);
		jycx.setQyid(id);
		
		List<ShiftManagement> shifs = shiftmanagementservice.selectRosterByKqzid(jycx);
		return ResultUtil.data(shifs);
	}
	
	/**
	 * 修改考勤组排班(修改排班后,需判断是否有打卡记录,有则匹配当天修改后的班次,无则不需要修改)
	 */
	@SuppressWarnings({ "unused", "deprecation" })
	@PutMapping(value = "/attscheduling")
	@ApiOperationSupport(order = 31)
	@ApiOperation(value = "修改班次信息", httpMethod = "PUT", notes = "接口发布说明")
	public Result<List<Schedule>> updateAttscheduling(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
			int id = Integer.valueOf(attass.getAttgroupid());//修改数据id
			
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			AttendanceGroup qttgrop = attendancegroupservice.selectByPrimaryKey(Integer.valueOf(attass.getAttgroupid()));
			
			//记录排班(排班制)
			List<Schedule> schlist=new ArrayList<Schedule>();
			Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
			if(schedules.length>0 && attass.getAtttype() == 2){
				for(int p=0;p<schedules.length;p++){
					Schedule sch = new Schedule();
					sch.setUserid(schedules[p].getUserid());//用户id 
					sch.setData(schedules[p].getData());//排班日期   格式:yyyy-MM-dd
					sch.setBcid(schedules[p].getBcid());//班次id  0为休息
					sch.setKqzid(Integer.valueOf(attass.getAttgroupid()));//考勤组id
					schlist.add(sch);
					
					/*****************************/
					//转换日期
					String data = mat.format(new Date(schedules[p].getData().toString()));
					
					Long startDate = 0l;
					Long endDate = 0l;
					try {
						startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
						endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(data,"yyyy-MM-dd")).getTime();
					} catch (ParseException e) {
							e.printStackTrace();
					}
					
					//当天修改后的班次
					ShiftManagement banci = shiftmanagementservice.selectByPrimaryKey(schedules[p].getBcid());
					Long sbdk1 = 0l;
					Long xbdk1 = 0l;
					Long sbdk2 = 0l;
					Long xbdk2 = 0l;
					Long sbdk3 = 0l;
					Long xbdk3 = 0l;
					if(banci != null){
						if(banci.getSxbcs()== 1 || banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
							sbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk1(),2)+":00"));
							xbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk1(),2)+":00"));
						}
						if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
							sbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk2(),2)+":00"));
							xbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk2(),2)+":00"));
						}
						if(banci.getSxbcs()== 3){
							sbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk3(),2)+":00"));
							xbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk3(),2)+":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());
						if(initial.size() > 0){
							RestMethod(initial,initial.get(0).getDkmxid());
						}
					}
					
					
					//当天的所有打卡记录
					List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,schedules[p].getUserid());
					PunchRecord minAttid = null;
					PunchRecord maxAttid = null;
					int dkmxid = 0;
					if(mapucalist.size() > 0){
						//最小值
				        minAttid = mapucalist.stream().min(Comparator.comparing(PunchRecord::getId)).get();
	//			        System.out.println(minAttid.getAttdate() +  "---min---" +minAttid.getId());
						//最大值
						maxAttid = mapucalist.stream().max(Comparator.comparing(PunchRecord::getId)).get();
	//			        System.out.println(maxAttid.getAttdate() +  "---max---" + maxAttid.getId());
						
						//对应打卡明细表id
						dkmxid = maxAttid.getDkmxid();
					}
					
					//当天有打卡记录且当天打卡班次和当前修改后的班次不匹配再进行重新维护
					if(mapuca != null && !(schedules[p].getBcid()).equals(mapuca.getBcid())){
						if(banci != null){//修改后有班次打卡
							if(banci.getSxbcs() == 1){//修改后一天打两次
								if(mapucalist.size() > 2){/////当天打卡多条的话 取最开始打的卡和最后打的卡 作为新一轮的上下班考勤
									for(PunchRecord pre : mapucalist){/********/
										if(pre.getId() != minAttid.getId() && pre.getId() != maxAttid.getId()){//去除最大和最小 其他均改为“打卡无效:此记录已被更新”
											PunchRecord record = new PunchRecord();
											record.setId(pre.getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											if((pre.getSort())%2 > 0){//上班
												Long time = (pre.getDktime() - sbdk1)/1000/60;
												if(time > 0){
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk1);//上班应打卡时间
											}else{//下班
												Long time = (pre.getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setResults(0);// 打卡结果
												}else{
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);//下班应打卡时间
											}
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}else{
											if(pre.getId() == minAttid.getId()){//上班
												PunchRecord record = new PunchRecord();
												record.setId(pre.getId());
												record.setType(1);//上班
												Long time = (pre.getDktime() - sbdk1)/1000/60;
												if(time > 0){
													record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk1);
												record.setBcid(banci.getId());//班次id
												punchrecordservice.updateByPrimaryKeySelective(record);
											}else if(pre.getId() == maxAttid.getId()){//下班
												PunchRecord record = new PunchRecord();
												record.setId(pre.getId());
												record.setType(2);//下班
												Long time = (pre.getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);
												record.setBcid(banci.getId());//班次id
												record.setSort(2);
												punchrecordservice.updateByPrimaryKeySelective(record);
											}
										}
									}
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									//
									PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//上班
									PunchCardDetails max = new PunchCardDetails();
									max.setId(dkmxid);//需修改的明细id
									max.setXbdk1(maxdata.getDktime());
									max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
									
									Long woktimes = (maxdata.getDktime() - mindata.getDktime())/1000/60;
									max.setGzsc(Double.valueOf(woktimes));
									
									punchcarddetailsservice.updateByPrimaryKeySelective(max);
								}else{////
									PunchRecord mindataone = null;
									//当天打卡记录为1条
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									//当天打卡记录为2条
									if(maxAttid != null && minAttid.getId() != maxAttid.getId()){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());
										record.setType(2);//下班
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);
										record.setBcid(banci.getId());//班次id
										record.setSort(2);
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										PunchCardDetails max = new PunchCardDetails();
										max.setId(dkmxid);//需修改的明细id
										max.setXbdk1(maxdata.getDktime());
										max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
										
										Long woktimes = (maxdata.getDktime() - mindataone.getDktime())/1000/60;
										max.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(max);
									}
								}
							}else if(banci.getSxbcs() == 2){//修改后一天打四次
								if(mapucalist.size() > 4){//当天打卡多次
									String[] str= new String[3];
									for(int y=0;y<mapucalist.size();y++){
										if(y == 0){//上班
											PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
	//										record.setType(1);//上班
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
											if(time > 0){
												record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk1);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										if(y == 1 || y == 2){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											
											if((mapucalist.get(y).getSort())%2 == 0){//下班
												Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
												if(time > 0){
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}else{
													record.setStatus(4);
													record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
												}
												record.setAttime(xbdk1);//下班应打卡时间
												
												str[0] = String.valueOf(mapucalist.get(y).getId());
											}else{//上班
												Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
												if(time > 0){
													record.setStatus(3);
													record.setResults(Integer.valueOf(time.toString()));// 打卡结果
												}else{
													record.setStatus(1);
													record.setResults(0);// 打卡结果
												}
												record.setAttime(sbdk2);//上班应打卡时间
												
												str[1] = String.valueOf(mapucalist.get(y).getId());
											}
											
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										
										
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
											PunchRecord record = new PunchRecord();
											
											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk2)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setSort(4);
											record.setAttime(xbdk2);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
											
											str[2] = String.valueOf(maxdata.getId());
										}
										
										if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											record.setResults(0);// 打卡结果
											record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
									}
									
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									
									for(int t=0;t<str.length;t++){
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(str[t]));//单条打卡明细
										
										PunchCardDetails dkmx = new PunchCardDetails();
										dkmx.setId(dkmxid);//需修改的明细id
										if(t == 0){
											dkmx.setXbdk1(dtdkmx.getDktime());
											dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
										}else if(t == 1){
											dkmx.setSbdk2(dtdkmx.getDktime());
											dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
										}else{
											dkmx.setXbdk2(dtdkmx.getDktime());
											dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
										}
										Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
										dkmx.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
									}
									 
								}else{//打卡小于4次
									PunchRecord mindataone = null;
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									
									PunchCardDetails pcd = new PunchCardDetails();
									if(mapucalist.size() >= 2){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());//当天一条记录的id
										record.setType(2);
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
										pcd.setXbdk1(dtdkmx.getDktime());
										pcd.setXbdk1jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 3){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(2).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
										pcd.setSbdk2(dtdkmx.getDktime());
										pcd.setSbdk2jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 4){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(maxAttid.getId());//当天一条记录的id
										record.setType(2);
										Long time = (maxAttid.getDktime() - xbdk2)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk2(dtdkmx.getDktime());
										pcd.setXbdk2jg(dtdkmx.getResults());
									}
									
									pcd.setId(dkmxid);
									punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
								}
							}else if(banci.getSxbcs() == 3){//修改后一天打六次
								if(mapucalist.size() > 6){//当天打卡多次
									String[] str= new String[5];
									for(int y=0;y<mapucalist.size();y++){
										if(y == 0){//上班
											PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											Long time = (mindata.getDktime() - sbdk1)/1000/60;
											if(time > 0){
												record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk1);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										if(y == 1 || y == 2 || y == 3 || y == 4){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											
											if((mapucalist.get(y).getSort())%2 == 0){//下班
												if(y == 1){
													Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
													if(time > 0){
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}else{
														record.setStatus(4);
														record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
													}
													record.setAttime(xbdk1);//下班应打卡时间
													str[0] = String.valueOf(mapucalist.get(y).getId());
												}
												
												if(y == 3){
													Long time = (mapucalist.get(y).getDktime() - xbdk2)/1000/60;
													if(time > 0){
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}else{
														record.setStatus(4);
														record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
													}
													record.setAttime(xbdk2);//下班应打卡时间
													str[2] = String.valueOf(mapucalist.get(y).getId());
												}
												
											}else{//上班
												if(y == 2){
													Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
													if(time > 0){
														record.setStatus(3);
														record.setResults(Integer.valueOf(time.toString()));// 打卡结果
													}else{
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}
													record.setAttime(sbdk2);//上班应打卡时间
													str[1] = String.valueOf(mapucalist.get(y).getId());
												}
												
												if(y == 4){
													Long time = (mapucalist.get(y).getDktime() - sbdk3)/1000/60;
													if(time > 0){
														record.setStatus(3);
														record.setResults(Integer.valueOf(time.toString()));// 打卡结果
													}else{
														record.setStatus(1);
														record.setResults(0);// 打卡结果
													}
													record.setAttime(sbdk3);//上班应打卡时间
													str[3] = String.valueOf(mapucalist.get(y).getId());
												}
											}
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
										
										
										PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
										if(mapucalist.get(y).getId() == maxdata.getId()){//下班
											PunchRecord record = new PunchRecord();
											
											record.setId(maxdata.getId());
											record.setType(2);//下班
											Long time = (maxdata.getDktime() - xbdk3)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setSort(6);
											record.setAttime(xbdk3);
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
											
											str[4] = String.valueOf(maxdata.getId());
										}
										
										if(y == 5 || y > 5 && mapucalist.get(y).getId() != maxdata.getId()){
											PunchRecord record = new PunchRecord();
											record.setId(mapucalist.get(y).getId());
											record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setSort(0);//序号(0:打卡无效:此记录已被更新)
											record.setResults(0);// 打卡结果
											record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
											record.setBcid(banci.getId());//班次id
											punchrecordservice.updateByPrimaryKeySelective(record);
										}
									}
									
									//修改打卡明细
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchCardDetails record = new PunchCardDetails();
									record.setId(dkmxid);//需修改的明细id
									record.setSbdk1(mindata.getDktime());
									record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
									record.setXbdk1(null);
									record.setXbdk1jg(0);// 下班1打卡结果
									record.setSbdk2(null);
									record.setSbdk2jg(0);// 上班2打卡结果
									record.setXbdk2(null);
									record.setXbdk2jg(0);// 下班2打卡结果
									record.setSbdk3(null);
									record.setSbdk3jg(0);// 上班3打卡结果
									record.setXbdk3(null);
									record.setXbdk3jg(0);// 下班3打卡结果
									record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
									record.setGzsc(Double.valueOf("0"));
									punchcarddetailsservice.ModifyPunchDetails(record);
									
									for(int t=0;t<str.length;t++){
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(str[t]));//单条打卡明细
										
										PunchCardDetails dkmx = new PunchCardDetails();
										dkmx.setId(dkmxid);//需修改的明细id
										if(t == 0){
											dkmx.setXbdk1(dtdkmx.getDktime());
											dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
										}else if(t == 1){
											dkmx.setSbdk2(dtdkmx.getDktime());
											dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
										}else if(t == 2){
											dkmx.setXbdk2(dtdkmx.getDktime());
											dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
										}else if(t == 3){
											dkmx.setSbdk3(dtdkmx.getDktime());
											dkmx.setSbdk3jg(dtdkmx.getResults());// 上班3打卡结果
										}else{
											dkmx.setXbdk3(dtdkmx.getDktime());
											dkmx.setXbdk3jg(dtdkmx.getResults());// 下班3打卡结果
										}
										Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
										dkmx.setGzsc(Double.valueOf(woktimes));
										
										punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
									}
								}else{
									/**aaa**/
									PunchRecord mindataone = null;
									if(minAttid != null || maxAttid != null){
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(0).getId());//当天一条记录的id
										record.setType(1);//上班
										Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										//
										mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
										PunchCardDetails dan = new PunchCardDetails();
										dan.setId(dkmxid);//需修改的明细id
										dan.setSbdk1(mindataone.getDktime());
										dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
										dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
										dan.setGzsc(Double.valueOf("0"));
										punchcarddetailsservice.updateByPrimaryKeySelective(dan);
									}
									
									PunchCardDetails pcd = new PunchCardDetails();
									if(mapucalist.size() >= 2){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(1).getId());//当天一条记录的id
										record.setType(2);
										Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
										pcd.setXbdk1(dtdkmx.getDktime());
										pcd.setXbdk1jg(dtdkmx.getResults());
									}
									if(mapucalist.size() >= 3){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(2).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
										pcd.setSbdk2(dtdkmx.getDktime());
										pcd.setSbdk2jg(dtdkmx.getResults());
									}
									
									
									if(mapucalist.size() >= 4){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(3).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(3).getDktime() - xbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(xbdk2);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(3).getId());//单条打卡明细
										pcd.setXbdk2(dtdkmx.getDktime());
										pcd.setXbdk2jg(dtdkmx.getResults());
										
									}
									if(mapucalist.size() >= 5){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(mapucalist.get(4).getId());//当天一条记录的id
										record.setType(1);
										Long time = (mapucalist.get(4).getDktime() - sbdk3)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk3);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(4).getId());//单条打卡明细
										pcd.setSbdk3(dtdkmx.getDktime());
										pcd.setSbdk3jg(dtdkmx.getResults());
										
									}
									
									if(mapucalist.size() >= 6){
										/***/
										PunchRecord record = new PunchRecord();
										record.setId(maxAttid.getId());//当天一条记录的id
										record.setType(2);
										Long time = (maxAttid.getDktime() - xbdk3)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk3);//当天应打卡时间
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
										/***/
										PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
										pcd.setXbdk3(dtdkmx.getDktime());
										pcd.setXbdk3jg(dtdkmx.getResults());
									}
									
									pcd.setId(dkmxid);
									punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
									/**bbb***/
								}
							}
						}else{////修改后班次为休息的
							RestMethod(mapucalist,dkmxid);
						}
					}
					
					/***********************/
				}
			}
			if(schlist.size()>0){
				//删除排班明细表(自由排班)
				scheduleservice.deleteByPrimaryBykqzid(id);
				scheduleservice.insertKqglAssoPbmxList(schlist);
				return ResultUtil.data(schlist,"修改考勤组排班成功");
			}
			
			return ResultUtil.error("修改考勤组排班失败");
	}
	
	/**
	 *	班次修改调用方法
	 */
	public void RestMethod(List<PunchRecord> mapucalist,int dkmxid){
		int q = 1;
		for(PunchRecord pres : mapucalist){
			PunchRecord pp = new PunchRecord();
			pp.setId(pres.getId());
			pp.setResults(0);//
			if(q%2 > 0){
				pp.setType(1);//
			}else{
				pp.setType(2);//
			}
			pp.setStatus(1);//
			pp.setSort(q);
			pp.setAttime(pres.getDktime());
			pp.setBcid(0);//
			punchrecordservice.updateByPrimaryKeySelective(pp);
			q++;
		}
		/*************/
		if(mapucalist.size() > 0){/*******修改打卡明细数据****/
			PunchCardDetails pcd = new PunchCardDetails();
			if(mapucalist.size() >= 1){
				pcd.setSbdk1(mapucalist.get(0).getDktime());
				pcd.setSbdk1jg(0);
			}
			if(mapucalist.size() >= 2){
				pcd.setXbdk1(mapucalist.get(1).getDktime());
				pcd.setXbdk1jg(0);
			}
			if(mapucalist.size() >= 3){
				pcd.setSbdk2(mapucalist.get(2).getDktime());
				pcd.setSbdk2jg(0);
			}
			if(mapucalist.size() >= 4){
				pcd.setXbdk2(mapucalist.get(3).getDktime());
				pcd.setXbdk2jg(0);
			}
			if(mapucalist.size() >= 5){
				pcd.setSbdk3(mapucalist.get(4).getDktime());
				pcd.setSbdk3jg(0);
			}
			if(mapucalist.size() >= 6){
				pcd.setXbdk3(mapucalist.get(5).getDktime());
				pcd.setXbdk3jg(0);
			}
			pcd.setId(dkmxid);
			punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
		}
	}
	
	/**
	 * 	根据考勤组id获取所有信息--【修改考勤组】
	 */
	@GetMapping(value="/AttendanceGroup/{id}")
	@ApiOperation(value = "根据考勤组id获取所有信息", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 32)
	public Result<AttendanceGroup> getAttendanceGroup(@PathVariable("id") Integer id) {
		
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		
		return ResultUtil.data(attgro);
	}
	
	/**
	 * 	获取当前考勤组所有人员
	 */
	@GetMapping(value="/AttUserGroupList/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 33)
	public Result<List<UserAttendanceRel>> getAttUserGroupList(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
		
		int qyid = userBean.getOrgCode();//坏小孩【企业id】
		List<UserAttendanceRel> userattgor = userattendancerelservice.selectAttendanceOfficerByKqzid(id,qyid);
		
		return ResultUtil.data(userattgor);
	}
	
	/**
	 * 	提醒人员
	 */
	@GetMapping(value="/AttReminderStaff/{id}")
	@ApiOperation(value = "提醒人员", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 34)
	public Result<List<YgglMainEmp>> getAttReminderStaff(@PathVariable("id") Integer id) {
		
		List<YgglMainEmp> yggl = new ArrayList<YgglMainEmp>();
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String txry = attgro.getTxry();
		
		if(txry != null && !("").equals(txry)){
			String[] coge=txry.split(";");
			String[] launchsArray=coge[0].split(",");
			launchsstr = txry.substring(0,txry.length() - 1);
			for(int i=0;i<launchsArray.length;i++){
//				System.out.println(launchsArray[i]);
				YgglMainEmp txyg = attendancegroupservice.selectByPrimaryByempNum(Integer.valueOf(launchsArray[i]));
				
				YgglMainEmp txyy = YgglMainEmp.builder().build();///
				txyy.setId(txyg.getId());
				txyy.setName(txyg.getName());
				txyy.setEmpNum(txyg.getEmpNum());
				yggl.add(txyy);
			}
		}
		return ResultUtil.data(yggl);
	}
	
	/**
	 * 提示方式
	 */
	@GetMapping(value="/PromptingMode/{id}")
	@ApiOperation(value = "提示方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 35)
	public Result<List<KqzAttendanceGroupSearch>> getAttPromptingMode(@PathVariable("id") Integer id) {
		
		List<KqzAttendanceGroupSearch> tsfslist = new ArrayList<KqzAttendanceGroupSearch>();
		
		AttendanceGroup attgro = attendancegroupservice.selectByPrimaryKey(id);
		String launchsstr = null;
		String tsfs = attgro.getTsfs();
		
		if(tsfs != null && !("").equals(tsfs)){
			String[] coge=tsfs.split(";");
			String[] launchsArray=coge[0].split(",");
			launchsstr = tsfs.substring(0,tsfs.length() - 1);
			for(int i=0;i<launchsArray.length;i++){
				System.out.println(launchsArray[i]);
				KqzAttendanceGroupSearch xtxt = new KqzAttendanceGroupSearch();
				xtxt.setOverall(launchsArray[i]);
				tsfslist.add(xtxt);
			}
		}
		
		return ResultUtil.data(tsfslist);
	}
	
	/**
	 * ??????
	 */
	@GetMapping(value="/WeeklyScheduling/{id}")
	@ApiOperation(value = "", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 36)
	public Result<List<AttendanceWeeklySch>> getAttWeeklyScheduling(@PathVariable("id") Integer id) {
		
		List<AttendanceWeeklySch> atwesclist = attendanceweeklyschservice.selectAttWeeklySchedulingByKqzid(id);
		
		
		return ResultUtil.data(atwesclist);
	}
	
	/**
	 * 考勤组绑定的打卡方式
	 */
	@GetMapping(value="/Attendancemethod/{id}")
	@ApiOperation(value = "考勤组绑定的打卡方式", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 37)
	public Result<List<AttGroupBinPunchMode>> getAttendancemethodList(@PathVariable("id") Integer id) {
		
		List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodeservice.selectByPrimaryByKqzId(id);
		
		return ResultUtil.data(attmetlist);
	}
	
	/**
	 * 固定排班周
	 */
	@GetMapping(value="/AttendanceWeeklyScheduling/{id}")
	@ApiOperation(value = "固定排班周", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 38)
	public Result<List<AttendanceWeeklySch>> AttendanceWeeklySchedulingList(@PathVariable("id") Integer id) {
		
		List<AttendanceWeeklySch> attweeklist = attendanceweeklyschservice.selectAttWeeklySchByKqzid(id);
		
		return ResultUtil.data(attweeklist);
	}
	
	/**
	 * 固定排班特殊日期
	 */
	@GetMapping(value="/AttSpecialDates/{id}")
	@ApiOperation(value = "固定排班特殊日期", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 39)
	public Result<List<SpecialDate>> AttSpecialDatesList(@PathVariable("id") Integer id) {
		
		List<SpecialDate> tesulist = specialdateservice.selectSpecialDatesByKqzid(id);
		
		return ResultUtil.data(tesulist);
	}
	
	
	/**
	 *	 修改考勤基本信息
	 */
	@PutMapping(value = "/BasicAttendanceInformation")
	@ApiOperation(value = "修改考勤信息", httpMethod = "PUT", notes = "接口发布说明")
	@ApiOperationSupport(order = 40)
	public Result<Void> BasicAttendanceInformation(@CurrentUser UserBean userBean,@RequestBody AttendanceAssistant attass) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			int attgrpid = Integer.valueOf(attass.getAttgroupid());//考勤组ID
			
			AttendanceGroup attgro = new AttendanceGroup();
			attgro.setId(attgrpid);//修改考勤组id
			attgro.setName(attass.getName());//名称
			attgro.setKqbz(attass.getRemarks());//考勤备注
			attgro.setPbfs(attass.getAtttype());//排班方式 // 考勤类型:1-固定排班、2-排班制、3-自由工时 *
			attgro.setQyid(qyid);//企业id
			
			attgro.setIsWq(attass.getFieldpersonnel());//外勤:0-关  1-开
			
			if(attass.getAtttype() == 1){
				attgro.setIsFdjjr(attass.getLegalholidays());//是否开启法定节假日休息(固定排班)
			}
			if(attass.getAtttype() == 2){
				String[] attShifts = attass.getAttShifts();
				String sybc=String.join(",",attShifts);
				attgro.setSybc(sybc);
				attgro.setIsDqtx(attass.getAttRemind());//是否开启到期提醒([排班制专用]0:否;1:是)
				
				attgro.setIsXzbcdk(attass.getOptscheduling());//未排班时,员工可选择班次打卡
				
				 String[] coge=attass.getAttRemindUserids();
				 String str=String.join(",",coge);
				attgro.setTxry(str);//提醒人员([排班制专用]员工id以[“,”]连接  json数组)
				attgro.setTxfs(attass.getAdvanceDays());//提醒方式([排班制专用]提前15天、7天、3天、1天)
				attgro.setTxxhts(attass.getRemCycleDays());//提醒循环天数([排班制专用])
				attgro.setTxsjTime(attass.getReminderTime());//提醒时间([排班制专用])
				 String[] rem=attass.getPromptingMode();
				 String strrem=String.join(",",rem);
				attgro.setTsfs(strrem);//提示方式([排班制专用]PC端、APP客户端、短信、邮件 以[“,”]连接  json数组)
				attgro.setIsWpbsdk(attass.getAttRemind());//是否开启未排班时打卡([排班制专用]0:否;1:是;未排班时,员工可以选择班次打卡)
			}
			if(attass.getAtttype() == 3){
				attgro.setKqkssjTime(attass.getNewAttTime());//考勤开始时间(自由工时专用)
				attgro.setZsgzsc(attass.getLeastworkTime());//至少工作时长(自由工时专用)
				attgro.setZcgzsc(attass.getNormalWorkTime());//正常工作时长(自由工时专用)
				attgro.setJbzdsc(attass.getMaxOvertimeTime());//加班最大时长(自由工时专用)
			}
			attendancegroupservice.updateByPrimaryKeySelective(attgro);
			
			/*********/
			attgroupbinpunchmodeservice.deleteByPrimaryBykqzid(attgrpid);
			/**********/
			List<AttGroupBinPunchMode> kqzdkfslist=new ArrayList<AttGroupBinPunchMode>();
			//考勤机
			String[] attmac = attass.getAttmachines();
			if(attmac.length>0){
				for (int i = 0; i < attmac.length; i++) {
					AttGroupBinPunchMode attgbpmac = new AttGroupBinPunchMode();
					attgbpmac.setDkfsid(Integer.valueOf(attmac[i]));// 考勤机、地址、WIFI的id
					attgbpmac.setKqzId(attgrpid);// 考勤组ID
					attgbpmac.setType(1);// 1:考勤机;2:地址;3:WIFI
					attgbpmac.setQyid(qyid);// 企业id
					attgbpmac.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpmac);
				}
			}
			//考勤地址
			String[] atad = attass.getAttadds();
			if(atad.length > 0){
				for(int a=0;a<atad.length;a++){
					AttGroupBinPunchMode attgbpadd = new AttGroupBinPunchMode();
					attgbpadd.setDkfsid(Integer.valueOf(atad[a]));// 考勤机、地址、WIFI的id
					attgbpadd.setKqzId(attgrpid);// 考勤组ID
					attgbpadd.setType(2);// 1:考勤机;2:地址;3:WIFI
					attgbpadd.setQyid(qyid);// 企业id
					attgbpadd.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpadd);
				}
			}
			//考勤WIFI
			String[] atwf = attass.getAttwifis();
			if(atwf.length > 0){
				for(int f=0;f<atwf.length;f++){
					AttGroupBinPunchMode attgbpwf = new AttGroupBinPunchMode();
					attgbpwf.setDkfsid(Integer.valueOf(atwf[f]));// 考勤机、地址、WIFI的id
					attgbpwf.setKqzId(attgrpid);// 考勤组ID
					attgbpwf.setType(3);// 1:考勤机;2:地址;3:WIFI
					attgbpwf.setQyid(qyid);// 企业id
					attgbpwf.setState(1);// 0:停用;1:启用
					kqzdkfslist.add(attgbpwf);
				}
			}
			if(kqzdkfslist.size()>0){
				attgroupbinpunchmodeservice.insertKqglAssokqzdKfsList(kqzdkfslist);
			}
			//用户与设备关系(考勤机id-->用户id)
			
			
			//用户和考勤组关系
			/***/
			userattendancerelservice.deleteByPrimaryBykqzid(attgrpid);
			/**/
			List<UserAttendanceRel> yhkqzlist=new ArrayList<UserAttendanceRel>();
			String[] attser = attass.getAttuserids();
			if(attser.length>0){
				
				String user_id = "";
				String user_name = "";
				String DevId = "";
				
				for(int u=0;u<attser.length;u++){
					
					if(attass.getAtttype() == 2){//排班制     考勤组与用户、用户排班
						scheduleservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					}
					userattendancerelservice.deleteByPrimaryByUserid(Integer.valueOf(attser[u]));
					
					UserAttendanceRel kquser = new UserAttendanceRel();
					kquser.setKqzid(attgrpid);
					kquser.setUserid(Integer.valueOf(attser[u]));
					kquser.setQyid(qyid);
					yhkqzlist.add(kquser);
					
					
					/***********************************录入相应的考勤机(修改)**************************************************************/
					List<AttGroupBinPunchMode> kqjs = attgroupbinpunchmodeservice.selectMachineByKqzId(attgrpid);//该考勤组所绑定的考勤机
					
					for(AttGroupBinPunchMode abp:kqjs) {
						AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid());//查询考勤机“序列号”
						UserEquiRelation kqjry = userequirelationmapper.selectByuserIdkqjid(Integer.valueOf(attser[u]), kqj.getId());
						if(kqjry == null) {
							//用户与设备关系(考勤机id-->用户id)
							UserEquiRelation uskqj = new UserEquiRelation();
							uskqj.setUserId(Integer.valueOf(attser[u]));//用户id
							uskqj.setKqjid(kqj.getId());//设备id
							uskqj.setType(1);//类型(类型 1:考勤机)
							UserEquiRelation isgly = userequirelationmapper.selectByuserId(Integer.valueOf(attser[u]));
							if(isgly != null) {
								uskqj.setIsGly(isgly.getIsGly());
							}else {
								uskqj.setIsGly(0);
							}
							userequirelationmapper.insert(uskqj);
						}
						Integer orgCode = userBean.getOrgCode();
						QueryWrapper<YgglMainEmp> queryWrapper = new QueryWrapper<>();
						queryWrapper.eq("org_code", orgCode).eq("emp_num", attser[u]);
						YgglMainEmp yggluser = YgglMainEmp.builder().build().selectOne(queryWrapper);
						user_id=attser[u];//
						user_name=yggluser.getName();//
						DevId=kqj.getCode();//考勤机--设备编码
						if(user_id == null || DevId == null){
							try {
								throw new Exception("User_ID or DevId is null");
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
						if(user_name == null){
							user_name = "";
						}
						JSONObject vResultJson = new JSONObject();
						vResultJson.put("user_id", user_id);
						vResultJson.put("user_name", user_name);
						vResultJson.put("user_privilege", "USER");
						String sFinal = vResultJson.toString();
						String url = StaticVariable.mac_command;
				        HttpHeaders headers = new HttpHeaders();
				        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
				        params.add("cmd", "SET_USER_INFO");
				        params.add("devid", DevId);
				        params.add("json", sFinal);
				        RestTemplate restTemplate = new RestTemplate();
				        HttpEntity httpEntity = new HttpEntity(params, headers);
				        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
						System.out.println("|============修改(新增)===================	|");
					}
					/*****************************************************************************/
				}
			}
			if(yhkqzlist.size()>0){
				userattendancerelservice.insertKqglAssoKqzdkfsList(yhkqzlist);
			}
			
			//固定排版周记录  attendanceweeklyschservice
			/*****/
			attendanceweeklyschservice.deleteByPrimaryBykqzid(attgrpid);
			/****/
			List<AttendanceWeeklySch> attweeklist=new ArrayList<AttendanceWeeklySch>();
			String[] weektime = attass.getAttWeekdays();//周工作日【固定排班】
			String[] weekshif = attass.getAttWeekdaysShifts();//周工作日班次【固定排班】
			if(weektime.length>0 && weekshif.length>0 && attass.getAtttype() == 1){
				for(int h=0;h<weektime.length;h++){
					AttendanceWeeklySch attweek = new AttendanceWeeklySch();
					attweek.setKqzid(attgrpid);
					attweek.setType(Integer.valueOf(weektime[h]));
					attweek.setBcid(Integer.valueOf(weekshif[h]));
					attweeklist.add(attweek);
				}
			}
			//自由工时 周排班
			String[] attFrWorkdays = attass.getAttFreeWorkdays();// 周工作日【自由工时】
			if(attFrWorkdays.length>0 && attass.getAtttype() == 3){
				for(int w=0;w<attFrWorkdays.length;w++){
					AttendanceWeeklySch attfrwor = new AttendanceWeeklySch();
					attfrwor.setKqzid(attgrpid);
					attfrwor.setType(Integer.valueOf(attFrWorkdays[w]));
					attfrwor.setBcid(0);
					attweeklist.add(attfrwor);
				}
			}
			if(attweeklist.size()>0){
				attendanceweeklyschservice.insertKqglAssoZhoupaibanList(attweeklist);
			}
			
			/***********/
			specialdateservice.deleteByPrimaryBykqzid(attgrpid);
			/**********/
			//特殊日期--必须打卡、不用打卡日期
			List<SpecialDate> speclist=new ArrayList<SpecialDate>();
			String[] attmuspudata = attass.getAttMustPunchData();// 必须打卡的日期【固定排班】
			String[] attmuspushifid = attass.getAttMustPunchShifid();// 必须打卡的班次id【固定排班】
			String[] attnonpudata = attass.getAttNonPunchData();// 不用打卡的日期【固定排班】
			if(attmuspudata.length>0 && attmuspushifid.length>0 && attass.getAtttype() == 1){
				for(int m=0;m<attmuspudata.length;m++){
					SpecialDate mut = new SpecialDate();
					mut.setKqzid(attgrpid);//考勤组id
					mut.setTsrq(attmuspudata[m]);//日期
					mut.setBcid(Integer.valueOf(attmuspushifid[m]));//班次id
					long date = new Date().getTime();
					mut.setLusjTime(date);//录入时间
					mut.setLuryid(180658);// 录入人员***********
					mut.setType(1);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(mut);
				}
			}
			if(attnonpudata.length>0 && attass.getAtttype() == 1){
				for(int n=0;n<attnonpudata.length;n++){
					SpecialDate non = new SpecialDate();
					non.setKqzid(attgrpid);//考勤组id
					non.setTsrq(attnonpudata[n]);//日期
					non.setBcid(0);//班次id
					long date = new Date().getTime();
					non.setLusjTime(date);//录入时间
					non.setLuryid(180658);// 录入人员***********
					non.setType(2);// 类型 1:必须打卡日期;2:不用打卡日期(扩展字段)
					speclist.add(non);
				}
			}
			if(speclist.size()>0){
				specialdateservice.insertKqglAssoTeshuList(speclist);
			}
			
			/**********/
			scheduleservice.deleteByPrimaryBykqzid(attgrpid);
			/***********/
			//记录排班(排班制)
			List<Schedule> schlist=new ArrayList<Schedule>();
			Schedule[] schedules = attass.getSchedules();// 排班日期【排班制】--班次id、日期
			if(schedules.length>0 && attass.getAtttype() == 2){
				for(int p=0;p<schedules.length;p++){
					Schedule sch = new Schedule();
					sch.setUserid(schedules[p].getUserid());
					sch.setData(schedules[p].getData());
					sch.setBcid(schedules[p].getBcid());
					sch.setKqzid(attgrpid);
					schlist.add(sch);
				}
			}
			if(schlist.size()>0){
				scheduleservice.insertKqglAssoPbmxList(schlist);
			}
			
			
	//		if (shiftmanagementservice.updateByPrimaryKeySelective(shif) > 0) {
				return ResultUtil.data(null,"修改考勤组信息成功");
	//		}
	//		return ResultUtil.error("修改考勤组信息失败");
	}
	
	/*******考勤组--结束*********/

	
	/***********APP--调用接口开始*****************/
	
	
//	@GetMapping(value="/attendancereport")
//	@ApiOperation(value = "获取考勤报表数据", httpMethod = "GET", notes = "接口发布说明")
	/**
	 * 获取考勤报表数据
	 */
	@PostMapping(value = "/attendancereport")
	@ApiOperation(value = "获取考勤报表数据", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 41)
	public Result<List<AttendanceReport>> getAttendanceReport(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
		
		
			//考勤报表列表
			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
			
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH) + 1;
			int date = cal.get(Calendar.DATE);
			
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    String str = sdf.format(d);
			
			Long startDate = 0l;
			Long endDate = 0l;
			
			if(!("").equals(attendancedetails.getStart())){
			   try {
				   String sdaet = getMinMonthDate(attendancedetails.getStart());
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
				   String edate = getMaxMonthDate(attendancedetails.getEnd());
				   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else{
				try {
					Calendar c = Calendar.getInstance();    
					c.add(Calendar.MONTH, 0);
					c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
					String first = mat.format(c.getTime());
					startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
					//获取当前月最后一天
					Calendar ca = Calendar.getInstance();    
					ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
					String last = mat.format(ca.getTime());
					endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			
			
			List<YgglMainEmp> attoff = attendancegroupservice.selectAttendanceOfficer(String.valueOf(qyid),attendancedetails.getText());//获取公司人员
			
			for(YgglMainEmp kqry : attoff){
				
				int gzsc = punchcarddetailsservice.selectWorkingHours(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
				
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,Integer.valueOf(kqry.getEmpNum()));
				int latenum = 0;// 迟到次数
				int latehours = 0;// 迟到时长
				int leanum = 0;// 早退次数
				int leahours = 0;// 早退时长
				if(initial.size() > 0){
					for(PunchRecord prd : initial){
						if(prd.getType() == 1 && prd.getResults() > 0){
							latenum++;
							latehours += prd.getResults();
						}
						if(prd.getType() == 2 && prd.getResults() > 0){
							leanum++;
							leahours += prd.getResults();
						}
					}
				}
				
				AttendanceReport apr = new AttendanceReport();
				apr.setId(Integer.valueOf(kqry.getEmpNum()));
				apr.setName(kqry.getName());//姓名
				apr.setJobnumber(kqry.getEmpNum());//工号
				apr.setWorkhours(gzsc);//工作时长
				
				apr.setLatenum(latenum);//
				apr.setLatehours(latehours);//
				apr.setLeanum(leanum);//
				apr.setLeahours(leahours);//
				/**********/
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum())); //考勤组信息
				//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
				if(attgro != null){//该员工是否加入到考勤组
					if(attgro.getPbfs() == 1){
						//当前月     必须打卡日期
						List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						int bxdk = bxdklist.size();
						//当前月     无需打卡日期
						List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						String[] appmaps= new String[wxdk.size()];
						int d1 = 0;
						for(SpecialDate spe:wxdk){
							appmaps[d1] = spe.getTsrq();
							d1++;
						}
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						int q = 0;
						 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])){
										
										q++;
										
										y++;
										if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
											y = y-1;
										}
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
						 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++;
							}
						}
	//					System.out.println(xiuxi);
						apr.setRestday(xiuxi);//休息天数
						apr.setAnswerday(shangban);//应出勤
					}else{
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						 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();
							}
						 }
						 
						 int xiuxi = getDaysByYearMonth(year,month) - y;
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y);//应出勤
					}
				    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate);//打卡记录
				    apr.setActualday(attendance.size());//已出勤
					if(apr.getAnswerday() > 0){
						BigDecimal g = new BigDecimal(apr.getAnswerday());  
						BigDecimal h = new BigDecimal(apr.getActualday()); 
						int lack = g.subtract(h).intValue();  
						apr.setMinerday(lack);//缺勤
					}
		            int sbqk = 0;
		            int xbqk = 0;
		            for(PunchCardDetails pcd:attendance){
		            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk1() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk1() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk2() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk2() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk3() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk3() == null){
		            			xbqk++;
		            		}
		            	}
		            }
		            apr.setGoworkmissingcard(sbqk);//上班缺卡
		            apr.setOffworkmissingcard(xbqk);//下班缺卡
				}
				/**********/
				
				
				
				attrep.add(apr);
			}
			
			
			return ResultUtil.data(attrep);
	}
	
	
	
	
	
	
	/**
	 * 获取考勤详情
	 */
	@GetMapping(value="/attendancedetails")
	@ApiOperation(value = "获取考勤详情数据", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 42)
	public Result<List<PunchCardDetails>> getAttendanceDetails(@CurrentUser UserBean userBean) {
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			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();
			}
			
			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("");
				}
			} 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 = getMinMonthDate(str);
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
				   String edate = 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); //考勤组信息
			//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);
					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);
					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);//打卡记录
				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 = getMinMonthDate(str);
			   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
			       
			   String edate = 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); //考勤组信息
		
		//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		if(attgro != null){//该员工是否加入到考勤组
			 
			if(attgro.getPbfs() == 1){//固定排班
				String yemo = year + "-" + month;
				
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
				
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
				
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
					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);
					
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					
					
					//考勤打卡原始记录
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
					
					int week = Integer.valueOf(dateToWeek(famt.format(da)));//2
				    AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
				    
				    if(atwek != null){//有固定周排班
			    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), famt.format(da));//查询打卡当天是否在特殊休息日期里面存在
			    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}else{//今天上班
				    		ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
				    		if(bcz != null){
				    			GetScheduleAux(bcz,ss,famt.format(da));
				    		}
			    		}
			    	}else{
			    		//必须打卡
			    		SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), famt.format(da));//判断特殊日期
			    		if(tsri != null){
			    			ShiftManagement tsrq = shiftmanagementservice.selectByPrimaryKey(tsri.getBcid());
			    			if(tsrq!=null){
			    				GetScheduleAux(tsrq,ss,famt.format(da));
			    			}
			    		}else{
			    			//休息
			    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
			    			AttSchedule as = new AttSchedule();
			    			as.setId(0);
				    		as.setSort(0);//0:表示今天为休息日
				    		as.setTime(0l);
				    		as.setStarttime(0l);
				    		as.setEndtime(0l);
				    		atts.add(as);
				    		ss.setAttsch(atts);
			    		}
			    	}
					dss.add(ss);
				}
				
				return ResultUtil.data(dss);
				
				
			}else if(attgro.getPbfs() == 2){//自由排班
				
				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);//打卡数据
				
				String[] array1 = new String[callist.size()];
				
				String[] erinnern1 = new String[rltilist.size()];
				
				int r = 0;
				
				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++;
					
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					int q = 0; 
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = sdu.getData();//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						
						System.out.println(q+"--"+punchtime);
						
						erinnern1[q] = punchtime;
						q++;
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
//						String schetime = mat.format(new Date(sdu.getData().toString()));//排班详细数据日期
						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);
						}
					}
					
					
					ShiftManagement shifs = shiftmanagementservice.selectByPrimaryKey(sdu.getBcid());
					
					/*********/
					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);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk1(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks1(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs1(),2)+":00")));
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(2);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk1(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks1(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs1(),2)+":00")));
									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);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk2(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks2(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs2(),2)+":00")));
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(4);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk2(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks2(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs2(),2)+":00")));
									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);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk3(),2)+":00")));
									as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks3(),2)+":00")));
									as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs3(),2)+":00")));
									atts.add(as);
								}else{
									AttSchedule as = new AttSchedule();
									as.setId(shifs.getId());
									as.setSort(6);
									as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk3(),2)+":00")));
									as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks3(),2)+":00")));
									as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs3(),2)+":00")));
									atts.add(as);
								}
							}
							ss.setAttsch(atts);
						}
					}else{
						List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
		    			AttSchedule as = new AttSchedule();
		    			as.setId(0);
			    		as.setSort(0);//0:表示今天为休息日
			    		as.setTime(0l);
			    		as.setStarttime(0l);
			    		as.setEndtime(0l);
			    		atts1.add(as);
			    		ss.setAttsch(atts1);
					}
					/*******/
					
					dss.add(ss);
				}
				
				String yemo = year + "-" + month;
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
					Date da = null;
					try {
						da = famt.parse(yemo + "-" + i);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					
					
					
					
				}
				
				
				
//				String[] array1 = {"2019-11-10","2019-11-12","2019-11-13"};  
//		        String[] array2 = {"2019-11-10","2019-11-14"};  
		        
				List<String> erilist = compare(array1,erinnern1);  //缺少的天数
		        String[] eris=erilist.toArray(new String[erilist.size()]);//缺少的具体天数(yyyy-mm-dd)
		        
		        String[] eridadys = array_unique(eris);
		        
				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);
				}
				
				
				
				
				
				//打卡记录
				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();
				}
				
				List<String> list = compare(array1,array2);  
		        String[] dadys=list.toArray(new String[list.size()]);
				for(int g=0;g<dadys.length;g++){
					ScheduleAux ss = new ScheduleAux();
					ss.setId(0);
					ss.setUserid(userid);
					ss.setData(dadys[g]);
					ss.setBcid(0);
					ss.setKqzid(0);
					
					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);
				}
				
				return ResultUtil.data(dss);
				
			}else{//自由工时
				String yemo = year + "-" + month;
				
				List<CalendarAlarm> rltilist = calendaralarmservice.getCalendarAlarmList(startDate,endDate,userid);//日历提醒事务
				
				List<ScheduleAux> dss = new ArrayList<ScheduleAux>();
				List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);//打卡数据
				for(int i = 1; i <= getDaysByYearMonth(year,month); i++){//全月
					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);
					
					//日历提醒事务
					List<AttCalendarAlarm> affairs = new ArrayList<AttCalendarAlarm>();
					for(CalendarAlarm acd : rltilist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(Long.valueOf(acd.getRemindtime()));
						if(schetime.equals(punchtime)){
							AttCalendarAlarm afa = AttCalendarAlarm.builder().build();
							afa.setId(acd.getId());
							afa.setRemindtime(String.valueOf(acd.getRemindtime()));//提醒日期
							afa.setContent(acd.getContent());//内容
							long nowtime = 0;
							try {
								nowtime = DateUtil.getStringTime(now,"yyyy-MM-dd");
							} catch (ParseException e) {
								e.printStackTrace();
							}
							Long time = (Long.valueOf(acd.getRemindtime()) - nowtime)/1000/60;
							if(time < 0){
								afa.setState(2);//类型 0:未完成 1:已完成 2:逾期
							}else{
								afa.setState(acd.getState());//类型 0:未完成 1:已完成 2:逾期
							}
							affairs.add(afa);
							ss.setRemind(affairs);
						}
					}
					
					List<PunchRecord> attprs = new ArrayList<PunchRecord>();
					for(PunchRecord pre:dajllist){//对应的打卡数据
						String schetime = famt.format(da);//排班详细数据日期
						String punchtime = DateUtil.getStringFormat(pre.getAttime());
						if(schetime.equals(punchtime)){
							PunchRecord ar = new PunchRecord();
							ar.setId(pre.getId());
							ar.setDktime(pre.getDktime());// 打卡时间
							ar.setStrdktime(pre.getStrdktime());//
							ar.setLon(pre.getLon());// 经度
							ar.setLat(pre.getLat());// 纬度
							ar.setAddress(pre.getAddress());// 定位地址
							ar.setResults(pre.getResults());// 打卡结果
							ar.setUserId(pre.getUserId());// 用户id
							ar.setType(pre.getType());// 类型(pre.get类型 0:无排班打卡 1:上班 2:下班)
							ar.setStatus(pre.getStatus());// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:请假迟到 9:请假早退 10:调休)',
							ar.setSort(pre.getSort());// 序号
							ar.setCardType(pre.getCardType());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
							ar.setMac(pre.getMac());// mac地址
							ar.setMacname(pre.getMacname());// WIFI名称
							ar.setQyid(pre.getQyid());// 企业id
							ar.setAttdate(pre.getAttdate());// 考勤日期
							ar.setAttime(pre.getAttime());// 考勤时间
							ar.setStrattime(pre.getStrattime());//
							ar.setDkmxid(pre.getDkmxid());// 打卡明细id
							ar.setBcid(pre.getBcid());// 班次id
							ar.setRemarks(pre.getRemarks());// 考勤备注
							ar.setUsername(pre.getUsername());
							attprs.add(ar);
							ss.setAttpr(attprs);
						}
					}
					
					int week = Integer.valueOf(dateToWeek(famt.format(da)));//2
					AttendanceWeeklySch atwek = attendanceweeklyschservice.selectFreeWorkingHours(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{
			    		//必须打卡
			    		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);
			    		}
			    	}
					
					dss.add(ss);
				}
				
				
				
				return ResultUtil.data(dss);
			}
		}
		
		return ResultUtil.data(null);
	}
	 
//	 @GetMapping(value = "/ClockData")
//	 @ApiOperation(value = "获取考勤打卡数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
	/**
	 * 获取考勤打卡数据------APP打卡
	 */
	 @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 {
			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();
		 }
		 
					 
				 
				 
				 int qyid = userBean.getOrgCode();//坏小孩【企业id】
				 int userid = userBean.getEmpNum();//用户id	
				 
		//		 QueryWrapper<YgglAttaHtxxb> queryWrapper = new QueryWrapper<>();
		//		 queryWrapper.eq("org_code",qyid).eq("emp_num", userid);
				 
				 
			     
			     
			     AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid); //考勤组信息
			     
			     //pbfs:排班方式 1:固定排班;2:自由排班;3:自由工时
				 if(attgro != null){//判断当前用户是否加入到考勤组
					 //排班制
				     Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
				     //固定排班
				     int week = Integer.valueOf(dateToWeek(str));//4
				     AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
					 
				    if(attgro.getPbfs() == 1){//固定排班
		//		    	int week = Integer.valueOf(dateToWeek(str));//4
		//		    	AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);
				    	if(atwek != null){//有固定周排班
				    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), str);//查询打卡当天是否在特殊休息日期里面存在
				    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
				    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts.add(as);
					    		attcar.setAttsch(atts);
				    		}else{//今天上班
					    		ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
					    		if(bcz != null){
					    			Getshiftinformationbatch(bcz,attcar,str);
					    		}
				    		}
				    	}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(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs1(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(2);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs1(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 2 || jrpb.getSxbcs() == 3){//2次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(3);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs2(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(4);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs2(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 3){//3次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(5);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs3(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(6);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs3(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
							}else{//当天排班为休息
								List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts1.add(as);
					    		attcar.setAttsch(atts1);
							}
						}else{//当天考勤组为给排班
							List<ShiftManagement> shifs = shiftmanagementservice.selectByPrimaryByQyid(qyid);
							List<SystemShift> akms = new ArrayList<SystemShift>();
							for(ShiftManagement ah:shifs){
								 SystemShift sys = new SystemShift();
								 sys.setId(ah.getId());
								 
								 String name = ah.getName();
								 String context = "";
								 if(ah.getSxbcs() == 1 || ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
									 context = dealDateFormat(ah.getSbdk1(),2) + "-" + dealDateFormat(ah.getXbdk1(),2);
								 }
								 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
									 context = context +" "+ dealDateFormat(ah.getSbdk2(),2) + "-" + dealDateFormat(ah.getXbdk2(),2);
								 }
								 if(ah.getSxbcs() == 3){
									 context = context +" "+ dealDateFormat(ah.getSbdk3(),2) + "-" + dealDateFormat(ah.getXbdk3(),2);
								 }
								 sys.setContext(name+ " " + context);
								 
								 akms.add(sys);
						   }
						   attcar.setSsfh(akms);//无排班时 获取的系统班次
						}
				    	
					}else{//自由工时
						//int week = Integer.valueOf(dateToWeek(str));//4
						
						AttendanceWeeklySch wekz = attendanceweeklyschservice.WeeklyFreeRoster(attgro.getId(),week);
						if(wekz != null){//
							String dada = str+" "+attgro.getKqkssjTime()+":00";
							attcar.setStapclotime(Long.valueOf(dateToStamp(dada)));
						}
						
						if(!("").equals(attgro.getJbzdsc())){
							attcar.setCanpunchworkdate(Double.valueOf(attgro.getJbzdsc()));//上班打卡后多久大下班卡
						}
						
						
					}
				    if(jrpb != null || atwek != null){
				    	ShiftManagement shif = null;
				    	if(attgro.getPbfs() == 1){
				    		shif = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
				    	}else if(attgro.getPbfs() == 2){
				    		shif = shiftmanagementservice.selectByPrimaryKey(jrpb.getBcid());
				    	}
				    	
				    	if(shif != null){
				    		if(shif.getIsXbdk() == 1){
				    			attcar.setNoclockout(true);// 下班不用打卡
				    		}else{
				    			attcar.setNoclockout(false);// 下班不用打卡
				    		}
				    		attcar.setAllowlate(shif.getYxcdfzs());// 允许迟到分钟数
				    		attcar.setSeriouslate(shif.getYzcdfzs());// 严重迟到分钟数
				    		attcar.setAbsenteeismlate(shif.getKgcdfzs());// 旷工迟到分钟数
				    		if(shif.getIsWzwd() == 1){
				    			attcar.setIslatelate(true);// 晚走晚到
				    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
				    			int p = 0;
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1())){p = 2;}
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2())){p = 4;}
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2()) && !("").equals(shif.getXbwz3()) && !("").equals(shif.getSbwd3())){p = 6;}
				    			AttLateLate ala = new AttLateLate();
				    			ala.setLatewalk(shif.getXbwz1());
				    			ala.setArrivelate(shif.getSbwd1());
				    			atwzwd.add(ala);
				    			if(p == 4 || p == 6){
				    				AttLateLate alat = new AttLateLate();
				    				alat.setLatewalk(shif.getXbwz2());
				    				alat.setArrivelate(shif.getSbwd2());
				    				atwzwd.add(alat);
				    			}
				    			if(p == 6){
				    				AttLateLate alas = new AttLateLate();
				    				alas.setLatewalk(shif.getXbwz3());
				    				alas.setArrivelate(shif.getSbwd3());
				    				atwzwd.add(alas);
				    			}
				    			attcar.setAttlat(atwzwd);
				    		}else{
				    			attcar.setIslatelate(false);// 晚走晚到
				    		}
				    	}
				    }
				    
				    attcar.setAttgrouptype(attgro.getPbfs());//1:固定排班;2:自由排班;3:自由工时
				    
				    //外勤   true:开   false:关
				    if(attgro.getIsWq() == 1) {
				    	attcar.setFieldpersonnel(true);
				    }else {
				    	attcar.setFieldpersonnel(false);
				    }
				    
				    
					//打卡方式
				    List<AttGroupBinPunchMode> attmetlist =  attgroupbinpunchmodeservice.selectByPrimaryByKqzId(attgro.getId());
				    for(AttGroupBinPunchMode agbp:attmetlist){
				    	//类型(1:考勤机;2:地址;3:WIFI)
				    	if(agbp.getType() == 1){
				    		attcar.setAttmachine(true);
				    	}else if(agbp.getType() == 2){
				    		attcar.setAttaddress(true);
				    	}else{
				    		attcar.setAttwifi(true);
				    	}
				    }
				    
				    //详细打卡方式
				    List<AttClockMethod> akms = new ArrayList<AttClockMethod>();
				    
				    for(AttGroupBinPunchMode abp:attmetlist){
				    	if(abp.getType() == 1){
				    		AttendanceMachine kqjs = attendancemachineservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqjs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(1);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
				    		akms.add(akm);
				    	}else if(abp.getType() == 2){
				    		PunchCardAddress kqdzs = punchcardaddressservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqdzs.getName());// 打卡名称
				    		akm.setMac("");// wifi【wifi】
				    		akm.setAttrange(kqdzs.getDkfw());// 范围【地址】
				    		akm.setType(2);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(kqdzs.getLon());// 经度【地址】
				    		akm.setLatitude(kqdzs.getLat());// 纬度【地址】
				    		akms.add(akm);
				    	}else{
				    		PunchCardWiFi kqwfs = punchcardwifiservice.selectByPrimaryKey(abp.getDkfsid()); 
				    		AttClockMethod akm = AttClockMethod.builder().build();
				    		akm.setName(kqwfs.getName());// 打卡名称
				    		akm.setMac(kqwfs.getMac());// wifi【wifi】
				    		akm.setAttrange(0);// 范围【地址】
				    		akm.setType(3);// 类型(1:考勤机;2:地址;3:WIFI)
				    		akm.setLongitude(0);// 经度【地址】
				    		akm.setLatitude(0);// 纬度【地址】
				    		akms.add(akm);
				    	}
				    }
				    attcar.setMachine(akms);
				    
				    
				 }else{
					 //无排班
					 //系统班次
		//			 List<ShiftManagement> shifs = shiftmanagementservice.selectByPrimaryByQyid(qyid);
		//			 List<SystemShift> akms = new ArrayList<SystemShift>();
		//			 for(ShiftManagement ah:shifs){
		//				 SystemShift sys = new SystemShift();
		//				 sys.setId(ah.getId());
		//				 
		//				 String name = ah.getName();
		//				 String context = "";
		//				 if(ah.getSxbcs() == 1 || ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
		//					 context = dealDateFormat(ah.getSbdk1(),2) + "-" + dealDateFormat(ah.getXbdk1(),2);
		//				 }
		//				 if(ah.getSxbcs() == 2 || ah.getSxbcs() == 3){
		//					 context = context +" "+ dealDateFormat(ah.getSbdk2(),2) + "-" + dealDateFormat(ah.getXbdk2(),2);
		//				 }
		//				 if(ah.getSxbcs() == 3){
		//					 context = context +" "+ dealDateFormat(ah.getSbdk3(),2) + "-" + dealDateFormat(ah.getXbdk3(),2);
		//				 }
		//				 sys.setContext(name+ " " + context);
		//				 
		//				 akms.add(sys);
		//			 }
		//			 attcar.setSsfh(akms);//无排班时 获取的系统班次
					 
					 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(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs1(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs1(),2)+":00")));
			    		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(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs2(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs2(),2)+":00")));
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(5);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs3(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs3(),2)+":00")));
			    		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(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs1(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(2);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk1(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks1(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs1(),2)+":00")));
			    		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(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs2(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(4);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk2(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks2(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs2(),2)+":00")));
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	    	if(shiftm.getSxbcs() == 3){//3次上下班
	    		for(int o=0;o<2;o++){
	    			if(o==0){
		    			AttSchedule as = new AttSchedule();
		    			as.setId(shiftm.getId());
			    		as.setSort(5);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getSbqjjs3(),2)+":00")));
			    		atts.add(as);
	    			}else{
	    				AttSchedule as = new AttSchedule();
	    				as.setId(shiftm.getId());
			    		as.setSort(6);
			    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbdk3(),2)+":00")));
			    		as.setStarttime(("").equals(shiftm.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjks3(),2)+":00")));
			    		as.setEndtime(("").equals(shiftm.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shiftm.getXbqjjs3(),2)+":00")));
			    		atts.add(as);
	    			}
	    		}
	    		attcar.setAttsch(atts);
	    	}
	 }
	 
	 /**
	   * 根据班次id获取班次信息
	   */
	 @GetMapping(value="/shiftdetails/{id}")
	 @ApiOperation(value = "获取班次详细数据------APP打卡", httpMethod = "GET", notes = "接口发布说明")
	 @ApiOperationSupport(order = 50)
	 public Result<ShiftDetails> getShiftDetails(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
	     
	     int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
		 
		 Date d = new Date();
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		 String str = sdf.format(d);
		 
		 Long startDate = 0l;
	     Long endDate = 0l;
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(str,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid); //考勤组信息
		 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(dateToStamp(data+" "+dealDateFormat(banci.getSbdk1(),2)+":00"));
					xbdk1 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk1(),2)+":00"));
				}
				if(banci.getSxbcs()== 2 || banci.getSxbcs()== 3){
					sbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk2(),2)+":00"));
					xbdk2 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk2(),2)+":00"));
				}
				if(banci.getSxbcs()== 3){
					sbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getSbdk3(),2)+":00"));
					xbdk3 = Long.valueOf(dateToStamp(data+" "+dealDateFormat(banci.getXbdk3(),2)+":00"));
				}
			}
			//之前打卡的班次
			PunchRecord mapuca = punchrecordservice.MaintenancePunchCard(startCorrDate,endCorrDate,userid);
			
			if(mapuca != null && !id.equals(mapuca.getBcid())){
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid);
				if(initial.size() > 0){
					RestMethod(initial,initial.get(0).getDkmxid());
				}
			}
			
			//当天的所有打卡记录
			List<PunchRecord> mapucalist = punchrecordservice.getMaintenancePunchCardList(startCorrDate,endCorrDate,userid);
			PunchRecord minAttid = null;
			PunchRecord maxAttid = null;
			int dkmxid = 0;
			if(mapucalist.size() > 0){
				//最小值
		        minAttid = mapucalist.stream().min(Comparator.comparing(PunchRecord::getId)).get();
//		        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 && !id.equals(mapuca.getBcid())){
				if(banci != null){//修改后有班次打卡
					if(banci.getSxbcs() == 1){//修改后一天打两次
						if(mapucalist.size() > 2){/////当天打卡多条的话 取最开始打的卡和最后打的卡 作为新一轮的上下班考勤
							for(PunchRecord pre : mapucalist){/********/
								if(pre.getId() != minAttid.getId() && pre.getId() != maxAttid.getId()){//去除最大和最小 其他均改为“打卡无效:此记录已被更新”
									PunchRecord record = new PunchRecord();
									record.setId(pre.getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									if((pre.getSort())%2 > 0){//上班
										Long time = (pre.getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);//上班应打卡时间
									}else{//下班
										Long time = (pre.getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setResults(0);// 打卡结果
										}else{
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//下班应打卡时间
									}
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}else{
									if(pre.getId() == minAttid.getId()){//上班
										PunchRecord record = new PunchRecord();
										record.setId(pre.getId());
										record.setType(1);//上班
										Long time = (pre.getDktime() - sbdk1)/1000/60;
										if(time > 0){
											record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk1);
										record.setBcid(banci.getId());//班次id
										punchrecordservice.updateByPrimaryKeySelective(record);
									}else if(pre.getId() == maxAttid.getId()){//下班
										PunchRecord record = new PunchRecord();
										record.setId(pre.getId());
										record.setType(2);//下班
										Long time = (pre.getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);
										record.setBcid(banci.getId());//班次id
										record.setSort(2);
										punchrecordservice.updateByPrimaryKeySelective(record);
									}
								}
							}
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							//
							PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//上班
							PunchCardDetails max = new PunchCardDetails();
							max.setId(dkmxid);//需修改的明细id
							max.setXbdk1(maxdata.getDktime());
							max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
							
							Long woktimes = (maxdata.getDktime() - mindata.getDktime())/1000/60;
							max.setGzsc(Double.valueOf(woktimes));
							
							punchcarddetailsservice.updateByPrimaryKeySelective(max);
						}else{////
							PunchRecord mindataone = null;
							//当天打卡记录为1条
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							//当天打卡记录为2条
							if(maxAttid != null && minAttid.getId() != maxAttid.getId()){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());
								record.setType(2);//下班
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);
								record.setBcid(banci.getId());//班次id
								record.setSort(2);
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								PunchCardDetails max = new PunchCardDetails();
								max.setId(dkmxid);//需修改的明细id
								max.setXbdk1(maxdata.getDktime());
								max.setXbdk1jg(maxdata.getResults());// 下班1打卡结果
								
								Long woktimes = (maxdata.getDktime() - mindataone.getDktime())/1000/60;
								max.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(max);
							}
						}
					}else if(banci.getSxbcs() == 2){//修改后一天打四次
						if(mapucalist.size() > 4){//当天打卡多次
							String[] scstr= new String[3];
							for(int y=0;y<mapucalist.size();y++){
								if(y == 0){//上班
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
//									record.setType(1);//上班
									Long time = (mindata.getDktime() - sbdk1)/1000/60;
									if(time > 0){
										record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
										record.setResults(Integer.valueOf(time.toString()));// 打卡结果
									}else{
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}
									record.setAttime(sbdk1);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								if(y == 1 || y == 2){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									
									if((mapucalist.get(y).getSort())%2 == 0){//下班
										Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
										if(time > 0){
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}else{
											record.setStatus(4);
											record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
										}
										record.setAttime(xbdk1);//下班应打卡时间
										
										scstr[0] = String.valueOf(mapucalist.get(y).getId());
									}else{//上班
										Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
										if(time > 0){
											record.setStatus(3);
											record.setResults(Integer.valueOf(time.toString()));// 打卡结果
										}else{
											record.setStatus(1);
											record.setResults(0);// 打卡结果
										}
										record.setAttime(sbdk2);//上班应打卡时间
										
										scstr[1] = String.valueOf(mapucalist.get(y).getId());
									}
									
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								
								
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								if(mapucalist.get(y).getId() == maxdata.getId()){//下班
									PunchRecord record = new PunchRecord();
									
									record.setId(maxdata.getId());
									record.setType(2);//下班
									Long time = (maxdata.getDktime() - xbdk2)/1000/60;
									if(time > 0){
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}else{
										record.setStatus(4);
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
									record.setSort(4);
									record.setAttime(xbdk2);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
									
									scstr[2] = String.valueOf(maxdata.getId());
								}
								
								if(y == 3 || y > 3 && mapucalist.get(y).getId() != maxdata.getId()){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									record.setResults(0);// 打卡结果
									record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
							}
							
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							
							for(int t=0;t<scstr.length;t++){
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(scstr[t]));//单条打卡明细
								
								PunchCardDetails dkmx = new PunchCardDetails();
								dkmx.setId(dkmxid);//需修改的明细id
								if(t == 0){
									dkmx.setXbdk1(dtdkmx.getDktime());
									dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
								}else if(t == 1){
									dkmx.setSbdk2(dtdkmx.getDktime());
									dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
								}else{
									dkmx.setXbdk2(dtdkmx.getDktime());
									dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
								}
								Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
								dkmx.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
							}
							 
						}else{//打卡小于4次
							PunchRecord mindataone = null;
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							
							PunchCardDetails pcd = new PunchCardDetails();
							if(mapucalist.size() >= 2){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());//当天一条记录的id
								record.setType(2);
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
								pcd.setXbdk1(dtdkmx.getDktime());
								pcd.setXbdk1jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 3){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(2).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
								pcd.setSbdk2(dtdkmx.getDktime());
								pcd.setSbdk2jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 4){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(maxAttid.getId());//当天一条记录的id
								record.setType(2);
								Long time = (maxAttid.getDktime() - xbdk2)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
								pcd.setXbdk2(dtdkmx.getDktime());
								pcd.setXbdk2jg(dtdkmx.getResults());
							}
							
							pcd.setId(dkmxid);
							punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
						}
					}else if(banci.getSxbcs() == 3){//修改后一天打六次
						if(mapucalist.size() > 6){//当天打卡多次
							String[] lcstr= new String[5];
							for(int y=0;y<mapucalist.size();y++){
								if(y == 0){//上班
									PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									Long time = (mindata.getDktime() - sbdk1)/1000/60;
									if(time > 0){
										record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
										record.setResults(Integer.valueOf(time.toString()));// 打卡结果
									}else{
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}
									record.setAttime(sbdk1);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								if(y == 1 || y == 2 || y == 3 || y == 4){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									
									if((mapucalist.get(y).getSort())%2 == 0){//下班
										if(y == 1){
											Long time = (mapucalist.get(y).getDktime() - xbdk1)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setAttime(xbdk1);//下班应打卡时间
											lcstr[0] = String.valueOf(mapucalist.get(y).getId());
										}
										
										if(y == 3){
											Long time = (mapucalist.get(y).getDktime() - xbdk2)/1000/60;
											if(time > 0){
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}else{
												record.setStatus(4);
												record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
											}
											record.setAttime(xbdk2);//下班应打卡时间
											lcstr[2] = String.valueOf(mapucalist.get(y).getId());
										}
										
									}else{//上班
										if(y == 2){
											Long time = (mapucalist.get(y).getDktime() - sbdk2)/1000/60;
											if(time > 0){
												record.setStatus(3);
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk2);//上班应打卡时间
											lcstr[1] = String.valueOf(mapucalist.get(y).getId());
										}
										
										if(y == 4){
											Long time = (mapucalist.get(y).getDktime() - sbdk3)/1000/60;
											if(time > 0){
												record.setStatus(3);
												record.setResults(Integer.valueOf(time.toString()));// 打卡结果
											}else{
												record.setStatus(1);
												record.setResults(0);// 打卡结果
											}
											record.setAttime(sbdk3);//上班应打卡时间
											lcstr[3] = String.valueOf(mapucalist.get(y).getId());
										}
									}
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
								
								
								PunchRecord maxdata = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//下班
								if(mapucalist.get(y).getId() == maxdata.getId()){//下班
									PunchRecord record = new PunchRecord();
									
									record.setId(maxdata.getId());
									record.setType(2);//下班
									Long time = (maxdata.getDktime() - xbdk3)/1000/60;
									if(time > 0){
										record.setStatus(1);
										record.setResults(0);// 打卡结果
									}else{
										record.setStatus(4);
										record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
									}
									record.setSort(6);
									record.setAttime(xbdk3);
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
									
									lcstr[4] = String.valueOf(maxdata.getId());
								}
								
								if(y == 5 || y > 5 && mapucalist.get(y).getId() != maxdata.getId()){
									PunchRecord record = new PunchRecord();
									record.setId(mapucalist.get(y).getId());
									record.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setSort(0);//序号(0:打卡无效:此记录已被更新)
									record.setResults(0);// 打卡结果
									record.setAttime(mapucalist.get(y).getDktime());//上班应打卡时间
									record.setBcid(banci.getId());//班次id
									punchrecordservice.updateByPrimaryKeySelective(record);
								}
							}
							
							//修改打卡明细
							PunchRecord mindata = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
							PunchCardDetails record = new PunchCardDetails();
							record.setId(dkmxid);//需修改的明细id
							record.setSbdk1(mindata.getDktime());
							record.setSbdk1jg(mindata.getResults());// 上班1打卡结果
							record.setXbdk1(null);
							record.setXbdk1jg(0);// 下班1打卡结果
							record.setSbdk2(null);
							record.setSbdk2jg(0);// 上班2打卡结果
							record.setXbdk2(null);
							record.setXbdk2jg(0);// 下班2打卡结果
							record.setSbdk3(null);
							record.setSbdk3jg(0);// 上班3打卡结果
							record.setXbdk3(null);
							record.setXbdk3jg(0);// 下班3打卡结果
							record.setYdkcs(banci.getSxbcs()*2);//应打卡次数
							record.setGzsc(Double.valueOf("0"));
							punchcarddetailsservice.ModifyPunchDetails(record);
							
							for(int t=0;t<lcstr.length;t++){
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(Integer.valueOf(lcstr[t]));//单条打卡明细
								
								PunchCardDetails dkmx = new PunchCardDetails();
								dkmx.setId(dkmxid);//需修改的明细id
								if(t == 0){
									dkmx.setXbdk1(dtdkmx.getDktime());
									dkmx.setXbdk1jg(dtdkmx.getResults());// 下班1打卡结果
								}else if(t == 1){
									dkmx.setSbdk2(dtdkmx.getDktime());
									dkmx.setSbdk2jg(dtdkmx.getResults());// 上班2打卡结果
								}else if(t == 2){
									dkmx.setXbdk2(dtdkmx.getDktime());
									dkmx.setXbdk2jg(dtdkmx.getResults());// 下班2打卡结果
								}else if(t == 3){
									dkmx.setSbdk3(dtdkmx.getDktime());
									dkmx.setSbdk3jg(dtdkmx.getResults());// 上班3打卡结果
								}else{
									dkmx.setXbdk3(dtdkmx.getDktime());
									dkmx.setXbdk3jg(dtdkmx.getResults());// 下班3打卡结果
								}
								Long woktimes = (dtdkmx.getDktime() - mindata.getDktime())/1000/60;
								dkmx.setGzsc(Double.valueOf(woktimes));
								
								punchcarddetailsservice.updateByPrimaryKeySelective(dkmx);
							}
						}else{
							/**aaa**/
							PunchRecord mindataone = null;
							if(minAttid != null || maxAttid != null){
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(0).getId());//当天一条记录的id
								record.setType(1);//上班
								Long time = (mapucalist.get(0).getDktime() - sbdk1)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								//
								mindataone = punchrecordservice.selectByPrimaryKey(minAttid.getId());//上班
								PunchCardDetails dan = new PunchCardDetails();
								dan.setId(dkmxid);//需修改的明细id
								dan.setSbdk1(mindataone.getDktime());
								dan.setSbdk1jg(mindataone.getResults());// 上班1打卡结果
								dan.setYdkcs(banci.getSxbcs()*2);//应打卡次数
								dan.setGzsc(Double.valueOf("0"));
								punchcarddetailsservice.updateByPrimaryKeySelective(dan);
							}
							
							PunchCardDetails pcd = new PunchCardDetails();
							if(mapucalist.size() >= 2){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(1).getId());//当天一条记录的id
								record.setType(2);
								Long time = (mapucalist.get(1).getDktime() - xbdk1)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk1);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(1).getId());//单条打卡明细
								pcd.setXbdk1(dtdkmx.getDktime());
								pcd.setXbdk1jg(dtdkmx.getResults());
							}
							if(mapucalist.size() >= 3){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(2).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(2).getDktime() - sbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(2).getId());//单条打卡明细
								pcd.setSbdk2(dtdkmx.getDktime());
								pcd.setSbdk2jg(dtdkmx.getResults());
							}
							
							
							if(mapucalist.size() >= 4){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(3).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(3).getDktime() - xbdk2)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(xbdk2);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(3).getId());//单条打卡明细
								pcd.setXbdk2(dtdkmx.getDktime());
								pcd.setXbdk2jg(dtdkmx.getResults());
								
							}
							if(mapucalist.size() >= 5){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(mapucalist.get(4).getId());//当天一条记录的id
								record.setType(1);
								Long time = (mapucalist.get(4).getDktime() - sbdk3)/1000/60;
								if(time > 0){
									record.setStatus(3);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
									record.setResults(Integer.valueOf(time.toString()));// 打卡结果
								}else{
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}
								record.setAttime(sbdk3);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(mapucalist.get(4).getId());//单条打卡明细
								pcd.setSbdk3(dtdkmx.getDktime());
								pcd.setSbdk3jg(dtdkmx.getResults());
								
							}
							
							if(mapucalist.size() >= 6){
								/***/
								PunchRecord record = new PunchRecord();
								record.setId(maxAttid.getId());//当天一条记录的id
								record.setType(2);
								Long time = (maxAttid.getDktime() - xbdk3)/1000/60;
								if(time > 0){
									record.setStatus(1);
									record.setResults(0);// 打卡结果
								}else{
									record.setStatus(4);
									record.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
								}
								record.setAttime(xbdk3);//当天应打卡时间
								record.setBcid(banci.getId());//班次id
								punchrecordservice.updateByPrimaryKeySelective(record);
								/***/
								PunchRecord dtdkmx = punchrecordservice.selectByPrimaryKey(maxAttid.getId());//单条打卡明细
								pcd.setXbdk3(dtdkmx.getDktime());
								pcd.setXbdk3jg(dtdkmx.getResults());
							}
							
							pcd.setId(dkmxid);
							punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
							/**bbb***/
						}
					}
				}else{////修改后班次为休息的
					RestMethod(mapucalist,dkmxid);
				}
			}
			
			/***********************/
		 
		 
		 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(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk1(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks1(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs1(),2)+":00")));
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(2);
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk1(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks1(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs1(),2)+":00")));
				    		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(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk2(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks2(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs2(),2)+":00")));
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(4);
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk2(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks2(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs2(),2)+":00")));
				    		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(dateToStamp(str+" "+dealDateFormat(shifs.getSbdk3(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjks3(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getSbqjjs3(),2)+":00")));
				    		atts.add(as);
		    			}else{
		    				AttSchedule as = new AttSchedule();
		    				as.setId(shifs.getId());
				    		as.setSort(6);
				    		as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbdk3(),2)+":00")));
				    		as.setStarttime(("").equals(shifs.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjks3(),2)+":00")));
				    		as.setEndtime(("").equals(shifs.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(shifs.getXbqjjs3(),2)+":00")));
				    		atts.add(as);
		    			}
		    		}
		    		shde.setAttsch(atts);
		    	}
			    	
	    		if(shifs.getIsXbdk() == 1){
	    			shde.setNoclockout(true);// 下班不用打卡
	    		}else{
	    			shde.setNoclockout(false);// 下班不用打卡
	    		}
	    		shde.setAllowlate(shifs.getYxcdfzs());// 允许迟到分钟数
	    		shde.setSeriouslate(shifs.getYzcdfzs());// 严重迟到分钟数
	    		shde.setAbsenteeismlate(shifs.getKgcdfzs());// 旷工迟到分钟数
	    		if(shifs.getIsWzwd() == 1){
	    			shde.setIslatelate(true);// 晚走晚到
	    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
	    			int p = 0;
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1())){p = 2;}
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1()) && !("").equals(shifs.getXbwz2()) && !("").equals(shifs.getSbwd2())){p = 4;}
	    			if(!("").equals(shifs.getXbwz1()) && !("").equals(shifs.getSbwd1()) && !("").equals(shifs.getXbwz2()) && !("").equals(shifs.getSbwd2()) && !("").equals(shifs.getXbwz3()) && !("").equals(shifs.getSbwd3())){p = 6;}
	    			AttLateLate ala = new AttLateLate();
	    			ala.setLatewalk(shifs.getXbwz1());
	    			ala.setArrivelate(shifs.getSbwd1());
	    			atwzwd.add(ala);
	    			if(p == 4 || p == 6){
	    				AttLateLate alat = new AttLateLate();
	    				alat.setLatewalk(shifs.getXbwz2());
	    				alat.setArrivelate(shifs.getSbwd2());
	    				atwzwd.add(alat);
	    			}
	    			if(p == 6){
	    				AttLateLate alas = new AttLateLate();
	    				alas.setLatewalk(shifs.getXbwz3());
	    				alas.setArrivelate(shifs.getSbwd3());
	    				atwzwd.add(alas);
	    			}
	    			shde.setAttlat(atwzwd);
	    		}else{
	    			shde.setIslatelate(false);// 晚走晚到
	    		}
		 }
		//打卡记录
	    List<PunchRecord> dajllist = punchrecordservice.getDetailedRecordClock(startDate,endDate,userid);
	    shde.setAttpr(dajllist);
		 
		return ResultUtil.data(shde);
	 }
	
	 /**
	 * @param clock
	 * @return 日历提醒
	 */
	 @PostMapping(value = "/Attendancecalendar")
	 @ApiOperation(value = "日历提醒", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 51)
	 public Result<CalendarAlarm> AttendanceCalendar(@CurrentUser UserBean userBean,@RequestBody ReminderAuxiliary remind) {
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
		
		CalendarAlarm cal = new CalendarAlarm();
		cal.setUserid(userid);// 用户id
		try {
			cal.setRemindtime(DateUtil.getStringTime(remind.getRemindtime(),"yyyy-MM-dd"));// 提醒时间
		} catch (ParseException e) {
			e.printStackTrace();
		}
		cal.setContent(remind.getContent());// 内容
		
		if(remind.getType().equals(1)){//新增
			cal.setState(0);// 状态(0:未完成,1:已完成,2:已过期)
			cal.setAddtime(new Date().getTime());// 添加时间
			if(calendaralarmservice.insertSelective(cal)>0){
				return ResultUtil.data(cal,"新增成功");
			}else{
				return ResultUtil.error("新增失败");
			}
		}else if(remind.getType().equals(2)){
			cal.setId(remind.getId());//
			if (calendaralarmservice.updateByPrimaryKeySelective(cal) > 0) {
				return ResultUtil.data(cal,"修改成功");
			}else {
				return ResultUtil.error("修改失败");	
			}
		}else{
			cal.setState(1);// 状态(0:未完成,1:已完成,2:已过期)
			cal.setId(remind.getId());//
			if (calendaralarmservice.updateByPrimaryKeySelective(cal) > 0) {
				return ResultUtil.data(cal,"标记成功");
			}else {
				return ResultUtil.error("标记失败");	
			}
		}
	 }
	 
	 
	/**
	 * 	删除日历提醒信息
	 */
	@DeleteMapping(value = "/CalendarAlarm/{id}")
	@ApiOperation(value = "删除日历提醒信息", httpMethod = "DELETE", notes = "接口发布说明")
	@ApiOperationSupport(order = 52)
	public Result<Integer> deleteCalendarAlarm(@PathVariable("id") Integer id) {
		
		if (calendaralarmservice.deleteByPrimaryKey(id) > 0) {
			return ResultUtil.data(id,"删除成功");
		}
		return ResultUtil.error("删除失败");
	}
	 
	 /**
	  * 	考勤打卡------APP打卡
	  */
	 @PostMapping(value = "/AttendanceCard")
	 @ApiOperation(value = "考勤打卡------APP打卡", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 53)
	 public Result<Void> AttendanceCard(@CurrentUser UserBean userBean,@RequestBody ClockCollectData clock) {
		 int qyid = userBean.getOrgCode();//坏小孩【企业id】
		 int userid = userBean.getEmpNum();//用户id	
		 
		 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid); //考勤组信息
		 //pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
		 
	     String putime = new SimpleDateFormat("yyyy-MM-dd").format(Double.valueOf(clock.getPunchtime()));//转换打卡时间格式
		 Long startDate = 0l;//打卡当天开始时间
	     Long endDate = 0l;//打卡当天结束时间
		 try {
			startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
			endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
		 } catch (ParseException e) {
				e.printStackTrace();
		 }
		 
		 ShiftManagement shif = null;
		 if(clock.getShifid() > 0){//有无班次
			 shif = shiftmanagementservice.selectByPrimaryKey(clock.getShifid());
		 }
		 
		 int dkmx = 0;
		 PunchCardDetails dkmc = punchcarddetailsservice.SingleAttendanceDays(userid,startDate,endDate);//查询打卡当天是否有记录
		 
		 if(dkmc != null){//有记录就修改之前的
			//修改
			 dkmx = dkmc.getId();
			 PunchCardDetails pcd = new PunchCardDetails();
			 if(clock.getType() == 1){
				 if(clock.getDiffer() == 1){//打卡
					 if(!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null){
						 return ResultUtil.error("重复打卡");
					 }
				 }else{//更新打卡
					 pcd.setId(dkmc.getId());
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
					 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
				 }
				 
			 }else if(clock.getType() == 2){
				 if(("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() == null){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else{

					if(clock.getDiffer() == 1){//打卡
						return ResultUtil.error("重复打卡");
					}else{//更新打卡
						pcd.setId(dkmc.getId());
						pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
						if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							if(time > 0){
								 pcd.setXbdk1jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
							 }
						}
						//班次为2次时,计算工作时长
						if(dkmc.getSbdk1() != null){
							Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
							pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
						}
						punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					}
				 }
				 //班次为2次时,计算工作时长
				 if(dkmc.getSbdk1() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk1())/1000/60;
					 pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
				 }
			 }else if(clock.getType() == 3){
				 if(("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() == null){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
						 }else{
							pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));//上班2打卡结果
							 }else{
								pcd.setSbdk2jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 4){
				 if(("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() == null){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
						 }
						 
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班2打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk2jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));//下班2打卡结果
							 }
						 }
						 //班次为4次时,计算工作时长
						 if(dkmc.getSbdk2() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为4次时,计算工作时长
				 if(dkmc.getSbdk2() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk2())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }else if(clock.getType() == 5){
				 if(("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() == null){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));//上班3打卡结果
							 }else{
								 pcd.setSbdk3jg(0);// 打卡结果
							 }
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
			 }else if(clock.getType() == 6){
				 if(("").equals(dkmc.getXbdk3()) || dkmc.getXbdk3() == null){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
						 }
					 }
				 }else{
					 if(clock.getDiffer() == 1){//打卡
						 return ResultUtil.error("重复打卡");
					 }else{
						 pcd.setId(dkmc.getId());
						 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班3打卡时间
						 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时[有班次时]
							 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
							 if(time > 0){
								 pcd.setXbdk3jg(0);// 打卡结果
							 }else{
								 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));//下班3打卡结果
							 }
						 }
						 //班次为6次时,计算工作时长
						 if(dkmc.getSbdk3() != null){
							 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
							 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
							 BigDecimal on = new BigDecimal(time);
							 double worktime = Math.abs(om.add(on).doubleValue());
							 pcd.setGzsc(worktime);
						 }
						 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
					 }
				 }
				 //班次为6次时,计算工作时长
				 if(dkmc.getSbdk3() != null){
					 Long time = (Long.valueOf(clock.getPunchtime()) - dkmc.getSbdk3())/1000/60;
					 BigDecimal om = new BigDecimal(dkmc.getGzsc());//第二次
					 BigDecimal on = new BigDecimal(time);
					 double worktime = Math.abs(om.add(on).doubleValue());
					 pcd.setGzsc(worktime);
				 }
			 }
			 pcd.setId(dkmc.getId());
			 if(clock.getType() <= 6){
				 int update = punchcarddetailsservice.updateByPrimaryKeySelective(pcd);
			 }
			 
		 }else{//没有数据就新增一条数据
			 //新增
			 if(clock.getDiffer() == 1){//打卡
				 PunchCardDetails pcd = new PunchCardDetails();
				 pcd.setUserid(userid);
				 pcd.setData(putime);//打卡日期(yyyy-MM-dd)
				 if(clock.getType() == 1){
					 pcd.setSbdk1(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }else{
							 pcd.setSbdk1jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 2){
					 pcd.setXbdk1(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk1jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
						 }
					 }
				 }else if(clock.getType() == 3){
					 pcd.setSbdk2(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk2jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 4){
					 pcd.setXbdk2(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk2jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }else if(clock.getType() == 5){
					 pcd.setSbdk3(Long.valueOf(clock.getPunchtime()));//上班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }else{
							 pcd.setSbdk3jg(0);// 打卡结果
						 }
					 }
				 }else if(clock.getType() == 6){
					 pcd.setXbdk3(Long.valueOf(clock.getPunchtime()));//下班1打卡时间
					 if(!("0").equals(clock.getPunchcardtime())){//有应打卡时间时
						 Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
						 if(time > 0){
							 pcd.setXbdk3jg(0);// 打卡结果
						 }else{
							 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
						 }
					 }
				 }
				 if(shif != null){
					 pcd.setYdkcs(shif.getSxbcs()*2);//应打卡次数
				 }
				 pcd.setQyid(qyid);//企业id
				 pcd.setDksj(startDate);//打卡时间
				 
				 punchcarddetailsservice.insertSelective(pcd);
				 
				 dkmx = pcd.getId();
			 }
		 }
		 
		 
		 
		 //打卡记录
		 if(clock.getDiffer() == 2){//更新打卡 
			PunchRecord punch = punchrecordservice.selectPunchResults(startDate,endDate,userid,clock.getType());
			if(punch != null){
				PunchRecord pr = new PunchRecord();
				pr.setId(punch.getId());
				pr.setStatus(0);//状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:补卡 4:请假)
				pr.setSort(0);//序号(0:打卡无效:此记录已被更新)
				punchrecordservice.updateByPrimaryKeySelective(pr);
			}else{
				return ResultUtil.error("打卡失败");
			}
		 }
		
		PunchRecord pre = new PunchRecord();
		pre.setDktime(Long.valueOf(clock.getPunchtime()));// 打卡时间
		if(clock.getPunchcardtype() == 1){
			pre.setLon(Double.valueOf(clock.getLon()));// 经度
			pre.setLat(Double.valueOf(clock.getLat()));// 纬度
			pre.setAddress(clock.getAddress());// 定位地址
		}
		
		Long time = (Long.valueOf(clock.getPunchtime()) - Long.valueOf(clock.getPunchcardtime()))/1000/60;
		if(("0").equals(clock.getPunchcardtime())){
			pre.setResults(0);// 打卡结果
		}else{
			if((clock.getType())%2 > 0){//上班
				if(time > 0){
					pre.setResults(Integer.valueOf(time.toString()));// 打卡结果
				}else{
					pre.setResults(0);// 打卡结果
				}
			}else{//下班
				if(time > 0){
					pre.setResults(0);// 打卡结果
				}else{
					pre.setResults(Math.abs(Integer.valueOf(time.toString())));// 打卡结果
				}
			}
		}
		
		pre.setUserId(userid);// 用户id
		if((clock.getType())%2 > 0){
			pre.setType(1);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time > 0){
					pre.setStatus(3);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}else{
			pre.setType(2);// 类型(类型 0:无排班打卡 1:上班 2:下班)
			if(("0").equals(clock.getPunchcardtime())){//无班次打卡
				pre.setStatus(1);
			}else{
				//打卡
				if(time < 0){
					pre.setStatus(4);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}else if(pre.getResults() == 0){
					pre.setStatus(1);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
				}
			}
		}
		pre.setSort(clock.getType());// 序号
		pre.setCardType(clock.getPunchcardtype());// 打卡类型(1:GPS,2:WIFI,3:考勤机)
		if(clock.getPunchcardtype() == 2){
			pre.setMac(clock.getMac());// mac地址
			pre.setMacname(clock.getMacname());// WIFI名称
		}
		pre.setQyid(qyid);// 企业id
		String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
		pre.setAttdate(attdate_+" "+dateToWeek2(putime));// 考勤日期
		
		long date = new Date().getTime();
		if(("0").equals(clock.getPunchcardtime())){
			pre.setAttime(date);// 考勤时间(应打卡时间)	
		}else{
			pre.setAttime(Long.valueOf(clock.getPunchcardtime()));// 考勤时间(应打卡时间)
		}
		
		pre.setDkmxid(dkmx);// 打卡明细id
		pre.setBcid(clock.getShifid());// 班次id
		punchrecordservice.insertSelective(pre);//新增打卡记录
			
		 
		 
//		if(shiftmanagementservice.insertSelective(shif)>0){
			return ResultUtil.data(null,"打卡成功");
//		}else{
//			return ResultUtil.error("新增班次失败");
//		}
	 }
	
	 /************************************************************************************************************************************/
	 /***************************************************工具方法区***************************************************************************/
	 /************************************************************************************************************************************/
	 /**
	 * 时间转换时间戳
	 */
	public static String dateToStamp(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
		try {
			date = simpleDateFormat.parse(s);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }
	
	/**
	 * 2019-10-24T00:30:23.000Z 转化时间
	 */
	public String dealDateFormat(String oldDateStr,int num) {
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); // yyyy-MM-dd'T'HH:mm:ss.SSSZ
			Date date = null;
			try {
				date = df.parse(oldDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			SimpleDateFormat df1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
			Date date1 = null;
			try {
				date1 = df1.parse(date.toString());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			DateFormat df2 = null;
			if(num == 1){
				df2 = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss");
			}else if(num == 2){
				df2 = new SimpleDateFormat("HH:mm");
			}
			
			return df2.format(date1);
	}
	/**
     * 根据日期获取 星期 (2019-05-06 ——> 星期一)
     * @param datetime
     * @return
     */
    public static String dateToWeek(String datetime) {

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

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

	/**
	 * 获取月份最后日期
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public String getMaxMonthDate(String date) throws ParseException {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(famt.parse(date));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return famt.format(calendar.getTime());
	}
	
	/**
	 * 对比两个字符串数组
	 * @param t1
	 * @param t2
	 * @return
	 */
	public static <T> List<T> compare(T[] t1, T[] t2) {    
	      List<T> list1 = Arrays.asList(t1); //将t1数组转成list数组   
	      List<T> list2 = new ArrayList<T>();//用来存放2个数组中不相同的元素    
	      for (T t : t2) {    
	          if (!list1.contains(t)) {    
	              list2.add(t);    
	          }    
	      }    
	      return list2;    
	  }
	
	public static String[] array_unique(String[] ss) {
		Set<String> set=new HashSet<String>(Arrays.asList(ss));
		return set.toArray(new String[set.size()]);
		//或者return new HashSet<String>(Arrays.asList(ss)).toArray(new String[0]);
	}
	
	
	/**
	 * 	考勤机一键同步
	 */
	@GetMapping(value="/synchroni/{id}")
	@ApiOperation(value = "考勤机一键同步", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 54)
	public Result<AttemacDto> synchroni(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
		Integer orgCode = userBean.getOrgCode();
		
		List<UserAttendanceRel> member = userattendancerelservice.selectAttNotMember(id,orgCode);
		
		AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(id);//查询考勤机“序列号”
		
		for(UserAttendanceRel usmer:member) {
			
			YgglMainEmp user = new LambdaQueryChainWrapper<YgglMainEmp>(ygglmainempmapper).eq(YgglMainEmp::getEmpNum, usmer.getUserid())
					.eq(YgglMainEmp::getOrgCode, orgCode).one();
			
			JSONObject vResultJson = new JSONObject();
			vResultJson.put("user_id", usmer.getUserid());
			vResultJson.put("user_name", user.getName());
			vResultJson.put("user_privilege", "USER");
			String sFinal = vResultJson.toString();
			
			String url = StaticVariable.mac_command;
	        HttpHeaders headers = new HttpHeaders();
	        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
	        params.add("cmd", "SET_USER_INFO");
	        params.add("devid", kqj.getCode());
	        params.add("json", sFinal);
	        RestTemplate restTemplate = new RestTemplate();
	        HttpEntity httpEntity = new HttpEntity(params, headers);
	        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
	        
	        
	        
	      //用户与设备关系(考勤机id-->用户id)
			UserEquiRelation uskqj = new UserEquiRelation();
			uskqj.setUserId(usmer.getUserid());//用户id
			uskqj.setKqjid(kqj.getId());//设备id
			uskqj.setType(1);//类型(类型 1:考勤机)
			uskqj.setIsGly(0);
			
			userequirelationmapper.insert(uskqj);
	        
		}
		
		return ResultUtil.success("成功");
	}
	
	@GetMapping(value="/synchrotime/{code}")
	@ApiOperation(value = "考勤机一键同步", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 54)
	public Result<AttemacDto> SynchronizationTime(@CurrentUser UserBean userBean,@PathVariable("code") String code) {
		
		String sNowTxt = DateUtil.getStringFormat(System.currentTimeMillis(),"yyyyMMddHHmmss");
		
		JSONObject vResultJson = new JSONObject();
		vResultJson.put("time", sNowTxt);
		String sFinal = vResultJson.toString();
		
		String url = StaticVariable.mac_command;
        HttpHeaders headers = new HttpHeaders();
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("cmd", "SET_TIME");
        params.add("devid", code);
        params.add("json", sFinal);
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity httpEntity = new HttpEntity(params, headers);
        try {
			ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
		} catch (RestClientException e) {
//			e.printStackTrace();
			System.err.println("提示:考勤机服务出错");
			return ResultUtil.success("失败");
		}
		
		return ResultUtil.success("成功");
	}
	
	
	/**
	 * 	移除考勤机管理员
	 */
	@PostMapping(value = "/removeadministrator/{kqjid}/{id}")
	@ApiOperation(value = "移除考勤机管理员", httpMethod = "POST", notes = "接口发布说明")
    @ApiOperationSupport(order = 55)
	public Result<Void> RemoveAdministrator(@PathVariable int kqjid,@PathVariable int id, @RequestBody Map<String,String> mmd) {
		
		String[] xgyh = mmd.get("a").split(",");
		 if(xgyh.length > 0){
			 for(int a=0;a<xgyh.length;a++){
					
					AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(kqjid);//查询考勤机“序列号”
					
					JSONObject vResultJson = new JSONObject();
					vResultJson.put("user_id", xgyh[a]);
					vResultJson.put("user_privilege", "USER");
					String sFinal = vResultJson.toString();
					
					String url = StaticVariable.mac_command;
			        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);
			        
			        UserEquiRelation kqjry = new UserEquiRelation();
			        kqjry.setId(id);
			        kqjry.setIsGly(0);
			        userequirelationmapper.updateByPrimaryKeySelective(kqjry);
				
			 }
		 }
		
		
		return ResultUtil.success("成功");
	}
	
	
	
	
	
	
	
	@GetMapping(value="/aircraftmembers/{id}")
	@ApiOperation(value = "考勤机成员", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 56)
	public ResponseResult selectAircraftMembers(@CurrentUser UserBean userBean,@PathVariable("id") Integer id) {
		Integer orgCode = userBean.getOrgCode();
		
		 List<MachinememberDto> kqjcys = userequirelationmapper.selectAircraftMembers(id,orgCode);
		
		
		return new ResponseResult().success("考勤机成员", kqjcys);
	}
	
	
//	asDevId //考勤机编号
//	asUserId //打卡用户id
//	asVerifyMode //打卡方式  1:指纹  20:人脸
//	asIOMode
//	sStdIoTime //打卡时间
	
	@PostMapping(value = "/punchclock")
	@ApiOperation(value = "考勤机打卡", httpMethod = "POST", notes = "接口发布说明")
	public ResponseResult punchclock(@RequestParam String json) {
		JSONObject jsonArray = new JSONObject(json);
		String asDevId = jsonArray.get("asDevId").toString();
		String asUserId = jsonArray.get("asUserId").toString();
		String asVerifyMode = jsonArray.get("asVerifyMode").toString();
		String asIOMode = "0";
		String sStdIoTime = jsonArray.get("sStdIoTime").toString();
		
/***********************************************************考勤机打卡(开始)********************************************************************************************/
		
		YgglMainEmp user = new LambdaQueryChainWrapper<YgglMainEmp>(ygglmainempmapper).eq(YgglMainEmp::getEmpNum, asUserId).one();
		if(user != null) {
			int qyid = user.getOrgCode();//坏小孩【企业id】
			int userid = user.getEmpNum();//用户id	
			 
			 AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(userid); //考勤组信息
			 //pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
			 if(attgro != null) {
				 List<AttGroupBinPunchMode> kqjs = attgroupbinpunchmodeservice.selectMachineByKqzId(attgro.getId());//该考勤组所绑定的考勤机
				 
				 if(kqjs.size() > 0) {
					 
				     long time_ = 0;
					try {
						time_ = DateUtil.getStringTime(sStdIoTime, "yyyy-MM-dd HH:mm:ss");
					} catch (ParseException e1) {
						e1.printStackTrace();
					}//打卡时间戳
					 String putime = new SimpleDateFormat("yyyy-MM-dd").format(time_);//转换打卡时间格式
					 Long startDate = 0l;//打卡当天开始时间
				     Long endDate = 0l;//打卡当天结束时间
					 try {
						startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
						endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(putime,"yyyy-MM-dd")).getTime();
					 } catch (ParseException e) {
							e.printStackTrace();
					 }
					 
					 int dkmx = 0;
					 PunchCardDetails dkmc = punchcarddetailsservice.SingleAttendanceDays(userid,startDate,endDate);//查询打卡当天是否有记录
					 
					 AttendanceCardList attdate = MethodCall(qyid,userid,putime);
					 
					 ClockCollectData clockt = new ClockCollectData();
					 long starttime1 = 0; long starttime1ks = 0; long starttime1js = 0;	 
					 long endtime1 = 0; long endtime1ks = 0; long endtime1js = 0;
					 long starttime2 = 0; long starttime2ks = 0; long starttime2js = 0;
					 long endtime2 = 0; long endtime2ks = 0; long endtime2js = 0;
					 long starttime3 = 0; long starttime3ks = 0; long starttime3js = 0;
					 long endtime3 = 0; long endtime3ks = 0; long endtime3js = 0;
					 if(attdate.getAttsch().size() > 0) {
						 List<AttSchedule> ash = attdate.getAttsch();
						 int y = 0;
						 clockt.setShifid(ash.get(y).getId());
						 
						 if(attdate.getAttsch().size() == 2 || attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
							 starttime1 = ash.get(0).getTime();
							 starttime1ks = ash.get(0).getStarttime();
							 starttime1js = ash.get(0).getEndtime();
							 
							 endtime1 = ash.get(1).getTime();
							 endtime1ks = ash.get(1).getStarttime();
							 endtime1js = ash.get(1).getEndtime();
						 }
					 	if(attdate.getAttsch().size() == 4 || attdate.getAttsch().size() == 6) {
					 		starttime2 = ash.get(2).getTime();
					 		starttime2ks = ash.get(2).getStarttime();
							starttime2js = ash.get(2).getEndtime();
							 
						    endtime2 = ash.get(3).getTime();
						    endtime2ks = ash.get(3).getStarttime();
						    endtime2js = ash.get(3).getEndtime();
						}
					 	if(attdate.getAttsch().size() == 6) {
					 		starttime3 = ash.get(4).getTime();
					 		starttime3ks = ash.get(4).getStarttime();
							starttime3js = ash.get(4).getEndtime();
							
							endtime3 = ash.get(5).getTime();
							endtime3ks = ash.get(5).getStarttime();
						    endtime3js = ash.get(5).getEndtime();
						 }
					 }
					 long punchcardtime = 0;//应打卡时间
					 long punchstart = 0;//应打卡开始时间
					 long punchend = 0;//应打卡结束时间
					 int atttype = 0;
					 if(dkmc == null) {//上班1   ****新增
						 punchcardtime = starttime1;
						 punchstart = starttime1ks;
				    	 punchend = starttime1js;
						 atttype = 1;
					 }else {
						 if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() == null)){	//下班1
							 punchcardtime = endtime1;
							 punchstart = endtime1ks;
					    	 punchend = endtime1js;
							 atttype = 2;
					     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
					    		 && (("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() == null)){	//上班2
					    	 punchcardtime = starttime2;
					    	 punchstart = starttime2ks;
					    	 punchend = starttime2js;
					    	 atttype = 3;
					     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
					    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() == null)){	//下班2
					    	 punchcardtime = endtime2;
					    	 punchstart = endtime2ks;
					    	 punchend = endtime2js;
					    	 atttype = 4;
					     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
					    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (!("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() != null)
					    		 && (("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() == null)){	//上班3
					    	 punchcardtime = starttime3;
					    	 punchstart = starttime3ks;
					    	 punchend = starttime3js;
					    	 atttype = 5;
					     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
					    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (!("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() != null)
					    		 && (!("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() != null) && (("").equals(dkmc.getXbdk3()) || dkmc.getXbdk3() == null)){	//下班3
					    	 punchcardtime = endtime3;
					    	 punchstart = endtime3ks;
					    	 punchend = endtime3js;
					    	 atttype = 6;
					     }else {
					    	 punchcardtime = 0;
					    	 punchstart = 0;
					    	 punchend = 0;
					    	 atttype = 7;
					     }
					 }
					 
					 
					 
					 ShiftManagement shif = null;
					 if(attdate.getAttsch().size() > 0 && clockt.getShifid() > 0){//有无班次
						 shif = shiftmanagementservice.selectByPrimaryKey(clockt.getShifid());
					 }
					 
					 //打卡记录录入*****************************************************************************************************************************
					 //打卡是否有时间范围限制
					 boolean isRange = true;
					 if(punchstart>0 && punchend>0) {
						 String staputime = new SimpleDateFormat("HH:mm").format(punchstart);//应打卡开始时间
						 String entputime = new SimpleDateFormat("HH:mm").format(punchend);//应打卡结束时间
						 
						 String DKputime = new SimpleDateFormat("HH:mm").format(time_);//打卡时间

						 System.out.println(staputime);
						 System.out.println(entputime);
						 System.out.println(DKputime);
						
						 boolean effectiveDate = false;
						
						 try {
						 	 effectiveDate = hourMinuteBetween(DKputime, staputime, entputime);
						 } catch (Exception e) {
							 e.printStackTrace();
						 }
						 if (effectiveDate) {
							 System.out.println("当前时间在范围内");
						 }else {
							 System.out.println("当前时间在不在范围内");
							 isRange = false;
						 }
					 }
					 
					 if(isRange) {
						 
						 if(dkmc == null) {//上班1   ****新增
							 PunchCardDetails pcd = new PunchCardDetails();
							 pcd.setUserid(userid);
							 pcd.setData(putime);//打卡日期(yyyy-MM-dd)
							 
							 pcd.setSbdk1(time_);//上班1打卡时间
							 if(punchcardtime != 0){//有应打卡时间时
								 
								 Long time = (time_ - punchcardtime)/1000/60;
								 if(time > 0){
									 pcd.setSbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
								 }else{
									 pcd.setSbdk1jg(0);// 打卡结果
								 }
							 }
							 
							 if(shif != null){
								 pcd.setYdkcs(shif.getSxbcs()*2);//应打卡次数
							 }
							 pcd.setQyid(qyid);//企业id
							 pcd.setDksj(startDate);//打卡时间
							 
							 punchcarddetailsservice.insertSelective(pcd);
							 
							 dkmx = pcd.getId();
							 
						 }else { //*****修改
							 
							 dkmx = dkmc.getId();
							 PunchCardDetails pcd = new PunchCardDetails();
							 if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() == null)){//下班1
								 pcd.setId(dkmc.getId());
								 pcd.setXbdk1(time_);//下班1打卡时间
								 if(punchcardtime != 0){//有应打卡时间时
									 Long time = (time_ - punchcardtime)/1000/60;
									 if(time > 0){
										 pcd.setXbdk1jg(0);// 打卡结果
									 }else{
										 pcd.setXbdk1jg(Math.abs(Integer.valueOf(time.toString())));//上班1打卡结果
									 }
								 }
								 
								 if(dkmc.getSbdk1() != null){
									Long time = (time_ - dkmc.getSbdk1())/1000/60;
									pcd.setGzsc(Math.abs(Double.valueOf(time.toString())));//只打一次卡时计算工作时长
								 }
								 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
								 
						     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
						    		 && (("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() == null)){//上班2
						    	 pcd.setId(dkmc.getId());
						    	 pcd.setSbdk2(time_);//上班1打卡时间
								 if(punchcardtime != 0){//有应打卡时间时
									 Long time = (time_ - punchcardtime)/1000/60;
									 if(time > 0){
										 pcd.setSbdk2jg(Math.abs(Integer.valueOf(time.toString())));
									 }else{
										 pcd.setSbdk2jg(0);// 打卡结果
									 }
								 }
								 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
						     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
						    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() == null)){//下班2
						    	 pcd.setId(dkmc.getId());
						    	 pcd.setXbdk2(time_);//下班1打卡时间
								 if(punchcardtime != 0){//有应打卡时间时
									 Long time = (time_ - punchcardtime)/1000/60;
									 if(time > 0){
										 pcd.setXbdk2jg(0);// 打卡结果
									 }else{
										 pcd.setXbdk2jg(Math.abs(Integer.valueOf(time.toString())));
									 }
								 }
								 
								//班次为4次时,计算工作时长
								 if(dkmc.getSbdk2() != null){
									 Long time = (time_ - 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);//修改打卡记录
						     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
						    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (!("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() != null)
						    		 && (("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() == null)){//上班3
						    	 pcd.setId(dkmc.getId());
						    	 pcd.setSbdk3(time_);//上班1打卡时间
								 if(punchcardtime != 0){//有应打卡时间时
									 Long time = (time_ - punchcardtime)/1000/60;
									 if(time > 0){
										 pcd.setSbdk3jg(Math.abs(Integer.valueOf(time.toString())));
									 }else{
										 pcd.setSbdk3jg(0);// 打卡结果
									 }
								 }
								 punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
						     }else if((!("").equals(dkmc.getSbdk1()) || dkmc.getSbdk1() != null) && (!("").equals(dkmc.getXbdk1()) || dkmc.getXbdk1() != null)
						    		 && (!("").equals(dkmc.getSbdk2()) || dkmc.getSbdk2() != null) && (!("").equals(dkmc.getXbdk2()) || dkmc.getXbdk2() != null)
						    		 && (!("").equals(dkmc.getSbdk3()) || dkmc.getSbdk3() != null) && (("").equals(dkmc.getXbdk3()) || dkmc.getXbdk3() == null)){//下班3
						    	 pcd.setId(dkmc.getId());
						    	 pcd.setXbdk3(time_);//下班1打卡时间
								 if(punchcardtime != 0){//有应打卡时间时
									 Long time = (time_ - punchcardtime)/1000/60;
									 if(time > 0){
										 pcd.setXbdk3jg(0);// 打卡结果
									 }else{
										 pcd.setXbdk3jg(Math.abs(Integer.valueOf(time.toString())));
									 }
								 }
								 
								//班次为6次时,计算工作时长
								 if(dkmc.getSbdk3() != null){
									 Long time = (time_ - 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(atttype <= 6){
								 int update = punchcarddetailsservice.updateByPrimaryKeySelective(pcd);//修改打卡记录
							 }
						 }
					 }
					 
				
					//原始打卡记录数据录入**************************************************************************************************************************************
					PunchRecord pre = new PunchRecord();
					pre.setDktime(time_);// 打卡时间
					
					Long time = (time_ - punchcardtime)/1000/60;
					if(punchcardtime == 0){
						pre.setResults(0);// 打卡结果
					}else{
						if(isRange) {
							if((atttype)%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())));// 打卡结果
								}
							}
						}else {
							pre.setResults(0);// 打卡结果
						}
						
					}
					
					pre.setUserId(userid);// 用户id
					if((atttype)%2 > 0){
						pre.setType(1);// 类型(类型 0:无排班打卡 1:上班 2:下班)
						
						if(punchcardtime == 0){//无班次打卡
							pre.setStatus(1);
						}else{
							if(isRange) {
								//打卡
								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.setStatus(2);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
							}
							
						}
					}else{
						pre.setType(2);// 类型(类型 0:无排班打卡 1:上班 2:下班)
						if(punchcardtime == 0){//无班次打卡
							pre.setStatus(1);
						}else{
							if(isRange) {
								//打卡
								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:调休)
								}
							}else {
								pre.setStatus(2);// 状态(0:打卡无效:此记录已被更新 1:正常 2:异常 3:迟到 4:早退 5:补卡 6:请假 7:加班 8:调休)
							}
						}
					}
					pre.setSort(atttype);// 序号
					pre.setCardType(3);// 打卡类型(1:GPS,2:WIFI,3:考勤机)
					
					
					pre.setQyid(qyid);// 企业id
					String attdate_ = new SimpleDateFormat("yy-MM-dd").format(Double.valueOf(startDate));//转换打卡时间格式
					pre.setAttdate(attdate_+" "+dateToWeek2(putime));// 考勤日期
					
					long date = new Date().getTime();
					if(punchcardtime == 0 && !isRange){
						pre.setAttime(date);// 考勤时间(应打卡时间)	
					}else{
						pre.setAttime(punchcardtime);// 考勤时间(应打卡时间)
					}
					
					pre.setDkmxid(dkmx);// 打卡明细id
					pre.setBcid(clockt.getShifid());// 班次id
					
					if(("1").equals(asVerifyMode)) {
						pre.setRemarks("考勤机指纹打卡");
					}else if(("20").equals(asVerifyMode)) {
						pre.setRemarks("考勤机人脸打卡");
					}
					pre.setPunchmode(Integer.valueOf(asVerifyMode));
					pre.setPunchequipment(asDevId);//
					punchrecordservice.insertSelective(pre);//新增打卡记录
				}
			 }
		}
		
/***********************************************************考勤机打卡(结束)********************************************************************************************/
		
		
		return new ResponseResult().success("考勤机打卡成功", null);
	}
	
	/**
	 * 
	 * @param nowDate   要比较的时间
	 * @param startDate   开始时间
	 * @param endDate   结束时间
	 * @return   true在时间段内,false不在时间段内
	 * @throws Exception
	 */
	public static boolean hourMinuteBetween(String nowDate, String startDate, String endDate) throws Exception{
		
		SimpleDateFormat format = new SimpleDateFormat("HH:mm");
		
		Date now = format.parse(nowDate);
		Date start = format.parse(startDate);
		Date end = format.parse(endDate);
		
		long nowTime = now.getTime();
		long startTime = start.getTime();
		long endTime = end.getTime();
		
		return nowTime >= startTime && nowTime <= endTime;

	}
	
	@PostMapping(value = "/removeuser/{kqjid}")
	@ApiOperation(value = "批量移除用户", httpMethod = "POST", notes = "接口发布说明")
    @ApiOperationSupport(order = 56)
	public Result<Void> RemoveUser(@PathVariable int kqjid, @RequestBody Map<String,String> mmd) {
		
		String[] xgyh = mmd.get("a").split(",");
		 if(xgyh.length > 0){
			 for(int a=0;a<xgyh.length;a++){
				UserEquiRelation scyhkqj = userequirelationmapper.selectByuserIdkqjid(Integer.valueOf(xgyh[a]), kqjid);
				
				AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(scyhkqj.getKqjid());//查询考勤机“序列号”
				 
				JSONObject vResultJson = new JSONObject();
				vResultJson.put("user_id", scyhkqj.getUserId());
				String sFinal = vResultJson.toString();
				
				String url = StaticVariable.mac_command;
		        HttpHeaders headers = new HttpHeaders();
		        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
		        params.add("cmd", "DELETE_USER");
		        params.add("devid", kqj.getCode());
		        params.add("json", sFinal);
		        RestTemplate restTemplate = new RestTemplate();
		        HttpEntity httpEntity = new HttpEntity(params, headers);
		        try {
					ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
				} catch (RestClientException e) {
//					e.printStackTrace();
					System.err.println("提示:考勤机服务出错");
					return ResultUtil.success("失败");
				}
				
		        userequirelationmapper.deleteByPrimaryKey(scyhkqj.getId());
		        
		        //该用户是否为管理员  否则一同删除
//		        KqglAssoKqjgly gly = new LambdaQueryChainWrapper<KqglAssoKqjgly>(kqglassokqjglymapper).eq(KqglAssoKqjgly::getKqjid, kqjid)
//						.eq(KqglAssoKqjgly::getUserid, xgyh[a]).one();
//		        
//		        if(gly != null){
//		        	KqglAssoKqjgly.builder().build().deleteById(gly.getId());
//		        }
		        
			 }
		 }
		
		
		return ResultUtil.success("成功");
	}
	
	
	 @PostMapping(value = "/modifyauthority/{kqjid}/{id}")
	 @ApiOperation(value = "添加考勤机管理员", httpMethod = "POST", notes = "接口发布说明")
	 @ApiOperationSupport(order = 55)
	 public Result<Void> ModifyAuthority(@CurrentUser UserBean userBean,@PathVariable int kqjid,@PathVariable int id, @RequestBody Map<String,String> mmd) {
		 
		 Integer empNum = userBean.getEmpNum();
		 Integer orgCode = userBean.getOrgCode();
		 
		 String[] xgyh = mmd.get("a").split(",");
		 if(xgyh.length > 0){
			 AttendanceMachine kqj = attendancemachineservice.selectByPrimaryKey(kqjid);
			for(int a=0;a<xgyh.length;a++){
				
				YgglMainEmp use = new LambdaQueryChainWrapper<YgglMainEmp>(ygglmainempmapper).eq(YgglMainEmp::getEmpNum, xgyh[a]).one();
				
				JSONObject vResultJson = new JSONObject();
				vResultJson.put("user_id", xgyh[a]);
//				vResultJson.put("user_name", "管-"+use.getName()+"-"+a);
				vResultJson.put("user_privilege", "MANAGER");
				String sFinal = vResultJson.toString();
				
				String url = StaticVariable.mac_command;
		        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);
		        try {
					ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);
				} catch (RestClientException e) {
//					e.printStackTrace();
					System.err.println("提示:考勤机服务出错");
					return ResultUtil.success("失败");
				}
		        
		        
		        UserEquiRelation kqjry = new UserEquiRelation();
		        kqjry.setId(id);
		        kqjry.setIsGly(1);
		        userequirelationmapper.updateByPrimaryKeySelective(kqjry);
		        
		        
		        //考勤机管理员
//		        KqglAssoKqjgly gly = KqglAssoKqjgly.builder().build();
//		        gly.setKqjid(kqjid);//考勤机id
//		        gly.setGlybh(Integer.valueOf(xgyh[a]));//管理员编号
//		        gly.setGluxm("管-"+use.getName());//管理员姓名
//		        gly.setUserid(use.getEmpNum());//原用户id
//		        gly.setTjry(empNum);//添加人员
//		        gly.setQyid(orgCode);//企业id
//		        gly.insertOrUpdate();
				
			}
		}
		return ResultUtil.success("成功");
		 
	}
	
	
	
	public AttendanceCardList MethodCall(int qyid,int userid,String date) {
		 
		 AttendanceCardList attcar = new AttendanceCardList();
		 
		 String str = null;
		 if(!("").equals(date)){
			 str = date;
		 }else{
			 Date d = new Date();
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 str = sdf.format(d);
		 }
		 
		 Long startDate = 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); //考勤组信息
			     
			     //pbfs:排班方式 1:固定排班;2:自由排班;3:自由工时
				 if(attgro != null){//判断当前用户是否加入到考勤组
					 //排班制
				     Schedule jrpb = scheduleservice.getScheduleSpecificAttendance(attgro.getId(),userid,str);
				     //固定排班
				     int week = Integer.valueOf(dateToWeek(str));//4
				     AttendanceWeeklySch atwek = attendanceweeklyschservice.selectZhouDetail(attgro.getId(),week);//固定周排班
					 
				    if(attgro.getPbfs() == 1){//固定排班
				    	if(atwek != null){//有固定周排班
				    		SpecialDate rest = specialdateservice.SpecialDateSpecialDayOff(attgro.getId(), str);//查询打卡当天是否在特殊休息日期里面存在
				    		if(rest != null){//今天休息  Sort返回0【特殊日期--休息】
				    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts.add(as);
					    		attcar.setAttsch(atts);
				    		}else{//今天上班
					    		ShiftManagement bcz = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
					    		if(bcz != null){
					    			Getshiftinformationbatch(bcz,attcar,str);
					    		}
				    		}
				    	}else{
				    		//必须打卡
				    		SpecialDate tsri = specialdateservice.SpecialDateTroubleshooting(attgro.getId(), str);//判断特殊日期
				    		if(tsri != null){
				    			ShiftManagement tsrq = shiftmanagementservice.selectByPrimaryKey(tsri.getBcid());
				    			if(tsrq!=null){
				    				Getshiftinformationbatch(tsrq,attcar,str);
				    			}
				    		}else{
				    			//休息
				    			List<AttSchedule> atts = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts.add(as);
					    		attcar.setAttsch(atts);
				    		}
				    	}
				    	
					}else if(attgro.getPbfs() == 2){//自由排班
						
						//未排班时,员工可选择班次打卡
					    if(attgro.getIsXzbcdk() == 1){
					    	attcar.setOptscheduling(true);	
					    }else{
					    	attcar.setOptscheduling(false);
					    }
						
		//				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(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks1())? 0 :Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs1(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(2);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk1(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks1(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs1()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs1(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 2 || jrpb.getSxbcs() == 3){//2次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(3);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs2(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(4);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk2(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks2(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs2()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs2(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
								if(jrpb.getSxbcs() == 3){//3次上下班
									for(int o=0;o<2;o++){
										if(o==0){
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(5);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getSbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getSbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getSbqjjs3(),2)+":00")));
											atts.add(as);
										}else{
											AttSchedule as = new AttSchedule();
											as.setId(jrpb.getBcid());
											as.setSort(6);
											as.setTime(Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbdk3(),2)+":00")));
											as.setStarttime(("").equals(jrpb.getXbqjks3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjks3(),2)+":00")));
											as.setEndtime(("").equals(jrpb.getXbqjjs3()) ? 0 : Long.valueOf(dateToStamp(str+" "+dealDateFormat(jrpb.getXbqjjs3(),2)+":00")));
											atts.add(as);
										}
									}
									attcar.setAttsch(atts);
								}
							}else{//当天排班为休息
								List<AttSchedule> atts1 = new ArrayList<AttSchedule>();
				    			AttSchedule as = new AttSchedule();
				    			as.setId(0);
					    		as.setSort(0);//0:表示今天为休息日
					    		as.setTime(0l);
					    		as.setStarttime(0l);
					    		as.setEndtime(0l);
					    		atts1.add(as);
					    		attcar.setAttsch(atts1);
							}
						}
				    	
					}else{//自由工时
						//int week = Integer.valueOf(dateToWeek(str));//4
						
						AttendanceWeeklySch wekz = attendanceweeklyschservice.WeeklyFreeRoster(attgro.getId(),week);
						if(wekz != null){//
							String dada = str+" "+attgro.getKqkssjTime()+":00";
							attcar.setStapclotime(Long.valueOf(dateToStamp(dada)));
						}
						
						if(!("").equals(attgro.getJbzdsc())){
							attcar.setCanpunchworkdate(Double.valueOf(attgro.getJbzdsc()));//上班打卡后多久大下班卡
						}
						
						
					}
				    if(jrpb != null || atwek != null){
				    	ShiftManagement shif = null;
				    	if(attgro.getPbfs() == 1){
				    		shif = shiftmanagementservice.selectByPrimaryKey(atwek.getBcid());
				    	}else if(attgro.getPbfs() == 2){
				    		shif = shiftmanagementservice.selectByPrimaryKey(jrpb.getBcid());
				    	}
				    	
				    	if(shif != null){
				    		if(shif.getIsXbdk() == 1){
				    			attcar.setNoclockout(true);// 下班不用打卡
				    		}else{
				    			attcar.setNoclockout(false);// 下班不用打卡
				    		}
				    		attcar.setAllowlate(shif.getYxcdfzs());// 允许迟到分钟数
				    		attcar.setSeriouslate(shif.getYzcdfzs());// 严重迟到分钟数
				    		attcar.setAbsenteeismlate(shif.getKgcdfzs());// 旷工迟到分钟数
				    		if(shif.getIsWzwd() == 1){
				    			attcar.setIslatelate(true);// 晚走晚到
				    			List<AttLateLate> atwzwd = new ArrayList<AttLateLate>();
				    			int p = 0;
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1())){p = 2;}
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2())){p = 4;}
				    			if(!("").equals(shif.getXbwz1()) && !("").equals(shif.getSbwd1()) && !("").equals(shif.getXbwz2()) && !("").equals(shif.getSbwd2()) && !("").equals(shif.getXbwz3()) && !("").equals(shif.getSbwd3())){p = 6;}
				    			AttLateLate ala = new AttLateLate();
				    			ala.setLatewalk(shif.getXbwz1());
				    			ala.setArrivelate(shif.getSbwd1());
				    			atwzwd.add(ala);
				    			if(p == 4 || p == 6){
				    				AttLateLate alat = new AttLateLate();
				    				alat.setLatewalk(shif.getXbwz2());
				    				alat.setArrivelate(shif.getSbwd2());
				    				atwzwd.add(alat);
				    			}
				    			if(p == 6){
				    				AttLateLate alas = new AttLateLate();
				    				alas.setLatewalk(shif.getXbwz3());
				    				alas.setArrivelate(shif.getSbwd3());
				    				atwzwd.add(alas);
				    			}
				    			attcar.setAttlat(atwzwd);
				    		}else{
				    			attcar.setIslatelate(false);// 晚走晚到
				    		}
				    	}
				    }
				    
				    attcar.setAttgrouptype(attgro.getPbfs());//1:固定排班;2:自由排班;3:自由工时
				    
				 }else{
					 attcar.setAttgrouptype(0);//1:固定排班;2:自由排班;3:自由工时
				 }
				 
		  return attcar;
				 
	 }
	
	
	/**********************/
	/**********************/
	/**
	 * 	获取报表汇总
	 */
	@PostMapping(value = "/reportsummary")
	@ApiOperation(value = "获取报表汇总", httpMethod = "POST", notes = "接口发布说明")
	@ApiOperationSupport(order = 56)
	public Result<List<AttendanceReport>> ReportSummary(@CurrentUser UserBean userBean,@RequestBody AttendanceDetails attendancedetails) {
		
			//考勤报表列表
			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
			
			int qyid = userBean.getOrgCode();//坏小孩【企业id】
			int userid = userBean.getEmpNum();//用户id	
			
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH) + 1;
			int date = cal.get(Calendar.DATE);
			
			Date d = new Date();
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    String str = sdf.format(d);
			
			Long startDate = 0l;
			Long endDate = 0l;
			
			if(!("").equals(attendancedetails.getStart())){
			   try {
				   String sdaet = getMinMonthDate(attendancedetails.getStart());
				   startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(sdaet,"yyyy-MM-dd")).getTime();
				       
				   String edate = getMaxMonthDate(attendancedetails.getEnd());
				   endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(edate,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else{
				try {
					Calendar c = Calendar.getInstance();    
					c.add(Calendar.MONTH, 0);
					c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
					String first = mat.format(c.getTime());
					startDate = DateUtil.getStartTime(0,DateUtil.getStringTime(first,"yyyy-MM-dd")).getTime();
					//获取当前月最后一天
					Calendar ca = Calendar.getInstance();    
					ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
					String last = mat.format(ca.getTime());
					endDate = DateUtil.getnowEndTime(23,DateUtil.getStringTime(last,"yyyy-MM-dd")).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			
			
			List<YgglMainEmp> attoff = attendancegroupservice.selectAttendanceOfficer(String.valueOf(qyid),attendancedetails.getText());//获取公司人员
			
			for(YgglMainEmp kqry : attoff){
				
				int gzsc = punchcarddetailsservice.selectWorkingHours(Integer.valueOf(kqry.getEmpNum()),startDate,endDate);
				
				List<PunchRecord> initial = punchrecordservice.getMaintenancePunchCardList(startDate,endDate,Integer.valueOf(kqry.getEmpNum()));
				int latenum = 0;// 迟到次数
				int latehours = 0;// 迟到时长
				int leanum = 0;// 早退次数
				int leahours = 0;// 早退时长
				if(initial.size() > 0){
					for(PunchRecord prd : initial){
						if(prd.getType() == 1 && prd.getResults() > 0){
							latenum++;
							latehours += prd.getResults();
						}
						if(prd.getType() == 2 && prd.getResults() > 0){
							leanum++;
							leahours += prd.getResults();
						}
					}
				}
				
				AttendanceReport apr = new AttendanceReport();
				apr.setId(Integer.valueOf(kqry.getEmpNum()));
				apr.setName(kqry.getName());//姓名
				apr.setJobnumber(kqry.getEmpNum());//工号
				apr.setWorkhours(gzsc);//工作时长
				
				apr.setLatenum(latenum);//
				apr.setLatehours(latehours);//
				apr.setLeanum(leanum);//
				apr.setLeahours(leahours);//
				/**********/
				AttendanceGroup attgro = attendancegroupservice.getAttendanceGroupInformationByUserid(Integer.valueOf(kqry.getEmpNum())); //考勤组信息
				//pbfs;// 排班方式 1:固定排班;2:自由排班;3:自由工时
				if(attgro != null){//该员工是否加入到考勤组
					if(attgro.getPbfs() == 1){
						//当前月     必须打卡日期
						List<SpecialDate> bxdklist = specialdateservice.ShouldSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						int bxdk = bxdklist.size();
						//当前月     无需打卡日期
						List<SpecialDate> wxdk = specialdateservice.RestSpecialDatessetByKqzid(attgro.getId(),startDate,endDate);
						String[] appmaps= new String[wxdk.size()];
						int d1 = 0;
						for(SpecialDate spe:wxdk){
							appmaps[d1] = spe.getTsrq();
							d1++;
						}
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						int q = 0;
						 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])){
										
										q++;
										
										y++;
										if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
											y = y-1;
										}
									}
								}
							} catch (ParseException c) {
								c.printStackTrace();
							}
						 }
						 
						 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++;
							}
						}
	//					System.out.println(xiuxi);
						apr.setRestday(xiuxi);//休息天数
						apr.setAnswerday(shangban);//应出勤
					}else{
						List<AttendanceWeeklySch> atwek = attendanceweeklyschservice.selectAttendanceMadeByUserid(Integer.valueOf(kqry.getEmpNum()));
						String[] week= new String[atwek.size()];
						int e = 0;
						for(AttendanceWeeklySch awek : atwek){
							week[e] = awek.getWekmc();
							e++;
						}
						String yemo = year + "-" + month;
						String datetime = year + "-" + month + "-" + date;
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
						sdf1.setLenient(false);
						SimpleDateFormat sdf2 = new SimpleDateFormat("EEE");
						try {
							Date parse = sdf.parse(datetime);
							Calendar lastDate = Calendar.getInstance();
							 lastDate.setTime(parse);
							 lastDate.set(Calendar.DATE, 1);
							 lastDate.add(Calendar.MONTH, 1);
							 lastDate.add(Calendar.DATE, -1);
						} catch (ParseException e1) {
							e1.printStackTrace();
						}
						int y = 0;
						 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();
							}
						 }
						 
						 int xiuxi = getDaysByYearMonth(year,month) - y;
						 apr.setRestday(xiuxi);//休息天数
						 apr.setAnswerday(y);//应出勤
					}
				    List<PunchCardDetails> attendance = punchcarddetailsservice.selectAttendanceDays(Integer.valueOf(kqry.getEmpNum()), startDate, endDate);//打卡记录
				    apr.setActualday(attendance.size());//已出勤
					if(apr.getAnswerday() > 0){
						BigDecimal g = new BigDecimal(apr.getAnswerday());  
						BigDecimal h = new BigDecimal(apr.getActualday()); 
						int lack = g.subtract(h).intValue();  
						apr.setMinerday(lack);//缺勤
					}
		            int sbqk = 0;
		            int xbqk = 0;
		            for(PunchCardDetails pcd:attendance){
		            	if(pcd.getYdkcs() == 2 || pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk1() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk1() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 4 || pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk2() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk2() == null){
		            			xbqk++;
		            		}
		            	}
		            	if(pcd.getYdkcs() == 6){
		            		if(pcd.getSbdk3() == null){
		            			sbqk++;
		            		}
		            		if(pcd.getXbdk3() == null){
		            			xbqk++;
		            		}
		            	}
		            }
		            apr.setGoworkmissingcard(sbqk);//上班缺卡
		            apr.setOffworkmissingcard(xbqk);//下班缺卡
				}
				/**********/
				
				
				
				attrep.add(apr);
			}
			
			
//			List<AttendanceReport> attrep = new ArrayList<AttendanceReport>();
			int attshouldmade = 0;//应出勤
			for(AttendanceReport reps:attrep) {
				System.out.println(reps.getAnswerday());
			}
			
			
			
			return ResultUtil.data(attrep);
	}
}