Esempio n. 1
0
  /**
   * 返回null表示修改成功
   *
   * @param cell
   * @return
   */
  @SuppressWarnings("unused")
  private BatchExceptionData modifyUserAccountProject(Cell[] cell) {

    String message = "";

    try {

      String projectName = cell[0].getContents().trim();
      int projectId = Integer.parseInt(cell[1].getContents().trim());

      String realName = cell[3].getContents().trim();
      String userName = cell[4].getContents().trim();

      CompanyProject project = companyProjectServices.findCompanyProjectById(projectId);
      if (project == null || !projectName.equals(project.getProjectName())) {

        message = "项目名称与id不一致";
        throw new Exception();
      }

      UserAccount user = userAccountServices.findUserAccountByUserNameIncludeDelete(userName);
      if (user == null || !realName.equals(user.getRealName())) {

        message = "用户的姓名与账号不一致";
        throw new Exception();
      }

      user.setProjectId(projectId);

      user.setModId(SessionUser.getUserId());
      user.setModTime(new Date());

      userAccountServices.updateUserAccount(user);

    } catch (Exception e) {

      if (CommonUtils.isStrEmpty(message)) {

        message = "数据格式不合法";
      }
    }

    if (CommonUtils.isStrEmpty(message)) {
      // 表示修改成功

      return null;
    }

    BatchExceptionData retPojo = new BatchExceptionData();

    retPojo.setProjectName(cell[0].getContents());
    retPojo.setProjectId(cell[1].getContents());
    retPojo.setJobNumber(cell[2].getContents());
    retPojo.setRealName(cell[3].getContents());
    retPojo.setUserName(cell[4].getContents());
    retPojo.setExceptionData(message);

    return retPojo;
  }
Esempio n. 2
0
  /**
   * 返回null表示修改成功
   *
   * @param cell
   * @param proList
   * @param companyId
   * @return
   */
  private BatchExceptionData modifyUserAccountProject(
      Cell[] cell, List<CompanyProject> proList, int companyId) {

    String message = "";

    try {

      String projectName = cell[0].getContents().trim();
      int projectId = 0;
      try {
        projectId = Integer.parseInt(cell[1].getContents().trim());
      } catch (Exception e) {
      }

      String jobNumber = cell[2].getContents().trim();

      String realName = cell[3].getContents().trim();

      if (projectId > 0) {
        // 表示填了项目id

        CompanyProject project = companyProjectServices.findCompanyProjectById(projectId);
        if (project == null || !projectName.equals(project.getProjectName())) {

          message = "项目名称与id不一致";
          throw new Exception();
        }
      } else {
        // 没有填项目id

        List<CompanyProject> inclueProList = isIncludeOnlyCompanyProject(proList, projectName);
        if (CommonUtils.isCollectionEmpty(inclueProList) || inclueProList.size() != 1) {

          message = "选择的公司该项目不合法";
          throw new Exception();
        }

        projectId = inclueProList.get(0).getId();
      }

      UserAccount userAccount = new UserAccount(); // 参数
      userAccount.setCompanyId(companyId);
      userAccount.setRealName(realName);
      if (!CommonUtils.isStrEmpty(jobNumber)) {
        userAccount.setJobNumber(jobNumber);
      }

      List<UserAccount> userList =
          userAccountServices.findUserAccountByCompanyIdAndRealNameOrJobNumberIncludeDelete(
              userAccount);
      if (CommonUtils.isCollectionEmpty(userList) || userList.size() != 1) {

        message = "用户姓名不能唯一确定一个用户";
        throw new Exception();
      }

      UserAccount user = userList.get(0);

      user.setProjectId(projectId);

      user.setModId(SessionUser.getUserId());
      user.setModTime(new Date());

      userAccountServices.updateUserAccount(user);

    } catch (Exception e) {

      if (CommonUtils.isStrEmpty(message)) {

        message = "数据格式不合法\n" + e.getMessage();
      }
    }

    if (CommonUtils.isStrEmpty(message)) {
      // 表示修改成功

      return null;
    }

    BatchExceptionData retPojo = new BatchExceptionData();

    retPojo.setProjectName(cell[0].getContents());
    retPojo.setProjectId(cell[1].getContents());
    retPojo.setJobNumber(cell[2].getContents());
    retPojo.setRealName(cell[3].getContents());
    retPojo.setExceptionData(message);

    return retPojo;
  }