首页>代码>ssm进销存流程管理系统>/erp/src/cn/erp/controller/ExcelController.java
package cn.erp.controller;

import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.erp.dto.ExcelGoodsByTimeAndGys;
import cn.erp.dto.ExcelOrderNumById;
import cn.erp.pojo.TblSupplier;
import cn.erp.service.GoodsService;
import cn.erp.service.SupplierService;

/**
 * 报表中心
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value="/excel")
public class ExcelController {

	
	@Autowired
	private SupplierService supplierService;
	@Autowired
	private GoodsService goodsService;
	
	
	/**
	 * 进货报表列表页面
	 * @param model
	 * @param starttimes
	 * @param endtimes
	 * @param gysuuid
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/index.do")
	public String excelIndex(ModelMap model,String starttimes,String endtimes,Long gysuuid) throws Exception{
		//所有供应商
		List<TblSupplier> suppliers = supplierService.selAllSupplier();
		model.addAttribute("suppliers", suppliers);
		SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		Long starttime=null;
		Long endtime=null;
		if(StringUtils.isNotBlank(starttimes)){
			starttime = dateFormat.parse(starttimes).getTime();
		}
		if(StringUtils.isNotBlank(endtimes)){
			endtime = dateFormat.parse(endtimes).getTime();
		}
		//TblSupplier supplier = null;  1422782442006
		//if(StringUtils.isNotBlank(gysname)){  1422782485205
		//	 supplier = supplierService.getGysByName(gysname);
		//}
		//Long gysuuid =null;
		//if(supplier != null){
		//	 gysuuid = supplier.getUuid();
		//}
		
		if(gysuuid != null){
			//报表,根据订单时间,供应商uuid查询 商品
			List<ExcelGoodsByTimeAndGys> excelGoods=goodsService.selExcelGoodsByTimeAndGys(gysuuid,starttime,endtime);
			model.addAttribute("excelGoods", excelGoods);
		}
		model.addAttribute("starttimes", starttimes);
		model.addAttribute("endtimes", endtimes);
		model.addAttribute("gysuuid", gysuuid);
		return "bill/in/inGoods"; 
	}
	
	//详情查询,报表,根据商品id查询订单num,订单时间//暂时不用!
	@RequestMapping(value = "/excelDetails.do")
	public Object excelDetails(Long goodsuuid,HttpServletRequest request,HttpServletResponse response) throws Exception{
		response.setContentType("text/html;charset=UTF-8");
		List<ExcelOrderNumById> orderNums=goodsService.excelDetails(goodsuuid);
		PrintWriter writer = response.getWriter();
		writer.print(orderNums);
		writer.flush();
		writer.close();
		return null;
	}
	
	//excel导出
	@RequestMapping(value = "/exportExcel.do")
	public void exportExcel(String starttimes,String endtimes,Long gysuuid,HttpServletResponse response) throws Exception{
		SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		Long starttime=null;
		Long endtime=null;
		if(StringUtils.isNotBlank(starttimes)){
			starttime = dateFormat.parse(starttimes).getTime();
		}
		if(StringUtils.isNotBlank(endtimes)){
			endtime = dateFormat.parse(endtimes).getTime();
		}
		List<ExcelGoodsByTimeAndGys> excelGoods=null;
		if(gysuuid != null){
			//报表,根据订单时间,供应商uuid查询 商品
			excelGoods=goodsService.selExcelGoodsByTimeAndGys(gysuuid,starttime,endtime);
		}
		//导出
		try {
			//HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/x-execl");
			response.setHeader("Content-Disposition", "attachment;filename=" + new String("商品列表.xls".getBytes(), "ISO-8859-1"));
			ServletOutputStream outputStream = response.getOutputStream();
			goodsService.exportExcel(excelGoods, outputStream);
			if(outputStream != null){
				outputStream.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}
	
	
}
最近下载更多
lqzixi  LV4 2024年10月9日
Zyy19820821  LV2 2024年9月17日
过往烟尘  LV1 2024年7月31日
murphy  LV7 2024年7月14日
小海脑洞大开  LV11 2024年2月4日
微信网友_5986558820093952  LV4 2023年12月28日
2017143155  LV12 2023年7月20日
西域行者  LV3 2023年4月24日
我睡觉时不困  LV7 2022年12月10日
dlgaotao  LV2 2022年11月9日
最近浏览更多
benben2020 3月19日
暂无贡献等级
rxj515  LV2 3月17日
wlax99  LV12 2月17日
krispeng  LV14 1月2日
2072376767  LV2 2024年12月26日
三秋桂子  LV1 2024年12月21日
微信网友_7303446832484352 2024年12月19日
暂无贡献等级
dongandmin  LV8 2024年12月18日
WenMeng  LV9 2024年12月2日
我是你唯一的执着  LV4 2024年11月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友