supplyanddemand.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. package com.cnd3b.restcontroller.customer.supplyanddemand;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.cnd3b.common.Controller;
  4. import com.cnd3b.common.D3bException;
  5. import com.cnd3b.common.data.Row;
  6. import com.cnd3b.common.data.Rows;
  7. import com.cnd3b.common.data.RowsMap;
  8. import com.cnd3b.common.data.SQLFactory;
  9. import p2.pao.PaoRemote;
  10. import p2.pao.PaoSetRemote;
  11. import p2.util.P2Exception;
  12. import java.util.Arrays;
  13. public class supplyanddemand extends Controller {
  14. public supplyanddemand(JSONObject content) {
  15. super(content);
  16. }
  17. /**
  18. * 供需列表查询
  19. *
  20. * @return
  21. */
  22. public String query_supplyanddemandList() {
  23. /**
  24. *排序条件设置
  25. */
  26. String[] sortfield = {"t1.tsupplyanddemandid desc"};
  27. String sort = getSort(sortfield, "t1.tsupplyanddemandid desc");
  28. /**
  29. * 过滤条件设置
  30. */
  31. StringBuffer where = new StringBuffer(" 1=1 ");
  32. if (content.containsKey("where")) {
  33. JSONObject whereObject = content.getJSONObject("where");
  34. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  35. where.append(" and(");
  36. where.append("t1.ftitle like'%").append(whereObject.getString("condition")).append("%' ");
  37. where.append(")");
  38. }
  39. if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
  40. where.append(" and t1.ftype ='").append(whereObject.getString("ftype")).append("' ");
  41. }
  42. if (whereObject.containsKey("fissupply")) {
  43. where.append(" and t1.fissupply =").append(whereObject.getBooleanValue("fissupply") ? 1 : 0);
  44. }
  45. }
  46. SQLFactory sqlFactory = new SQLFactory(this, "供需列表查询", pageSize, pageNumber, sort);
  47. sqlFactory.addParameter("siteid", siteid);
  48. sqlFactory.addParameter_SQL("where", where);
  49. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  50. RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
  51. for (Row row : rows) {
  52. row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
  53. }
  54. return getSucReturnObject().setDataByPaging(rows).saveToDataPool().toString();
  55. }
  56. /**
  57. * 供需详情查询
  58. *
  59. * @return
  60. */
  61. public String query_supplyanddemandMain() throws P2Exception {
  62. long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
  63. SQLFactory sqlFactory = new SQLFactory(this, "供需详情查询");
  64. sqlFactory.addParameter("siteid", siteid);
  65. sqlFactory.addParameter("tagentsid", tagentsid);
  66. sqlFactory.addParameter("tsupplyanddemandid", tsupplyanddemandid);
  67. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  68. RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
  69. for (Row row : rows) {
  70. row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
  71. Rows imdialogRows = dbConnect.runSqlQuery("select timdialogid from timdialog where siteid='" + siteid + "' and ownertable='tsupplyanddemand' and ownerid='" + tsupplyanddemandid + "' and tenterprise_userid=" + userid);
  72. long timdialogid;
  73. if (!imdialogRows.isEmpty()) {
  74. timdialogid = imdialogRows.get(0).getLong("timdialogid");
  75. } else {
  76. //聊天对话框不存在时,自动生成一个聊天对话框
  77. PaoSetRemote timdialogSet = getP2ServerSystemPaoSet("timdialog");
  78. PaoRemote timdialog = timdialogSet.addAtEnd();
  79. timdialog.setValue("siteid", siteid, 11L);//企业ID
  80. timdialog.setValue("createby", username, 11L);//创建人
  81. timdialog.setValue("createdate", sysdate, 11L);//创建时间
  82. timdialog.setValue("fimdialogtype", "供需", 11L);//对话框类型
  83. timdialog.setValue("ownertable", "tsupplyanddemand", 11L);//所有表
  84. timdialog.setValue("ownerid", tsupplyanddemandid, 11L);//所有表ID
  85. timdialog.setValue("tenterprise_userid", userid, 11L);//创建账号ID
  86. timdialog.setValue("fimdialogname", row.getString("ftitle"), 11L);//对话框类型
  87. timdialogid = timdialog.getUniqueIDValue();
  88. timdialogSet.save();
  89. SQLFactory addusers = new SQLFactory(this, "即时通讯群人员添加");
  90. addusers.addParameter("createby", username);
  91. addusers.addParameter("timdialogid", timdialogid);
  92. addusers.addParameter("siteid", siteid);
  93. addusers.addParameter_in("tenterprise_userid", new String[]{String.valueOf(userid), row.getString("tenterprise_userid")});
  94. dbConnect.runSqlUpdate(addusers.getSQL());
  95. }
  96. row.put("timdialogid", timdialogid);
  97. }
  98. return getSucReturnObject().setData(rows).toString();
  99. }
  100. /**
  101. * 我的供需列表查询
  102. *
  103. * @return
  104. */
  105. public String query_mysupplyanddemandList() {
  106. /**
  107. *排序条件设置
  108. */
  109. String[] sortfield = {"t1.tsupplyanddemandid desc"};
  110. String sort = getSort(sortfield, "t1.tsupplyanddemandid desc");
  111. /**
  112. * 过滤条件设置
  113. */
  114. StringBuffer where = new StringBuffer(" 1=1 ");
  115. if (content.containsKey("where")) {
  116. JSONObject whereObject = content.getJSONObject("where");
  117. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  118. where.append(" and(");
  119. where.append("t1.ftitle like'%").append(whereObject.getString("condition")).append("%' ");
  120. where.append(")");
  121. }
  122. if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
  123. where.append(" and t1.ftype ='").append(whereObject.getString("ftype")).append("' ");
  124. }
  125. if (whereObject.containsKey("fissupply")) {
  126. where.append(" and t1.fissupply =").append(whereObject.getBooleanValue("fissupply") ? 1 : 0);
  127. }
  128. }
  129. SQLFactory sqlFactory = new SQLFactory(this, "我的供需列表查询", pageSize, pageNumber, sort);
  130. sqlFactory.addParameter("siteid", siteid);
  131. sqlFactory.addParameter("tagentsid", tagentsid);
  132. sqlFactory.addParameter_SQL("where", where);
  133. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  134. RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
  135. for (Row row : rows) {
  136. row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
  137. }
  138. return getSucReturnObject().setDataByPaging(rows).saveToDataPool().toString();
  139. }
  140. /**
  141. * 我的供需详情查询
  142. *
  143. * @return
  144. */
  145. public String query_mysupplyanddemandMain() {
  146. long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
  147. SQLFactory sqlFactory = new SQLFactory(this, "我的供需详情查询");
  148. sqlFactory.addParameter("siteid", siteid);
  149. sqlFactory.addParameter("tagentsid", tagentsid);
  150. sqlFactory.addParameter("tsupplyanddemandid", tsupplyanddemandid);
  151. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  152. SQLFactory dialoglistSQL = new SQLFactory(this, "我的供需详情查询_对话框列表");
  153. dialoglistSQL.addParameter("siteid", siteid);
  154. dialoglistSQL.addParameter("tagentsid", tagentsid);
  155. dialoglistSQL.addParameter("tsupplyanddemandid", tsupplyanddemandid);
  156. dialoglistSQL.addParameter("userid", userid);
  157. Rows dialogrows = dbConnect.runSqlQuery(dialoglistSQL.getSQL());
  158. System.err.println(dialoglistSQL.getSQL());
  159. RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
  160. for (Row row : rows) {
  161. row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
  162. row.put("imdialogs", dialogrows);
  163. }
  164. return getSucReturnObject().setData(rows).toString();
  165. }
  166. /**
  167. * 新增或修改供需
  168. *
  169. * @return
  170. */
  171. public String insertormodify() throws D3bException, P2Exception {
  172. long tsupplyanddemandid = content.getLongValue("tsupplyanddemandid");//需求ID,新增时传0
  173. String ftype = content.getString("ftype");
  174. String ftitle = content.getString("ftitle", "tsupplyanddemand.ftitle", "需求标题");
  175. String fcontent = content.getString("fcontent", "tsupplyanddemand.fcontent", "需求内容");
  176. String fenddate = content.getString("fenddate");
  177. boolean fissupply = content.getBoolean("fissupply");
  178. PaoSetRemote tsupplyanddemandSet = getP2ServerSystemPaoSet("tsupplyanddemand", "siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  179. PaoRemote tsupplyanddemand = null;
  180. if (tsupplyanddemandid <= 0 || tsupplyanddemandSet.isEmpty()) {
  181. tsupplyanddemand = tsupplyanddemandSet.addAtEnd();
  182. tsupplyanddemand.setValue("siteid", siteid, 11L);//企业ID
  183. tsupplyanddemand.setValue("tagentsid", tagentsid, 11L);//企业ID
  184. tsupplyanddemand.setValue("createby", username, 11L);//录入人
  185. tsupplyanddemand.setValue("createdate", sysdate, 11L);//录入时间
  186. tsupplyanddemand.setValue("tenterprise_userid", userid, 11L);//发布人账号ID
  187. tsupplyanddemand.setValue("fissupply", fissupply, 11L);//供、需
  188. tsupplyanddemand.setValue("fstatus", "新建", 11L);//状态
  189. } else {
  190. tsupplyanddemand = tsupplyanddemandSet.getPao(0);
  191. }
  192. tsupplyanddemand.setValue("ftype", ftype, 11L);//产品名称
  193. tsupplyanddemand.setValue("ftitle", ftitle, 11L);//需求标题
  194. tsupplyanddemand.setValue("fcontent", fcontent, 11L);//需求内容
  195. tsupplyanddemand.setValue("fenddate", fenddate, 11L);//到期时间
  196. tsupplyanddemand.setValue("changeby", username, 11L);//修改人
  197. tsupplyanddemand.setValue("changedate", sysdate, 11L);//修改时间
  198. content.put("tsupplyanddemandid", tsupplyanddemand.getUniqueIDValue());
  199. tsupplyanddemandSet.save();
  200. return query_mysupplyanddemandMain();
  201. }
  202. /**
  203. * 供需状态变更
  204. *
  205. * @return
  206. */
  207. public String updatesupplyanddemandstatus() {
  208. long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
  209. String fstatus = content.getString("fstatus");
  210. Rows rows = dbConnect.runSqlQuery("select * from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  211. if (rows.isEmpty()) {
  212. return getErrReturnObject().setErrMsg("供需内容不存在").toString();
  213. }
  214. if (!Arrays.asList(new String[]{"新建", "发布", "待对接", "正在对接", "已解决", "已过期"}).contains(fstatus)) {
  215. return getErrReturnObject().setErrMsg("无效的供需状态").toString();
  216. }
  217. switch (fstatus) {
  218. case "新建": {
  219. dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='新建',checkby=null,checkdate=null where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  220. break;
  221. }
  222. case "发布": {
  223. if (!"新建".equals(rows.get(0).getString("fstatus"))) {
  224. return getErrReturnObject().setErrMsg("当前状态不可发布").toString();
  225. }
  226. dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='待对接',checkby='" + username + "',checkdate=getDate() where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  227. break;
  228. }
  229. default: {
  230. dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='" + fstatus + "' where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  231. break;
  232. }
  233. }
  234. return query_mysupplyanddemandMain();
  235. }
  236. /**
  237. * 供需删除
  238. *
  239. * @return
  240. */
  241. public String deletesupplyanddemand() {
  242. long tsupplyanddemandid = content.getLongValue("tsupplyanddemandid");
  243. Rows rows = dbConnect.runSqlQuery("select * from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  244. if (!rows.isEmpty() && !"新建".equals(rows.get(0).getString("fstatus"))) {
  245. return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
  246. }
  247. String status = dbConnect.runSqlUpdate("delete from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
  248. if ("true".equals(status)) {
  249. return getSucReturnObject().toString();
  250. } else {
  251. return getErrReturnObject().toString();
  252. }
  253. }
  254. }