| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- 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<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
- // 封面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<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
- 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);
- }
- }
- }
|