Example #1
0
  @Override
  public void handleFiles(List<String> filePaths, MultipartRequest req, BaseRep rs)
      throws Exception {
    try {
      String phone = req.getParameter("phone");
      String project_id = req.getParameter("project_id");
      String longitude = req.getParameter("longitude");
      String latitude = req.getParameter("latitude");
      String forWho = req.getParameter("for_who");
      String address = req.getParameter("address");
      String parent_user = req.getParameter("parent_user");
      String is_out_scannng = "0";
      if (StringUtil.isEmpty(parent_user)) {
        logger.info("上级管理员为空");
        rs.setRES_CODE(Global.USER_ID_NULL);
        rs.setRES_MESSAGE("请先登录");
        return;
      }
      if (StringUtil.isEmpty(phone)) {
        logger.info("缺少用户电话号码");
        rs.setRES_CODE(Global.USER_ID_NULL);
        rs.setRES_MESSAGE("请先登录");
        return;
      }
      if (StringUtil.isEmpty(longitude)
          || StringUtil.isEmpty(latitude)
          || StringUtil.isEmpty(address)) {
        logger.info("缺少位置信息");
        rs.setRES_CODE(Global.ADDRESS_NULL);
        rs.setRES_MESSAGE("定位失败,请重试");
        return;
      }
      if (StringUtil.isEmpty(project_id)) {
        logger.info("当前位置无任何项目");
        rs.setRES_CODE(Global.ADDRESS_NULL);
        rs.setRES_MESSAGE("当前位置无任何项目");
        return;
      }
      List<Map<String, Object>> users = userService.queryUserByPhone(phone);
      String user_id = "";
      String user_name = "";
      // 未注册用户打卡自动为其注册
      if (users == null || users.size() == 0) {
        UserVO userVO = userService.register(phone, UtilUniqueKey.getKey());
        if (userVO != null) {
          user_id = userVO.getUSER_ID();
          user_name = userVO.getUSER_NAME();
        }
      } else {
        if (users.get(0).get("user_id") != null) {
          user_id = users.get(0).get("user_id").toString();
          user_name = users.get(0).get("user_name").toString();
        }
      }
      if (StringUtil.isEmpty(user_id)) {
        logger.info("用户信息查询失败或插入新用户失败");
        rs.setRES_CODE(Global.USER_ID_NULL);
        rs.setRES_MESSAGE("用户信息查询失败,请重试");
        return;
      }
      double current_longitude = Double.parseDouble(longitude);
      double current_latitude = Double.parseDouble(latitude);
      Map<String, String> datas = new HashMap<String, String>();
      String parent_id = "";
      String root_id = "";
      String root_name = "";
      // 帮人打卡
      if (forWho != null && forWho.equals("1")) {
        String current_root_id = "";
        String project_name = "";
        // 获取管理员所在项目
        ProjectVO parentProject = null;
        List<Map<String, Object>> parentProjects = projectService.queryProjectByID(project_id);
        if (parentProjects != null && parentProjects.size() > 0) {
          parentProject = ProjectVO.assembleProject(parentProjects.get(0));
        }
        if (parentProject == null) {
          logger.info("当前未加入任何项目");
          rs.setRES_CODE(Global.PROJECT_NULL);
          rs.setRES_MESSAGE("当前未加入任何项目");
          return;
        }
        logger.info("当前管理项目===>" + parentProject.getPROJECT_ID());
        parent_id = parentProject.getPARENT_ID();
        root_id = parentProject.getROOT_ID();
        root_name = parentProject.getROOT_PROJECT_NAME();
        double parent_longitude = Double.parseDouble(parentProject.getLONGITUDE());
        double parent_latitude = Double.parseDouble(parentProject.getLATITUDE());
        // 项目位置内为正常考勤,否则为外出考勤
        if (ToolsUtil.getDistance(
                current_longitude, current_latitude, parent_longitude, parent_latitude)
            < 500) {
          is_out_scannng = "0";
        } else {
          is_out_scannng = "1";
        }

        // 获取该考勤下级所有项目,判断是否与当前项目位置范围有重叠,重叠则不允许打卡
        List<Map<String, Object>> projects = projectService.queryProjectByCreateUser(user_id);
        if (projects != null && projects.size() > 0) {
          for (Map<String, Object> project : projects) {
            double project_longitude = Double.parseDouble(project.get("longitude").toString());
            double project_latitude = Double.parseDouble(project.get("latitude").toString());
            if (ToolsUtil.getDistance(
                    current_longitude, current_latitude, project_longitude, project_latitude)
                < 500) {
              project_id = project.get("project_id").toString();
              current_root_id = project.get("root_id").toString();
              project_name = project.get("project_name").toString();
              logger.info("用户在当前位置已经有项目==>" + project.get("project_name").toString());
              break;
            }
          }
        }
        if (StringUtil.isEmpty(current_root_id)) {
          ProjectVO projectVO =
              projectService.createProject(
                  user_name + "的项目",
                  "",
                  parent_id,
                  root_id,
                  user_id,
                  address,
                  longitude,
                  latitude,
                  root_name);
          project_id = projectVO.getPROJECT_ID();
          project_name = projectVO.getPROJECT_NAME();
        } else if (!current_root_id.equals(root_id)) {
          rs.setRES_CODE(Global.PROJECT_NULL);
          rs.setRES_MESSAGE(user_name + "在当前位置已加入其他项目,请提示他进行项目迁移");
          return;
        }
        datas.put("user_name", project_name);
        datas.put("user_phone", phone);
      } else {
        ProjectVO project = null;
        List<Map<String, Object>> projects = projectService.queryProjectByID(project_id);
        if (projects != null && projects.size() > 0) {
          project = ProjectVO.assembleProject(projects.get(0));
        }
        if (project == null) {
          logger.info("当前未加入任何项目");
          rs.setRES_CODE(Global.PROJECT_NULL);
          rs.setRES_MESSAGE("当前未加入任何项目");
          return;
        }
        project_id = project.getPROJECT_ID();
        parent_id = project.getPARENT_ID();
        root_id = project.getROOT_ID();
        double project_longitude = Double.parseDouble(project.getLONGITUDE());
        double project_latitude = Double.parseDouble(project.getLATITUDE());
        // 项目位置内为正常考勤,否则为外出考勤
        if (ToolsUtil.getDistance(
                current_longitude, current_latitude, project_longitude, project_latitude)
            < 500) {
          is_out_scannng = "0";
        } else {
          is_out_scannng = "1";
        }
      }
      rs.setRES_OBJ(GsonUtil.getInstance().toJson(datas));

      if (filePaths.size() > 0 && filePaths.get(0) != null) {
        String imgFile = filePaths.get(0).toString();
        AttchVO attch =
            attchService.insertAttch(
                AttchVO.TYPE_ATTENCHANCE,
                user_id + "_" + format.format(new Date(System.currentTimeMillis())),
                imgFile);
        boolean result = false;
        if (attendanceService.isScanningToday(project_id)) {
          logger.info("今天有打卡数据");
          if (attendanceService.isScanningTodayVaild(project_id)) {
            result =
                attendanceService.scanning(
                    user_id,
                    project_id,
                    parent_id,
                    root_id,
                    attch.getATTCH_ID(),
                    address,
                    longitude,
                    latitude,
                    is_out_scannng,
                    imgFile);
          } else {
            result =
                attendanceService.updateScanning(
                    user_id,
                    project_id,
                    parent_id,
                    root_id,
                    attch.getATTCH_ID(),
                    address,
                    longitude,
                    latitude,
                    is_out_scannng,
                    imgFile);
          }
        } else {
          if (!project_id.equals(parent_id)) {
            scanningParent(parent_id, address, longitude, latitude);
          }
          result =
              attendanceService.scanning(
                  user_id,
                  project_id,
                  parent_id,
                  root_id,
                  attch.getATTCH_ID(),
                  address,
                  longitude,
                  latitude,
                  is_out_scannng,
                  imgFile);
        }
        if (result) {
          logger.info("打卡成功");
          rs.setRES_CODE(Global.RESP_SUCCESS);
          rs.setRES_MESSAGE("打卡成功");
        } else {
          logger.info("数据库写入失败");
          rs.setRES_CODE(Global.ORACLE_ERROR);
          rs.setRES_MESSAGE("打卡失败,请重试");
        }
      } else {
        logger.info("文件上传失败");
        rs.setRES_CODE(Global.FILE_UPLOAD_FAILED);
        rs.setRES_MESSAGE("照片上传失败,请重试");
      }
    } catch (Exception e) {
      e.printStackTrace();
      rs.setRES_CODE(Global.RESP_ERROR);
      rs.setRES_MESSAGE("服务器异常,请重试");
    }
  };
Example #2
0
 public static UserVO assembleUserVO(Map<String, Object> userInfo) {
   UserVO user = new UserVO();
   if (userInfo.get("user_id") != null) {
     user.setUSER_ID(userInfo.get("user_id").toString().trim());
   }
   if (userInfo.get("user_name") != null) {
     user.setUSER_NAME(userInfo.get("user_name").toString().trim());
   }
   if (userInfo.get("phone") != null) {
     user.setPHONE(userInfo.get("phone").toString().trim());
   }
   if (userInfo.get("remark") != null) {
     user.setREMARK(userInfo.get("remark").toString().trim());
   }
   if (userInfo.get("sex") != null) {
     user.setSEX(userInfo.get("sex").toString().trim());
   }
   if (userInfo.get("small_head") != null) {
     user.setSMALL_HEAD(userInfo.get("small_head").toString().trim());
   }
   if (userInfo.get("big_head") != null) {
     user.setBIG_HEAD(userInfo.get("big_head").toString().trim());
   }
   if (userInfo.get("create_time") != null) {
     user.setCREATE_TIME(userInfo.get("create_time").toString().trim());
   }
   if (userInfo.get("idcard") != null) {
     user.setIDCARD(userInfo.get("idcard").toString().trim());
   }
   if (userInfo.get("idcard_front") != null) {
     user.setIDCARD_FRONT(userInfo.get("idcard_front").toString().trim());
   }
   if (userInfo.get("idcard_back") != null) {
     user.setIDCARD_BACK(userInfo.get("idcard_back").toString().trim());
   }
   if (userInfo.get("idcard_hand") != null) {
     user.setIDCARD_HAND(userInfo.get("idcard_hand").toString().trim());
   }
   if (userInfo.get("rate") != null && userInfo.get("rate_count") != null) {
     float rate = Float.parseFloat(userInfo.get("rate").toString().trim());
     float rate_count = Integer.parseInt(userInfo.get("rate_count").toString().trim());
     user.setRATE((rate_count * rate + 3.0f) / (rate_count + 1.0f));
   } else {
     user.setRATE(3.0f);
   }
   return user;
 }