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