first commit
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙WEB容器(zhiqim_httpd)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_httpd.htm
|
||||
*
|
||||
* This file is part of [zhiqim_httpd].
|
||||
*
|
||||
* [zhiqim_httpd] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_httpd] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_httpd].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.announcement.action;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.announcement.dbo.ZoaAnnouncement;
|
||||
import org.zhiqim.announcement.dbo.ZoaAnnouncementEx;
|
||||
import org.zhiqim.announcement.dbo.ZoaAnnouncementReader;
|
||||
import org.zhiqim.httpd.HttpRequest;
|
||||
import org.zhiqim.httpd.HttpSessionManager;
|
||||
import org.zhiqim.httpd.HttpSessionUser;
|
||||
import org.zhiqim.httpd.HttpWebsocketConnection;
|
||||
import org.zhiqim.httpd.context.extend.StdSwitchAction;
|
||||
import org.zhiqim.httpd.validate.ones.IsIntegerValue;
|
||||
import org.zhiqim.httpd.validate.ones.IsLen;
|
||||
import org.zhiqim.httpd.validate.ones.IsNotEmpty;
|
||||
import org.zhiqim.kernel.paging.PageResult;
|
||||
import org.zhiqim.kernel.util.Ids;
|
||||
import org.zhiqim.kernel.util.Sqls;
|
||||
import org.zhiqim.orm.ORM;
|
||||
import org.zhiqim.orm.dbo.Selector;
|
||||
import org.zhiqim.orm.dbo.Updater;
|
||||
|
||||
/**
|
||||
* 公告管理,支持公告的增加、修改和删除权限
|
||||
*
|
||||
* @version v1.0.0 @author duanxiaohui 2017-11-13 新建与整理
|
||||
*/
|
||||
public class AnnouncementAction extends StdSwitchAction
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void validateId(HttpRequest request)
|
||||
{
|
||||
request.addValidate(new IsNotEmpty("announcementId", "请选择一个选项"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateForm(HttpRequest request)
|
||||
{
|
||||
request.addValidate(new IsLen("announcementTitle", "公告标题不能为空,[1, 60]范围", 1, 60));
|
||||
request.addValidate(new IsIntegerValue("announcementType", "公告类型请选择一项", 1, 3));
|
||||
request.addValidate(new IsLen("announcementContent", "公告内容不能为空,[1, 1000]范围", 1, 1000));
|
||||
}
|
||||
|
||||
protected void item(HttpRequest request) throws Exception
|
||||
{
|
||||
long announcementId = request.getParameterLong("announcementId");
|
||||
ZoaAnnouncement item = ORM.table().item(ZoaAnnouncement.class, announcementId);
|
||||
if (item == null)
|
||||
{
|
||||
request.returnHistory("该公告不存在或数据不完整!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ORM.table().count(ZoaAnnouncementReader.class, announcementId, request.getSessionName()) == 0)
|
||||
{//未读的,更新为已读
|
||||
ZoaAnnouncementReader reader = new ZoaAnnouncementReader();
|
||||
reader.setAnnouncementId(announcementId);
|
||||
reader.setOperatorCode(request.getSessionName());
|
||||
ORM.table().insert(reader);
|
||||
}
|
||||
|
||||
request.setAttribute("item", item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void list(HttpRequest request) throws Exception
|
||||
{
|
||||
int pageNo = request.getParameterInt("page", 1);
|
||||
int pageSize = request.getContextAttributeInt("fmr_page_size", 20);
|
||||
|
||||
Selector selector = new Selector();
|
||||
selector.addJoin(ZoaAnnouncementReader.class, new Selector("operatorCode", request.getSessionName()));
|
||||
selector.addMaybeLike("announcementTitle", request.getParameter("announcementTitle"));
|
||||
selector.addMust("announcementStatus", 0);
|
||||
selector.addOrderbyDesc("announcementTime");
|
||||
|
||||
PageResult<ZoaAnnouncementEx> result = ORM.view().page(ZoaAnnouncementEx.class, pageNo, pageSize, selector);
|
||||
result.addConditionMap(request.getParameterMap());
|
||||
|
||||
request.setAttribute("result", result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void add(HttpRequest request) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void insert(HttpRequest request) throws Exception
|
||||
{
|
||||
String announcementTitle = request.getParameter("announcementTitle");
|
||||
int announcementType = request.getParameterInt("announcementType");
|
||||
String announcementContent = request.getParameter("announcementContent");
|
||||
|
||||
ZoaAnnouncement item = new ZoaAnnouncement();
|
||||
item.setAnnouncementId(Ids.longId());
|
||||
item.setAnnouncementTitle(announcementTitle);
|
||||
item.setAnnouncementType(announcementType);
|
||||
item.setAnnouncementStatus(0);
|
||||
item.setAnnouncementContent(announcementContent);
|
||||
item.setAnnouncementTime(Sqls.nowTimestamp());
|
||||
item.setAnnouncementPublisher(request.getSessionName());
|
||||
|
||||
ORM.table().insert(item);
|
||||
|
||||
//对所有连上来的WS进行消息推送
|
||||
HttpSessionManager manager = request.getContext().getSessionManager();
|
||||
List<HttpSessionUser> list = manager.getSessionUserList();
|
||||
for (HttpSessionUser sessionUser : list)
|
||||
{
|
||||
List<HttpWebsocketConnection> connList = request.getContext().getWebsocketManager().get("zoa_announcement", sessionUser.getSessionId());
|
||||
for (HttpWebsocketConnection conn : connList)
|
||||
{
|
||||
conn.send("zoa_announcement_new");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(HttpRequest request) throws Exception
|
||||
{//实际为修改为已删除状态
|
||||
|
||||
Updater updater = new Updater();
|
||||
updater.addMust("announcementId", request.getParameterLong("announcementId"));
|
||||
updater.addField("announcementStatus", 1);
|
||||
|
||||
ORM.table().update(ZoaAnnouncement.class, updater);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
//不支持修改
|
||||
/****************************************************************************************/
|
||||
|
||||
@Override
|
||||
protected void modify(HttpRequest request) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update(HttpRequest request) throws Exception
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user