Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.02 KB | None | 0 0
  1. package com.mlpt.bvnextgen.generatePDLGD.generateLGD.CallProcedure;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Map;
  8.  
  9. import org.hibernate.FlushMode;
  10. import org.hibernate.Query;
  11. import org.hibernate.Session;
  12. import org.hibernate.SessionFactory;
  13. import org.json.simple.JSONObject;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16.  
  17. import com.mlpt.bvnextgen.MasterGeneralConstants;
  18. import com.mlpt.bvnextgen.PDGenerator.MigrateLPHIRThreading;
  19. import com.mlpt.bvnextgen.annotation.Info;
  20. import com.mlpt.bvnextgen.annotation.InfoIn;
  21. import com.mlpt.bvnextgen.annotation.InfoOut;
  22. import com.mlpt.bvnextgen.dao.ConfigurationDao;
  23. import com.mlpt.bvnextgen.dao.TableLPHIRDao;
  24. import com.mlpt.bvnextgen.procedureSQL.CallProcedure;
  25.  
  26. @InfoIn(value = {
  27.  
  28. })
  29. @InfoOut(value = {
  30. @Info(name = "status", description = "status", type = "String.class"),
  31. @Info(name = "errorMessage", description = "error Message", type = "String.class") })
  32. @Service
  33. public class CallLWOBLX_LPHIR {
  34. @Autowired
  35. ConfigurationDao configureDao;
  36.  
  37. @Autowired
  38. CallProcedure procedureCall;
  39.  
  40. @Autowired
  41. TableLPHIRDao tableLphir;
  42.  
  43. // @Autowired
  44. // MigrateLPHIRThreading migrateLPHIRThreading;
  45.  
  46. Session session;
  47.  
  48. @Autowired
  49. private SessionFactory sessionFactory;
  50.  
  51. public SessionFactory getSessionFactory() {
  52. return sessionFactory;
  53. }
  54.  
  55. public void setSessionFactory(SessionFactory sessionFactory) {
  56. this.sessionFactory = sessionFactory;
  57. }
  58.  
  59. @SuppressWarnings("unchecked")
  60. public JSONObject processBo(JSONObject serviceInput) {
  61.  
  62. session = sessionFactory.openSession();
  63. session.setFlushMode(FlushMode.MANUAL);
  64.  
  65. JSONObject resultOutput = new JSONObject();
  66.  
  67. String errorMessage = "";
  68.  
  69. List<Map<String, String>> parameter = new ArrayList<Map<String, String>>();
  70. Map<String, String> configure = new HashMap<String, String>();
  71.  
  72. String period = String.valueOf(serviceInput.get("period"));
  73. String status = "";
  74.  
  75. try {
  76.  
  77. // -----------------------------------------------------
  78. // 0. LPHIR
  79. System.out.println("LPHIR");
  80. // yymm
  81. String lpperdLHPIR = period.substring(2, 4)+ period.substring(4, 6);
  82. // mmyy
  83. String lpperdBV = period.substring(4, 6) + period.substring(2, 4);
  84. System.out.println("lpperdBV : " + lpperdBV);
  85. System.out.println("lpperdLHPIR : " + lpperdLHPIR);
  86.  
  87. // serviceInput.put("periodeBV", lpperdBV);
  88. // serviceInput.put("periodeLPHIR", lpperdLHPIR);
  89. // System.out.println("serviceInput : "+serviceInput.toString());
  90.  
  91. List<Long> getMaxPeriode = new ArrayList<Long>();
  92.  
  93. Query findMaxPeriode = tableLphir
  94. .createQuery("Select max(periode) "
  95. + "from com.mlpt.bvnextgen.entity.lphir ");
  96. getMaxPeriode = findMaxPeriode.list();
  97.  
  98. System.out.println("INI max periode : " + getMaxPeriode.get(0));
  99. System.out.println("INI PERIODE DARI parameter : "
  100. + Long.valueOf(lpperdLHPIR));
  101.  
  102. Long maxPeriode = getMaxPeriode.get(0).longValue();
  103.  
  104. if (null == maxPeriode) {
  105. System.out.println("Pertama kali");
  106. callProcedureMigrateLPHIR(lpperdBV, lpperdLHPIR);
  107. // migrateLPHIRThreading.processBo(serviceInput);
  108. status = "S";
  109. } else if (Long.valueOf(lpperdLHPIR) < maxPeriode) {
  110. System.out.println("LEBIH KECIL");
  111. status = "F";
  112. resultOutput.put("status", status);
  113. return resultOutput;
  114. } else if (Long.valueOf(lpperdLHPIR) == (maxPeriode + 2)) {
  115. System.out.println("Longkap 2 gak boleh");
  116. status = "F";
  117. resultOutput.put("status", status);
  118. resultOutput.put("errorMessage",
  119. "Migrate only valid for the next month from : "
  120. + (maxPeriode + 200000));
  121. return resultOutput;
  122. } else {
  123. System.out.println("LEBIH BESAR");
  124. callProcedureMigrateLPHIR(lpperdBV, lpperdLHPIR);
  125. // migrateLPHIRThreading.processBo(serviceInput);
  126. status = "S";
  127. }
  128.  
  129. // -----------------------------------------------------
  130. // 1. LWOBLX_ST1
  131. JSONObject periodLGD = calculatePeriodLGD(period);
  132. System.out.println("LWOBLX_ST1");
  133.  
  134. String periodNow = String.valueOf(periodLGD.get("periodST1"));
  135. System.out.println("periodNow : " + periodNow);
  136.  
  137. // flush the MAP
  138. configure = new HashMap<String, String>();
  139.  
  140. // --------------SETTING PARAMETER----------------------------//
  141. configure.put("parameterName", MasterGeneralConstants.PERIOD);
  142. configure.put("parameterValue", periodNow);
  143.  
  144. parameter.add(configure);
  145.  
  146. procedureCall.callProcedure(MasterGeneralConstants.LWOBLX_ST1,parameter);
  147.  
  148.  
  149. // -------------------------------------------------------------//
  150. // 2. LWOBLX_ST3
  151. System.out.println("LWOBLX_ST3");
  152. String period5YearsAgoStr = String.valueOf(periodLGD.get("periodST3"));
  153. System.out.println("period5YearsAgoStr : " + period5YearsAgoStr);
  154.  
  155. Query findDHWROF = session.createSQLQuery(" Select count(1) From DHWROF ");
  156. Long countDHWROF = Long.valueOf(String.valueOf(findDHWROF.uniqueResult()));
  157. session.flush();
  158.  
  159. System.out.println("countDHWROF : " + countDHWROF);
  160. // FLUSH the LIST AND MAP
  161. if (countDHWROF > 0) {
  162. // FLUSH the LIST AND MAP
  163. configure = new HashMap<String, String>();
  164. parameter = new ArrayList<Map<String, String>>();
  165.  
  166. // --------------SETTING PARAMETER----------------------------//
  167. configure.put("parameterName", MasterGeneralConstants.PERIOD);
  168. configure.put("parameterValue", period5YearsAgoStr);
  169.  
  170. parameter.add(configure);
  171.  
  172. // -------------------------------------------------------------//
  173. procedureCall.callProcedure(MasterGeneralConstants.LWOBLX_ST3,parameter);
  174. }
  175.  
  176. resultOutput.put("status", "S");
  177.  
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180.  
  181. errorMessage = e.getCause().toString();
  182. errorMessage = errorMessage.substring(
  183. (errorMessage.indexOf(':') + 1), errorMessage.length());
  184. errorMessage = errorMessage.trim();
  185.  
  186. resultOutput.put("status", "F");
  187. resultOutput.put("errorMessage", errorMessage);
  188.  
  189. return resultOutput;
  190. }
  191.  
  192. return resultOutput;
  193.  
  194. }
  195.  
  196. public JSONObject calculatePeriodLGD(String period) {
  197.  
  198. List<Object> resultList = new ArrayList<Object>();
  199. Integer periodAktif = 0;
  200. JSONObject returnPeriod = new JSONObject();
  201.  
  202. try {
  203. Query inquireLGDConfig = configureDao
  204. .createQuery("Select id, subconfig, configValue "
  205. + "from com.mlpt.bvnextgen.entity.Configuration "
  206. + "where active = :active and configMenu = :configMenu");
  207. inquireLGDConfig.setParameter("active",
  208. MasterGeneralConstants.ACTIVATE);
  209. inquireLGDConfig.setParameter("configMenu", "LGD");
  210. resultList = inquireLGDConfig.list();
  211.  
  212. configureDao.closeSessionCreateQuery();
  213.  
  214. Iterator iter = resultList.iterator();
  215.  
  216. while (iter.hasNext()) {
  217. Object[] obj = (Object[]) iter.next();
  218. JSONObject config = new JSONObject();
  219.  
  220. Long id = (Long) obj[0];
  221.  
  222. String subconfig = (String) obj[1];
  223. String configValue = (String) obj[2];
  224. if (subconfig.equals("CalculateActiveStatus")) {
  225. periodAktif = Integer.valueOf(configValue);
  226. }
  227. }
  228.  
  229. Integer periodNowInt = Integer.valueOf(period);
  230. Integer periodStartInt = periodNowInt - (periodAktif * 100);
  231.  
  232. String tempYearMonth = periodStartInt.toString();
  233. String tempYear = tempYearMonth.substring(0, 4);
  234. String tempMonth = tempYearMonth.substring(4, 6);
  235. System.out.println("Temp Year >>>>>>>>>>>>>>>>>>>>>>>>>>: "
  236. + tempYear);
  237. System.out.println("Temp Month >>>>>>>>>>>>>>>>>>>>>>>>>>: "
  238. + tempMonth);
  239. System.out.println("Temp Year Month >>>>>>>>>>>>>>>>>>>>>>>> : "
  240. + tempYearMonth);
  241.  
  242. if (Integer.valueOf(tempMonth) > 12) {
  243. tempMonth = "01";
  244. Integer yearAdd = Integer.valueOf(tempYear) + 1;
  245. tempYear = yearAdd.toString();
  246. }
  247.  
  248. String period5YearsAgo = String.valueOf(tempYear.concat(tempMonth));
  249. String newPeriod5YearsAgo = period5YearsAgo.substring(4).concat(
  250. period5YearsAgo.substring(2, 4));
  251.  
  252. String periodNow = period.substring(4).concat(
  253. period.substring(2, 4));
  254.  
  255. returnPeriod.put("periodST1", periodNow);
  256. returnPeriod.put("periodST3", newPeriod5YearsAgo);
  257.  
  258. return returnPeriod;
  259.  
  260. } catch (Exception e) {
  261. e.printStackTrace();
  262.  
  263. return null;
  264. }
  265. }
  266.  
  267. public String callProcedureMigrateLPHIR(String periode, String lpperd) {
  268. String periodd = periode.toString();
  269. String tempYear = periodd.substring(2, 4);
  270. String tempMonth = periodd.substring(4, 6);
  271. String per = tempMonth + "" + tempYear;
  272. System.out.println("perip : " + per);
  273. session = sessionFactory.openSession();
  274. session.setFlushMode(FlushMode.MANUAL);
  275.  
  276. String outputResult = "";
  277. // String nama = "Lonely Camper";
  278.  
  279. Query query = session
  280. .createSQLQuery("CALL p_migrate_lphir(:per,:lpperd)");
  281.  
  282. query.setParameter("per", per);
  283. query.setParameter("lpperd", lpperd);
  284.  
  285. Integer hasil = query.executeUpdate();
  286.  
  287. System.out.println("Hasil call procedure : " + hasil);
  288.  
  289. return outputResult;
  290. }
  291.  
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement