| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528 |
- package restcontroller.sale.itemgroup;
- import beans.Item.Item;
- import beans.datatag.DataTag;
- import beans.enterprise.Enterprise;
- import beans.itemclass.ItemClass;
- import beans.itemgroup.Itemgroup;
- import beans.itemprice.ItemPrice;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.annotation.CACHEING;
- import common.data.Row;
- import common.data.Rows;
- import common.data.RowsMap;
- import common.data.SQLFactory;
- import org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import restcontroller.sale.promotion.promotion;
- import java.math.BigDecimal;
- import java.util.*;
- @API(title = "商品组")
- public class itemgroup extends Controller {
- public itemgroup(JSONObject arg0) throws YosException {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
- /**
- * * 查询商品组
- *
- * @return
- */
- @API(title = "查询", apiversion = R.ID20221219113503.v1.class)
- @CACHEING
- public String queryItemSaleClasses() throws YosException {
- Long istool = content.getLongValue("istool");
- Rows itemclassRows = Enterprise.getItemSaleClasses(this, sys_enterpriseid, true, istool);
- return getSucReturnObject().setData(itemclassRows).toString();
- }
- /**
- * * 查询商品组
- *
- * @return
- */
- @API(title = "查询", apiversion = R.ID20220926142203.v1.class)
- @CACHEING
- public String queryItemgroup() throws YosException {
- Long istool = content.getLongValue("istool");
- //Rows itemclassRows = Enterprise.getItemSaleClasses(this, sys_enterpriseid, true, istool);
- if (content.containsKey("sys_enterpriseid")) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- }
- /*
- * * 过滤条件设置
- */
- String where = " 1=1 ";
- String where1 = "";
- String itemclasssql = "select itemclassid from plm_itemclass where siteid='" + siteid + "'";
- if (sys_enterpriseid > 0) {
- Row enterpriseRow = Enterprise.getEnterprise(this, sys_enterpriseid);
- if (!enterpriseRow.isEmpty()) {
- //企业营销类别
- boolean saleclassauth = enterpriseRow.getBoolean("saleclassauth");
- if (saleclassauth) {
- 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 + "')";
- }
- //企业领域
- Rows tradefieldrows = dbConnect.runSqlQuery("SELECT tradefield from sys_enterprise_tradefield WHERE sys_enterpriseid =" + sys_enterpriseid + " and siteid ='" + siteid + "'");
- if (!tradefieldrows.isEmpty()) {
- for (Row row : tradefieldrows) {
- where1 = where1 + " (t1.tradefield like'%" + row.getString("tradefield") + "%') or ";
- }
- } else {
- where1 = where1 + " 1=2 ";
- }
- } else {
- where1 = " 1=2 ";
- }
- } else {
- where1 = " 1=1 ";
- }
- if (where1.contains("or")) {
- where1 = where1.substring(0, where1.lastIndexOf("or"));
- }
- Rows itemclassRows = dbConnect.runSqlQuery(itemclasssql);
- ArrayList<Long> itemclassList = new ArrayList<Long>();
- for (Row row : itemclassRows) {
- //System.out.println(row.getLong("itemclassid"));
- itemclassList.add(row.getLong("itemclassid"));
- itemclassList.addAll(ItemClass.getSubItemClassIds(this, row.getLong("itemclassid")));
- }
- SQLFactory factorygroupid = new SQLFactory(this, "查询授权范围内的商品组商品");
- factorygroupid.addParameter("siteid", siteid);
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + " and (t1.groupname like'%" + whereObject.getString("condition")
- + "%' or t1.groupnum like'%" + whereObject.getString("condition")
- + "%' 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 '%"
- + whereObject.getString("condition") + "%' or s2.itemno like '%" + whereObject.getString("condition")
- + "%' or s2.standards like '%" + whereObject.getString("condition")
- + "%' or s2.spec like '%" + whereObject.getString("condition")
- + "%' or s2.byname like '%" + whereObject.getString("condition")
- + "%' or s2.model like '%" + whereObject.getString("condition")
- + "%') and s1.sa_itemgroupid=t1.sa_itemgroupid) ) ";
- }
- if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
- where = where + " and (t1.tradefield like'%" + whereObject.getString("tradefield") + "%') ";
- }
- // else {
- // if (sys_enterpriseid > 0) {
- // where = where + " and (t1.tradefield in (SELECT tradefield from sys_enterprise_tradefield WHERE sys_enterpriseid = " + sys_enterpriseid + " and siteid='" + siteid + "') ) ";
- // }
- // }
- if (whereObject.containsKey("standards") && !"".equals(whereObject.getString("standards"))) {
- where = where
- + " 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='"
- + whereObject.getString("standards") + "' and s1.sa_itemgroupid=t1.sa_itemgroupid) ";
- }
- if (whereObject.containsKey("itemclassid") && !"".equals(whereObject.getString("itemclassid"))) {
- ArrayList<Long> list = ItemClass.getSubItemClassIds(this, whereObject.getLong("itemclassid"));
- list.add(whereObject.getLong("itemclassid"));
- ArrayList<Long> listNew = new ArrayList<>();
- listNew.add((long) 0);
- for (long itemclassid : list) {
- if (itemclassList.contains(itemclassid)) {
- listNew.add(itemclassid);
- }
- }
- factorygroupid.addParameter_in("itemclassid", listNew);
- } else {
- factorygroupid.addParameter_in("itemclassid",
- itemclassList);
- }
- } else {
- factorygroupid.addParameter_in("itemclassid",
- itemclassList);
- }
- JSONArray brandids = content.getJSONArray("brandids");
- if (brandids.isEmpty()) {
- Rows rows;
- if (sys_enterpriseid > 0) {
- rows = Enterprise.getBrands(this, sys_enterpriseid);
- } else {
- rows = dbConnect.runSqlQuery("select sa_brandid from sa_brand where siteid='" + siteid + "'");
- }
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- brandids.add(row.getLong("sa_brandid"));
- }
- } else {
- brandids.add(0);
- }
- }
- factorygroupid.addParameter("siteid", siteid);
- Enterprise.EnterpriseGrade enterpriseGrade = Enterprise.getEnterpriseGrade(this, sys_enterpriseid);
- if (enterpriseGrade != null) {
- factorygroupid.addParameter("pricegrade", enterpriseGrade.getPricegrade());
- }else {
- Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
- if(!siteParameterRows.isEmpty()){
- if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
- factorygroupid.addParameter("pricegrade", "1");
- }else{
- factorygroupid.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
- }
- }else{
- factorygroupid.addParameter("pricegrade", "1");
- }
- }
- Rows rowsgroupids = dbConnect.runSqlQuery(factorygroupid.getSQL());
- RowsMap itemgroupRowMap = rowsgroupids.toRowsMap("sa_itemgroupid");
- /*
- * SQL查询参数设置并查询
- */
- SQLFactory factory = new SQLFactory(this, "商品组列表查询", pageSize, pageNumber, pageSorting);
- factory.addParameter("siteid", siteid);
- factory.addParameter_in("sa_brandid", brandids.toArray());
- factory.addParameter_in("sa_itemgroupids", rowsgroupids.toArrayList("sa_itemgroupid", new ArrayList<Long>()));
- factory.addParameter_SQL("where", where);
- factory.addParameter_SQL("where1", where1);
- String sql = factory.getSQL();
- //System.out.println(sql);
- Rows rows = dbConnect.runSqlQuery(sql);
- ArrayList<Long> itemgroupids = rows.toArrayList("sa_itemgroupid", new ArrayList<Long>());
- RowsMap itemgroupScemeRowsMap = Itemgroup.getItemgroupScemeid(this, itemgroupids);
- for (Row row2 : rows) {
- long sa_itemgroupid = row2.getLong("sa_itemgroupid");
- ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", sa_itemgroupid, false);
- row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
- // HashMap<Long, ItemPrice> ItemPriceList = ItemPrice.getItemGroupPrice(this, sys_enterpriseid,
- // row2.getLong("sa_itemgroupid"));
- // BigDecimal max = new BigDecimal(0);
- // BigDecimal min = ((ItemPrice) ItemPriceList.values().toArray()[0]).getPrice();
- // for (ItemPrice itemPrice : ItemPriceList.values()) {
- // BigDecimal itemprice = itemPrice.getPrice();
- // if (itemprice.compareTo(max) >0) {
- // max = itemprice;
- // }
- // if (itemprice.compareTo(min) <0) {
- // min = itemprice;
- // }
- // }
- Rows rows1 = itemgroupRowMap.get(String.valueOf(sa_itemgroupid));
- if (rows1.isEmpty()) {
- row2.put("maxprice", 0);
- row2.put("minprice", 0);
- } else {
- row2.put("maxprice", rows1.get(0).getBigDecimal("maxprice"));
- row2.put("minprice", rows1.get(0).getBigDecimal("minprice"));
- }
- Long id = sa_itemgroupid;
- if (itemgroupScemeRowsMap.get(id.toString()).isNotEmpty()) {
- if (itemgroupScemeRowsMap.get(id.toString()).get(0).getLong("sa_customschemeid") > 0) {
- row2.put("isscheme", true);
- } else {
- row2.put("isscheme", false);
- }
- } else {
- row2.put("isscheme", false);
- }
- }
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- /**
- * 查询商品明细
- */
- SQLFactory sqlFactory = new SQLFactory(this, "查询商品列表");
- sqlFactory.addParameter_in("itemids", ids);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- for (Row row : itemrows) {
- ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
- row.put("oldprice", itemPrice.getPrice());
- if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
- row.put("gradeprice", itemPrice.getContractprice());
- } else {
- row.put("gradeprice", itemPrice.getMarketprice());
- }
- }
- RowsMap itemRowsMap = itemrows.toRowsMap("itemid");
- //默认商品图片
- Rows defaultImageRows = Item.getItemdefaultImage(this);
- // 封面cover
- RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
- // 附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- // 附件
- RowsMap itemgroupRowsMap = getAttachmentUrl("sa_itemgroup", itemgroupids);
- Rows rowsitemclass = dbConnect.runSqlQuery(
- " 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='"
- + siteid + "'");
- RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
- for (Row row : rows) {
- Rows itemRows = itemRowsMap.get(row.getString("itemid"));
- row.put("item", itemRows);
- Rows coverRows = coverRowsMap.get(row.getString("itemid"));
- if (coverRows.isEmpty()) {
- if (!defaultImageRows.isEmpty()) {
- row.put("cover", defaultImageRows.get(0).getString("url"));
- } else {
- row.put("cover", "");
- }
- } else {
- row.put("cover", coverRows.get(0).getString("url"));
- }
- if ((itemgroupRowsMap.getOrDefault(row.getString("sa_itemgroupid"), new Rows())).isNotEmpty()) {
- row.put("attinfos", itemgroupRowsMap.getOrDefault(row.getString("sa_itemgroupid"), new Rows()));
- } else {
- if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
- row.put("attinfos", defaultImageRows);
- } else {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- }
- }
- row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "商品组详情", apiversion = R.ID20220926142303.v1.class)
- public String queryItemgroupMain() throws YosException {
- Long sa_itemgroupid = content.getLong("sa_itemgroupid");
- SQLFactory sqlFactory = new SQLFactory(this, "商品组详情查询");
- sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- Rows rowsitemclass = dbConnect.runSqlQuery(
- " 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='"
- + siteid + "'");
- RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
- if (!rows.isEmpty()) {
- ArrayList<String> list = DataTag.queryTag(this, "sa_itemgroup", rows.get(0).getLong("sa_itemgroupid"),
- false);
- rows.get(0).put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
- rows.get(0).put("itemclass", itemclassRowsMap.get(rows.get(0).getString("itemid")));
- }
- return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
- }
- @API(title = "商品组商品明细列表", apiversion = R.ID20220926142403.v1.class)
- @CACHEING
- public String queryItemgroupMxList() throws YosException {
- if (content.containsKey("sys_enterpriseid")) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- }
- /*
- * 过滤条件设置
- */
- String where = " 1=1 ";
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + "and t2.itemname like'%" + whereObject.getString("condition") + "%'";
- }
- }
- Long sa_itemgroupid = content.getLong("sa_itemgroupid");
- // String hrid = content.getString("hrid");
- SQLFactory sqlFactory = new SQLFactory(this, "商品组商品明细查询", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- //默认商品图片
- Rows defaultImageRows = Item.getItemdefaultImage(this);
- // 封面cover
- RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
- // 附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- Rows technicalinforows = dbConnect.runSqlQuery("select plm_technicalinfoid,itemid from plm_technicalinfo_item");
- RowsMap technicalinfoRowsMap = technicalinforows.toRowsMap("itemid");
- Rows technicalinforows1 = dbConnect.runSqlQuery("select plm_technicalinfoid from plm_technicalinfo");
- ArrayList<Long> plm_technicalinfoids = technicalinforows1.toArrayList("plm_technicalinfoid", new ArrayList<>());
- // 产品技术资料附件
- RowsMap plm_technicalinfoRowsMap = getAttachmentUrl("plm_technicalinfo", plm_technicalinfoids);
- // 商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- Rows rowsitemclass = dbConnect.runSqlQuery(
- " select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
- + siteid + "'");
- RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
- RowsMap itemextendRowsMap = dbConnect.runSqlQuery("select itemid,material,device,prodline,specalnote,pressure,connection,valveplatematerial,actuatortype,actuatorbrand,butterflyplatedrive from plm_itemextend where siteid='" + siteid + "'").toRowsMap("itemid");
- SQLFactory priceSqlFactory = new SQLFactory(this, "查询商品原价");
- priceSqlFactory.addParameter("sa_itemgroupid", sa_itemgroupid);
- priceSqlFactory.addParameter("siteid", siteid);
- Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
- if(!siteParameterRows.isEmpty()){
- if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
- priceSqlFactory.addParameter("pricegrade", "1");
- }else{
- priceSqlFactory.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
- }
- }else{
- priceSqlFactory.addParameter("pricegrade", "1");
- }
- Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
- RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
- for (Row row : rows) {
- ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
- row.put("oldprice", itemPrice.getMarketprice());
- if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
- row.put("gradeprice", itemPrice.getContractprice());
- } else {
- if(pricerowsMap.containsKey(row.getString("itemid"))){
- if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
- row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
- }else{
- row.put("gradeprice",0);
- }
- }else {
- row.put("gradeprice", 0);
- }
- }
- Rows jsonArray = new Rows();
- Rows coverRows = coverRowsMap.get(row.getString("itemid"));
- if (coverRows.isEmpty()) {
- row.put("cover", "");
- } else {
- row.put("cover", coverRows.get(0).getString("url"));
- }
- if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
- row.put("attinfos", defaultImageRows);
- } else {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- }
- //row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
- Rows technicalinforowsforitem = technicalinfoRowsMap.get(row.getString("itemid"));
- for (Row row2 : technicalinforowsforitem) {
- jsonArray.addAll(plm_technicalinfoRowsMap.get(row2.getString("plm_technicalinfoid")));
- }
- row.put("technicalinfo", jsonArray);
- row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- if (itemextendRowsMap.containsKey(row.getString("itemid"))) {
- row.put("itemextend", itemextendRowsMap.get(row.getString("itemid")));
- } else {
- row.put("itemextend", new Rows());
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "商品组列表", apiversion = R.ID20221223165503.v1.class)
- @CACHEING
- public String querymx() throws YosException {
- Set<String> listParmBlank = new LinkedHashSet<String>();
- Set<String> listParmNotBlank = new LinkedHashSet<String>();
- Set<String> firstcolorList = new LinkedHashSet();
- Set<String> firstspecList = new LinkedHashSet();
- Set<String> firstmaterialList = new LinkedHashSet();
- Set<String> firstcheekList = new LinkedHashSet();
- Set<parm> colorList = new LinkedHashSet();
- Set<parm> specList = new LinkedHashSet();
- Set<parm> materialList = new LinkedHashSet();
- Set<parm> cheekList = new LinkedHashSet();
- String color = content.getStringValue("color");
- String spec = content.getStringValue("spec");
- String material = content.getStringValue("material");
- String cheek = content.getStringValue("cheek");
- /**
- * SQL商品组明细查询参数设置并查询
- */
- Rows rows = null;
- SQLFactory factory = new SQLFactory(this, "商品组明细查询");
- factory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
- factory.addParameter("siteid", siteid);
- String where1 = " 1=1 ";
- Rows tradefieldRows = dbConnect.runSqlQuery("SELECT DISTINCT t1.tradefield from sys_enterprise_tradefield t1 WHERE t1.sys_enterpriseid = " + sys_enterpriseid + " and t1.siteid='" + siteid + "'");
- if (!tradefieldRows.isEmpty()) {
- for (Row row : tradefieldRows) {
- where1 = where1 + " or t4.tradefield like '%" + row.getString("tradefield") + "%' ";
- }
- }
- factory.addParameter_SQL("where1", where1);
- 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");
- 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");
- RowsMap customschemeItems1RowsMap = customschemeItems1.toRowsMap("value");
- if (!customschemeItems.isEmpty()) {
- for (Row row : customschemeItems) {
- if (StringUtils.isNotBlank(row.getString("value"))) {
- if (StringUtils.isNotBlank(content.getString(row.getString("value")))) {
- listParmNotBlank.add(row.getString("value"));
- } else {
- listParmBlank.add(row.getString("value"));
- }
- }
- }
- }
- Set<String> listAll = new LinkedHashSet<String>();
- listAll.addAll(listParmBlank);
- listAll.addAll(listParmNotBlank);
- factory.addParameter_SQL("where", "1=1");
- rows = dbConnect.runSqlQuery(factory.getSQL());
- Rows rowsall=rows;
- for (Row row : rows) {
- for (String value : listAll) {
- if (value.equals("color")) {
- firstcolorList.add(row.getString("color"));
- } else if (value.equals("spec")) {
- firstspecList.add(row.getString("spec"));
- } else if (value.equals("material")) {
- firstmaterialList.add(row.getString("material"));
- } else if (value.equals("cheek")) {
- firstcheekList.add(row.getString("cheek"));
- }
- }
- }
- JSONArray colormap = new JSONArray();
- JSONArray specmap = new JSONArray();
- JSONArray materialmap = new JSONArray();
- JSONArray cheekmap = new JSONArray();
- if (listParmNotBlank == null || listParmNotBlank.size() == 0) {
- factory.addParameter_SQL("where", "1=1");
- for (Row row : rows) {
- for (String value : listParmBlank) {
- if (value.equals("color")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- } else if (value.equals("spec")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- } else if (value.equals("material")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- } else if (value.equals("cheek")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- }
- }
- }
- } else if (listParmBlank == null || listParmBlank.size() == 0) {
- // for (Row row : rows) {
- // for (String value : listParmNotBlank) {
- // if (value.equals("color")) {
- // JSONObject jsonObject =new JSONObject();
- // jsonObject.put("parm", row.getString("color"));
- // jsonObject.put("flag", true);
- // colormap.add(jsonObject);
- // } else if (value.equals("spec")) {
- // JSONObject jsonObject =new JSONObject();
- // jsonObject.put("parm", row.getString("spec"));
- // jsonObject.put("flag", true);
- // specmap.add(jsonObject);
- // } else if (value.equals("material")) {
- // JSONObject jsonObject =new JSONObject();
- // jsonObject.put("parm", row.getString("material"));
- // jsonObject.put("flag", true);
- // materialmap.add(jsonObject);
- // } else if (value.equals("cheek")) {
- // JSONObject jsonObject =new JSONObject();
- // jsonObject.put("parm", row.getString("cheek"));
- // jsonObject.put("flag", true);
- // cheekmap.add(jsonObject);
- // }
- //
- // }
- // }
- String colorwhere = "";
- String specwhere = "";
- String materialwhere = "";
- String cheekwhere = "";
- for (String value : listParmNotBlank) {
- if (value.equals("color")) {
- colorwhere = " and " + value + "='" + content.getString(value) + "' ";
- } else if (value.equals("spec")) {
- specwhere = " and " + value + "='" + content.getString(value) + "' ";
- } else if (value.equals("material")) {
- materialwhere = " and " + value + "='" + content.getString(value) + "' ";
- } else if (value.equals("cheek")) {
- cheekwhere = " and " + value + "='" + content.getString(value) + "' ";
- }
- }
- for (String value : listAll) {
- if (value.equals("color")) {
- factory.addParameter_SQL("where", " 1=1 " + specwhere + materialwhere + cheekwhere);
- //System.out.println(" 1=1 " + specwhere + materialwhere + cheekwhere);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- } else if (value.equals("spec")) {
- factory.addParameter_SQL("where", " 1=1 " + colorwhere + materialwhere + cheekwhere);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- }
- }
- } else if (value.equals("material")) {
- factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + cheekwhere);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- }
- }
- } else if (value.equals("cheek")) {
- factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- }
- }
- }
- }
- for (String firstcolor : firstcolorList) {
- boolean isexistParm = false;
- for (Object object : colormap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcolor)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcolor);
- jsonObject.put("flag", false);
- colormap.add(jsonObject);
- }
- }
- for (String firstspec : firstspecList) {
- boolean isexistParm = false;
- for (Object object : specmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstspec)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstspec);
- jsonObject.put("flag", false);
- specmap.add(jsonObject);
- }
- }
- for (String firstmaterial : firstmaterialList) {
- boolean isexistParm = false;
- for (Object object : materialmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstmaterial)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstmaterial);
- jsonObject.put("flag", false);
- materialmap.add(jsonObject);
- }
- }
- for (String firstcheek : firstcheekList) {
- boolean isexistParm = false;
- for (Object object : cheekmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcheek)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcheek);
- jsonObject.put("flag", false);
- cheekmap.add(jsonObject);
- }
- }
- factory.addParameter_SQL("where", " 1=1 " + colorwhere + specwhere + materialwhere + cheekwhere);
- } else if(listParmNotBlank.size()==1){
- String where = " 1=1 ";
- for (String value : listParmNotBlank) {
- if (value.equals("color")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- // for (String firstcolor : firstcolorList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstcolor.equals(content.getString("color"))) {
- // jsonObject1.put("parm",firstcolor);
- // jsonObject1.put("flag", true);
- // colormap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("spec")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- // for (String firstspec : firstspecList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstspec.equals(content.getString("spec"))) {
- // jsonObject1.put("parm",firstspec);
- // jsonObject1.put("flag", true);
- // specmap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("material")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- // for (String firstmaterial : firstmaterialList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstmaterial.equals(content.getString("material"))) {
- // jsonObject1.put("parm",firstmaterial);
- // jsonObject1.put("flag", true);
- // materialmap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("cheek")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- // for (String firstcheek : firstcheekList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstcheek.equals(content.getString("cheek"))) {
- // jsonObject1.put("parm", firstcheek);
- // jsonObject1.put("flag", true);
- // cheekmap.add(jsonObject1);
- // }
- // }
- }
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- factory.addParameter_SQL("where", where);
- for (String value : listAll) {
- if (value.equals("color")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- } else if (value.equals("spec")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- }
- }
- } else if (value.equals("material")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- }
- }
- } else if (value.equals("cheek")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- }
- }
- }
- }
- List<String> list = new ArrayList<>(listParmNotBlank);
- for (String firstcolor : firstcolorList) {
- boolean isexistParm = false;
- for (Object object : colormap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcolor)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- if(list.get(0).equals("color")){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcolor);
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }else{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcolor);
- jsonObject.put("flag", false);
- colormap.add(jsonObject);
- }
- }
- }
- for (String firstspec : firstspecList) {
- boolean isexistParm = false;
- for (Object object : specmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstspec)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- if(list.get(0).equals("spec")){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstspec);
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- }else{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstspec);
- jsonObject.put("flag", false);
- specmap.add(jsonObject);
- }
- }
- }
- for (String firstmaterial : firstmaterialList) {
- boolean isexistParm = false;
- for (Object object : materialmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstmaterial)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- if(list.get(0).equals("material")){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstmaterial);
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- }else{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstmaterial);
- jsonObject.put("flag", false);
- materialmap.add(jsonObject);
- }
- }
- }
- for (String firstcheek : firstcheekList) {
- boolean isexistParm = false;
- for (Object object : cheekmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcheek)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- if(list.get(0).equals("cheek")){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcheek);
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- }else{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcheek);
- jsonObject.put("flag", false);
- cheekmap.add(jsonObject);
- }
- }
- }
- }else {
- String where = " 1=1 ";
- for (String value : listParmNotBlank) {
- if (value.equals("color")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- // for (String firstcolor : firstcolorList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstcolor.equals(content.getString("color"))) {
- // jsonObject1.put("parm",firstcolor);
- // jsonObject1.put("flag", true);
- // colormap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("spec")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- // for (String firstspec : firstspecList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstspec.equals(content.getString("spec"))) {
- // jsonObject1.put("parm",firstspec);
- // jsonObject1.put("flag", true);
- // specmap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("material")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- // for (String firstmaterial : firstmaterialList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstmaterial.equals(content.getString("material"))) {
- // jsonObject1.put("parm",firstmaterial);
- // jsonObject1.put("flag", true);
- // materialmap.add(jsonObject1);
- // }
- // }
- } else if (value.equals("cheek")) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", content.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- // for (String firstcheek : firstcheekList) {
- // JSONObject jsonObject1 =new JSONObject();
- // if (!firstcheek.equals(content.getString("cheek"))) {
- // jsonObject1.put("parm", firstcheek);
- // jsonObject1.put("flag", true);
- // cheekmap.add(jsonObject1);
- // }
- // }
- }
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- factory.addParameter_SQL("where", where);
- for (String value : listAll) {
- if (value.equals("color")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- } else if (value.equals("spec")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("spec"));
- jsonObject.put("flag", true);
- specmap.add(jsonObject);
- }
- }
- } else if (value.equals("material")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("material"));
- jsonObject.put("flag", true);
- materialmap.add(jsonObject);
- }
- }
- } else if (value.equals("cheek")) {
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("cheek"));
- jsonObject.put("flag", true);
- cheekmap.add(jsonObject);
- }
- }
- }
- }
- if(customschemeItems1RowsMap.containsKey("color")){
- where=" 1=1 ";
- for (String value : listParmNotBlank) {
- if(!value.equals("color")){
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- }
- factory.addParameter_SQL("where", where);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("color"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- for (String firstcolor : firstcolorList) {
- boolean isexistParm = false;
- for (Object object : colormap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcolor)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcolor);
- jsonObject.put("flag", false);
- colormap.add(jsonObject);
- }
- }
- }else{
- for (String firstcolor : firstcolorList) {
- boolean isexistParm = false;
- for (Object object : colormap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcolor)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcolor);
- jsonObject.put("flag", false);
- colormap.add(jsonObject);
- }
- }
- }
- if(customschemeItems1RowsMap.containsKey("spec")){
- where=" 1=1 ";
- for (String value : listParmNotBlank) {
- if(!value.equals("spec")){
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- }
- factory.addParameter_SQL("where", where);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("spec"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- for (String firstspec : firstspecList) {
- boolean isexistParm = false;
- for (Object object : specmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstspec)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstspec);
- jsonObject.put("flag", false);
- specmap.add(jsonObject);
- }
- }
- }else{
- for (String firstspec : firstspecList) {
- boolean isexistParm = false;
- for (Object object : specmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstspec)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstspec);
- jsonObject.put("flag", false);
- specmap.add(jsonObject);
- }
- }
- }
- if(customschemeItems1RowsMap.containsKey("material")){
- where=" 1=1 ";
- for (String value : listParmNotBlank) {
- if(!value.equals("material")){
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- }
- factory.addParameter_SQL("where", where);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("material"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- for (String firstmaterial : firstmaterialList) {
- boolean isexistParm = false;
- for (Object object : materialmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstmaterial)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstmaterial);
- jsonObject.put("flag", false);
- materialmap.add(jsonObject);
- }
- }
- }else{
- for (String firstmaterial : firstmaterialList) {
- boolean isexistParm = false;
- for (Object object : materialmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstmaterial)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstmaterial);
- jsonObject.put("flag", false);
- materialmap.add(jsonObject);
- }
- }
- }
- if(customschemeItems1RowsMap.containsKey("cheek")){
- where=" 1=1 ";
- for (String value : listParmNotBlank) {
- if(!value.equals("cheek")){
- where = where + " and " + value + "='" + content.getString(value) + "' ";
- }
- }
- factory.addParameter_SQL("where", where);
- rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", row.getString("cheek"));
- jsonObject.put("flag", true);
- colormap.add(jsonObject);
- }
- }
- for (String firstcheek : firstcheekList) {
- boolean isexistParm = false;
- for (Object object : cheekmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcheek)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcheek);
- jsonObject.put("flag", false);
- cheekmap.add(jsonObject);
- }
- }
- }else{
- for (String firstcheek : firstcheekList) {
- boolean isexistParm = false;
- for (Object object : cheekmap) {
- JSONObject jsonObject = (JSONObject) object;
- if (jsonObject.getString("parm").equals(firstcheek)) {
- isexistParm = true;
- break;
- }
- }
- if (!isexistParm) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("parm", firstcheek);
- jsonObject.put("flag", false);
- cheekmap.add(jsonObject);
- }
- }
- }
- }
- colormap = jsonArraySortByField(colormap.toJSONString(), "parm", "0");
- specmap = jsonArraySortByField(specmap.toJSONString(), "parm", "0");
- materialmap = jsonArraySortByField(materialmap.toJSONString(), "parm", "0");
- cheekmap = jsonArraySortByField(cheekmap.toJSONString(), "parm", "0");
- for (Object object : colormap) {
- boolean flag = false;
- parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
- for (parm parm1 : colorList) {
- if (parm1.getParm().equals(parm.getParm())) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- colorList.add(parm);
- }
- }
- for (Object object : specmap) {
- boolean flag = false;
- parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
- for (parm parm1 : specList) {
- if (parm1.getParm().equals(parm.getParm())) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- specList.add(parm);
- }
- }
- for (Object object : materialmap) {
- boolean flag = false;
- parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
- for (parm parm1 : materialList) {
- if (parm1.getParm().equals(parm.getParm())) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- materialList.add(parm);
- }
- }
- for (Object object : cheekmap) {
- boolean flag = false;
- parm parm = JSON.parseObject(((JSONObject) object).toJSONString(), parm.class);
- for (parm parm1 : cheekList) {
- if (parm1.getParm().equals(parm.getParm())) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- cheekList.add(parm);
- }
- }
- // colorList.addAll(JSONObject.parseArray(colormap.toJSONString(), parm.class));
- // specList.addAll(JSONObject.parseArray(specmap.toJSONString(), parm.class));
- // materialList.addAll(JSONObject.parseArray(materialmap.toJSONString(), parm.class));
- // cheekList.addAll(JSONObject.parseArray(cheekmap.toJSONString(), parm.class));
- rows = dbConnect.runSqlQuery(factory.getSQL());
- String itemno = "";
- if (!rows.isEmpty()) {
- itemno = rows.get(0).getString("itemno");
- }
- /**
- * 查询商品明细
- */
- SQLFactory priceSqlFactory = new SQLFactory(this, "查询商品原价");
- priceSqlFactory.addParameter("sa_itemgroupid", content.getString("sa_itemgroupid"));
- priceSqlFactory.addParameter("siteid", siteid);
- Rows siteParameterRows =dbConnect.runSqlQuery("select defaultlevelprice from sys_site_parameter where siteid='"+siteid+"'");
- if(!siteParameterRows.isEmpty()){
- if(StringUtils.isBlank(siteParameterRows.get(0).getString("defaultlevelprice"))){
- priceSqlFactory.addParameter("pricegrade", "1");
- }else{
- priceSqlFactory.addParameter("pricegrade", siteParameterRows.get(0).getString("defaultlevelprice"));
- }
- }else{
- priceSqlFactory.addParameter("pricegrade", "1");
- }
- Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
- RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
- SQLFactory sqlFactory = new SQLFactory(this, "查询商品详情", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", "t2.itemno='" + itemno + "' ");
- sqlFactory.addParameter("itemno", itemno);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- for (Row row : itemrows) {
- row.put("customschemeItems",customschemeItems);
- ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
- row.put("oldprice", itemPrice.getPrice());
- if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
- row.put("gradeprice", itemPrice.getContractprice());
- } else {
- if(pricerowsMap.containsKey(row.getString("itemid"))){
- if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
- row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
- }else{
- row.put("gradeprice",0);
- }
- }else {
- row.put("gradeprice", 0);
- }
- }
- //判断商品是否参与活动:当前经销商参与的有效的活动
- if(listAll.size()==listParmNotBlank.size()){
- SQLFactory activitysqlFactory = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询");
- activitysqlFactory.addParameter("siteid", siteid);
- activitysqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- activitysqlFactory.addParameter_SQL("where", "1=1");
- Rows activityrows = dbConnect.runSqlQuery(activitysqlFactory);
- SQLFactory sqlFactory1 = new SQLFactory(new promotion(new JSONObject()), "促销订单金额合计查询");
- sqlFactory1.addParameter("siteid", siteid);
- sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
- RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
- SQLFactory sqlFactory2 = new SQLFactory(new promotion(new JSONObject()), "促销方案列表查询(触发的促销方案)");
- sqlFactory2.addParameter("siteid", siteid);
- sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
- RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
- ListIterator<Row> iterator = activityrows.listIterator();
- while (iterator.hasNext()) {
- Row activityrow = iterator.next();
- if(activityrow.getLong("sa_openpromotionid")!=0){
- if(sumAmountRowsMap.containsKey(activityrow.getString("sa_promotionid"))){
- BigDecimal sumamount = sumAmountRowsMap.get(activityrow.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
- if(sumamount.compareTo(activityrow.getBigDecimal("openamount"))>=0){
- if(openPromotionsRowsMap.containsKey(activityrow.getString("sa_openpromotionid"))){
- iterator.add(openPromotionsRowsMap.get(activityrow.getString("sa_openpromotionid")).get(0));
- }
- }
- }
- }
- }
- SQLFactory promotionsqlFactory = new SQLFactory(this, "查询商品所在有效活动", pageSize, pageNumber, pageSorting);
- promotionsqlFactory.addParameter("itemno", itemno);
- promotionsqlFactory.addParameter_in("sa_promotionids", activityrows.toArray("sa_promotionid"));
- promotionsqlFactory.addParameter("siteid", siteid);
- Rows promotionrows = dbConnect.runSqlQuery(promotionsqlFactory.getSQL());
- row.put("canuseactivity",promotionrows);
- }else{
- row.put("canuseactivity",new Rows());
- }
- }
- ArrayList<Long> ids = itemrows.toArrayList("itemid", new ArrayList<>());
- //默认商品图片
- Rows defaultImageRows = Item.getItemdefaultImage(this);
- // 封面cover
- RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
- // 附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- Rows rowsitemclass = dbConnect.runSqlQuery(
- " 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='"
- + siteid + "'");
- RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
- // 货品档案领域
- Rows rowstradefield = dbConnect.runSqlQuery(
- " select t6.itemid,t6.tradefield from plm_item_tradefield t6 where t6.siteid='" + siteid + "'");
- RowsMap tradefieldRowsMap = rowstradefield.toRowsMap("itemid");
- // 品牌
- Rows rowsbrand = dbConnect.runSqlQuery(
- " 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='"
- + siteid + "'");
- RowsMap brandRowsMap = rowsbrand.toRowsMap("itemid");
- for (Row row : itemrows) {
- Rows coverRows = coverRowsMap.get(row.getString("itemid"));
- if (coverRows.isEmpty()) {
- row.put("cover", "");
- } else {
- row.put("cover", coverRows.get(0).getString("url"));
- }
- if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
- row.put("attinfos", defaultImageRows);
- } else {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- }
- row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
- row.put("tradefield", tradefieldRowsMap.get(row.getString("itemid")));
- row.put("brand", brandRowsMap.get(row.getString("itemid")));
- }
- JSONObject oject = new JSONObject();
- oject.put("customschemeItems", customschemeItems.toJsonArray());
- if(customschemeItems.size()==1){
- if(customschemeItems.get(0).getString("value").equals("color")){
- RowsMap rowsMap = rowsall.toRowsMap("color");
- for (parm parm : colorList) {
- if(rowsMap.containsKey(parm.getParm())){
- parm.setDelistingstatus(rowsMap.get(parm.getParm()).get(0).getString("delistingstatus"));
- }
- }
- }
- if(customschemeItems.get(0).getString("value").equals("spec")){
- RowsMap rowsMap = rowsall.toRowsMap("spec");
- for (parm parm : specList) {
- if(rowsMap.containsKey(parm.getParm())) {
- parm.setDelistingstatus(rowsMap.get(parm.getParm()).get(0).getString("delistingstatus"));
- }
- }
- }
- if(customschemeItems.get(0).getString("value").equals("material")){
- RowsMap rowsMap = rowsall.toRowsMap("material");
- for (parm parm : materialList) {
- if(rowsMap.containsKey(parm.getParm())) {
- parm.setDelistingstatus(rowsMap.get(parm.getParm()).get(0).getString("delistingstatus"));
- }
- }
- }
- if(customschemeItems.get(0).getString("value").equals("cheek")){
- RowsMap rowsMap = rowsall.toRowsMap("cheek");
- for (parm parm : cheekList) {
- if(rowsMap.containsKey(parm.getParm())) {
- parm.setDelistingstatus(rowsMap.get(parm.getParm()).get(0).getString("delistingstatus"));
- }
- }
- }
- }
- oject.put("colorRows", colorList);
- oject.put("specRows", specList);
- oject.put("materialRows", materialList);
- oject.put("cheekRows", cheekList);
- oject.put("rows", rows);
- oject.put("item", itemrows);
- return getSucReturnObject().setData(oject).toString();
- }
- /**
- * 按照JSONArray中的对象的某个字段进行排序(采用fastJson)
- *
- * @param jsonArrayStr json数组字符串
- * @param sortkeyname 根据哪个字段进行排序
- * @param order 倒序:0;非0顺序
- * @return 排序后的jsonarray
- */
- public JSONArray jsonArraySortByField(String jsonArrayStr, String sortkeyname, String order) throws YosException {
- JSONArray sortedJsonArray = new JSONArray();
- try {
- JSONArray jsonArray = JSON.parseArray(jsonArrayStr);
- List<JSONObject> jsonList = new ArrayList<JSONObject>();
- for (int i = 0; i < jsonArray.size(); i++) {
- jsonList.add(jsonArray.getJSONObject(i));
- }
- Collections.sort(jsonList, new Comparator<JSONObject>() {
- @Override
- public int compare(JSONObject a, JSONObject b) {
- String strA = new String();
- String strB = new String();
- String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\-_\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
- String aStr = a.getStringValue(sortkeyname);
- strA = aStr.replaceAll(regEx, "");
- String bStr = b.getStringValue(sortkeyname);
- strB = bStr.replaceAll(regEx, "");
- if ("0".equals(order)) {
- return -strA.compareTo(strB);
- } else {
- return strA.compareTo(strB);
- }
- }
- });
- for (int i = 0; i < jsonArray.size(); i++) {
- sortedJsonArray.add(jsonList.get(i));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return sortedJsonArray;
- }
- }
|