/**
  * 调整某个员工的任职信息
  *
  * @param employeeId
  * @param responsibleJobHoldings
  * @return
  */
 @ResponseBody
 @RequestMapping(
     value = "/transform-post",
     method = RequestMethod.POST,
     consumes = "application/json")
 public Map<String, Object> transformPost(
     Long employeeId, @RequestBody ResponsiblePostDTO[] responsibleJobHoldings) {
   Map<String, Object> dataMap = new HashMap<String, Object>();
   try {
     Employee employee = getBaseApplication().getEntity(Employee.class, employeeId);
     employeeApplication.transformPost(
         employee, new HashSet<ResponsiblePostDTO>(Arrays.asList(responsibleJobHoldings)));
     dataMap.put("result", "success");
   } catch (HasPrincipalPostYetException exception) {
     dataMap.put("result", "该员工已经有主任职岗位!");
     exception.printStackTrace();
   } catch (EmployeeMustHaveAtLeastOnePostException exception) {
     dataMap.put("result", "必须保证每名员工至少在一个岗位上任职!");
     exception.printStackTrace();
   } catch (Exception e) {
     dataMap.put("result", "调整职务失败!");
     e.printStackTrace();
   }
   return dataMap;
 }
  /**
   * 获得某个员工的任职信息
   *
   * @param employeeId
   * @return
   */
  @ResponseBody
  @RequestMapping("/get-posts-by-employee")
  public Map<String, Object> getPostsByEmployee(Long employeeId) {
    Employee employee = getBaseApplication().getEntity(Employee.class, employeeId);

    Map<String, Object> dataMap = new HashMap<String, Object>();
    dataMap.put("data", employeeApplication.getPostsByEmployee(employee));
    return dataMap;
  }
 /**
  * 根据ID号获得员工
  *
  * @param id
  * @return
  */
 @ResponseBody
 @RequestMapping("/get/{id}")
 public Map<String, Object> get(@PathVariable("id") Long id) {
   Map<String, Object> dataMap = new HashMap<String, Object>();
   try {
     dataMap.put("data", employeeApplication.getEmployeeById(id));
   } catch (Exception e) {
     dataMap.put("error", "查询指定职务失败!");
     e.printStackTrace();
   }
   return dataMap;
 }
  /**
   * 分页查询某个机构下的员工
   *
   * @param page
   * @param pagesize
   * @param example
   * @param organizationId
   * @return
   */
  @ResponseBody
  @RequestMapping("/pagingquery-by-org")
  public Page pagingQueryByOrganization(
      int page, int pagesize, EmployeeDTO example, Long organizationId, boolean queryAllChildren) {
    Page<EmployeeDTO> employees = null;
    if (organizationId == 0) {
      employees = employeeApplication.pagingQueryEmployeesWhoNoPost(example, page, pagesize);
    } else {
      Organization organization =
          getBaseApplication().getEntity(Organization.class, organizationId);
      if (queryAllChildren) {
        employees =
            employeeApplication.pagingQueryEmployeesByOrganizationAndChildren(
                example, organization, page, pagesize);
      } else {
        employees =
            employeeApplication.pagingQueryEmployeesByOrganization(
                example, organization, page, pagesize);
      }
    }

    return employees;
  }
  /**
   * 创建一个员工
   *
   * @param employee
   * @param jobId
   * @param organizationId
   * @return
   */
  @ResponseBody
  @RequestMapping("/create")
  public Map<String, Object> createEmployee(Employee employee, Long postId) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      Post post = null;
      if (postId != null) {
        post = getBaseApplication().getEntity(Post.class, postId);
      }

      employeeApplication.createEmployeeWithPost(employee, post);
      dataMap.put("result", "success");
    } catch (SnIsExistException exception) {
      dataMap.put("result", "员工编号: " + employee.getSn() + " 已被使用!");
    } catch (IdNumberIsExistException exception) {
      dataMap.put("result", "不能使用与其他人一样的证件号码!");
    } catch (Exception e) {
      dataMap.put("result", "保存失败!");
      e.printStackTrace();
    }
    return dataMap;
  }
 /**
  * 分页查询员工
  *
  * @param page
  * @param pagesize
  * @param example
  * @return
  */
 @ResponseBody
 @RequestMapping("/pagingquery")
 public Page pagingQuery(int page, int pagesize, EmployeeDTO example) {
   Page<EmployeeDTO> employees = employeeApplication.pagingQueryEmployees(example, page, pagesize);
   return employees;
 }