customschemeItems.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package restcontroller.webmanage.sale.customscheme;
  2. import beans.data.BatchDeleteErr;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.data.Row;
  11. import common.data.Rows;
  12. import common.data.RowsMap;
  13. import common.data.SQLFactory;
  14. import org.apache.commons.io.filefilter.FalseFileFilter;
  15. import restcontroller.R;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. public class customschemeItems extends Controller {
  20. /**
  21. * 构造函数
  22. *
  23. * @param content
  24. */
  25. public customschemeItems(JSONObject content) throws YosException {
  26. super(content);
  27. }
  28. @API(title = "方案选择列表查询", apiversion = R.ID20230325133303.v1.class)
  29. @CACHEING
  30. public String querySelectSchemeList() throws YosException {
  31. /*
  32. * 过滤条件设置
  33. */
  34. Long sa_customschemeid = content.getLong("sa_customschemeid");
  35. Rows rows = dbConnect.runSqlQuery("select value from sa_customscheme_items where sa_customschemeid="+sa_customschemeid);
  36. Rows selectRows = new Rows();
  37. JSONObject jsonObject1 =new JSONObject();
  38. JSONObject jsonObject2 =new JSONObject();
  39. JSONObject jsonObject3 =new JSONObject();
  40. JSONObject jsonObject4 =new JSONObject();
  41. jsonObject1.put("value", "spec");
  42. jsonObject1.put("description", "尺寸");
  43. jsonObject2.put("value", "material");
  44. jsonObject2.put("description", "基材");
  45. jsonObject3.put("value", "color");
  46. jsonObject3.put("description", "颜色");
  47. jsonObject4.put("value", "cheek");
  48. jsonObject4.put("description", "边框");
  49. boolean hsacolor =false;
  50. boolean hsamaterial =false;
  51. boolean hsaspec =false;
  52. boolean hsacheek =false;
  53. if(!rows.isEmpty()){
  54. for (Row row:rows) {
  55. if(row.getString("value").equals("color")){
  56. hsacolor=true;
  57. }
  58. if(row.getString("value").equals("material")){
  59. hsamaterial=true;
  60. }
  61. if(row.getString("value").equals("spec")){
  62. hsaspec=true;
  63. }
  64. if(row.getString("value").equals("cheek")){
  65. hsacheek=true;
  66. }
  67. }
  68. }
  69. JSONArray jsonArray = new JSONArray();
  70. if(!hsacolor){
  71. jsonArray.add(jsonObject3);
  72. }
  73. if(!hsamaterial){
  74. jsonArray.add(jsonObject2);
  75. }
  76. if(!hsaspec){
  77. jsonArray.add(jsonObject1);
  78. }
  79. if(!hsacheek){
  80. jsonArray.add(jsonObject4);
  81. }
  82. return getSucReturnObject().setData(jsonArray).toString();
  83. }
  84. @API(title = "新建或修改商品定制方案明细", apiversion = R.ID20230321155503.v1.class,intervaltime = 200)
  85. @CACHEING_CLEAN(apiClass = {customschemeItems.class})
  86. public String insertormodify_customschemeItems() throws YosException {
  87. Long sa_customschemeid = content.getLong("sa_customschemeid");
  88. JSONArray iteminfos = content.getJSONArray("iteminfos");
  89. ArrayList<String> sqlList = new ArrayList<>();
  90. Rows rowscount = dbConnect.runSqlQuery("select sa_customschemeid from sa_customscheme where sa_customschemeid=" + sa_customschemeid);
  91. Rows RowsStatus = dbConnect.runSqlQuery("select itemid from plm_item where siteid='" + siteid + "' and sa_customschemeid='" + sa_customschemeid + "'");
  92. if (rowscount.isEmpty()) {
  93. return getErrReturnObject().setErrMsg("该商品定制方案不存在").toString();
  94. }
  95. if (RowsStatus.isNotEmpty()) {
  96. return getErrReturnObject().setErrMsg("已在商品档案中使用的定制方案明细无法新增修改").toString();
  97. }
  98. int i = 0;
  99. long[] sa_customscheme_itemsid = createTableID("sa_customscheme_items", iteminfos.size());
  100. for (Object obj : iteminfos) {
  101. JSONObject iteminfo = (JSONObject) obj;
  102. if (iteminfo.getLong("sa_customscheme_itemsid") <= 0 || dbConnect
  103. .runSqlQuery("select sa_customscheme_itemsid from sa_customscheme_items where sa_customscheme_itemsid="
  104. + iteminfo.getLong("sa_customscheme_itemsid"))
  105. .isEmpty()) {
  106. if(i==0){
  107. sqlList.add("delete from sa_customscheme_items where sa_customschemeid="+sa_customschemeid);
  108. }
  109. SQLFactory saleFactory = new SQLFactory(this, "商品定制方案明细新增");
  110. System.out.println("1234");
  111. saleFactory.addParameter("siteid", siteid);
  112. saleFactory.addParameter("sa_customscheme_itemsid", sa_customscheme_itemsid[i]);
  113. saleFactory.addParameter("sa_customschemeid", sa_customschemeid);
  114. saleFactory.addParameter("value", iteminfo.getStringValue("value"));
  115. saleFactory.addParameter("description", iteminfo.getStringValue("description"));
  116. sqlList.add(saleFactory.getSQL());
  117. i++;
  118. } else {
  119. SQLFactory saleFactory = new SQLFactory(this, "商品定制方案明细更新");
  120. saleFactory.addParameter("siteid", siteid);
  121. saleFactory.addParameter("sa_customscheme_itemsid", iteminfo.getLongValue("sa_customscheme_itemsid"));
  122. saleFactory.addParameter("sa_customschemeid", sa_customschemeid);
  123. saleFactory.addParameter("value", iteminfo.getStringValue("value"));
  124. saleFactory.addParameter("description", iteminfo.getStringValue("description"));
  125. sqlList.add(saleFactory.getSQL());
  126. }
  127. }
  128. dbConnect.runSqlUpdate(sqlList);
  129. return querycustomschemeItemsList();
  130. }
  131. @API(title = "商品定制方案明细明细列表", apiversion = R.ID20230321155603.v1.class)
  132. @CACHEING
  133. public String querycustomschemeItemsList() throws YosException {
  134. /*
  135. * 过滤条件设置
  136. */
  137. StringBuffer where = new StringBuffer(" 1=1 ");
  138. if (content.containsKey("where")) {
  139. JSONObject whereObject = content.getJSONObject("where");
  140. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  141. where.append(" and(");
  142. where.append("t1.value like'%").append(whereObject.getString("condition")).append("%' ");
  143. where.append("or t1.description like'%").append(whereObject.getString("condition")).append("%' ");
  144. where.append(")");
  145. }
  146. }
  147. Long sa_customschemeid = content.getLong("sa_customschemeid");
  148. // String hrid = content.getString("hrid");
  149. SQLFactory sqlFactory = new SQLFactory(this, "商品定制方案明细列表查询", pageSize, pageNumber, pageSorting);
  150. sqlFactory.addParameter_SQL("where", where);
  151. sqlFactory.addParameter("sa_customschemeid", sa_customschemeid);
  152. sqlFactory.addParameter("siteid", siteid);
  153. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  154. return getSucReturnObject().setData(rows).toString();
  155. }
  156. @API(title = "删除明细", apiversion = R.ID20230321155703.v1.class)
  157. @CACHEING_CLEAN(apiClass = {customschemeItems.class})
  158. public String deletemx() throws YosException {
  159. JSONArray sa_customscheme_itemsids = content.getJSONArray("sa_customscheme_itemsids");
  160. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_customscheme_itemsids.size());
  161. long sa_customschemeid = 0;
  162. for (Object o : sa_customscheme_itemsids) {
  163. long sa_customscheme_itemsid = Long.parseLong(o.toString());
  164. Rows RowsStatus = dbConnect
  165. .runSqlQuery("select itemid from plm_item where siteid='" + siteid
  166. + "' and sa_customschemeid in (select sa_customschemeid from sa_customscheme_items where sa_customscheme_itemsid='" + sa_customscheme_itemsid + "')");
  167. if (RowsStatus.isNotEmpty()) {
  168. batchDeleteErr.addErr(sa_customschemeid, "已在商品档案中使用的定制方案明细无法删除");
  169. continue;
  170. }
  171. ArrayList<String> list = new ArrayList<>();
  172. SQLFactory deletesql = new SQLFactory("sql:delete from sa_customscheme_items where siteid='" + siteid
  173. + "' and sa_customscheme_itemsid=" + sa_customscheme_itemsid);
  174. list.add(deletesql.getSQL());
  175. dbConnect.runSqlUpdate(list);
  176. }
  177. return batchDeleteErr.getReturnObject().toString();
  178. }
  179. }