package com.report.invest.web.actions;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.spsoft.framework.security.AuthenticatorHolder;
import com.spsoft.framework.security.ClientSession;
import com.spsoft.framework.struts.BasePerformAction;
import com.spsoft.global.service.Services;
import com.spsoft.report.invest.domain.MonthadviceplanReport;
import com.spsoft.report.invest.service.YearadviceplanService;
import com.spsoft.report.invest.web.forms.MonthadviceplanForm;
import com.spsoft.sysmgr.service.SysCorpService;
/**
* @author gjy
*
*/
public class QueryMonthAdvicePlanToExcelAction extends BasePerformAction {
// 标题长度
private final short TITLE_COL_LEN = 20;
// 标题
private final short TITLE_COL = 0;
// 说明
private final short DESC_COL = 0;
//项目信息
private final short ettprojInfo_COL =0;
//项目名称
private final short ettprojname_COL =0;
//项目编号
private final short code_COL =1;
//年度资金计划
private final short YEARFUNDPLAN_COL =2;
//当年计划
private final short yearfundplannow_COL =2;
//剩余计划
private final short sparePlan_COL =3;
//到上季末累计资金计划
private final short totalfundplan_COL =4;
//建议季度资金计划
private final short fundplanadvice_COL =5;
// 合计
private final short sum_COL =5;
//本季工程款预付
private final short engineeringadvance_COL =6;
//第一月
private final short engineeringadvance1_COL =6;
//第二月
private final short engineeringadvance2_COL =7;
//第三月
private final short engineeringadvance3_COL =8;
//本季物资款预付
private final short monthadviceplanid_COL =9;
//第一月
private final short monthadviceplanid1_COL =9;
//第二月
private final short monthadviceplanid2_COL =10;
//第三月
private final short monthadviceplanid3_COL =11;
//上季工程款结算
private final short upengineeringadvance_COL =12;
//第一月
private final short upengineeringadvance1_COL =12;
//第二月
private final short upengineeringadvance2_COL =13;
//第三月
private final short upengineeringadvance3_COL =14;
//上季物资款结算
private final short upmonthadvice_COL =15;
//第一月
private final short upmonthadvice1_COL =15;
//第二月
private final short upmonthadvice2_COL =16;
//第三月
private final short upmonthadvice3_COL =17;
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
YearadviceplanService service = (YearadviceplanService) Services
.GetService(YearadviceplanService.SERVICE_NAME);
MonthadviceplanForm objForm = (MonthadviceplanForm) form;
ClientSession clientSession = AuthenticatorHolder.getClientSession();
String userCode = clientSession.getUser().getUserCode();
HashMap map = new HashMap();
if (objForm.getYear() != null && !objForm.getYear().equals("")) {
map.put("year", objForm.getYear());
objForm.setYear(objForm.getYear());
} else {
Calendar date = Calendar.getInstance();
map.put("year", date.get(Calendar.YEAR) + "");
objForm.setYear(date.get(Calendar.YEAR) + "");
}
if (objForm.getQuarter() != null && !objForm.getQuarter().equals("")) {
if (objForm.getQuarter().equals("1")) {
map.put("month1", "1");
map.put("month2", "2");
map.put("month3", "3");
} else if (objForm.getQuarter().equals("2")) {
map.put("month1", "4");
map.put("month2", "5");
map.put("month3", "6");
} else if (objForm.getQuarter().equals("3")) {
map.put("month1", "7");
map.put("month2", "8");
map.put("month3", "9");
} else if (objForm.getQuarter().equals("4")) {
map.put("month1", "10");
map.put("month2", "11");
map.put("month3", "12");
}
} else {
map.put("month1", "1");
map.put("month2", "2");
map.put("month3", "3");
}
String vol = request.getParameter("voltageGrade");
String corpId = request.getParameter("corp");
String isAll = request.getParameter("recursive");
request.setAttribute("voltageGrade", vol);
request.setAttribute("corp", corpId);
request.setAttribute("recursive", isAll);
SysCorpService sysCorpService = (SysCorpService) Services.GetService(SysCorpService.SERVICE_NAME);
String corpCode = null;
if (corpId != null) {
corpCode = sysCorpService.getCode(Long.decode(corpId));
}
if (vol != null && !vol.equals("10")) {
map.put("vol", vol);
}
if (isAll != null && isAll.equals("true")) {
if (corpCode != null) {
map.put("corpCode", corpCode + "%");
}
map.put("isAll", "true");
} else {
if (corpCode != null) {
map.put("corpCode", corpCode);
}
map.put("isAll", "false");
}
map.put("userName", userCode);
List list = service.queryMonthPageReport(map);
//把你查出要倒出的记录放入List调用export()方法就行了
try {
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename="
+ new String("季度投资和资金建议计划填报.xls".getBytes("GBK"),"ISO-8859-1"));
export(list, response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.pr