/**
  * 签到处理
  *
  * @return
  * @throws UnsupportedEncodingException
  */
 @RequestMapping(
     value = "doSign",
     method = {RequestMethod.GET, RequestMethod.POST})
 public @ResponseBody Object doSign() {
   ResponseResult responseResult = new ResponseResult();
   try {
     // 获取请假申请信息
     JSONObject jsonSignInfoObj =
         JSON.parseObject(
             URLDecoder.decode(HttpRequestUtil.getInstance().getString("signInfo"), "UTF-8"));
     Map<String, Object> resultData = new HashMap<String, Object>();
     responseResult.setValue(resultData);
     if (null != jsonSignInfoObj) {
       String sSignTime = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm");
       Date signTime = DateUtil.stringToDate(sSignTime + ":00");
       String id = CommonUtil.GeneGUID();
       jsonSignInfoObj.put("signTime", signTime);
       jsonSignInfoObj.put("id", id);
       resultData.put("id", id);
       resultData.put("signTime", DateUtil.dateToString(signTime, "HH:mm"));
     }
     signService.doSign(jsonSignInfoObj);
   } catch (Exception e) {
     e.printStackTrace();
     responseResult.setStatus(-1);
   }
   return responseResult;
 }
 /**
  * 根据月份查询当月统计
  *
  * @return
  */
 @RequestMapping(value = "signStatisticView", method = RequestMethod.GET)
 public ModelAndView signStatisticView() {
   ModelAndView modelAndView = super.createModelAndView("sign-statistic");
   modelAndView.addObject("currentMonth", DateUtil.dateToString(new Date(), "yyyy-MM"));
   // TODO 取出当月统计数据
   return modelAndView;
 }
 @Override
 public DataResult getAuditAppraisalRecord(
     Appraisal appraisal, Map<String, Object> params, int pageIndex, int pageSize) {
   DataResult dataResult = new DataResult();
   SqlQueryParameter sqlQueryParameter = new SqlQueryParameter();
   if (pageIndex != -1) {
     sqlQueryParameter.setPageIndex(pageIndex);
     sqlQueryParameter.setPage(true);
   }
   if (pageSize != -1) {
     sqlQueryParameter.setPageSize(pageSize);
   }
   sqlQueryParameter.setParameter(appraisal);
   if (!CollectionUtils.isEmpty(params)) {
     sqlQueryParameter.getKeyValMap().putAll(params);
   }
   List<Appraisal> appraisalList = appraisalDao.getAuditAppraisalRecord(sqlQueryParameter);
   if (!CollectionUtils.isEmpty(appraisalList)) {
     List<Map<String, Object>> dataMap = new ArrayList<Map<String, Object>>();
     Map<String, Object> temp = null;
     for (Appraisal a : appraisalList) {
       temp = a.getPersistentState();
       temp.put("screateDate", DateUtil.dateToString(a.getCreateTime(), "yyyy年MM月dd日"));
       temp.put(
           "statusDisplay",
           SystemCacheUtil.getInstance()
               .getSystemStatusCache()
               .get("Status_" + StringUtil.getString(temp.get("status"))));
       dataMap.add(temp);
     }
     dataResult.setData(dataMap);
     dataResult.setTotal(sqlQueryParameter.getTotalRecord());
   }
   return dataResult;
 }
 /**
  * 查询签到异常信息 根据月份 并统计
  *
  * @return
  */
 @RequestMapping(
     value = "getExceptionKQRecordByMonth",
     method = {RequestMethod.GET, RequestMethod.POST})
 public @ResponseBody Object getExceptionKQRecordByMonth(HttpServletRequest request) {
   // 获取请假申请信息
   DataResult dataResult = new DataResult();
   Map<String, Object> singCountInfo = new HashMap<String, Object>();
   singCountInfo.put("userId", SystemCacheUtil.getInstance().getCurrentUser().getUserid());
   singCountInfo.put(
       "monthDate",
       DateUtil.stringToDate(HttpRequestUtil.getInstance().getString("monthDate"), "yyyy-MM"));
   // 异常考勤记录
   dataResult.setData(signUserService.getExceptionKQSignByMonth(singCountInfo));
   return dataResult;
 }
 /**
  * 查询签到统计到信息 根据月份
  *
  * @return
  */
 @RequestMapping(
     value = "getSignStatisticByMonth",
     method = {RequestMethod.GET, RequestMethod.POST})
 public @ResponseBody Object getSignStatisticByMonth(HttpServletRequest request) {
   // 获取请假申请信息
   DataResult dataResult = new DataResult();
   Map<String, Object> resultData = new HashMap<String, Object>();
   Map<String, Object> singCountInfo = new HashMap<String, Object>();
   singCountInfo.put("userId", SystemCacheUtil.getInstance().getCurrentUser().getUserid());
   singCountInfo.put(
       "monthDate",
       DateUtil.stringToDate(HttpRequestUtil.getInstance().getString("monthDate"), "yyyy-MM"));
   // 签到统计
   singCountInfo.put("signType", "1");
   resultData.put("qtSignCountInfo", signUserService.getSignCountByMonth(singCountInfo));
   // 迟到早退
   singCountInfo.put("isSignException", "0");
   resultData.put("qtBeLateLeaveEarlyInfo", signUserService.getSignCountByMonth(singCountInfo));
   // 出勤率
   resultData.put("qtAttendance", signUserService.getAttendanceRateByMonth(singCountInfo));
   dataResult.setData(resultData);
   return dataResult;
 }
  /**
   * 我发起的签到信息
   *
   * @return
   */
  @RequestMapping(value = "myLaunchSignDetailView", method = RequestMethod.GET)
  public ModelAndView myLaunchSignDetailView() {
    ModelAndView modelAndView = super.createModelAndView("myLaunch_signDetail");
    String id = HttpRequestUtil.getInstance().getString("id");
    // 需要获取签到信息
    Map<String, Object> dataMap = signService.getSignById(id);
    modelAndView.addObject("signInfo", dataMap);
    EntityAccount entityAccount = new EntityAccount();
    entityAccount.setEntityId(id);
    entityAccount.setEntityType(EntityType.QD.value());
    // 获取应签到用户
    List<EntityAccount> entityAccountList = entityAccountService.getEntityAccount(entityAccount);
    // 获取所有应签到用户
    SignUser signUser = new SignUser();
    signUser.setSignId(id);
    List<Map<String, Object>> signUserList = signUserService.getSignUser(signUser);
    // 查询已经签到用户
    List<String> userList = new ArrayList<String>();
    String userId = null;
    for (Map<String, Object> map : signUserList) {
      userId = StringUtil.getString(map.get("userId"));
      if (!userList.contains(userId)) {
        userList.add(userId);
      }
    }
    // 应该签到者
    StringBuffer shouldSignUserInfo = new StringBuffer();
    // 已签到者
    StringBuffer signUserInfo = new StringBuffer();
    // 未签到者
    StringBuffer noSignUserInfo = new StringBuffer();

    // 遍历应签到人
    for (int i = 0, size = (entityAccountList == null) ? 0 : entityAccountList.size();
        i < size;
        i++) {
      entityAccount = entityAccountList.get(i);
      userId = entityAccount.getAccountId();
      if (userList.contains(userId)) {
        signUserInfo.append(',').append(entityAccount.getAccountName());
      } else {
        noSignUserInfo.append(',').append(entityAccount.getAccountName());
      }
      shouldSignUserInfo.append(',').append(entityAccount.getAccountName());
    }

    if (signUserInfo.length() > 0) {
      signUserInfo.deleteCharAt(0);
    }
    if (noSignUserInfo.length() > 0) {
      noSignUserInfo.deleteCharAt(0);
    }
    if (shouldSignUserInfo.length() > 0) {
      shouldSignUserInfo.deleteCharAt(0);
    }
    if (StringUtils.isEmpty(signUserInfo.toString())) {
      signUserInfo.append("无");
    }
    if (StringUtils.isEmpty(noSignUserInfo.toString())) {
      noSignUserInfo.append("无");
    }
    if (StringUtils.isEmpty(shouldSignUserInfo.toString())) {
      shouldSignUserInfo.append("无");
    }
    modelAndView.addObject("signUserInfo", signUserInfo.toString());
    modelAndView.addObject("noSignUserInfo", noSignUserInfo.toString());
    modelAndView.addObject("shouldSignUserInfo", shouldSignUserInfo.toString());
    // 当前时间信息
    Date curentDate = new Date();
    modelAndView.addObject(
        "date", DateUtil.dateToString(curentDate, "MM月dd日") + DateUtil.getDayOfWeek(curentDate));
    modelAndView.addObject("time", DateUtil.dateToString(curentDate, "HH:mm"));

    // TODO 取出当月统计数据
    return modelAndView;
  }
  /**
   * 签到详情
   *
   * @return
   */
  @RequestMapping(value = "signDetailView", method = RequestMethod.GET)
  public ModelAndView signDetailView(HttpServletRequest request) {
    ModelAndView modelAndView = super.createModelAndViewWithSign("sign_detail", request);
    Map<String, Object> requestParams = getRequestParams(request);
    String id = StringUtil.getString(requestParams.get("id"));
    if (StringUtils.isEmpty(id)) {
      throw new BusinessEnergyException(
          SpringContextUtil.getI18n("1002002", new String[] {"id"}, null));
    }
    // 需要获取签到信息
    Sign sign = new Sign();
    sign.setId(id);
    List<Map<String, Object>> signListMap = signService.getSign(sign);
    if (!CollectionUtils.isEmpty(signListMap)) {
      modelAndView.addObject("signInfo", signListMap.get(0));
    } else {
      if (CollectionUtils.isEmpty(signListMap)) {
        throw new EnergyException(
            SpringContextUtil.getI18n("1002003", new String[] {"id", id}, null));
      }
    }
    // 判断如果已经过期需要提醒
    Date currentDate = new Date();
    String signType = (String) signListMap.get(0).get("signType");
    Date beginTime = (Date) signListMap.get(0).get("beginTime");

    SignUser signUser = new SignUser();
    signUser.setSignId(id);
    signUser.setUserId(SystemCacheUtil.getInstance().getCurrentUser().getUserid());
    List<Map<String, Object>> signUserList = signUserService.getSignUser(signUser);
    if (!CollectionUtils.isEmpty(signUserList)) {
      Map<String, Object> temp = null;
      for (int i = 0, size = signUserList.size(); i < size; i++) {
        temp = signUserList.get(i);
        // 签到信息
        if ("0".equals(temp.get("attendType"))) {
          modelAndView.addObject("sign_in", temp);
          List<Accessory> accessoryList =
              accessoryService.getAccessoryByEntityId(StringUtil.getString(temp.get("id")));
          if (!CollectionUtils.isEmpty(accessoryList)) {
            modelAndView.addObject("signInAccessoryInfor", accessoryList);
          }
        } else
        /** 签退信息 */
        {
          modelAndView.addObject("sign_out", temp);
          List<Accessory> accessoryList =
              accessoryService.getAccessoryByEntityId(StringUtil.getString(temp.get("id")));
          if (!CollectionUtils.isEmpty(accessoryList)) {
            modelAndView.addObject("signOutAccessoryInfor", accessoryList);
          }
        }
      }
    }
    if ("0".equals(signType) && signUserList.size() < 2) {
      // 判断如果不是当天的考勤不能正常进行
      if (!DateUtil.dateToString(currentDate, "yyyy-MM-dd")
          .equals(DateUtil.dateToString(beginTime, "yyyy-MM-dd"))) {
        throw new BusinessEnergyException(SpringContextUtil.getI18n("1002007"));
      }
    }
    Date curentDate = new Date();
    modelAndView.addObject(
        "date", DateUtil.dateToString(curentDate, "MM月dd日") + DateUtil.getDayOfWeek(curentDate));
    modelAndView.addObject("time", DateUtil.dateToString(curentDate, "HH:mm"));

    return modelAndView;
  }