package restcontroller.saletool.notice; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.annotation.CACHEING; import common.data.Row; import common.data.Rows; import common.data.RowsMap; import common.data.SQLFactory; import restcontroller.R; import java.util.ArrayList; @API(title = "通告") public class notice extends Controller { public notice(JSONObject content) throws YosException { super(content); } @API(title = "通告列表", apiversion = R.ID20221111090904.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 t1.sat_notice_classid = " + whereObject.getString("sat_notice_classid"); } } SQLFactory sqlFactory = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, pageSorting); sqlFactory.addParameter_SQL("where", where); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_in("departmentid", departmentid); sqlFactory.addParameter_in("hrid", hrid); sqlFactory.addParameter_in("sa_agentsid", userInfo.getAgentsId()); sqlFactory.addParameter_in("sa_saleareaid", userInfo.getSaleAreaIds()); Rows rows = dbConnect.runSqlQuery(sqlFactory); ArrayList ids = rows.toArrayList("sat_noticeid", new ArrayList()); // 封面cover RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover"); // 附件 RowsMap RowsMap = getAttachmentUrl("sat_notice", ids); 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); } } 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")); } } SQLFactory sqlFactorycount = new SQLFactory(this, "通告列表总数量查询"); sqlFactorycount.addParameter("siteid", siteid); sqlFactorycount.addParameter_in("departmentid", departmentid); sqlFactorycount.addParameter_in("userid", userid); sqlFactorycount.addParameter_in("hrid", hrid); sqlFactorycount.addParameter_in("sa_agentsid", userInfo.getAgentsId()); sqlFactorycount.addParameter_in("sa_saleareaid", userInfo.getSaleAreaIds()); Row readrow = dbConnect.runSqlQuery(0, sqlFactorycount); JSONObject object = new JSONObject(); object.put("readNum", readrow.getLong("num")); return getSucReturnObject().setData(rows).setTips(object).toString(); } @API(title = "通告详情") 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); for (Row row : rows) { Rows Rows = attRowsMap.get(row.getString("sat_noticeid")); if (Rows.isEmpty()) { row.put("attinfos", new Rows()); } else { row.put("attinfos", Rows); } } return getSucReturnObject().setData(rows.get(0)).toString(); } /** * 查询阅读记录(通告留言和打分) * * @return */ @API(title = "查询阅读记录") public String queryReadRecord() throws YosException { Long sat_noticeid = content.getLong("sat_noticeid"); 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 t1.siteid = '" + siteid + "' AND t1.sat_noticeid ='" + sat_noticeid + "' AND t1.createuserid = '" + userid + "'"); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("阅读记录不存在").toString(); } return getSucReturnObject().setData(rows).toString(); } /** * 更新阅读记录(通告留言和打分) * * @return */ @API(title = "更新阅读记录") 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); sqlFactory.addParameter("hrid", hrid); sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId()); dbConnect.runSqlUpdate(sqlFactory); return getSucReturnObject().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(); } // 添加阅读记录 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); String result = "false"; 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); } } }