/** @see com.pureinfo.ark.interaction.ActionBase#beforeExecution() */
 protected ActionForward beforeExecution() throws PureException {
   QueryFilter filter = ((SearchForm) form).getQueryFilter();
   filter.addCondition("{this.contractId}=0 or {this.contractId} IS NULL");
   filter.addPropertyCondition(
       "this", "lStatus", SQLOperator.LESS, new Integer(ProjectConstants.STATUS_FINISHED));
   SRMUser user = (SRMUser) loginUser;
   boolean bAdmin2 = user.isAdmin2();
   if (bAdmin2) {
     filter.addPropertyCondition(
         "this", "college", SQLOperator.EQUAL, new Integer(user.getCollegeId()));
   }
   return super.beforeExecution();
 }
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    // TODO Auto-generated method stub
    int nImportType = Integer.parseInt(_sToProperty);

    // ¼ì²â
    if (Xls2srmForm.JUSTFORCHECK == nImportType) return null;

    String value = _old.getStrProperty(_sFromProperty);
    if (value != null && !"".equals(value.trim())) {
      IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
      SRMUser user = null;
      IObjects users = null;
      IStatement query = null;
      try {
        query =
            mgr.createQuery(
                "SELECT {this.trueName} FROM {this} WHERE {this.employeeSId}=? and {this.name}=? and {this.status}<>32",
                1);
        query.setString(0, value.trim());
        query.setString(1, value.trim());
        users = query.executeQuery(false);
        user = (SRMUser) users.next();
      } finally {
        DolphinHelper.clear(users, query);
      }

      if (user != null) {
        System.out.println("--------------------------------------------");
        System.out.println("TrueName:" + user.getTrueName());
        System.out.println("---------------------------------------------");
        return user.getTrueName();
      }
    }
    return "";
  }
 private int getAuthorId(String _sAuthorName) throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
     // 1. formal table
     String strSQL = "SELECT * FROM {this} WHERE {this.trueName}=?";
     query = userMgr.createQuery(strSQL, 1);
     query.setString(0, _sAuthorName);
     result = query.executeQuery();
     SRMUser user = (SRMUser) result.next();
     if (user != null) return user.getId();
     // 2. temp table
     strSQL = "SELECT * FROM {this}0 WHERE {this.trueName}=?";
     query = userMgr.createQuery(strSQL, 1);
     query.setString(0, _sAuthorName);
     result = query.executeQuery();
     user = (SRMUser) result.next();
     if (user != null) return user.getId();
     return 0;
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
  /**
   * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
   *     com.pureinfo.dolphin.model.DolphinObject, java.lang.String, java.lang.String,
   *     com.pureinfo.dolphin.persister.ISession, com.pureinfo.dolphin.persister.ISession,
   *     com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, java.lang.String)
   */
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    String sAdminName = _old.getStrProperty(_sFromProperty);
    if (sAdminName == null) return null;
    String sDeptCode = _old.getStrProperty("单位代码");
    _new.setProperty("firstAuthorName", sAdminName);

    IObjects users = null;
    IStatement query = null;
    SRMUser user = null;
    int nUserId = 0;
    try {
      ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
      query =
          userMgr.createQuery(
              "SELECT * FROM {this} WHERE {this.trueName}=?", DolphinConstants.MAXSIZE_UNLIMITED);
      query.setString(0, sAdminName);
      users = query.executeQuery();
      SRMUser[] aUsers = (SRMUser[]) users.toList().toArray(new SRMUser[0]);
      if (aUsers.length == 0) {
        nUserId = 0;
      } else if (aUsers.length == 1) {
        user = aUsers[0];
        nUserId = user.getId();
      } else {
        if (sDeptCode == null) {
          sDeptCode = _old.getStrProperty("字段1");
        }
        String sCollege = sDeptCode.substring(0, 2);
        for (int i = 0; i < aUsers.length; i++) {
          Organization org = aUsers[i].getDepartment();
          String sCode = null;
          if (org != null) sCode = org.getCode();
          if (sCode != null && sCode.length() > 2) sCode = sCode.substring(0, 2);
          if (sCode != null && sCode.equals(sCollege)) {
            user = aUsers[i];
            nUserId = user.getId();
            break;
          }
        }
        if (user == null) {
          logger.error(_old.getStrProperty("成果名称") + "," + _old.getStrProperty("负责人"));
          user = aUsers[0];
          nUserId = user.getId();
        }
      }
      LocalContextHelper.currentSession().autoGenerateProperty(_new, "id");
      int nProductId = _new.getIntProperty("id", -1);
      ObjUserMapping author = new ObjUserMapping();

      author.setObjType(SRMTypes.PRODUCT);
      author.setUserType("1");
      author.setUserId(nUserId);
      author.setUserName(sAdminName);
      author.setOrderNo(1);
      author.setObjId(nProductId);
      author.setWeightYear(WeightConstants.WEIGHT_YEAR_DEFAULT_VALUE);

      IObjUserMappingMgr puMgr =
          (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(ObjUserMapping.class);
      puMgr.save(author);
    } finally {
      DolphinHelper.clear(users, query);
    }
    return "" + nUserId;
  }
  public String getTailedButtons() throws PureException {
    SRMUser user = (SRMUser) loginUser;
    String sProductForm = request.getParameter("dp_productForm");

    if (request.getParameter("paperForm") != null) {
      Product product = new Product();
      product.setProductForm(ProductConstants.SPRODUCT_FORM_PAPER);
      product.setCollege(user.getCollegeId());
      if (Auth2Helper.getManager().hasRight(loginUser, product, ArkActionTypes.AUDIT, false)) {
        StringBuffer sbuff = new StringBuffer();
        try {
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要打回为待审核吗?')){");
          sbuff.append("this.disabled=true;mainForm.action='../product/productBackWaitCheck.do");
          sbuff.append("';mainForm.target='_blank';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/return.gif\">打回待审核</button>&nbsp;&nbsp;");
          return sbuff.toString();
        } finally {
          sbuff.setLength(0);
        }
      }
    }

    if (user.isAdmin1() || user.isProductAdmin()) {
      if (ProductConstants.SPRODUCT_FORM_HONOR.equals(sProductForm)
          || ProductConstants.SPRODUCT_FORM_APPRAISE.equals(sProductForm)) {
        StringBuffer sbuff = new StringBuffer();
        try {
          if (ProductConstants.SPRODUCT_FORM_HONOR.equals(sProductForm)) {
            sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
            sbuff.append("else{doCompile();this.disabled=true;}\">");
            sbuff.append(
                "<img align=\"absMiddle\" src=\"../images/word.gif\">奖励汇编</button>&nbsp;&nbsp;");
            sbuff.append("<script>");
            sbuff.append("	function doCompile() {");
            sbuff.append("    	var aa = document.getElementsByName('id');");
            sbuff.append("var ids = '';");
            sbuff.append("for(var i=0;i<aa.length;i++){");
            sbuff.append("if(aa[i].checked){");
            sbuff.append("ids += aa[i].value + ',';");
            sbuff.append("}");
            sbuff.append("}");
            sbuff.append("document.HeadForm.ids.value = ids;");
            sbuff.append("document.HeadForm.action = '../product/honor-compile-type-select.jsp';");
            // sbuff.append("document.HeadForm.target='_blank';");
            sbuff.append("document.HeadForm.submit();");
            sbuff.append("}");
            sbuff.append("</script>");
          }
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要修改选中奖励吗?')){");
          sbuff.append(
              "this.disabled=true;mainForm.action='../product/ProductBatchEditDatumAndCer.do?");
          sbuff.append("actionType=cer&dp_productForm=").append(sProductForm);
          sbuff.append("';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/edit.gif\">证书存档批量修改</button>&nbsp;&nbsp;");
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要修改选中奖励吗?')){");
          sbuff.append(
              "this.disabled=true;mainForm.action='../product/ProductBatchEditDatumAndCer.do?");
          sbuff.append("actionType=datum&dp_productForm=");
          sbuff.append(sProductForm).append("';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/edit.gif\">材料存档批量修改</button>&nbsp;&nbsp;");
          return sbuff.toString();
        } finally {
          sbuff.setLength(0);
        }
      }
    }

    return null;
  }