Advertisement
aadddrr

DoProcessTrxReceiveLogServiceDoProcessTrxReceiveLogService

Dec 27th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.46 KB | None | 0 0
  1. package org.jleaf.pos.services.data;
  2.  
  3. import java.io.PrintWriter;
  4. import java.io.StringWriter;
  5. import java.util.List;
  6.  
  7. import org.jleaf.erp.master.MasterConstants;
  8. import org.jleaf.pos.PosBoConstants;
  9. import org.jleaf.pos.PosBoExceptionConstants;
  10. import org.jleaf.pos.services.AbstractPosJleafService;
  11. import org.jleaf.baseservices.util.ServiceUtil;
  12. import org.jleaf.core.CoreException;
  13. import org.jleaf.core.Dto;
  14. import org.jleaf.core.GeneralConstants;
  15. import org.jleaf.core.annotation.Info;
  16. import org.jleaf.core.annotation.InfoIn;
  17. import org.jleaf.core.annotation.InfoOut;
  18. import org.jleaf.core.annotation.ServiceDoc;
  19. import org.jleaf.util.DateUtil;
  20.  
  21. /**
  22.  * Do process trx receive log
  23.  *
  24.  * @author WTC, Jun 2, 2013
  25.  * @version 1.0.0
  26.  */
  27. @ServiceDoc
  28. //@formatter:off
  29. @InfoIn(value = {
  30.         @Info(name = "result.header.userLoginId", description = "user login id", type = Long.class),
  31.         @Info(name = "result.header.roleLoginId", description = "role login id", type = Long.class),
  32.         @Info(name = "result.header.tenantLoginId", description = "tenant login id", type = Long.class),
  33.         @Info(name = "result.header.datetime", description = "datetime", type = String.class),
  34.         @Info(name = "result.header.sessionId", description = "session id", type = String.class),
  35.         @Info(name = "result.header.secureKey", description = "secure key", type = String.class),
  36.         @Info(name = "result.header.taskName", description = "task name", type = String.class),
  37.         @Info(name = "result.payload.tenantId", description = "tenant id", type = Long.class)
  38. })
  39. @InfoOut(value = { })
  40. //@formatter:on
  41. public class DoProcessTrxReceiveLogService extends AbstractPosJleafService {
  42.  
  43.     @Override
  44.     public String getTaskName() {
  45.         return "doProcessTrxReceiveLog";
  46.     }
  47.  
  48.     @SuppressWarnings("unchecked")
  49.     @Override
  50.     public Dto process(Dto inputDto) throws Exception {
  51.         // Declaring Variables
  52.         Dto inputDtoForCheckSysConfigValue;
  53.         Dto outputDtoForCheckSysConfigValue;
  54.         Dto inputDtoForFindParameterByIndex = null;
  55.         Dto outputDtoForFindParameterByIndex = null;
  56.         Dto inputDtoForValDoProcessTrxReceiveLog = null;
  57.         Dto inputDtoForFindLatestTrxRcvLogByFlgProcess = null;
  58.         Dto outputDtoForFindLatestTrxRcvLogByFlgProcess = null;
  59.         Dto inputDtoForGetTrxRcvDataLogListByTrxRcvLogId = null;
  60.         Dto outputDtoForGetTrxRcvDataLogListByTrxRcvLogId = null;
  61.         Dto inputDtoForProcessTrxDataLog = null;
  62.         Dto inputDtoForEditTrxRcvDataLog = null;
  63.         Dto inputDtoForEditTrxRcvLog = null;
  64.         Dto inputDtoForEditLastDataOutlet = null;
  65.  
  66.         // Validating Input Variables
  67.         ServiceUtil.valNullParams(inputDto, "result.header.userLoginId", "result.header.roleLoginId", "result.payload.tenantId");
  68.  
  69.         // Validate this outlet is activated
  70.         inputDtoForCheckSysConfigValue = new Dto();
  71.         inputDtoForCheckSysConfigValue.put("tenantId", Long.parseLong(inputDto.getString("result.header.tenantLoginId")));
  72.         inputDtoForCheckSysConfigValue.put("parameterCode", PosBoConstants.PARAM_ACTIVE_DATE_TIME);
  73.         inputDtoForCheckSysConfigValue.put("value", GeneralConstants.SPACE_VALUE);
  74.         outputDtoForCheckSysConfigValue = getBusinessFunction("isMatchSystemConfigValueByParameterCode").execute(inputDtoForCheckSysConfigValue);
  75.         if (outputDtoForCheckSysConfigValue.getBoolean("isTrue"))
  76.             throw new CoreException(PosBoExceptionConstants.VAL_OUTLET_ACTIVE);
  77.  
  78.         // Preparing
  79.         Long userLoginId = Long.valueOf(inputDto.getString("result.header.userLoginId"));
  80.         Long roleLoginId = Long.valueOf(inputDto.getString("result.header.roleLoginId"));
  81.         Long tenantId = Long.valueOf(inputDto.getString("result.payload.tenantId"));
  82.  
  83.         // Get parameter ouId  from master parameter
  84.         inputDtoForFindParameterByIndex = new Dto();
  85.         inputDtoForFindParameterByIndex.put("tenantId", tenantId);
  86.         inputDtoForFindParameterByIndex.put("parameterCode", PosBoConstants.PARAM_OU_ID);
  87.         outputDtoForFindParameterByIndex = getBusinessFunction("findSystemConfigByParamCode").execute(
  88.                 inputDtoForFindParameterByIndex);
  89.         Long ouId = Long.valueOf(outputDtoForFindParameterByIndex.getString("value"));
  90.  
  91.         // Check is user can do process receive log
  92.         inputDtoForValDoProcessTrxReceiveLog = new Dto();
  93.         inputDtoForValDoProcessTrxReceiveLog.put("tenantId", tenantId);
  94.         inputDtoForValDoProcessTrxReceiveLog.put("ouId", ouId);
  95.         getBusinessFunction("valDoProcessTrxReceiveLog").execute(inputDtoForValDoProcessTrxReceiveLog);
  96.  
  97.         // Find latest receive log that not be processed yet
  98.         inputDtoForFindLatestTrxRcvLogByFlgProcess = new Dto();
  99.         inputDtoForFindLatestTrxRcvLogByFlgProcess.put("tenantId", tenantId);
  100.         inputDtoForFindLatestTrxRcvLogByFlgProcess.put("ouId", ouId);
  101.         inputDtoForFindLatestTrxRcvLogByFlgProcess.put("flgProcess", GeneralConstants.NO);
  102.         outputDtoForFindLatestTrxRcvLogByFlgProcess = getBusinessFunction("findLatestTrxRcvLogByFlgProcess").execute(
  103.                 inputDtoForFindLatestTrxRcvLogByFlgProcess);
  104.  
  105.         Long trxRcvLogId = outputDtoForFindLatestTrxRcvLogByFlgProcess.getLong("id");
  106.  
  107.         // Get Receive Data Log
  108.         inputDtoForGetTrxRcvDataLogListByTrxRcvLogId = new Dto();
  109.         inputDtoForGetTrxRcvDataLogListByTrxRcvLogId.put("trxRcvLogId", trxRcvLogId);
  110.         outputDtoForGetTrxRcvDataLogListByTrxRcvLogId = getBusinessFunction("getTrxRcvDataLogListByTrxRcvLogId").execute(
  111.                 inputDtoForGetTrxRcvDataLogListByTrxRcvLogId);
  112.  
  113.         List<Dto> rcvDataLogList = outputDtoForGetTrxRcvDataLogListByTrxRcvLogId.getList("trxRcvDataLogList");
  114.         boolean isContinue = true;
  115.         Long lastTrxDataLogId = 0L;
  116.         String nowDatetime;
  117.         for (Dto rcvDataLogDto : rcvDataLogList) {
  118.             String remark = GeneralConstants.EMPTY_VALUE;
  119.  
  120.             try {
  121.                 // Just do the process if there is no error on the process before
  122.                 if (isContinue) {
  123.                     lastTrxDataLogId = rcvDataLogDto.getLong("trxDataLogId");
  124.  
  125.                     // Preparing log (dbVersion;typeData;modeLog;dataLog)
  126.                     String log = rcvDataLogDto.getString("dbVersion").concat(MasterConstants.LOG_DATA_SEPARATOR)
  127.                             .concat(rcvDataLogDto.getString("typeData")).concat(MasterConstants.LOG_DATA_SEPARATOR)
  128.                             .concat(rcvDataLogDto.getString("modeLog")).concat(MasterConstants.LOG_DATA_SEPARATOR)
  129.                             .concat(rcvDataLogDto.getString("dataLog"));
  130.  
  131.                     // Processing detail data
  132.                     inputDtoForProcessTrxDataLog = new Dto();
  133.                     inputDtoForProcessTrxDataLog.put("log", log);
  134.                     inputDtoForProcessTrxDataLog.put("userLoginId", userLoginId);
  135.                     inputDtoForProcessTrxDataLog.put("datetime", inputDto.get("result.header.datetime"));
  136.                     getBusinessTransaction("processTrxDataLog").execute(inputDtoForProcessTrxDataLog);
  137.                 }
  138.             } catch (Exception e) {
  139.                 e.printStackTrace();
  140.  
  141.                 // Give the flag false when there is error
  142.                 isContinue = false;
  143.                 remark = getFullPrintStackTrace(e).substring(0, 1000);
  144.             } finally {
  145.                 nowDatetime = DateUtil.dateTimeNow();
  146.  
  147.                 // Edit flag in receive data log to Success
  148.                 inputDtoForEditTrxRcvDataLog = new Dto();
  149.                 inputDtoForEditTrxRcvDataLog.put("id", rcvDataLogDto.getLong("id"));
  150.                 inputDtoForEditTrxRcvDataLog.put("flgProcess", isContinue ? GeneralConstants.YES : GeneralConstants.FAIL);
  151.                 inputDtoForEditTrxRcvDataLog.put("processDatetime", nowDatetime);
  152.                 inputDtoForEditTrxRcvDataLog.put("processUserId", userLoginId);
  153.                 inputDtoForEditTrxRcvDataLog.put("remark", remark);
  154.                 inputDtoForEditTrxRcvDataLog.put("version", rcvDataLogDto.getLong("version"));
  155.                 inputDtoForEditTrxRcvDataLog.put("userLoginId", userLoginId);
  156.                 inputDtoForEditTrxRcvDataLog.put("roleLoginId", roleLoginId);
  157.                 inputDtoForEditTrxRcvDataLog.put("tenantLoginId", tenantId);
  158.                 inputDtoForEditTrxRcvDataLog.put("datetime", nowDatetime);
  159.  
  160.                 getBusinessTransaction("editTrxRcvDataLog").execute(inputDtoForEditTrxRcvDataLog);
  161.  
  162.                 if (!isContinue) {
  163.                     break;
  164.                 }
  165.             }
  166.         }
  167.  
  168.         nowDatetime = DateUtil.dateTimeNow();
  169.  
  170.         // Change Header Receive Log
  171.         inputDtoForEditTrxRcvLog = new Dto();
  172.         inputDtoForEditTrxRcvLog.put("id", trxRcvLogId);
  173.         inputDtoForEditTrxRcvLog.put("flgProcess", isContinue ? GeneralConstants.YES : GeneralConstants.FAIL);
  174.         inputDtoForEditTrxRcvLog.put("processDatetime", nowDatetime);
  175.         inputDtoForEditTrxRcvLog.put("processUserId", userLoginId);
  176.         inputDtoForEditTrxRcvLog.put("remark", isContinue ? GeneralConstants.EMPTY_VALUE : lastTrxDataLogId);
  177.         inputDtoForEditTrxRcvLog.put("version", outputDtoForFindLatestTrxRcvLogByFlgProcess.getLong("version"));
  178.         inputDtoForEditTrxRcvLog.put("userLoginId", userLoginId);
  179.         inputDtoForEditTrxRcvLog.put("roleLoginId", roleLoginId);
  180.         inputDtoForEditTrxRcvLog.put("tenantLoginId", tenantId);
  181.         inputDtoForEditTrxRcvLog.put("datetime", nowDatetime);
  182.         getBusinessTransaction("editTrxRcvLog").execute(inputDtoForEditTrxRcvLog);
  183.  
  184.         // Change Last Data log Id
  185.         inputDtoForEditLastDataOutlet = new Dto();
  186.         inputDtoForEditLastDataOutlet.put("ouId", ouId);
  187.         inputDtoForEditLastDataOutlet.put("trxDataLogId", lastTrxDataLogId);
  188.         inputDtoForEditLastDataOutlet.put("userLoginId", userLoginId);
  189.         inputDtoForEditLastDataOutlet.put("roleLoginId", roleLoginId);
  190.         inputDtoForEditLastDataOutlet.put("tenantLoginId", tenantId);
  191.         inputDtoForEditLastDataOutlet.put("datetime", nowDatetime);
  192.         getBusinessTransaction("editLastDataOutletOfTrx").execute(inputDtoForEditLastDataOutlet);
  193.  
  194.         return null;
  195.     }
  196.    
  197.     /**
  198.      * Get Full Stack Trace in String
  199.      *
  200.      * http://stackoverflow.com/questions/4812570/how-to-store-printstacktrace-into-a-string
  201.      * @param ex
  202.      * @return
  203.      */
  204.     private String getFullPrintStackTrace(Throwable ex) {
  205.         StringWriter errors = new StringWriter();
  206.         ex.printStackTrace(new PrintWriter(errors));
  207.         return errors.toString();
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement