grep

기본형 : grep [OPTION] [PATTERN] [FILE]

- 파일에서 특정 문자열을 포함한 줄의 내용 표시.
  grep "2021-06-29 14:15:27.407" /log/resin/erp/online/app.log
- 파일에서 특정 문자열을 포함한 줄을 기준으로 위로 10줄, 아래로 20줄의 내용 표시.
  grep "2021-06-29 14:15:27.407" /log/resin/erp/online/app.log -B10 -A20

서로 다른 유형의 List 복사

 /**
  * @description
  * <pre>
  * source list 중 target list와 항목명이 같은 데이터를 복사
  * </pre>
  * @param srcList : source list
  * @param trgtList : target list
  * @param pTargetType : target type
  */
  public static <E, T> void copyData(List<E> srcList, List<T> trgtList, Class<T> pTargetType) {
    try {
      for( E src : srcList) {
        T trgt = (T) pTargetType.newInstance();
        BeanUtils.copyProperties(src, trgt);
        trgtList.add(trgt);
      }
    } catch (BeansException be) {
      logger.debug(be.getMessage(), be);
    } catch (Exception e) {
      logger.debug(e.getMessage(), e);
    }
  }

사용예)
  List<TrgtVo> trgtList = new ArrayList<TrgtVo>();
  List<SrcVo> srcList = svc.getList(paramVo);
  ErpUtils.copyData(srcList, trgtList, TrgtVo.class);

관련글 : 서로 다른 유형의 object 복사

nexacro copy dataset

/*----------------------------------------------------------------------------------------------
 * 설명     : dataset 복사. column명이 같은것만 복사.
 * 파라미터 : pSrc : (필수) source dataset
                  pTrgt : (필수) target dataset
 * 리턴값    : true : 복사 성공, false : 복사 실패.
-----------------------------------------------------------------------------------------------*/
this.gf_ErpCopyData = function(pSrc:nexacro.NormalDataset, pTrgt:nexacro.NormalDataset) {
  
  try {
    pTrgt.clearData();
    var nToRow = 0; 
    pTrgt.set_updatecontrol(false);
    for( var nRow = 0; nRow < pSrc.rowcount; nRow++ ) {
      nToRow = pTrgt.addRow();
      pTrgt.copyRow(nToRow, pSrc, nRow);
      pTrgt.setRowType(nRow, pSrc.getRowType(nRow));
    };
    pTrgt.set_updatecontrol(true);
    
    return pTrgt.rowcount == pSrc.rowcount;
  } catch(e) {
    return false;
  };
};

사용예)
this.gf_ErpCopyData(this.ds_src, this.trgt);

javascript string format 구현

String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
      ;
    });
};

사용예)
var sTemp = " num1 : {0}, num2 : {1}";
console.log(sTemp.format("12","25"));
결과)
num1 : 12, num2 : 25

Nexacro callback 정의 및 호출

//callback function
this.fn_callbackTest = function(param1, param2) {
  console.log(param1);
  console.log(param2);
};

//init object
this.fv_objConfig;
this.fn_initObject = function(){
    this.fv_objConfig = {
      objForm : this,
      id : "service01",
      callbackFunc : this.fn_callbackTest,
      param1 : "p1",
      param2 : "p2"
    };
};

//call callback
this.fn_testFunc = function() {  
    var param1      = this.fv_objConfig.param1;
  var param2      = this.fv_objConfig.param2;
  var callbackFunc  = this.fv_objConfig.callbackFunc;
  var pThis     = this.fv_objConfig.objForm;
  
  if(callbackFunc){
    callbackFunc.call(pThis, param1, param2);
  }
};

oracle table, column 정보 조회1

SELECT SUBSTR(a.TABLE_NAME,0,2) AS "업무구분"
     , a.TABLE_NAME AS "테이블명"
     , b.COMMENTS AS "테이블한글명"
     , a.COLUMN_ID AS "컬럼순번"
     , a.COLUMN_NAME AS "컬럼명"
     , c.COMMENTS AS "컬럼한글명"
     , a.DATA_TYPE AS "타입"
     , CASE WHEN NVL(a.DATA_SCALE,0) = 0 THEN TO_CHAR(a.DATA_LENGTH)
            ELSE a.DATA_LENGTH||'('||a.DATA_SCALE||')'
       END AS "길이"
     , CASE WHEN d.COLUMN_NAME IS NOT NULL THEN TO_CHAR(d.KEY_SEQ)
            ELSE ''
       END AS "KEY"
     , CASE WHEN a.nullable = 'N' THEN 'Y'
            ELSE ''
       END AS "NOT NULL"
     , a.DATA_DEFAULT AS "초기값"
  FROM ALL_TAB_COLUMNS a
 INNER JOIN ALL_TAB_COMMENTS b
    ON a.OWNER = b.OWNER
   AND a.TABLE_NAME = b.TABLE_NAME
  LEFT OUTER JOIN ALL_COL_COMMENTS c
    ON a.OWNER = c.OWNER
   AND a.TABLE_NAME = c.TABLE_NAME
   AND a.COLUMN_NAME = c.COLUMN_NAME
  LEFT OUTER JOIN (
       SELECT ia.OWNER
            , ia.TABLE_NAME
            , ib.COLUMN_NAME
            , ib.POSITION AS KEY_SEQ
         FROM ALL_CONSTRAINTS ia
        INNER JOIN ALL_CONS_COLUMNS ib
           ON ia.OWNER  = ib.OWNER
          AND ia.TABLE_NAME = ib.TABLE_NAME
          AND ia.CONSTRAINT_NAME = ib.CONSTRAINT_NAME
          AND ia.CONSTRAINT_TYPE = 'P'
       ) d
    ON a.OWNER = d.OWNER
   AND a.TABLE_NAME = d.TABLE_NAME
   AND a.COLUMN_NAME = d.COLUMN_NAME
 WHERE a.OWNER = 'SEMA_ERP' /* bx-erp : ERP, semis : SEMA_OWN  */
   AND a.TABLE_NAME LIKE '%_HIST%' /*조회할 Table명*/
--   AND a.TABLE_NAME = 'AM_CARDCONFMDTALSRECPT' /*조회할 Table명*/
--   AND b.COMMENTS LIKE '%원천징수%' /*조회할 Table명*/
--   AND a.TABLE_NAME  = 'AM_SLIP_WRT_M'
--   AND a.COLUMN_NAME LIKE '%ACNUT_NM_DIV_CD%'
--    AND c.COMMENTS LIKE '%통화%코드%'
--   AND a.column_name NOT LIKE '%#_%'ESCAPE'#'
-- ORDER BY a.TABLE_NAME
--     , a.COLUMN_ID
ORDER BY a.TABLE_NAME
    , a.COLUMN_ID
--    , a.COLUMN_NAME 
;

oracle dml 문장 생성 1

WITH tempTbl AS (
    SELECT a.COLUMN_ID AS colId 
         , a.COLUMN_NAME AS colName
         , LOWER(SUBSTR(REPLACE(INITCAP(a.COLUMN_NAME),'_'),1,1))||SUBSTR(REPLACE(INITCAP(a.COLUMN_NAME),'_'),2,LENGTH(a.COLUMN_NAME)-1) AS camel 
         , ('/*'||c.COMMENTS || ','|| a.DATA_TYPE ||'('||a.DATA_LENGTH ||')'||'*/') AS cmt
         , ('/*'||c.COMMENTS ||'*/') AS cmt2
         , c.COMMENTS AS orgCmt
         , a.DATA_TYPE AS dataType
         , a.DATA_LENGTH AS dataLen
      FROM ALL_TAB_COLUMNS a
      LEFT OUTER JOIN ALL_COL_COMMENTS c
        ON a.OWNER = c.OWNER
       AND a.TABLE_NAME = c.TABLE_NAME
       AND a.COLUMN_NAME = c.COLUMN_NAME
     WHERE a.OWNER = 'SEMA_ERP'
       AND a.TABLE_NAME IN ('AM_CMMN_COSTPT_D') /*조회할 Table명*/
--       AND a.COLUMN_NAME IN ('COMPANY_CODE','BANK_NO_SEQ','BANK_NO','BANK_DIV','CUST_CODE','DEPOSIT_OWNER','USE_YN','DEPT_CODE','APL_STR_DTE'
--                            ,'APL_END_DTE','FUND_CHK_YN','FUND_CHK_NOTE','FUND_CHK_YN_B','BANK_RES_CODE','BANK_RES_DESC','INPUT_DATE','INPUT_DUTY_ID'
--                            ,'CHG_DATE','CHG_DUTY_ID'
--       )
)
SELECT MAX(aa.ommType) AS ommType
     , MAX(aa.colId) AS colId
     , aa.ommName
     , MAX(aa.ommDescription) AS ommDescription
     , MAX(aa.ommLength) AS ommLength
     , (MAX(aa.ommType)||' '||aa.ommName||'<length='||MAX(aa.ommLength)||' description="'||MAX(aa.ommDescription)||'">;') AS ommGenStr
     , MAX(aa.dmlStr) AS dmlStr
     , MAX(aa.dmlStr2) AS dmlStr2
  FROM (
        SELECT CASE WHEN a.dataType IN ('VARCHAR2') THEN 'String' 
                    WHEN a.dataType IN ('DATE') THEN 'Date'
                    WHEN a.dataType IN ('NUMBER') AND a.dataLen < 10 THEN 'Integer'
                    WHEN a.dataType IN ('NUMBER') AND a.dataLen >= 10 THEN 'BigDecimal'
               END ommType
             , a.camel AS ommName
             , a.orgCmt AS ommDescription
             , a.dataLen AS ommLength
             , a.colId 
             , (', '||RPAD(a.colName, b.maxLenCol, ' ') ||' AS '||RPAD(a.camel, b.maxLenCmt,' ')||' '||a.cmt) AS dmlStr
             , (', '||RPAD(a.colName, b.maxLenCol, ' ') ||' '||a.cmt2) AS dmlStr2
          FROM tempTbl a
         OUTER APPLY( SELECT MAX(LENGTHB(colName)) AS maxLenCol
                           , MAX(LENGTHB(camel)) AS maxLenCmt 
                        FROM tempTbl
                    ) b  
       ) aa
 GROUP BY aa.ommName
-- ORDER BY aa.ommName
 ORDER BY MAX(aa.colId)
-- ORDER BY MAX(aa.ommName)

Nexacro transaction시 동적 dataset 지정

this.dsEdcRptsResult = new Dataset();  //기안 상신 결과
this.dsEdcRptsResult.set_name("dsEdcRptsResult");
this.gf_ErpEdcRptsCall = function(pSetting) {

  var sIfJobDivCd = pSetting.ifJobDivCd;
  var sIfTrkey = pSetting.ifTrkey;
  var sAppId = pSetting.appId;
  var sEdcFormId = pSetting.edcFormId;
  var sEdcTitle = pSetting.edcTitle;
  var sEdcContent1 = pSetting.edcContent1;
  var sEdcContent2 = this.gf_Nvl(pSetting.edcContent2,"");
  var sUserId = this.gf_Nvl(pSetting.userId, this.gf_ErpGetUserInfo().userId);
  var sDeptCode = this.gf_Nvl(pSetting.deptCode, this.gf_ErpGetUserInfo().deptCode);
  var sSiteCode = this.gf_Nvl(pSetting.siteCode, this.gf_ErpGetUserInfo().siteCode);
  var sCompanyCode = this.gf_Nvl(pSetting.companyCode, this.gf_ErpGetUserInfo().companyCode);
  
  var inDs = new Dataset();
  inDs.addColumn("ifJobDivCd","string");
  inDs.addColumn("ifTrkey","string");
  inDs.addColumn("appId","string");
  inDs.addColumn("edcFormId","string");
  inDs.addColumn("edcTitle","string");
  inDs.addColumn("edcContent1","string");
  inDs.addColumn("edcContent2","string");
  inDs.addColumn("userId","string");
  inDs.addColumn("deptCode","string");
  inDs.addColumn("siteCode","string");
  inDs.addColumn("companyCode","string");
  inDs.addRow();
  inDs.set_name("inDs");
  
  inDs.setColumn(0,"ifJobDivCd", sIfJobDivCd);
  inDs.setColumn(0,"ifTrkey", sIfTrkey);
  inDs.setColumn(0,"appId", sAppId);
  inDs.setColumn(0,"edcFormId", sEdcFormId);
  inDs.setColumn(0,"edcTitle", sEdcTitle);
  inDs.setColumn(0,"edcContent1", sEdcContent1);
  inDs.setColumn(0,"edcContent2", sEdcContent2);
  inDs.setColumn(0,"userId", sUserId);
  inDs.setColumn(0,"deptCode", sDeptCode);
  inDs.setColumn(0,"siteCode", sSiteCode);
  inDs.setColumn(0,"companyCode", sCompanyCode);
  
  var strInDs = "ds_input_" + this.gf_GetRandomKey();
  var strOutDs = "ds_ouput_" + this.gf_GetRandomKey();
  this.addChild(strInDs, inDs);
  this.addChild(strOutDs, this.dsEdcRptsResult);
  
  var sInDataset  = "_IN_ROOT_="+strInDs;
  var sOutDataset = strOutDs+"=_OUT_ROOT_";
  
  this.gf_ErpTransaction("SSMCMMSVC", "SSMCMMSVC002", sInDataset, sOutDataset, "gf_ErpCallback");
  
};

grid column중 dataset과 bind된 column의 edit max length 설정.

/*----------------------------------------------------------------------------------------------
 * 설명     : grid column중 dataset과 bind된 column의 edit max length 설정.
 * 파라미터 : pGridArray : (필수) 대상 grid array
 * 리턴값    : N/A
-----------------------------------------------------------------------------------------------*/
this.gf_ErpSetGridColMaxLength = function(pGridArray) {
  
  var nEditMaxLength = -1;
  var sBindCol = "";
  var oOuter = this;
  
  if(this.gf_IsNull(pGridArray)) return;
  
  pGridArray.forEach(function(tGrid, idx) {
    for(var nCol = 0; nCol < tGrid.getFormatColCount(); nCol++) {
      try {
        sBindCol = tGrid._getBodyCellInfo(nCol).text._bindexpr;
        if( !oOuter.gf_IsNull(sBindCol) ) {
          nEditMaxLength = tGrid.bindDS.getColumnInfo(sBindCol).size;
          tGrid.setCellProperty("body",nCol,"editmaxlength",nEditMaxLength);
        };
      } catch(e){};
    };
  });
};
사용예)
this.gf_ErpSetGridColMaxLength([this.tab_subDetail.tap_subDetail1.form.grd_SSMCODE37113Out01, 
                                  this.tab_subDetail.tap_subDetail2.form.grd_SSMCODE37113Out02,
                  this.tab_subDetail.tap_subDetail3.form.grd_SSMCODE37113Out03,
                  this.tab_subDetail.tap_subDetail4.form.grd_SSMCODE37113Out04,
                  this.tab_subDetail.tap_subDetail5.form.grd_SSMCODE37113Out05]);

nexacro dataset과 bind된 component의 max length 설정.

/*----------------------------------------------------------------------------------------------
 * 설명     : dataset과 bind된 component의 max length 설정.
 * 파라미터 : pForm : (필수) form object. 보통 this를 넘기면 됨.
 * 리턴값    : N/A
-----------------------------------------------------------------------------------------------*/
this.gf_ErpSetBindCompMaxLength = function(pForm) {
  var sColId = "";
  var aBindList = pForm.binds;
  for( var nIdx = 0; nIdx < aBindList.length; nIdx++ ){
    sColId = aBindList[nIdx].columnid;
    try {
      if( !this.gf_IsNull(aBindList[nIdx]._dataset) && !this.gf_IsNull(aBindList[nIdx]._comp.maxlength) ) {
        for( var nCol = 0; nCol < aBindList[nIdx]._dataset.colinfos.length; nCol++ ) {
          if( sColId == aBindList[nIdx]._dataset.colinfos[nCol].id ) {
            aBindList[nIdx]._comp.set_maxlength(aBindList[nIdx]._dataset.colinfos[nCol].size);
          };
        };
      };
    } catch(e) {
      this.gf_Trace("["+sColId+"] : " + e.message);
    };
  };
};
사용예)
this.gf_ErpSetBindCompMaxLength(this);