/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-10-17
 * 描述            ：平整计划进程表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Tpm.Design.impl;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import market.Api.Mes.impl.Utils;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Tpm.Design.mapper.PlnSkinrollingDsnMainMapper;
import market.Mes.Tpm.Design.service.PlnSrPlanStatisticService;
import market.Mes.Tpm.Design.vo.PlnSkinrollingDsnMain;
import market.Mes.Tpm.Design.vo.PlnSkinrollingDsnMultinfoSum;
import market.Mes.Tpm.Design.vo.PlnSrPlanStatistic;
import market.Mes.Tpm.mapper.PlnSkinrollingPlanMapper;
import market.Mes.Tpm.vo.PlnSkinrollingPlan;

import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path="PlnSrPlanStatisticService")
public class PlnSrPlanStatisticServiceImpl extends BaseServiceImpl<PlnSrPlanStatistic,Object> implements PlnSrPlanStatisticService {

	/**
	 * 查询待编制计划钢卷
	 * memo1 1为计划时间 2为交货时间
	 * memo2 外径下限值
	 * memo3 外径上限值
	 * memo4 平整计划号
	 * */
	public ResultModel doQueryWaitPlanWeb(CommonPage<PlnSkinrollingDsnMain> sum){
		ResultModel rm=new ResultModel();
		
		try{
			// 工序点信息
			ComBaseInfo infoI = this.getMapper(ComBaseInfoMapper.class).findById("200204");
			String sWhere1="",sWhere2="",sWhere3="";
			//假如为1则为下发生产时间  为2交货时间 
			if("2".equals(sum.getMemo1())){
				sWhere1+=" and t3.deliver_date between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ";
			}else if ("4".equals(sum.getMemo1())) {
				sWhere1+=" and t3.create_time between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ";
			}

			if(sum.getMemo2()!=null&&!"".equals(sum.getMemo2())){
				sWhere3+=" and t1.diameter_out>="+sum.getMemo2();
			}
			if(sum.getMemo3()!=null&&!"".equals(sum.getMemo3())){
				sWhere3+=" and t1.diameter_out<="+sum.getMemo3();
			}
			if(sum.getMemo4()!=null&&!"".equals(sum.getMemo4().trim())){
				sWhere3+=" and t1.sr_plan_no like '%"+sum.getMemo4().trim()+"%'";
			}

			PlnSkinrollingDsnMain pdm=(sum.getObject()==null?(new PlnSkinrollingDsnMain()):sum.getObject());
			if(sum.getObject()!=null){
				//条件2
				if(sum.getObject().getOrder_no()!=null
						&&!"".equals(sum.getObject().getOrder_no().trim())){
					sWhere2+=" and t2.order_no like '%"+sum.getObject().getOrder_no().trim()+"%' ";
				}
				if(sum.getObject().getProd_order_no()!=null
						&&!"".equals(sum.getObject().getProd_order_no().trim())){
					sWhere2+=" and t2.prod_order_no like '%"+sum.getObject().getProd_order_no().trim()+"%' ";
				}
			}
			rm.setData(this.getMapper(PlnSkinrollingDsnMainMapper.class).doQueryWaitPlan(sWhere1, sWhere2, sWhere3,pdm,infoI.getMemo()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询出错！");
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	// 调整计划序号 2018-12-18
	// 表计划旧 计划号-顺序号
	Map<String, Integer> v_planno_old = new HashMap<String, Integer>();
		
	/**
	 * 查询已编制平整计划
	 * memo1 1为计划时间 2为交货时间
	 * memo2 外径下限值
	 * memo3 外径上限值
	 * memo4 平整计划号
	 * */
	public ResultModel doQueryCompletePlanWeb(CommonPage<PlnSkinrollingDsnMain> sum){
		ResultModel rm=new ResultModel();
		v_planno_old.clear();
		try{
			StringBuffer sWhere0 = new StringBuffer();
			StringBuffer sWhere1 = new StringBuffer();
			StringBuffer sWhere2 = new StringBuffer();
			StringBuffer sWhere3 = new StringBuffer();
			//假如为1则为计划时间  为2交货时间 
			if("1".equals(sum.getMemo1())){
				sWhere0.append(" and t6.send_date between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ");
			}else if("2".equals(sum.getMemo1())){
				sWhere1.append(" and P.deliver_date between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ");
			}else if("3".equals(sum.getMemo1())){
				sWhere1.append(" and ttt.feeding_time between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ");
			}else if ("4".equals(sum.getMemo1())) {
				sWhere1.append(" and P.create_time between to_date('"+sum.getStartTime()+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+sum.getEndTime()+"','yyyy-MM-dd HH24:mi:ss') ");
			}

			if(sum.getMemo2()!=null&&!"".equals(sum.getMemo2())){
				sWhere3.append(" and t1.diameter_out>="+sum.getMemo2());
			}
			if(sum.getMemo3()!=null&&!"".equals(sum.getMemo3())){
				sWhere3.append(" and t1.diameter_out<="+sum.getMemo3());
			}
			if(sum.getMemo4()!=null&&!"".equals(sum.getMemo4().trim())){
				sWhere3.append(" and t1.sr_plan_no like '%"+sum.getMemo4().trim()+"%'");
			}

			PlnSkinrollingDsnMain pdm=(sum.getObject()==null?(new PlnSkinrollingDsnMain()):sum.getObject());
			if(sum.getObject()!=null){
				//条件2
				if(sum.getObject().getOrder_no()!=null
						&&!"".equals(sum.getObject().getOrder_no().trim())){
					sWhere2.append(" and P.order_no like '%"+sum.getObject().getOrder_no().trim()+"%' ");
				}
				if(sum.getObject().getProd_order_no()!=null
						&&!"".equals(sum.getObject().getProd_order_no().trim())){
					sWhere2.append(" and P.prod_order_no like '%"+sum.getObject().getProd_order_no().trim()+"%' ");
				}
				
				// 增加状态筛选框默认不显示已完成的计划
				if(StringUtils.isEmpty(sum.getObject().getStatus())) {
					sWhere0.append(" and t6.status != '5BSR10' ");
				} else if (!sum.getObject().getStatus().equals("0")) {
					sWhere0.append(" and t6.status = '"+sum.getObject().getStatus()+"'");
				}
			}
			List<PlnSkinrollingDsnMultinfoSum> listPSum = this.getMapper(PlnSkinrollingDsnMainMapper.class).doQueryCompletePlan(sWhere0.toString(),sWhere1.toString(), sWhere2.toString(), sWhere3.toString(),pdm);
			for(PlnSkinrollingDsnMultinfoSum orders:listPSum){
				// 在界面查询刷新后，赋值 V_PlanNo 和 V_PlanSeq_Old
				v_planno_old.put(orders.getSr_plan_no(), orders.getPlan_seq());
				//加工计划备注PlnProcessPlan
//				PlnProcessPlan pplan=new PlnProcessPlan();
//				pplan.setOrder_no(orders.getOrder_no());
//				pplan.setCut_order_no(1L);
//				// SELECT PLAN_NO,PRODUCE_NO,CUT_ORDER_NO,ORDER_NO,PURCHASE_CONTRACT_NO,STEEL_CODE,STEEL_NAME,SPEC,MAT_WIDTH,MAT_THICK,MAT_LENGTH,MAT_DIAMETER_INN,MAT_DIAMETER_OUT,MAT_ESTIMATE_WEIGHT,WIDTH,THICK,LENGTH,DIAMETER_INN,DIAMETER_OUT,ESTIMATE_WEIGHT,CUT_STYLE,CROSSCUT_STYLE,CUT_TYPE,CUT_NUM,REMARK,VALID_FLAG,CREATE_MAN_NAME,CREATE_TIME,UPDATE_MAN_NAME,UPDATE_TIME FROM PLN_PROCESS_PLAN WHERE CUT_ORDER_NO = 1 AND ORDER_NO = 'YTGD-0329010001'
//				List<PlnProcessPlan> planList=this.getMapper(PlnProcessPlanMapper.class).findWithCondition(pplan, "", null, 0, 0);
//				if(planList.size()>0){
//					//关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
//					orders.setProcessMemo(planList.get(0).getRemark());
//				}
			}
			rm.setData(listPSum);
			rm.setState("200");

		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询出错！");
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	/**
	 * 动作处理_移动确认按钮
	 * 
	 * @param sum V_PlanNo--按顺序保存左表计划号 查询的时候保存 V_PlanSeq_Old--按顺序保存左表计划顺序号
	 *            V_PlanSeq_New
	 * @return
	 * @throws Exception 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doMove(CommonPage<PlnSkinrollingPlan> sum) throws Exception {
		ResultModel rm = new ResultModel();
		// 记录计划号index用于查找对应循序号
		Integer i = 0;
		List<PlnSkinrollingPlan> plns = sum.getObjectList();
		PlnSkinrollingPlan p = new PlnSkinrollingPlan();
		for (PlnSkinrollingPlan pln : plns) {
			i = v_planno_old.get(pln.getSr_plan_no());
			if (i == 0) {
				throw new Exception("调整计划顺序失败。计划[" + pln.getSr_plan_no() + "]的顺序或状态已经改变，请刷新重试。");
			}
			p.setSr_plan_no(pln.getSr_plan_no());
			List<PlnSkinrollingPlan> plrp = this.getMapper(PlnSkinrollingPlanMapper.class).find(p, 0, 0);
			if (plrp == null || plrp.size() == 0) {
				throw new Exception("计划信息[" + pln.getSr_plan_no() + "]不存在！");
			}
//			if (!"0PSR01".equals(plrp.get(0).getStatus())) {
//				throw new Exception("只有已编制待下发计划允许调整循序！");
//			}
			int count = this.getMapper(PlnSkinrollingPlanMapper.class).doUpdateSeq(pln, i);
			if (count == 0) {
				throw new Exception("调整计划顺序失败。计划[" + pln.getSr_plan_no() + "]的顺序或状态已经改变，请刷新重试。");
			}
		}
		// 释放旧数据
		v_planno_old.clear();
		rm.setState("200");
		rm.setMsgInfo("调整计划循序成功!");
		return rm ; 
	}
	
	/**
	 * 报表导出
	 * */
	public ResultModel doExportCompletePlanWeb(CommonPage<PlnSkinrollingDsnMain> sum){
		ResultModel rm=new ResultModel();
		try{
			// 1，创建一个webbook，对应一个Excel文件
			WritableWorkbook workbook;
			//2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator;  //临时保存路径
			File dir = new File(path);
			if(!dir.exists()) {
				new File(path).mkdir();
			}
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat stdSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String sTime=sum.getStartTime();
			if(sTime!=null&&sTime.length()>1){
				Date sDate=sdf.parse(sTime);
				sTime=sdf.format(sDate);
			}
			String eTime=sum.getEndTime();
			if(eTime!=null&&eTime.length()>1){
				Date eDate=sdf.parse(eTime);
				eTime=sdf.format(eDate);
			}
			String filename = sTime +"至"+ eTime +  "已编制平整计划报表";
			String file=filename+".xls";  //文件名
			//3. 操作EXCEL文件
			workbook = Workbook.createWorkbook(new File(path+file));
			WritableSheet sheet = workbook.createSheet(filename, 1);
			//行高
			sheet.getSettings().setDefaultRowHeight(300);
			//列宽
			sheet.setColumnView(0,5);
			sheet.setColumnView(1,18);
			sheet.setColumnView(2,22);
			sheet.setColumnView(3,30);
			sheet.setColumnView(4,18);
			sheet.setColumnView(5,15);		//状态
			sheet.setColumnView(6,20);		//虚拟母卷号
			sheet.setColumnView(7,15);		//实物卷号
			sheet.setColumnView(8,18);
			sheet.setColumnView(9,20);
			sheet.setColumnView(10,10);		//销售备注
			sheet.setColumnView(11,10);
			sheet.setColumnView(12,10);		//产线
			sheet.setColumnView(13,10);		//机台
			sheet.setColumnView(20,15);		//平整规格
			sheet.setColumnView(23,15);		//最早交货日期
			sheet.setColumnView(24,15);		//最晚交货日期
			sheet.setColumnView(26,20);		//创建时间
			sheet.setColumnView(27,20);		//生产时间			
			//字体  参数可自行配置
			WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
			WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
			cellFormat1.setAlignment(Alignment.CENTRE);
			cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
			//表头
			sheet.mergeCells(0, 0, 0, 1);
			sheet.addCell(new Label(0,0,"序号",cellFormat1));
			sheet.mergeCells(1, 0, 1, 1);
			sheet.addCell(new Label(1,0,"合同号",cellFormat1));
			sheet.mergeCells(2, 0, 2, 1);
			sheet.addCell(new Label(2,0,"订单号",cellFormat1));
			sheet.mergeCells(3, 0, 3, 1);
			sheet.addCell(new Label(3,0,"客户名称",cellFormat1));
			sheet.mergeCells(4, 0, 4, 1);
			sheet.addCell(new Label(4,0,"平整计划号",cellFormat1));
			sheet.mergeCells(5, 0, 5, 1);
			sheet.addCell(new Label(5,0,"状态",cellFormat1));
			sheet.mergeCells(6, 0, 6, 1);
			sheet.addCell(new Label(6,0,"虚拟母卷号(母卷)",cellFormat1));
			sheet.mergeCells(7, 0, 7, 1);
			sheet.addCell(new Label(7,0,"实物卷号",cellFormat1));
			sheet.mergeCells(8, 0, 8, 1);
			sheet.addCell(new Label(8,0,"原料卷号",cellFormat1));
			sheet.mergeCells(9, 0, 9, 1);
			sheet.addCell(new Label(9,0,"销售备注",cellFormat1));
			sheet.mergeCells(10, 0, 10, 1);
			sheet.addCell(new Label(10,0,"加工计划备注",cellFormat1));
//			sheet.mergeCells(11, 0, 11, 1);
//			sheet.addCell(new Label(11,0,"产线",cellFormat1));
//			sheet.mergeCells(12, 0, 12, 1);
//			sheet.addCell(new Label(12,0,"机台",cellFormat1));
			sheet.mergeCells(11, 0, 11, 1);
			sheet.addCell(new Label(11,0,"牌号",cellFormat1));
			sheet.mergeCells(12, 0, 12, 1);
			sheet.addCell(new Label(12,0,"重量",cellFormat1));
			sheet.mergeCells(13, 0, 16, 0);
			sheet.addCell(new Label(13,0,"母卷规格",cellFormat1));
			sheet.addCell(new Label(13,1,"厚度",cellFormat1));
			sheet.addCell(new Label(14,1,"宽度",cellFormat1));
			sheet.addCell(new Label(15,1,"内径",cellFormat1));
			sheet.addCell(new Label(16,1,"外径",cellFormat1));
//			sheet.mergeCells(19, 0, 19, 1);
//			sheet.addCell(new Label(19,0,"平整数",cellFormat1));
			sheet.mergeCells(17, 0, 17, 1);
			sheet.addCell(new Label(17,0,"收货单位",cellFormat1));
			sheet.mergeCells(18, 0, 18, 1);
			sheet.addCell(new Label(18,0,"收货地址",cellFormat1));
			sheet.mergeCells(19, 0, 19, 1);
			sheet.addCell(new Label(19,0,"切边方式",cellFormat1));
			sheet.mergeCells(20, 0, 20, 1);
			sheet.addCell(new Label(20,0,"最早交货日期",cellFormat1));
			sheet.mergeCells(21, 0, 21, 1);
			sheet.addCell(new Label(21,0,"最晚交货日期",cellFormat1));
			sheet.mergeCells(22, 0, 22, 1);
			sheet.addCell(new Label(22,0,"创建人",cellFormat1));
			sheet.mergeCells(23, 0, 23, 1);
			sheet.addCell(new Label(23,0,"创建时间",cellFormat1));
			sheet.mergeCells(24, 0, 24, 1);
			sheet.addCell(new Label(24,0,"生产时间",cellFormat1));
//			sheet.mergeCells(25, 0, 25, 1);
//			sheet.addCell(new Label(25,0,"合计",cellFormat1));

			WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
			WritableCellFormat cellFormat = new WritableCellFormat(font); 
			cellFormat.setAlignment(Alignment.CENTRE);
			cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);

			//获取查询结果
			rm=doQueryCompletePlanWeb(sum);
			if("500".equals(rm.getState())) return rm;
			List<PlnSkinrollingDsnMultinfoSum> list=(List<PlnSkinrollingDsnMultinfoSum>) rm.getData();
			Double total_weight=0d;
			for(int v=0;v<list.size();v++){
				PlnSkinrollingDsnMultinfoSum main=list.get(v);
				sheet.addCell(new Label(0,v+2,""+(v+1),cellFormat));
				if(main.getContract_no() != null ) {
					sheet.addCell(new Label(1,v+2,main.getContract_no(),cellFormat));
				}
				if(main.getOrder_no() != null) {
					sheet.addCell(new Label(2,v+2,main.getOrder_no(),cellFormat));
				}
				if(main.getCustomer_name() != null) {
					sheet.addCell(new Label(3,v+2,main.getCustomer_name(),cellFormat));
				}
				if(main.getSr_plan_no() != null) {
					sheet.addCell(new Label(4,v+2,main.getSr_plan_no(),cellFormat));
				}
				String status_content="";
				if("5BSR10".equals(main.getStatus())) status_content="平整作业完成";
				if("5BSR01".equals(main.getStatus())) status_content="计划已编制";
				if("5BSR02".equals(main.getStatus())) status_content="计划已下发";
				if("5BSR03".equals(main.getStatus())) status_content="开始平整作业";
				sheet.addCell(new Label(5,v+2,status_content,cellFormat));
				if(main.getObject_no_vt() != null ) {
					sheet.addCell(new Label(6,v+2,main.getObject_no_vt(),cellFormat));
				}
				if(main.getObject_no() != null ) {
					sheet.addCell(new Label(7,v+2,main.getObject_no(),cellFormat));
				}
				if(main.getMaterailcoilno() != null ) {
					sheet.addCell(new Label(8,v+2,main.getMaterailcoilno(),cellFormat));
				}
				if(main.getOrder_memo() != null) {
					sheet.addCell(new Label(9,v+2,main.getOrder_memo(),cellFormat));
				}
				if(main.getProcessMemo() != null ) {
					sheet.addCell(new Label(10,v+2,main.getProcessMemo(),cellFormat));
				}
//				if(main.getPline_name() != null ) {
//					sheet.addCell(new Label(11,v+2,main.getPline_name(),cellFormat));
//				}
//				if(main.getMachine_name() != null ) {
//					sheet.addCell(new Label(12,v+2,main.getMachine_name(),cellFormat));
//				}
				if(main.getSteel_name() != null ) {
					sheet.addCell(new Label(11,v+2,main.getSteel_name(),cellFormat));
				}
				if(main.getSingle_weight() != null ) {
					sheet.addCell(new Label(12,v+2,main.getSingle_weight(),cellFormat));
					double weight=Double.parseDouble(main.getSingle_weight());
					total_weight+=weight;
				}
				if(main.getThick() != null ) {
					sheet.addCell(new Label(13,v+2,main.getThick(),cellFormat));
				}
				if(main.getWidth() != null ) {
					sheet.addCell(new Label(14,v+2,main.getWidth(),cellFormat));
				}
				if(main.getDiameter_inn() != null) {
					sheet.addCell(new Label(15,v+2,main.getDiameter_inn(),cellFormat));
				}
				if(main.getDiameter_out() != null) {
					sheet.addCell(new Label(16,v+2,main.getDiameter_out(),cellFormat));
				}
				if(main.getReciver_unit_name() != null) {
					sheet.addCell(new Label(17,v+2,main.getReciver_unit_name(),cellFormat));
				}
				if(main.getReciver_address() != null) {
					sheet.addCell(new Label(18,v+2,main.getReciver_address(),cellFormat));
				}
				String content="";
				if("102501".equals(main.getCut_edge_type_no())) content="四毛";
				if("102502".equals(main.getCut_edge_type_no())) content="二切";
				if("102503".equals(main.getCut_edge_type_no())) content="四切";
				sheet.addCell(new Label(19,v+2,content,cellFormat));

//				if(main.getCrosscut_style()==null) main.setCrosscut_style("不横切");
//				sheet.addCell(new Label(22,v+2,main.getCrosscut_style(),cellFormat));
				if(main.getDeliver_date_earliest() != null) {
					sheet.addCell(new Label(20,v+2,main.getDeliver_date_earliest(),cellFormat));
				}
				if(main.getDeliver_date_latest() != null) {
					sheet.addCell(new Label(21,v+2,main.getDeliver_date_latest(),cellFormat));
				}
				if(main.getCreate_man_name() != null ) {
					sheet.addCell(new Label(22,v+2,main.getCreate_man_name(),cellFormat));
				}
				if(main.getCreate_time() != null ) {
					Date createDate=stdSdf.parse(main.getCreate_time());
					String create_time=stdSdf.format(createDate);
					sheet.addCell(new Label(23,v+2,create_time,cellFormat));
				}
				if(main.getCharge_time() != null ) {
					Date feedingDate=stdSdf.parse(main.getCharge_time());
					String feeding_time=stdSdf.format(feedingDate);
					sheet.addCell(new Label(24,v+2,feeding_time,cellFormat));
				}
			}
//			sheet.mergeCells(0, list.size()+2, 0, 1);
			sheet.addCell(new Label(0,list.size()+2,"合计",cellFormat1));
			sheet.addCell(new Label(14,list.size()+2,String.valueOf(total_weight),cellFormat));
			sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
			sheet.getSettings().setVerticalFreeze(2);

			//关闭
			workbook.write();
			workbook.close();

			rm.setData("/download?filename="+file);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo(ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
}
