titemgroup.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package titemgroup;
  2. import baseclass.PaoCust;
  3. import baseclass.tools.GetFieldsName;
  4. import openapi.base.SQLFactory;
  5. import openapi.base.data.Row;
  6. import openapi.base.data.Rows;
  7. import openapi.base.data.db.DBConnect;
  8. import p2.p2server.P2Server;
  9. import p2.pao.PaoRemote;
  10. import p2.pao.PaoSet;
  11. import p2.pao.PaoSetRemote;
  12. import p2.util.P2AppException;
  13. import p2.util.P2Exception;
  14. import java.util.ArrayList;
  15. public class titemgroup extends PaoCust {
  16. public titemgroup(PaoSet arg0) {
  17. super(arg0);
  18. }
  19. @Override
  20. public void init() throws P2Exception {
  21. super.init();
  22. if (!toBeAdded() && getBoolean("fisused")) {
  23. setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
  24. }
  25. if (!toBeAdded() && !getPaoSet("titem_group").isEmpty()) {
  26. setFieldFlag("fsaleclsnum", READONLY, true);
  27. setFieldFlag("fieldname", READONLY, true);
  28. }
  29. }
  30. @Override
  31. public void add() throws P2Exception {
  32. super.add();
  33. setValue("fgroupnum", getBillNum(getThisPaoSet().getApp()));
  34. }
  35. @Override
  36. protected void save() throws P2Exception {
  37. super.save();
  38. if ("".equals(getString("fitemno")) && !getPaoSet("titem_group").isEmpty()) {
  39. setValue("fitemno", getPaoSet("titem_group").getPao(0).getString("fitemno"), 11L);
  40. }
  41. }
  42. @Override
  43. public void canDelete() throws P2Exception {
  44. super.canDelete();
  45. if (getBoolean("fisused")) {
  46. throw new P2AppException("", "已启用,不可删除");
  47. }
  48. if (!getPaoSet("titem_group").isEmpty()) {
  49. throw new P2AppException("", "已绑定商品,不可删除");
  50. }
  51. }
  52. @Override
  53. public void usedvalidate(boolean isused) throws P2Exception {
  54. super.usedvalidate(isused);
  55. }
  56. @Override
  57. public void used(boolean isused) throws P2Exception {
  58. setValue("fisused", isused, 11L);
  59. }
  60. public void additems(PaoSetRemote titemSet) throws P2Exception {
  61. PaoSetRemote titem_groupSet = getPaoSet("titem_group");
  62. BatchAdd(titemSet, new String[]{"fitemno", "$" + getString("fgroupnum")}, titem_groupSet, new String[]{"fitemno", "fgroupnum"}, true);
  63. reflashSaleclsnum();
  64. }
  65. /**
  66. * 刷新商品组营销分类
  67. *
  68. * @throws P2Exception
  69. */
  70. public void reflashSaleclsnum() throws P2Exception {
  71. PaoSetRemote titem_groupSet = getPaoSet("titem_group");
  72. PaoSetRemote titemgroup_saleclsnumSet = getPaoSet("titemgroup_saleclsnum");
  73. String[] fsaleclsnums = getStrings(titemgroup_saleclsnumSet, "fsaleclsnum");//已存在的营销类别
  74. String[] fitemnos = getStrings(titem_groupSet, "fitemno");//已存在的商品编号
  75. SQLFactory sqlFactory = new SQLFactory(this, "商品营销分类查询");
  76. sqlFactory.addParameter("siteid", getString("siteid"));
  77. sqlFactory.addParameter_in("fitemno", fitemnos);
  78. DBConnect dbConnect = new DBConnect();
  79. Rows fsaleclsnumrows = dbConnect.runSqlQuery(sqlFactory.getSQL());//需要授权的营销类别
  80. for (Row fsaleclsnumrow : fsaleclsnumrows) {
  81. boolean isadd = true;
  82. for (String fsaleclsnum : fsaleclsnums) {
  83. if (fsaleclsnumrow.getString("fsaleclsnum").equals(fsaleclsnum)) {
  84. isadd = false;
  85. break;
  86. }
  87. }
  88. if (isadd) {
  89. PaoRemote pao = titemgroup_saleclsnumSet.addAtEnd();
  90. pao.setValue("fsaleclsnum", fsaleclsnumrow.getString("fsaleclsnum"), 2L);
  91. }
  92. }
  93. ArrayList<PaoRemote> deletepaolist = new ArrayList<>();
  94. int i = 0;
  95. while (titemgroup_saleclsnumSet.getPao(i) != null) {
  96. boolean isdelete = true;
  97. for (Row fsaleclsnumrow : fsaleclsnumrows) {
  98. if (titemgroup_saleclsnumSet.getPao(i).getString("fsaleclsnum").equals(fsaleclsnumrow.getString("fsaleclsnum"))) {
  99. isdelete = false;
  100. }
  101. }
  102. if (isdelete) {
  103. deletepaolist.add(titemgroup_saleclsnumSet.getPao(i));
  104. }
  105. i++;
  106. }
  107. for (PaoRemote deletepao : deletepaolist) {
  108. deletepao.delete();
  109. }
  110. }
  111. @Override
  112. public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
  113. super.fieldValidate(paoField, fieldname);
  114. if ("FGROUPNAME".equals(fieldname)) {
  115. //distinctfieldcheck("FGROUPNAME");
  116. }
  117. }
  118. @Override
  119. public void fieldAction(Object paoField, String fieldname) throws P2Exception {
  120. super.fieldAction(paoField, fieldname);
  121. if ("FSALECLSNUM".equals(fieldname)) {
  122. String fsaleclsnum = getString("fsaleclsnum");
  123. if ("".equals(fsaleclsnum)) {
  124. setValue("flongsaleclsnum", "", 11L);
  125. } else {
  126. String flongsaleclsnum = fsaleclsnum;
  127. boolean hasup = true;
  128. while (hasup) {
  129. PaoSetRemote titemclass = P2Server.getP2Server().getPaoSet("titemclass", getUserInfo());
  130. titemclass.setWhere("fitemclsnum='" + fsaleclsnum + "' and fclasstype='营销类别' and fupclass is not null");
  131. titemclass.reset();
  132. if (titemclass.isEmpty()) {
  133. hasup = false;
  134. } else {
  135. fsaleclsnum = titemclass.getPao(0).getString("fupclass");
  136. flongsaleclsnum = fsaleclsnum + "/" + flongsaleclsnum;
  137. }
  138. }
  139. setValue("flongsaleclsnum", flongsaleclsnum, 11L);
  140. }
  141. }
  142. }
  143. }