Renderings.java 20 KB

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