| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- package com.cnd3b.restcontroller.enterprise.noticemag;
- import com.alibaba.fastjson.JSONArray;
- 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 com.cnd3b.common.data.db.DataPool;
- import p2.pao.PaoRemote;
- import p2.pao.PaoSetRemote;
- import p2.util.P2Exception;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Iterator;
- public class noticemag extends Controller {
- public noticemag(JSONObject content) {
- super(content);
- }
- /**
- * 通告列表查询
- *
- * @return
- */
- public String query_noticeList() {
- /**
- *排序条件设置
- */
- String[] sortfield = {"t1.fisontop desc,t1.checkdate desc"};
- String sort = getSort(sortfield, "t1.fisontop desc,t1.checkdate 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("or t1.ftype like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.fsummary 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("'");
- }
- }
- SQLFactory noticehead = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, sort);
- noticehead.addParameter("siteid", siteid);
- noticehead.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(noticehead.getSQL());
- ArrayList<String> tnoticeidlist = rows.toArrayList("tnoticeid");
- //通告附件数量查询
- RowsMap attinfocountmap = getAttachmentQty("tnotice", tnoticeidlist);
- //通告封面图查询
- RowsMap noticecovermap = getAttachmentUrl("tnotice", tnoticeidlist, "cover");
- for (Row row : rows) {
- String tnoticeid = row.getString("tnoticeid");
- row.put("fattachmentcount", attinfocountmap.containsKey(tnoticeid) ? attinfocountmap.get(tnoticeid).getRow(0).getInteger("fattachmentcount") : 0);
- row.put("attinfos", noticecovermap.get(tnoticeid));
- row.put("headportraiturl", getHeadPic(row.getLong("tenterprise_userid")));
- }
- return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(DataPool.defaultdatalife, 1);
- }
- /**
- * 通告主界面查询
- *
- * @return
- */
- public String query_noticeMain() {
- String tnoticeid = content.getString("tnoticeid");
- SQLFactory noticehead = new SQLFactory(this, "通告主界面查询");
- noticehead.addParameter("siteid", siteid);
- noticehead.addParameter("tnoticeid", tnoticeid);
- Rows rows = dbConnect.runSqlQuery(noticehead.getSQL());
- Rows attinfosRows = getAttachmentUrl("tnotice", tnoticeid);
- rows.get(0).put("attinfos", attinfosRows);
- rows.get(0).put("headportraiturl", getHeadPic(rows.get(0).getLong("tenterprise_userid")));
- return getSucReturnObject().setData(rows).toString();
- }
- /**
- * 通告置顶
- *
- * @return
- */
- public String noticeontop() {
- String tnoticeid = content.getString("tnoticeid");
- int fisontop = content.getInteger("fisontop");//是否置顶
- String status = dbConnect.runSqlUpdate("update tnotice set fisontop=" + fisontop + ", changeby='" + username + "',changedate=getdate() where siteid='" + siteid + "' and tnoticeid='" + tnoticeid + "'");
- if ("true".equals(status)) {
- return getSucReturnObject().toString();
- } else {
- return getErrReturnObject().setErrMsg(status).toString();
- }
- }
- /**
- * 通告新增、修改
- *
- * @return
- */
- public String insertOrModify() throws D3bException, P2Exception {
- long tnoticeid = content.getLongValue("tnoticeid"); //新增时默认传0
- String ftype = content.getString("ftype");//通告类型
- String ftitle = content.getString("ftitle", "tnotice.ftitle", "标题");//标题
- String fsummary = content.getString("fsummary", "tnotice.fsummary", "通告导语");//概述、导读
- String fcontent = content.getString("fcontent", "tnotice.fcontent", "正文");//通告内容
- boolean fishomepage = content.getBooleanValue("fishomepage");//门户可见
- boolean fischeckagent = content.getBooleanValue("fischeckagent");//认证商户可见
- boolean fisagentsubuser = content.getBooleanValue("fisagentsubuser");//认证商户子账号可见
- boolean fisspecifiedrange = content.getBooleanValue("fisspecifiedrange");//指定认证商户范围
- boolean fissingleagent = content.getBooleanValue("fissingleagent");//个人商户可见
- boolean fisontop = content.getBooleanValue("fisontop");//是否置顶
- Date fbegdate = content.getDate("fbegdate");//开始时间
- Date fenddate = content.getDate("fenddate");//结束时间
- PaoSetRemote tnoticeSet = getP2ServerSystemPaoSet("tnotice", "siteid='" + siteid + "' and tnoticeid='" + tnoticeid + "'");
- PaoRemote tnotice = null;
- if (tnoticeid <= 0 || tnoticeSet.isEmpty()) {
- tnotice = tnoticeSet.addAtEnd();
- tnotice.setValue("siteid", siteid, 11L);//企业ID
- tnotice.setValue("createby", username, 11L);//录入人
- tnotice.setValue("createdate", sysdate, 11L);//录入时间
- tnotice.setValue("tenterprise_userid", userid, 11L);//创建者id
- } else {
- tnotice = tnoticeSet.getPao(0);
- }
- tnotice.setValue("ftype", ftype, 11L);//通告类型
- tnotice.setValue("ftitle", ftitle, 11L);//标题
- tnotice.setValue("fsummary", fsummary, 11L);//概述、导读
- tnotice.setValue("fcontent", fcontent, 11L);//通告内容
- tnotice.setValue("fishomepage", fishomepage, 11L);//门户可见
- tnotice.setValue("fischeckagent", fischeckagent, 11L);//认证商户可见
- tnotice.setValue("fisagentsubuser", fisagentsubuser, 11L);//认证商户子账号可见
- tnotice.setValue("fisspecifiedrange", fisspecifiedrange, 11L);//指定认证商户范围
- tnotice.setValue("fissingleagent", fissingleagent, 11L);//个人商户可见
- tnotice.setValue("fisontop", fisontop, 11L);//是否置顶
- tnotice.setValue("fbegdate", fbegdate, 11L);//开始时间
- tnotice.setValue("fenddate", fenddate, 11L);//结束时间
- tnotice.setValue("changeby", username, 11L);//修改人
- tnotice.setValue("changedate", sysdate, 11L);//修改时间
- content.put("tnoticeid", tnotice.getUniqueIDValue());
- tnoticeSet.save();
- return query_noticeMain();
- }
- /**
- * 发布
- *
- * @return
- */
- public String check() {
- String tnoticeid = content.getString("tnoticeid");
- boolean fischeck = content.getBooleanValue("fischeck");//是否发布
- SQLFactory sqlFactory = null;
- if (fischeck) {
- sqlFactory = new SQLFactory(this, "通告发布");
- sqlFactory.addParameter("checkby", username);
- } else {
- sqlFactory = new SQLFactory(this, "通告取消发布");
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("tnoticeid", tnoticeid);
- String status = dbConnect.runSqlUpdate(sqlFactory.getSQL());
- if ("true".equalsIgnoreCase(status)) {
- return getSucReturnObject().toString();
- } else {
- return getErrReturnObject().setErrMsg(status).toString();
- }
- }
- /**
- * 通告删除
- *
- * @return
- */
- public String delete() {
- long tnoticeid = content.getLongValue("tnoticeid");
- if (dbConnect.runSqlQuery("select * from tnotice where siteid='" + siteid + "' and fstatus='新建' and tnoticeid=" + tnoticeid).isEmpty()) {
- return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
- }
- SQLFactory sqlFactory = new SQLFactory(this, "通告删除");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("tnoticeid", tnoticeid);
- String result = dbConnect.runSqlUpdate(sqlFactory.getSQL());
- if ("true".equals(result)) {
- return getSucReturnObject().toString();
- } else {
- return getErrReturnObject().setErrMsg(result).toString();
- }
- }
- /**
- * 已浏览用户列表
- *
- * @return
- */
- public String havereaduserlist() {
- String tnoticeid = content.getString("tnoticeid");
- /**
- *排序条件设置
- */
- String[] sortfield = {"t1.tenterprise_userid"};
- String sort = getSort(sortfield, "t1.tenterprise_userid");
- SQLFactory factory = new SQLFactory(this, "浏览用户列表", pageSize, pageNumber, sort);
- factory.addParameter("siteid", siteid);
- factory.addParameter("tnoticeid", tnoticeid);
- Rows rows = dbConnect.runSqlQuery(factory.getSQL());
- return getSucReturnObject().setDataByPaging(rows).setFinalDo(DataPool.defaultdatalife, 1);
- }
- /**
- * 查询通告人员
- *
- * @return
- */
- public String query_noticeuserList() {
- String tnoticeid = content.getString("tnoticeid");
- /**
- *排序条件设置
- */
- String[] sortfield = {"t1.tnotice_usersid"};
- String sort = getSort(sortfield, "t1.tnotice_usersid");
- /**
- * 过滤条件设置
- */
- 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("t2.fname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("t3.fagentname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("t3.fbrand like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "查询通告人员", pageSize, pageNumber, sort);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("tnoticeid", tnoticeid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- return getSucReturnObject().setDataByPaging(rows).setFinalDo(DataPool.defaultdatalife, 1);
- }
- /**
- * 添加通告人员
- *
- * @return
- */
- public String adduser() {
- String tnoticeid = content.getString("tnoticeid");
- JSONArray idarray = content.getJSONArray("tagentsid");
- Iterator<Object> it = idarray.iterator();
- ArrayList<String> list = new ArrayList<>();
- while (it.hasNext()) {
- SQLFactory sqlFactory = new SQLFactory(this, "添加通告人员");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("createby", username);
- sqlFactory.addParameter("tnoticeid", tnoticeid);
- sqlFactory.addParameter("tagentsid", String.valueOf(it.next()));
- list.add(sqlFactory.getSQL());
- }
- if (!list.isEmpty()) {
- String status = dbConnect.runSqlUpdate(list);
- if ("true".equals(status)) {
- return getSucReturnObject().toString();
- } else {
- return getErrReturnObject().setErrMsg(status).toString();
- }
- }
- return getErrReturnObject().setErrMsg("没有选择添加人员").toString();
- }
- /**
- * 删除提报人员
- *
- * @return
- */
- public String deleteuser() {
- String tnoticeid = content.getString("tnoticeid");
- JSONArray idarray = content.getJSONArray("tagentsid");
- Iterator<Object> it = idarray.iterator();
- ArrayList<String> list = new ArrayList<>();
- while (it.hasNext()) {
- SQLFactory sqlFactory = new SQLFactory(this, "删除通告人员");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("createby", username);
- sqlFactory.addParameter("tnoticeid", tnoticeid);
- sqlFactory.addParameter("tagentsid", (String) it.next());
- list.add(sqlFactory.getSQL());
- }
- if (!list.isEmpty()) {
- String status = dbConnect.runSqlUpdate(list);
- if ("true".equals(status)) {
- return getSucReturnObject().toString();
- } else {
- return getErrReturnObject().setErrMsg(status).toString();
- }
- }
- return getErrReturnObject().setErrMsg("没有选择删除人员").toString();
- }
- }
|