/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-09
 * 描述            ：加工计划信息表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Slm.OrderManagement.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jxl.CellView;
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 jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import market.Api.Mes.impl.MesApiDesignInfoImpl;
import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.OrderManagement.mapper.SlmOrderChangeApplyMapper;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;
import market.Slm.OrderManagement.mapper.SlmOrderSplitInfoMapper;
import market.Slm.OrderManagement.service.SlmOrderChangeApplyService;
import market.Slm.OrderManagement.vo.SlmOrderChangeApply;
import market.Slm.OrderManagement.vo.SlmOrderInfo;
import market.Slm.OrderManagement.vo.SlmOrderSplitInfo;

import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.service.support.PageModel;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;
import com.ibm.icu.text.SimpleDateFormat;

@RemoteService(path="SlmOrderChangeApplyService")
public class SlmOrderChangeApplyServiceImpl extends BaseServiceImpl<SlmOrderChangeApply,Object> implements SlmOrderChangeApplyService {

	/**
	 * 查询
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmOrderChangeApply> sum){
		ResultModel rm=new ResultModel();
		SlmOrderChangeApply plan=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			String sWhere=" 1=1 ";
			if(startTime!=null&&!"".equals(startTime)){		
				sWhere+=" and to_char(create_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
				sWhere+=" and to_char(create_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			if(plan.getContract_no()!=null&&!"".equals(plan.getContract_no())){
				sWhere+=" and contract_no like '%"+plan.getContract_no()+"%' ";
				plan.setContract_no(null);
			}
			List<SlmOrderChangeApply> list=this.getMapper(SlmOrderChangeApplyMapper.class).findWithCondition(plan, sWhere, " create_time desc",0,0);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmOrderChangeApply> sum){
		ResultModel rm=new ResultModel();
		SlmOrderChangeApply apply=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			//订单改为变更中
			SlmOrderInfo order=this.getMapper(SlmOrderInfoMapper.class).findById(apply.getOrder_no());
			if(order!=null){
				if("2".equals(order.getChange_flag())){
					rm.setState("500");
					rm.setMsgInfo("该订单正在变更中，请操作变更信息");
					return rm;
				}
				// ===========2019-06-14=======================
				SlmOrderSplitInfo sosi=new SlmOrderSplitInfo();
				sosi.setOrder_no(apply.getOrder_no());
				sosi.setValid_flag("1");
				int icount=this.getMapper(SlmOrderSplitInfoMapper.class).count(sosi);
				if(icount>0){
					rm.setState("500");
					rm.setMsgInfo("拆分订单无法进行变更操作");
					return rm;
				}
				// ============================================
				
				
				String id=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
				apply.setApply_id(id);
				apply.setCreate_man_no(userId);
				apply.setCreate_man_name(userName);
				apply.setCreate_time(new Date());
				apply.setValid_flag("1");
				apply.setStatus("1");		//1：待提交
				apply.setContract_no(order.getContract_no());
				apply.setContract_line_seq(order.getContract_line_seq());
				apply.setOrder_seq(order.getOrder_seq());
				this.getMapper(SlmOrderChangeApplyMapper.class).insert(apply);

				order.setChange_flag("2");
				this.getMapper(SlmOrderInfoMapper.class).update(order);
			}else{
				rm.setState("500");
				rm.setMsgInfo("未找到对应订单"+apply.getOrder_no());
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("新增失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提交
	 * plan_no
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSubmitWeb(CommonPage<SlmOrderChangeApply> sum) throws Exception{
		ResultModel rm=new ResultModel();
		SlmOrderChangeApply one_apply=sum.getObject();
		List<SlmOrderChangeApply> apply_list=sum.getObjectList();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			List<SlmOrderChangeApply> list=new ArrayList<SlmOrderChangeApply>();
			if(apply_list==null){
				apply_list=new ArrayList<SlmOrderChangeApply>();
				apply_list.add(one_apply);
			}
			for(SlmOrderChangeApply apply:apply_list){
				apply=this.getMapper(SlmOrderChangeApplyMapper.class).findById(apply.getApply_id());
				if(apply==null){
					rm.setState("500");
					rm.setMsgInfo("请检查参数");
					return rm;
				}
				if(!"1".equals(apply.getValid_flag())&&!"1".equals(apply.getStatus())){
					rm.setState("500");
					rm.setMsgInfo(apply.getOrder_no()+"数据已提交或已删除，请刷新界面");
					return rm;
				}
				list.add(apply);
			}
			for(SlmOrderChangeApply apply:list){
				SlmOrderInfo order=this.getMapper(SlmOrderInfoMapper.class).findById(apply.getOrder_no());
				if(order!=null){
					//  调用生产接口判断能否通过 修改订单状态
					String order_no=order.getContract_no()+order.getContract_line_seq()+order.getOrder_seq();
					boolean pass=this.getBean(MesApiDesignInfoImpl.class).canOrderChange(order_no,apply.getChange_content());
					apply.setUpdate_man_no(userId);
					apply.setUpdate_man_name(userName);
					apply.setUpdate_time(new Date());
					if(pass){
						apply.setStatus("3");  			//通过
						//通过，订单变更状态 change_flag=4 可变更
						order.setChange_flag("4");
						//生产接口
						this.getBean(MesApiDesignInfoImpl.class).updateOrderStatus(order_no);
					}else{
						apply.setStatus("4");  			//不通过
						//通过，订单变更状态 change_flag=0 未变更
						order.setChange_flag("0");
					}
					this.getMapper(SlmOrderInfoMapper.class).update(order);
					this.getMapper(SlmOrderChangeApplyMapper.class).update(apply);
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("编辑失败"+e.getMessage());
			e.printStackTrace();
			throw e;
		}
		return rm;
	}

	/**
	 * 编辑
	 * plan_no
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<SlmOrderChangeApply> sum){
		ResultModel rm=new ResultModel();
		SlmOrderChangeApply apply=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			apply.setUpdate_man_no(userId);
			apply.setUpdate_man_name(userName);
			apply.setUpdate_time(new Date());
			this.getMapper(SlmOrderChangeApplyMapper.class).update(apply);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("编辑失败"+e.getMessage());
			e.printStackTrace();
			throw e;
		}
		return rm;
	}

	/**
	 * 删除
	 * plan_no
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteWeb(CommonPage<SlmOrderChangeApply> sum){
		ResultModel rm=new ResultModel();
		SlmOrderChangeApply apply=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			//订单改为变更中
			apply=this.getMapper(SlmOrderChangeApplyMapper.class).findById(apply.getApply_id());
			if(apply!=null&&"1".equals(apply.getStatus())){
				apply.setDelete_man_no(userId);
				apply.setDelete_man_name(userName);
				apply.setDelete_time(new Date());
				apply.setValid_flag("0");
				this.getMapper(SlmOrderChangeApplyMapper.class).update(apply);
				SlmOrderInfo order=this.getMapper(SlmOrderInfoMapper.class).findById(apply.getOrder_no());
				if(order!=null){
					order.setChange_flag("0");
					this.getMapper(SlmOrderInfoMapper.class).update(order);
				}
			}else{
				rm.setState("500");
				rm.setMsgInfo("只允许删除待提交的数据");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("编辑失败"+e.getMessage());
			e.printStackTrace();
			throw e;
		}
		return rm;
	}
	
	/**
	 * 导出
	 * */
	@SuppressWarnings("unchecked")
	public ResultModel doExportWeb(CommonPage<SlmOrderInfo> sum){
		ResultModel rm=new ResultModel();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			ResultModel re_rm=this.getBean(SlmOrderInfoServiceImpl.class).doQueryWeb(sum);
			PageModel<SlmOrderInfo> pm=(PageModel<SlmOrderInfo>) re_rm.getData();
			List<SlmOrderInfo> list=pm.getRows();
			// 2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator; // 临时保存路径
			File dir = new File(path);
			if (!dir.exists()) {
				new File(path).mkdir();
			}
			generateExcel(rm, list, path,startTime,endTime);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("导出失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 导出
	 * **/
	private void generateExcel(ResultModel rm, List<SlmOrderInfo> list, String path,String startTime,String endTime)
			throws IOException, WriteException, RowsExceededException {
		String filename ="";
		if(startTime != null && !"".equals(startTime)&&endTime != null && !"".equals(endTime)){
			startTime=startTime.substring(0, 10);
			endTime=endTime.substring(0, 10);
			filename = startTime +"至"+ endTime + "下发订单";
		}else{
			filename =  "下发订单";
		}
		WritableWorkbook workbook;
		String file=filename+".xls";  //文件名
		//3. 操作EXCEL文件
		workbook = Workbook.createWorkbook(new File(path+file));
		WritableSheet sheet = workbook.createSheet("订单", 1);
		sheet.getSettings().setDefaultRowHeight(350);
		//字体  参数可自行配置
		WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
		cellFormat1.setAlignment(Alignment.CENTRE);
		cellFormat1.setWrap(true);
		cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
		
		CellView cellview=new CellView();
		cellview.setAutosize(true);
		//表头
		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, 8, 0);
		sheet.addCell(new Label(7,0,"规格",cellFormat1));
		sheet.addCell(new Label(7,1,"厚",cellFormat1));
		sheet.addCell(new Label(8,1,"宽",cellFormat1));

		sheet.mergeCells(9, 0, 9, 1);
		sheet.addCell(new Label(9,0,"重量",cellFormat1));

		sheet.mergeCells(10, 0, 12, 0);
		sheet.addCell(new Label(10,0,"价格",cellFormat1));
		sheet.addCell(new Label(10,1,"结算价",cellFormat1));
		sheet.addCell(new Label(11,1,"加工配送费",cellFormat1));
		sheet.addCell(new Label(12,1,"含税",cellFormat1));

		sheet.mergeCells(13, 0, 13, 1);
		sheet.addCell(new Label(13,0,"合同行序号",cellFormat1));
		
		sheet.mergeCells(14, 0, 14, 1);
		sheet.addCell(new Label(14,0,"订单序号",cellFormat1));
		
		sheet.mergeCells(15, 0, 15, 1);
		sheet.addCell(new Label(15,0,"产品规范码",cellFormat1));
		
		sheet.mergeCells(16, 0, 16, 1);
		sheet.addCell(new Label(16,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));
		
		sheet.mergeCells(26, 0, 26, 1);
		sheet.addCell(new Label(26,0,"供货单位",cellFormat1));
		
		sheet.mergeCells(27, 0, 27, 1);
		sheet.addCell(new Label(27,0,"供货地址",cellFormat1));
		
		sheet.mergeCells(28, 0, 28, 1);
		sheet.addCell(new Label(28,0,"收货单位",cellFormat1));
		
		sheet.mergeCells(29, 0, 29, 1);
		sheet.addCell(new Label(29,0,"收货地址",cellFormat1));
		sheet.mergeCells(30, 0, 30, 1);
		sheet.addCell(new Label(30,0,"创建人",cellFormat1));
		sheet.mergeCells(31, 0, 31, 1);
		sheet.addCell(new Label(31,0,"创建时间",cellFormat1));
		sheet.mergeCells(32, 0, 32, 1);
		sheet.addCell(new Label(32,0,"下发人",cellFormat1));
		sheet.mergeCells(33, 0, 33, 1);
		sheet.addCell(new Label(33,0,"下发时间",cellFormat1));

		WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat = new WritableCellFormat(font); 
		cellFormat.setAlignment(Alignment.LEFT);
		cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
		//时间转字符串的格式
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for(int i = 0; i < list.size(); i++) {
			//序号
			sheet.addCell(new Label(0,i+2,String.valueOf(i+1),cellFormat));
			//客户名称
			if(list.get(i).getCustomer_name() != null ) {
				sheet.addCell(new Label(1,i+2,list.get(i).getCustomer_name(),cellFormat));
			}
			//合同号
			if(list.get(i).getContract_no()!= null ) {
				sheet.addCell(new Label(2,i+2,list.get(i).getContract_no(),cellFormat));
			}
			//采购合同号
			if(list.get(i).getPurchase_contract_no()!= null ) {
				sheet.addCell(new Label(3,i+2,list.get(i).getPurchase_contract_no(),cellFormat));
			}
			//订单状态
			if(list.get(i).getOrder_flag_name()!= null ) {
				sheet.addCell(new Label(4,i+2,list.get(i).getOrder_flag_name(),cellFormat));
			}
			//钢级
			if(list.get(i).getSteel_name()!= null ) {
				sheet.addCell(new Label(5,i+2,list.get(i).getSteel_name(),cellFormat));
			}
			//订单属性
			if(list.get(i).getOrder_nature()!= null ) {
			String order_nature="原料卷";
			if("2".equals(list.get(i).getOrder_nature())) order_nature="需加工";
			if("3".equals(list.get(i).getOrder_nature())) order_nature="非计划";
				sheet.addCell(new Label(6,i+2,order_nature,cellFormat));
			}
			//厚
			if(list.get(i).getThick()!= null ) {
				sheet.addCell(new Label(7,i+2,String.valueOf(list.get(i).getThick()),cellFormat));
			}
			//宽
			if(list.get(i).getWidth()!= null ) {
				sheet.addCell(new Label(8,i+2,String.valueOf(list.get(i).getWidth()),cellFormat));
			}
			//重量
			if(list.get(i).getEstimate_weight()!= null ) {
				sheet.addCell(new Label(9,i+2,String.valueOf(list.get(i).getEstimate_weight()),cellFormat));
			}
			//结算价
			if(list.get(i).getBalance_price()!= null ) {
				sheet.addCell(new Label(10,i+2,String.valueOf(list.get(i).getBalance_price()),cellFormat));
			}
			//加工配送费
			if(list.get(i).getWork_price()!= null ) {
				sheet.addCell(new Label(11,i+2,sdf.format(list.get(i).getWork_price()),cellFormat));
			}
			//含税
			if(list.get(i).getIs_tax()!= null ) {
				String tax="是";
				if("0".equals(list.get(i).getIs_tax())) tax="否";
				sheet.addCell(new Label(12,i+2,tax,cellFormat));
			}
			//合同行序号
			if(list.get(i).getContract_line_seq()!= null ) {
				sheet.addCell(new Label(13,i+2,list.get(i).getContract_line_seq(),cellFormat));
			}
			//订单序号
			if(list.get(i).getOrder_seq()!= null ) {
				sheet.addCell(new Label(14,i+2,list.get(i).getOrder_seq(),cellFormat));
			}
			//产品规范码
			if(list.get(i).getPsc_desc()!= null ) {
				sheet.addCell(new Label(15,i+2,list.get(i).getPsc_desc(),cellFormat));
			}
			//精度类型
			if(list.get(i).getPrecisicon_type_desc()!= null ) {
				sheet.addCell(new Label(16,i+2,list.get(i).getPrecisicon_type_desc(),cellFormat));
			}
			//精度等级
			if(list.get(i).getLv_desc()!= null ) {
				sheet.addCell(new Label(17,i+2,list.get(i).getLv_desc(),cellFormat));
			}
			//工艺要求
			if(list.get(i).getProcess()!= null ) {
				sheet.addCell(new Label(18,i+2,list.get(i).getProcess(),cellFormat));
			}
			//卷号
			if(list.get(i).getPlan_memo()!= null ) {
				sheet.addCell(new Label(19,i+2,list.get(i).getPlan_memo(),cellFormat));
			}
			//计重方式
			if(list.get(i).getWeight_type_name()!= null ) {
				sheet.addCell(new Label(20,i+2,list.get(i).getWeight_type_name(),cellFormat));
			}
			//整卷发运
			String whole="否";
			if(list.get(i).getWhole_coil()!=null&&"1".equals(list.get(i).getWhole_coil())) whole="是";
				sheet.addCell(new Label(21,i+2,whole,cellFormat));
			//运输方案
			if(list.get(i).getSolutions_name()!= null ) {
				sheet.addCell(new Label(22,i+2,list.get(i).getSolutions_name(),cellFormat));
			}
			//产品名称
			if(list.get(i).getProd_name()!= null ) {
				sheet.addCell(new Label(23,i+2,list.get(i).getProd_name(),cellFormat));
			}
			//交货期
			if(list.get(i).getDeliver_date()!= null ) {
				sheet.addCell(new Label(24,i+2,sdf.format(list.get(i).getDeliver_date()),cellFormat));
			}
			//交货状态
			if(list.get(i).getDelivery_state_desc()!= null ) {
				sheet.addCell(new Label(25,i+2,list.get(i).getDelivery_state_desc(),cellFormat));
			}
			//供货单位
			if(list.get(i).getSupplier_unit_name()!= null ) {
				sheet.addCell(new Label(26,i+2,list.get(i).getSupplier_unit_name(),cellFormat));
			}
			//供货地址
			if(list.get(i).getSupplier_address()!= null ) {
				sheet.addCell(new Label(27,i+2,list.get(i).getSupplier_address(),cellFormat));
			}
			//收货单位
			if(list.get(i).getReciver_unit_name()!= null ) {
				sheet.addCell(new Label(28,i+2,list.get(i).getReciver_unit_name(),cellFormat));
			}
			//收货地址
			if(list.get(i).getReciver_address()!= null ) {
				sheet.addCell(new Label(29,i+2,list.get(i).getReciver_address(),cellFormat));
			}
		}
		sheet.setColumnView(0, cellview);
		sheet.setColumnView(1, cellview);
		sheet.setColumnView(2, cellview);
		sheet.setColumnView(3, cellview);
		sheet.setColumnView(4, cellview);
		sheet.setColumnView(5, cellview);
		sheet.setColumnView(6, cellview);
		sheet.setColumnView(7, cellview);
		sheet.setColumnView(8, cellview);
		sheet.setColumnView(9, cellview);
		sheet.setColumnView(10, cellview);
		sheet.setColumnView(11, cellview);
		sheet.setColumnView(12, cellview);
		sheet.setColumnView(13, cellview);
		sheet.setColumnView(14, cellview);
		sheet.setColumnView(15, cellview);
		sheet.setColumnView(16, cellview);
		sheet.setColumnView(17, cellview);
		sheet.setColumnView(18, cellview);
		sheet.setColumnView(19, cellview);
		sheet.setColumnView(20, cellview);
		sheet.setColumnView(21, cellview);
		sheet.setColumnView(22, cellview);
		sheet.setColumnView(23, cellview);
		sheet.setColumnView(24, cellview);
		sheet.setColumnView(25, cellview);
		sheet.setColumnView(26, cellview);
		sheet.setColumnView(27, cellview);
		sheet.setColumnView(28, cellview);
		sheet.setColumnView(29, cellview);
		
		sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
		sheet.getSettings().setVerticalFreeze(2);  		//首行冻结
		//关闭
		workbook.write();
		workbook.close();

		rm.setData("/download?filename="+file);
	}
}
