你好BANQ,你覺的execute方法中的迴圈程式碼和組裝respMsg物件的程式碼有沒有必要在這個類中再加兩個方法封裝

xysniper發表於2006-12-31
package com.moloon.sonny.action;

import java.util.Iterator;
import java.util.List;

import com.moloon.aslan.core.Item;
import com.moloon.aslan.core.Request;
import com.moloon.aslan.core.Response;
import com.moloon.aslan.core.support.ActionSupport;
import com.moloon.framework.exception.ServiceException;
import com.moloon.framework.page.Page;
import com.moloon.sonny.message.request.CircleAlbumInfoMessage;
import com.moloon.sonny.message.response.CircleAlbumInfoRespMessage;
import com.moloon.sonny.message.response.ErrorRespMessage;
import com.moloon.sonny.message.response.item.AlbumUserInfoRespItem;
import com.moloon.sonny.message.response.item.SimpleCircleItem;
import com.moloon.sonny.pojo.Troop;
import com.moloon.sonny.service.CircleService;
import com.moloon.sonny.service.UserBaseInfoService;
import com.moloon.sonny.util.PageCalculator;
import com.moloon.sonny.vo.PhotoListVO;
import com.moloon.sonny.vo.SmsUserBaseInfoVO;

/**
* 請求圈相簿資訊
*
* @author lvyg
* @version 1.1, 2006-12-7
* @since JDK1.5
*/
public class LoadCircleAlbumAction extends ActionSupport {
private CircleService circleService;
private UserBaseInfoService baseInfoService;
private int pageStep = 10;

public UserBaseInfoService getBaseInfoService() {
return baseInfoService;
}

public void setBaseInfoService(UserBaseInfoService baseInfoService) {
this.baseInfoService = baseInfoService;
}

/**
* @return Returns the pageStep.
*/
public int getPageStep() {
return pageStep;
}

/**
* @param pageStep
* The pageStep to set.
*/
public void setPageStep(int pageStep) {
this.pageStep = pageStep;
}

/**
* @return Returns the circleService.
*/
public CircleService getCircleService() {
return circleService;
}

/**
* @param circleService
* The circleService to set.
*/
public void setCircleService(CircleService circleService) {
this.circleService = circleService;
}

@Override
public String execute(Request request, Response response) {
CircleAlbumInfoMessage reqMsg = (CircleAlbumInfoMessage) request
.getMessage();
Page page = new Page();
page.setCurrPageNo(reqMsg.getPageId());
page.setPageSize(pageStep);
PageCalculator pageBar = new PageCalculator(page);
List list = null;
try {
list = circleService.getPhotoUserInfo(String.valueOf(reqMsg
.getCricleId()), page);

Item[] albumUserInfoItem = null;
if (list != null&&list.size()>0) {
albumUserInfoItem=new AlbumUserInfoRespItem[list.size()];
Iterator it = list.iterator();
int i=0;
while(it.hasNext()) {
PhotoListVO photoVo = (PhotoListVO) it.next();
AlbumUserInfoRespItem respItem = new AlbumUserInfoRespItem();
respItem.setName(photoVo.getUserName());
respItem.setUserId(photoVo.getUserId());
respItem.setAge(photoVo.getAge().byteValue());
respItem.setSex(photoVo.getSex().byteValue());
respItem.setProvName(photoVo.getProvinceName());
try {
SmsUserBaseInfoVO vo=baseInfoService.getUserBaseInfoVO(photoVo.getUserId());
respItem.setCircleOwner(vo.isIsTroopCreater());
} catch (Exception e) {
respItem.setCircleOwner(false);
}
albumUserInfoItem[i++] = respItem;
}
}

CircleAlbumInfoRespMessage respMsg = new CircleAlbumInfoRespMessage();
if(null == albumUserInfoItem || 0 == albumUserInfoItem.length) {
respMsg.setUserNum(0);
} else {
respMsg.setUserNum(albumUserInfoItem.length);
respMsg.setAlbumUserInfoItem(albumUserInfoItem);
}
respMsg.setBackPage(pageBar.getFront());// 上一頁
respMsg.setNextPage(pageBar.getBack());// 下一頁
respMsg.setSessionId(reqMsg.getSessionId());
respMsg.setSequence(reqMsg.getSequence());
response.write(respMsg);
} catch (ServiceException e) {
ErrorRespMessage errMsg = new ErrorRespMessage();
errMsg.setSequence(reqMsg.getSequence());
errMsg.setSessionId(reqMsg.getSessionId());
response.write(errMsg);
}
return null;
}
}

相關文章