package restcontroller.webmanage.saletool.sharematerial; import beans.attachment.Attachment; import beans.datacontrllog.DataContrlLog; import beans.itemclass.ItemClass; import beans.parameter.Parameter; 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 restcontroller.webmanage.saletool.fad.FadHelper; import java.util.ArrayList; /** * 效果图管理 */ public class Renderings extends Controller { /** * 构造函数 * * @param content */ public Renderings(JSONObject content) throws YosException { super(content); } String sat_sharematerial = "sat_sharematerial"; @API(title = "效果图新增或编辑", apiversion = R.ID20240415164202.v1.class) public String insertOrUpdate() throws YosException { Long sat_sharematerialid = content.getLongValue("sat_sharematerialid"); if (sat_sharematerialid <= 0) { sat_sharematerialid = createTableID(sat_sharematerial); InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial); sqlFactory.setSiteid(siteid); sqlFactory.setUniqueid(sat_sharematerialid); sqlFactory.setValue("classid", 4); sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid); sqlFactory.setValue("title", content.getStringValue("title")); sqlFactory.setValue("subtitle", content.getStringValue("subtitle")); sqlFactory.setValue("notes", content.getStringValue("notes")); sqlFactory.setValue("panoramaurl", content.getStringValue("panoramaurl", true)); sqlFactory.setValue("renderingstype", content.getStringValue("renderingstype")); sqlFactory.setValue("renderingsclass", content.getJSONObject("renderingsclass")); sqlFactory.setValue("isapplet", content.getBooleanValue("isapplet")); sqlFactory.setValue("isbussinesspic", content.getBooleanValue("isbussinesspic")); sqlFactory.setValue("sequence", content.getLongValue("sequence")); sqlFactory.setValue("readcount_start", content.getLongValue("readcount_start")); sqlFactory.insert(); content.put("sat_sharematerialid", sat_sharematerialid); DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "新建", "新建效果图 " + content.getStringValue("title")).insert(); } else { UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sat_sharematerial); sqlFactory.setUniqueid(sat_sharematerialid); sqlFactory.setSiteid(siteid); sqlFactory.setValue("title", content.getStringValue("title")); sqlFactory.setValue("subtitle", content.getStringValue("subtitle")); sqlFactory.setValue("notes", content.getStringValue("notes")); sqlFactory.setValue("panoramaurl", content.getStringValue("panoramaurl", true)); sqlFactory.setValue("renderingstype", content.getStringValue("renderingstype")); sqlFactory.setValue("renderingsclass", content.getJSONObject("renderingsclass")); sqlFactory.setValue("isapplet", content.getBooleanValue("isapplet")); sqlFactory.setValue("isbussinesspic", content.getBooleanValue("isbussinesspic")); sqlFactory.setValue("sequence", content.getLongValue("sequence")); sqlFactory.setValue("readcount_start", content.getLongValue("readcount_start")); sqlFactory.update(); DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "编辑", "编辑效果图 " + content.getStringValue("title")).insert(); } Row row = new Row(); row.put("sat_sharematerialid", sat_sharematerialid); return getSucReturnObject().setData(row).toString(); } @API(title = "效果图详情", apiversion = R.ID20240415164302.v1.class, accesstoken = false) public String detail() throws YosException { Long sat_sharematerialid = content.getLongValue("sat_sharematerialid"); String ownertable = "sat_sharematerial"; Rows sharematerialrows = dbConnect.runSqlQuery("select * from sat_sharematerial where sat_sharematerialid=" + sat_sharematerialid); if (sharematerialrows.isNotEmpty()) { siteid = sharematerialrows.get(0).getString("siteid"); } dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET readcount=readcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid); QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial") .setTableAlias("t1"); querySQ.addJoinTable(JOINTYPE.left, "sys_datacollect", "t2", "t2.siteid=t1.siteid and t2.ownertable='sat_sharematerial' and t2.type=1 and t2.ownerid=t1.sat_sharematerialid and t2.userid='" + userid + "'"); querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END"); querySQ.setWhere("sat_sharematerialid", sat_sharematerialid); Rows rows = querySQ.query(); Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row(); Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid); attRows.sortby("sequence", "linksid"); detailRow.put("attinfos", attRows); detailRow.putIfAbsent("checkdate", ""); detailRow.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + sat_sharematerialid); if (StringUtils.isBlank(detailRow.getString("panoramaurl"))) { detailRow.put("ispanorama", 0); } else { detailRow.put("ispanorama", 1); } if (detailRow.getString("title").equals("")) { detailRow.put("title", detailRow.getString("title_c")); } QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1"); attachmentQuery.setSiteid(detailRow.getString("siteid")); attachmentQuery.setWhere("ownertable", ownertable); attachmentQuery.setWhere("ownerid", sat_sharematerialid); attachmentQuery.setWhere("usetype", ownertable); attachmentQuery.setOrderBy("t1.sequence,t1.linksid"); Rows attachmentRows = attachmentQuery.query(); ArrayList 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); return getSucReturnObject().setData(detailRow).toString(); } @API(title = "效果图列表", apiversion = R.ID20240415164402.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.title like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) { where.append(" and ("); where.append("t1.status ='").append(whereObject.getString("status")).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") && !"".equals(whereObject.getString("begindate"))) { where.append(" and ("); where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' "); where.append(")"); } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where.append(" and ("); where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' "); where.append(")"); } if (whereObject.containsKey("ispanorama") && !"".equals(whereObject.getString("ispanorama"))) { if (whereObject.getString("ispanorama").equals("1")) { where.append(" and ("); where.append("LENGTH(t1.panoramaurl)>0 "); where.append(")"); } else { where.append(" and ("); where.append("LENGTH(t1.panoramaurl)=0 or t1.panoramaurl is null "); where.append(")"); } } if (whereObject.containsKey("renderingstype") && !"".equals(whereObject.getString("renderingstype"))) { where.append(" and ("); where.append("t1.renderingstype ='").append(whereObject.getString("renderingstype")).append("' "); where.append(")"); } if (whereObject.containsKey("style") && !"".equals(whereObject.getString("style"))) { where.append(" and ("); where.append("JSON_CONTAINS(t1.renderingsclass->'$.style', '\"" + whereObject.getString("style") + "\"')"); where.append(")"); } if (whereObject.containsKey("space") && !"".equals(whereObject.getString("space"))) { where.append(" and ("); where.append("JSON_CONTAINS(t1.renderingsclass->'$.space', '\"" + whereObject.getString("space") + "\"')"); where.append(")"); } if (whereObject.containsKey("spec") && !"".equals(whereObject.getString("spec"))) { where.append(" and ("); where.append("JSON_CONTAINS(t1.renderingsclass->'$.spec', '\"" + whereObject.getString("spec") + "\"')"); where.append(")"); } if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) { if (whereObject.getString("iscollect").equals("1")) { where.append(" and ("); where.append(" t1.sat_sharematerialid in (SELECT ownerid from sys_datacollect WHERE ownertable='sat_sharematerial' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")"); where.append(")"); } } } QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial, "sat_sharematerialid", "title", "status", "renderingstype", "readcount", "readcount_start", "sequence", "createdate", "checkdate", "renderingsclass", "panoramaurl") .setTableAlias("t1"); sqlFactory.setSiteid(siteid); sqlFactory.setWhere("classid", 4); sqlFactory.setWhere(where.toString()); sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber); Rows rows = sqlFactory.query(); ArrayList ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>()); // 附件 RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids); for (Row row : rows) { Rows Rows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()); row.put("attinfos", Rows); row.putIfAbsent("checkdate", ""); if (StringUtils.isBlank(row.getString("panoramaurl"))) { row.put("ispanorama", 0); } else { row.put("ispanorama", 1); } row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + row.getString("sat_sharematerialid")); } return getSucReturnObject().setData(rows).toString(); } @API(title = "选择单品列表", apiversion = R.ID20240419135702.v1.class) public String chooseFadList() 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(")"); } } Long sat_sharematerialid = content.getLongValue("sat_sharematerialid"); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad" , "sa_fadid", "name", "model", "spec", "price", "onsaledate"); querySQL.setTableAlias("t1"); querySQL.setWhere("t1.siteid", siteid); querySQL.setWhere(where.toString()); querySQL.setWhere("not exists(select 1 from sat_sharematerial_link where sat_sharematerialid=" + sat_sharematerialid + " and sa_fadid=t1.sa_fadid and siteid='" + siteid + "' )"); querySQL.setOrderBy(pageSorting); querySQL.setPage(pageSize, pageNumber); Rows rows = querySQL.query(); ArrayList ids = rows.toArrayList("sa_fadid", new ArrayList<>()); // 附件 RowsMap RowsMap = getAttachmentUrl("sa_fad", ids); for (Row row : rows) { Rows Rows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows()); row.put("attinfos", Rows); row.putIfAbsent("onsaledate", ""); } return getSucReturnObject().setData(rows).toString(); } @API(title = "关联单品列表", apiversion = R.ID20240419135802.v1.class) public String relateFadList() 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(")"); } } Long sat_sharematerialid = content.getLongValue("sat_sharematerialid"); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad" , "sa_fadid", "name", "model", "spec", "price", "onsaledate"); querySQL.addJoinTable(JOINTYPE.inner, "sat_sharematerial_link", "t2", "t2.sa_fadid=t1.sa_fadid", "sat_sharematerial_linkid"); querySQL.setTableAlias("t1"); querySQL.setWhere("t2.sat_sharematerialid", sat_sharematerialid); querySQL.setWhere("t1.siteid", siteid); querySQL.setWhere(where.toString()); querySQL.setOrderBy(pageSorting); querySQL.setPage(pageSize, pageNumber); Rows rows = querySQL.query(); ArrayList ids = rows.toArrayList("sa_fadid", new ArrayList<>()); // 附件 RowsMap RowsMap = getAttachmentUrl("sa_fad", ids); for (Row row : rows) { Rows Rows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows()); row.put("attinfos", Rows); row.putIfAbsent("onsaledate", ""); } return getSucReturnObject().setData(rows).toString(); } @API(title = "关联单品", apiversion = R.ID20240419135902.v1.class) public String relateFad() throws YosException { Long sat_sharematerialid = content.getLongValue("sat_sharematerialid"); JSONArray sa_fadids = content.getJSONArray("sa_fadids"); ArrayList sqlList = new ArrayList<>(); for (Object obj : sa_fadids) { InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_link"); insertSQL.setSiteid(siteid); insertSQL.setUniqueid(createTableID("sat_sharematerial_link")); insertSQL.setValue("sa_fadid", obj); insertSQL.setValue("sat_sharematerialid", sat_sharematerialid); sqlList.add(insertSQL.getSQL()); } dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "删除单品", apiversion = R.ID20240419136002.v1.class) public String deleteFad() throws YosException { JSONArray sat_sharematerial_linkids = content.getJSONArray("sat_sharematerial_linkids"); DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sat_sharematerial_link"); deleteSQL.setSiteid(siteid); deleteSQL.setWhere("sat_sharematerial_linkid", sat_sharematerial_linkids); deleteSQL.delete(); return getSucReturnObject().toString(); } @API(title = "选择产品(单品,效果图,设计实景图)", apiversion = R.ID20240420095702.v1.class) public String getFadUrl() throws YosException { int type = content.getIntValue("type"); 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("); if (type == 3) { where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' "); } else { where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' "); } where.append(")"); } } QuerySQL querySQL = null; //单品 if (type == 1) { querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial" , "sat_sharematerialid", "title").setTableAlias("t1"); querySQL.setWhere("classid", 4); querySQL.setWhere("status='发布'"); } else if (type == 2) { querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial" , "sat_sharematerialid", "title").setTableAlias("t1"); querySQL.setWhere("classid", 5); querySQL.setWhere("status='发布'"); } else { querySQL = SQLFactory.createQuerySQL(this, "sa_fad" , "sa_fadid").setTableAlias("t1"); querySQL.addQueryFields("title", "name"); querySQL.setWhere("isonsale=1"); } querySQL.setWhere(where.toString()); querySQL.setSiteid(siteid); querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting); Rows rows = querySQL.query(); RowsMap rowsMap; if (type == 3) { rowsMap = getAttachmentUrl("sa_fad", rows.toArrayList("sa_fadid", new ArrayList<>()), "sa_fad"); } else { rowsMap = getAttachmentUrl("sat_sharematerial", rows.toArrayList("sat_sharematerialid", new ArrayList<>()), "sat_sharematerial"); } for (Row row : rows) { if (type == 1) { row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + row.getString("sat_sharematerialid")); Rows Rows = rowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()); row.put("attinfos", Rows); } if (type == 2) { row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "DesignImgsUrl") + row.getString("sat_sharematerialid")); Rows Rows = rowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()); row.put("attinfos", Rows); } if (type == 3) { row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadUrl") + row.getString("sa_fadid")); Rows Rows = rowsMap.getOrDefault(row.getString("sa_fadid"), new Rows()); row.put("attinfos", Rows); } } return getSucReturnObject().setData(rows).toString(); } }