Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.33 KB | None | 0 0
  1. package mega.loanoncardbulk.process;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7.  
  8. import mega.loanoncardbulk.dao.LoanOnCardDbDao;
  9. import mega.loanoncardbulk.utils.ConfigProperties;
  10. import mega.loanoncardbulk.utils.FileCreateManage;
  11. import mega.loanoncardbulk.utils.HTTPComponentPOST;
  12. import mega.loanoncardbulk.utils.UtilsHelper;
  13.  
  14. import org.apache.commons.codec.binary.Base64;
  15. import org.apache.commons.lang.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import org.mule.api.MuleContext;
  18. import org.mule.api.MuleEventContext;
  19. import org.mule.api.MuleMessage;
  20. import org.mule.api.lifecycle.Callable;
  21.  
  22.  
  23.  
  24. public class GetBulkDataProcess implements Callable {
  25. private String code = new String();
  26. Logger log = Logger.getLogger(LoanOnCardDbDao.class);
  27.  
  28. @Override
  29. public Object onCall(MuleEventContext eventContext) throws Exception {
  30. // TODO Auto-generated method stub
  31.  
  32. try {
  33. MuleContext muleContext = eventContext.getMuleContext();
  34. MuleMessage message = eventContext.getMessage();
  35. UtilsHelper util = new UtilsHelper();
  36. LoanOnCardDbDao db = (LoanOnCardDbDao) muleContext.getRegistry().lookupObject("mysqlDao");
  37. ConfigProperties configProperties = (ConfigProperties) muleContext.getRegistry().lookupObject("configProperties");
  38. FileCreateManage filemanage = new FileCreateManage();
  39.  
  40. HashMap<String, String> mftf_header = new HashMap<String, String>();
  41. mftf_header = db.getMftfHeader();
  42.  
  43. String file_code = mftf_header.get("name_file");
  44. String flagFl = mftf_header.get("flag");
  45. String acctdebt = mftf_header.get("acct_debt");
  46. String srcbranch = mftf_header.get("src_branch");
  47. String name_file = file_code + util.getDateTimeByFormat("yyyyMMdd", 0);
  48. String trxdate = util.getDateTimeByFormat("ddMMyy", 0);
  49. String remark3 = "Upload Testing1";
  50.  
  51. // properties
  52. int maxDataDetail = Integer.parseInt(configProperties.getProperties("max_DataDetail"));
  53. int maxSequenceFile = Integer.parseInt(configProperties.getProperties("max_SequenceFile"));
  54. String path = configProperties.getProperties("file_read_path_done");
  55. String ext = configProperties.getProperties("file_up_format");
  56.  
  57. String flag = configProperties.getProperties("flag_up");
  58.  
  59. int total = db.getTotalLocData(flag);
  60. // total = 160000;
  61.  
  62. log.info("Total perkiraan data = " + total);
  63.  
  64. if (total != 0) {
  65. int perulangan = (total / maxDataDetail) + 1;
  66. log.info("Total perkiraan perulangan = " + perulangan);
  67.  
  68. for (int x = 1; x <= perulangan; x++) {
  69.  
  70. String namePartFile = StringUtils.leftPad(Integer.toString(x), 4, "0");
  71.  
  72. if(perulangan > maxSequenceFile){
  73.  
  74. log.info("GENERATED FILE HAS BEEN STOP, You have reach max file name today = "+namePartFile);
  75. break;
  76. }
  77.  
  78. namePartFile = name_file + namePartFile;
  79. String datetime = util.getDateTimeByFormat("yyyyMMdd HHmmss", 0);
  80. String datetimeall[] = datetime.split(" ");
  81. String date = datetimeall[0];
  82. String time = datetimeall[1];
  83.  
  84.  
  85. //created file
  86. filemanage.generateFile(path, namePartFile, ext);
  87.  
  88. try{
  89. String fullPath = path + namePartFile + "." + ext;
  90.  
  91. List<HashMap<String, String>> listresult = new ArrayList<HashMap<String, String>>();
  92.  
  93. listresult = db.getLocToLimit(flag, maxDataDetail);
  94.  
  95. int totalList = listresult.size();
  96. // int row = 1;
  97. // long totalAmount = 0;
  98. BigDecimal totalAmt = new BigDecimal(0);
  99. for (HashMap<String, String> result : listresult) {
  100. // totalAmount = totalAmount + Long.parseLong(result.get("amount"));
  101. totalAmt = totalAmt.add(new BigDecimal(result.get("amount")));
  102. }
  103. log.info("Total List data = " + totalList);
  104.  
  105. String dateHeader = date.substring(6, 8)+date.substring(4,6)+date.substring(2, 4);
  106.  
  107. StringBuilder sb = new StringBuilder();
  108. for (int a=1; a<=2; a++){
  109. String line = new String();
  110.  
  111.  
  112. for (int y = 1; y <= 8; y++) {
  113.  
  114. if (y <= 8) {
  115. if (y == 1) {
  116. line = "Flag:," + flagFl + ",,,,,,,,,,,,,,,,,,,,";
  117. writeToFile(a,line, fullPath, "y");
  118. } else if (y == 2) {
  119. line = "Account Debit:," + acctdebt + ",,,,,,,,,,,,,,,,,,,,";
  120. writeToFile(a,line, fullPath, "y");
  121. } else if (y == 3) {
  122. line = "Total transaction:," + totalList + ",,,,,,,,,,,,,,,,,,,,";
  123. writeToFile(a,line, fullPath, "y");
  124. } else if (y == 4) {
  125. line = "Total transaction amount:," + totalAmt.toString().trim().replace(".", "") + ",,,,,,,,,,,,,,,,,,,,";
  126. writeToFile(a,line, fullPath, "y");
  127. } else if (y == 5) {
  128. line = "Transaction date:," +dateHeader + ",,,,,,,,,,,,,,,,,,,,";
  129. writeToFile(a,line, fullPath, "y");
  130. } else if (y == 6) {
  131. // line ="User ID:,"+header.getUserId();
  132. line = "User ID:,,,,,,,,,,,,,,,,,,,,,";
  133. writeToFile(a,line, fullPath, "y");
  134. } else if (y == 7) {
  135. // line ="User ID:,"+header.getUserId();
  136. if( a==2){
  137. line = "Code:,"+this.code+",,,,,,,,,,,,,,,,,,,,";
  138. writeToFile(a,line, fullPath, "y");
  139. }
  140. else {
  141. continue;
  142. }
  143. }else if (y == 8) {
  144. String line1, line2;
  145. line1 = ",,,,,,,,,,,,,,,,,,,,,";
  146. writeToFile(a,line1, fullPath, "y");
  147. // line = "Service code,Source Branch,Date DDMMYY,Reff no,Amount,Remark Line 3,Remark Line 4,REMARK TRX,BIC BANK PENERIMA,NAMA PENGIRIM,REKENING PENGIRIM,CHARGE 1,CHARGE 2,Jenis nasabah penerima,Status penduduk penerima,Account Credit,Account Debit,REKENING PENERIMA SKN,NAMA PENERIMA SKN,REKENING PENERIMA RTG,NAMA PENERIMA RTG,Reff User";
  148. line2 = "Service code,Source Branch,Date DDMMYY,Reff no,Amount,Remark Line 3,Remark Line 4,REMARK TRX,BIC BANK PENERIMA,NAMA PENGIRIM,REKENING PENGIRIM,CHARGE 1,CHARGE 2,Jenis nasabah penerima,Status penduduk penerima,Account Credit,Account Debit,NAMA PENERIMA OVB,REKENING PENERIMA SKN,NAMA PENERIMA SKN,REKENING PENERIMA RTG,NAMA PENERIMA RTG,AlAMAT PENERIMA,AlAMAT KOTA PENERIMA,KODE CABANG BANK PENERIMA,Reff User";
  149. writeToFile(a,line2, fullPath, "y");
  150. line = line1 + line2;
  151. }
  152.  
  153. //collectline
  154. sb.append(line);
  155. }
  156.  
  157. }
  158.  
  159.  
  160. for (HashMap<String, String> result : listresult) {
  161. // String line = new String();
  162.  
  163. //before..
  164. // if(result.get("kode_bene").equals("MEGAIDJA")){
  165. // line = "OVB,"
  166. // +srcbranch+","
  167. // +trxdate+","
  168. // +"," //ovb.getReffno()
  169. // +result.get("amount").trim().replace(".", "")+","
  170. // +remark3+","
  171. // +"," //ovb.getRemarkTrx4()
  172. // +",,,,,,,,"
  173. // +result.get("rek_bene")+","
  174. // +acctdebt+","
  175. // +",,,,"+result.get("id"); //ovb.getReffusr()
  176. //
  177. //// OVB,801,081117,,100000,Upload Testing1,,,,,,,,,,010740020106872,010740012019880,,,,,0
  178. // filemanage.writeToFile(line, fullPath, "y");
  179. //// row++;
  180. //
  181. // }
  182.  
  183. if(result.get("kode_bene").equals("MEGAIDJA")){
  184. line = "OVB,"
  185. +srcbranch+","
  186. +trxdate+","
  187. +"," //ovb.getReffno()
  188. +result.get("amount").trim().replace(".", "")+","
  189. +remark3+","
  190. +"," //ovb.getRemarkTrx4()
  191. +",,,,,,,,"
  192. +result.get("rek_bene")+","
  193. +acctdebt+","
  194. +result.get("nama_bene")+","
  195. +",,,,,,,"+result.get("id"); //ovb.getReffusr()
  196.  
  197. // OVB,801,081117,,100000,Upload Testing1,,,,,,,,,,010740020106872,010740012019880,,,,,0
  198. writeToFile(a,line, fullPath, "y");
  199. // row++;
  200.  
  201. } else if(new BigDecimal(result.get("amount").trim()).compareTo(new BigDecimal(100000000))==1 ){
  202. line = "RTG,"
  203. +srcbranch+","
  204. +trxdate+","
  205. +"," //ovb.getReffno()
  206. +result.get("amount").trim().replace(".", "")+","
  207. +remark3+","
  208. +",,"
  209. +result.get("kode_bene")+","
  210. +"BM CARD CENTER"+","
  211. +acctdebt+","
  212. +"0"+","
  213. +",,,"
  214. +",,,,,"
  215. +result.get("rek_bene")+","
  216. +result.get("nama_bene")+","
  217. +result.get("address_bene1")+","
  218. +result.get("city_bene")+","
  219. +result.get("kodebank_bene")+","
  220. +result.get("id");
  221. writeToFile(a,line, fullPath, "y");
  222. } else {
  223. line = "SKN,"
  224. +srcbranch+","
  225. +trxdate+","
  226. +"," //ovb.getReffno()
  227. +result.get("amount").trim().replace(".", "")+","
  228. +remark3+","
  229. +",,"
  230. +result.get("kode_bene")+","
  231. +"BM CARD CENTER"+","
  232. +acctdebt+","
  233. +"0"+","
  234. +","
  235. +"1"+","
  236. +"1"+","
  237. +",,,"
  238. +result.get("rek_bene")+","
  239. +result.get("nama_bene")+","
  240. +",,,,,"+result.get("id");
  241. writeToFile(a,line, fullPath, "y");
  242. }
  243.  
  244. sb.append(line);
  245. }
  246.  
  247. if(a==1){
  248. String CRC = sb.toString();
  249. byte[] encodedCRC = Base64.encodeBase64(CRC.getBytes());
  250. HashMap<String, Object> request = new HashMap<String, Object>();
  251. request.put("content", encodedCRC);
  252. //log.info("CRC = " + CRC);
  253.  
  254. HTTPComponentPOST post = new HTTPComponentPOST();
  255. post.setIp("10.11.33.123");
  256. post.setPort("4747");
  257. post.setPath("/encryptor");
  258. post.setCto(2000);
  259. post.setRto(2000);
  260.  
  261. HashMap<String, Object> dataResp = post.sendToHttpPost(request);
  262.  
  263. if(dataResp.get("status").equals("00")){
  264. log.info(dataResp.get("status"));
  265. this.code = String.valueOf(dataResp.get("data"));
  266. }
  267. else{
  268. System.out.println("Encrypt code error");
  269. return null;
  270. }
  271.  
  272. }
  273.  
  274. }
  275. db.updateLocToBulkBatch(listresult);
  276. db.insertFileHistory(namePartFile, date, time);
  277.  
  278. }catch (Exception e) {
  279. // TODO: handle exception
  280. e.printStackTrace();
  281. }
  282. }
  283. }
  284.  
  285. } catch (Exception e) {
  286. // TODO: handle exception
  287. e.printStackTrace();
  288. }
  289.  
  290. return null;
  291. }
  292.  
  293.  
  294. private void writeToFile (int a, String line, String fullPath, String downline){
  295. FileCreateManage filemanage = new FileCreateManage();
  296. if(a==2){
  297. filemanage.writeToFile(line, fullPath, downline);
  298. }
  299. return;
  300. }
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement