📄 itemgroupaction.java
字号:
package com.easyjf.item.action;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import com.easyjf.bbs.business.ActiveUser;
import com.easyjf.bbs.business.UserInfo;
import com.easyjf.item.business.ItemGroup;
import com.easyjf.item.business.ItemUserRole;
import com.easyjf.util.CommUtil;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.AbstractCrudAction;
import com.easyjf.web.tools.DbPageList;
import com.easyjf.web.tools.IActiveUser;
import com.easyjf.web.tools.IPageList;
import com.easyjf.web.tools.ListQuery;
import com.easyjf.web.tools.PageList;
public class ItemGroupAction extends AbstractCrudAction {
public Page doApprove(WebForm form, Module module){
ActiveUser u=(ActiveUser)this.getCurrentUser(form);
ItemGroup obj=(ItemGroup)form2Obj(form);
if(u==null || (!"admin".equals(u.getUserName().trim())))return new Page("popedomError","/bbs/norights.htm","page");
if((obj.getStatus()!=null) && (obj.getStatus().intValue()==2))
{
obj.setStatus(new Integer(0));
}
else
{
obj.setStatus(new Integer(2));
obj.setApproveTime(new Date());
obj.setApproveUser(u.getUserName());
}
obj.update();
form.addResult("msg","操作成功!");
return super.doQuery(form,module,this.getCurrentUser(form));
}
public Page doJoin(WebForm form, Module module)
{
ActiveUser u=(ActiveUser)this.getCurrentUser(form);
if(u==null){
form.addResult("msg","请先登录!");
return new Page("login","/bbs/login.html","template");
}
ItemUserRole role=ItemUserRole.getUserRole(null,u);
if(!role.isMember())
{
form.addResult("msg","只有EasyJF开源团队的正式成员,才能申请加入项目!");
return super.doQuery(form,module,u);
}
ItemGroup obj=(ItemGroup)form2Obj(form);
if(obj.addMember(UserInfo.readByUserName(u.getUserName())))
{
form.addResult("msg","申请加入成功!");
}
else
{
form.addResult("msg","申请加入失败,可能是你已经提交过申请!");
}
return doGroupMember(form,module);
}
public Page doGroupMember(WebForm form, Module module)
{
int currentPage=CommUtil.null2Int(form.get("page"));
int pageSize=CommUtil.null2Int(form.get("pageSize"));
String cid=CommUtil.null2String(form.get("cid"));
ItemGroup group=ItemGroup.read(cid);
if(currentPage<1)currentPage=1;
if(pageSize<1)pageSize=15;
if(group!=null){
form.addPo(group);
IPageList pList=new PageList(new ListQuery(group.groupMembers()));
pList.doList(pageSize,currentPage,"","");
if(pList!=null){
List members=pList.getResult();
/*
for(int i=0;i<members.size();i++)
{
Map map=new HashMap();
String userName=(String)((DBObject)members.get(i)).get("userName");
map.put("userName",userName);
UserInfo u=UserInfo.readByUserName(userName);
members.set(i,));
}*/
form.addResult("list",members);
form.addResult("pages",new Integer(pList.getPages()));
form.addResult("rows",new Integer(pList.getRowCount()));
form.addResult("page",new Integer(pList.getCurrentPage()));
form.addResult("gotoPageHTML",CommUtil.showPageHtml(pList.getCurrentPage(),pList.getPages()));
}
}
return module.findPage("member");
}
public IPageList doQuery(WebForm form, int currentPage, int pageSize) {
//ActiveUser u=(ActiveUser)this.getCurrentUser(form);
String scope="1=1";
Collection paras=new ArrayList();
String orderType=CommUtil.null2String(form.get("orderType"));
String orderField=CommUtil.null2String(form.get("orderField"));
if(orderField.equals(""))
{
orderField="inputTime";
orderType="desc";
}
if(!orderField.equals(""))
{
scope +=" order by "+orderField;
if(!orderType.equals(""))scope+=" "+orderType;
}
DbPageList pList=new DbPageList(ItemGroup.class,scope,paras);
pList.doList(currentPage,pageSize);
return pList;
}
public void doInit(WebForm form, Module module) {
// TODO Auto-generated method stub
}
public IActiveUser getCurrentUser(WebForm form) {
ActiveUser user=(ActiveUser)ActionContext.getContext().getSession().getAttribute("bbsuser");
return user;
}
public Object doBefore(WebForm form, Module module) {
String command=(String)form.get("easyJWebCommand");
//"add".equals(command)||
if("edit".equals(command)||"update".equals(command)||"del".equals(command))
{
ActiveUser u=(ActiveUser)this.getCurrentUser(form);
ItemGroup obj=ItemGroup.read((String)form.get("cid"));
if(obj!=null)
{
String manager=obj.getManager();
if(manager==null || "".equals(manager))manager=obj.getInputUser();
//System.out.println("管理员:"+manager);
if(u==null || (!("admin".equals(u.getUserName().trim()) || u.getUserName().trim().equals(manager.trim()))))return new Page("popedomError","/bbs/norights.htm","page");
}
}
return null;
}
public void doAfter(WebForm form, Module module) {
// TODO Auto-generated method stub
}
public Object form2Obj(WebForm form) {//doAdd,Edit,Del
String cid=CommUtil.null2String(form.get("cid"));
ItemGroup obj=null;
if(cid.equals(""))
{
obj=(ItemGroup)form.toPo(ItemGroup.class);
obj.setInputTime(new Date());
ActiveUser u=(ActiveUser)this.getCurrentUser(form);
obj.setInputUser(u!=null?u.getUserName():"guest");
obj.setStatus(new Integer(-1));
}
else
{
obj=ItemGroup.read(cid);
form.toPo(obj);
}
return obj;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -