|
|
@@ -0,0 +1,278 @@
|
|
|
+package com.cnd3b.restcontroller.customer.supplyanddemand;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.cnd3b.common.Controller;
|
|
|
+import com.cnd3b.common.D3bException;
|
|
|
+import com.cnd3b.common.data.Row;
|
|
|
+import com.cnd3b.common.data.Rows;
|
|
|
+import com.cnd3b.common.data.RowsMap;
|
|
|
+import com.cnd3b.common.data.SQLFactory;
|
|
|
+import p2.pao.PaoRemote;
|
|
|
+import p2.pao.PaoSetRemote;
|
|
|
+import p2.util.P2Exception;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+public class supplyanddemand extends Controller {
|
|
|
+ public supplyanddemand(JSONObject content) {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供需列表查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String query_supplyanddemandList() {
|
|
|
+ /**
|
|
|
+ *排序条件设置
|
|
|
+ */
|
|
|
+ String[] sortfield = {"t1.tsupplyanddemandid desc"};
|
|
|
+ String sort = getSort(sortfield, "t1.tsupplyanddemandid desc");
|
|
|
+ /**
|
|
|
+ * 过滤条件设置
|
|
|
+ */
|
|
|
+ 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.ftitle like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
|
|
|
+ where.append(" and t1.ftype ='").append(whereObject.getString("ftype")).append("' ");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("fissupply")) {
|
|
|
+ where.append(" and t1.fissupply =").append(whereObject.getBooleanValue("fissupply") ? 1 : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "供需列表查询", pageSize, pageNumber, sort);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setDataByPaging(rows).saveToDataPool().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供需详情查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String query_supplyanddemandMain() throws P2Exception {
|
|
|
+ long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "供需详情查询");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("tagentsid", tagentsid);
|
|
|
+ sqlFactory.addParameter("tsupplyanddemandid", tsupplyanddemandid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
|
|
|
+
|
|
|
+ Rows imdialogRows = dbConnect.runSqlQuery("select timdialogid from timdialog where siteid='" + siteid + "' and ownertable='tsupplyanddemand' and ownerid='" + tsupplyanddemandid + "' and tenterprise_userid=" + userid);
|
|
|
+ long timdialogid;
|
|
|
+ if (!imdialogRows.isEmpty()) {
|
|
|
+ timdialogid = imdialogRows.get(0).getLong("timdialogid");
|
|
|
+ } else {
|
|
|
+ //聊天对话框不存在时,自动生成一个聊天对话框
|
|
|
+ PaoSetRemote timdialogSet = getP2ServerSystemPaoSet("timdialog");
|
|
|
+ PaoRemote timdialog = timdialogSet.addAtEnd();
|
|
|
+ timdialog.setValue("siteid", siteid, 11L);//企业ID
|
|
|
+ timdialog.setValue("createby", username, 11L);//创建人
|
|
|
+ timdialog.setValue("createdate", sysdate, 11L);//创建时间
|
|
|
+ timdialog.setValue("fimdialogtype", "供需", 11L);//对话框类型
|
|
|
+ timdialog.setValue("ownertable", "tsupplyanddemand", 11L);//所有表
|
|
|
+ timdialog.setValue("ownerid", tsupplyanddemandid, 11L);//所有表ID
|
|
|
+ timdialog.setValue("tenterprise_userid", userid, 11L);//创建账号ID
|
|
|
+ timdialog.setValue("fimdialogname", row.getString("ftitle"), 11L);//对话框类型
|
|
|
+ timdialogid = timdialog.getUniqueIDValue();
|
|
|
+ timdialogSet.save();
|
|
|
+
|
|
|
+ SQLFactory addusers = new SQLFactory(this, "即时通讯群人员添加");
|
|
|
+ addusers.addParameter("createby", username);
|
|
|
+ addusers.addParameter("timdialogid", timdialogid);
|
|
|
+ addusers.addParameter("siteid", siteid);
|
|
|
+ addusers.addParameter_in("tenterprise_userid", new String[]{String.valueOf(userid), row.getString("tenterprise_userid")});
|
|
|
+ dbConnect.runSqlUpdate(addusers.getSQL());
|
|
|
+ }
|
|
|
+ row.put("timdialogid", timdialogid);
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的供需列表查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String query_mysupplyanddemandList() {
|
|
|
+ /**
|
|
|
+ *排序条件设置
|
|
|
+ */
|
|
|
+ String[] sortfield = {"t1.tsupplyanddemandid desc"};
|
|
|
+ String sort = getSort(sortfield, "t1.tsupplyanddemandid desc");
|
|
|
+ /**
|
|
|
+ * 过滤条件设置
|
|
|
+ */
|
|
|
+ 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.ftitle like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
|
|
|
+ where.append(" and t1.ftype ='").append(whereObject.getString("ftype")).append("' ");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("fissupply")) {
|
|
|
+ where.append(" and t1.fissupply =").append(whereObject.getBooleanValue("fissupply") ? 1 : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "我的供需列表查询", pageSize, pageNumber, sort);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("tagentsid", tagentsid);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setDataByPaging(rows).saveToDataPool().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的供需详情查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String query_mysupplyanddemandMain() {
|
|
|
+ long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "我的供需详情查询");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("tagentsid", tagentsid);
|
|
|
+ sqlFactory.addParameter("tsupplyanddemandid", tsupplyanddemandid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+
|
|
|
+ SQLFactory dialoglistSQL = new SQLFactory(this, "我的供需详情查询_对话框列表");
|
|
|
+ dialoglistSQL.addParameter("siteid", siteid);
|
|
|
+ dialoglistSQL.addParameter("tagentsid", tagentsid);
|
|
|
+ dialoglistSQL.addParameter("tsupplyanddemandid", tsupplyanddemandid);
|
|
|
+ dialoglistSQL.addParameter("userid", userid);
|
|
|
+ Rows dialogrows = dbConnect.runSqlQuery(dialoglistSQL.getSQL());
|
|
|
+ System.err.println(dialoglistSQL.getSQL());
|
|
|
+
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("tsupplyanddemand", rows.toArrayList("tsupplyanddemandid"));
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfoRowsMap.get(row.getString("tsupplyanddemandid")));
|
|
|
+ row.put("imdialogs", dialogrows);
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改供需
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String insertormodify() throws D3bException, P2Exception {
|
|
|
+ long tsupplyanddemandid = content.getLongValue("tsupplyanddemandid");//需求ID,新增时传0
|
|
|
+ String ftype = content.getString("ftype");
|
|
|
+ String ftitle = content.getString("ftitle", "tsupplyanddemand.ftitle", "需求标题");
|
|
|
+ String fcontent = content.getString("fcontent", "tsupplyanddemand.fcontent", "需求内容");
|
|
|
+ String fenddate = content.getString("fenddate");
|
|
|
+ boolean fissupply = content.getBoolean("fissupply");
|
|
|
+
|
|
|
+ PaoSetRemote tsupplyanddemandSet = getP2ServerSystemPaoSet("tsupplyanddemand", "siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ PaoRemote tsupplyanddemand = null;
|
|
|
+ if (tsupplyanddemandid <= 0 || tsupplyanddemandSet.isEmpty()) {
|
|
|
+ tsupplyanddemand = tsupplyanddemandSet.addAtEnd();
|
|
|
+ tsupplyanddemand.setValue("siteid", siteid, 11L);//企业ID
|
|
|
+ tsupplyanddemand.setValue("tagentsid", tagentsid, 11L);//企业ID
|
|
|
+ tsupplyanddemand.setValue("createby", username, 11L);//录入人
|
|
|
+ tsupplyanddemand.setValue("createdate", sysdate, 11L);//录入时间
|
|
|
+ tsupplyanddemand.setValue("tenterprise_userid", userid, 11L);//发布人账号ID
|
|
|
+ tsupplyanddemand.setValue("fissupply", fissupply, 11L);//供、需
|
|
|
+ tsupplyanddemand.setValue("fstatus", "新建", 11L);//状态
|
|
|
+ } else {
|
|
|
+ tsupplyanddemand = tsupplyanddemandSet.getPao(0);
|
|
|
+ }
|
|
|
+ tsupplyanddemand.setValue("ftype", ftype, 11L);//产品名称
|
|
|
+ tsupplyanddemand.setValue("ftitle", ftitle, 11L);//需求标题
|
|
|
+ tsupplyanddemand.setValue("fcontent", fcontent, 11L);//需求内容
|
|
|
+ tsupplyanddemand.setValue("fenddate", fenddate, 11L);//到期时间
|
|
|
+
|
|
|
+ tsupplyanddemand.setValue("changeby", username, 11L);//修改人
|
|
|
+ tsupplyanddemand.setValue("changedate", sysdate, 11L);//修改时间
|
|
|
+ content.put("tsupplyanddemandid", tsupplyanddemand.getUniqueIDValue());
|
|
|
+ tsupplyanddemandSet.save();
|
|
|
+ return query_mysupplyanddemandMain();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供需状态变更
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String updatesupplyanddemandstatus() {
|
|
|
+ long tsupplyanddemandid = content.getLong("tsupplyanddemandid");
|
|
|
+ String fstatus = content.getString("fstatus");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("供需内容不存在").toString();
|
|
|
+ }
|
|
|
+ if (!Arrays.asList(new String[]{"新建", "发布", "待对接", "正在对接", "已解决", "已过期"}).contains(fstatus)) {
|
|
|
+ return getErrReturnObject().setErrMsg("无效的供需状态").toString();
|
|
|
+ }
|
|
|
+ switch (fstatus) {
|
|
|
+ case "新建": {
|
|
|
+ dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='新建',checkby=null,checkdate=null where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "发布": {
|
|
|
+ if (!"新建".equals(rows.get(0).getString("fstatus"))) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前状态不可发布").toString();
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='待对接',checkby='" + username + "',checkdate=getDate() where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='" + fstatus + "' where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return query_mysupplyanddemandMain();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供需删除
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String deletesupplyanddemand() {
|
|
|
+ long tsupplyanddemandid = content.getLongValue("tsupplyanddemandid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ if (!rows.isEmpty() && !"新建".equals(rows.get(0).getString("fstatus"))) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
|
|
|
+ }
|
|
|
+ String status = dbConnect.runSqlUpdate("delete from tsupplyanddemand where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tsupplyanddemandid='" + tsupplyanddemandid + "'");
|
|
|
+ if ("true".equals(status)) {
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|