itemgroup.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package restcontroller.webmanage.sale.itemgroup;
  2. import beans.brand.Brand;
  3. import beans.data.BatchDeleteErr;
  4. import beans.datatag.DataTag;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import common.Controller;
  9. import common.YosException;
  10. import common.annotation.API;
  11. import common.annotation.CACHEING;
  12. import common.annotation.CACHEING_CLEAN;
  13. import common.annotation.cm;
  14. import common.data.Row;
  15. import common.data.Rows;
  16. import common.data.RowsMap;
  17. import common.data.SQLFactory;
  18. import restcontroller.R;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. @API(title = "商品组")
  22. public class itemgroup extends Controller {
  23. public itemgroup(JSONObject arg0) throws YosException {
  24. super(arg0);
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * 新增修改商品组
  29. *
  30. * @return
  31. */
  32. @API(title = "商品组新增修改", apiversion = R.ID20220922164303.v1.class)
  33. @CACHEING_CLEAN(cms = {@cm(clazz = itemgroup.class, method = {"queryItemgroup"})})
  34. public String insertormodify_itemgroup() throws YosException {
  35. long sa_itemgroupid = content.getLongValue("sa_itemgroupid");
  36. long sa_brandid = content.getLong("sa_brandid");
  37. String groupname = content.getString("groupname");
  38. String itemno = content.getString("itemno");
  39. String tradefield = content.getStringValue("tradefield");
  40. Long sequence = content.getLongValue("sequence");
  41. JSONArray tagArray = content.getJSONArray("tag");
  42. ArrayList<String> list = (ArrayList<String>) JSONObject.parseArray(tagArray.toJSONString(), String.class);
  43. Rows itemgroupRows = dbConnect.runSqlQuery("select sa_itemgroupid,sequence,isonsale from sa_itemgroup where sa_itemgroupid=" + sa_itemgroupid + " and siteid='" + siteid + "'");
  44. ArrayList<String> sqllist = new ArrayList<>();
  45. if (sa_itemgroupid <= 0 || itemgroupRows.isEmpty()) {
  46. // Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_itemgroup WHERE sa_brandid='" + sa_brandid + "' and groupname = '" + groupname + "' and siteid='" + siteid + "'");
  47. // if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  48. // return getErrReturnObject().setErrMsg("商品组已存在").toString();
  49. // }
  50. Rows rows1 = dbConnect.runSqlQuery("select sequence from sa_itemgroup where siteid = '" + siteid + "' order by sequence asc");
  51. if (rows1.isNotEmpty() && rows1.toArrayList("sequence").contains(sequence.toString())) {
  52. if (sequence <= rows1.getLastRow().getLong("sequence")) {
  53. sqllist.add("update sa_itemgroup set sequence = sequence+1 where siteid = '" + siteid + "' and sequence >= " + sequence);
  54. }
  55. }
  56. SQLFactory sqlAddFactory = new SQLFactory(this, "商品组新增");
  57. //String billcode=createBillCode("");
  58. //String billcode="123456789";
  59. String billcode = createBillCode("itemgroup");
  60. sa_itemgroupid = createTableID("sa_itemgroup");
  61. sqlAddFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  62. sqlAddFactory.addParameter("siteid", siteid);
  63. sqlAddFactory.addParameter("groupname", groupname);
  64. sqlAddFactory.addParameter("itemno", itemno);
  65. sqlAddFactory.addParameter("username", username);
  66. sqlAddFactory.addParameter("groupnum", billcode);
  67. sqlAddFactory.addParameter("tradefield", tradefield);
  68. sqlAddFactory.addParameter("sa_brandid", sa_brandid);
  69. sqlAddFactory.addParameter("sequence", sequence);
  70. content.put("sa_itemgroupid", sa_itemgroupid);
  71. DataTag.updateTag(this, "sa_itemgroup", sa_itemgroupid, list);
  72. sqllist.add(sqlAddFactory.getSQL());
  73. } else {
  74. // Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_itemgroup WHERE sa_brandid='" + sa_brandid + "' and sa_itemgroupid!=" + content.getLong("sa_itemgroupid") + " and groupname = '" + groupname + "' and siteid='" + siteid + "'");
  75. // if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  76. // return getErrReturnObject().setErrMsg("商品组已存在").toString();
  77. // }
  78. if (!itemgroupRows.isEmpty() && itemgroupRows.get(0).getBoolean("isonsale")) {
  79. return getErrReturnObject().setErrMsg("商品组已上架,无法修改").toString();
  80. }
  81. if (sequence < itemgroupRows.get(0).getLong("sequence")) {
  82. sqllist.add("update sa_itemgroup set sequence = sequence+1 where siteid = '" + siteid + "' and sequence between " + sequence + " and " + itemgroupRows.get(0).getLong("sequence"));
  83. } else if (sequence > itemgroupRows.get(0).getLong("sequence")) {
  84. sqllist.add("update sa_itemgroup set sequence = sequence-1 where siteid = '" + siteid + "' and sequence between " + itemgroupRows.get(0).getLong("sequence") + " and " + sequence);
  85. }
  86. SQLFactory sqlUpdateFactory = new SQLFactory(this, "商品组更新");
  87. sqlUpdateFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  88. sqlUpdateFactory.addParameter("groupname", groupname);
  89. sqlUpdateFactory.addParameter("itemno", itemno);
  90. sqlUpdateFactory.addParameter("tradefield", tradefield);
  91. sqlUpdateFactory.addParameter("sequence", sequence);
  92. sqlUpdateFactory.addParameter("username", username);
  93. DataTag.updateTag(this, "sa_itemgroup", sa_itemgroupid, list);
  94. sqllist.add(sqlUpdateFactory.getSQL());
  95. }
  96. dbConnect.runSqlUpdate(sqllist);
  97. return queryItemgroupMain();
  98. }
  99. /**
  100. * 查询商品组
  101. *
  102. * @return
  103. */
  104. @API(title = "查询", apiversion = R.ID20220922164403.v1.class)
  105. @CACHEING
  106. public String queryItemgroup() throws YosException {
  107. /*
  108. 过滤条件设置
  109. */
  110. String where = " 1=1 ";
  111. if (content.containsKey("where")) {
  112. JSONObject whereObject = content.getJSONObject("where");
  113. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  114. where = where + " and (t1.groupname like'%" + whereObject.getString("condition")
  115. + "%' or t1.groupnum like'%" + whereObject.getString("condition") + "%') ";
  116. }
  117. if (whereObject.containsKey("brandname") && !"".equals(whereObject.getString("brandname"))) {
  118. where = where + " and (t3.brandname ='" + whereObject.getString("brandname") + "') ";
  119. }
  120. if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
  121. where=where+" and t1.sa_itemgroupid in(select t1.sa_itemgroupid from sa_itemgroupmx t1 left join plm_item_tradefield t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t2.tradefield like '%"+whereObject.getString("tradefield")+"%') ";
  122. }
  123. if (whereObject.containsKey("itemclassname") && !"".equals(whereObject.getString("itemclassname"))) {
  124. where = where + " and (t5.itemclassname ='" + whereObject.getString("itemclassname") + "') ";
  125. }
  126. if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
  127. where = where + " and (t1.isonsale ='" + whereObject.getString("isonsale") + "') ";
  128. }
  129. if (whereObject.containsKey("iteminfo") && !"".equals(whereObject.getString("iteminfo"))) {
  130. where=where+" and t1.sa_itemgroupid in(select t1.sa_itemgroupid from sa_itemgroupmx t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where (t2.itemno like '%"+whereObject.getString("iteminfo")+"%' or t2.itemname like '%"+whereObject.getString("iteminfo")+"%')) ";
  131. }
  132. }
  133. /*
  134. SQL查询参数设置并查询
  135. */
  136. SQLFactory factory = new SQLFactory(this, "商品组列表查询", pageSize, pageNumber, pageSorting);
  137. factory.addParameter("siteid", siteid);
  138. factory.addParameter_SQL("where", where);
  139. String sql = factory.getSQL();
  140. Rows rows = dbConnect.runSqlQuery(sql);
  141. for (Row row2 : rows) {
  142. ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", row2.getLong("sa_itemgroupid"), false);
  143. row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
  144. }
  145. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  146. //默认商品图片
  147. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  148. //封面cover
  149. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  150. //附件
  151. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  152. Rows rowsitemclass = dbConnect.runSqlQuery(
  153. " select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 inner JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
  154. + siteid + "'");
  155. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  156. for (Row row : rows) {
  157. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  158. if (coverRows.isEmpty()) {
  159. if (!defaultImageRows.isEmpty()) {
  160. row.put("cover", defaultImageRows.get(0).getString("url"));
  161. } else {
  162. row.put("cover", "");
  163. }
  164. } else {
  165. row.put("cover", coverRows.get(0).getString("url"));
  166. }
  167. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  168. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  169. }
  170. return getSucReturnObject().setData(rows).toString();
  171. }
  172. @API(title = "商品组详情", apiversion = R.ID20220923091903.v1.class)
  173. public String queryItemgroupMain() throws YosException {
  174. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  175. SQLFactory sqlFactory = new SQLFactory(this, "商品组详情查询");
  176. sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  177. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  178. Rows rowsitemclass = dbConnect.runSqlQuery(
  179. " select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 inner JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
  180. + siteid + "'");
  181. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  182. if (!rows.isEmpty()) {
  183. ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", rows.get(0).getLong("sa_itemgroupid"), false);
  184. rows.get(0).put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
  185. rows.get(0).put("itemclass", itemclassRowsMap.get(rows.get(0).getString("itemid")));
  186. }
  187. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  188. }
  189. /**
  190. * 商品组上架
  191. *
  192. * @return
  193. */
  194. @API(title = "商品组上架", apiversion = R.ID20220923143603.v1.class)
  195. @CACHEING_CLEAN(cms = {@cm(clazz = itemgroup.class, method = {"queryItemgroup", "queryItemgroupMain"})})
  196. public String release() throws YosException {
  197. JSONArray sa_itemgroupids = content.getJSONArray("sa_itemgroupids");
  198. String[] s = {"sa_itemgroupids"};
  199. for (String s1 : s) {
  200. if (!content.containsKey(s1))
  201. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  202. }
  203. List<Long> list = sa_itemgroupids.toJavaList(Long.class);
  204. Long[] stringArray = list.toArray(new Long[0]);
  205. // SQLFactory sqlFactoryquery = new SQLFactory(this, "商品组状态查询");
  206. // sqlFactoryquery.addParameter("siteid", siteid);
  207. // sqlFactoryquery.addParameter_in("sa_itemgroupids", stringArray);
  208. String whereSql = "select isonsale,groupname,sa_itemgroupid from sa_itemgroup where sa_itemgroupid in " + list + " and siteid='" + siteid + "'";
  209. whereSql = whereSql.replace("[", "(").replace("]", ")");
  210. Rows rows = dbConnect.runSqlQuery(whereSql);
  211. for (Row row : rows) {
  212. if (row.getBoolean("isonsale")) {
  213. return getErrReturnObject().setErrMsg("【" + row.getString("groupname") + "】商品组已上架,无法再次上架").toString();
  214. }
  215. Rows rowscount = dbConnect.runSqlQuery("select distinct ifnull(t2.sa_customschemeid,0) sa_customschemeid from sa_itemgroupmx t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.siteid='"+siteid+"' and t1.sa_itemgroupid="+row.getLong("sa_itemgroupid"));
  216. if(rowscount.size()>1){
  217. return getErrReturnObject().setErrMsg("【" + row.getString("groupname") + "】商品组存在两个以上方案的商品,无法上架").toString();
  218. }
  219. }
  220. SQLFactory sqlFactoryupdate = new SQLFactory(this, "商品组上架");
  221. sqlFactoryupdate.addParameter("siteid", siteid);
  222. sqlFactoryupdate.addParameter_in("sa_itemgroupids", stringArray);
  223. dbConnect.runSqlUpdate(sqlFactoryupdate);
  224. // //发送消息
  225. // for (String id : stringArray) {
  226. // sendMsg(Long.parseLong(id));
  227. // }
  228. return getSucReturnObject().toString();
  229. }
  230. /**
  231. * 商品组下架
  232. *
  233. * @return
  234. */
  235. @API(title = "下架", apiversion = R.ID20220923143703.v1.class)
  236. @CACHEING_CLEAN(cms = {@cm(clazz = itemgroup.class, method = {"queryItemgroup", "queryItemgroupMain"})})
  237. public String undercarriage() throws YosException {
  238. JSONArray sa_itemgroupids = content.getJSONArray("sa_itemgroupids");
  239. String[] s = {"sa_itemgroupids"};
  240. for (String s1 : s) {
  241. if (!content.containsKey(s1))
  242. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  243. }
  244. List<Long> list = sa_itemgroupids.toJavaList(Long.class);
  245. Long[] stringArray = list.toArray(new Long[0]);
  246. String whereSql = "select isonsale,groupname from sa_itemgroup where sa_itemgroupid in " + list + " and siteid='" + siteid + "'";
  247. whereSql = whereSql.replace("[", "(").replace("]", ")");
  248. Rows rows = dbConnect.runSqlQuery(whereSql);
  249. for (Row row : rows) {
  250. if (!row.getBoolean("isonsale")) {
  251. return getErrReturnObject().setErrMsg("【" + row.getString("groupname") + "】商品组已下架,无法再次下架").toString();
  252. }
  253. }
  254. SQLFactory sqlFactoryupdate = new SQLFactory(this, "商品组下架");
  255. sqlFactoryupdate.addParameter("siteid", siteid);
  256. sqlFactoryupdate.addParameter_in("sa_itemgroupids", stringArray);
  257. dbConnect.runSqlUpdate(sqlFactoryupdate);
  258. return getSucReturnObject().toString();
  259. }
  260. @API(title = "新建或修改商品组商品明细", apiversion = R.ID20220923110303.v1.class)
  261. @CACHEING_CLEAN(cms = {
  262. @cm(clazz = itemgroup.class, method = {"queryItemgroupMxList", "queryItemgList"})})
  263. public String insertormodify_itemgroupmx() throws YosException {
  264. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  265. JSONArray iteminfos = content.getJSONArray("itemclassinfos");
  266. ArrayList<String> sqlList = new ArrayList<>();
  267. Rows rowscount = dbConnect.runSqlQuery(
  268. "select isonsale from sa_itemgroup where sa_itemgroupid=" + sa_itemgroupid);
  269. if (!rowscount.isEmpty()) {
  270. if (rowscount.get(0).getBoolean("isonsale")) {
  271. return getErrReturnObject().setErrMsg("上架状态的商品组无法新建及修改").toString();
  272. }
  273. }
  274. int i = 0;
  275. long maxid = 0;
  276. long[] sa_itemgroupmxid = createTableID("sa_itemgroupmx", iteminfos.size());
  277. Rows maxidRows = dbConnect.runSqlQuery("select MAX(sequence) sequence from sa_itemgroupmx where sa_itemgroupid=" + sa_itemgroupid);
  278. if (!maxidRows.isEmpty()) {
  279. maxid = maxidRows.get(0).getLong("sequence");
  280. }
  281. for (Object obj : iteminfos) {
  282. JSONObject iteminfo = (JSONObject) obj;
  283. if (iteminfo.getLong("sa_itemgroupmxid") <= 0
  284. || dbConnect.runSqlQuery("select sa_itemgroupmxid from sa_itemgroupmx where sa_itemgroupmxid="
  285. + iteminfo.getLong("sa_itemgroupmxid")).isEmpty()) {
  286. SQLFactory saleFactory = new SQLFactory(this, "商品组商品明细新增");
  287. saleFactory.addParameter("siteid", siteid);
  288. saleFactory.addParameter("sequence", maxid + i + 1);
  289. saleFactory.addParameter("sa_itemgroupmxid", sa_itemgroupmxid[i]);
  290. //saleFactory.addParameter("itemno", iteminfo.getString("itemno"));
  291. saleFactory.addParameter("itemid", iteminfo.getString("itemid"));
  292. Rows rows = dbConnect.runSqlQuery("select itemno from plm_item where itemid=" + iteminfo.getLong("itemid"));
  293. if (rows.isEmpty()) {
  294. saleFactory.addParameter("itemno", "null");
  295. } else {
  296. saleFactory.addParameter("itemno", rows.get(0).getString("itemno"));
  297. }
  298. saleFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  299. sqlList.add(saleFactory.getSQL());
  300. i++;
  301. } else {
  302. SQLFactory saleFactory = new SQLFactory(this, "商品组商品明细更新");
  303. saleFactory.addParameter("sa_itemgroupmxid", iteminfo.getLong("sa_itemgroupmxid"));
  304. saleFactory.addParameter("sequence", iteminfo.getLongValue("sequence"));
  305. //saleFactory.addParameter("itemno", iteminfo.getString("itemno"));
  306. saleFactory.addParameter("itemid", iteminfo.getString("itemid"));
  307. Rows rows = dbConnect.runSqlQuery("select itemno from plm_item where itemid=" + iteminfo.getLong("itemid"));
  308. if (rows.isEmpty()) {
  309. saleFactory.addParameter("itemno", "null");
  310. } else {
  311. saleFactory.addParameter("itemno", rows.get(0).getString("itemno"));
  312. }
  313. sqlList.add(saleFactory.getSQL());
  314. }
  315. }
  316. dbConnect.runSqlUpdate(sqlList);
  317. updateTradefield(sa_itemgroupid);
  318. return queryItemgroupMxList();
  319. }
  320. @API(title = "商品列表查询", apiversion = R.ID20220923112503.v1.class)
  321. @CACHEING
  322. public String queryItemgList() throws YosException {
  323. /*
  324. * 过滤条件设置
  325. */
  326. String where = " 1=1 ";
  327. if (content.containsKey("where")) {
  328. JSONObject whereObject = content.getJSONObject("where");
  329. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  330. where = where + " and (t1.itemname like '%" + whereObject.getString("condition") + "%'"
  331. + " or t1.itemno like '%" + whereObject.getString("condition") + "%')";
  332. }
  333. if (whereObject.containsKey("brandname") && !"".equals(whereObject.getString("brandname"))) {
  334. where = where + " and t5.brandname ='" + whereObject.getString("brandname") + "'";
  335. }
  336. }
  337. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  338. // String hrid = content.getString("hrid");
  339. SQLFactory sqlFactory = new SQLFactory(this, "商品查询", pageSize, pageNumber, pageSorting);
  340. sqlFactory.addParameter_SQL("where", where);
  341. sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  342. sqlFactory.addParameter("siteid", siteid);
  343. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
  344. //附件
  345. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  346. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  347. RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
  348. Rows rowsitemclass = dbConnect.runSqlQuery(" select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='" + siteid + "'");
  349. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  350. for (Row row : rows) {
  351. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  352. row.put("brand", brandRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  353. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  354. }
  355. return getSucReturnObject().setData(rows).toString();
  356. }
  357. @API(title = "商品组商品明细列表", apiversion = R.ID20220923101603.v1.class)
  358. @CACHEING
  359. public String queryItemgroupMxList() throws YosException {
  360. /*
  361. * 过滤条件设置
  362. */
  363. String where = " 1=1 ";
  364. if (content.containsKey("where")) {
  365. JSONObject whereObject = content.getJSONObject("where");
  366. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  367. where = where + "and t2.itemname like'%" + whereObject.getString("condition") + "%'";
  368. }
  369. }
  370. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  371. // String hrid = content.getString("hrid");
  372. SQLFactory sqlFactory = new SQLFactory(this, "商品组商品明细查询", pageSize, pageNumber, pageSorting);
  373. sqlFactory.addParameter_SQL("where", where);
  374. sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  375. sqlFactory.addParameter("siteid", siteid);
  376. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  377. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  378. //默认商品图片
  379. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  380. // 封面cover
  381. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  382. // 附件
  383. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  384. Rows technicalinforows = dbConnect.runSqlQuery("select plm_technicalinfoid,itemid from plm_technicalinfo_item");
  385. RowsMap technicalinfoRowsMap = technicalinforows.toRowsMap("itemid");
  386. Rows technicalinforows1 = dbConnect.runSqlQuery("select plm_technicalinfoid from plm_technicalinfo");
  387. ArrayList<Long> plm_technicalinfoids = technicalinforows1.toArrayList("plm_technicalinfoid", new ArrayList<>());
  388. // 产品技术资料附件
  389. RowsMap plm_technicalinfoRowsMap = getAttachmentUrl("plm_technicalinfo", plm_technicalinfoids);
  390. Rows rowsitemclass = dbConnect.runSqlQuery(
  391. " select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
  392. + siteid + "'");
  393. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  394. for (Row row : rows) {
  395. JSONArray jsonArray = new JSONArray();
  396. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  397. if (coverRows.isEmpty()) {
  398. if (!defaultImageRows.isEmpty()) {
  399. row.put("cover", defaultImageRows.get(0).getString("url"));
  400. } else {
  401. row.put("cover", "");
  402. }
  403. } else {
  404. row.put("cover", coverRows.get(0).getString("url"));
  405. }
  406. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  407. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  408. Rows technicalinforowsforitem = technicalinfoRowsMap.get(row.getString("itemid"));
  409. for (Row row2 : technicalinforowsforitem) {
  410. jsonArray.add(plm_technicalinfoRowsMap.get(row2.getString("plm_technicalinfoid")));
  411. }
  412. row.put("technicalinfo", jsonArray);
  413. }
  414. return getSucReturnObject().setData(rows).toString();
  415. }
  416. @API(title = "删除明细", apiversion = R.ID20220923105103.v1.class)
  417. @CACHEING_CLEAN(cms = {@cm(clazz = itemgroup.class, method = {"queryItemgroupMxList", "queryItemgList"})})
  418. public String deletemx() throws YosException {
  419. ArrayList<String> sqlList = new ArrayList<>();
  420. Long sa_itemgroupmxid = content.getLong("sa_itemgroupmxid");
  421. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  422. Rows rowscount = dbConnect.runSqlQuery(
  423. "select isonsale from sa_itemgroup where sa_itemgroupid=" + sa_itemgroupid);
  424. if (!rowscount.isEmpty()) {
  425. if (rowscount.get(0).getBoolean("isonsale")) {
  426. return getErrReturnObject().setErrMsg("上架状态的商品组明细无法删除").toString();
  427. }
  428. }
  429. String sql = "DELETE FROM sa_itemgroupmx WHERE sa_itemgroupmxid = '" + sa_itemgroupmxid + "'";
  430. sqlList.add(sql);
  431. // sqlList.add("DELETE FROM sa_salesforecastbill WHERE sa_salesforecastmodelid = '" + sa_salesforecastmodelid + "'");
  432. // sqlList.add("DELETE FROM sa_salesforecasthr WHERE sa_salesforecastmodelid = '" + sa_salesforecastmodelid + "'");
  433. dbConnect.runSqlUpdate(sqlList);
  434. updateTradefield(sa_itemgroupid);
  435. return getSucReturnObject().toString();
  436. }
  437. @API(title = "删除", apiversion = R.ID20220922164503.v1.class)
  438. @CACHEING_CLEAN(cms = {@cm(clazz = itemgroup.class, method = {"queryItemgroup"})})
  439. public String delete() throws YosException {
  440. JSONArray sa_itemgroupids = content.getJSONArray("sa_itemgroupids");
  441. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_itemgroupids.size());
  442. ArrayList<String> sqllist = new ArrayList<>();
  443. for (Object o : sa_itemgroupids) {
  444. long sa_itemgroupid = Long.parseLong(o.toString());
  445. Rows rowscount = dbConnect.runSqlQuery("select isonsale from sa_itemgroup where sa_itemgroupid=" + sa_itemgroupid);
  446. if (rowscount.isEmpty()) {
  447. batchDeleteErr.addErr(sa_itemgroupid, "此商品组不存在,无法删除");
  448. } else {
  449. if (rowscount.get(0).getBoolean("isonsale")) {
  450. batchDeleteErr.addErr(sa_itemgroupid, "此商品组已上架,无法删除");
  451. }
  452. }
  453. String deletesql = "DELETE FROM sa_itemgroup WHERE sa_itemgroupid = '" + sa_itemgroupid + "'";
  454. sqllist.add(deletesql);
  455. }
  456. dbConnect.runSqlUpdate(sqllist);
  457. return batchDeleteErr.getReturnObject().toString();
  458. }
  459. /**
  460. * 获取商品组领域
  461. *
  462. * @return
  463. * @throws YosException
  464. */
  465. public void updateTradefield(Long sa_itemgroupid) throws YosException {
  466. String sql = "";
  467. String tradefield = "";
  468. Rows rows = dbConnect.runSqlQuery("select distinct t2.tradefield from sa_itemgroupmx t1 inner join plm_item_tradefield t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where sa_itemgroupid=" + sa_itemgroupid);
  469. if (!rows.isEmpty()) {
  470. for (Row row : rows) {
  471. tradefield = tradefield + row.getString("tradefield") + ",";
  472. }
  473. }
  474. if (!tradefield.equals("")) {
  475. tradefield = tradefield.substring(0, tradefield.length() - 1);
  476. dbConnect.runSqlUpdate("update sa_itemgroup set tradefield='" + tradefield + "' where sa_itemgroupid=" + sa_itemgroupid);
  477. }
  478. }
  479. }