Beispiel #1
0
  /**
   * 批量修改项目
   *
   * @return
   * @throws Exception
   */
  public String batchModifyProject() throws Exception {

    // 先移除之前session中的异常数据

    request.getSession().removeAttribute(BATCH_EXCEPTION_DATA);

    ActionTemplate.executeAjaxMethod(
        this,
        new ActionAjaxMethodModifyNoThrowsExceptionCallback() {

          @Override
          public void modifyMethod() throws Exception {

            String ignoreFirstRowStr = request.getParameter("ignoreFirstRow"); // 是否忽略第一行
            boolean ignoreFirstRow = false;
            if (!CommonUtils.isStrEmpty(ignoreFirstRowStr)) {
              ignoreFirstRow = true;
            }

            List<Cell[]> cellList = ReadXlsUtils.readXls(batchFile, 5, ignoreFirstRow);

            if (CommonUtils.isCollectionEmpty(cellList)) {

              return;
            }

            int companyId = Integer.parseInt(request.getParameter("companyId"));
            CompanyProjectCond proCond = new CompanyProjectCond();
            proCond.setCompanyId(companyId);

            List<CompanyProject> proList = companyProjectServices.findCompanyProjectByCond(proCond);

            List<BatchExceptionData> pojoList = new ArrayList<BatchExceptionData>();
            BatchExceptionData pojo = null;

            for (Cell[] cell : cellList) {

              pojo = modifyUserAccountProject(cell, proList, companyId); // 返回null表示修改成功

              if (pojo != null) {

                pojoList.add(pojo);
              }
            }

            if (!CommonUtils.isCollectionEmpty(pojoList)) {
              // 表示有异常数据
              request.getSession().setAttribute(BATCH_EXCEPTION_DATA, pojoList);
            }
          }
        });

    return null;
  }
Beispiel #2
0
  /**
   * 判断是否有异常数据
   *
   * @return
   * @throws Exception
   */
  public String ajaxExceptionData() throws Exception {

    ActionTemplate.executeAjaxMethod(
        this,
        new ActionAjaxMethodModifyNoThrowsExceptionCallback() {

          @Override
          public void modifyMethod() throws Exception {

            Object obj = request.getSession().getAttribute(BATCH_EXCEPTION_DATA);
            if (obj == null) {
              // 表示没有异常数据
              throw new Exception();
            }
          }
        });

    return null;
  }
Beispiel #3
0
  /**
   * 提交批量新建用户
   *
   * @return
   */
  public String submitBatUser() {
    ActionTemplate.executeAjaxMethod(
        true,
        this,
        new ActionAjaxMethodModifyCallback() {

          @Override
          public void modifyMethodException(Exception e) {
            setUpEasyuiAjaxForFail(e.getMessage());
          }

          @Override
          public void modifyMethod() throws Exception {
            if (SessionUser.getUserId() != ContUserId.ADMIN) {
              throw new Exception("目前仅供系统管理员使用");
            }

            if (selProjectId <= 0) {
              throw new Exception("必须选择项目");
            }

            if (selRoleId <= 0) {
              throw new Exception("必须选择角色");
            }

            Date thisDate = new Date();
            CompanyProject project = companyProjectServices.findCompanyProjectById(selProjectId);

            if (userAccountList == null) {
              userAccountList = new ArrayList<UserAccount>();
            }

            // 每行格式校验
            String strLine[] = userStr.split("\r\n");

            for (int i = 0; i < strLine.length; i++) {
              if (strLine[i].endsWith(",")) {
                strLine[i] = strLine[i] + " ";
              }
              String strUserInfo[] = strLine[i].split(",");

              if (strUserInfo.length != 5) {
                throw new Exception("第" + (i + 1) + "行格式不对");
              }

              UserAccount userAccount = new UserAccount();
              userAccount.setUserName(strUserInfo[0]);
              userAccount.setRealName(strUserInfo[1]);
              userAccount.setRemark(strUserInfo[2]);
              userAccount.setMobilePhone(strUserInfo[3]);
              userAccount.setJobNumber(strUserInfo[4]);

              userAccount.setUserPwd(ContUserId.INIT_PASSWORD);
              userAccount.setAccountType("1");
              userAccount.setCompanyId(project.getCompanyId());
              userAccount.setProjectId(project.getId());
              userAccount.setCreatedId(SessionUser.getUserId());
              userAccount.setCreatedTime(thisDate);
              userAccount.setModId(SessionUser.getUserId());
              userAccount.setModTime(thisDate);
              userAccount.setIsDeleted("0");

              userAccountList.add(userAccount);
            }

            // 用户校验(用户名是否已经存在)
            for (int i = 0; i < userAccountList.size(); i++) {
              if (userAccountServices.findUserAccountByName(userAccountList.get(i).getUserName())
                  > 0) {
                throw new Exception(
                    "用户账号已经存在,无法添加(" + userAccountList.get(i).getUserName() + ")全部账号都不会创建!");
              }
            }

            // 执行保存
            for (int i = 0; i < userAccountList.size(); i++) {
              userAccountServices.saveUserAccount(userAccountList.get(i));

              addRole(userAccountList.get(i), selRoleId);
            }
          }
        });

    return null;
  }