itemgroup.java 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  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. Rows customschemeItems1 = dbConnect.runSqlQuery("select * from (select distinct value,description,isonlydisplay,sequence from sa_customscheme_items where isonlydisplay=1 and 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");
  435. RowsMap customschemeItems1RowsMap = customschemeItems1.toRowsMap("value");
  436. if (!customschemeItems.isEmpty()) {
  437. for (Row row : customschemeItems) {
  438. if (StringUtils.isNotBlank(row.getString("value"))) {
  439. if (StringUtils.isNotBlank(content.getString(row.getString("value")))) {
  440. listParmNotBlank.add(row.getString("value"));
  441. } else {
  442. listParmBlank.add(row.getString("value"));
  443. }
  444. }
  445. }
  446. }
  447. Set<String> listAll = new LinkedHashSet<String>();
  448. listAll.addAll(listParmBlank);
  449. listAll.addAll(listParmNotBlank);
  450. factory.addParameter_SQL("where", "1=1");
  451. rows = dbConnect.runSqlQuery(factory.getSQL());
  452. for (Row row : rows) {
  453. for (String value : listAll) {
  454. if (value.equals("color")) {
  455. firstcolorList.add(row.getString("color"));
  456. } else if (value.equals("spec")) {
  457. firstspecList.add(row.getString("spec"));
  458. } else if (value.equals("material")) {
  459. firstmaterialList.add(row.getString("material"));
  460. } else if (value.equals("cheek")) {
  461. firstcheekList.add(row.getString("cheek"));
  462. }
  463. }
  464. }
  465. JSONArray colormap = new JSONArray();
  466. JSONArray specmap = new JSONArray();
  467. JSONArray materialmap = new JSONArray();
  468. JSONArray cheekmap = new JSONArray();
  469. if (listParmNotBlank == null || listParmNotBlank.size() == 0) {
  470. factory.addParameter_SQL("where", "1=1");
  471. for (Row row : rows) {
  472. for (String value : listParmBlank) {
  473. if (value.equals("color")) {
  474. JSONObject jsonObject = new JSONObject();
  475. jsonObject.put("parm", row.getString("color"));
  476. jsonObject.put("flag", true);
  477. colormap.add(jsonObject);
  478. } else if (value.equals("spec")) {
  479. JSONObject jsonObject = new JSONObject();
  480. jsonObject.put("parm", row.getString("spec"));
  481. jsonObject.put("flag", true);
  482. specmap.add(jsonObject);
  483. } else if (value.equals("material")) {
  484. JSONObject jsonObject = new JSONObject();
  485. jsonObject.put("parm", row.getString("material"));
  486. jsonObject.put("flag", true);
  487. materialmap.add(jsonObject);
  488. } else if (value.equals("cheek")) {
  489. JSONObject jsonObject = new JSONObject();
  490. jsonObject.put("parm", row.getString("cheek"));
  491. jsonObject.put("flag", true);
  492. cheekmap.add(jsonObject);
  493. }
  494. }
  495. }
  496. } else if (listParmBlank == null || listParmBlank.size() == 0) {
  497. // for (Row row : rows) {
  498. // for (String value : listParmNotBlank) {
  499. // if (value.equals("color")) {
  500. // JSONObject jsonObject =new JSONObject();
  501. // jsonObject.put("parm", row.getString("color"));
  502. // jsonObject.put("flag", true);
  503. // colormap.add(jsonObject);
  504. // } else if (value.equals("spec")) {
  505. // JSONObject jsonObject =new JSONObject();
  506. // jsonObject.put("parm", row.getString("spec"));
  507. // jsonObject.put("flag", true);
  508. // specmap.add(jsonObject);
  509. // } else if (value.equals("material")) {
  510. // JSONObject jsonObject =new JSONObject();
  511. // jsonObject.put("parm", row.getString("material"));
  512. // jsonObject.put("flag", true);
  513. // materialmap.add(jsonObject);
  514. // } else if (value.equals("cheek")) {
  515. // JSONObject jsonObject =new JSONObject();
  516. // jsonObject.put("parm", row.getString("cheek"));
  517. // jsonObject.put("flag", true);
  518. // cheekmap.add(jsonObject);
  519. // }
  520. //
  521. // }
  522. // }
  523. String colorwhere = "";
  524. String specwhere = "";
  525. String materialwhere = "";
  526. String cheekwhere = "";
  527. for (String value : listParmNotBlank) {
  528. if (value.equals("color")) {
  529. colorwhere = " and " + value + "='" + content.getString(value) + "' ";
  530. } else if (value.equals("spec")) {
  531. specwhere = " and " + value + "='" + content.getString(value) + "' ";
  532. } else if (value.equals("material")) {
  533. materialwhere = " and " + value + "='" + content.getString(value) + "' ";
  534. } else if (value.equals("cheek")) {
  535. cheekwhere = " and " + value + "='" + content.getString(value) + "' ";
  536. }
  537. }
  538. for (String value : listAll) {
  539. if (value.equals("color")) {
  540. factory.addParameter_SQL("where", " 1=1 " + specwhere + materialwhere + cheekwhere);
  541. //System.out.println(" 1=1 " + specwhere + materialwhere + cheekwhere);
  542. rows = dbConnect.runSqlQuery(factory.getSQL());
  543. if (!rows.isEmpty()) {
  544. for (Row row : rows) {
  545. JSONObject jsonObject = new JSONObject();
  546. jsonObject.put("parm", row.getString("color"));
  547. jsonObject.put("flag", true);
  548. colormap.add(jsonObject);
  549. }
  550. }
  551. } else if (value.equals("spec")) {
  552. factory.addParameter_SQL("where", " 1=1 " + colorwhere + materialwhere + cheekwhere);
  553. rows = dbConnect.runSqlQuery(factory.getSQL());
  554. if (!rows.isEmpty()) {
  555. for (Row row : rows) {
  556. JSONObject jsonObject = new JSONObject();
  557. jsonObject.put("parm", row.getString("spec"));
  558. jsonObject.put("flag", true);
  559. specmap.add(jsonObject);
  560. }
  561. }
  562. } else if (value.equals("material")) {
  563. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + cheekwhere);
  564. rows = dbConnect.runSqlQuery(factory.getSQL());
  565. if (!rows.isEmpty()) {
  566. for (Row row : rows) {
  567. JSONObject jsonObject = new JSONObject();
  568. jsonObject.put("parm", row.getString("material"));
  569. jsonObject.put("flag", true);
  570. materialmap.add(jsonObject);
  571. }
  572. }
  573. } else if (value.equals("cheek")) {
  574. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere);
  575. rows = dbConnect.runSqlQuery(factory.getSQL());
  576. if (!rows.isEmpty()) {
  577. for (Row row : rows) {
  578. JSONObject jsonObject = new JSONObject();
  579. jsonObject.put("parm", row.getString("cheek"));
  580. jsonObject.put("flag", true);
  581. cheekmap.add(jsonObject);
  582. }
  583. }
  584. }
  585. }
  586. for (String firstcolor : firstcolorList) {
  587. boolean isexistParm = false;
  588. for (Object object : colormap) {
  589. JSONObject jsonObject = (JSONObject) object;
  590. if (jsonObject.getString("parm").equals(firstcolor)) {
  591. isexistParm = true;
  592. break;
  593. }
  594. }
  595. if (!isexistParm) {
  596. JSONObject jsonObject = new JSONObject();
  597. jsonObject.put("parm", firstcolor);
  598. jsonObject.put("flag", false);
  599. colormap.add(jsonObject);
  600. }
  601. }
  602. for (String firstspec : firstspecList) {
  603. boolean isexistParm = false;
  604. for (Object object : specmap) {
  605. JSONObject jsonObject = (JSONObject) object;
  606. if (jsonObject.getString("parm").equals(firstspec)) {
  607. isexistParm = true;
  608. break;
  609. }
  610. }
  611. if (!isexistParm) {
  612. JSONObject jsonObject = new JSONObject();
  613. jsonObject.put("parm", firstspec);
  614. jsonObject.put("flag", false);
  615. specmap.add(jsonObject);
  616. }
  617. }
  618. for (String firstmaterial : firstmaterialList) {
  619. boolean isexistParm = false;
  620. for (Object object : materialmap) {
  621. JSONObject jsonObject = (JSONObject) object;
  622. if (jsonObject.getString("parm").equals(firstmaterial)) {
  623. isexistParm = true;
  624. break;
  625. }
  626. }
  627. if (!isexistParm) {
  628. JSONObject jsonObject = new JSONObject();
  629. jsonObject.put("parm", firstmaterial);
  630. jsonObject.put("flag", false);
  631. materialmap.add(jsonObject);
  632. }
  633. }
  634. for (String firstcheek : firstcheekList) {
  635. boolean isexistParm = false;
  636. for (Object object : cheekmap) {
  637. JSONObject jsonObject = (JSONObject) object;
  638. if (jsonObject.getString("parm").equals(firstcheek)) {
  639. isexistParm = true;
  640. break;
  641. }
  642. }
  643. if (!isexistParm) {
  644. JSONObject jsonObject = new JSONObject();
  645. jsonObject.put("parm", firstcheek);
  646. jsonObject.put("flag", false);
  647. cheekmap.add(jsonObject);
  648. }
  649. }
  650. factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere + cheekwhere);
  651. } else if(listParmNotBlank.size()==1){
  652. String where = " 1=1 ";
  653. for (String value : listParmNotBlank) {
  654. if (value.equals("color")) {
  655. JSONObject jsonObject = new JSONObject();
  656. jsonObject.put("parm", content.getString("color"));
  657. jsonObject.put("flag", true);
  658. colormap.add(jsonObject);
  659. // for (String firstcolor : firstcolorList) {
  660. // JSONObject jsonObject1 =new JSONObject();
  661. // if (!firstcolor.equals(content.getString("color"))) {
  662. // jsonObject1.put("parm",firstcolor);
  663. // jsonObject1.put("flag", true);
  664. // colormap.add(jsonObject1);
  665. // }
  666. // }
  667. } else if (value.equals("spec")) {
  668. JSONObject jsonObject = new JSONObject();
  669. jsonObject.put("parm", content.getString("spec"));
  670. jsonObject.put("flag", true);
  671. specmap.add(jsonObject);
  672. // for (String firstspec : firstspecList) {
  673. // JSONObject jsonObject1 =new JSONObject();
  674. // if (!firstspec.equals(content.getString("spec"))) {
  675. // jsonObject1.put("parm",firstspec);
  676. // jsonObject1.put("flag", true);
  677. // specmap.add(jsonObject1);
  678. // }
  679. // }
  680. } else if (value.equals("material")) {
  681. JSONObject jsonObject = new JSONObject();
  682. jsonObject.put("parm", content.getString("material"));
  683. jsonObject.put("flag", true);
  684. materialmap.add(jsonObject);
  685. // for (String firstmaterial : firstmaterialList) {
  686. // JSONObject jsonObject1 =new JSONObject();
  687. // if (!firstmaterial.equals(content.getString("material"))) {
  688. // jsonObject1.put("parm",firstmaterial);
  689. // jsonObject1.put("flag", true);
  690. // materialmap.add(jsonObject1);
  691. // }
  692. // }
  693. } else if (value.equals("cheek")) {
  694. JSONObject jsonObject = new JSONObject();
  695. jsonObject.put("parm", content.getString("cheek"));
  696. jsonObject.put("flag", true);
  697. cheekmap.add(jsonObject);
  698. // for (String firstcheek : firstcheekList) {
  699. // JSONObject jsonObject1 =new JSONObject();
  700. // if (!firstcheek.equals(content.getString("cheek"))) {
  701. // jsonObject1.put("parm", firstcheek);
  702. // jsonObject1.put("flag", true);
  703. // cheekmap.add(jsonObject1);
  704. // }
  705. // }
  706. }
  707. where = where + " and " + value + "='" + content.getString(value) + "' ";
  708. }
  709. factory.addParameter_SQL("where", where);
  710. for (String value : listAll) {
  711. if (value.equals("color")) {
  712. rows = dbConnect.runSqlQuery(factory.getSQL());
  713. if (!rows.isEmpty()) {
  714. for (Row row : rows) {
  715. JSONObject jsonObject = new JSONObject();
  716. jsonObject.put("parm", row.getString("color"));
  717. jsonObject.put("flag", true);
  718. colormap.add(jsonObject);
  719. }
  720. }
  721. } else if (value.equals("spec")) {
  722. rows = dbConnect.runSqlQuery(factory.getSQL());
  723. if (!rows.isEmpty()) {
  724. for (Row row : rows) {
  725. JSONObject jsonObject = new JSONObject();
  726. jsonObject.put("parm", row.getString("spec"));
  727. jsonObject.put("flag", true);
  728. specmap.add(jsonObject);
  729. }
  730. }
  731. } else if (value.equals("material")) {
  732. rows = dbConnect.runSqlQuery(factory.getSQL());
  733. if (!rows.isEmpty()) {
  734. for (Row row : rows) {
  735. JSONObject jsonObject = new JSONObject();
  736. jsonObject.put("parm", row.getString("material"));
  737. jsonObject.put("flag", true);
  738. materialmap.add(jsonObject);
  739. }
  740. }
  741. } else if (value.equals("cheek")) {
  742. rows = dbConnect.runSqlQuery(factory.getSQL());
  743. if (!rows.isEmpty()) {
  744. for (Row row : rows) {
  745. JSONObject jsonObject = new JSONObject();
  746. jsonObject.put("parm", row.getString("cheek"));
  747. jsonObject.put("flag", true);
  748. cheekmap.add(jsonObject);
  749. }
  750. }
  751. }
  752. }
  753. List<String> list = new ArrayList<>(listParmNotBlank);
  754. for (String firstcolor : firstcolorList) {
  755. boolean isexistParm = false;
  756. for (Object object : colormap) {
  757. JSONObject jsonObject = (JSONObject) object;
  758. if (jsonObject.getString("parm").equals(firstcolor)) {
  759. isexistParm = true;
  760. break;
  761. }
  762. }
  763. if (!isexistParm) {
  764. if(list.get(0).equals("color")){
  765. JSONObject jsonObject = new JSONObject();
  766. jsonObject.put("parm", firstcolor);
  767. jsonObject.put("flag", true);
  768. colormap.add(jsonObject);
  769. }else{
  770. JSONObject jsonObject = new JSONObject();
  771. jsonObject.put("parm", firstcolor);
  772. jsonObject.put("flag", false);
  773. colormap.add(jsonObject);
  774. }
  775. }
  776. }
  777. for (String firstspec : firstspecList) {
  778. boolean isexistParm = false;
  779. for (Object object : specmap) {
  780. JSONObject jsonObject = (JSONObject) object;
  781. if (jsonObject.getString("parm").equals(firstspec)) {
  782. isexistParm = true;
  783. break;
  784. }
  785. }
  786. if (!isexistParm) {
  787. if(list.get(0).equals("spec")){
  788. JSONObject jsonObject = new JSONObject();
  789. jsonObject.put("parm", firstspec);
  790. jsonObject.put("flag", true);
  791. specmap.add(jsonObject);
  792. }else{
  793. JSONObject jsonObject = new JSONObject();
  794. jsonObject.put("parm", firstspec);
  795. jsonObject.put("flag", false);
  796. specmap.add(jsonObject);
  797. }
  798. }
  799. }
  800. for (String firstmaterial : firstmaterialList) {
  801. boolean isexistParm = false;
  802. for (Object object : materialmap) {
  803. JSONObject jsonObject = (JSONObject) object;
  804. if (jsonObject.getString("parm").equals(firstmaterial)) {
  805. isexistParm = true;
  806. break;
  807. }
  808. }
  809. if (!isexistParm) {
  810. if(list.get(0).equals("material")){
  811. JSONObject jsonObject = new JSONObject();
  812. jsonObject.put("parm", firstmaterial);
  813. jsonObject.put("flag", true);
  814. materialmap.add(jsonObject);
  815. }else{
  816. JSONObject jsonObject = new JSONObject();
  817. jsonObject.put("parm", firstmaterial);
  818. jsonObject.put("flag", false);
  819. materialmap.add(jsonObject);
  820. }
  821. }
  822. }
  823. for (String firstcheek : firstcheekList) {
  824. boolean isexistParm = false;
  825. for (Object object : cheekmap) {
  826. JSONObject jsonObject = (JSONObject) object;
  827. if (jsonObject.getString("parm").equals(firstcheek)) {
  828. isexistParm = true;
  829. break;
  830. }
  831. }
  832. if (!isexistParm) {
  833. if(list.get(0).equals("cheek")){
  834. JSONObject jsonObject = new JSONObject();
  835. jsonObject.put("parm", firstcheek);
  836. jsonObject.put("flag", true);
  837. cheekmap.add(jsonObject);
  838. }else{
  839. JSONObject jsonObject = new JSONObject();
  840. jsonObject.put("parm", firstcheek);
  841. jsonObject.put("flag", false);
  842. cheekmap.add(jsonObject);
  843. }
  844. }
  845. }
  846. }else {
  847. String where = " 1=1 ";
  848. for (String value : listParmNotBlank) {
  849. if (value.equals("color")) {
  850. JSONObject jsonObject = new JSONObject();
  851. jsonObject.put("parm", content.getString("color"));
  852. jsonObject.put("flag", true);
  853. colormap.add(jsonObject);
  854. // for (String firstcolor : firstcolorList) {
  855. // JSONObject jsonObject1 =new JSONObject();
  856. // if (!firstcolor.equals(content.getString("color"))) {
  857. // jsonObject1.put("parm",firstcolor);
  858. // jsonObject1.put("flag", true);
  859. // colormap.add(jsonObject1);
  860. // }
  861. // }
  862. } else if (value.equals("spec")) {
  863. JSONObject jsonObject = new JSONObject();
  864. jsonObject.put("parm", content.getString("spec"));
  865. jsonObject.put("flag", true);
  866. specmap.add(jsonObject);
  867. // for (String firstspec : firstspecList) {
  868. // JSONObject jsonObject1 =new JSONObject();
  869. // if (!firstspec.equals(content.getString("spec"))) {
  870. // jsonObject1.put("parm",firstspec);
  871. // jsonObject1.put("flag", true);
  872. // specmap.add(jsonObject1);
  873. // }
  874. // }
  875. } else if (value.equals("material")) {
  876. JSONObject jsonObject = new JSONObject();
  877. jsonObject.put("parm", content.getString("material"));
  878. jsonObject.put("flag", true);
  879. materialmap.add(jsonObject);
  880. // for (String firstmaterial : firstmaterialList) {
  881. // JSONObject jsonObject1 =new JSONObject();
  882. // if (!firstmaterial.equals(content.getString("material"))) {
  883. // jsonObject1.put("parm",firstmaterial);
  884. // jsonObject1.put("flag", true);
  885. // materialmap.add(jsonObject1);
  886. // }
  887. // }
  888. } else if (value.equals("cheek")) {
  889. JSONObject jsonObject = new JSONObject();
  890. jsonObject.put("parm", content.getString("cheek"));
  891. jsonObject.put("flag", true);
  892. cheekmap.add(jsonObject);
  893. // for (String firstcheek : firstcheekList) {
  894. // JSONObject jsonObject1 =new JSONObject();
  895. // if (!firstcheek.equals(content.getString("cheek"))) {
  896. // jsonObject1.put("parm", firstcheek);
  897. // jsonObject1.put("flag", true);
  898. // cheekmap.add(jsonObject1);
  899. // }
  900. // }
  901. }
  902. where = where + " and " + value + "='" + content.getString(value) + "' ";
  903. }
  904. factory.addParameter_SQL("where", where);
  905. for (String value : listAll) {
  906. if (value.equals("color")) {
  907. rows = dbConnect.runSqlQuery(factory.getSQL());
  908. if (!rows.isEmpty()) {
  909. for (Row row : rows) {
  910. JSONObject jsonObject = new JSONObject();
  911. jsonObject.put("parm", row.getString("color"));
  912. jsonObject.put("flag", true);
  913. colormap.add(jsonObject);
  914. }
  915. }
  916. } else if (value.equals("spec")) {
  917. rows = dbConnect.runSqlQuery(factory.getSQL());
  918. if (!rows.isEmpty()) {
  919. for (Row row : rows) {
  920. JSONObject jsonObject = new JSONObject();
  921. jsonObject.put("parm", row.getString("spec"));
  922. jsonObject.put("flag", true);
  923. specmap.add(jsonObject);
  924. }
  925. }
  926. } else if (value.equals("material")) {
  927. rows = dbConnect.runSqlQuery(factory.getSQL());
  928. if (!rows.isEmpty()) {
  929. for (Row row : rows) {
  930. JSONObject jsonObject = new JSONObject();
  931. jsonObject.put("parm", row.getString("material"));
  932. jsonObject.put("flag", true);
  933. materialmap.add(jsonObject);
  934. }
  935. }
  936. } else if (value.equals("cheek")) {
  937. rows = dbConnect.runSqlQuery(factory.getSQL());
  938. if (!rows.isEmpty()) {
  939. for (Row row : rows) {
  940. JSONObject jsonObject = new JSONObject();
  941. jsonObject.put("parm", row.getString("cheek"));
  942. jsonObject.put("flag", true);
  943. cheekmap.add(jsonObject);
  944. }
  945. }
  946. }
  947. }
  948. if(customschemeItems1RowsMap.containsKey("color")){
  949. where=" 1=1 ";
  950. for (String value : listParmNotBlank) {
  951. if(!value.equals("color")){
  952. where = where + " and " + value + "='" + content.getString(value) + "' ";
  953. }
  954. }
  955. factory.addParameter_SQL("where", where);
  956. rows = dbConnect.runSqlQuery(factory.getSQL());
  957. if (!rows.isEmpty()) {
  958. for (Row row : rows) {
  959. JSONObject jsonObject = new JSONObject();
  960. jsonObject.put("parm", row.getString("color"));
  961. jsonObject.put("flag", true);
  962. colormap.add(jsonObject);
  963. }
  964. }
  965. for (String firstcolor : firstcolorList) {
  966. boolean isexistParm = false;
  967. for (Object object : colormap) {
  968. JSONObject jsonObject = (JSONObject) object;
  969. if (jsonObject.getString("parm").equals(firstcolor)) {
  970. isexistParm = true;
  971. break;
  972. }
  973. }
  974. if (!isexistParm) {
  975. JSONObject jsonObject = new JSONObject();
  976. jsonObject.put("parm", firstcolor);
  977. jsonObject.put("flag", false);
  978. colormap.add(jsonObject);
  979. }
  980. }
  981. }else{
  982. for (String firstcolor : firstcolorList) {
  983. boolean isexistParm = false;
  984. for (Object object : colormap) {
  985. JSONObject jsonObject = (JSONObject) object;
  986. if (jsonObject.getString("parm").equals(firstcolor)) {
  987. isexistParm = true;
  988. break;
  989. }
  990. }
  991. if (!isexistParm) {
  992. JSONObject jsonObject = new JSONObject();
  993. jsonObject.put("parm", firstcolor);
  994. jsonObject.put("flag", false);
  995. colormap.add(jsonObject);
  996. }
  997. }
  998. }
  999. if(customschemeItems1RowsMap.containsKey("spec")){
  1000. where=" 1=1 ";
  1001. for (String value : listParmNotBlank) {
  1002. if(!value.equals("spec")){
  1003. where = where + " and " + value + "='" + content.getString(value) + "' ";
  1004. }
  1005. }
  1006. factory.addParameter_SQL("where", where);
  1007. rows = dbConnect.runSqlQuery(factory.getSQL());
  1008. if (!rows.isEmpty()) {
  1009. for (Row row : rows) {
  1010. JSONObject jsonObject = new JSONObject();
  1011. jsonObject.put("parm", row.getString("spec"));
  1012. jsonObject.put("flag", true);
  1013. colormap.add(jsonObject);
  1014. }
  1015. }
  1016. for (String firstspec : firstspecList) {
  1017. boolean isexistParm = false;
  1018. for (Object object : specmap) {
  1019. JSONObject jsonObject = (JSONObject) object;
  1020. if (jsonObject.getString("parm").equals(firstspec)) {
  1021. isexistParm = true;
  1022. break;
  1023. }
  1024. }
  1025. if (!isexistParm) {
  1026. JSONObject jsonObject = new JSONObject();
  1027. jsonObject.put("parm", firstspec);
  1028. jsonObject.put("flag", false);
  1029. specmap.add(jsonObject);
  1030. }
  1031. }
  1032. }else{
  1033. for (String firstspec : firstspecList) {
  1034. boolean isexistParm = false;
  1035. for (Object object : specmap) {
  1036. JSONObject jsonObject = (JSONObject) object;
  1037. if (jsonObject.getString("parm").equals(firstspec)) {
  1038. isexistParm = true;
  1039. break;
  1040. }
  1041. }
  1042. if (!isexistParm) {
  1043. JSONObject jsonObject = new JSONObject();
  1044. jsonObject.put("parm", firstspec);
  1045. jsonObject.put("flag", false);
  1046. specmap.add(jsonObject);
  1047. }
  1048. }
  1049. }
  1050. if(customschemeItems1RowsMap.containsKey("material")){
  1051. where=" 1=1 ";
  1052. for (String value : listParmNotBlank) {
  1053. if(!value.equals("material")){
  1054. where = where + " and " + value + "='" + content.getString(value) + "' ";
  1055. }
  1056. }
  1057. factory.addParameter_SQL("where", where);
  1058. rows = dbConnect.runSqlQuery(factory.getSQL());
  1059. if (!rows.isEmpty()) {
  1060. for (Row row : rows) {
  1061. JSONObject jsonObject = new JSONObject();
  1062. jsonObject.put("parm", row.getString("material"));
  1063. jsonObject.put("flag", true);
  1064. colormap.add(jsonObject);
  1065. }
  1066. }
  1067. for (String firstmaterial : firstmaterialList) {
  1068. boolean isexistParm = false;
  1069. for (Object object : materialmap) {
  1070. JSONObject jsonObject = (JSONObject) object;
  1071. if (jsonObject.getString("parm").equals(firstmaterial)) {
  1072. isexistParm = true;
  1073. break;
  1074. }
  1075. }
  1076. if (!isexistParm) {
  1077. JSONObject jsonObject = new JSONObject();
  1078. jsonObject.put("parm", firstmaterial);
  1079. jsonObject.put("flag", false);
  1080. materialmap.add(jsonObject);
  1081. }
  1082. }
  1083. }else{
  1084. for (String firstmaterial : firstmaterialList) {
  1085. boolean isexistParm = false;
  1086. for (Object object : materialmap) {
  1087. JSONObject jsonObject = (JSONObject) object;
  1088. if (jsonObject.getString("parm").equals(firstmaterial)) {
  1089. isexistParm = true;
  1090. break;
  1091. }
  1092. }
  1093. if (!isexistParm) {
  1094. JSONObject jsonObject = new JSONObject();
  1095. jsonObject.put("parm", firstmaterial);
  1096. jsonObject.put("flag", false);
  1097. materialmap.add(jsonObject);
  1098. }
  1099. }
  1100. }
  1101. if(customschemeItems1RowsMap.containsKey("cheek")){
  1102. where=" 1=1 ";
  1103. for (String value : listParmNotBlank) {
  1104. if(!value.equals("cheek")){
  1105. where = where + " and " + value + "='" + content.getString(value) + "' ";
  1106. }
  1107. }
  1108. factory.addParameter_SQL("where", where);
  1109. rows = dbConnect.runSqlQuery(factory.getSQL());
  1110. if (!rows.isEmpty()) {
  1111. for (Row row : rows) {
  1112. JSONObject jsonObject = new JSONObject();
  1113. jsonObject.put("parm", row.getString("cheek"));
  1114. jsonObject.put("flag", true);
  1115. colormap.add(jsonObject);
  1116. }
  1117. }
  1118. for (String firstcheek : firstcheekList) {
  1119. boolean isexistParm = false;
  1120. for (Object object : cheekmap) {
  1121. JSONObject jsonObject = (JSONObject) object;
  1122. if (jsonObject.getString("parm").equals(firstcheek)) {
  1123. isexistParm = true;
  1124. break;
  1125. }
  1126. }
  1127. if (!isexistParm) {
  1128. JSONObject jsonObject = new JSONObject();
  1129. jsonObject.put("parm", firstcheek);
  1130. jsonObject.put("flag", false);
  1131. cheekmap.add(jsonObject);
  1132. }
  1133. }
  1134. }else{
  1135. for (String firstcheek : firstcheekList) {
  1136. boolean isexistParm = false;
  1137. for (Object object : cheekmap) {
  1138. JSONObject jsonObject = (JSONObject) object;
  1139. if (jsonObject.getString("parm").equals(firstcheek)) {
  1140. isexistParm = true;
  1141. break;
  1142. }
  1143. }
  1144. if (!isexistParm) {
  1145. JSONObject jsonObject = new JSONObject();
  1146. jsonObject.put("parm", firstcheek);
  1147. jsonObject.put("flag", false);
  1148. cheekmap.add(jsonObject);
  1149. }
  1150. }
  1151. }
  1152. }
  1153. colormap = jsonArraySortByField(colormap.toJSONString(), "parm", "0");
  1154. specmap = jsonArraySortByField(specmap.toJSONString(), "parm", "0");
  1155. materialmap = jsonArraySortByField(materialmap.toJSONString(), "parm", "0");
  1156. cheekmap = jsonArraySortByField(cheekmap.toJSONString(), "parm", "0");
  1157. for (Object object : colormap) {
  1158. boolean flag = false;
  1159. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  1160. for (parm parm1 : colorList) {
  1161. if (parm1.getParm().equals(parm.getParm())) {
  1162. flag = true;
  1163. break;
  1164. }
  1165. }
  1166. if (!flag) {
  1167. colorList.add(parm);
  1168. }
  1169. }
  1170. for (Object object : specmap) {
  1171. boolean flag = false;
  1172. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  1173. for (parm parm1 : specList) {
  1174. if (parm1.getParm().equals(parm.getParm())) {
  1175. flag = true;
  1176. break;
  1177. }
  1178. }
  1179. if (!flag) {
  1180. specList.add(parm);
  1181. }
  1182. }
  1183. for (Object object : materialmap) {
  1184. boolean flag = false;
  1185. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  1186. for (parm parm1 : materialList) {
  1187. if (parm1.getParm().equals(parm.getParm())) {
  1188. flag = true;
  1189. break;
  1190. }
  1191. }
  1192. if (!flag) {
  1193. materialList.add(parm);
  1194. }
  1195. }
  1196. for (Object object : cheekmap) {
  1197. boolean flag = false;
  1198. parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
  1199. for (parm parm1 : cheekList) {
  1200. if (parm1.getParm().equals(parm.getParm())) {
  1201. flag = true;
  1202. break;
  1203. }
  1204. }
  1205. if (!flag) {
  1206. cheekList.add(parm);
  1207. }
  1208. }
  1209. // colorList.addAll(JSONObject.parseArray(colormap.toJSONString(), parm.class));
  1210. // specList.addAll(JSONObject.parseArray(specmap.toJSONString(), parm.class));
  1211. // materialList.addAll(JSONObject.parseArray(materialmap.toJSONString(), parm.class));
  1212. // cheekList.addAll(JSONObject.parseArray(cheekmap.toJSONString(), parm.class));
  1213. rows = dbConnect.runSqlQuery(factory.getSQL());
  1214. String itemno = "";
  1215. if (!rows.isEmpty()) {
  1216. itemno = rows.get(0).getString("itemno");
  1217. }
  1218. /**
  1219. * 查询商品明细
  1220. */
  1221. SQLFactory priceSqlFactory = new SQLFactory(this, "查询商品原价");
  1222. priceSqlFactory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
  1223. priceSqlFactory.addParameter("siteid", siteid);
  1224. Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
  1225. if(!siteParameterRows.isEmpty()){
  1226. if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
  1227. priceSqlFactory.addParameter("pricegrade", "1");
  1228. }else{
  1229. priceSqlFactory.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
  1230. }
  1231. }else{
  1232. priceSqlFactory.addParameter("pricegrade", "1");
  1233. }
  1234. Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
  1235. RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
  1236. SQLFactory sqlFactory = new SQLFactory(this, "查询商品详情", pageSize, pageNumber, pageSorting);
  1237. sqlFactory.addParameter_SQL("where", "t2.itemno='" + itemno + "' ");
  1238. sqlFactory.addParameter("itemno", itemno);
  1239. sqlFactory.addParameter("siteid", siteid);
  1240. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  1241. Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  1242. for (Row row : itemrows) {
  1243. row.put("customschemeItems",customschemeItems);
  1244. ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
  1245. row.put("oldprice", itemPrice.getPrice());
  1246. if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
  1247. row.put("gradeprice", itemPrice.getContractprice());
  1248. } else {
  1249. if(pricerowsMap.containsKey(row.getString("itemid"))){
  1250. if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
  1251. row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
  1252. }else{
  1253. row.put("gradeprice",0);
  1254. }
  1255. }else {
  1256. row.put("gradeprice", 0);
  1257. }
  1258. }
  1259. //判断商品是否参与活动:当前经销商参与的有效的活动
  1260. if(listAll.size()==listParmNotBlank.size()){
  1261. SQLFactory activitysqlFactory = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询");
  1262. activitysqlFactory.addParameter("siteid", siteid);
  1263. activitysqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  1264. activitysqlFactory.addParameter_SQL("where", "1=1");
  1265. Rows activityrows = dbConnect.runSqlQuery(activitysqlFactory);
  1266. SQLFactory sqlFactory1 = new SQLFactory(new promotion(new JSONObject()), "促销订单金额合计查询");
  1267. sqlFactory1.addParameter("siteid", siteid);
  1268. sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
  1269. Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
  1270. RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
  1271. SQLFactory sqlFactory2 = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询(触发的促销方案)");
  1272. sqlFactory2.addParameter("siteid", siteid);
  1273. sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
  1274. Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
  1275. RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
  1276. ListIterator<Row> iterator = activityrows.listIterator();
  1277. while (iterator.hasNext()) {
  1278. Row activityrow = iterator.next();
  1279. if(activityrow.getLong("sa_openpromotionid")!=0){
  1280. if(sumAmountRowsMap.containsKey(activityrow.getString("sa_promotionid"))){
  1281. BigDecimal sumamount = sumAmountRowsMap.get(activityrow.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
  1282. if(sumamount.compareTo(activityrow.getBigDecimal("openamount"))>=0){
  1283. if(openPromotionsRowsMap.containsKey(activityrow.getString("sa_openpromotionid"))){
  1284. iterator.add(openPromotionsRowsMap.get(activityrow.getString("sa_openpromotionid")).get(0));
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. SQLFactory promotionsqlFactory = new SQLFactory(this, "查询商品所在有效活动", pageSize, pageNumber, pageSorting);
  1291. promotionsqlFactory.addParameter("itemno", itemno);
  1292. promotionsqlFactory.addParameter_in("sa_promotionids", activityrows.toArray("sa_promotionid"));
  1293. promotionsqlFactory.addParameter("siteid", siteid);
  1294. Rows promotionrows = dbConnect.runSqlQuery(promotionsqlFactory.getSQL());
  1295. row.put("canuseactivity",promotionrows);
  1296. }else{
  1297. row.put("canuseactivity",new Rows());
  1298. }
  1299. }
  1300. ArrayList<Long> ids = itemrows.toArrayList("itemid", new ArrayList<>());
  1301. //默认商品图片
  1302. Rows defaultImageRows = Item.getItemdefaultImage(this);
  1303. // 封面cover
  1304. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  1305. // 附件
  1306. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  1307. Rows rowsitemclass = dbConnect.runSqlQuery(
  1308. " 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='"
  1309. + siteid + "'");
  1310. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  1311. // 货品档案领域
  1312. Rows rowstradefield = dbConnect.runSqlQuery(
  1313. " select t6.itemid,t6.tradefield from plm_item_tradefield t6 where t6.siteid='" + siteid + "'");
  1314. RowsMap tradefieldRowsMap = rowstradefield.toRowsMap("itemid");
  1315. // 品牌
  1316. Rows rowsbrand = dbConnect.runSqlQuery(
  1317. " 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='"
  1318. + siteid + "'");
  1319. RowsMap brandRowsMap = rowsbrand.toRowsMap("itemid");
  1320. for (Row row : itemrows) {
  1321. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  1322. if (coverRows.isEmpty()) {
  1323. row.put("cover", "");
  1324. } else {
  1325. row.put("cover", coverRows.get(0).getString("url"));
  1326. }
  1327. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  1328. row.put("attinfos", defaultImageRows);
  1329. } else {
  1330. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  1331. }
  1332. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  1333. row.put("tradefield", tradefieldRowsMap.get(row.getString("itemid")));
  1334. row.put("brand", brandRowsMap.get(row.getString("itemid")));
  1335. }
  1336. JSONObject oject = new JSONObject();
  1337. oject.put("customschemeItems", customschemeItems.toJsonArray());
  1338. oject.put("colorRows", colorList);
  1339. oject.put("specRows", specList);
  1340. oject.put("materialRows", materialList);
  1341. oject.put("cheekRows", cheekList);
  1342. oject.put("rows", rows);
  1343. oject.put("item", itemrows);
  1344. return getSucReturnObject().setData(oject).toString();
  1345. }
  1346. /**
  1347. * 按照JSONArray中的对象的某个字段进行排序(采用fastJson)
  1348. *
  1349. * @param jsonArrayStr json数组字符串
  1350. * @param sortkeyname 根据哪个字段进行排序
  1351. * @param order 倒序:0;非0顺序
  1352. * @return 排序后的jsonarray
  1353. */
  1354. public JSONArray jsonArraySortByField(String jsonArrayStr, String sortkeyname, String order) throws YosException {
  1355. JSONArray sortedJsonArray = new JSONArray();
  1356. try {
  1357. JSONArray jsonArray = JSON.parseArray(jsonArrayStr);
  1358. List<JSONObject> jsonList = new ArrayList<JSONObject>();
  1359. for (int i = 0; i < jsonArray.size(); i++) {
  1360. jsonList.add(jsonArray.getJSONObject(i));
  1361. }
  1362. Collections.sort(jsonList, new Comparator<JSONObject>() {
  1363. @Override
  1364. public int compare(JSONObject a, JSONObject b) {
  1365. String strA = new String();
  1366. String strB = new String();
  1367. String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\-_\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
  1368. String aStr = a.getStringValue(sortkeyname);
  1369. strA = aStr.replaceAll(regEx, "");
  1370. String bStr = b.getStringValue(sortkeyname);
  1371. strB = bStr.replaceAll(regEx, "");
  1372. if ("0".equals(order)) {
  1373. return -strA.compareTo(strB);
  1374. } else {
  1375. return strA.compareTo(strB);
  1376. }
  1377. }
  1378. });
  1379. for (int i = 0; i < jsonArray.size(); i++) {
  1380. sortedJsonArray.add(jsonList.get(i));
  1381. }
  1382. } catch (Exception e) {
  1383. e.printStackTrace();
  1384. }
  1385. return sortedJsonArray;
  1386. }
  1387. }