Renderings.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. package restcontroller.webmanage.saletool.sharematerial;
  2. import beans.attachment.Attachment;
  3. import beans.datacontrllog.DataContrlLog;
  4. import beans.itemclass.ItemClass;
  5. import beans.parameter.Parameter;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import common.Controller;
  9. import common.YosException;
  10. import common.annotation.API;
  11. import common.data.*;
  12. import org.apache.commons.lang.StringUtils;
  13. import restcontroller.R;
  14. import restcontroller.webmanage.saletool.fad.FadHelper;
  15. import java.util.ArrayList;
  16. /**
  17. * 效果图管理
  18. */
  19. public class Renderings extends Controller {
  20. /**
  21. * 构造函数
  22. *
  23. * @param content
  24. */
  25. public Renderings(JSONObject content) throws YosException {
  26. super(content);
  27. }
  28. String sat_sharematerial = "sat_sharematerial";
  29. @API(title = "效果图新增或编辑", apiversion = R.ID20240415164202.v1.class)
  30. public String insertOrUpdate() throws YosException {
  31. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  32. if (sat_sharematerialid <= 0) {
  33. sat_sharematerialid = createTableID(sat_sharematerial);
  34. InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial);
  35. sqlFactory.setSiteid(siteid);
  36. sqlFactory.setUniqueid(sat_sharematerialid);
  37. sqlFactory.setValue("classid", 4);
  38. sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
  39. sqlFactory.setValue("title", content.getStringValue("title"));
  40. sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
  41. sqlFactory.setValue("notes", content.getStringValue("notes"));
  42. sqlFactory.setValue("panoramaurl", content.getStringValue("panoramaurl", true));
  43. sqlFactory.setValue("renderingstype", content.getStringValue("renderingstype"));
  44. sqlFactory.setValue("renderingsclass", content.getJSONObject("renderingsclass"));
  45. sqlFactory.setValue("isapplet", content.getBooleanValue("isapplet"));
  46. sqlFactory.setValue("isbussinesspic", content.getBooleanValue("isbussinesspic"));
  47. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  48. sqlFactory.setValue("readcount_start", content.getLongValue("readcount_start"));
  49. sqlFactory.insert();
  50. content.put("sat_sharematerialid", sat_sharematerialid);
  51. DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "新建", "新建效果图 " + content.getStringValue("title")).insert();
  52. } else {
  53. UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sat_sharematerial);
  54. sqlFactory.setUniqueid(sat_sharematerialid);
  55. sqlFactory.setSiteid(siteid);
  56. sqlFactory.setValue("title", content.getStringValue("title"));
  57. sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
  58. sqlFactory.setValue("notes", content.getStringValue("notes"));
  59. sqlFactory.setValue("panoramaurl", content.getStringValue("panoramaurl", true));
  60. sqlFactory.setValue("renderingstype", content.getStringValue("renderingstype"));
  61. sqlFactory.setValue("renderingsclass", content.getJSONObject("renderingsclass"));
  62. sqlFactory.setValue("isapplet", content.getBooleanValue("isapplet"));
  63. sqlFactory.setValue("isbussinesspic", content.getBooleanValue("isbussinesspic"));
  64. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  65. sqlFactory.setValue("readcount_start", content.getLongValue("readcount_start"));
  66. sqlFactory.update();
  67. DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "编辑", "编辑效果图 " + content.getStringValue("title")).insert();
  68. }
  69. Row row = new Row();
  70. row.put("sat_sharematerialid", sat_sharematerialid);
  71. return getSucReturnObject().setData(row).toString();
  72. }
  73. @API(title = "效果图详情", apiversion = R.ID20240415164302.v1.class, accesstoken = false)
  74. public String detail() throws YosException {
  75. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  76. String ownertable = "sat_sharematerial";
  77. Rows sharematerialrows = dbConnect.runSqlQuery("select * from sat_sharematerial where sat_sharematerialid=" + sat_sharematerialid);
  78. if (sharematerialrows.isNotEmpty()) {
  79. siteid = sharematerialrows.get(0).getString("siteid");
  80. }
  81. dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET readcount=readcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid);
  82. QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial")
  83. .setTableAlias("t1");
  84. 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 + "'");
  85. querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END");
  86. querySQ.setWhere("sat_sharematerialid", sat_sharematerialid);
  87. Rows rows = querySQ.query();
  88. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  89. Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
  90. attRows.sortby("sequence", "linksid");
  91. detailRow.put("attinfos", attRows);
  92. detailRow.putIfAbsent("checkdate", "");
  93. detailRow.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + sat_sharematerialid);
  94. if (StringUtils.isBlank(detailRow.getString("panoramaurl"))) {
  95. detailRow.put("ispanorama", 0);
  96. } else {
  97. detailRow.put("ispanorama", 1);
  98. }
  99. if (detailRow.getString("title").equals("")) {
  100. detailRow.put("title", detailRow.getString("title_c"));
  101. }
  102. QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
  103. attachmentQuery.setSiteid(detailRow.getString("siteid"));
  104. attachmentQuery.setWhere("ownertable", ownertable);
  105. attachmentQuery.setWhere("ownerid", sat_sharematerialid);
  106. attachmentQuery.setWhere("usetype", ownertable);
  107. attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
  108. Rows attachmentRows = attachmentQuery.query();
  109. ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
  110. RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
  111. for (Row row : attachmentRows) {
  112. Rows attPicRows = new Rows();
  113. Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
  114. for (Row tempAttRow : tempAttRows) {
  115. // if (tempAttRow.getString("usetype").equals(ownertable)) {
  116. attPicRows.add(tempAttRow);
  117. // }
  118. }
  119. row.put("attinfos", attPicRows);
  120. }
  121. detailRow.put("attinfos_pic", attachmentRows);
  122. return getSucReturnObject().setData(detailRow).toString();
  123. }
  124. @API(title = "效果图列表", apiversion = R.ID20240415164402.v1.class)
  125. public String list() throws YosException {
  126. /*
  127. 过滤条件设置
  128. */
  129. StringBuffer where = new StringBuffer(" 1=1 ");
  130. if (content.containsKey("where")) {
  131. JSONObject whereObject = content.getJSONObject("where");
  132. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  133. where.append(" and (");
  134. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  135. where.append(")");
  136. }
  137. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  138. where.append(" and (");
  139. where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
  140. where.append(")");
  141. }
  142. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  143. where.append(" and (");
  144. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  145. where.append(")");
  146. }
  147. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  148. where.append(" and (");
  149. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  150. where.append(")");
  151. }
  152. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  153. where.append(" and (");
  154. where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
  155. where.append(")");
  156. }
  157. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  158. where.append(" and (");
  159. where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  160. where.append(")");
  161. }
  162. if (whereObject.containsKey("ispanorama") && !"".equals(whereObject.getString("ispanorama"))) {
  163. if (whereObject.getString("ispanorama").equals("1")) {
  164. where.append(" and (");
  165. where.append("LENGTH(t1.panoramaurl)>0 ");
  166. where.append(")");
  167. } else {
  168. where.append(" and (");
  169. where.append("LENGTH(t1.panoramaurl)=0 or t1.panoramaurl is null ");
  170. where.append(")");
  171. }
  172. }
  173. if (whereObject.containsKey("renderingstype") && !"".equals(whereObject.getString("renderingstype"))) {
  174. where.append(" and (");
  175. where.append("t1.renderingstype ='").append(whereObject.getString("renderingstype")).append("' ");
  176. where.append(")");
  177. }
  178. if (whereObject.containsKey("style") && !"".equals(whereObject.getString("style"))) {
  179. where.append(" and (");
  180. where.append("JSON_CONTAINS(t1.renderingsclass->'$.style', '\"" + whereObject.getString("style") + "\"')");
  181. where.append(")");
  182. }
  183. if (whereObject.containsKey("space") && !"".equals(whereObject.getString("space"))) {
  184. where.append(" and (");
  185. where.append("JSON_CONTAINS(t1.renderingsclass->'$.space', '\"" + whereObject.getString("space") + "\"')");
  186. where.append(")");
  187. }
  188. if (whereObject.containsKey("spec") && !"".equals(whereObject.getString("spec"))) {
  189. where.append(" and (");
  190. where.append("JSON_CONTAINS(t1.renderingsclass->'$.spec', '\"" + whereObject.getString("spec") + "\"')");
  191. where.append(")");
  192. }
  193. if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) {
  194. if (whereObject.getString("iscollect").equals("1")) {
  195. where.append(" and (");
  196. where.append(" t1.sat_sharematerialid in (SELECT ownerid from sys_datacollect WHERE ownertable='sat_sharematerial' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")");
  197. where.append(")");
  198. }
  199. }
  200. }
  201. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
  202. "sat_sharematerialid", "title", "status", "renderingstype", "readcount", "readcount_start", "sequence", "createdate", "checkdate", "renderingsclass", "panoramaurl")
  203. .setTableAlias("t1");
  204. sqlFactory.setSiteid(siteid);
  205. sqlFactory.setWhere("classid", 4);
  206. sqlFactory.setWhere(where.toString());
  207. sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  208. Rows rows = sqlFactory.query();
  209. ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
  210. // 附件
  211. RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids);
  212. for (Row row : rows) {
  213. Rows Rows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  214. row.put("attinfos", Rows);
  215. row.putIfAbsent("checkdate", "");
  216. if (StringUtils.isBlank(row.getString("panoramaurl"))) {
  217. row.put("ispanorama", 0);
  218. } else {
  219. row.put("ispanorama", 1);
  220. }
  221. row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + row.getString("sat_sharematerialid"));
  222. }
  223. return getSucReturnObject().setData(rows).toString();
  224. }
  225. @API(title = "选择单品列表", apiversion = R.ID20240419135702.v1.class)
  226. public String chooseFadList() throws YosException {
  227. StringBuffer where = new StringBuffer(" 1=1 ");
  228. if (content.containsKey("where")) {
  229. JSONObject whereObject = content.getJSONObject("where");
  230. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  231. where.append(" and(");
  232. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  233. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  234. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  235. where.append(")");
  236. }
  237. }
  238. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  239. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad"
  240. , "sa_fadid", "name", "model", "spec", "price", "onsaledate");
  241. querySQL.setTableAlias("t1");
  242. querySQL.setWhere("t1.siteid", siteid);
  243. querySQL.setWhere(where.toString());
  244. querySQL.setWhere("not exists(select 1 from sat_sharematerial_link where sat_sharematerialid=" + sat_sharematerialid + " and sa_fadid=t1.sa_fadid and siteid='" + siteid + "' )");
  245. querySQL.setOrderBy(pageSorting);
  246. querySQL.setPage(pageSize, pageNumber);
  247. Rows rows = querySQL.query();
  248. ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
  249. // 附件
  250. RowsMap RowsMap = getAttachmentUrl("sa_fad", ids);
  251. for (Row row : rows) {
  252. Rows Rows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
  253. row.put("attinfos", Rows);
  254. row.putIfAbsent("onsaledate", "");
  255. }
  256. return getSucReturnObject().setData(rows).toString();
  257. }
  258. @API(title = "关联单品列表", apiversion = R.ID20240419135802.v1.class)
  259. public String relateFadList() throws YosException {
  260. StringBuffer where = new StringBuffer(" 1=1 ");
  261. if (content.containsKey("where")) {
  262. JSONObject whereObject = content.getJSONObject("where");
  263. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  264. where.append(" and(");
  265. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  266. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  267. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  268. where.append(")");
  269. }
  270. }
  271. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  272. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad"
  273. , "sa_fadid", "name", "model", "spec", "price", "onsaledate");
  274. querySQL.addJoinTable(JOINTYPE.inner, "sat_sharematerial_link", "t2", "t2.sa_fadid=t1.sa_fadid", "sat_sharematerial_linkid");
  275. querySQL.setTableAlias("t1");
  276. querySQL.setWhere("t2.sat_sharematerialid", sat_sharematerialid);
  277. querySQL.setWhere("t1.siteid", siteid);
  278. querySQL.setWhere(where.toString());
  279. querySQL.setOrderBy(pageSorting);
  280. querySQL.setPage(pageSize, pageNumber);
  281. Rows rows = querySQL.query();
  282. ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
  283. // 附件
  284. RowsMap RowsMap = getAttachmentUrl("sa_fad", ids);
  285. for (Row row : rows) {
  286. Rows Rows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
  287. row.put("attinfos", Rows);
  288. row.putIfAbsent("onsaledate", "");
  289. }
  290. return getSucReturnObject().setData(rows).toString();
  291. }
  292. @API(title = "关联单品", apiversion = R.ID20240419135902.v1.class)
  293. public String relateFad() throws YosException {
  294. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  295. JSONArray sa_fadids = content.getJSONArray("sa_fadids");
  296. ArrayList<String> sqlList = new ArrayList<>();
  297. for (Object obj : sa_fadids) {
  298. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_link");
  299. insertSQL.setSiteid(siteid);
  300. insertSQL.setUniqueid(createTableID("sat_sharematerial_link"));
  301. insertSQL.setValue("sa_fadid", obj);
  302. insertSQL.setValue("sat_sharematerialid", sat_sharematerialid);
  303. sqlList.add(insertSQL.getSQL());
  304. }
  305. dbConnect.runSqlUpdate(sqlList);
  306. return getSucReturnObject().toString();
  307. }
  308. @API(title = "删除单品", apiversion = R.ID20240419136002.v1.class)
  309. public String deleteFad() throws YosException {
  310. JSONArray sat_sharematerial_linkids = content.getJSONArray("sat_sharematerial_linkids");
  311. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sat_sharematerial_link");
  312. deleteSQL.setSiteid(siteid);
  313. deleteSQL.setWhere("sat_sharematerial_linkid", sat_sharematerial_linkids);
  314. deleteSQL.delete();
  315. return getSucReturnObject().toString();
  316. }
  317. @API(title = "选择产品(单品,效果图,设计实景图)", apiversion = R.ID20240420095702.v1.class)
  318. public String getFadUrl() throws YosException {
  319. int type = content.getIntValue("type");
  320. StringBuffer where = new StringBuffer(" 1=1 ");
  321. if (content.containsKey("where")) {
  322. JSONObject whereObject = content.getJSONObject("where");
  323. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  324. where.append(" and(");
  325. if (type == 3) {
  326. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  327. } else {
  328. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  329. }
  330. where.append(")");
  331. }
  332. }
  333. QuerySQL querySQL = null;
  334. //单品
  335. if (type == 1) {
  336. querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial"
  337. , "sat_sharematerialid", "title").setTableAlias("t1");
  338. querySQL.setWhere("classid", 4);
  339. querySQL.setWhere("status='发布'");
  340. } else if (type == 2) {
  341. querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial"
  342. , "sat_sharematerialid", "title").setTableAlias("t1");
  343. querySQL.setWhere("classid", 5);
  344. querySQL.setWhere("status='发布'");
  345. } else {
  346. querySQL = SQLFactory.createQuerySQL(this, "sa_fad"
  347. , "sa_fadid").setTableAlias("t1");
  348. querySQL.addQueryFields("title", "name");
  349. querySQL.setWhere("isonsale=1");
  350. }
  351. querySQL.setWhere(where.toString());
  352. querySQL.setSiteid(siteid);
  353. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  354. Rows rows = querySQL.query();
  355. RowsMap rowsMap;
  356. if (type == 3) {
  357. rowsMap = getAttachmentUrl("sa_fad", rows.toArrayList("sa_fadid", new ArrayList<>()), "sa_fad");
  358. } else {
  359. rowsMap = getAttachmentUrl("sat_sharematerial", rows.toArrayList("sat_sharematerialid", new ArrayList<>()), "sat_sharematerial");
  360. }
  361. for (Row row : rows) {
  362. if (type == 1) {
  363. row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "CaseImgsUrl") + row.getString("sat_sharematerialid"));
  364. Rows Rows = rowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  365. row.put("attinfos", Rows);
  366. }
  367. if (type == 2) {
  368. row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "DesignImgsUrl") + row.getString("sat_sharematerialid"));
  369. Rows Rows = rowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  370. row.put("attinfos", Rows);
  371. }
  372. if (type == 3) {
  373. row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadUrl") + row.getString("sa_fadid"));
  374. Rows Rows = rowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
  375. row.put("attinfos", Rows);
  376. }
  377. }
  378. return getSucReturnObject().setData(rows).toString();
  379. }
  380. }