package com.jpsoft.shinestar.modules.mobile.controller;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.config.OSSConfig;
import com.jpsoft.shinestar.config.TemperatureConfig;
import com.jpsoft.shinestar.config.WxConfig;
import com.jpsoft.shinestar.modules.base.constant.AttendanceTypes;
import com.jpsoft.shinestar.modules.base.dto.*;
import com.jpsoft.shinestar.modules.base.entity.*;
import com.jpsoft.shinestar.modules.base.service.*;
import com.jpsoft.shinestar.modules.business.dto.ArrangeShiftListDTO;
import com.jpsoft.shinestar.modules.business.entity.*;
import com.jpsoft.shinestar.modules.business.service.*;
import com.jpsoft.shinestar.modules.common.dto.MessageResult;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.jpsoft.shinestar.modules.common.utils.JwtUtil2;
import com.jpsoft.shinestar.modules.common.utils.PojoUtils;
import com.jpsoft.shinestar.modules.common.utils.TypeNameUtil;
import com.jpsoft.shinestar.modules.common.utils.WechatMessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/mobile/workAttendance")
@Slf4j
public class WorkAttendanceApiController {
    @Autowired
    private PersonInfoService personInfoService;

    @Value("${jwt.secret}")
    private String jwtSecret;

    @Autowired
    private CompanyInfoService companyInfoService;

    @Autowired
    private PersonRoleIconService personRoleIconService;

    @Autowired
    private SupplementWorkService supplementWorkService;

    @Autowired
    private BusinessOutService businessOutService;

    @Autowired
    private WorkScheduleAttendanceService workScheduleAttendanceService;

    @Autowired
    private RequestForLeaveInfoService requestForLeaveInfoService;

    @Autowired
    private WxConfig wxConfig;

    @Autowired
    private PersonRoleInfoService personRoleInfoService;

    @Autowired
    private PersonCompanyService personCompanyService;

    @Autowired
    private AlarmConfigService alarmConfigService;

    @Autowired
    private ApplicationExamineService applicationExamineService;

    @Autowired
    private SupplementWorkPersonService supplementWorkPersonService;

    @Autowired
    private TemperatureConfig temperatureConfig;

    @Autowired
    private WorkAttendanceService workAttendanceService;

    @Autowired
    private PersonPopedomService personPopedomService;

    @Autowired
    private FillAttendanceService fillAttendanceService;

    @Autowired
    private FillAttendanceFilesService fillAttendanceFilesService;

    @Autowired
    private OSSConfig ossConfig;

    @Autowired
    private HolidayInfoService holidayInfoService;

    @Autowired
    private PersonDeviceLogService personDeviceLogService;

    @Autowired
    private WorkPersonSchedulingService workPersonSchedulingService;

    @ApiOperation(value = "考勤记录")
    @RequestMapping(value = "pageList", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "result", value = "全部/缺卡（0/1）", required = true, paramType = "form")
    })

    public MessageResult<Map> pageList(@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                       @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, String result,
                                       @RequestAttribute String subject, String token) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();
            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            Map<String, Object> searchParams = new HashMap<>();
            List<Sort> sortList = new ArrayList<>();
            sortList.add(new Sort("record_time", "desc"));
            searchParams.put("personId", personInfo.getId());

            if ("1".equals(result)) {
                searchParams.put("result", "0");
                searchParams.put("workStatus","1");
            }
            Page<WorkScheduleAttendance> page = workScheduleAttendanceService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
            Page<WorkDTO> workDTOPage = PojoUtils.convertPage(page, WorkDTO.class);
            if (workDTOPage.getResult().size() > 0) {
                for (WorkDTO workDTO : workDTOPage) {
                    if (workDTO.getResult().equals("0")) {
                     //   if (fillAttendance != null) {
                        if (StringUtils.isNotBlank(workDTO.getSupplementWorkPersonId())){
                            SupplementWorkPerson supplementWorkPerson = supplementWorkPersonService.get(workDTO.getSupplementWorkPersonId());

                            if(supplementWorkPerson!=null) {
                                SupplementWork supplementWork = supplementWorkService.get(supplementWorkPerson.getSupplementWorkId());

                                workDTO.setSupplementWorkId(supplementWork.getId());
                                //   workDTO.setFillAttendanceId(fillAttendance.getId());
                                workDTO.setStatus(supplementWork.getStatus());
                                if (supplementWork.getStatus().equals("0")) {
                                    workDTO.setStatusN("审核中");
                                } else if (supplementWork.getStatus().equals("1")) {
                                    workDTO.setStatusN("通过");
                                } else if (supplementWork.getStatus().equals("3")) {
                                    workDTO.setStatusN("拒绝");
                                }
                            }
                            else{
                                workDTO.setStatusN("未处理");
                            }
                        } else {
                            workDTO.setStatusN("未处理");
                        }

                        if ("3".equals(workDTO.getWorkStatus())){
                            workDTO.setResult("5");
                        }
                        if ("4".equals(workDTO.getWorkStatus())){
                            workDTO.setResult("4");
                        }
                    } else if (workDTO.getResult().equals("1")) {
                        if (StringUtils.isNotBlank(workDTO.getSupplementWorkPersonId())){
                            SupplementWorkPerson supplementWorkPerson = supplementWorkPersonService.get(workDTO.getSupplementWorkPersonId());

                            if (supplementWorkPerson!=null) {
                                SupplementWork supplementWork = supplementWorkService.get(supplementWorkPerson.getSupplementWorkId());

                                workDTO.setSupplementWorkId(supplementWork.getId());
                                if ("1".equals(supplementWork.getStatus())) {
                                    workDTO.setStatus("1");
                                    workDTO.setStatusN("审核通过");
                                }
                            }
                         //   workDTO.setFillAttendanceId(fillAttendance.getId());
                        }
                    }
                }

            }
            dataMap = PojoUtils.pageWrapper(workDTOPage);


            msgResult.setData(dataMap);
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }

    @ApiOperation(value = "考勤记录（统计）")
    @RequestMapping(value = "statistics", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "date", value = "时间（如：2021-05-10）", required = true, paramType = "form")
    })

    public MessageResult<Map> statistics(String token, @RequestAttribute String subject,String date) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();
            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            Map<String, Object> searchParams = new HashMap<>();
            List<Sort> sortList = new ArrayList<>();
            sortList.add(new Sort("record_time", "desc"));
            searchParams.put("personId", personInfo.getId());
            searchParams.put("attendanceDateLike",date+"%");
            //searchParams.put("result", "0");
           // searchParams.put("workStatus","1");

            String dateStr = date + "-01 " + "00:00:00";

            Date startDate = DateUtil.parse(dateStr);
            Date endDate = DateUtil.endOfMonth(startDate);


            List<WorkScheduleAttendance> page = workScheduleAttendanceService.listSearch(searchParams, sortList);
           //Page<WorkDTO> workDTOPage = PojoUtils.convertPage(page, WorkDTO.class);
            List<WorkDTO> list=new ArrayList<>();
            if (page!=null&&page.size() > 0) {
                for (WorkScheduleAttendance workDTO : page) {
                    WorkDTO dto=new WorkDTO();
                    BeanUtils.copyProperties(workDTO,dto);

                    if (workDTO.getResult().equals("0")) {
                        //   if (fillAttendance != null) {
                        if (StringUtils.isNotBlank(workDTO.getSupplementWorkPersonId())){
                            SupplementWorkPerson supplementWorkPerson = supplementWorkPersonService.get(workDTO.getSupplementWorkPersonId());

                            if (supplementWorkPerson!=null) {
                                SupplementWork supplementWork = supplementWorkService.get(supplementWorkPerson.getSupplementWorkId());

                                dto.setSupplementWorkId(supplementWork.getId());
                                //   workDTO.setFillAttendanceId(fillAttendance.getId());
                                dto.setStatus(supplementWork.getStatus());
                                if (supplementWork.getStatus().equals("0")) {
                                    dto.setStatusN("审核中");
                                } else if (supplementWork.getStatus().equals("1")) {
                                    dto.setStatusN("通过");
                                } else if (supplementWork.getStatus().equals("3")) {
                                    dto.setStatusN("拒绝");
                                }
                            }
                        } else {
                            dto.setStatusN("未处理");
                        }

                        if ("3".equals(workDTO.getWorkStatus())){
                            dto.setResult("5");
                        }
                        if ("4".equals(workDTO.getWorkStatus())){
                            dto.setResult("4");
                        }
                    } else if (workDTO.getResult().equals("1")) {
                        if (StringUtils.isNotBlank(workDTO.getSupplementWorkPersonId())){
                            SupplementWorkPerson supplementWorkPerson = supplementWorkPersonService.get(workDTO.getSupplementWorkPersonId());

                            if (supplementWorkPerson!=null) {
                                SupplementWork supplementWork = supplementWorkService.get(supplementWorkPerson.getSupplementWorkId());

                                dto.setSupplementWorkId(supplementWork.getId());
                                if ("1".equals(supplementWork.getStatus())) {
                                    dto.setStatus("1");
                                    dto.setStatusN("审核通过");
                                }
                            }
                            //   workDTO.setFillAttendanceId(fillAttendance.getId());
                        }

                    }
                    list.add(dto);
                }


            }
            //先查总班次 确认正常上班和休息
            List<WorkPersonScheduling> startWorkPersonScheduling
                    = workPersonSchedulingService.findByPersonIdSDateAndEDate(personInfo.getId(),startDate,endDate,false);

            //全勤天数totalAttendanceDays
            BigDecimal totalAttendanceDays = workScheduleAttendanceService.findTotalAttendance(personInfo.getId(),startDate,endDate,"1");
            dataMap.put("attendanceDays",startWorkPersonScheduling.size());
            dataMap.put("totalAttendanceDays",totalAttendanceDays);

            dataMap.put("list",list);
            msgResult.setData(dataMap);
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }
    @ApiOperation(value = "补卡申请获取时间段")
    @RequestMapping(value = "patchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "workAttendanceId", value = "考勤id", required = false, paramType = "form"),
            @ApiImplicitParam(name = "attendanceType", value = "外出/出差（2/3）", required = false, paramType = "form")
    })
    public MessageResult<Map> patchCard(String workAttendanceId, @RequestAttribute String subject, String token, String attendanceType) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("申请人不存在");
            }

            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());

            String workAttendanceDate = "";
            String workAttendanceTime = "";
            String alarmConfigId = "";
            if (StringUtils.isNotBlank(workAttendanceId)) {
                WorkAttendance workAttendance = workAttendanceService.get(workAttendanceId);
                AlarmConfig alarmConfig = alarmConfigService.get(workAttendance.getAlarmConfigId());
                if (workAttendance == null) {
                    throw new Exception("考勤记录不存在");
                }
                if (!"0".equals(workAttendance.getResult())) {
                    throw new Exception("只有缺卡才能申请补卡");
                }
                //考勤日期
                workAttendanceDate = DateUtil.format(workAttendance.getRecordTime(), "yyyy-MM-dd");

                //考勤时间段
                if (alarmConfig.getClassifier().equals(1)) {
                    workAttendanceTime = alarmConfig.getStartTime() + "-" + alarmConfig.getAttendanceTime();
                } else {
                    workAttendanceTime = alarmConfig.getAttendanceTime() + "-" + alarmConfig.getEndTime();
                }
            } else {
                Integer type = 2;
                /*if ("3".equals(attendanceType)) {
                    type = 2;
                }*/
                workAttendanceDate = DateUtil.today();
                //     String newWorkAttendanceTime = "";
                //获取当天星期，国外和国内一周开始日期不一样，要偏一天
                Integer weekDay = DateUtil.dayOfWeek(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, -1));

                List<AlarmConfig> alarmConfigList = null;
                List<AlarmConfig> alarmConfigList0 = alarmConfigService.findByCompanyIdAndWeekDay(personInfo.getCompanyId(), '%' + weekDay.toString() + '%', type);
                if (alarmConfigList0.size() == 0) {
                    CompanyInfo companyInfo1 = companyInfoService.get(personInfo.getCompanyId());

                    String[] arr = companyInfo.getCode().split(",");
                    for (int i = arr.length - 1; i >= 0; i--) {
                        List<AlarmConfig> alarmConfigList1 = alarmConfigService.findByCompanyIdAndWeekDay(arr[i], '%' + weekDay.toString() + '%', type);
                        if (alarmConfigList1.size() == 0) {
                            continue;
                        } else {
                            alarmConfigList = alarmConfigList1;
                        }
                    }

                } else {
                    alarmConfigList = alarmConfigList0;
                }

                if (alarmConfigList == null) {
                    throw new Exception("当天无考勤配置");
                }

                if (alarmConfigList.size() <= 0) {
                    throw new Exception("当天无考勤配置");
                }


                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

                for (AlarmConfig alarmConfig : alarmConfigList) {
                    Long nowTime = new Date().getTime();

                    Long startTime = sdf.parse(workAttendanceDate + " " + alarmConfig.getStartTime()).getTime();
                    Long attendanceTime = sdf.parse(workAttendanceDate + " " + alarmConfig.getAttendanceTime()).getTime();
                    Long endTime = sdf.parse(workAttendanceDate + " " + alarmConfig.getEndTime()).getTime();

                    if (nowTime <= endTime && nowTime >= startTime) {
//                      workAttendanceTime = alarmConfig.getStartTime() + "-" + alarmConfig.getEndTime();
                        //考勤时间段
                        if (alarmConfig.getClassifier().equals(1)) {
                            //正常上班时段
                            if (nowTime >= startTime && nowTime <= attendanceTime) {
                                //上班
                                workAttendanceTime = alarmConfig.getStartTime() + "-" + alarmConfig.getAttendanceTime();
                            }
                        } else {
                            //正常下班时段
                            if (nowTime >= attendanceTime && nowTime <= endTime) {
                                workAttendanceTime = alarmConfig.getAttendanceTime() + "-" + alarmConfig.getEndTime();
                            }
                        }

                        alarmConfigId = alarmConfig.getId();
                        break;
                    } else {
                        continue;
                    }
                }

                if (StringUtils.isBlank(workAttendanceTime)) {
                    throw new Exception("不在考勤时间段");
                }
            }

            HashMap<String, Object> dataMap = new HashMap<>();
            dataMap.put("workAttendanceId", workAttendanceId);
            dataMap.put("workAttendanceDate", workAttendanceDate);
            dataMap.put("workAttendanceTime", workAttendanceTime);
            dataMap.put("alarmConfigId", alarmConfigId);
            msgResult.setData(dataMap);
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }


    @ApiOperation(value = "补卡申请数据提交")
    @RequestMapping(value = "postPatchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "workAttendanceId", value = "考勤id", required = false, paramType = "form"),
            @ApiImplicitParam(name = "alarmConfigId", value = "考勤时间段设置id", required = false, paramType = "form"),
            @ApiImplicitParam(name = "workAttendanceDate", value = "考勤日期", required = true, paramType = "form"),
            @ApiImplicitParam(name = "workAttendanceTime", value = "考勤时间段", required = true, paramType = "form"),
            @ApiImplicitParam(name = "type", value = "外勤打卡/补卡（1/2）", required = true, paramType = "form"),
            @ApiImplicitParam(name = "content", value = "申请理由", required = true, paramType = "form"),
            @ApiImplicitParam(name = "photoFile", value = "图片", required = false, paramType = "form"),
            @ApiImplicitParam(name = "longitude", value = "经度", required = false, paramType = "form"),
            @ApiImplicitParam(name = "latitude", value = "纬度", required = false, paramType = "form"),
            @ApiImplicitParam(name = "address", value = "打卡地址", required = false, paramType = "form"),
            @ApiImplicitParam(name = "approvalPersonId", value = "审核人", required = false, paramType = "form"),
            @ApiImplicitParam(name = "attendanceType", value = "外出/出差（2/3）", required = false, paramType = "form")
    })
    public MessageResult<WorkAttendanceDTO> postPatchCard(
            String workAttendanceId, String alarmConfigId,
            @RequestParam("workAttendanceDate") String workAttendanceDate,
            @RequestParam("workAttendanceTime") String workAttendanceTime,
            @RequestParam("type") String type,
            @RequestParam("content") String content,
            String photoFile, String longitude, String latitude, String address,
            String approvalPersonId,
            @RequestAttribute String subject, String token, String attendanceType) {
        MessageResult<WorkAttendanceDTO> msgResult = new MessageResult<>();

        try {
            //查询操作人
            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("申请人不存在");
            }

            //申请人角色
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());


            //外勤打卡
            if ("1".equals(type)) {
                if (StringUtils.isNotBlank(personInfo.getWorkStatus())) {
                    if (!attendanceType.equals(personInfo.getWorkStatus())) {
                        throw new Exception("工作类型与考勤类型不符");
                    }
                }


                Map<String, Object> searchParam = new HashMap<>();
                searchParam.put("alarmConfigId", alarmConfigId);
                searchParam.put("personId", personInfo.getId());
                searchParam.put("maxRecordTime", DateUtil.beginOfDay(new Date()));
                List<Sort> sortList = new ArrayList<>();
                sortList.add(new Sort("record_time", "desc"));
                Page<WorkAttendance> workAttendancePage = workAttendanceService.pageSearch(searchParam, 1, 20, true, sortList);
                if (workAttendancePage.getResult().size() > 0) {
                    throw new Exception("此时间段已有打卡记录");
                }


            }
            //补卡
            else if ("2".equals(type)) {
                if (StringUtils.isBlank(workAttendanceId)) {
                    throw new Exception("考勤记录id不存在");
                }

                WorkAttendance workAttendance = workAttendanceService.get(workAttendanceId);
                if (workAttendance == null) {
                    throw new Exception("考勤记录不存在");
                }
                if (!"0".equals(workAttendance.getResult())) {
                    throw new Exception("只有缺卡才能申请补卡");
                }

                FillAttendance fillAttendance = fillAttendanceService.findByBusinessWorkAttendanceId(workAttendanceId);
                if (fillAttendance != null && fillAttendance.getStatus().equals("1")) {
                    throw new Exception("已经审核通过");
                }


            }

            FillAttendance fillAttendance = fillAttendanceService.insertAndfile(workAttendanceId, workAttendanceDate,
                    workAttendanceTime, content, type, photoFile, longitude, latitude,
                    approvalPersonId, personInfo.getId(), alarmConfigId, address, attendanceType);


            WorkAttendanceDTO workAttendanceDTO = new WorkAttendanceDTO();
            BeanUtils.copyProperties(fillAttendance, workAttendanceDTO);
            workAttendanceDTO.setFillAttendanceDayAndTime(fillAttendance.getFillDay() + " " + fillAttendance.getFillAttendanceTime());
            workAttendanceDTO.setPersonName(personInfo.getName());
            workAttendanceDTO.setFaceImageUrl(personInfo.getFaceImageUrl());
            if (StringUtils.isNotBlank(approvalPersonId)) {
                PersonPopedom personPopedom1 = personPopedomService.get(approvalPersonId);
                PersonInfo approvalPerson = personInfoService.get(personPopedom1.getPersonId());
                workAttendanceDTO.setApprovalPersonName(approvalPerson.getName());
            }
            if (StringUtils.isBlank(approvalPersonId)) {
                workAttendanceDTO.setApprovalPersonName("自动审核");
            }


            if (fillAttendance.getType().equals("1")) {
                workAttendanceDTO.setTypeN("外勤打卡");
            } else if (fillAttendance.getType().equals("2")) {
                workAttendanceDTO.setTypeN("补卡");
            }
            workAttendanceDTO.setCompanyName(personInfo.getCompanyName());
            workAttendanceDTO.setFillAttendanceFilesUrl(photoFile == null ? "" : photoFile);

            msgResult.setData(workAttendanceDTO);
            msgResult.setMessage("提交成功");
            msgResult.setResult(true);


            new Thread(() -> {
                try {

                    //只有补卡申请才需要审核
                    if ("2".equals(fillAttendance.getType())) {

                        PersonPopedom personPopedom1 = personPopedomService.get(approvalPersonId);
                        PersonInfo approvalPerson = personInfoService.get(personPopedom1.getPersonId());

                        String accessToken = JwtUtil2.createToken(jwtSecret, approvalPerson.getId() + "", DateTime.now().plusHours(30 * 24).toDate());
                        WechatMessageUtil.sendEvenMessage(approvalPerson.getOpenId(), "有一条新的补卡信息待审核", personInfo.getName(), fillAttendance.getApprovalNo(), "前往处理", wxConfig.getPortalUrl() + "master/attendance/verifyInfo?id=" + fillAttendance.getId() + "&exchange=1&role_id=" + personPopedom1.getId() + "&token=" + accessToken, wxConfig.getAppId(), wxConfig.getAppSecret());


                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                }
            }).start();

        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }



    @ApiOperation(value = "个人补卡申请提交")
    @PostMapping(value = "supplementWorkSubmit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "考勤记录id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "reason", value = "申请理由", required = true, paramType = "form"),
            @ApiImplicitParam(name = "imageUrl", value = "照片地址", required = false, paramType = "form"),
            @ApiImplicitParam(name = "formId", value = "标识", required = true, paramType = "form"),
            @ApiImplicitParam(name = "draft", value = "状态（0：草稿，1：提交）", required = true, paramType = "form")
    })
    public MessageResult<Map> supplementWorkSubmit(String ids,String draft,String id, String reason, String imageUrl,String formId, String token, @RequestAttribute String subject) {


        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            PersonInfo person = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(person.getPopedom());


            String supplementWorkId = supplementWorkService.supplementWorkSubmit(personPopedom, id, reason,imageUrl, formId,ids,draft);

            Map<String, Object> map = new HashMap<>();
            map.put("id", supplementWorkId);
            messageResult.setData(map);
            messageResult.setCode(200);
            messageResult.setResult(true);


        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);

        }

        return messageResult;
    }


    @ApiOperation(value = "批量补卡申请提交")
    @PostMapping(value = "supplementWorkBatchSubmit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "年月日", required = true, paramType = "form"),
            @ApiImplicitParam(name = "reason", value = "申请理由", required = true, paramType = "form"),
            @ApiImplicitParam(name = "personIds", value = "人员", required = true, paramType = "form"),
            @ApiImplicitParam(name = "imageUrl", value = "照片地址", required = false, paramType = "form"),
            @ApiImplicitParam(name = "formId", value = "标识", required = true, paramType = "form"),
            @ApiImplicitParam(name = "draft", value = "状态（0：草稿，1：提交）", required = true, paramType = "form")
    })
    public MessageResult<Map> supplementWorkBatchSubmit(String ids,String draft,String date, String reason,String personIds, String imageUrl,String formId, String token, @RequestAttribute String subject) {


        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            PersonInfo person = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(person.getPopedom());


            String supplementWorkId = supplementWorkService.supplementWorkBatchSubmit(personPopedom, date,personIds, reason,imageUrl, formId,ids,draft);

            Map<String, Object> map = new HashMap<>();
            map.put("id", supplementWorkId);
            messageResult.setData(map);
            messageResult.setCode(200);
            messageResult.setResult(true);


        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);

        }

        return messageResult;
    }

    @ApiOperation(value = "根据id查询个人补卡详情")
    @PostMapping(value = "supplementWorkDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form")
    })
    public MessageResult<Map> supplementWorkDetail(String id, String token, @RequestAttribute String subject) {


        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            PersonInfo person = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(person.getPopedom());



            //主业务
            SupplementWork supplementWork = supplementWorkService.get(id);

            //申请人
               PersonPopedom supplementWorkPopedom = personPopedomService.get(supplementWork.getPersonPopedomId());
            PersonInfo supplementWorkPerson = personInfoService.get(supplementWorkPopedom.getPersonId());


            Map<String, Object> map = new HashMap<>();
            map.put("name", supplementWorkPerson.getName());
            map.put("faceImageUrl",supplementWorkPerson.getFaceImageUrl());
            map.put("imageUrl", supplementWork.getImageUrl());
            map.put("reason",supplementWork.getReason());
          //  map.put("type",supplementWork.getType());
           // map.put("typeName", TypeNameUtil.getLeaveTypeName(supplementWork.getType()));
            map.put("status", supplementWork.getStatus());
            map.put("statusName", TypeNameUtil.getExamineTypeName(supplementWork.getStatus().toString()));
            map.put("attendanceDate", supplementWork.getAttendanceDate());
            map.put("createTime",DateUtil.format(supplementWork.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));

            messageResult.setData(map);
            messageResult.setCode(200);
            messageResult.setResult(true);

        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);

        }
        return messageResult;
    }

    @ApiOperation(value = "根据id查询批量补卡详情")
    @PostMapping(value = "supplementWorkBatchDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form")
    })
    public MessageResult<Map> supplementWorkBatchDetail(String id, String token, @RequestAttribute String subject) {


        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            PersonInfo person = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(person.getPopedom());



            //主业务
            SupplementWork supplementWork = supplementWorkService.get(id);

            String name = "";
            String nameId = "";
            //子业务表
            List<SupplementWorkPerson> supplementWorkPersonList = supplementWorkPersonService.findBySupplementWorkId(supplementWork.getId());
            if (supplementWorkPersonList.size()>0){
                for (SupplementWorkPerson supplementWorkPerson : supplementWorkPersonList){

                    if (supplementWorkPerson!=null) {
                        PersonPopedom personPopedom1 = personPopedomService.get(supplementWorkPerson.getPersonPopedomId());

                        if (personPopedom1 != null) {
                            PersonInfo personInfo = personInfoService.get(personPopedom1.getPersonId());
                            if (StringUtils.isBlank(name)) {
                                name = personInfo.getName();
                                nameId = String.valueOf(personInfo.getId());
                            } else {
                                name = name + "," + personInfo.getName();
                                nameId = nameId + "," + personInfo.getId();
                            }
                        }
                    }
                }
            }



            Map<String, Object> map = new HashMap<>();
            map.put("name", name);
            map.put("imageUrl", supplementWork.getImageUrl());
            map.put("reason",supplementWork.getReason());
            map.put("status", supplementWork.getStatus());
            map.put("statusName", TypeNameUtil.getExamineTypeName(supplementWork.getStatus().toString()));
            map.put("attendanceDate", supplementWork.getAttendanceDate());
            map.put("createTime",DateUtil.format(supplementWork.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
            map.put("nameId",nameId);

            messageResult.setData(map);
            messageResult.setCode(200);
            messageResult.setResult(true);

        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);

        }
        return messageResult;
    }

    @ApiOperation(value = "批量补卡记录列表")
    @PostMapping(value = "supplementWorkBatchList")
    public MessageResult<Map> supplementWorkBatchList(String token, @RequestAttribute String subject, @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {


        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            PersonInfo person = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(person.getPopedom());

            List<ArrangeShiftListDTO> list = new ArrayList<>();
            Map<String, Object> searchParams = new HashMap<>();
            searchParams.put("personPopedomId", personPopedom.getId());
            searchParams.put("type","2");
            List<Sort> sortList = new ArrayList<>();
            sortList.add(new Sort("create_time", "desc"));
            Page<SupplementWork> page = supplementWorkService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);

            List<SupplementWork> supplementWorkList = page.getResult();
            if (supplementWorkList.size()>0){
                for (SupplementWork supplementWork : supplementWorkList){
                    List<SupplementWorkPerson> supplementWorkPersonList = supplementWorkPersonService.findBySupplementWorkId(supplementWork.getId());
                    SupplementWorkPerson supplementWorkPerson = supplementWorkPersonList.get(0);
                    PersonPopedom personPopedom1 = personPopedomService.get(supplementWorkPerson.getPersonPopedomId());
                    PersonInfo personInfo = personInfoService.get(personPopedom1.getPersonId());
                    ArrangeShiftListDTO arrangeShiftListDTO = new ArrangeShiftListDTO();
                    arrangeShiftListDTO.setId(supplementWork.getId());
                    arrangeShiftListDTO.setName(personInfo.getName()+"等"+supplementWorkPersonList.size()+"人");
                    arrangeShiftListDTO.setAdjustDate(supplementWork.getAttendanceDate());
                    arrangeShiftListDTO.setSubmitDate(DateUtil.format(supplementWork.getSubmitTime(),"yyyy-MM-dd HH:mm:ss"));
                    arrangeShiftListDTO.setStatus(supplementWork.getStatus());
                    arrangeShiftListDTO.setStatusName(TypeNameUtil.getExamineTypeName(supplementWork.getStatus()));
                    list.add(arrangeShiftListDTO);

                }
            }

            Map<String, Object> pageMap = new HashMap<>();
            pageMap.put("recordsTotal", page.getTotal());
            pageMap.put("recordsFiltered", page.getTotal());
            pageMap.put("totalPage", page.getPages());
            pageMap.put("pageNumber", page.getPageNum());
            pageMap.put("pageSize", page.getPageSize());
            pageMap.put("data", list);

            messageResult.setData(pageMap);
            messageResult.setCode(200);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);

        }

        return messageResult;
    }




    @ApiOperation(value = "个人考勤申请记录列表")
    @RequestMapping(value = "ownListPatchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
    })
    public MessageResult<Map> ownListPatchCard(
            @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
            @RequestAttribute String subject, String token) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("人员不存在");
            }

            Map<String, Object> searchParam = new HashMap<>();
            searchParam.put("personId", personInfo.getId());
            List<Sort> sortList = new ArrayList<>();
            sortList.add(new Sort("create_time", "desc"));
            Page<FillAttendance> fillAttendancePage = fillAttendanceService.pageSearch(searchParam, pageIndex, pageSize, sortList);
            if (fillAttendancePage.getResult().size() > 0) {
                for (FillAttendance fillAttendance : fillAttendancePage) {
                    fillAttendance.setFaceImageUrl(personInfo.getFaceImageUrl());
                    if (fillAttendance.getType().equals("1")) {
                        fillAttendance.setTypeN("外勤打卡");
                    }
                    if (fillAttendance.getType().equals("2")) {
                        fillAttendance.setTypeN("补卡");
                    }
                    if (fillAttendance.getStatus().equals("0")) {
                        fillAttendance.setStatusN("审核中");
                    }
                    if (fillAttendance.getStatus().equals("1")) {
                        fillAttendance.setStatusN("通过");
                    }
                    if (fillAttendance.getStatus().equals("2")) {
                        fillAttendance.setStatusN("拒绝");
                    }
                }
            }


            msgResult.setData(PojoUtils.pageWrapper(fillAttendancePage));
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }

    @ApiOperation(value = "审核人考勤申请记录列表")
    @RequestMapping(value = "adminListPatchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "status", value = "状态（0：未处理，3：已处理）", required = true, paramType = "form")
    })
    public MessageResult<Map> adminListPatchCard(
            @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
            @RequestAttribute String subject, String token, String status) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("人员不存在");
            }
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());

            List<Sort> sortList = new ArrayList<>();
            Map<String, Object> searchParam = new HashMap<>();

            if (status.equals("0")) {
                searchParam.put("approvalPersonPopedomId", personPopedom.getId());
                searchParam.put("status", status);
                sortList.add(new Sort("create_time", "desc"));
            } else {
                //已处理
                searchParam.put("notStatus", "0");
                searchParam.put("approvalPersonIdStr","%"+ personPopedom.getId()+"%");
                sortList.add(new Sort("approval_time", "desc"));
            }


            Page<FillAttendance> fillAttendancePage = fillAttendanceService.pageSearch(searchParam, pageIndex, pageSize, sortList);
            if (fillAttendancePage.getResult().size() > 0) {
                for (FillAttendance fillAttendance : fillAttendancePage) {
                    PersonInfo workerPerson = personInfoService.get(fillAttendance.getPersonId());
                    fillAttendance.setFaceImageUrl(workerPerson.getFaceImageUrl());
                    if (fillAttendance.getType().equals("1")) {
                        fillAttendance.setTypeN("外勤打卡");
                    }
                    if (fillAttendance.getType().equals("2")) {
                        fillAttendance.setTypeN("补卡");
                    }
                    if (fillAttendance.getStatus().equals("0")) {
                        fillAttendance.setStatusN("审核中");
                    }
                    if (fillAttendance.getStatus().equals("1")) {
                        fillAttendance.setStatusN("通过");
                    }
                    if (fillAttendance.getStatus().equals("2")) {
                        fillAttendance.setStatusN("拒绝");
                    }
                }
            }


            msgResult.setData(PojoUtils.pageWrapper(fillAttendancePage));
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }

    @ApiOperation(value = "审核人列表")
    @RequestMapping(value = "approvalList", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "审批类型（补卡1，外出2，出差3 ，请假4）", required = false, paramType = "form"),
            @ApiImplicitParam(name = "level", value = "层级", required = false, paramType = "form"),
            @ApiImplicitParam(name = "days", value = "请假天数", required = false, paramType = "form")
    })
    public MessageResult<Map> approvalList(
            @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
            @RequestAttribute String subject, String token,
            @RequestParam(value = "type", defaultValue = "2") String type,
            @RequestParam(value = "level", defaultValue = "1") String levelStr,
            @RequestParam(value = "days", defaultValue = "") String daysStr) {
        MessageResult<Map> msgResult = new MessageResult<>();

        try {
            Integer level = null;
            BigDecimal days = null;

            if (StringUtils.isNotEmpty(levelStr)) {
                level = Integer.valueOf(levelStr);
            }

            if (StringUtils.isNotEmpty(daysStr)) {
                days = new BigDecimal(daysStr);
            }

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("人员不存在");
            }
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());


            List<PersonPopedom> dataList = personPopedomService.findApprovalList(personInfo,type, level, days);





            Map<String, Object> map = new HashMap<>();
            map.put("data", dataList);
            map.put("workOverTime",personPopedom.getWorkOverTime());
            msgResult.setData(map);
            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }


    @ApiOperation(value = "考勤申请记录详情")
    @RequestMapping(value = "detailPatchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "考勤申请id", required = true, paramType = "form"),
    })
    public MessageResult<WorkAttendanceDTO> detailPatchCard(@RequestParam("id") String id,
                                                            @RequestAttribute String subject, String token) {
        MessageResult<WorkAttendanceDTO> msgResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("人员不存在");
            }
            PersonPopedom personPopedom0 = personPopedomService.get(personInfo.getPopedom());

            FillAttendance fillAttendance = fillAttendanceService.get(id);
            if (fillAttendance == null) {
                throw new Exception("记录不存在");
            }
            FillAttendanceFiles fillAttendanceFiles = fillAttendanceFilesService.findByFillAttendanceId(fillAttendance.getId());

            PersonInfo approvalPerson = null;
            if (fillAttendance.getApprovalPersonId() != null) {
                approvalPerson = personInfoService.get(fillAttendance.getApprovalPersonId());
            }

            PersonInfo workerPerson = personInfoService.get(fillAttendance.getPersonId());

            WorkAttendanceDTO workAttendanceDTO = new WorkAttendanceDTO();
            BeanUtils.copyProperties(fillAttendance, workAttendanceDTO);
            workAttendanceDTO.setFillAttendanceDayAndTime(fillAttendance.getFillDay() + " " + fillAttendance.getFillAttendanceTime());
            workAttendanceDTO.setPersonName(workerPerson.getName());
            workAttendanceDTO.setFaceImageUrl(workerPerson.getFaceImageUrl());
            if (approvalPerson != null) {
                workAttendanceDTO.setApprovalPersonName(approvalPerson.getName());
            } else {
                workAttendanceDTO.setApprovalPersonName(fillAttendance.getApprovalContent());
            }

            workAttendanceDTO.setAttendanceTime(fillAttendance.getApprovalTime());
            if (fillAttendance.getType().equals("1")) {
                workAttendanceDTO.setTypeN("外勤打卡");
            } else if (fillAttendance.getType().equals("2")) {
                workAttendanceDTO.setTypeN("补卡");
            }


            workAttendanceDTO.setType(fillAttendance.getType());
            workAttendanceDTO.setCompanyName(workerPerson.getCompanyName());

            if (fillAttendanceFiles != null) {
                workAttendanceDTO.setFillAttendanceFilesUrl(fillAttendanceFiles.getFileUrl() == null ? "" : fillAttendanceFiles.getFileUrl());
            } else {
                workAttendanceDTO.setFillAttendanceFilesUrl("");
            }


            //审核人
            PersonPopedom personPopedom = personPopedomService.get(fillAttendance.getApprovalPersonPopedomId());

            PersonInfo approved = null;
            if (personPopedom ==null){
                approved = personInfoService.get(fillAttendance.getApprovalPersonId());
            }else {
                approved = personInfoService.get(personPopedom.getPersonId());
            }

           /* requestForLeaveDetailDto.setApprovedName(approved.getName());
            requestForLeaveDetailDto.setApprovalOpinions(requestForLeaveInfo.getApprovalOpinions());
            requestForLeaveDetailDto.setApprovalExplain(requestForLeaveInfo.getApprovalExplain());

            if(requestForLeaveInfo.getApprovedTime()!=null) {
                String approvedTime = sdf.format(requestForLeaveInfo.getApprovedTime());
                requestForLeaveDetailDto.setApprovedTime(approvedTime);
            }*/



            //审批人
            List<String> personPopedomList = null;
            if (org.apache.commons.lang3.StringUtils.isNotBlank(fillAttendance.getApprovalPersonIdStr())) {
                personPopedomList = Arrays.asList(fillAttendance.getApprovalPersonIdStr().split(","));
            }
            //审批时间
            List<String> approvalTimeList = null;
            if (org.apache.commons.lang3.StringUtils.isNotBlank(fillAttendance.getApprovalTimeStr())) {
                approvalTimeList = Arrays.asList(fillAttendance.getApprovalTimeStr().split(","));
            }

            //审批内容
            List<String> approvalContentList = null;
            if (org.apache.commons.lang3.StringUtils.isNotBlank(fillAttendance.getApprovalContentStr())) {
                approvalContentList = Arrays.asList(fillAttendance.getApprovalContentStr().split(","));
            }

            //审批状态
            List<String> statusList = null;
            if (org.apache.commons.lang3.StringUtils.isNotBlank(fillAttendance.getApprovalStatusStr())) {
                statusList = Arrays.asList(fillAttendance.getApprovalStatusStr().split(","));
            }


            List<ApprovalDTO> approvalDTOList = new ArrayList<>();


            if (personPopedomList != null && personPopedomList.size() != 0) {
                Integer n = personPopedomList.size();

                for (int i = 0; i < n; i++) {
                    ApprovalDTO approvalDTO = new ApprovalDTO();

                    //审核人
                    PersonPopedom personPopedom1 = personPopedomService.get(personPopedomList.get(i));

                    if (personPopedom1 != null) {


                        PersonInfo personInfo1 = personInfoService.get(personPopedom1.getPersonId());
                        approvalDTO.setName(personInfo1.getName());
                        approvalDTO.setFaceImageUrl(personInfo1.getFaceImageUrl());
                        approvalDTO.setStatus(statusList.get(i));
                        if ("0".equals(statusList.get(i))) {
                            approvalDTO.setStatusN("待审核");
                        }
                        if ("1".equals(statusList.get(i))) {
                            approvalDTO.setStatusN("同意");
                            if (approvalTimeList != null) {
                                approvalDTO.setApprovalContent(approvalContentList.get(i));
                                approvalDTO.setTime(approvalTimeList.get(i));
                            }
                        }
                        if ("2".equals(statusList.get(i))) {
                            approvalDTO.setStatusN("拒绝");
                            if (approvalTimeList != null) {
                                approvalDTO.setApprovalContent(approvalContentList.get(i));
                                approvalDTO.setTime(approvalTimeList.get(i));
                            }
                        }
                        approvalDTOList.add(approvalDTO);

                    }
                }
            }

            ApprovalDTO approvalDTO0 = new ApprovalDTO();

            if (approved != null) {
                approvalDTO0.setName(approved.getName());
                approvalDTO0.setFaceImageUrl(approved.getFaceImageUrl());
            }

            if (fillAttendance.getApprovalTime() != null) {
                approvalDTO0.setTime(DateUtil.format(fillAttendance.getApprovalTime(), "yyyy-MM-dd HH:mm"));
            }
            approvalDTO0.setStatus(fillAttendance.getStatus());
            approvalDTO0.setStatusN(fillAttendance.getStatusName());
            approvalDTO0.setApprovalContent(fillAttendance.getApprovalContent());
            approvalDTOList.add(approvalDTO0);


            workAttendanceDTO.setList(approvalDTOList);


            boolean approvalEnable = false;
            if (personPopedom0.getId().equals(fillAttendance.getApprovalPersonPopedomId())) {
                approvalEnable = true;
            }
            workAttendanceDTO.setApprovalEnable(approvalEnable);

            msgResult.setData(workAttendanceDTO);


            msgResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }

    @ApiOperation(value = "考勤申请记录审核")
    @RequestMapping(value = "approvalPatchCard", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "ids", value = "考勤申请ids", required = true, paramType = "form"),
            @ApiImplicitParam(name = "content", value = "审核意见", required = false, paramType = "form"),
            @ApiImplicitParam(name = "status", value = "通过/拒绝（1/2）", required = true, paramType = "form")
    })
    public MessageResult<WorkAttendanceDTO> approvalPatchCard(@RequestParam("ids") String ids, String content, @RequestParam("status") String status,
                                                              @RequestAttribute String subject, String token) {
        MessageResult<WorkAttendanceDTO> msgResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
            if (personInfo == null) {
                throw new Exception("人员不存在");
            }
            if (StringUtils.isBlank(ids)) {
                throw new Exception("请选择要处理的记录");
            }

            if (StringUtils.isNotBlank(content)){
                content = StrUtil.replace(content,",","，");
            }

            fillAttendanceService.approvalFillAttendance(personInfo,ids,content,status);
           /* List<String> idList = Arrays.asList(ids.split(","));
            for (String id : idList) {
                FillAttendance fillAttendance = fillAttendanceService.get(id);

                if (fillAttendance != null) {
                    if ("2".equals(status)) {
                        fillAttendance.setStatus(status);
                        fillAttendance.setUpdateTime(new Date());
                        fillAttendance.setUpdateBy(personInfo.getName());
                        fillAttendance.setApprovalTime(new Date());
                        fillAttendance.setApprovalContent(content);
                        fillAttendanceService.update(fillAttendance);
                    } else {
                        fillAttendanceService.updateAndWorkAtten(personInfo, content, fillAttendance);
                    }
                }
            }*/

            msgResult.setResult(true);
            msgResult.setMessage("成功");
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            msgResult.setResult(false);
            msgResult.setMessage(ex.getMessage());
        }

        return msgResult;
    }

    @GetMapping("findAttendancePeriod")
    @ApiOperation(value = "根据日期查询考勤时段")
    public MessageResult<List> findAttendancePeriod(@RequestAttribute String subject, @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate) {
        MessageResult<List> messageResult = new MessageResult<>();

        DateTime recordTime = new DateTime(queryDate);
        String date = recordTime.toString("yyyy-MM-dd");

        Date startDate = recordTime.minusDays(7).toDate();
        Date endDate = recordTime.plusDays(1).toDate();

        Long personId = Long.valueOf(subject);

        int weekday = recordTime.getDayOfWeek();

        try {
            PersonInfo personInfo = personInfoService.get(personId);
            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());

            //放假日期
            Set<String> realHolidaySet = holidayInfoService.getHolidaySetByDate(companyInfo.getCode(), startDate, endDate, false);

            //虽然放假但正常上班
            Map<String, HolidayInfo> fakeHolidayMap = holidayInfoService.getHolidayMapByDate(companyInfo.getCode(),startDate, endDate, true);

            String[] arr = companyInfo.getCode().split(",");

            List<AlarmConfig> configList = null;

            //查询当前用户的考勤设置
            for (int i = arr.length - 1; i >= 0; i--) {
                configList = alarmConfigService.findByCompanyId(arr[i]);

                if (configList != null && configList.size() > 0) {
                    break;
                }
            }

            if (fakeHolidayMap.containsKey(date)) {
                //虽然放假但需要工作
                HolidayInfo holidayInfo = fakeHolidayMap.get(date);

                //参考工作日
                weekday = holidayInfo.getRefWeekday();
            }

            List<Map> mapList = new ArrayList<>();

            if (configList != null) {
                for (AlarmConfig alarmConfig : configList) {
                    //考勤设置中包含有当前工作日
                    if (alarmConfig.getWeekdays().indexOf(String.valueOf(weekday)) != -1) {
                        Map<String, Object> map = new HashMap<>();

                        map.put("alarmConfigId", alarmConfig.getId());

                        String attendanceTypeN = alarmConfig.getAttendanceType() == AttendanceTypes.IN ? "内勤" : "外勤";

                        if (alarmConfig.getClassifier().equals(1)) {
                            //上班考勤
                            map.put("timeRange", attendanceTypeN + "上班：" + alarmConfig.getStartTime() + "-" + alarmConfig.getAttendanceTime());
                        } else {
                            //下班考勤
                            map.put("timeRange", attendanceTypeN + "下班：" + alarmConfig.getAttendanceTime() + "-" + alarmConfig.getEndTime());
                        }

                        mapList.add(map);
                    }
                }
            }

            //todo 填写具体代码
            messageResult.setData(mapList);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("workAttendanceStat")
    @ApiOperation(value = "考勤统计")
    public MessageResult<Map> workAttendanceStat(@RequestAttribute String subject, String token,
                                                 @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate,
                                                 String alarmConfigId) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            Long personId = Long.valueOf(subject);

            PersonInfo personInfo = personInfoService.get(personId);

            List<CompanyInfo> companyList = new ArrayList<>();

            companyList.add(companyInfoService.get(personInfo.getCompanyId()));

            List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(personInfo.getId());

            for (PersonCompany personCompany : personCompanyList) {
                CompanyInfo relatedCompany = companyInfoService.get(personCompany.getCompanyId());

                if (relatedCompany != null) {
                    companyList.add(relatedCompany);
                }
            }

            List<Map> groupList = new ArrayList<>();

            int workCount = 0;
            int absentCount = 0;

            for (CompanyInfo companyInfo : companyList) {
                Map<String, Object> group = new HashMap<>();

                group.put("companyName", companyInfo.getName());
                group.put("companyId", companyInfo.getId());

                List<Map> mapList = new ArrayList<>();

                //    List<PersonInfo> personList = personInfoService.findByCompanyId(companyInfo.getId());

                Map<String, Object> searchParams = new HashMap<>();
                searchParams.put("companyId", companyInfo.getId());
                List<Sort> sortList = new ArrayList<>();
                sortList.add(new Sort("create_time", "desc"));
                Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams, 1, 10, true, sortList);

                List<PersonInfo> personList = personInfoPage.getResult();

                for (PersonInfo person : personList) {
                    Map<String, Object> personMap = new HashMap<>();

                    personMap.put("name", person.getName());

                    WorkAttendance workAttendance = workAttendanceService.findByPersonIdAndPeriod(person.getId(), queryDate, alarmConfigId);

                    if (workAttendance != null) {
                        if ("0".equals(workAttendance.getResult())) {
                            absentCount++;
                        } else {
                            workCount++;
                        }

                        personMap.put("result", workAttendance.getResultN());
                        personMap.put("remark", workAttendance.getRemark());

                        //type:0=设备打卡，1=异地打卡、2=补卡
                        personMap.put("type", "1".equals(workAttendance.getSources()) ? "0" : workAttendance.getType());

                        personMap.put("personDeviceLogId", null);
                        personMap.put("fillAttendanceId", null);

                        if ("1".equals(workAttendance.getSources())) {
                            //查询测温记录(考勤前后一分钟)
                            DateTime recordTime = new DateTime(workAttendance.getRecordTime());

                            Date startDate = recordTime.minusMinutes(-1).toDate();
                            Date endDate = recordTime.plusMinutes(1).toDate();

                            List<PersonDeviceLog> personDeviceLogs = personDeviceLogService.findByPersonAndDate(person.getId(), startDate, endDate);

                            if (personDeviceLogs.size() > 0) {
                                personMap.put("personDeviceLogId", personDeviceLogs.get(0).getId());
                            }
                        } else {
                            FillAttendance fillAttendance = fillAttendanceService.findByBusinessWorkAttendanceId(workAttendance.getId());

                            if (fillAttendance != null) {
                                personMap.put("fillAttendanceId", fillAttendance.getId());
                            }
                        }
                    }

                    mapList.add(personMap);
                }

                group.put("personList", mapList);
                group.put("totalPage", personInfoPage.getPages());
                group.put("pageNumber", personInfoPage.getPageNum());
                group.put("pageSize", personInfoPage.getPageSize());


                groupList.add(group);
            }

            dataMap.put("groupList", groupList);

            //已打卡、缺卡人数统计
            dataMap.put("workCount", workCount);
            dataMap.put("absentCount", absentCount);

            //todo 填写具体代码
            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("workAttendanceStatByCompanyId")
    @ApiOperation(value = "考勤统计（按公司）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "queryDate", value = "时间", required = true, paramType = "form"),
            @ApiImplicitParam(name = "alarmConfigId", value = "考勤时间段", required = false, paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "form")
    })
    public MessageResult<Map> workAttendanceStatByCompanyId(@RequestAttribute String subject, String token, @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate, String alarmConfigId, String companyId) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            Long personId = Long.valueOf(subject);

            PersonInfo personInfo = personInfoService.get(personId);

            List<CompanyInfo> companyList = new ArrayList<>();


            List<Map> groupList = new ArrayList<>();

            //正常
            int workCount = 0;
            //缺卡
            int absentCount = 0;
            //迟到
            int lateCount = 0;
            //早退
            int leaveEarlyCount = 0;
            if (StringUtils.isNotBlank(companyId)) {


                CompanyInfo companyInfo0 = companyInfoService.get(companyId);
                if (companyInfo0 != null) {
                    companyList.add(companyInfo0);
                }


                for (CompanyInfo companyInfo : companyList) {
                    Map<String, Object> group = new HashMap<>();

                    group.put("companyName", companyInfo.getName());

                    List<Map> mapList = new ArrayList<>();

                    //    List<PersonInfo> personList = personInfoService.findByCompanyId(companyInfo.getId());

                    //  Map<String, Object> searchParams = new HashMap<>();
                    //   searchParams.put("companyId", companyInfo.getId());
                    //   List<Sort> sortList = new ArrayList<>();
                    //   sortList.add(new Sort("create_time", "desc"));
                    //   Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
                    //   List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyId(companyInfo.getId());
                    List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode("%" + companyInfo.getId() + "%");
                    List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyList(companyInfoList);

                    //   List<PersonInfo> personList = personInfoPage.getResult();

                    List<PersonInfo> personInfoList = new ArrayList<>();
                    for (PersonPopedom personPopedom : personPopedomList) {
                        PersonInfo person = personInfoService.get(personPopedom.getPersonId());
                        if (person != null && !personInfoList.contains(person)) {

                            personInfoList.add(person);

                            Map<String, Object> personMap = new HashMap<>();

                            personMap.put("name", person.getName());
                            personMap.put("workStatus", person.getWorkStatus());
                            personMap.put("workStatusN", person.getWorkStatusN());
                            String statusId = "";
                            if ("2".equals(person.getWorkStatus()) || "3".equals(person.getWorkStatus())) {
                                List<BusinessOut> businessOutList = businessOutService.findByPersonPopedomAndEndTimeIsNull(personPopedom.getId());
                                if (businessOutList.size() > 0) {
                                    statusId = businessOutList.get(0).getId();
                                }
                            }
                            if ("4".equals(person.getWorkStatus())) {
                                List<RequestForLeaveInfo> requestForLeaveInfoList = requestForLeaveInfoService.findByPersonAndStatus(person.getId(), "1");
                                if (requestForLeaveInfoList.size() > 0) {
                                    statusId = requestForLeaveInfoList.get(0).getId();
                                }
                            }

                            personMap.put("statusId", statusId);


                            WorkAttendance workAttendance = workAttendanceService.findByPersonIdAndPeriod(person.getId(), queryDate, alarmConfigId);

                            if (workAttendance != null) {
                                if ("0".equals(workAttendance.getResult())) {
                                    absentCount++;
                                }
                                if ("1".equals(workAttendance.getResult())) {
                                    workCount++;
                                }
                                if ("2".equals(workAttendance.getResult())) {
                                    lateCount++;
                                }
                                if ("3".equals(workAttendance.getResult())) {
                                    leaveEarlyCount++;
                                }

                                personMap.put("result", workAttendance.getResult());
                                personMap.put("resultN", workAttendance.getResultN());
                                personMap.put("remark", workAttendance.getRemark());

                                Date workTime = null;
                                if (!"0".equals(workAttendance.getResult())) {
                                    workTime = workAttendance.getRecordTime();
                                }
                                personMap.put("workTime", DateUtil.format(workTime, "HH:mm"));

                                //type:0=设备打卡，1=异地打卡、2=补卡
                                personMap.put("type", "1".equals(workAttendance.getSources()) ? "0" : workAttendance.getType());

                                personMap.put("personDeviceLogId", null);
                                personMap.put("fillAttendanceId", null);

                                if ("1".equals(workAttendance.getSources())) {
                                    //查询测温记录(考勤前后一分钟)
                                    DateTime recordTime = new DateTime(workAttendance.getRecordTime());

                                    Date startDate = recordTime.minusMinutes(-1).toDate();
                                    Date endDate = recordTime.plusMinutes(1).toDate();

                                    List<PersonDeviceLog> personDeviceLogs = personDeviceLogService.findByPersonAndDate(person.getId(), startDate, endDate);

                                    if (personDeviceLogs.size() > 0) {
                                        personMap.put("personDeviceLogId", personDeviceLogs.get(0).getId());
                                    }
                                } else {
                                    FillAttendance fillAttendance = fillAttendanceService.findByBusinessWorkAttendanceId(workAttendance.getId());

                                    if (fillAttendance != null) {
                                        personMap.put("fillAttendanceId", fillAttendance.getId());
                                    }
                                }
                                mapList.add(personMap);
                            }


                        }
                    }

                    group.put("personList", mapList);
                    /*group.put("totalPage", personInfoPage.getPages());
                    group.put("pageNumber", personInfoPage.getPageNum());
                    group.put("pageSize", personInfoPage.getPageSize());*/


                    groupList.add(group);
                }

            }

            dataMap.put("groupList", groupList);
            //已打卡、缺卡人数统计
            dataMap.put("workCount", workCount);
            dataMap.put("absentCount", absentCount);
            dataMap.put("lateCount", lateCount);
            dataMap.put("leaveEarlyCount", leaveEarlyCount);

            //todo 填写具体代码
            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("workAttendanceStatByCompanyIdAndDate")
    @ApiOperation(value = "考勤统计（按公司和日期）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "queryDate", value = "时间", required = true, paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "resultN", value = "考勤状态（0-缺卡，1-正常，2-迟到，3-早退，4-出差，5-休假，6-外出）", required = false, paramType = "form")
    })
    public MessageResult<Map> workAttendanceStatByCompanyIdAndDate(@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                                                   @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
                                                                   @RequestAttribute String subject, String token,
                                                                   @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate,
                                                                   String companyId,
                                                                   String resultN) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();
            Long personId = Long.valueOf(subject);

            List<Map> groupList = new ArrayList<>();

            //正常
            int workCount = 0;
            //缺卡
            int absentCount = 0;
            //迟到
            int lateCount = 0;
            //早退
            int leaveEarlyCount = 0;
            //出差
            int businessCount = 0;
            //休假
            int vacationCount = 0;
            //外出
            int outCount = 0;

            List<Map> mapList = new ArrayList<>();

            if (StringUtils.isNotBlank(resultN)){
                pageSize = 500;
            }

            if (StringUtils.isNotBlank(companyId)) {
                CompanyInfo companyInfo = companyInfoService.get(companyId);
                Map<String, Object> group = new HashMap<>();
                group.put("companyName", companyInfo.getName());

                List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode("%" + companyInfo.getId() + "%");
                List<String> companyIdList = new ArrayList<>();

                if (companyInfoList.size() > 0) {
                    for (CompanyInfo companyInfo1 : companyInfoList) {
                        companyIdList.add(companyInfo1.getId());
                    }
                }

                Map<String, Object> searchParams = new HashMap<>();
                searchParams.put("companyId", companyId);
                List<Sort> sortList = new ArrayList<>();
                sortList.add(new Sort("a.create_time", "asc"));

//                List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyList(companyInfoList);
                Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);

                for (PersonInfo person : page) {
                    Map<String, Object> personMap = new HashMap<>();

                    PersonPopedom personPopedom = personPopedomService.findOneByPersonId(person.getId());

                    personMap.put("name", person.getName());
                    personMap.put("id", personPopedom.getId());
                    personMap.put("workStatus", person.getWorkStatus());
                    personMap.put("workStatusN", person.getWorkStatusN());

                    String statusId = "";
                    if ("2".equals(person.getWorkStatus()) || "3".equals(person.getWorkStatus())) {
                        List<BusinessOut> businessOutList = businessOutService.findByPersonPopedomAndEndTimeIsNull(personPopedom.getId());

                        if (businessOutList.size() > 0) {
                            statusId = businessOutList.get(0).getId();
                        }
                    }
                    if ("4".equals(person.getWorkStatus())) {
                        List<RequestForLeaveInfo> requestForLeaveInfoList = requestForLeaveInfoService.findByPersonAndStatus(person.getId(), "1");

                        if (requestForLeaveInfoList.size() > 0) {
                            statusId = requestForLeaveInfoList.get(0).getId();
                        }
                    }

                    personMap.put("statusId", statusId);

                    if ("3".equals(person.getWorkStatus())) {
                        businessCount++;
                    }
                    if ("4".equals(person.getWorkStatus())) {
                        vacationCount++;
                    }
                    if ("2".equals(person.getWorkStatus())) {
                        outCount++;
                    }


                //    List<WorkScheduleAttendance> workAttendanceList = new ArrayList<>();
                    String resultN1 = "0,1,2,3";
                    String tempResultN = resultN;
                    String workStatus0 = "1";
                    if (!resultN1.contains(resultN)){
                        if ("4".equals(resultN)) {
                            workStatus0 = "3";
                            tempResultN = null;
                        }
                        if ("5".equals(resultN)) {
                            workStatus0 = "4";
                            tempResultN = null;
                        }
                    }


                    List<WorkScheduleAttendance> workAttendanceList = workScheduleAttendanceService.findByPersonIdAndDate(person.getId(), DateUtil.beginOfDay(queryDate), DateUtil.endOfDay(queryDate),tempResultN,workStatus0);

                    // WorkAttendance workAttendance = workAttendanceService.findByPersonIdAndPeriod(person.getId(), queryDate, alarmConfigId);
                    List<Map> dateList = new ArrayList<>();
                    if (workAttendanceList.size() > 0) {
                        for (WorkScheduleAttendance workAttendance : workAttendanceList) {
                            Map<String, Object> data = new HashMap<>();
                            String time = DateUtil.format(workAttendance.getRecordTime(), "HH:mm");
                            String remark = null;
                            String workStatus = workAttendance.getWorkStatus();

                            //0：无操作， 1:机器打卡记录，2：请假审批详情，3：外勤打卡、补卡审批详情
                            String status = null;
                            String id = workAttendance.getId();
                            String result = null;

                            //工作状态：工作
                            if ("1".equals(workAttendance.getWorkStatus())) {
                                //缺卡
                                if ("0".equals(workAttendance.getResult())) {
                                    absentCount++;
                                    remark = "缺卡";
                                    status = "0";
                                    //   workStatus = "0";
                                    result = "0";
                                }

                                //有考勤，要区分是机器打卡还是填报打卡
                                if (!"0".equals(workAttendance.getResult())) {
                                    //机器打卡
//                                    if (StringUtils.isBlank(workAttendance.getType())) {
                                        remark = "正常";
                                        status = "1";
//                                    }
//                                    //填报打卡
//                                    else {
//                                        remark = "正常";
//                                        status = "3";
//                                    }
                                    //考勤正常
                                    if ("1".equals(workAttendance.getResult())) {
                                        workCount++;
                                        result = "1";
                                    }
                                    //迟到
                                    if ("2".equals(workAttendance.getResult())) {
                                        lateCount++;
                                        remark = "迟到";
                                        result = "2";
                                    }
                                    //早退
                                    if ("3".equals(workAttendance.getResult())) {
                                        leaveEarlyCount++;
                                        remark = "早退";
                                        result = "3";
                                    }
                                }
                            }

                            //工作状态：请假
                            if ("4".equals(workAttendance.getWorkStatus())) {
                                remark = "请假";
                                status = "2";
                                result = "5";
                            }

                            if ("3".equals(workAttendance.getWorkStatus())){
                                remark = "出差";
                                status = "0";
                                result = "4";
                            }

                            data.put("time", time);
                            data.put("remark", remark);
                            data.put("status", status);
                            data.put("workStatus", workStatus);
                            data.put("result", result);
                            data.put("id", id);

                            if (StringUtils.isBlank(resultN)) {
                                if (!dateList.contains(data)) {
                                    dateList.add(data);
                                }
                            } else {
                                if (resultN.equals(data.get("result"))) {
                                    if (!dateList.contains(data)) {
                                        dateList.add(data);
                                    }
                                }
                                if ("4".equals(resultN) || "5".equals(resultN) || "6".equals(resultN)) {
                                    if (!dateList.contains(data)) {
                                        dateList.add(data);
                                    }
                                }
                            }
                        }
                        if (StringUtils.isNotBlank(resultN)){
                            personMap.put("list", dateList);
                            mapList.add(personMap);
                        }

                    }
                    if (StringUtils.isBlank(resultN)){
                        personMap.put("list", dateList);
                        mapList.add(personMap);
                    }

                    /*if (StringUtils.isBlank(resultN)) {
                        personMap.put("list", dateList);
                        mapList.add(personMap);
                    } else {

                        if (!"4".equals(resultN) && !"5".equals(resultN) && !"6".equals(resultN)) {
                            if (dateList.size() != 0) {
                                personMap.put("list", dateList);
                                mapList.add(personMap);
                            }
                        } else {
                            String temp = null;
                            if ("4".equals(resultN)) {
                                temp = "3";
                            }
                            if ("5".equals(resultN)) {
                                temp = "4";
                            }
                            if ("6".equals(resultN)) {
                                temp = "2";
                            }
                            if (temp.equals(personMap.get("workStatus"))) {
                                personMap.put("list", dateList);
                                mapList.add(personMap);
                            }
                        }
                    }*/
                }

                group.put("personList", mapList);
                group.put("pageNumber", pageIndex);
                group.put("pageSize", pageSize);
                group.put("totalPage", page.getPages());

                groupList.add(group);
            }

            dataMap.put("groupList", groupList);
            //已打卡、缺卡人数统计
            dataMap.put("workCount", workCount);
            dataMap.put("absentCount", absentCount);
            dataMap.put("lateCount", lateCount);
            dataMap.put("leaveEarlyCount", leaveEarlyCount);
            dataMap.put("businessCount", businessCount);
            dataMap.put("vacationCount", vacationCount);
            dataMap.put("outCount", outCount);

            //todo 填写具体代码
            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }


    @PostMapping("xsyWorkAttendanceStatNumByCompanyIdAndDate")
    @ApiOperation(value = "考勤统计数字（按公司和日期,新生源）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "queryDate", value = "时间", required = true, paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "form")

    })
    public MessageResult<Map> xsyWorkAttendanceStatNumByCompanyIdAndDate(@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                                                   @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, @RequestAttribute String subject, String token, @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate,String companyId) {

        MessageResult<Map> messageResult = new MessageResult<>();

        try {

            PersonInfo personInfo = personInfoService.get(Long.parseLong(subject));
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());

            CompanyInfo companyInfo = companyInfoService.get(companyId);

            //正常
            int workCount = 0;
            //缺卡
            int absentCount = 0;
            //迟到
            int lateCount = 0;
            //早退
            int leaveEarlyCount = 0;
            //出差
            int businessCount = 0;
            //休假
            int vacationCount = 0;
            //外出
         //   int outCount = 0;


       //     List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode(companyInfo.getCode());
            Map<String, Object> searchParams = new HashMap<>();
            searchParams.put("code", "%"+companyInfo.getCode() +"%");
            List<Sort> sortList = new ArrayList<>();
            sortList.add(new Sort("id_","asc"));

            List<PersonInfo> personInfoList = personInfoService.findByCompanyCode(searchParams,sortList);

            Map<String, Object> searchParams1 = new HashMap<>();
            searchParams1.put("personInfoList", personInfoList);
            searchParams1.put("attendanceDate",DateUtil.format(queryDate,"yyyy-MM-dd"));
        //    searchParams1.put("result","0");
            List<Sort> sortList1 = new ArrayList<>();
            sortList1.add(new Sort("id_","asc"));

            //缺卡
            searchParams1.put("result","0");
            searchParams1.put("workStatus","1");
            List<WorkScheduleAttendance> workScheduleAttendanceList = workScheduleAttendanceService.numListSearch(searchParams1,sortList1);
            absentCount = workScheduleAttendanceList.size();
            //正常
            searchParams1.put("result","1");
            List<WorkScheduleAttendance> workScheduleAttendanceList1 = workScheduleAttendanceService.numListSearch(searchParams1,sortList1);
            workCount = workScheduleAttendanceList1.size();
            //迟到
            searchParams1.put("result","2");
            List<WorkScheduleAttendance> workScheduleAttendanceList2 = workScheduleAttendanceService.numListSearch(searchParams1,sortList1);
            lateCount = workScheduleAttendanceList2.size();
            //早退
            searchParams1.put("result","3");
            List<WorkScheduleAttendance> workScheduleAttendanceList3 = workScheduleAttendanceService.numListSearch(searchParams1,sortList1);
            leaveEarlyCount = workScheduleAttendanceList3.size();


            //出差
            Map<String, Object> searchParams2 = new HashMap<>();
            searchParams2.put("personInfoList", personInfoList);
            searchParams2.put("requestStartTime",DateUtil.beginOfDay(queryDate));
            searchParams2.put("requestEndTime",DateUtil.endOfDay(queryDate));
            searchParams2.put("status","1");
            List<Sort> sortList2 = new ArrayList<>();
            sortList2.add(new Sort("a.create_time","desc"));
            List<BusinessOut> businessOutList = businessOutService.listSearch(searchParams2,sortList2);
            businessCount = businessOutList.size();

            //请假
            Map<String, Object> searchParams3 = new HashMap<>();
            searchParams3.put("personInfoList", personInfoList);
            searchParams3.put("startTime",DateUtil.format(queryDate,"yyyy-MM-dd HH:mm:ss"));
            searchParams3.put("endTime",DateUtil.format(queryDate,"yyyy-MM-dd HH:mm:ss"));
            searchParams3.put("status","1");
            List<Sort> sortList3 = new ArrayList<>();
            sortList3.add(new Sort("create_time","desc"));
            List<RequestForLeaveInfo> requestForLeaveInfoList = requestForLeaveInfoService.listSearch(searchParams3,sortList3);
            vacationCount = requestForLeaveInfoList.size();


            Map<String, Object> dataMap = new HashMap<>();
            //已打卡、缺卡人数统计
            dataMap.put("workCount", workCount);
            dataMap.put("absentCount", absentCount);
            dataMap.put("lateCount", lateCount);
            dataMap.put("leaveEarlyCount", leaveEarlyCount);
            dataMap.put("businessCount", businessCount);
            dataMap.put("vacationCount", vacationCount);
         //   dataMap.put("outCount", outCount);

            messageResult.setCode(200);
            messageResult.setData(dataMap);
            messageResult.setResult(true);



        }catch (Exception ex){
            log.error(ex.getMessage(),ex);
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);
        }

        return messageResult;


    }



    @GetMapping("workAttendanceStatCompanyList")
    @ApiOperation(value = "考勤统计的关联公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = false, paramType = "form"),
            @ApiImplicitParam(name = "alarmConfigId", value = "考勤时间段", required = false, paramType = "form"),
            @ApiImplicitParam(name = "queryDate", value = "时间", required = false, paramType = "form")
    })
    public MessageResult<Map> workAttendanceStatCompanyList(@RequestAttribute String subject, String token, String companyId, String alarmConfigId, @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            Long personId = Long.valueOf(subject);

            PersonInfo personInfo = personInfoService.get(personId);
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());
            CompanyInfo companyInfo = companyInfoService.get(personPopedom.getCompanyId());

            List<CompanyInfo> list = new ArrayList<>();
            List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(personInfo.getId());

            if (StringUtils.isBlank(companyId)) {
                if (personCompanyList.size() == 0) {

                    list.add(companyInfo);
                } else {
                    for (PersonCompany personCompany : personCompanyList) {
                        CompanyInfo companyInfo1 = companyInfoService.get(personCompany.getCompanyId());
                        if (companyInfo1 != null && !list.contains(companyInfo1)) {
                            list.add(companyInfo1);
                        }
                    }
                }
            } else {
                List<CompanyInfo> companyInfos = companyInfoService.findByParentId(companyId);
                list.addAll(companyInfos);
            }


            List<WorkAttendanceCompanyDTO> workList = new ArrayList<>();
            for (CompanyInfo companyInfo2 : list) {
                //  List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyId(companyInfo2.getId());
//                List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode("%" + companyInfo2.getId() + "%");
                //  Integer num = personPopedomService.findNumByCompanyList(companyInfoList);
//                List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyList(companyInfoList);
//                Integer num = personPopedomList.size();

//                List<PersonInfo> personInfoList = new ArrayList<>();
//                Integer subNum = 0;
//                for (PersonPopedom personPopedom0 : personPopedomList) {
//                    if (!personPopedom0.getEnableAttendance()) {
//                        subNum++;
//                    }
//                }
                Long num = personInfoService.countByCompanyId(companyInfo2.getId());

                List<CompanyInfo> companyInfos = companyInfoService.findByParentId(companyInfo2.getId());
                WorkAttendanceCompanyDTO workAttendanceCompanyDTO = new WorkAttendanceCompanyDTO();
                workAttendanceCompanyDTO.setId(companyInfo2.getId());
                workAttendanceCompanyDTO.setName(companyInfo2.getName());
                workAttendanceCompanyDTO.setNumber(num.intValue());

                if (companyInfos.size() > 0) {
                    workAttendanceCompanyDTO.setHasNext(true);
                } else {
                    workAttendanceCompanyDTO.setHasNext(false);
                }
                workList.add(workAttendanceCompanyDTO);
            }


            dataMap.put("list", workList);
            messageResult.setData(dataMap);
            messageResult.setResult(true);
            messageResult.setCode(200);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("structureCompanyList")
    @ApiOperation(value = "组织架构的关联公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = false, paramType = "form")
    })
    public MessageResult<Map> structureCompanyList(@RequestAttribute String subject, String token, String companyId) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            Long personId = Long.valueOf(subject);

            PersonInfo personInfo = personInfoService.get(personId);
            PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());
            CompanyInfo companyInfo = companyInfoService.get(personPopedom.getCompanyId());

            List<CompanyInfo> list = new ArrayList<>();
            List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(personInfo.getId());

            if (StringUtils.isBlank(companyId)) {
                if (personCompanyList.size() == 0) {

                    list.add(companyInfo);
                } else {
                    for (PersonCompany personCompany : personCompanyList) {
                        CompanyInfo companyInfo1 = companyInfoService.get(personCompany.getCompanyId());
                        if (companyInfo1 != null && !list.contains(companyInfo1)) {
                            list.add(companyInfo1);
                        }
                    }
                }
            } else {
                List<CompanyInfo> companyInfos = companyInfoService.findByParentId(companyId);
                list.addAll(companyInfos);
            }


            List<WorkAttendanceCompanyDTO> workList = new ArrayList<>();
            List<PersonInfo> personList = new ArrayList<>();
            for (CompanyInfo companyInfo2 : list) {
                //  List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyId(companyInfo2.getId());
                List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode("%" + companyInfo2.getId() + "%");
                Integer num = personPopedomService.findNumByCompanyList(companyInfoList);
                List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyList(companyInfoList);


                List<PersonInfo> personInfoList = new ArrayList<>();
                //    Integer subNum = 0;
                for (PersonPopedom personPopedom0 : personPopedomList) {
                    PersonInfo person = personInfoService.get(personPopedom0.getPersonId());
                    if (person != null && !personInfoList.contains(person)) {
                        personInfoList.add(person);
                       /* WorkAttendance workAttendance = workAttendanceService.findByPersonIdAndPeriod(person.getId(), queryDate, alarmConfigId);

                        if (workAttendance == null) {
                            subNum++;
                        }*/
                    }
                }


                List<CompanyInfo> companyInfos = companyInfoService.findByParentId(companyInfo2.getId());
                WorkAttendanceCompanyDTO workAttendanceCompanyDTO = new WorkAttendanceCompanyDTO();
                workAttendanceCompanyDTO.setId(companyInfo2.getId());
                workAttendanceCompanyDTO.setName(companyInfo2.getName());
                workAttendanceCompanyDTO.setNumber(num);
                if (companyInfos.size() > 0) {
                    workAttendanceCompanyDTO.setHasNext(true);
                } else {
                    workAttendanceCompanyDTO.setHasNext(false);
                }
                workList.add(workAttendanceCompanyDTO);
            }


            dataMap.put("list", workList);
            messageResult.setData(dataMap);
            messageResult.setResult(true);
            messageResult.setCode(200);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("structureByCompanyId")
    @ApiOperation(value = "组织架构（按公司）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "form")
    })
    public MessageResult<Map> structureByCompanyId(@RequestAttribute String subject, String token, String companyId, String name) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            Long personId = Long.valueOf(subject);

            PersonInfo personInfo = personInfoService.get(personId);

            List<CompanyInfo> companyList = new ArrayList<>();


            List<Map> groupList = new ArrayList<>();

            //工作
            int workCount = 0;
            //外出
            int outCount = 0;
            //出差
            int businessCount = 0;
            //休假
            int vacationCount = 0;
            if (StringUtils.isNotBlank(companyId)) {


                CompanyInfo companyInfo0 = companyInfoService.get(companyId);
                if (companyInfo0 != null) {
                    companyList.add(companyInfo0);
                }


                for (CompanyInfo companyInfo : companyList) {
                    Map<String, Object> group = new HashMap<>();

                    group.put("companyName", companyInfo.getName());

                    List<Map> mapList = new ArrayList<>();

                    //    List<PersonInfo> personList = personInfoService.findByCompanyId(companyInfo.getId());

                    //  Map<String, Object> searchParams = new HashMap<>();
                    //   searchParams.put("companyId", companyInfo.getId());
                    //   List<Sort> sortList = new ArrayList<>();
                    //   sortList.add(new Sort("create_time", "desc"));
                    //   Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
                    //   List<PersonPopedom> personPopedomList = personPopedomService.findByCompanyId(companyInfo.getId());
                    List<CompanyInfo> companyInfoList = companyInfoService.findAllCompanyByCode("%" + companyInfo.getId() + "%");

                    List<PersonPopedom> personPopedomList = new ArrayList<>();
                    if (StringUtils.isBlank(name)) {
                        personPopedomList = personPopedomService.findByCompanyList(companyInfoList);
                    } else {
                        personPopedomList = personPopedomService.findByCompanyListAndName(companyInfoList, "%" + name + "%");
                    }


                    //   List<PersonInfo> personList = personInfoPage.getResult();

                    List<PersonInfo> personInfoList = new ArrayList<>();
                    for (PersonPopedom personPopedom : personPopedomList) {
                        PersonInfo person = personInfoService.get(personPopedom.getPersonId());
                        if (person != null && !personInfoList.contains(person)) {

                            personInfoList.add(person);

                            Map<String, Object> personMap = new HashMap<>();

                            personMap.put("id", personPopedom.getId());
                            personMap.put("name", person.getName());
                            personMap.put("workStatus", person.getWorkStatus());
                            personMap.put("workStatusN", person.getWorkStatusN());
                            personMap.put("remark", personPopedom.getRemark());

                            if ("1".equals(person.getWorkStatus())) {
                                workCount++;
                            }
                            if ("2".equals(person.getWorkStatus())) {
                                outCount++;
                            }
                            if ("3".equals(person.getWorkStatus())) {
                                businessCount++;
                            }
                            if ("4".equals(person.getWorkStatus())) {
                                vacationCount++;
                            }


                            mapList.add(personMap);


                        }
                    }

                    //    }

                    group.put("personList", mapList);
                    /*group.put("totalPage", personInfoPage.getPages());
                    group.put("pageNumber", personInfoPage.getPageNum());
                    group.put("pageSize", personInfoPage.getPageSize());*/


                    groupList.add(group);
                }

            }

            dataMap.put("groupList", groupList);
            //已打卡、缺卡人数统计
            dataMap.put("workCount", workCount);
            dataMap.put("outCount", outCount);
            dataMap.put("businessCount", businessCount);
            dataMap.put("vacationCount", vacationCount);

            //todo 填写具体代码
            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("structurePersonDetail")
    @ApiOperation(value = "组织架构个人详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form")
    })
    public MessageResult<Map> structurePersonDetail(@RequestAttribute String subject, String token, String id) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            PersonPopedomDTO personPopedomDTO = new PersonPopedomDTO();
            PersonPopedom personPopedom = personPopedomService.get(id);
            if (personPopedom != null) {
                PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());
                CompanyInfo companyInfo = companyInfoService.get(personPopedom.getCompanyId());
                if (personInfo != null) {
                    personPopedomDTO.setId(id);
                    personPopedomDTO.setPersonName(personInfo.getName());
                    personPopedomDTO.setCompanyName(companyInfo.getName());
                    personPopedomDTO.setFaceImagUrl(personInfo.getFaceImageUrl());
                    personPopedomDTO.setWorkStatus(personInfo.getWorkStatus());
                    personPopedomDTO.setWorkStatusN(personInfo.getWorkStatusN());
                    personPopedomDTO.setTelephone(personInfo.getPhone());
                }
            }


            dataMap.put("personInfo", personPopedomDTO);
            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("updatePersonWorkStatus")
    @ApiOperation(value = "修改个人工作状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "workStatus", value = "工作状态（1：工作，2：外出，3：出差，4：休假）", required = true, paramType = "form")
    })
    public MessageResult<Map> updatePersonWorkStatus(@RequestAttribute String subject, String token, String id, String workStatus) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            Map<String, Object> dataMap = new HashMap<>();

            PersonPopedomDTO personPopedomDTO = new PersonPopedomDTO();
            PersonPopedom personPopedom = personPopedomService.get(id);
            if (personPopedom != null) {
                PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());
                if (personInfo != null) {
                    personInfo.setWorkStatus(workStatus);
                    personInfoService.update(personInfo);


                }
            }

            messageResult.setData(dataMap);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }

    @GetMapping("getBusinessId")
    @ApiOperation(value = "获取业务id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form")
    })
    public MessageResult<Map> getBusinessId(@RequestAttribute String subject, String token, String id) {
        MessageResult<Map> messageResult = new MessageResult<>();

        try {
            //    Map<String, Object> dataMap = new HashMap<>();
            String businessId = null;
            String status = null;
            WorkScheduleAttendance workAttendance = workScheduleAttendanceService.get(id);
            //工作状态：工作
            if (!"4".equals(workAttendance.getWorkStatus())) {

                //有考勤，要区分是机器打卡还是填报打卡
                if (!"0".equals(workAttendance.getResult())) {
                    //机器打卡
//                    if (StringUtils.isBlank(workAttendance.getType())) {
                        //查询机器上的记录
                        PersonDeviceLog personDeviceLog = personDeviceLogService.findByPersonAndRecordTime(workAttendance.getPersonId(), workAttendance.getRecordTime());
                        if (personDeviceLog != null) {
                            businessId = personDeviceLog.getId();
                            status = "1";
                        }
//                    }
                    //填报打卡
//                    else {
//
//                        //查询外勤或补卡记录
//                        FillAttendance fillAttendance = fillAttendanceService.findByBusinessWorkAttendanceId(workAttendance.getId());
//                        if (fillAttendance != null) {
//                            businessId = fillAttendance.getId();
//                            status = "3";
//                        }
//
//                    }
                }
            }

            //工作状态：请假
            if ("4".equals(workAttendance.getWorkStatus())) {
                //查询请假详情
                RequestForLeaveInfo requestForLeaveInfo = requestForLeaveInfoService.findByPersonId(workAttendance.getPersonId(), DateUtil.format(workAttendance.getRecordTime(), "yyyy-MM-dd HH:mm:ss"));
                /*if (requestForLeaveInfos.size() > 0) {
                    businessId = requestForLeaveInfos.get(0).getId();
                    status = "2";
                }*/

                if (requestForLeaveInfo != null) {
                    businessId = requestForLeaveInfo.getId();
                    status = "2";
                }
            }

            Map<String, Object> map = new HashMap<>();
            map.put("id", businessId);
            map.put("status", status);


            messageResult.setData(map);
            messageResult.setResult(true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);

            messageResult.setResult(false);
            messageResult.setMessage(ex.getMessage());
        }

        return messageResult;
    }


    @ApiOperation(value = "外勤打卡添加备注")
    @RequestMapping(value = "addRemarkForAttendance", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "remark", value = "备注", required = true, paramType = "form")
    })
    public MessageResult<Map> addRemarkForAttendance(@RequestAttribute String subject, String token, String id, String remark) {

        MessageResult<Map> messageResult = new MessageResult<>();
        try {

            FillAttendance fillAttendance = fillAttendanceService.get(id);
            if (fillAttendance != null) {
                fillAttendance.setRemark(remark);
                fillAttendanceService.update(fillAttendance);
            }

            messageResult.setCode(200);
            messageResult.setResult(true);


        } catch (Exception ex) {

            log.error(ex.getMessage(), ex);
            messageResult.setCode(400);
            messageResult.setResult(false);
        }
        return messageResult;

    }
}
