Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mlpt.bvnextgen.generatePDLGD.generateLGD.CallProcedure;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import org.hibernate.FlushMode;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.json.simple.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.mlpt.bvnextgen.MasterGeneralConstants;
- import com.mlpt.bvnextgen.PDGenerator.MigrateLPHIRThreading;
- import com.mlpt.bvnextgen.annotation.Info;
- import com.mlpt.bvnextgen.annotation.InfoIn;
- import com.mlpt.bvnextgen.annotation.InfoOut;
- import com.mlpt.bvnextgen.dao.ConfigurationDao;
- import com.mlpt.bvnextgen.dao.TableLPHIRDao;
- import com.mlpt.bvnextgen.procedureSQL.CallProcedure;
- @InfoIn(value = {
- })
- @InfoOut(value = {
- @Info(name = "status", description = "status", type = "String.class"),
- @Info(name = "errorMessage", description = "error Message", type = "String.class") })
- @Service
- public class CallLWOBLX_LPHIR {
- @Autowired
- ConfigurationDao configureDao;
- @Autowired
- CallProcedure procedureCall;
- @Autowired
- TableLPHIRDao tableLphir;
- // @Autowired
- // MigrateLPHIRThreading migrateLPHIRThreading;
- Session session;
- @Autowired
- private SessionFactory sessionFactory;
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
- @SuppressWarnings("unchecked")
- public JSONObject processBo(JSONObject serviceInput) {
- session = sessionFactory.openSession();
- session.setFlushMode(FlushMode.MANUAL);
- JSONObject resultOutput = new JSONObject();
- String errorMessage = "";
- List<Map<String, String>> parameter = new ArrayList<Map<String, String>>();
- Map<String, String> configure = new HashMap<String, String>();
- String period = String.valueOf(serviceInput.get("period"));
- String status = "";
- try {
- // -----------------------------------------------------
- // 0. LPHIR
- System.out.println("LPHIR");
- // yymm
- String lpperdLHPIR = period.substring(2, 4)+ period.substring(4, 6);
- // mmyy
- String lpperdBV = period.substring(4, 6) + period.substring(2, 4);
- System.out.println("lpperdBV : " + lpperdBV);
- System.out.println("lpperdLHPIR : " + lpperdLHPIR);
- // serviceInput.put("periodeBV", lpperdBV);
- // serviceInput.put("periodeLPHIR", lpperdLHPIR);
- // System.out.println("serviceInput : "+serviceInput.toString());
- List<Long> getMaxPeriode = new ArrayList<Long>();
- Query findMaxPeriode = tableLphir
- .createQuery("Select max(periode) "
- + "from com.mlpt.bvnextgen.entity.lphir ");
- getMaxPeriode = findMaxPeriode.list();
- System.out.println("INI max periode : " + getMaxPeriode.get(0));
- System.out.println("INI PERIODE DARI parameter : "
- + Long.valueOf(lpperdLHPIR));
- Long maxPeriode = getMaxPeriode.get(0).longValue();
- if (null == maxPeriode) {
- System.out.println("Pertama kali");
- callProcedureMigrateLPHIR(lpperdBV, lpperdLHPIR);
- // migrateLPHIRThreading.processBo(serviceInput);
- status = "S";
- } else if (Long.valueOf(lpperdLHPIR) < maxPeriode) {
- System.out.println("LEBIH KECIL");
- status = "F";
- resultOutput.put("status", status);
- return resultOutput;
- } else if (Long.valueOf(lpperdLHPIR) == (maxPeriode + 2)) {
- System.out.println("Longkap 2 gak boleh");
- status = "F";
- resultOutput.put("status", status);
- resultOutput.put("errorMessage",
- "Migrate only valid for the next month from : "
- + (maxPeriode + 200000));
- return resultOutput;
- } else {
- System.out.println("LEBIH BESAR");
- callProcedureMigrateLPHIR(lpperdBV, lpperdLHPIR);
- // migrateLPHIRThreading.processBo(serviceInput);
- status = "S";
- }
- // -----------------------------------------------------
- // 1. LWOBLX_ST1
- JSONObject periodLGD = calculatePeriodLGD(period);
- System.out.println("LWOBLX_ST1");
- String periodNow = String.valueOf(periodLGD.get("periodST1"));
- System.out.println("periodNow : " + periodNow);
- // flush the MAP
- configure = new HashMap<String, String>();
- // --------------SETTING PARAMETER----------------------------//
- configure.put("parameterName", MasterGeneralConstants.PERIOD);
- configure.put("parameterValue", periodNow);
- parameter.add(configure);
- procedureCall.callProcedure(MasterGeneralConstants.LWOBLX_ST1,parameter);
- // -------------------------------------------------------------//
- // 2. LWOBLX_ST3
- System.out.println("LWOBLX_ST3");
- String period5YearsAgoStr = String.valueOf(periodLGD.get("periodST3"));
- System.out.println("period5YearsAgoStr : " + period5YearsAgoStr);
- Query findDHWROF = session.createSQLQuery(" Select count(1) From DHWROF ");
- Long countDHWROF = Long.valueOf(String.valueOf(findDHWROF.uniqueResult()));
- session.flush();
- System.out.println("countDHWROF : " + countDHWROF);
- // FLUSH the LIST AND MAP
- if (countDHWROF > 0) {
- // FLUSH the LIST AND MAP
- configure = new HashMap<String, String>();
- parameter = new ArrayList<Map<String, String>>();
- // --------------SETTING PARAMETER----------------------------//
- configure.put("parameterName", MasterGeneralConstants.PERIOD);
- configure.put("parameterValue", period5YearsAgoStr);
- parameter.add(configure);
- // -------------------------------------------------------------//
- procedureCall.callProcedure(MasterGeneralConstants.LWOBLX_ST3,parameter);
- }
- resultOutput.put("status", "S");
- } catch (Exception e) {
- e.printStackTrace();
- errorMessage = e.getCause().toString();
- errorMessage = errorMessage.substring(
- (errorMessage.indexOf(':') + 1), errorMessage.length());
- errorMessage = errorMessage.trim();
- resultOutput.put("status", "F");
- resultOutput.put("errorMessage", errorMessage);
- return resultOutput;
- }
- return resultOutput;
- }
- public JSONObject calculatePeriodLGD(String period) {
- List<Object> resultList = new ArrayList<Object>();
- Integer periodAktif = 0;
- JSONObject returnPeriod = new JSONObject();
- try {
- Query inquireLGDConfig = configureDao
- .createQuery("Select id, subconfig, configValue "
- + "from com.mlpt.bvnextgen.entity.Configuration "
- + "where active = :active and configMenu = :configMenu");
- inquireLGDConfig.setParameter("active",
- MasterGeneralConstants.ACTIVATE);
- inquireLGDConfig.setParameter("configMenu", "LGD");
- resultList = inquireLGDConfig.list();
- configureDao.closeSessionCreateQuery();
- Iterator iter = resultList.iterator();
- while (iter.hasNext()) {
- Object[] obj = (Object[]) iter.next();
- JSONObject config = new JSONObject();
- Long id = (Long) obj[0];
- String subconfig = (String) obj[1];
- String configValue = (String) obj[2];
- if (subconfig.equals("CalculateActiveStatus")) {
- periodAktif = Integer.valueOf(configValue);
- }
- }
- Integer periodNowInt = Integer.valueOf(period);
- Integer periodStartInt = periodNowInt - (periodAktif * 100);
- String tempYearMonth = periodStartInt.toString();
- String tempYear = tempYearMonth.substring(0, 4);
- String tempMonth = tempYearMonth.substring(4, 6);
- System.out.println("Temp Year >>>>>>>>>>>>>>>>>>>>>>>>>>: "
- + tempYear);
- System.out.println("Temp Month >>>>>>>>>>>>>>>>>>>>>>>>>>: "
- + tempMonth);
- System.out.println("Temp Year Month >>>>>>>>>>>>>>>>>>>>>>>> : "
- + tempYearMonth);
- if (Integer.valueOf(tempMonth) > 12) {
- tempMonth = "01";
- Integer yearAdd = Integer.valueOf(tempYear) + 1;
- tempYear = yearAdd.toString();
- }
- String period5YearsAgo = String.valueOf(tempYear.concat(tempMonth));
- String newPeriod5YearsAgo = period5YearsAgo.substring(4).concat(
- period5YearsAgo.substring(2, 4));
- String periodNow = period.substring(4).concat(
- period.substring(2, 4));
- returnPeriod.put("periodST1", periodNow);
- returnPeriod.put("periodST3", newPeriod5YearsAgo);
- return returnPeriod;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public String callProcedureMigrateLPHIR(String periode, String lpperd) {
- String periodd = periode.toString();
- String tempYear = periodd.substring(2, 4);
- String tempMonth = periodd.substring(4, 6);
- String per = tempMonth + "" + tempYear;
- System.out.println("perip : " + per);
- session = sessionFactory.openSession();
- session.setFlushMode(FlushMode.MANUAL);
- String outputResult = "";
- // String nama = "Lonely Camper";
- Query query = session
- .createSQLQuery("CALL p_migrate_lphir(:per,:lpperd)");
- query.setParameter("per", per);
- query.setParameter("lpperd", lpperd);
- Integer hasil = query.executeUpdate();
- System.out.println("Hasil call procedure : " + hasil);
- return outputResult;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement