| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- 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();
- }
- }
- }
|