[Java] 纯文本查看 复制代码 package com.chunqiu.smp.web.tagbean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import com.chunqiu.smp.common.util.Page;
import com.chunqiu.smp.common.util.SqlParam;
import com.chunqiu.smp.web.channel.ChannelImpl;
import com.chunqiu.smp.web.channel.vo.ChannelVO;
import com.chunqiu.smp.web.event.EventImpl;
import com.chunqiu.smp.web.event.vo.EventVO;
public class EventTagBean {
private EventVO prevEvent;
private EventVO nextEvnet;
public EventVO getPrevEvent() {
return prevEvent;
}
public void setPrevEvent(EventVO prevEvent) {
this.prevEvent = prevEvent;
}
public EventVO getNextEvnet() {
return nextEvnet;
}
public void setNextEvnet(EventVO nextEvnet) {
this.nextEvnet = nextEvnet;
}
public EventImpl getImp() {
return imp;
}
public void setImp(EventImpl imp) {
this.imp = imp;
}
EventImpl imp;
public EventTagBean() {
imp = new EventImpl();
}
public Map getEvents(Map map, ServletRequest request){
Map rslt = new HashMap();
Map para = new HashMap();
String channelId = String.valueOf(map.get("tid"));
String tidType = String.valueOf(map.get("tidType")).toUpperCase();
String pageSize = map.get("pageSize") != null ? String.valueOf(map .get("pageSize")) : "20";
boolean needpage = map.get("needPage")!=null? Boolean.parseBoolean(String.valueOf(map.get("needPage"))):false;
if(channelId==null || channelId.equals("") || channelId.equals("null")){
channelId = String.valueOf(request.getAttribute("channelId"));
tidType = "ID";
}
if (channelId == null || channelId.equals("") || channelId.equals("null")) {
rslt.put("page", null);
rslt.put("list", null);
return rslt;
}
if(channelId.equals("SMP_ZERO") || channelId.equals("SMP_ROOT") || channelId.equals("SMP_PARENT")){
long chnId=0;
if(!channelId.equals("SMP_ZERO")){
chnId=Long.parseLong(String.valueOf(request.getAttribute("channelId")));
ChannelVO vo= new ChannelImpl().getChannelById(chnId);
if(vo==null){
rslt.put("list",null);
return rslt;
}
String[] ids=vo.getChannelIdPath().split("-");
if(channelId.equals("SMP_ROOT")){
chnId=Long.parseLong(ids[0]);
}else if(channelId.equals("SMP_PARENT")){
int l=ids.length;
l=l>1?l-2:l;
chnId=Long.parseLong(ids[l]);
}
}
channelId=String.valueOf(chnId);
tidType="ID";
}
if(!tidType.equals("ID")){
ChannelVO vo = new ChannelImpl().getChannelByName(channelId);
if (vo == null) {
rslt.put("page", null);
rslt.put("list", null);
return rslt;
}
channelId=String.valueOf(vo.getChannelId());
}
para.put("channelId", Long.parseLong(channelId));
para.put("pageSize", map.get("pageSize"));
para.put("startNo", 1);
para.put("includeSub", map.get("includeSub"));
para.put("where", map.get("where"));
para.put("order", map.get("orderBy"));
if (needpage) {
String page = Integer.parseInt(map.get("page").toString()) != 0 ? String .valueOf(map.get("page"))
: (request.getParameter("page") != null ? String.valueOf(request.getParameter("page")) : "1");
int cnt = imp.getEventCount(para);
Page pg = new Page(cnt, Integer.parseInt(page), Integer.parseInt(pageSize));
para.put("pageSize", pg.getPageSize());
para.put("startNo", pg.getStartRecord());
rslt.put("page", pg);
}
rslt.put("list", imp.getEventList(para));
return rslt;
}
@SuppressWarnings("unchecked")
public Map getEventData(Map map,ServletRequest request){
Map rslt = new HashMap();
String id=String.valueOf(map.get("tid"));
if(id==null || id.equals("") || id.equals("null")){
id=String.valueOf(request.getAttribute("id"));
}
if(id==null || id.equals("") || id.equals("null")){
rslt.put("data", null);
}else{
EventVO cvo =imp.getEventById(Long.parseLong(id));
Map map1 = new HashMap();
List<SqlParam> sqlParaLst1 = new ArrayList<SqlParam>();
map1.put("channelId", cvo.getEvent_channel());
map1.put("pageSize", 1);
map1.put("where", " event_id<#Id ");
map1.put("order", " event_id desc ");
map1.put("whereParas", sqlParaLst1);
sqlParaLst1.add(new SqlParam(Long.class, "#Id", cvo.getEvent_id()));
List list1 = imp.getEventList(map1);
if(list1.size()>0) cvo.setPrevEvent((EventVO)list1.get(0));
Map map2 = new HashMap();
List<SqlParam> sqlParaLst2 = new ArrayList<SqlParam>();
map2.put("channelId", cvo.getEvent_channel());
map2.put("pageSize", 1);
map2.put("where", " event_id>#Id ");
map2.put("order", " event_id asc ");
map2.put("whereParas", sqlParaLst2);
sqlParaLst2.add(new SqlParam(Long.class, "#Id", cvo.getEvent_id()));
List list2 = imp.getEventList(map2);
if(list2.size()>0) cvo.setNextEvnet((EventVO)list2.get(0));
rslt.put("data", cvo);
}
return rslt;
}
}
|