itemgroup.java 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. package restcontroller.sale.itemgroup;
  2. import beans.Item.Item;
  3. import beans.datatag.DataTag;
  4. import beans.enterprise.Enterprise;
  5. import beans.itemclass.ItemClass;
  6. import beans.itemgroup.Itemgroup;
  7. import beans.itemprice.ItemPrice;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  11. import common.Controller;
  12. import common.YosException;
  13. import common.annotation.API;
  14. import common.annotation.CACHEING;
  15. import common.data.Row;
  16. import common.data.Rows;
  17. import common.data.RowsMap;
  18. import common.data.SQLFactory;
  19. import org.apache.commons.lang.StringUtils;
  20. import restcontroller.R;
  21. import restcontroller.sale.promotion.promotion;
  22. import java.math.BigDecimal;
  23. import java.util.*;
  24. @API(title = "商品组")
  25. public class itemgroup extends Controller {
  26. public itemgroup(JSONObject arg0) throws YosException {
  27. super(arg0);
  28. // TODO Auto-generated constructor stub
  29. }
  30. /**
  31. * * 查询商品组
  32. *
  33. * @return
  34. */
  35. @API(title = "查询", apiversion = R.ID20221219113503.v1.class)
  36. @CACHEING
  37. public String queryItemSaleClasses() throws YosException {
  38. Long istool = content.getLongValue("istool");
  39. Rows itemclassRows = Enterprise.getItemSaleClasses(this, sys_enterpriseid, true, istool);
  40. return getSucReturnObject().setData(itemclassRows).toString();
  41. }
  42. /**
  43. * * 查询商品组
  44. *
  45. * @return
  46. */
  47. @API(title = "查询", apiversion = R.ID20220926142203.v1.class)
  48. @CACHEING
  49. public String queryItemgroup() throws YosException {
  50. Long istool = content.getLongValue("istool");
  51. //Rows itemclassRows = Enterprise.getItemSaleClasses(this, sys_enterpriseid, true, istool);
  52. if (content.containsKey("sys_enterpriseid")) {
  53. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  54. }
  55. /*
  56. * * 过滤条件设置
  57. */
  58. String where = " 1=1 ";
  59. String where1 = "";
  60. String itemclasssql = "select itemclassid from plm_itemclass where siteid='" + siteid + "'";
  61. if (sys_enterpriseid > 0) {
  62. Row enterpriseRow = Enterprise.getEnterprise(this, sys_enterpriseid);
  63. if (!enterpriseRow.isEmpty()) {
  64. //企业营销类别
  65. boolean saleclassauth = enterpriseRow.getBoolean("saleclassauth");
  66. if (saleclassauth) {
  67. itemclasssql = "select itemclassid from plm_itemclass where siteid='" + siteid + "' and itemclassid in ( SELECT itemclassid from sys_enterprise_saleclass WHERE sys_enterpriseid = " + sys_enterpriseid + " and siteid='" + siteid + "')";
  68. }
  69. //企业领域
  70. Rows tradefieldrows = dbConnect.runSqlQuery("SELECT tradefield from sys_enterprise_tradefield WHERE sys_enterpriseid =" + sys_enterpriseid + " and siteid ='" + siteid + "'");
  71. if (!tradefieldrows.isEmpty()) {
  72. for (Row row : tradefieldrows) {
  73. where1 = where1 + " (t1.tradefield like'%" + row.getString("tradefield") + "%') or ";
  74. }
  75. } else {
  76. where1 = where1 + " 1=2 ";
  77. }
  78. } else {
  79. where1 = " 1=2 ";
  80. }
  81. } else {
  82. where1 = " 1=1 ";
  83. }
  84. if (where1.contains("or")) {
  85. where1 = where1.substring(0, where1.lastIndexOf("or"));
  86. }
  87. Rows itemclassRows = dbConnect.runSqlQuery(itemclasssql);
  88. ArrayList<Long> itemclassList = new ArrayList<Long>();
  89. for (Row row : itemclassRows) {
  90. //System.out.println(row.getLong("itemclassid"));
  91. itemclassList.add(row.getLong("itemclassid"));
  92. itemclassList.addAll(ItemClass.getSubItemClassIds(this, row.getLong("itemclassid")));
  93. }
  94. SQLFactory factorygroupid = new SQLFactory(this, "查询授权范围内的商品组商品");
  95. factorygroupid.addParameter("siteid", siteid);
  96. if (content.containsKey("where")) {
  97. JSONObject whereObject = content.getJSONObject("where");
  98. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  99. where = where + " and (t1.groupname like'%" + whereObject.getString("condition")
  100. + "%' or t1.groupnum like'%" + whereObject.getString("condition")
  101. + "%' or exists(select 1 from sa_itemgroupmx s1 left join plm_item s2 on s1.itemid=s2.itemid and s1.siteid=s2.siteid where (s2.itemname like '%"
  102. + whereObject.getString("condition") + "%' or s2.itemno like '%" + whereObject.getString("condition")
  103. + "%' or s2.standards like '%" + whereObject.getString("condition")
  104. + "%' or s2.spec like '%" + whereObject.getString("condition")
  105. + "%' or s2.model like '%" + whereObject.getString("condition")
  106. + "%') and s1.sa_itemgroupid=t1.sa_itemgroupid) ) ";
  107. }
  108. if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
  109. where = where + " and (t1.tradefield like'%" + whereObject.getString("tradefield") + "%') ";
  110. }
  111. // else {
  112. // if (sys_enterpriseid > 0) {
  113. // where = where + " and (t1.tradefield in (SELECT tradefield from sys_enterprise_tradefield WHERE sys_enterpriseid = " + sys_enterpriseid + " and siteid='" + siteid + "') ) ";
  114. // }
  115. // }
  116. if (whereObject.containsKey("standards") && !"".equals(whereObject.getString("standards"))) {
  117. where = where
  118. + " and exists(select 1 from sa_itemgroupmx s1 left join plm_item s2 on s1.itemid=s2.itemid and s1.siteid=s2.siteid where s2.standards='"
  119. + whereObject.getString("standards") + "' and s1.sa_itemgroupid=t1.sa_itemgroupid) ";
  120. }
  121. if (whereObject.containsKey("itemclassid") && !"".equals(whereObject.getString("itemclassid"))) {
  122. ArrayList<Long> list = ItemClass.getSubItemClassIds(this, whereObject.getLong("itemclassid"));
  123. list.add(whereObject.getLong("itemclassid"));
  124. ArrayList<Long> listNew = new ArrayList<>();
  125. listNew.add((long) 0);
  126. for (long itemclassid : list) {
  127. if (itemclassList.contains(itemclassid)) {
  128. listNew.add(itemclassid);
  129. }
  130. }
  131. factorygroupid.addParameter_in("itemclassid", listNew);
  132. } else {
  133. factorygroupid.addParameter_in("itemclassid",
  134. itemclassList);
  135. }
  136. } else {
  137. factorygroupid.addParameter_in("itemclassid",
  138. itemclassList);
  139. }
  140. JSONArray brandids = content.getJSONArray("brandids");
  141. if (brandids.isEmpty()) {
  142. Rows rows;
  143. if (sys_enterpriseid > 0) {
  144. rows = Enterprise.getBrands(this, sys_enterpriseid);
  145. } else {
  146. rows = dbConnect.runSqlQuery("select sa_brandid from sa_brand where siteid='" + siteid + "'");
  147. }
  148. if (!rows.isEmpty()) {
  149. for (Row row : rows) {
  150. brandids.add(row.getLong("sa_brandid"));
  151. }
  152. } else {
  153. brandids.add(0);
  154. }
  155. }
  156. factorygroupid.addParameter("siteid", siteid);
  157. Enterprise.EnterpriseGrade enterpriseGrade = Enterprise.getEnterpriseGrade(this, sys_enterpriseid);
  158. if (enterpriseGrade != null) {
  159. factorygroupid.addParameter("pricegrade", enterpriseGrade.getPricegrade());
  160. }else {
  161. Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
  162. if(!siteParameterRows.isEmpty()){
  163. if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
  164. factorygroupid.addParameter("pricegrade", "1");
  165. }else{
  166. factorygroupid.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
  167. }
  168. }else{
  169. factorygroupid.addParameter("pricegrade", "1");
  170. }
  171. }
  172. Rows rowsgroupids = dbConnect.runSqlQuery(factorygroupid.getSQL());
  173. RowsMap itemgroupRowMap = rowsgroupids.toRowsMap("sa_itemgroupid");
  174. /*
  175. * SQL查询参数设置并查询
  176. */
  177. SQLFactory factory = new SQLFactory(this, "商品组列表查询", pageSize, pageNumber, pageSorting);
  178. factory.addParameter("siteid", siteid);
  179. factory.addParameter_in("sa_brandid", brandids.toArray());
  180. factory.addParameter_in("sa_itemgroupids", rowsgroupids.toArrayList("sa_itemgroupid", new ArrayList<Long>()));
  181. factory.addParameter_SQL("where", where);
  182. factory.addParameter_SQL("where1", where1);
  183. String sql = factory.getSQL();
  184. //System.out.println(sql);
  185. Rows rows = dbConnect.runSqlQuery(sql);
  186. ArrayList<Long> itemgroupids = rows.toArrayList("sa_itemgroupid", new ArrayList<Long>());
  187. RowsMap itemgroupScemeRowsMap = Itemgroup.getItemgroupScemeid(this, itemgroupids);
  188. for (Row row2 : rows) {
  189. long sa_itemgroupid = row2.getLong("sa_itemgroupid");
  190. ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", sa_itemgroupid, false);
  191. row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
  192. // HashMap<Long, ItemPrice> ItemPriceList = ItemPrice.getItemGroupPrice(this, sys_enterpriseid,
  193. // row2.getLong("sa_itemgroupid"));
  194. // BigDecimal max = new BigDecimal(0);
  195. // BigDecimal min = ((ItemPrice) ItemPriceList.values().toArray()[0]).getPrice();
  196. // for (ItemPrice itemPrice : ItemPriceList.values()) {
  197. // BigDecimal itemprice = itemPrice.getPrice();
  198. // if (itemprice.compareTo(max) >0) {
  199. // max = itemprice;
  200. // }
  201. // if (itemprice.compareTo(min) <0) {
  202. // min = itemprice;
  203. // }
  204. // }
  205. Rows rows1 = itemgroupRowMap.get(String.valueOf(sa_itemgroupid));
  206. if (rows1.isEmpty()) {
  207. row2.put("maxprice", 0);
  208. row2.put("minprice", 0);
  209. } else {
  210. row2.put("maxprice", rows1.get(0).getBigDecimal("maxprice"));
  211. row2.put("minprice", rows1.get(0).getBigDecimal("minprice"));
  212. }
  213. Long id = sa_itemgroupid;
  214. if (itemgroupScemeRowsMap.get(id.toString()).isNotEmpty()) {
  215. if (itemgroupScemeRowsMap.get(id.toString()).get(0).getLong("sa_customschemeid") > 0) {
  216. row2.put("isscheme", true);
  217. } else {
  218. row2.put("isscheme", false);
  219. }
  220. } else {
  221. row2.put("isscheme", false);
  222. }
  223. }
  224. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  225. /**
  226. * 查询商品明细
  227. */
  228. SQLFactory sqlFactory = new SQLFactory(this, "查询商品列表");
  229. sqlFactory.addParameter_in("itemids", ids);
  230. sqlFactory.addParameter("siteid", siteid);
  231. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  232. Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  233. for (Row row : itemrows) {
  234. ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
  235. row.put("oldprice", itemPrice.getPrice());
  236. if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
  237. row.put("gradeprice", itemPrice.getContractprice());
  238. } else {
  239. row.put("gradeprice", itemPrice.getMarketprice());
  240. }
  241. }
  242. RowsMap itemRowsMap = itemrows.toRowsMap("itemid");
  243. //默认商品图片
  244. Rows defaultImageRows = Item.getItemdefaultImage(this);
  245. // 封面cover
  246. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  247. // 附件
  248. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  249. // 附件
  250. RowsMap itemgroupRowsMap = getAttachmentUrl("sa_itemgroup", itemgroupids);
  251. Rows rowsitemclass = dbConnect.runSqlQuery(
  252. " select t7.itemclassname,t6.itemid,t8.brandname,t7.itemclassfullname 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='"
  253. + siteid + "'");
  254. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  255. for (Row row : rows) {
  256. Rows itemRows = itemRowsMap.get(row.getString("itemid"));
  257. row.put("item", itemRows);
  258. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  259. if (coverRows.isEmpty()) {
  260. if (!defaultImageRows.isEmpty()) {
  261. row.put("cover", defaultImageRows.get(0).getString("url"));
  262. } else {
  263. row.put("cover", "");
  264. }
  265. } else {
  266. row.put("cover", coverRows.get(0).getString("url"));
  267. }
  268. if ((itemgroupRowsMap.getOrDefault(row.getString("sa_itemgroupid"), new Rows())).isNotEmpty()) {
  269. row.put("attinfos", itemgroupRowsMap.getOrDefault(row.getString("sa_itemgroupid"), new Rows()));
  270. } else {
  271. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  272. row.put("attinfos", defaultImageRows);
  273. } else {
  274. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  275. }
  276. }
  277. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  278. }
  279. return getSucReturnObject().setData(rows).toString();
  280. }
  281. @API(title = "商品组详情", apiversion = R.ID20220926142303.v1.class)
  282. public String queryItemgroupMain() throws YosException {
  283. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  284. SQLFactory sqlFactory = new SQLFactory(this, "商品组详情查询");
  285. sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  286. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  287. Rows rowsitemclass = dbConnect.runSqlQuery(
  288. " 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='"
  289. + siteid + "'");
  290. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  291. if (!rows.isEmpty()) {
  292. ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", rows.get(0).getLong("sa_itemgroupid"),
  293. false);
  294. rows.get(0).put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
  295. rows.get(0).put("itemclass", itemclassRowsMap.get(rows.get(0).getString("itemid")));
  296. }
  297. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  298. }
  299. @API(title = "商品组商品明细列表", apiversion = R.ID20220926142403.v1.class)
  300. @CACHEING
  301. public String queryItemgroupMxList() throws YosException {
  302. if (content.containsKey("sys_enterpriseid")) {
  303. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  304. }
  305. /*
  306. * 过滤条件设置
  307. */
  308. String where = " 1=1 ";
  309. if (content.containsKey("where")) {
  310. JSONObject whereObject = content.getJSONObject("where");
  311. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  312. where = where + "and t2.itemname like'%" + whereObject.getString("condition") + "%'";
  313. }
  314. }
  315. Long sa_itemgroupid = content.getLong("sa_itemgroupid");
  316. // String hrid = content.getString("hrid");
  317. SQLFactory sqlFactory = new SQLFactory(this, "商品组商品明细查询", pageSize, pageNumber, pageSorting);
  318. sqlFactory.addParameter_SQL("where", where);
  319. sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  320. sqlFactory.addParameter("siteid", siteid);
  321. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  322. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  323. //默认商品图片
  324. Rows defaultImageRows = Item.getItemdefaultImage(this);
  325. // 封面cover
  326. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  327. // 附件
  328. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  329. Rows technicalinforows = dbConnect.runSqlQuery("select plm_technicalinfoid,itemid from plm_technicalinfo_item");
  330. RowsMap technicalinfoRowsMap = technicalinforows.toRowsMap("itemid");
  331. Rows technicalinforows1 = dbConnect.runSqlQuery("select plm_technicalinfoid from plm_technicalinfo");
  332. ArrayList<Long> plm_technicalinfoids = technicalinforows1.toArrayList("plm_technicalinfoid", new ArrayList<>());
  333. // 产品技术资料附件
  334. RowsMap plm_technicalinfoRowsMap = getAttachmentUrl("plm_technicalinfo", plm_technicalinfoids);
  335. // 商品领域
  336. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  337. Rows rowsitemclass = dbConnect.runSqlQuery(
  338. " 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='"
  339. + siteid + "'");
  340. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  341. RowsMap itemextendRowsMap = dbConnect.runSqlQuery("select itemid,material,device,prodline,specalnote,pressure,connection,valveplatematerial,actuatortype,actuatorbrand,butterflyplatedrive from plm_itemextend where siteid='" + siteid + "'").toRowsMap("itemid");
  342. SQLFactory priceSqlFactory = new SQLFactory(this, "查询商品原价");
  343. priceSqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
  344. priceSqlFactory.addParameter("siteid", siteid);
  345. Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
  346. if(!siteParameterRows.isEmpty()){
  347. if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
  348. priceSqlFactory.addParameter("pricegrade", "1");
  349. }else{
  350. priceSqlFactory.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
  351. }
  352. }else{
  353. priceSqlFactory.addParameter("pricegrade", "1");
  354. }
  355. Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
  356. RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
  357. for (Row row : rows) {
  358. ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
  359. row.put("oldprice", itemPrice.getMarketprice());
  360. if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
  361. row.put("gradeprice", itemPrice.getContractprice());
  362. } else {
  363. if(pricerowsMap.containsKey(row.getString("itemid"))){
  364. if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
  365. row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
  366. }else{
  367. row.put("gradeprice",0);
  368. }
  369. }else {
  370. row.put("gradeprice", 0);
  371. }
  372. }
  373. Rows jsonArray = new Rows();
  374. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  375. if (coverRows.isEmpty()) {
  376. row.put("cover", "");
  377. } else {
  378. row.put("cover", coverRows.get(0).getString("url"));
  379. }
  380. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  381. row.put("attinfos", defaultImageRows);
  382. } else {
  383. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  384. }
  385. //row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  386. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  387. Rows technicalinforowsforitem = technicalinfoRowsMap.get(row.getString("itemid"));
  388. for (Row row2 : technicalinforowsforitem) {
  389. jsonArray.addAll(plm_technicalinfoRowsMap.get(row2.getString("plm_technicalinfoid")));
  390. }
  391. row.put("technicalinfo", jsonArray);
  392. row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  393. if (itemextendRowsMap.containsKey(row.getString("itemid"))) {
  394. row.put("itemextend", itemextendRowsMap.get(row.getString("itemid")));
  395. } else {
  396. row.put("itemextend", new Rows());
  397. }
  398. }
  399. return getSucReturnObject().setData(rows).toString();
  400. }
  401. @API(title = "商品组列表", apiversion = R.ID20221223165503.v1.class)
  402. @CACHEING
  403. public String querymx() throws YosException {
  404. Set<String> listParmBlank = new LinkedHashSet<String>();
  405. Set<String> listParmNotBlank = new LinkedHashSet<String>();
  406. Set<String> firstcolorList = new LinkedHashSet();
  407. Set<String> firstspecList = new LinkedHashSet();
  408. Set<String> firstmaterialList = new LinkedHashSet();
  409. Set<String> firstcheekList = new LinkedHashSet();
  410. Set<parm> colorList = new LinkedHashSet();
  411. Set<parm> specList = new LinkedHashSet();
  412. Set<parm> materialList = new LinkedHashSet();
  413. Set<parm> cheekList = new LinkedHashSet();
  414. String color = content.getStringValue("color");
  415. String spec = content.getStringValue("spec");
  416. String material = content.getStringValue("material");
  417. String cheek = content.getStringValue("cheek");
  418. /**
  419. * SQL商品组明细查询参数设置并查询
  420. */
  421. Rows rows = null;
  422. SQLFactory factory = new SQLFactory(this, "商品组明细查询");
  423. factory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
  424. factory.addParameter("siteid", siteid);
  425. String where1 = " 1=1 ";
  426. Rows tradefieldRows = dbConnect.runSqlQuery("SELECT DISTINCT t1.tradefield from sys_enterprise_tradefield t1 WHERE t1.sys_enterpriseid = " + sys_enterpriseid + " and t1.siteid='" + siteid + "'");
  427. if (!tradefieldRows.isEmpty()) {
  428. for (Row row : tradefieldRows) {
  429. where1 = where1 + " or t4.tradefield like '%" + row.getString("tradefield") + "%' ";
  430. }
  431. }
  432. factory.addParameter_SQL("where1", where1);
  433. Rows customschemeItems = dbConnect.runSqlQuery("select * from (select distinct value,description,isonlydisplay,sequence from sa_customscheme_items where sa_customschemeid in(select t2.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=" + content.getString("sa_itemgroupid") + "))t order by t.sequence asc");
  434. if (!customschemeItems.isEmpty()) {
  435. for (Row row : customschemeItems) {
  436. if (StringUtils.isNotBlank(row.getString("value"))) {
  437. if (StringUtils.isNotBlank(content.getString(row.getString("value")))) {
  438. listParmNotBlank.add(row.getString("value"));
  439. } else {
  440. listParmBlank.add(row.getString("value"));
  441. }
  442. }
  443. }
  444. }
  445. Set<String> listAll = new LinkedHashSet<String>();
  446. listAll.addAll(listParmBlank);
  447. listAll.addAll(listParmNotBlank);
  448. factory.addParameter_SQL("where", "1=1");
  449. rows = dbConnect.runSqlQuery(factory.getSQL());
  450. for (Row row : rows) {
  451. for (String value : listAll) {
  452. if (value.equals("color")) {
  453. firstcolorList.add(row.getString("color"));
  454. } else if (value.equals("spec")) {
  455. firstspecList.add(row.getString("spec"));
  456. } else if (value.equals("material")) {
  457. firstmaterialList.add(row.getString("material"));
  458. } else if (value.equals("cheek")) {
  459. firstcheekList.add(row.getString("cheek"));
  460. }
  461. }
  462. }
  463. JSONArray colormap = new JSONArray();
  464. JSONArray specmap = new JSONArray();
  465. JSONArray materialmap = new JSONArray();
  466. JSONArray cheekmap = new JSONArray();
  467. if (listParmNotBlank == null || listParmNotBlank.size() == 0) {
  468. factory.addParameter_SQL("where", "1=1");
  469. for (Row row : rows) {
  470. for (String value : listParmBlank) {
  471. if (value.equals("color")) {
  472. JSONObject jsonObject = new JSONObject();
  473. jsonObject.put("parm", row.getString("color"));
  474. jsonObject.put("flag", true);
  475. colormap.add(jsonObject);
  476. } else if (value.equals("spec")) {
  477. JSONObject jsonObject = new JSONObject();
  478. jsonObject.put("parm", row.getString("spec"));
  479. jsonObject.put("flag", true);
  480. specmap.add(jsonObject);
  481. } else if (value.equals("material")) {
  482. JSONObject jsonObject = new JSONObject();
  483. jsonObject.put("parm", row.getString("material"));
  484. jsonObject.put("flag", true);
  485. materialmap.add(jsonObject);
  486. } else if (value.equals("cheek")) {
  487. JSONObject jsonObject = new JSONObject();
  488. jsonObject.put("parm", row.getString("cheek"));
  489. jsonObject.put("flag", true);
  490. cheekmap.add(jsonObject);
  491. }
  492. }
  493. }
  494. } else if (listParmBlank == null || listParmBlank.size() == 0) {
  495. // for (Row row : rows) {
  496. // for (String value : listParmNotBlank) {
  497. // if (value.equals("color")) {
  498. // JSONObject jsonObject =new JSONObject();
  499. // jsonObject.put("parm", row.getString("color"));
  500. // jsonObject.put("flag", true);
  501. // colormap.add(jsonObject);
  502. // } else if (value.equals("spec")) {
  503. // JSONObject jsonObject =new JSONObject();
  504. // jsonObject.put("parm", row.getString("spec"));
  505. // jsonObject.put("flag", true);
  506. // specmap.add(jsonObject);
  507. // } else if (value.equals("material")) {
  508. // JSONObject jsonObject =new JSONObject();
  509. // jsonObject.put("parm", row.getString("material"));
  510. // jsonObject.put("flag", true);
  511. // materialmap.add(jsonObject);
  512. // } else if (value.equals("cheek")) {
  513. // JSONObject jsonObject =new JSONObject();
  514. // jsonObject.put("parm", row.getString("cheek"));
  515. // jsonObject.put("flag", true);
  516. // cheekmap.add(jsonObject);
  517. // }
  518. //
  519. // }
  520. // }
  521. String colorwhere = "";
  522. String specwhere = "";
  523. String materialwhere = "";
  524. String cheekwhere = "";
  525. for (String value : listParmNotBlank) {
  526. if (value.equals("color")) {
  527. colorwhere = " and " + value + "='" + content.getString(value) + "' ";
  528. } else if (value.equals("spec")) {
  529. specwhere = " and " + value + "='" + content.getString(value) + "' ";
  530. } else if (value.equals("material")) {
  531. materialwhere = " and " + value + "='" + content.getString(value) + "' ";
  532. } else if (value.equals("cheek")) {
  533. cheekwhere = " and " + value + "='" + content.getString(value) + "' ";
  534. }
  535. }
  536. for (String value : listAll) {
  537. if (value.equals("color")) {
  538. factory.addParameter_SQL("where", " 1=1 " + specwhere + materialwhere + cheekwhere);
  539. //System.out.println(" 1=1 " + specwhere + materialwhere + cheekwhere);
  540. rows = dbConnect.runSqlQuery(factory.getSQL());
  541. if (!rows.isEmpty()) {
  542. for (Row row : rows) {
  543. JSONObject jsonObject = new JSONObject();
  544. jsonObject.put("parm", row.getString("color"));
  545. jsonObject.put("flag", true);
  546. colormap.add(jsonObject);
  547. }
  548. }
  549. } else if (value.equals("spec")) {
  550. factory.addParameter_SQL("where", " 1=1 " + colorwhere + materialwhere + cheekwhere);
  551. rows = dbConnect.runSqlQuery(factory.getSQL());
  552. if (!rows.isEmpty()) {
  553. for (Row row : rows) {
  554. JSONObject jsonObject = new JSONObject();
  555. jsonObject.put("parm", row.getString("spec"));
  556. jsonObject.put("flag", true);
  557. specmap.add(jsonObject);
  558. }
  559. }
  560. } else if (value.equals("material")) {
  561. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + cheekwhere);
  562. rows = dbConnect.runSqlQuery(factory.getSQL());
  563. if (!rows.isEmpty()) {
  564. for (Row row : rows) {
  565. JSONObject jsonObject = new JSONObject();
  566. jsonObject.put("parm", row.getString("material"));
  567. jsonObject.put("flag", true);
  568. materialmap.add(jsonObject);
  569. }
  570. }
  571. } else if (value.equals("cheek")) {
  572. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere);
  573. rows = dbConnect.runSqlQuery(factory.getSQL());
  574. if (!rows.isEmpty()) {
  575. for (Row row : rows) {
  576. JSONObject jsonObject = new JSONObject();
  577. jsonObject.put("parm", row.getString("cheek"));
  578. jsonObject.put("flag", true);
  579. cheekmap.add(jsonObject);
  580. }
  581. }
  582. }
  583. }
  584. for (String firstcolor : firstcolorList) {
  585. boolean isexistParm = false;
  586. for (Object object : colormap) {
  587. JSONObject jsonObject = (JSONObject) object;
  588. if (jsonObject.getString("parm").equals(firstcolor)) {
  589. isexistParm = true;
  590. break;
  591. }
  592. }
  593. if (!isexistParm) {
  594. JSONObject jsonObject = new JSONObject();
  595. jsonObject.put("parm", firstcolor);
  596. jsonObject.put("flag", false);
  597. colormap.add(jsonObject);
  598. }
  599. }
  600. for (String firstspec : firstspecList) {
  601. boolean isexistParm = false;
  602. for (Object object : specmap) {
  603. JSONObject jsonObject = (JSONObject) object;
  604. if (jsonObject.getString("parm").equals(firstspec)) {
  605. isexistParm = true;
  606. break;
  607. }
  608. }
  609. if (!isexistParm) {
  610. JSONObject jsonObject = new JSONObject();
  611. jsonObject.put("parm", firstspec);
  612. jsonObject.put("flag", false);
  613. specmap.add(jsonObject);
  614. }
  615. }
  616. for (String firstmaterial : firstmaterialList) {
  617. boolean isexistParm = false;
  618. for (Object object : materialmap) {
  619. JSONObject jsonObject = (JSONObject) object;
  620. if (jsonObject.getString("parm").equals(firstmaterial)) {
  621. isexistParm = true;
  622. break;
  623. }
  624. }
  625. if (!isexistParm) {
  626. JSONObject jsonObject = new JSONObject();
  627. jsonObject.put("parm", firstmaterial);
  628. jsonObject.put("flag", false);
  629. materialmap.add(jsonObject);
  630. }
  631. }
  632. for (String firstcheek : firstcheekList) {
  633. boolean isexistParm = false;
  634. for (Object object : cheekmap) {
  635. JSONObject jsonObject = (JSONObject) object;
  636. if (jsonObject.getString("parm").equals(firstcheek)) {
  637. isexistParm = true;
  638. break;
  639. }
  640. }
  641. if (!isexistParm) {
  642. JSONObject jsonObject = new JSONObject();
  643. jsonObject.put("parm", firstcheek);
  644. jsonObject.put("flag", false);
  645. cheekmap.add(jsonObject);
  646. }
  647. }
  648. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere + cheekwhere);
  649. } else {
  650. String where = " 1=1 ";
  651. for (String value : listParmNotBlank) {
  652. if (value.equals("color")) {
  653. JSONObject jsonObject = new JSONObject();
  654. jsonObject.put("parm", content.getString("color"));
  655. jsonObject.put("flag", true);
  656. colormap.add(jsonObject);
  657. // for (String firstcolor : firstcolorList) {
  658. // JSONObject jsonObject1 =new JSONObject();
  659. // if (!firstcolor.equals(content.getString("color"))) {
  660. // jsonObject1.put("parm",firstcolor);
  661. // jsonObject1.put("flag", true);
  662. // colormap.add(jsonObject1);
  663. // }
  664. // }
  665. } else if (value.equals("spec")) {
  666. JSONObject jsonObject = new JSONObject();
  667. jsonObject.put("parm", content.getString("spec"));
  668. jsonObject.put("flag", true);
  669. specmap.add(jsonObject);
  670. // for (String firstspec : firstspecList) {
  671. // JSONObject jsonObject1 =new JSONObject();
  672. // if (!firstspec.equals(content.getString("spec"))) {
  673. // jsonObject1.put("parm",firstspec);
  674. // jsonObject1.put("flag", true);
  675. // specmap.add(jsonObject1);
  676. // }
  677. // }
  678. } else if (value.equals("material")) {
  679. JSONObject jsonObject = new JSONObject();
  680. jsonObject.put("parm", content.getString("material"));
  681. jsonObject.put("flag", true);
  682. materialmap.add(jsonObject);
  683. // for (String firstmaterial : firstmaterialList) {
  684. // JSONObject jsonObject1 =new JSONObject();
  685. // if (!firstmaterial.equals(content.getString("material"))) {
  686. // jsonObject1.put("parm",firstmaterial);
  687. // jsonObject1.put("flag", true);
  688. // materialmap.add(jsonObject1);
  689. // }
  690. // }
  691. } else if (value.equals("cheek")) {
  692. JSONObject jsonObject = new JSONObject();
  693. jsonObject.put("parm", content.getString("cheek"));
  694. jsonObject.put("flag", true);
  695. cheekmap.add(jsonObject);
  696. // for (String firstcheek : firstcheekList) {
  697. // JSONObject jsonObject1 =new JSONObject();
  698. // if (!firstcheek.equals(content.getString("cheek"))) {
  699. // jsonObject1.put("parm", firstcheek);
  700. // jsonObject1.put("flag", true);
  701. // cheekmap.add(jsonObject1);
  702. // }
  703. // }
  704. }
  705. where = where + " and " + value + "='" + content.getString(value) + "' ";
  706. }
  707. factory.addParameter_SQL("where", where);
  708. for (String value : listAll) {
  709. if (value.equals("color")) {
  710. rows = dbConnect.runSqlQuery(factory.getSQL());
  711. if (!rows.isEmpty()) {
  712. for (Row row : rows) {
  713. JSONObject jsonObject = new JSONObject();
  714. jsonObject.put("parm", row.getString("color"));
  715. jsonObject.put("flag", true);
  716. colormap.add(jsonObject);
  717. }
  718. }
  719. } else if (value.equals("spec")) {
  720. rows = dbConnect.runSqlQuery(factory.getSQL());
  721. if (!rows.isEmpty()) {
  722. for (Row row : rows) {
  723. JSONObject jsonObject = new JSONObject();
  724. jsonObject.put("parm", row.getString("spec"));
  725. jsonObject.put("flag", true);
  726. specmap.add(jsonObject);
  727. }
  728. }
  729. } else if (value.equals("material")) {
  730. rows = dbConnect.runSqlQuery(factory.getSQL());
  731. if (!rows.isEmpty()) {
  732. for (Row row : rows) {
  733. JSONObject jsonObject = new JSONObject();
  734. jsonObject.put("parm", row.getString("material"));
  735. jsonObject.put("flag", true);
  736. materialmap.add(jsonObject);
  737. }
  738. }
  739. } else if (value.equals("cheek")) {
  740. rows = dbConnect.runSqlQuery(factory.getSQL());
  741. if (!rows.isEmpty()) {
  742. for (Row row : rows) {
  743. JSONObject jsonObject = new JSONObject();
  744. jsonObject.put("parm", row.getString("cheek"));
  745. jsonObject.put("flag", true);
  746. cheekmap.add(jsonObject);
  747. }
  748. }
  749. }
  750. }
  751. for (String firstcolor : firstcolorList) {
  752. boolean isexistParm = false;
  753. for (Object object : colormap) {
  754. JSONObject jsonObject = (JSONObject) object;
  755. if (jsonObject.getString("parm").equals(firstcolor)) {
  756. isexistParm = true;
  757. break;
  758. }
  759. }
  760. if (!isexistParm) {
  761. JSONObject jsonObject = new JSONObject();
  762. jsonObject.put("parm", firstcolor);
  763. jsonObject.put("flag", false);
  764. colormap.add(jsonObject);
  765. }
  766. }
  767. for (String firstspec : firstspecList) {
  768. boolean isexistParm = false;
  769. for (Object object : specmap) {
  770. JSONObject jsonObject = (JSONObject) object;
  771. if (jsonObject.getString("parm").equals(firstspec)) {
  772. isexistParm = true;
  773. break;
  774. }
  775. }
  776. if (!isexistParm) {
  777. JSONObject jsonObject = new JSONObject();
  778. jsonObject.put("parm", firstspec);
  779. jsonObject.put("flag", false);
  780. specmap.add(jsonObject);
  781. }
  782. }
  783. for (String firstmaterial : firstmaterialList) {
  784. boolean isexistParm = false;
  785. for (Object object : materialmap) {
  786. JSONObject jsonObject = (JSONObject) object;
  787. if (jsonObject.getString("parm").equals(firstmaterial)) {
  788. isexistParm = true;
  789. break;
  790. }
  791. }
  792. if (!isexistParm) {
  793. JSONObject jsonObject = new JSONObject();
  794. jsonObject.put("parm", firstmaterial);
  795. jsonObject.put("flag", false);
  796. materialmap.add(jsonObject);
  797. }
  798. }
  799. for (String firstcheek : firstcheekList) {
  800. boolean isexistParm = false;
  801. for (Object object : cheekmap) {
  802. JSONObject jsonObject = (JSONObject) object;
  803. if (jsonObject.getString("parm").equals(firstcheek)) {
  804. isexistParm = true;
  805. break;
  806. }
  807. }
  808. if (!isexistParm) {
  809. JSONObject jsonObject = new JSONObject();
  810. jsonObject.put("parm", firstcheek);
  811. jsonObject.put("flag", false);
  812. cheekmap.add(jsonObject);
  813. }
  814. }
  815. }
  816. colormap = jsonArraySortByField(colormap.toJSONString(), "parm", "0");
  817. specmap = jsonArraySortByField(specmap.toJSONString(), "parm", "0");
  818. materialmap = jsonArraySortByField(materialmap.toJSONString(), "parm", "0");
  819. cheekmap = jsonArraySortByField(cheekmap.toJSONString(), "parm", "0");
  820. for (Object object : colormap) {
  821. boolean flag = false;
  822. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  823. for (parm parm1 : colorList) {
  824. if (parm1.getParm().equals(parm.getParm())) {
  825. flag = true;
  826. break;
  827. }
  828. }
  829. if (!flag) {
  830. colorList.add(parm);
  831. }
  832. }
  833. for (Object object : specmap) {
  834. boolean flag = false;
  835. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  836. for (parm parm1 : specList) {
  837. if (parm1.getParm().equals(parm.getParm())) {
  838. flag = true;
  839. break;
  840. }
  841. }
  842. if (!flag) {
  843. specList.add(parm);
  844. }
  845. }
  846. for (Object object : materialmap) {
  847. boolean flag = false;
  848. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  849. for (parm parm1 : materialList) {
  850. if (parm1.getParm().equals(parm.getParm())) {
  851. flag = true;
  852. break;
  853. }
  854. }
  855. if (!flag) {
  856. materialList.add(parm);
  857. }
  858. }
  859. for (Object object : cheekmap) {
  860. boolean flag = false;
  861. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  862. for (parm parm1 : cheekList) {
  863. if (parm1.getParm().equals(parm.getParm())) {
  864. flag = true;
  865. break;
  866. }
  867. }
  868. if (!flag) {
  869. cheekList.add(parm);
  870. }
  871. }
  872. // colorList.addAll(JSONObject.parseArray(colormap.toJSONString(), parm.class));
  873. // specList.addAll(JSONObject.parseArray(specmap.toJSONString(), parm.class));
  874. // materialList.addAll(JSONObject.parseArray(materialmap.toJSONString(), parm.class));
  875. // cheekList.addAll(JSONObject.parseArray(cheekmap.toJSONString(), parm.class));
  876. rows = dbConnect.runSqlQuery(factory.getSQL());
  877. String itemno = "";
  878. if (!rows.isEmpty()) {
  879. itemno = rows.get(0).getString("itemno");
  880. }
  881. /**
  882. * 查询商品明细
  883. */
  884. SQLFactory priceSqlFactory = new SQLFactory(this, "查询商品原价");
  885. priceSqlFactory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
  886. priceSqlFactory.addParameter("siteid", siteid);
  887. Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
  888. if(!siteParameterRows.isEmpty()){
  889. if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
  890. priceSqlFactory.addParameter("pricegrade", "1");
  891. }else{
  892. priceSqlFactory.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
  893. }
  894. }else{
  895. priceSqlFactory.addParameter("pricegrade", "1");
  896. }
  897. Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
  898. RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
  899. SQLFactory sqlFactory = new SQLFactory(this, "查询商品详情", pageSize, pageNumber, pageSorting);
  900. sqlFactory.addParameter_SQL("where", "t2.itemno='" + itemno + "' ");
  901. sqlFactory.addParameter("itemno", itemno);
  902. sqlFactory.addParameter("siteid", siteid);
  903. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  904. Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  905. for (Row row : itemrows) {
  906. row.put("customschemeItems",customschemeItems);
  907. ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
  908. row.put("oldprice", itemPrice.getPrice());
  909. if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
  910. row.put("gradeprice", itemPrice.getContractprice());
  911. } else {
  912. if(pricerowsMap.containsKey(row.getString("itemid"))){
  913. if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
  914. row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
  915. }else{
  916. row.put("gradeprice",0);
  917. }
  918. }else {
  919. row.put("gradeprice", 0);
  920. }
  921. }
  922. //判断商品是否参与活动:当前经销商参与的有效的活动
  923. if(listAll.size()==listParmNotBlank.size()){
  924. SQLFactory activitysqlFactory = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询");
  925. activitysqlFactory.addParameter("siteid", siteid);
  926. activitysqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  927. activitysqlFactory.addParameter_SQL("where", "1=1");
  928. Rows activityrows = dbConnect.runSqlQuery(activitysqlFactory);
  929. SQLFactory sqlFactory1 = new SQLFactory(new promotion(new JSONObject()), "促销订单金额合计查询");
  930. sqlFactory1.addParameter("siteid", siteid);
  931. sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
  932. Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
  933. RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
  934. SQLFactory sqlFactory2 = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询(触发的促销方案)");
  935. sqlFactory2.addParameter("siteid", siteid);
  936. sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
  937. Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
  938. RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
  939. ListIterator<Row> iterator = activityrows.listIterator();
  940. while (iterator.hasNext()) {
  941. Row activityrow = iterator.next();
  942. if(activityrow.getLong("sa_openpromotionid")!=0){
  943. if(sumAmountRowsMap.containsKey(activityrow.getString("sa_promotionid"))){
  944. BigDecimal sumamount = sumAmountRowsMap.get(activityrow.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
  945. if(sumamount.compareTo(activityrow.getBigDecimal("openamount"))>=0){
  946. if(openPromotionsRowsMap.containsKey(activityrow.getString("sa_openpromotionid"))){
  947. iterator.add(openPromotionsRowsMap.get(activityrow.getString("sa_openpromotionid")).get(0));
  948. }
  949. }
  950. }
  951. }
  952. }
  953. SQLFactory promotionsqlFactory = new SQLFactory(this, "查询商品所在有效活动", pageSize, pageNumber, pageSorting);
  954. promotionsqlFactory.addParameter("itemno", itemno);
  955. promotionsqlFactory.addParameter_in("sa_promotionids", activityrows.toArray("sa_promotionid"));
  956. promotionsqlFactory.addParameter("siteid", siteid);
  957. Rows promotionrows = dbConnect.runSqlQuery(promotionsqlFactory.getSQL());
  958. row.put("canuseactivity",promotionrows);
  959. }else{
  960. row.put("canuseactivity",new Rows());
  961. }
  962. }
  963. ArrayList<Long> ids = itemrows.toArrayList("itemid", new ArrayList<>());
  964. //默认商品图片
  965. Rows defaultImageRows = Item.getItemdefaultImage(this);
  966. // 封面cover
  967. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  968. // 附件
  969. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  970. Rows rowsitemclass = dbConnect.runSqlQuery(
  971. " 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='"
  972. + siteid + "'");
  973. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  974. // 货品档案领域
  975. Rows rowstradefield = dbConnect.runSqlQuery(
  976. " select t6.itemid,t6.tradefield from plm_item_tradefield t6 where t6.siteid='" + siteid + "'");
  977. RowsMap tradefieldRowsMap = rowstradefield.toRowsMap("itemid");
  978. // 品牌
  979. Rows rowsbrand = dbConnect.runSqlQuery(
  980. " select distinct t8.sa_brandid,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='"
  981. + siteid + "'");
  982. RowsMap brandRowsMap = rowsbrand.toRowsMap("itemid");
  983. for (Row row : itemrows) {
  984. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  985. if (coverRows.isEmpty()) {
  986. row.put("cover", "");
  987. } else {
  988. row.put("cover", coverRows.get(0).getString("url"));
  989. }
  990. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  991. row.put("attinfos", defaultImageRows);
  992. } else {
  993. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  994. }
  995. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  996. row.put("tradefield", tradefieldRowsMap.get(row.getString("itemid")));
  997. row.put("brand", brandRowsMap.get(row.getString("itemid")));
  998. }
  999. JSONObject oject = new JSONObject();
  1000. oject.put("customschemeItems", customschemeItems);
  1001. oject.put("colorRows", colorList);
  1002. oject.put("specRows", specList);
  1003. oject.put("materialRows", materialList);
  1004. oject.put("cheekRows", cheekList);
  1005. oject.put("rows", rows);
  1006. oject.put("item", itemrows);
  1007. return getSucReturnObject().setData(oject).toString();
  1008. }
  1009. /**
  1010. * 按照JSONArray中的对象的某个字段进行排序(采用fastJson)
  1011. *
  1012. * @param jsonArrayStr json数组字符串
  1013. * @param sortkeyname 根据哪个字段进行排序
  1014. * @param order 倒序:0;非0顺序
  1015. * @return 排序后的jsonarray
  1016. */
  1017. public JSONArray jsonArraySortByField(String jsonArrayStr, String sortkeyname, String order) throws YosException {
  1018. JSONArray sortedJsonArray = new JSONArray();
  1019. try {
  1020. JSONArray jsonArray = JSON.parseArray(jsonArrayStr);
  1021. List<JSONObject> jsonList = new ArrayList<JSONObject>();
  1022. for (int i = 0; i < jsonArray.size(); i++) {
  1023. jsonList.add(jsonArray.getJSONObject(i));
  1024. }
  1025. Collections.sort(jsonList, new Comparator<JSONObject>() {
  1026. @Override
  1027. public int compare(JSONObject a, JSONObject b) {
  1028. String strA = new String();
  1029. String strB = new String();
  1030. String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\-_\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
  1031. String aStr = a.getStringValue(sortkeyname);
  1032. strA = aStr.replaceAll(regEx, "");
  1033. String bStr = b.getStringValue(sortkeyname);
  1034. strB = bStr.replaceAll(regEx, "");
  1035. if ("0".equals(order)) {
  1036. return -strA.compareTo(strB);
  1037. } else {
  1038. return strA.compareTo(strB);
  1039. }
  1040. }
  1041. });
  1042. for (int i = 0; i < jsonArray.size(); i++) {
  1043. sortedJsonArray.add(jsonList.get(i));
  1044. }
  1045. } catch (Exception e) {
  1046. e.printStackTrace();
  1047. }
  1048. return sortedJsonArray;
  1049. }
  1050. }