123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- package restcontroller.webmanage.saletool.fad;
- import beans.attachment.Attachment;
- import beans.brand.Brand;
- import beans.datacontrllog.DataContrlLog;
- import beans.itemclass.ItemClass;
- import beans.time.Time;
- import com.alibaba.excel.write.handler.RowWriteHandler;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.data.*;
- import org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import java.util.ArrayList;
- import java.util.LinkedHashSet;
- /**
- * 单品管理
- */
- public class Fad extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public Fad(JSONObject content) throws YosException {
- super(content);
- }
- String sa_fad = "sa_fad";
- @API(title = "单品新增或编辑", apiversion = R.ID20240418140902.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sa_fadid = content.getLongValue("sa_fadid");
- Long itemid = content.getLongValue("itemid");
- int isonsale = content.getIntValue("isonsale");
- JSONArray sa_fadclassids = new JSONArray();
- if (content.containsKey("sa_fadclassids")) {
- sa_fadclassids = content.getJSONArray("sa_fadclassids");
- for (Object obj : sa_fadclassids) {
- if (!(obj instanceof JSONArray)) {
- return getErrReturnObject().setErrMsg("分类格式不正确").toString();
- }
- }
- }
- String offsaledate = content.getStringValue("offsaledate", true, "null");
- boolean isstop = true;
- if (offsaledate.equals("null")) {
- isstop = false;
- }
- if (sa_fadid <= 0) {
- sa_fadid = createTableID(sa_fad);
- InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sa_fad);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setUniqueid(sa_fadid);
- sqlFactory.setValue("name", content.getStringValue("name"));
- sqlFactory.setValue("model", content.getStringValue("model"));
- sqlFactory.setValue("spec", content.getStringValue("spec"));
- sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
- sqlFactory.setValue("outurl", content.getStringValue("outurl", true));
- sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
- sqlFactory.setValue("sequence", content.getLongValue("sequence"));
- sqlFactory.setValue("content", content.getStringValue("contentstr", true));
- sqlFactory.setValue("price", content.getBigDecimalValue("price"));
- sqlFactory.setValue("offsaledate", offsaledate);
- sqlFactory.setValue("sa_fadclassids", sa_fadclassids);
- sqlFactory.setValue("classid", 1);
- sqlFactory.setValue("isstop", isstop);
- sqlFactory.insert();
- content.put("sa_fadid", sa_fadid);
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "新建", "新建单品 " + content.getString("name")).insert();
- } else {
- UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sa_fad);
- sqlFactory.setUniqueid(sa_fadid);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setValue("name", content.getStringValue("name"));
- sqlFactory.setValue("model", content.getStringValue("model"));
- sqlFactory.setValue("spec", content.getStringValue("spec"));
- sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
- sqlFactory.setValue("outurl", content.getStringValue("outurl", true));
- sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
- sqlFactory.setValue("sequence", content.getLongValue("sequence"));
- sqlFactory.setValue("content", content.getStringValue("contentstr", true));
- sqlFactory.setValue("price", content.getBigDecimalValue("price"));
- sqlFactory.setValue("offsaledate", offsaledate);
- sqlFactory.setValue("sa_fadclassids", sa_fadclassids);
- sqlFactory.setValue("isstop", isstop);
- sqlFactory.update();
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "编辑", "编辑单品 " + content.getString("name")).insert();
- }
- //上下架
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
- updateSQL.setSiteid(siteid);
- updateSQL.setWhere("sa_fadid", sa_fadid);
- updateSQL.setValue("isonsale", isonsale);
- updateSQL.setValue("onsaledate", isonsale == 1 ? Time.getDateTime_Str() : "null");
- updateSQL.setValue("onsaleby", isonsale == 1 ? username : "null");
- updateSQL.update();
- //关联商品
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fad_link");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sa_fad_link"));
- insertSQL.setValue("itemid", itemid);
- insertSQL.setValue("sa_fadid", sa_fadid);
- insertSQL.setWhere("not exists(select 1 from sa_fad_link where itemid=" + itemid + " and sa_fadid=" + sa_fadid + " )");
- insertSQL.insert();
- //插入图片
- Rows rows = Attachment.get(this, "plm_item", itemid, "cover");
- if (rows.isEmpty()) {
- rows = Attachment.get(this, "plm_item", itemid, "default");
- }
- if (rows.isNotEmpty()) {
- insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sys_attachment_links"));
- insertSQL.setValue("usetype", sa_fad);
- insertSQL.setValue("attachmentid", rows.get(0).getLong("attachmentid"));
- insertSQL.setValue("sequence", 1);
- insertSQL.setValue("ownertable", sa_fad);
- insertSQL.setValue("ownerid", sa_fadid);
- insertSQL.setWhere("not exists(select 1 from sys_attachment_links where attachmentid=" + rows.get(0).getLong("attachmentid") + " and ownertable='sa_fad' and siteid='" + siteid + "' and ownerid=" + sa_fadid + " )");
- insertSQL.insert();
- }
- Row row = new Row();
- row.put("sa_fadid", sa_fadid);
- return getSucReturnObject().setData(row).toString();
- }
- @API(title = "单品详情", apiversion = R.ID20240418141002.v1.class, accesstoken = false)
- public String detail() throws YosException {
- Long sa_fadid = content.getLongValue("sa_fadid");
- String ownertable = sa_fad;
- Rows fadrows = dbConnect.runSqlQuery("select * from sa_fad where sa_fadid=" + sa_fadid);
- if (fadrows.isNotEmpty()) {
- siteid = fadrows.get(0).getString("siteid");
- }
- dbConnect.runSqlUpdate("UPDATE sa_fad SET readcount=readcount+1 WHERE sa_fadid=" + sa_fadid);
- QuerySQL querySQ = SQLFactory.createQuerySQL(this, sa_fad)
- .setTableAlias("t1");
- querySQ.addJoinTable(JOINTYPE.left, "sys_datacollect", "t2", "t2.siteid=t1.siteid and t2.ownertable='sa_fad' and t2.type=1 and t2.ownerid=t1.sa_fadid and t2.userid='" + userid + "'");
- querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END");
- querySQ.setSiteid(siteid);
- querySQ.setWhere("sa_fadid", sa_fadid);
- Rows rows = querySQ.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- Rows attRows = getAttachmentUrl(sa_fad, sa_fadid);
- attRows.sortby("sequence", "linksid");
- detailRow.put("attinfos", attRows);
- detailRow.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadUrl") + sa_fadid);
- QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
- attachmentQuery.setSiteid(detailRow.getString("siteid"));
- attachmentQuery.setWhere("ownertable", ownertable);
- attachmentQuery.setWhere("ownerid", sa_fadid);
- attachmentQuery.setWhere("usetype", ownertable);
- attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
- Rows attachmentRows = attachmentQuery.query();
- ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
- RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- for (Row row : attachmentRows) {
- Rows attPicRows = new Rows();
- Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
- for (Row tempAttRow : tempAttRows) {
- // if (tempAttRow.getString("usetype").equals(ownertable)) {
- attPicRows.add(tempAttRow);
- // }
- }
- row.put("attinfos", attPicRows);
- }
- detailRow.put("attinfos_pic", attachmentRows);
- detailRow.putIfAbsent("offsaledate", "");
- detailRow.putIfAbsent("onsaledate", "");
- detailRow.put("classnames", getClassnames(detailRow.getJSONArray("sa_fadclassids"), false));
- detailRow.put("mainclassnames", getClassnames(detailRow.getJSONArray("sa_fadclassids"), true));
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "单品删除", apiversion = R.ID20240418141102.v1.class)
- public String delete() throws YosException {
- JSONArray sa_fadids = content.getJSONArray("sa_fadids");
- if (sa_fadids.size() == 0) {
- return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
- }
- DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sa_fad);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("sa_fadid", sa_fadids.toArray());
- sqlFactory.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "单品上下架", apiversion = R.ID20240418141202.v1.class)
- public String isonsale() throws YosException {
- JSONArray sa_fadids = content.getJSONArray("sa_fadids");
- int isonsale = content.getIntValue("isonsale");
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
- updateSQL.setSiteid(siteid);
- updateSQL.setWhere("sa_fadid", sa_fadids);
- updateSQL.setValue("isonsale", isonsale);
- updateSQL.setValue("onsaledate", isonsale == 0 ? "null" : Time.getDateTime_Str());
- updateSQL.setValue("onsaleby", isonsale == 0 ? "null" : username);
- updateSQL.update();
- //操作记录
- for (Object object : sa_fadids) {
- long sa_fadid = Long.parseLong(object.toString());
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + sa_fadid);
- if (isonsale == 0) {
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "下架", "下架单品 " + row.getString("name")).insert();
- } else {
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "上架", "上架单品 " + row.getString("name")).insert();
- }
- }
- return getSucReturnObject().toString();
- }
- @API(title = "单品列表", apiversion = R.ID20240418141302.v1.class)
- public String list() throws YosException {
- /*
- 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and (");
- where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
- where.append(" and (");
- where.append("t1.isonsale ='").append(whereObject.getString("isonsale")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("isstop") && !"".equals(whereObject.getString("isstop"))) {
- where.append(" and (");
- where.append("t1.isstop ='").append(whereObject.getString("isstop")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
- where.append(" and (");
- where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
- where.append(" and (");
- where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_onsale") && !"".equals(whereObject.getString("begindate_onsale"))) {
- where.append(" and (");
- where.append("t1.onsaledate >='").append(whereObject.getString("begindate_onsale")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_onsale") && !"".equals(whereObject.getString("enddate_onsale"))) {
- where.append(" and (");
- where.append("t1.onsaledate <='").append(whereObject.getString("enddate_onsale")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("sa_fadclassids") && !"".equals(whereObject.getString("sa_fadclassids"))) {
- JSONArray sa_fadclassids = whereObject.getJSONArray("sa_fadclassids");
- if (sa_fadclassids.size() > 0) {
- where.append(" and (1=2");
- for (Object obj : sa_fadclassids) {
- JSONArray array = (JSONArray) obj;
- if (array.size() > 0) {
- where.append(" or (");
- where.append("JSON_CONTAINS(t1.sa_fadclassids,'" + array.get(array.size() - 1) + "')");
- where.append(")");
- }
- }
- where.append(")");
- }
- }
- if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) {
- if (whereObject.getString("iscollect").equals("1")) {
- where.append(" and (");
- where.append(" t1.sa_fadid in (SELECT ownerid from sys_datacollect WHERE ownertable='sa_fad' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")");
- where.append(")");
- }
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "isonsale", "model", "spec", "price", "sequence", "createby", "createdate", "onsaledate", "isstop")
- .setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("classid", 1);
- querySQL.setWhere(where.toString());
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
- // 附件
- RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
- for (Row row : rows) {
- Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
- attRows.sortby("sequence", "linksid");
- row.put("attinfos", attRows);
- row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadUrl") + row.getString("sa_fadid"));
- row.putIfAbsent("onsaledate", "");
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "选择商品列表", apiversion = R.ID20240418141402.v1.class)
- public String chooseItemlist() throws YosException {
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_fadid = content.getLongValue("sa_fadid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
- , "itemid", "itemname", "itemno", "model", "spec", "color", "marketprice", "standards");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
- "itemclassname");
- querySQL.setWhere("t1.siteid", siteid);
- querySQL.setWhere(where.toString());
- querySQL.setWhere("not exists(select 1 from sa_fad_link where sa_fadid=" + sa_fadid + " and itemid=t1.itemid and siteid='" + siteid + "' )");
- querySQL.setOrderBy(pageSorting);
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- // 默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- // 附件
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- // 商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
- for (Row row : rows) {
- if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
- row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
- } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- } else {
- row.put("attinfos", defaultImageRows);
- }
- String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
- row.put("tradefield", StringUtils.join(tradefield, ","));
- String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
- row.put("itemclass", StringUtils.join(itemclass, ","));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "关联商品列表", apiversion = R.ID20240418141502.v1.class)
- public String relateItemlist() throws YosException {
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_fadid = content.getLongValue("sa_fadid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
- , "itemid", "itemname", "itemno", "model", "spec", "color", "marketprice", "standards");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
- "itemclassname");
- querySQL.addJoinTable(JOINTYPE.inner, "sa_fad_link", "t3", "t3.itemid = t1.itemid AND t3.siteid = t1.siteid",
- "sa_fad_linkid");
- querySQL.setWhere("t1.siteid", siteid);
- querySQL.setWhere(where.toString());
- querySQL.setWhere("t3.sa_fadid", sa_fadid);
- querySQL.setOrderBy(pageSorting);
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- // 默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- // 附件
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- // 商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
- for (Row row : rows) {
- if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
- row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
- } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- } else {
- row.put("attinfos", defaultImageRows);
- }
- String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
- row.put("tradefield", StringUtils.join(tradefield, ","));
- String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
- row.put("itemclass", StringUtils.join(itemclass, ","));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "关联商品", apiversion = R.ID20240418141602.v1.class)
- public String relateItem() throws YosException {
- Long sa_fadid = content.getLongValue("sa_fadid");
- JSONArray itemids = content.getJSONArray("itemids");
- ArrayList<String> sqlList = new ArrayList<>();
- for (Object obj : itemids) {
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fad_link");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sa_fad_link"));
- insertSQL.setValue("itemid", obj);
- insertSQL.setValue("sa_fadid", sa_fadid);
- sqlList.add(insertSQL.getSQL());
- Row row = dbConnect.runSqlQuery(0, "SELECT * from plm_item WHERE siteid='" + siteid + "' and itemid=" + obj);
- sqlList.add(DataContrlLog.createLog(this, "sa_fad", sa_fadid, "添加关联商品", "添加关联商品 " + row.getString("itemname")).getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "删除商品", apiversion = R.ID20240418141702.v1.class)
- public String deleteItem() throws YosException {
- JSONArray sa_fad_linkids = content.getJSONArray("sa_fad_linkids");
- for (Object obj : sa_fad_linkids) {
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sa_fad_link WHERE siteid='" + siteid + "' and sa_fad_linkid=" + obj);
- Long sa_fadid = row.getLong("sa_fadid");
- Long itemid = row.getLong("itemid");
- row = dbConnect.runSqlQuery(0, "SELECT * from plm_item WHERE siteid='" + siteid + "' and itemid=" + itemid);
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "删除关联商品", "删除关联商品 " + row.getString("itemname")).insert();
- }
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fad_link");
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("sa_fad_linkid", sa_fad_linkids);
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- public String getClassnames(JSONArray sa_fadclassids, boolean isMain) throws YosException {
- //[[1,2,3,6],[1,2]]
- RowsMap rowsMap = dbConnect.runSqlQuery("SELECT sa_fadclassid,classname from sa_fadclass WHERE siteid='" + siteid + "'").toRowsMap("sa_fadclassid");
- LinkedHashSet<String> classnames = new LinkedHashSet<>();
- for (Object object : sa_fadclassids) {
- ArrayList<String> temp = new ArrayList<>();
- if (object instanceof JSONArray) {
- JSONArray array = (JSONArray) object;
- for (Object obj : array) {
- temp.add(rowsMap.get(obj.toString()).get(0).getString("classname"));
- }
- }
- if (isMain) {
- classnames.add(temp.get(0));
- } else {
- classnames.add(String.join("-", temp));
- }
- }
- return String.join(";", classnames);
- }
- }
|