GetBasicDataFromU8.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package service;
  2. import common.ServiceController;
  3. import common.YosException;
  4. import common.data.*;
  5. import common.data.db.DBConnect;
  6. import common.data.db.QueryCallBack;
  7. import java.util.ArrayList;
  8. /**
  9. * 美大U8erp数据传输自动任务
  10. */
  11. public class GetBasicDataFromU8 extends ServiceController {
  12. private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
  13. @Override
  14. public void serviceRun() throws Exception {
  15. getUnit();
  16. getItem();
  17. getMcode();
  18. }
  19. @Override
  20. public ServiceParam paramSet() {
  21. return new ServiceParam("获取U8基础资料(计量单位-商品档案-序列号)", 1, RunType.minute);
  22. }
  23. /**
  24. * 计量单位
  25. */
  26. public void getUnit() throws YosException {
  27. YUNl_DB.runSqlQuery("select distinct cComUnitName from ComputationUnit where status=0 and accid in('666','888')", new QueryCallBack() {
  28. @Override
  29. public void onRowLoaded(long rowindex, Row row) throws YosException {
  30. try {
  31. String cComUnitName = row.getString("cComUnitName");
  32. InsertSQL unitInsert = SQLFactory.createInsertSQL(dbConnect, "plm_unit");
  33. unitInsert.setValue("siteid", "MD");
  34. unitInsert.setValue("unitname", cComUnitName);
  35. unitInsert.setWhere("not exists(select * from plm_unit where siteid='MD' and unitname='" + cComUnitName + "')");
  36. unitInsert.insert();
  37. YUNl_DB.runSqlUpdate("update ComputationUnit set status=1 where cComUnitName='" + cComUnitName + "' and accid in('666','888')");
  38. } catch (Exception e) {
  39. logger.error("U8计量单位同步DRP失败", row.toJsonObject(), e);
  40. }
  41. }
  42. });
  43. }
  44. /**
  45. * 商品档案
  46. */
  47. public void getItem() throws YosException {
  48. RowsMap unitMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid,unitname").setWhere("siteid", "MD").query().toRowsMap("unitname");
  49. Rows cInvCodeRows = YUNl_DB.runSqlQuery("select " + "cInvCode," +//--存货编码
  50. "cInvName," +//存货名称
  51. "cInvStd," +//规格型号
  52. "cComUnitName," +//主计量单位名称
  53. "isnull(bSerial,0)as bSerial " +//是否序列号管理
  54. "from Inventory where status=0 and accid in('666','888')");
  55. ArrayList<String> itemnoList = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemno").setWhere("siteid", "MD").setWhere("itemno", cInvCodeRows.toArrayList("cInvCode")).query().toArrayList("itemno");
  56. for (Row cInvCodeRow : cInvCodeRows) {
  57. try {
  58. String cComUnitName = cInvCodeRow.getString("cComUnitName");
  59. if (!unitMap.containsKey(cComUnitName)) {
  60. continue;//计量单位不存在
  61. }
  62. String cInvCode = cInvCodeRow.getString("cInvCode");
  63. String cInvName = cInvCodeRow.getString("cInvName");
  64. String cInvStd = cInvCodeRow.getString("cInvStd");
  65. boolean bSerial = cInvCodeRow.getBoolean("bSerial");
  66. if (itemnoList.contains(cInvCode)) {
  67. UpdateSQL plmItem = SQLFactory.createUpdateSQL(dbConnect, "plm_item");
  68. plmItem.setValue("itemname", cInvName);
  69. plmItem.setValue("model", cInvStd);
  70. plmItem.setValue("unitid", unitMap.get(cComUnitName).get(0).getLong("unitid"));
  71. plmItem.setValue("skucontrol", bSerial);
  72. plmItem.setValue("changeby", "U8");
  73. plmItem.setValue("WMSUPLOADFLAG", 2);
  74. plmItem.setWhere("siteid", "MD").setWhere("itemno", cInvCode);
  75. plmItem.update();
  76. } else {
  77. InsertSQL plmItem = SQLFactory.createInsertSQL(dbConnect, "plm_item");
  78. plmItem.setValue("itemno", cInvCode);
  79. plmItem.setValue("itemname", cInvName);
  80. plmItem.setValue("model", cInvStd);
  81. plmItem.setValue("unitid", unitMap.get(cComUnitName).get(0).getLong("unitid"));
  82. plmItem.setValue("skucontrol", bSerial);
  83. plmItem.setValue("createby", "U8");
  84. plmItem.setValue("WMSUPLOADFLAG", 2);
  85. plmItem.setValue("siteid", "MD");
  86. plmItem.insert();
  87. }
  88. YUNl_DB.runSqlUpdate("update Inventory set status=1 where cInvCode='" + cInvCode + "' and accid in('666','888')");
  89. } catch (Exception e) {
  90. logger.error("U8货品档案同步DRP失败", cInvCodeRow.toJsonObject(), e);
  91. }
  92. }
  93. }
  94. /**
  95. * 序列号
  96. */
  97. public void getMcode() throws YosException {
  98. Rows codeRows = YUNl_DB.runSqlQuery("SELECT cInvCode,cInvSN FROM ST_SNState where status=0 and accid in('666','888')");
  99. Rows itemrows = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemid", "itemno").setWhere("siteid", "MD").setWhere("itemno", codeRows.toArrayList("cInvCode")).query();
  100. RowsMap itemMap = itemrows.toRowsMap("itemno");
  101. //已存在的序列号
  102. ArrayList<String> codeList = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku").setWhere("siteid", "MD").setWhere("sku", codeRows.toArrayList("cInvSN")).query().toArrayList("sku");
  103. for (Row codeRow : codeRows) {
  104. String cInvCode = codeRow.getString("cInvCode");
  105. String cInvSN = codeRow.getString("cInvSN");
  106. if (itemMap.containsKey(cInvCode)) {
  107. if (codeList.contains(cInvSN)) {
  108. UpdateSQL sku = SQLFactory.createUpdateSQL(dbConnect, "sa_itemsku");
  109. sku.setValue("itemid", itemMap.get(cInvCode).get(0).getLong("itemid"));
  110. sku.setValue("changeby", "U8");
  111. sku.setWhere("siteid", "MD").setWhere("sku", cInvSN);
  112. sku.setValue("WMSUPLOADFLAG", 2);
  113. sku.update();
  114. } else {
  115. InsertSQL sku = SQLFactory.createInsertSQL(dbConnect, "sa_itemsku");
  116. sku.setValue("itemid", itemMap.get(cInvCode).get(0).getLong("itemid"));
  117. sku.setValue("sku", cInvSN);
  118. sku.setValue("status", "");
  119. sku.setValue("createby", "U8");
  120. sku.setValue("siteid", "MD");
  121. sku.setValue("WMSUPLOADFLAG", 2);
  122. sku.insert();
  123. }
  124. YUNl_DB.runSqlUpdate("update ST_SNState set status=1 where cInvCode='" + cInvCode + "' and cInvSN='" + cInvSN + "' and accid in('666','888')");
  125. } else {
  126. YUNl_DB.runSqlUpdate("update ST_SNState set status=2 where cInvCode='" + cInvCode + "' and cInvSN='" + cInvSN + "' and accid in('666','888')");
  127. }
  128. }
  129. }
  130. }