package restcontroller.webmanage.saletool.notice; import beans.remind.Remind; import beans.user.User; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.annotation.CACHEING; import common.annotation.CACHEING_CLEAN; import common.annotation.cm; import common.data.Row; import common.data.Rows; import common.data.RowsMap; import common.data.SQLFactory; import restcontroller.R; import java.util.ArrayList; import java.util.List; @API(title = "通告") public class notice extends Controller { public notice(JSONObject content) throws YosException { super(content); } @API(title = "通告新增修改", apiversion = R.ID20221101094803.v1.class) @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})}) public String insertormodify_notice() throws YosException { long sat_noticeid = content.getLong("sat_noticeid"); ArrayList sqllist = new ArrayList<>(); String title = content.getString("title"); Long sat_notice_classid = content.getLong("sat_notice_classid"); String summary = content.getString("summary"); String content1 = content.getString("content", true); boolean issecret = content.getBoolean("issecret"); boolean isontop = content.getBoolean("isontop"); String begdate = content.getStringValue("begdate"); String enddate = content.getStringValue("enddate"); if (sat_noticeid <= 0 || dbConnect .runSqlQuery("select sat_noticeid from sat_notice where sat_noticeid=" + sat_noticeid).isEmpty()) { sat_noticeid = createTableID("sat_notice"); SQLFactory sqlFactory = new SQLFactory(this, "通告新增"); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("createdepid", departmentid); sqlFactory.addParameter("createuserid", userid); sqlFactory.addParameter("createby", username); sqlFactory.addParameter("authuserid", userid); sqlFactory.addParameter("authdepid", departmentid); sqlFactory.addParameter("changeby", username); sqlFactory.addParameter("changeuserid", userid); sqlFactory.addParameter("title", title); sqlFactory.addParameter("sat_notice_classid", sat_notice_classid); sqlFactory.addParameter("summary", summary); sqlFactory.addParameter("content", content1); sqlFactory.addParameter("issecret", issecret); sqlFactory.addParameter("isontop", isontop); sqlFactory.addParameter("begdate", begdate.equals("") ? "null" : begdate); sqlFactory.addParameter("enddate", enddate.equals("") ? "null" : enddate); content.put("sat_noticeid", sat_noticeid); sqllist.add(sqlFactory.getSQL()); if (isontop) { sqllist.add("update sat_notice set isontop=0 where isontop=1 and sat_noticeid !=" + sat_noticeid); } } else { Rows rowscount = dbConnect.runSqlQuery("select status from sat_notice where sat_noticeid=" + sat_noticeid); if (rowscount.isEmpty()) { return getErrReturnObject().setErrMsg("此通告不存在").toString(); } else { if (!rowscount.get(0).getString("status").equals("新建")) { return getErrReturnObject().setErrMsg("非新建状态的通告无法更新").toString(); } } SQLFactory sqlFactory = new SQLFactory(this, "通告更新"); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("createdepid", departmentid); sqlFactory.addParameter("authuserid", userid); sqlFactory.addParameter("authdepid", departmentid); sqlFactory.addParameter("changeby", username); sqlFactory.addParameter("changeuserid", userid); sqlFactory.addParameter("title", title); sqlFactory.addParameter("isontop", isontop); sqlFactory.addParameter("sat_notice_classid", sat_notice_classid); sqlFactory.addParameter("summary", summary); sqlFactory.addParameter("content", content1); sqlFactory.addParameter("issecret", issecret); sqlFactory.addParameter("begdate", begdate.equals("") ? "null" : begdate); sqlFactory.addParameter("enddate", enddate.equals("") ? "null" : enddate); sqllist.add(sqlFactory.getSQL()); if (isontop) { sqllist.add("update sat_notice set isontop=0 where isontop=1 and sat_noticeid !=" + sat_noticeid); } } dbConnect.runSqlUpdate(sqllist); return queryNoticeMain(); } @API(title = "通告列表", apiversion = R.ID20221101094903.v1.class) @CACHEING public String queryNoticeList() throws YosException { /* 排序条件设置 */ String sort = "t1.createdate desc"; /* 过滤条件设置 */ String where = " 1=1 "; if (content.containsKey("where")) { JSONObject whereObject = content.getJSONObject("where"); if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) { where = where + " and t1.title like'%" + whereObject.getString("condition") + "%'"; } if (whereObject.containsKey("sat_notice_classid") && !"".equals(whereObject.getString("sat_notice_classid"))) { where = where + " and t2.sat_notice_classid = " + whereObject.getString("sat_notice_classid"); } if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) { where = where + " and t1.status ='" + whereObject.getString("status") + "' "; } if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) { where = where + " and t1.checkdate >='" + whereObject.getString("begindate") + "'"; } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where = where + " and t1.checkdate <='" + whereObject.getString("enddate") + "'"; } } SQLFactory sqlFactory = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, pageSorting); sqlFactory.addParameter_SQL("where", where); sqlFactory.addParameter("siteid", siteid); Rows rows = dbConnect.runSqlQuery(sqlFactory); ArrayList ids = rows.toArrayList("sat_noticeid", new ArrayList()); // 附件 RowsMap RowsMap = getAttachmentUrl("sat_notice", ids); // 封面cover RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover"); for (Row row : rows) { Rows Rows = RowsMap.get(row.getString("sat_noticeid")); if (Rows.isEmpty()) { row.put("attinfos", new Rows()); } else { row.put("attinfos", Rows); } // row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_coursewareid"), new Rows())); } for (Row row : rows) { Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid")); if (coverRows.isEmpty()) { row.put("cover", ""); } else { row.put("cover", coverRows.get(0).getString("url")); } } return getSucReturnObject().setData(rows).toString(); } @API(title = "通告详情", apiversion = R.ID20221101095003.v1.class) public String queryNoticeMain() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); // 新增记录 addReadRecord(sat_noticeid); SQLFactory sqlFactory = new SQLFactory(this, "通告详情查询"); sqlFactory.addParameter("sat_noticeid", sat_noticeid); Rows rows = dbConnect.runSqlQuery(sqlFactory); ArrayList ids = rows.toArrayList("sat_noticeid", new ArrayList()); // 附件 RowsMap attRowsMap = getAttachmentUrl("sat_notice", ids, "default"); // 封面cover RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover"); for (Row row : rows) { Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid")); if (coverRows.isEmpty()) { row.put("cover", ""); } else { row.put("cover", coverRows.get(0).getString("url")); } row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_noticeid"), new Rows())); } return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString(); } @API(title = "删除", apiversion = R.ID20221101095103.v1.class) @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})}) public String delete() throws YosException { JSONArray sat_noticeids = content.getJSONArray("sat_noticeids"); StringBuffer err = new StringBuffer(); for (Object o : sat_noticeids) { long sat_noticeid = Long.parseLong(o.toString()); Rows rowscount = dbConnect.runSqlQuery("select title,status from sat_notice where sat_noticeid=" + sat_noticeid); if (rowscount.isEmpty()) { err.append(rowscount.get(0).getString("title")).append("--").append("此通告不存在,无法删除;"); continue; } else if (!rowscount.get(0).getString("status").equals("新建")) { err.append(rowscount.get(0).getString("title")).append("--").append("非新建状态的通告无法删除;"); continue; } ArrayList list = new ArrayList<>(); String deletesql = "delete from sat_notice where sat_noticeid=" + sat_noticeid; list.add(deletesql); dbConnect.runSqlUpdate(list); } if (err.length() == 0) return getSucReturnObject().toString(); else return getSucReturnObject().setData(err).toString(); } /** * 通告发布 * * @return */ @API(title = "发布", apiversion = R.ID20221101095203.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221111090904.v1.class, R.ID20221101094903.v1.class}) public String release() throws YosException { JSONArray sat_noticeids = content.getJSONArray("sat_noticeids"); String[] s = {"sat_noticeids"}; for (String s1 : s) { if (!content.containsKey(s1)) return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString(); } List list = sat_noticeids.toJavaList(String.class); String[] stringArray = list.toArray(new String[0]); SQLFactory sqlFactoryquery = new SQLFactory(this, "通告状态查询"); sqlFactoryquery.addParameter("siteid", siteid); sqlFactoryquery.addParameter_in("sat_noticeids", stringArray); Rows rows = dbConnect.runSqlQuery(sqlFactoryquery); for (Row row : rows) { if (row.getString("status").equals("发布")) { return getErrReturnObject().setErrMsg("【" + row.getString("title") + "】通告已发布,无法再次发布").toString(); } } SQLFactory sqlFactoryupdate = new SQLFactory(this, "通告发布"); sqlFactoryupdate.addParameter("siteid", siteid); sqlFactoryupdate.addParameter_in("sat_noticeids", stringArray); sqlFactoryupdate.addParameter("checkby", username); dbConnect.runSqlUpdate(sqlFactoryupdate); //发送消息 for (String id : stringArray) { //sendMsg(Long.parseLong(id)); } return getSucReturnObject().toString(); } /** * 发送消息:新课程发布,商学院发布范围内的经销商/人员 * * @param id * @throws YosException */ public void sendMsg(Long id) throws YosException { SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sat_noticeid", id); Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL()); if (useridRows.isNotEmpty()) { for (Row row : useridRows) { Long tempUserid = row.getLong("userid"); if (tempUserid != 0) { Remind remind = new Remind(this); remind.setType("应用"); remind.setTitle("新通告发布"); remind.setContent("您有新的通告,请查看!"); remind.setTouserid(tempUserid); remind.sendByDialogMsg().createSys_message(); remind.setToemail(User.getUserMailAddress(this, tempUserid)); remind.sendByMail(); } } } } /** * 通告下架 * * @return */ @API(title = "下架", apiversion = R.ID20221101095303.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221111090904.v1.class, R.ID20221101094903.v1.class}) public String undercarriage() throws YosException { JSONArray sat_noticeids = content.getJSONArray("sat_noticeids"); String[] s = {"sat_noticeids"}; for (String s1 : s) { if (!content.containsKey(s1)) return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString(); } List list = sat_noticeids.toJavaList(String.class); String[] stringArray = list.toArray(new String[0]); SQLFactory sqlFactoryquery = new SQLFactory(this, "通告状态查询"); sqlFactoryquery.addParameter("siteid", siteid); sqlFactoryquery.addParameter_in("sat_noticeids", stringArray); Rows rows = dbConnect.runSqlQuery(sqlFactoryquery); for (Row row : rows) { if (row.getString("status").equals("新建")) { return getErrReturnObject().setErrMsg("【" + row.getString("title") + "】通告已下架,无法再次下架").toString(); } } SQLFactory sqlFactoryupdate = new SQLFactory(this, "通告下架"); sqlFactoryupdate.addParameter("siteid", siteid); sqlFactoryupdate.addParameter_in("sat_noticeids", stringArray); dbConnect.runSqlUpdate(sqlFactoryupdate); //发送消息 for (String id : stringArray) { if (rows.isNotEmpty()) { //sendOffMsg(Long.parseLong(id), rows.get(0).getString("title")); } } return getSucReturnObject().toString(); } /** * 发送消息:新课程发布,商学院发布范围内的经销商/人员 * * @param id * @throws YosException */ public void sendOffMsg(Long id, String title) throws YosException { SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sat_noticeid", id); Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL()); if (useridRows.isNotEmpty()) { for (Row row : useridRows) { Long tempUserid = row.getLong("userid"); if (tempUserid != 0) { Remind remind = new Remind(this); remind.setType("应用"); remind.setTitle("通告取消"); remind.setContent("通告【" + title + "】已取消发布,请查看!"); remind.setTouserid(tempUserid); remind.sendByDialogMsg().createSys_message(); remind.setToemail(User.getUserMailAddress(this, tempUserid)); remind.sendByMail(); } } } } /** * 通告置顶 * * @return */ @API(title = "置顶", apiversion = R.ID20221101095403.v1.class) @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})}) public String topping() throws YosException { String[] s = {"sat_noticeid"}; for (String s1 : s) { if (!content.containsKey(s1)) return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString(); } String sqlName = "SELECT COUNT(*) count FROM sat_notice WHERE sat_noticeid = '" + content.getIntValue("sat_noticeid") + "' and isontop=1"; Rows rowsName = dbConnect.runSqlQuery(sqlName); if (rowsName.get(0).getLong("count") > 0) { return getErrReturnObject().setErrMsg("此通告已置顶,无须再次置顶").toString(); } dbConnect.runSqlUpdate("update sat_notice set isontop=0 where isontop=1 "); dbConnect.runSqlUpdate( "update sat_notice set isontop=1 where sat_noticeid=" + content.getIntValue("sat_noticeid")); return getSucReturnObject().toString(); } /** * 通告取消置顶 * * @return */ @API(title = "取消置顶", apiversion = R.ID20221101095503.v1.class) @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})}) public String cancelTopping() throws YosException { String[] s = {"sat_noticeid"}; for (String s1 : s) { if (!content.containsKey(s1)) return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString(); } String sqlName = "SELECT COUNT(*) count FROM sat_notice WHERE sat_noticeid = '" + content.getIntValue("sat_noticeid") + "' and isontop=0"; Rows rowsName = dbConnect.runSqlQuery(sqlName); if (rowsName.get(0).getLong("count") > 0) { return getErrReturnObject().setErrMsg("此通告已取消置顶,无须再次取消").toString(); } dbConnect.runSqlUpdate( "update sat_notice set isontop=0 where sat_noticeid=" + content.getIntValue("sat_noticeid")); return getSucReturnObject().toString(); } /** * 更新阅读记录(通告留言和打分) * * @return */ @API(title = "更新阅读记录", apiversion = R.ID20221101095603.v1.class) public String updateReadRecord() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); int score = content.getInteger("score"); String leavemessage = content.getString("leavemessage"); Rows rows = dbConnect.runSqlQuery("select sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'"); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("阅读记录不存在,无法更新").toString(); } SQLFactory sqlFactory = new SQLFactory(this, "阅读记录更新"); sqlFactory.addParameter("leavemessage", leavemessage); sqlFactory.addParameter("score", score); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("userid", userid); dbConnect.runSqlUpdate(sqlFactory); return getSucReturnObject().toString(); } /** * 查询阅读记录(通告留言和打分) * * @return */ @API(title = "查询阅读记录", apiversion = R.ID20221101095703.v1.class) public String queryReadRecord() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); String where = " 1=1 "; if (content.containsKey("where")) { JSONObject whereObject = content.getJSONObject("where"); if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) { where = where + " and (t1.leavemessage like'%" + whereObject.getString("condition") + "%' or t3.position like '%" + whereObject.getString("condition") + "%' or t1.createby like '%" + whereObject.getString("condition") + "%')"; } if (whereObject.containsKey("score") && !"".equals(whereObject.getString("score"))) { where = where + " and t1.score ='" + whereObject.getString("score") + "' "; } if (whereObject.containsKey("usertype") && !"".equals(whereObject.getString("usertype"))) { where = where + " and t2.usertype ='" + whereObject.getString("usertype") + "' "; } if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) { where = where + " and t1.createdate >='" + whereObject.getString("begindate") + "'"; } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where = where + " and t1.createdate <='" + whereObject.getString("enddate") + "'"; } } Rows rows = dbConnect .runSqlQuery("select t2.usertype,t3.position,t1.createdate,t1.createby,t1.leavemessage,t1.score,(SELECT count(*) FROM sat_notice_read WHERE siteid ='" + siteid + "' AND sat_noticeid = '" + sat_noticeid + "' and score>0) evaluatecount FROM sat_notice_read t1\n" + " left join sys_usersite t2 on t1.createuserid=t2.userid and t1.siteid=t2.siteid\n" + " left join sys_enterprise_hr t3 on t1.createuserid=t3.userid and t1.siteid=t3.siteid\n" + " WHERE " + where + " and t1.siteid = '" + siteid + "' AND t1.sat_noticeid ='" + sat_noticeid + "' and !(isnull(t1.leavemessage) and t1.score=0)"); return getSucReturnObject().setData(rows).toString(); } @API(title = "更新下载附件记录") public String updateDownloadRecord() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); dbConnect.runSqlUpdate("UPDATE sat_notice_read SET isdownloadfile=1 WHERE siteid = '" + siteid + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'"); return getSucReturnObject().toString(); } @API(title = "通告阅读记录评分分析") public String scoreAnalysis() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); SQLFactory sqlFactory = new SQLFactory(this, "通告评分状况分析"); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("siteid", siteid); Rows rows = dbConnect.runSqlQuery(sqlFactory); return getSucReturnObject().setData(rows).toString(); } /** * 通告阅读记录下载分析 * * @return */ @API(title = "通告阅读记录下载分析") public String fileDownloadAnalysis() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); SQLFactory sqlFactory = new SQLFactory(this, "通告附件下载状况分析"); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("siteid", siteid); Rows rows = dbConnect.runSqlQuery(sqlFactory); SQLFactory sqlFactory1 = new SQLFactory(this, "通告总人数统计查询"); sqlFactory1.addParameter("sat_noticeid", sat_noticeid); sqlFactory1.addParameter("siteid", siteid); Rows rows1 = dbConnect.runSqlQuery(sqlFactory1); Rows rowscount = new Rows(); Row row = new Row(); row.put("sumcount", rows1.get(0).getLong("sumnum")); row.put("downloadcount", rows.get(0).getLong("downloadcount")); row.put("undownloadcount", rows1.get(0).getLong("sumnum") - rows.get(0).getLong("downloadcount")); rowscount.add(row); return getSucReturnObject().setData(rowscount).toString(); } @API(title = "同板块间通告评分对比") public String scoreContrast() throws YosException { String where = " 1=1 "; int sat_notice_classid = content.getIntValue("sat_notice_classid"); if (content.containsKey("where")) { JSONObject whereObject = content.getJSONObject("where"); if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) { where = where + " and t1.checkdate >='" + whereObject.getString("begindate") + "'"; } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where = where + " and t1.checkdate <='" + whereObject.getString("enddate") + "'"; } } SQLFactory sqlFactory = new SQLFactory(this, "同板块间通告评分对比"); sqlFactory.addParameter_SQL("where", where); sqlFactory.addParameter("sat_notice_classid", sat_notice_classid); sqlFactory.addParameter("siteid", siteid); Rows rows = dbConnect.runSqlQuery(sqlFactory); return getSucReturnObject().setData(rows).toString(); } // 添加阅读记录 public void addReadRecord(Long sat_noticeid) throws YosException { // 新增浏览次数 dbConnect.runSqlUpdate("UPDATE sat_notice SET readcount=readcount+1 WHERE sat_noticeid='" + sat_noticeid + "'"); // 查询当前用户的阅读记录是否存在 String sql = "SELECT sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'"; Rows rows = dbConnect.runSqlQuery(sql); if (rows.isEmpty()) { SQLFactory sqlFactory = new SQLFactory(this, "阅读记录新增"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sat_notice_readid", createTableID("sat_notice_read")); sqlFactory.addParameter("createby", username); sqlFactory.addParameter("changeby", username); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("createuserid", userid); sqlFactory.addParameter("hrid", hrid); sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId()); dbConnect.runSqlUpdate(sqlFactory); } else { SQLFactory sqlFactory = new SQLFactory(this, "阅读记录次数更新"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sat_noticeid", sat_noticeid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("hrid", hrid); sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId()); dbConnect.runSqlUpdate(sqlFactory); } } }