customschemeItems.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. if(siteid.equalsIgnoreCase("DLB")){
  42. jsonObject1.put("value", "spec");
  43. jsonObject1.put("description", "尺寸");
  44. jsonObject2.put("value", "material");
  45. jsonObject2.put("description", "选项");
  46. jsonObject3.put("value", "color");
  47. jsonObject3.put("description", "颜色");
  48. jsonObject4.put("value", "cheek");
  49. jsonObject4.put("description", "工艺");
  50. }else {
  51. jsonObject1.put("value", "spec");
  52. jsonObject1.put("description", "尺寸");
  53. jsonObject2.put("value", "material");
  54. jsonObject2.put("description", "基材");
  55. jsonObject3.put("value", "color");
  56. jsonObject3.put("description", "颜色");
  57. jsonObject4.put("value", "cheek");
  58. jsonObject4.put("description", "边框");
  59. }
  60. boolean hsacolor =false;
  61. boolean hsamaterial =false;
  62. boolean hsaspec =false;
  63. boolean hsacheek =false;
  64. if(!rows.isEmpty()){
  65. for (Row row:rows) {
  66. if(row.getString("value").equals("color")){
  67. hsacolor=true;
  68. }
  69. if(row.getString("value").equals("material")){
  70. hsamaterial=true;
  71. }
  72. if(row.getString("value").equals("spec")){
  73. hsaspec=true;
  74. }
  75. if(row.getString("value").equals("cheek")){
  76. hsacheek=true;
  77. }
  78. }
  79. }
  80. JSONArray jsonArray = new JSONArray();
  81. if(!hsacolor){
  82. jsonArray.add(jsonObject3);
  83. }
  84. if(!hsamaterial){
  85. jsonArray.add(jsonObject2);
  86. }
  87. if(!hsaspec){
  88. jsonArray.add(jsonObject1);
  89. }
  90. if(!hsacheek){
  91. jsonArray.add(jsonObject4);
  92. }
  93. return getSucReturnObject().setData(jsonArray).toString();
  94. }
  95. @API(title = "新建或修改商品定制方案明细", apiversion = R.ID20230321155503.v1.class,intervaltime = 200)
  96. @CACHEING_CLEAN(apiClass = {customschemeItems.class})
  97. public String insertormodify_customschemeItems() throws YosException {
  98. Long sa_customschemeid = content.getLong("sa_customschemeid");
  99. JSONArray iteminfos = content.getJSONArray("iteminfos");
  100. ArrayList<String> sqlList = new ArrayList<>();
  101. Rows rowscount = dbConnect.runSqlQuery("select sa_customschemeid from sa_customscheme where sa_customschemeid=" + sa_customschemeid);
  102. Rows RowsStatus = dbConnect.runSqlQuery("select itemid from plm_item where siteid='" + siteid + "' and sa_customschemeid='" + sa_customschemeid + "'");
  103. if (rowscount.isEmpty()) {
  104. return getErrReturnObject().setErrMsg("该商品定制方案不存在").toString();
  105. }
  106. if (RowsStatus.isNotEmpty()) {
  107. return getErrReturnObject().setErrMsg("已在商品档案中使用的定制方案明细无法新增修改").toString();
  108. }
  109. int i = 0;
  110. long[] sa_customscheme_itemsid = createTableID("sa_customscheme_items", iteminfos.size());
  111. for (Object obj : iteminfos) {
  112. JSONObject iteminfo = (JSONObject) obj;
  113. if (iteminfo.getLong("sa_customscheme_itemsid") <= 0 || dbConnect
  114. .runSqlQuery("select sa_customscheme_itemsid from sa_customscheme_items where sa_customscheme_itemsid="
  115. + iteminfo.getLong("sa_customscheme_itemsid"))
  116. .isEmpty()) {
  117. if(i==0){
  118. sqlList.add("delete from sa_customscheme_items where sa_customschemeid="+sa_customschemeid);
  119. }
  120. SQLFactory saleFactory = new SQLFactory(this, "商品定制方案明细新增");
  121. System.out.println("1234");
  122. saleFactory.addParameter("siteid", siteid);
  123. saleFactory.addParameter("sa_customscheme_itemsid", sa_customscheme_itemsid[i]);
  124. saleFactory.addParameter("sa_customschemeid", sa_customschemeid);
  125. saleFactory.addParameter("value", iteminfo.getStringValue("value"));
  126. saleFactory.addParameter("description", iteminfo.getStringValue("description"));
  127. saleFactory.addParameter("isonlydisplay", iteminfo.getLongValue("isonlydisplay"));
  128. sqlList.add(saleFactory.getSQL());
  129. i++;
  130. } else {
  131. SQLFactory saleFactory = new SQLFactory(this, "商品定制方案明细更新");
  132. saleFactory.addParameter("siteid", siteid);
  133. saleFactory.addParameter("sa_customscheme_itemsid", iteminfo.getLongValue("sa_customscheme_itemsid"));
  134. saleFactory.addParameter("sa_customschemeid", sa_customschemeid);
  135. saleFactory.addParameter("value", iteminfo.getStringValue("value"));
  136. saleFactory.addParameter("description", iteminfo.getStringValue("description"));
  137. saleFactory.addParameter("isonlydisplay", iteminfo.getLongValue("isonlydisplay"));
  138. sqlList.add(saleFactory.getSQL());
  139. }
  140. }
  141. dbConnect.runSqlUpdate(sqlList);
  142. return querycustomschemeItemsList();
  143. }
  144. @API(title = "商品定制方案明细明细列表", apiversion = R.ID20230321155603.v1.class)
  145. @CACHEING
  146. public String querycustomschemeItemsList() throws YosException {
  147. /*
  148. * 过滤条件设置
  149. */
  150. StringBuffer where = new StringBuffer(" 1=1 ");
  151. if (content.containsKey("where")) {
  152. JSONObject whereObject = content.getJSONObject("where");
  153. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  154. where.append(" and(");
  155. where.append("t1.value like'%").append(whereObject.getString("condition")).append("%' ");
  156. where.append("or t1.description like'%").append(whereObject.getString("condition")).append("%' ");
  157. where.append(")");
  158. }
  159. }
  160. Long sa_customschemeid = content.getLong("sa_customschemeid");
  161. // String hrid = content.getString("hrid");
  162. SQLFactory sqlFactory = new SQLFactory(this, "商品定制方案明细列表查询", pageSize, pageNumber, pageSorting);
  163. sqlFactory.addParameter_SQL("where", where);
  164. sqlFactory.addParameter("sa_customschemeid", sa_customschemeid);
  165. sqlFactory.addParameter("siteid", siteid);
  166. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  167. return getSucReturnObject().setData(rows).toString();
  168. }
  169. @API(title = "删除明细", apiversion = R.ID20230321155703.v1.class)
  170. @CACHEING_CLEAN(apiClass = {customschemeItems.class})
  171. public String deletemx() throws YosException {
  172. JSONArray sa_customscheme_itemsids = content.getJSONArray("sa_customscheme_itemsids");
  173. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_customscheme_itemsids.size());
  174. long sa_customschemeid = 0;
  175. for (Object o : sa_customscheme_itemsids) {
  176. long sa_customscheme_itemsid = Long.parseLong(o.toString());
  177. Rows RowsStatus = dbConnect
  178. .runSqlQuery("select itemid from plm_item where siteid='" + siteid
  179. + "' and sa_customschemeid in (select sa_customschemeid from sa_customscheme_items where sa_customscheme_itemsid='" + sa_customscheme_itemsid + "')");
  180. if (RowsStatus.isNotEmpty()) {
  181. batchDeleteErr.addErr(sa_customschemeid, "已在商品档案中使用的定制方案明细无法删除");
  182. continue;
  183. }
  184. ArrayList<String> list = new ArrayList<>();
  185. SQLFactory deletesql = new SQLFactory("sql:delete from sa_customscheme_items where siteid='" + siteid
  186. + "' and sa_customscheme_itemsid=" + sa_customscheme_itemsid);
  187. list.add(deletesql.getSQL());
  188. dbConnect.runSqlUpdate(list);
  189. }
  190. return batchDeleteErr.getReturnObject().toString();
  191. }
  192. }