DRPWarrantycardCheck.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package service;
  2. import common.ServiceController;
  3. import common.YosException;
  4. import common.data.*;
  5. import common.data.db.DBConnect;
  6. import java.util.HashMap;
  7. public class DRPWarrantycardCheck extends ServiceController {
  8. private static HashMap<String, Long> agentsnumMapping = new HashMap<>();
  9. static {
  10. try {
  11. Rows rows = new DBConnect().runSqlQuery("select agentnum,sa_agentsid from sa_agents");
  12. for (Row row : rows) {
  13. agentsnumMapping.put(row.getString("agentnum"), row.getLong("sa_agentsid"));
  14. }
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. @Override
  20. public void serviceRun() throws YosException {
  21. try {
  22. SQLDump sqlDump = new SQLDump();
  23. Rows drpWarrantycardRows = dbConnect.runSqlQuery("select * from mddrp.twarrantycard where eordermatchflag=0 limit 1000");
  24. RowsMap warrantycardRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_warrantycard", "cardno", "sa_customersid").setWhere("cardno", drpWarrantycardRows.toArrayList("fbillnum")).query().toRowsMap("cardno");
  25. RowsMap itemRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemno", "itemid").setWhere("itemno", drpWarrantycardRows.toArrayList("fitemno")).query().toRowsMap("itemno");
  26. for (Row drpWarrantycardRow : drpWarrantycardRows) {
  27. String fbillnum = drpWarrantycardRow.getString("fbillnum");
  28. String fmachinecode = drpWarrantycardRow.getString("fmachinecode");
  29. String ftoagentnum = drpWarrantycardRow.getString("ftoagentnum");
  30. if (warrantycardRowsMap.containsKey(fbillnum)) {//如果E-订单中存在该保修卡
  31. if (ftoagentnum.isEmpty()) {
  32. sqlDump.add("update sa_warrantycard set toagentnum=null,drpmatchflag=1 where cardno='" + fbillnum + "' and sku='" + fmachinecode + "'");
  33. sqlDump.add("update sa_customers set sa_agentsid_to=null where sa_customersid='" + warrantycardRowsMap.get(fbillnum).get(0).getLong("sa_customersid") + "'");
  34. } else {
  35. sqlDump.add("update sa_warrantycard set toagentnum='" + ftoagentnum + "',drpmatchflag=1 where cardno='" + fbillnum + "' and sku='" + fmachinecode + "'");
  36. sqlDump.add("update sa_customers set sa_agentsid_to=" + agentsnumMapping.getOrDefault(ftoagentnum, 0L) + " where sa_customersid='" + warrantycardRowsMap.get(fbillnum).get(0).getLong("sa_customersid") + "'");
  37. }
  38. } else {
  39. String fagentnum = drpWarrantycardRow.getString("fagentnum");
  40. InsertSQL customersInsert = SQLFactory.createInsertSQL(dbConnect, "sa_customers");
  41. customersInsert.setValue("datastatus", 0);
  42. customersInsert.setValue("tradingstatus", "已成交");
  43. customersInsert.setValue("siteid", "MD");
  44. customersInsert.setValue("sa_agentsid_to", agentsnumMapping.getOrDefault(ftoagentnum, 0L));
  45. customersInsert.setValue("custnum", fbillnum);
  46. customersInsert.setValue("address", drpWarrantycardRow.getString("faddress"));
  47. customersInsert.setValue("phonenumber", drpWarrantycardRow.getString("fphonenumber"));
  48. customersInsert.setValue("name", drpWarrantycardRow.getString("fname"));
  49. customersInsert.setValue("sa_agentsid", agentsnumMapping.getOrDefault(fagentnum, 0L));
  50. customersInsert.setValue("customergrade", "MD");
  51. customersInsert.setValue("sys_enterpriseid", agentsnumMapping.getOrDefault(fagentnum, 0L));
  52. customersInsert.setValue("status", "合作中");
  53. customersInsert.setValue("createby", drpWarrantycardRow.getString("createby"));
  54. if (!drpWarrantycardRow.getString("createdate").isEmpty()) {
  55. customersInsert.setValue("createdate", drpWarrantycardRow.getString("createdate"));
  56. } else {
  57. customersInsert.setValue("createdate", null);
  58. }
  59. InsertSQL warrantycardInsert = SQLFactory.createInsertSQL(dbConnect, "sa_warrantycard");
  60. warrantycardInsert.setValue("siteid", "MD");
  61. warrantycardInsert.setValue("drpmatchflag", 2);
  62. warrantycardInsert.setValue("isonlinejoin", drpWarrantycardRow.getBoolean("fisonlinejoin"));
  63. warrantycardInsert.setValue("name", drpWarrantycardRow.getString("fname"));
  64. warrantycardInsert.setValue("phonenumber", drpWarrantycardRow.getString("fphonenumber"));
  65. warrantycardInsert.setValue("isonline", drpWarrantycardRow.getBoolean("fisonline"));
  66. warrantycardInsert.setValue("sex", drpWarrantycardRow.getString("fsex"));
  67. warrantycardInsert.setValue("address", drpWarrantycardRow.getString("faddress"));
  68. warrantycardInsert.setValue("onlinename", drpWarrantycardRow.getString("fonlinename"));
  69. warrantycardInsert.setValue("onlineordernum", drpWarrantycardRow.getString("fonlineordernum"));
  70. warrantycardInsert.setValue("toagentnum", drpWarrantycardRow.getString("ftoagentnum"));
  71. warrantycardInsert.setValue("isvoid", drpWarrantycardRow.getBoolean("fisvoid"));
  72. warrantycardInsert.setValue("count", drpWarrantycardRow.getInteger("fcount"));
  73. if (!drpWarrantycardRow.getString("fvoiddate").isEmpty()) {
  74. warrantycardInsert.setValue("voiddate", drpWarrantycardRow.getString("fvoiddate"));
  75. }
  76. warrantycardInsert.setValue("voidreason", drpWarrantycardRow.getString("fvoidreason"));
  77. warrantycardInsert.setValue("sku", drpWarrantycardRow.getString("fmachinecode"));
  78. if (itemRowsMap.containsKey(drpWarrantycardRow.getString("fitemno"))) {
  79. warrantycardInsert.setValue("itemid", itemRowsMap.get(drpWarrantycardRow.getString("fitemno")).get(0).getLong("itemid"));
  80. }
  81. warrantycardInsert.setValue("sa_agentsid", agentsnumMapping.getOrDefault(fagentnum, 0L));
  82. if (!drpWarrantycardRow.getString("fenddate").isEmpty()) {
  83. warrantycardInsert.setValue("enddate", drpWarrantycardRow.getString("fenddate"));
  84. }
  85. if (!drpWarrantycardRow.getString("fbegdate").isEmpty()) {
  86. warrantycardInsert.setValue("begdate", drpWarrantycardRow.getString("fbegdate"));
  87. }
  88. warrantycardInsert.setValue("sa_customersid", customersInsert.getUniqueid());
  89. warrantycardInsert.setValue("cardno", fbillnum);
  90. warrantycardInsert.setValue("createby", drpWarrantycardRow.getString("createby"));
  91. if (!drpWarrantycardRow.getString("createdate").isEmpty()) {
  92. warrantycardInsert.setValue("createdate", drpWarrantycardRow.getString("createdate"));
  93. } else {
  94. warrantycardInsert.setValue("createdate", null);
  95. }
  96. sqlDump.add(customersInsert);
  97. sqlDump.add(warrantycardInsert);
  98. }
  99. sqlDump.add("update mddrp.twarrantycard set eordermatchflag=1 where fbillnum='" + fbillnum + "' and fmachinecode='" + fmachinecode + "'");
  100. }
  101. sqlDump.commit();
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. logger.error(e);
  105. }
  106. }
  107. @Override
  108. public ServiceParam paramSet() {
  109. return new ServiceParam("DRP保修卡归属经销商同步任务", 1, RunType.minute);
  110. }
  111. }