Fad.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. package restcontroller.webmanage.saletool.fad;
  2. import beans.attachment.Attachment;
  3. import beans.brand.Brand;
  4. import beans.itemclass.ItemClass;
  5. import beans.time.Time;
  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.data.*;
  12. import org.apache.commons.lang.StringUtils;
  13. import restcontroller.R;
  14. import java.util.ArrayList;
  15. import java.util.LinkedHashSet;
  16. /**
  17. * 单品管理
  18. */
  19. public class Fad extends Controller {
  20. /**
  21. * 构造函数
  22. *
  23. * @param content
  24. */
  25. public Fad(JSONObject content) throws YosException {
  26. super(content);
  27. }
  28. String sa_fad = "sa_fad";
  29. @API(title = "单品新增或编辑", apiversion = R.ID20240418140902.v1.class)
  30. public String insertOrUpdate() throws YosException {
  31. Long sa_fadid = content.getLongValue("sa_fadid");
  32. Long itemid = content.getLongValue("itemid");
  33. int isonsale = content.getIntValue("isonsale");
  34. JSONArray sa_fadclassids = new JSONArray();
  35. if (content.containsKey("sa_fadclassids")) {
  36. sa_fadclassids = content.getJSONArray("sa_fadclassids");
  37. for (Object obj : sa_fadclassids) {
  38. if (!(obj instanceof JSONArray)) {
  39. return getErrReturnObject().setErrMsg("分类格式不正确").toString();
  40. }
  41. }
  42. }
  43. if (sa_fadid <= 0) {
  44. sa_fadid = createTableID(sa_fad);
  45. InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sa_fad);
  46. sqlFactory.setSiteid(siteid);
  47. sqlFactory.setUniqueid(sa_fadid);
  48. sqlFactory.setValue("name", content.getStringValue("name"));
  49. sqlFactory.setValue("model", content.getStringValue("model"));
  50. sqlFactory.setValue("spec", content.getStringValue("spec"));
  51. sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
  52. sqlFactory.setValue("outurl", content.getStringValue("outurl", true));
  53. sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
  54. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  55. sqlFactory.setValue("content", content.getStringValue("contentstr", true));
  56. sqlFactory.setValue("price", content.getBigDecimalValue("price"));
  57. sqlFactory.setValue("offsaledate", content.getStringValue("offsaledate", true, "null"));
  58. sqlFactory.setValue("sa_fadclassids", sa_fadclassids);
  59. sqlFactory.setValue("classid", 1);
  60. sqlFactory.insert();
  61. content.put("sa_fadid", sa_fadid);
  62. } else {
  63. UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sa_fad);
  64. sqlFactory.setUniqueid(sa_fadid);
  65. sqlFactory.setSiteid(siteid);
  66. sqlFactory.setValue("name", content.getStringValue("name"));
  67. sqlFactory.setValue("model", content.getStringValue("model"));
  68. sqlFactory.setValue("spec", content.getStringValue("spec"));
  69. sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
  70. sqlFactory.setValue("outurl", content.getStringValue("outurl", true));
  71. sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
  72. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  73. sqlFactory.setValue("content", content.getStringValue("contentstr", true));
  74. sqlFactory.setValue("price", content.getBigDecimalValue("price"));
  75. sqlFactory.setValue("offsaledate", content.getStringValue("offsaledate", true, "null"));
  76. sqlFactory.setValue("sa_fadclassids", sa_fadclassids);
  77. sqlFactory.update();
  78. }
  79. //上下架
  80. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
  81. updateSQL.setSiteid(siteid);
  82. updateSQL.setWhere("sa_fadid", sa_fadid);
  83. updateSQL.setValue("isonsale", isonsale);
  84. updateSQL.setValue("onsaledate", isonsale == 1 ? Time.getDateTime_Str() : "null");
  85. updateSQL.setValue("onsaleby", isonsale == 1 ? username : "null");
  86. updateSQL.update();
  87. //关联商品
  88. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fad_link");
  89. insertSQL.setSiteid(siteid);
  90. insertSQL.setUniqueid(createTableID("sa_fad_link"));
  91. insertSQL.setValue("itemid", itemid);
  92. insertSQL.setValue("sa_fadid", sa_fadid);
  93. insertSQL.setWhere("not exists(select 1 from sa_fad_link where itemid=" + itemid + " and sa_fadid=" + sa_fadid + " )");
  94. insertSQL.insert();
  95. //插入图片
  96. Rows rows = Attachment.get(this, "plm_item", itemid, "cover");
  97. if (rows.isEmpty()) {
  98. rows = Attachment.get(this, "plm_item", itemid, "default");
  99. }
  100. if (rows.isNotEmpty()) {
  101. insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
  102. insertSQL.setSiteid(siteid);
  103. insertSQL.setUniqueid(createTableID("sys_attachment_links"));
  104. insertSQL.setValue("usetype", sa_fad);
  105. insertSQL.setValue("attachmentid", rows.get(0).getLong("attachmentid"));
  106. insertSQL.setValue("sequence", 1);
  107. insertSQL.setValue("ownertable", sa_fad);
  108. insertSQL.setValue("ownerid", sa_fadid);
  109. insertSQL.setWhere("not exists(select 1 from sys_attachment_links where attachmentid=" + rows.get(0).getLong("attachmentid") + " and ownertable='sa_fad' and siteid='" + siteid + "' and ownerid=" + sa_fadid + " )");
  110. insertSQL.insert();
  111. }
  112. return detail();
  113. }
  114. @API(title = "单品详情", apiversion = R.ID20240418141002.v1.class,accesstoken = false)
  115. public String detail() throws YosException {
  116. Long sa_fadid = content.getLongValue("sa_fadid");
  117. String ownertable = sa_fad;
  118. Rows fadrows = dbConnect.runSqlQuery("select * from sa_fad where sa_fadid=" + sa_fadid);
  119. if (fadrows.isNotEmpty()) {
  120. siteid = fadrows.get(0).getString("siteid");
  121. }
  122. dbConnect.runSqlUpdate("UPDATE sa_fad SET readcount=readcount+1 WHERE sa_fadid="+sa_fadid);
  123. QuerySQL querySQ = SQLFactory.createQuerySQL(this, sa_fad)
  124. .setTableAlias("t1");
  125. querySQ.addJoinTable(JOINTYPE.left, "sys_datacollect", "t2", "t2.siteid=t1.siteid and t2.ownertable='sa_fad' and t2.type=1 and t2.ownerid=t1.sa_fadid and t2.userid='" + userid + "'");
  126. querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END");
  127. querySQ.setSiteid(siteid);
  128. querySQ.setWhere("sa_fadid", sa_fadid);
  129. Rows rows = querySQ.query();
  130. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  131. Rows attRows = getAttachmentUrl(sa_fad, sa_fadid);
  132. attRows.sortby("sequence","linksid");
  133. detailRow.put("attinfos", attRows);
  134. detailRow.put("appleturl", FadHelper.getAppletUrl(this, "FadUrl", "单品小程序链接") + sa_fadid);
  135. QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
  136. attachmentQuery.setSiteid(detailRow.getString("siteid"));
  137. attachmentQuery.setWhere("ownertable", ownertable);
  138. attachmentQuery.setWhere("ownerid", sa_fadid);
  139. attachmentQuery.setWhere("usetype", ownertable);
  140. attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
  141. Rows attachmentRows = attachmentQuery.query();
  142. ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
  143. RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
  144. for (Row row : attachmentRows) {
  145. Rows attPicRows = new Rows();
  146. Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
  147. for (Row tempAttRow : tempAttRows) {
  148. if (tempAttRow.getString("usetype").equals(ownertable)) {
  149. attPicRows.add(tempAttRow);
  150. }
  151. }
  152. row.put("attinfos", attPicRows);
  153. }
  154. detailRow.put("attinfos_pic", attachmentRows);
  155. detailRow.putIfAbsent("offsaledate", "");
  156. detailRow.putIfAbsent("onsaledate", "");
  157. detailRow.put("classnames", getClassnames(detailRow.getJSONArray("sa_fadclassids"), false));
  158. detailRow.put("mainclassnames", getClassnames(detailRow.getJSONArray("sa_fadclassids"), true));
  159. return getSucReturnObject().setData(detailRow).toString();
  160. }
  161. @API(title = "单品删除", apiversion = R.ID20240418141102.v1.class)
  162. public String delete() throws YosException {
  163. JSONArray sa_fadids = content.getJSONArray("sa_fadids");
  164. if (sa_fadids.size() == 0) {
  165. return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
  166. }
  167. DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sa_fad);
  168. sqlFactory.setSiteid(siteid);
  169. sqlFactory.setWhere("sa_fadid", sa_fadids.toArray());
  170. sqlFactory.delete();
  171. return getSucReturnObject().toString();
  172. }
  173. @API(title = "单品上下架", apiversion = R.ID20240418141202.v1.class)
  174. public String isonsale() throws YosException {
  175. JSONArray sa_fadids = content.getJSONArray("sa_fadids");
  176. int isonsale = content.getIntValue("isonsale");
  177. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
  178. updateSQL.setSiteid(siteid);
  179. updateSQL.setWhere("sa_fadid", sa_fadids);
  180. updateSQL.setValue("isonsale", isonsale);
  181. updateSQL.setValue("onsaledate", isonsale == 0 ? "null" : Time.getDateTime_Str());
  182. updateSQL.setValue("onsaleby", isonsale == 0 ? "null" : username);
  183. updateSQL.update();
  184. return getSucReturnObject().toString();
  185. }
  186. @API(title = "单品列表", apiversion = R.ID20240418141302.v1.class)
  187. public String list() throws YosException {
  188. /*
  189. 过滤条件设置
  190. */
  191. StringBuffer where = new StringBuffer(" 1=1 ");
  192. if (content.containsKey("where")) {
  193. JSONObject whereObject = content.getJSONObject("where");
  194. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  195. where.append(" and (");
  196. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  197. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  198. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  199. where.append(")");
  200. }
  201. if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
  202. where.append(" and (");
  203. where.append("t1.isonsale ='").append(whereObject.getString("isonsale")).append("' ");
  204. where.append(")");
  205. }
  206. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  207. where.append(" and (");
  208. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  209. where.append(")");
  210. }
  211. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  212. where.append(" and (");
  213. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  214. where.append(")");
  215. }
  216. if (whereObject.containsKey("begindate_onsale") && !"".equals(whereObject.getString("begindate_onsale"))) {
  217. where.append(" and (");
  218. where.append("t1.onsaledate >='").append(whereObject.getString("begindate_onsale")).append("' ");
  219. where.append(")");
  220. }
  221. if (whereObject.containsKey("enddate_onsale") && !"".equals(whereObject.getString("enddate_onsale"))) {
  222. where.append(" and (");
  223. where.append("t1.onsaledate <='").append(whereObject.getString("enddate_onsale")).append(" 23:59:59' ");
  224. where.append(")");
  225. }
  226. if (whereObject.containsKey("sa_fadclassids") && !"".equals(whereObject.getString("sa_fadclassids"))) {
  227. JSONArray sa_fadclassids = whereObject.getJSONArray("sa_fadclassids");
  228. if (sa_fadclassids.size() > 0) {
  229. where.append(" and (1=2");
  230. for (Object obj : sa_fadclassids) {
  231. JSONArray array = (JSONArray) obj;
  232. for (Object obj2 : array) {
  233. where.append(" or (");
  234. where.append("JSON_CONTAINS(t1.sa_fadclassids,'" + obj2 + "')");
  235. where.append(")");
  236. }
  237. }
  238. where.append(")");
  239. }
  240. }
  241. if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) {
  242. if (whereObject.getString("iscollect").equals("1")) {
  243. where.append(" and (");
  244. where.append(" t1.sa_fadid in (SELECT ownerid from sys_datacollect WHERE ownertable='sa_fad' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")");
  245. where.append(")");
  246. }
  247. }
  248. }
  249. QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
  250. "sa_fadid", "name", "isonsale", "model", "spec", "price", "sequence", "createby", "createdate", "onsaledate")
  251. .setTableAlias("t1");
  252. querySQL.setSiteid(siteid);
  253. querySQL.setWhere("classid",1);
  254. querySQL.setWhere(where.toString());
  255. querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  256. Rows rows = querySQL.query();
  257. ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
  258. // 附件
  259. RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
  260. for (Row row : rows) {
  261. Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
  262. attRows.sortby("sequence","linksid");
  263. row.put("attinfos", attRows);
  264. row.put("appleturl", FadHelper.getAppletUrl(this, "FadUrl", "单品小程序链接") + row.getString("sa_fadid"));
  265. row.putIfAbsent("onsaledate", "");
  266. }
  267. return getSucReturnObject().setData(rows).toString();
  268. }
  269. @API(title = "选择商品列表", apiversion = R.ID20240418141402.v1.class)
  270. public String chooseItemlist() throws YosException {
  271. StringBuffer where = new StringBuffer(" 1=1 ");
  272. if (content.containsKey("where")) {
  273. JSONObject whereObject = content.getJSONObject("where");
  274. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  275. where.append(" and(");
  276. where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  277. where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  278. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  279. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  280. where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
  281. where.append(")");
  282. }
  283. }
  284. Long sa_fadid = content.getLongValue("sa_fadid");
  285. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
  286. , "itemid", "itemname", "itemno", "model", "spec", "color", "marketprice", "standards");
  287. querySQL.setTableAlias("t1");
  288. querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
  289. "itemclassname");
  290. querySQL.setWhere("t1.siteid", siteid);
  291. querySQL.setWhere(where.toString());
  292. querySQL.setWhere("not exists(select 1 from sa_fad_link where sa_fadid=" + sa_fadid + " and itemid=t1.itemid and siteid='" + siteid + "' )");
  293. querySQL.setOrderBy(pageSorting);
  294. querySQL.setPage(pageSize, pageNumber);
  295. Rows rows = querySQL.query();
  296. // 默认商品图片
  297. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  298. // 附件
  299. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  300. RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
  301. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  302. // 商品领域
  303. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  304. RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
  305. for (Row row : rows) {
  306. if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
  307. row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
  308. } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
  309. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  310. } else {
  311. row.put("attinfos", defaultImageRows);
  312. }
  313. String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
  314. row.put("tradefield", StringUtils.join(tradefield, ","));
  315. String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
  316. row.put("itemclass", StringUtils.join(itemclass, ","));
  317. }
  318. return getSucReturnObject().setData(rows).toString();
  319. }
  320. @API(title = "关联商品列表", apiversion = R.ID20240418141502.v1.class)
  321. public String relateItemlist() throws YosException {
  322. StringBuffer where = new StringBuffer(" 1=1 ");
  323. if (content.containsKey("where")) {
  324. JSONObject whereObject = content.getJSONObject("where");
  325. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  326. where.append(" and(");
  327. where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  328. where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  329. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  330. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  331. where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
  332. where.append(")");
  333. }
  334. }
  335. Long sa_fadid = content.getLongValue("sa_fadid");
  336. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
  337. , "itemid", "itemname", "itemno", "model", "spec", "color", "marketprice", "standards");
  338. querySQL.setTableAlias("t1");
  339. querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
  340. "itemclassname");
  341. querySQL.addJoinTable(JOINTYPE.inner, "sa_fad_link", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid",
  342. "sa_fad_linkid");
  343. querySQL.setWhere("t1.siteid", siteid);
  344. querySQL.setWhere(where.toString());
  345. querySQL.setWhere("t3.sa_fadid",sa_fadid);
  346. querySQL.setOrderBy(pageSorting);
  347. querySQL.setPage(pageSize, pageNumber);
  348. Rows rows = querySQL.query();
  349. // 默认商品图片
  350. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  351. // 附件
  352. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  353. RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
  354. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  355. // 商品领域
  356. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  357. RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
  358. for (Row row : rows) {
  359. if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
  360. row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
  361. } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
  362. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  363. } else {
  364. row.put("attinfos", defaultImageRows);
  365. }
  366. String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
  367. row.put("tradefield", StringUtils.join(tradefield, ","));
  368. String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
  369. row.put("itemclass", StringUtils.join(itemclass, ","));
  370. }
  371. return getSucReturnObject().setData(rows).toString();
  372. }
  373. @API(title = "关联商品", apiversion = R.ID20240418141602.v1.class)
  374. public String relateItem() throws YosException {
  375. Long sa_fadid = content.getLongValue("sa_fadid");
  376. JSONArray itemids = content.getJSONArray("itemids");
  377. ArrayList<String> sqlList = new ArrayList<>();
  378. for (Object obj : itemids) {
  379. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fad_link");
  380. insertSQL.setSiteid(siteid);
  381. insertSQL.setUniqueid(createTableID("sa_fad_link"));
  382. insertSQL.setValue("itemid", obj);
  383. insertSQL.setValue("sa_fadid", sa_fadid);
  384. sqlList.add(insertSQL.getSQL());
  385. }
  386. dbConnect.runSqlUpdate(sqlList);
  387. return getSucReturnObject().toString();
  388. }
  389. @API(title = "删除商品", apiversion = R.ID20240418141702.v1.class)
  390. public String deleteItem() throws YosException {
  391. JSONArray sa_fad_linkids = content.getJSONArray("sa_fad_linkids");
  392. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fad_link");
  393. deleteSQL.setSiteid(siteid);
  394. deleteSQL.setWhere("sa_fad_linkid", sa_fad_linkids);
  395. deleteSQL.delete();
  396. return getSucReturnObject().toString();
  397. }
  398. public String getClassnames(JSONArray sa_fadclassids, boolean isMain) throws YosException {
  399. //[[1,2,3,6],[1,2]]
  400. RowsMap rowsMap = dbConnect.runSqlQuery("SELECT sa_fadclassid,classname from sa_fadclass WHERE siteid='" + siteid + "'").toRowsMap("sa_fadclassid");
  401. LinkedHashSet<String> classnames = new LinkedHashSet<>();
  402. for (Object object : sa_fadclassids) {
  403. ArrayList<String> temp = new ArrayList<>();
  404. if (object instanceof JSONArray) {
  405. JSONArray array = (JSONArray) object;
  406. for (Object obj : array) {
  407. temp.add(rowsMap.get(obj.toString()).get(0).getString("classname"));
  408. }
  409. }
  410. if (isMain) {
  411. classnames.add(temp.get(0));
  412. } else {
  413. classnames.add(String.join("-", temp));
  414. }
  415. }
  416. return String.join(";", classnames);
  417. }
  418. }