对象存储cos 下载csv

pom.xml

		<cos.sdk.version>2.0.1</cos.sdk.version>
		<cos.api.version>5.2.4</cos.api.version>
		<commons-beanutils.version>1.9.3</commons-beanutils.version>
		<commons-lang3.version>3.3.2</commons-lang3.version>
		<commons-io.version>1.3.2</commons-io.version>
		<commons-net.version>3.3</commons-net.version>
                <commons-fileupload.version>1.3.1</commons-fileupload.version>

工具类:

package com.custom.common.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;

/**
 * 文件操作
 */
public class CSV {

	/**
	 * 生成为CVS文件
	 *
	 * @param exportData
	 *            源数据List
	 * @param map
	 *            csv文件的列表头map
	 * @param outPutPath
	 *            文件路径
	 * @param fileName
	 *            文件名称
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static File createCSVFile(List<Map<String, String>> exportData, LinkedHashMap<String, String> map,
			String outPutPath, String fileName) {
		File csvFile = null;
		BufferedWriter csvFileOutputStream = null;
		try {
			File file = new File(outPutPath);
			if (!file.exists()) {
				file.mkdir();
			}
			// 定义文件名格式并创建
			csvFile = File.createTempFile(fileName, ".csv", new File(outPutPath));
			// System.out.println("csvFile:" + csvFile);
			// UTF-8使正确读取分隔符","
			csvFileOutputStream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), "GBK"),
					1024);

			// System.out.println("csvFileOutputStream:" + csvFileOutputStream);
			// ----------------------------------------------------------------
			// 竖着排列标题
            // 写入文件头部
            for (Iterator propertyIterator = map.entrySet().iterator(); propertyIterator.hasNext();) {
                java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next();
                csvFileOutputStream.write(
                        "" + (String) propertyEntry.getValue() != null ? (String) propertyEntry.getValue() : "" + "");
                csvFileOutputStream.write(",");
                for (Iterator<Map<String, String>> iterator = exportData.iterator(); iterator.hasNext();) {
                    Object row = iterator.next();
                    csvFileOutputStream.write((String) BeanUtils.getProperty(row, (String) propertyEntry.getKey()));
                    if (iterator.hasNext()) {
                        csvFileOutputStream.newLine();
                    }
                    csvFileOutputStream.flush();
                }

                csvFileOutputStream.newLine();
            }
			// ---------------------------------------------------------------
			// 横着排列标题
			for (Iterator propertyIterator = map.entrySet().iterator(); propertyIterator.hasNext();) {
				java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next();
				csvFileOutputStream.write(
						"" + (String) propertyEntry.getValue() != null ? (String) propertyEntry.getValue() : "" + "");
				if (propertyIterator.hasNext()) {
					csvFileOutputStream.write(",");
				}
			}
			csvFileOutputStream.newLine();
			// 写入文件内容
			for (Iterator<Map<String, String>> iterator = exportData.iterator(); iterator.hasNext();) {
				Object row = iterator.next();
				for (Iterator propertyIterator = map.entrySet().iterator(); propertyIterator.hasNext();) {
					java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next();
					csvFileOutputStream.write(BeanUtils.getProperty(row, (String) propertyEntry.getKey()));
					if (propertyIterator.hasNext()) {
						csvFileOutputStream.write(",");
					}
				}
				if (iterator.hasNext()) {
					csvFileOutputStream.newLine();
				}
			}
			csvFileOutputStream.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				csvFileOutputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return csvFile;
	}

	/**
	 * 下载文件
	 *
	 * @param response
	 * @param csvFilePath
	 *            文件路径
	 * @param fileName
	 *            文件名称
	 * @throws IOException
	 */

	public static void exportFile(HttpServletResponse response, String csvFilePath, String fileName)
			throws IOException {
		response.setContentType("application/csv;charset=UTF-8");
		response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));

		InputStream in = null;
		try {
			in = new FileInputStream(csvFilePath);
			int len = 0;
			byte[] buffer = new byte[1024];
			response.setCharacterEncoding("UTF-8");
			OutputStream out = response.getOutputStream();
			while ((len = in.read(buffer)) > 0) {
				out.write(new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF });
				out.write(buffer, 0, len);
			}
		} catch (FileNotFoundException e) {
			System.out.println(e);
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (Exception e) {
					throw new RuntimeException(e);
				}
			}
		}
	}

	/**
	 * 删除该目录filePath下的所有文件
	 *
	 * @param filePath
	 *            文件目录路径
	 */
	public static void deleteFiles(String filePath) {
		File file = new File(filePath);
		if (file.exists()) {
			File[] files = file.listFiles();
			for (int i = 0; i < files.length; i++) {
				if (files[i].isFile()) {
					files[i].delete();
				}
			}
		}
	}

	/**
	 * 删除单个文件
	 *
	 * @param filePath
	 *            文件目录路径
	 * @param fileName
	 *            文件名称
	 */
	public static void deleteFile(String filePath, String fileName) {
		File file = new File(filePath);
		if (file.exists()) {
			File[] files = file.listFiles();
			for (int i = 0; i < files.length; i++) {
				if (files[i].isFile()) {
					if (files[i].getName().equals(fileName)) {
						files[i].delete();
						return;
					}
				}
			}
		}
	}

	static Connection conn = null;
	static PreparedStatement pst = null;
	static ResultSet rs = null;
	static String sql;
	static String sql2;

	public static void connData(String url, String username, String password) {
		String driver = "com.mysql.jdbc.Driver";
		try {
			Class.forName(driver);

			conn = (Connection) DriverManager.getConnection(url, username, password);
			if (!conn.isClosed())
				System.out.println("Succeeded connecting to the Database!");
			else
				System.out.println("Failure connecting to the Database!");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static String createCSVfile(String startdate, String enddate) throws Exception {

		List exportData = new ArrayList();
		LinkedHashMap<String, String> datamMap = null;

		Date creatdate = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		connData("jdbc:mysql://", "root", "");

		sql = "select logistics.id,logistics.logisticscompany,logistics.logisticssheetid,logistics.createtime,logistics.sender,ordersummary.customerid from logistics join ordersummary on ordersummary.customid=logistics.customid and (logistics.createtime >= '"
				+ startdate + "' and logistics.createtime <= '" + enddate + " 11:59:59 PM')";
		sql2 = "select * from ordersummary where customid='12dc123456000012'";
		System.out.println(sql2);
		System.out.println(sql);

		try {

			pst = (PreparedStatement) conn.prepareStatement(sql);
			rs = pst.executeQuery();

		} catch (Exception e) {
			e.printStackTrace();
		}
		while (rs.next()) {

			datamMap = new LinkedHashMap<String, String>();
			datamMap.put("1", rs.getString("id"));
			datamMap.put("2", rs.getString("logisticscompany") != null ? rs.getString("logisticscompany") : "");
			datamMap.put("3", rs.getString("logisticssheetid") != null ? rs.getString("logisticssheetid") : "");
			creatdate = rs.getTimestamp("createtime");
			datamMap.put("4", sdf.format(creatdate));
			datamMap.put("5", rs.getString("sender") != null ? rs.getString("sender") : "");
			datamMap.put("6", rs.getString("customerid") != null ? rs.getString("customerid") : "");

			exportData.add(datamMap);

		}
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("1", "ID");
		map.put("2", "物流公司");
		map.put("3", "物流单号");
		map.put("4", "发货时间");
		map.put("5", "发货人");
		map.put("6", "顾客淘宝号");
		map.put("7", "顾客淘");
		String path = "D:/";
		String fileName = "物流表";
		File file = CSV.createCSVFile(exportData, map, path, fileName);
		String fileName2 = file.getName();
		// System.out.println("文件名称:" + fileName2);
                //腾讯云cos的一些信息
		String bucketName = "";
		String secretId = "";
		String secretKey = "";

		COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);

		ClientConfig clientConfig = new ClientConfig(new Region("ap-chengdu"));
		COSClient cosclient = new COSClient(cred, clientConfig);

		File localFile = new File(path + fileName2);

		String key = "/CSV/" + fileName2;

		PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
		try {
			PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);

			String etag = putObjectResult.getETag();
			System.out.println(etag);
		} catch (CosServiceException e) {
			e.printStackTrace();
		} catch (CosClientException e) {
			e.printStackTrace();
		}

		cosclient.shutdown();
		String returnurl = "http://" + bucketName + ".coscd.myqcloud.com" + key;
		// deleteFile(path, fileName2);
		return returnurl;

	}

	// @SuppressWarnings({ "rawtypes", "unchecked" })
	// public static String getCSV(Ordersummary list, Logistics
	// selectByLogistics, Designpattern designpattern)
	// throws Exception {
	//
	// String patternmemo = designpattern.getPatternmemo();
	// List exportData = new ArrayList();
	// LinkedHashMap<String, String> datamMap = new LinkedHashMap<String,
	// String>();
	// LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
	// map.put("1", "收货人姓名");
	// map.put("2", "收货人详细地址");
	// map.put("3", "电话");
	// map.put("4", "总价");
	// map.put("5", "产品编号");
	// map.put("6", "订单编号");
	// map.put("7", "下单日期");
	// map.put("8", "出货日期");
	// map.put("9", "产品名称");
	// map.put("10", "数量");
	// map.put("11", "尺寸");
	// map.put("12", "材料");
	// map.put("13", "电镀");
	// map.put("14", "工艺");
	// map.put("15", "厚度");
	// map.put("16", "背模");
	// map.put("17", "背字");
	// map.put("18", "配件");
	// map.put("19", "镶边");
	// map.put("20", "抛光");
	// map.put("21", "其他");
	// map.put("22", "设计备注");
	// map.put("23", "包装");
	// map.put("24", "订单状况");
	// map.put("25", "设计师");
	// map.put("26", "模具师");
	// map.put("27", "金工车间");
	// map.put("28", "抛光车间");
	// map.put("29", "焊针车间");
	// map.put("30", "上色车间");
	// map.put("31", "包装员");
	// map.put("32", "厂长审核");
	// map.put("33", "刻模不晚于");
	// map.put("34", "打胚不晚于");
	// map.put("35", "抛光不晚于");
	// map.put("36", "电镀不晚于");
	// map.put("37", "上色不晚于");
	// map.put("38", "镭射不晚于");
	// map.put("39", "包装不晚于");
	// map.put("40", "出货不晚于");
	// map.put("41", "注意事项");
	//
	// datamMap.put("1", selectByLogistics.getRecipient() != null ?
	// selectByLogistics.getRecipient() : "");
	// datamMap.put("2",
	// selectByLogistics.getLogisticsaddress1() != null ?
	// selectByLogistics.getLogisticsaddress1() : "");
	// datamMap.put("3", selectByLogistics.getRecipienttele() != null ?
	// selectByLogistics.getRecipienttele() : "");
	// Long finalprice = list.getFinalprice();
	// datamMap.put("4", "" + 2 + "");
	// datamMap.put("5", "");
	// datamMap.put("6", list.getOrderid() != null ? list.getOrderid() : "");
	// datamMap.put("7", list.getPaytime() != null ? list.getPaytime() : "");
	// datamMap.put("8", "" + (list.getDeadline() != null ? list.getDeadline() :
	// "") + "");
	// datamMap.put("9", list.getGoodsname() != null ? list.getGoodsname() :
	// "");
	// datamMap.put("10", "" + (list.getNumber() != null ? list.getNumber() :
	// "") + "");
	// datamMap.put("11", "" + list.getLength() + "*" + list.getWidth() + "*" +
	// list.getHeight() + "");
	// datamMap.put("12", list.getTexturename() != null ? list.getTexturename()
	// : "");
	// datamMap.put("13", list.getColor() != null ? list.getColor() : "");
	// datamMap.put("14", list.getTechnology() != null ? list.getTechnology() :
	// "");
	// datamMap.put("15", "" + (list.getHeight() != null ? list.getHeight() :
	// "") + "");
	// datamMap.put("16", "");
	// datamMap.put("17", "");
	// datamMap.put("18", list.getAccessoriesname() != null ?
	// list.getAccessoriesname() : "");
	// datamMap.put("19", "");
	// datamMap.put("20", "");
	// datamMap.put("21", "");
	// datamMap.put("22", patternmemo != null ? patternmemo : "");
	// datamMap.put("23", "");
	// datamMap.put("24", "");
	// datamMap.put("25", "");
	// datamMap.put("26", "");
	// datamMap.put("27", "");
	// datamMap.put("28", "");
	// datamMap.put("29", "");
	// datamMap.put("30", "");
	// datamMap.put("31", "");
	// datamMap.put("32", "");
	// datamMap.put("33", "");
	// datamMap.put("34", "");
	// datamMap.put("35", "");
	// datamMap.put("36", "");
	// datamMap.put("37", "");
	// datamMap.put("38", "");
	// datamMap.put("39", "");
	// datamMap.put("40", "");
	// datamMap.put("41", list.getMemo() != null ? list.getMemo() : "");
	// exportData.add(datamMap);
	// String path = "D:/";
	// String fileName = "订单信息表";
	// File file = CSV.createCSVFile(exportData, map, path, fileName);
	// String fileName2 = file.getName();
	//
	// String bucketName = "";
	// String secretId = "";
	// String secretKey = "";
	//
	// COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
	//
	// ClientConfig clientConfig = new ClientConfig(new Region("ap-chengdu"));
	// COSClient cosclient = new COSClient(cred, clientConfig);
	//
	// File localFile = new File(path + fileName2);
	//
	// String key = "/CSV/" + fileName2;
	//
	// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key,
	// localFile);
	// try {
	// PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
	//
	// String etag = putObjectResult.getETag();
	// System.out.println(etag);
	// } catch (CosServiceException e) {
	// e.printStackTrace();
	// } catch (CosClientException e) {
	// e.printStackTrace();
	// }
	//
	// cosclient.shutdown();
	// String returnurl = "http://" + bucketName + ".coscd.myqcloud.com" + key;
	// // deleteFile(path, fileName2);
	// return returnurl;
	// }

	public static void main(String[] args) throws Exception {
		// Ordersummary list = new Ordersummary();
		// list.setLength(12D);
		// list.setWidth(11D);
		// list.setHeight(10D);
		// Logistics selectByLogistics = new Logistics();
		// selectByLogistics.setRecipient("xxx");
		// selectByLogistics.setLogisticsaddress1("sssss");
		// selectByLogistics.setRecipienttele("123");
		// String custopmid = "123";
		// Designpattern designpattern = new Designpattern();
		// String getCSVURL = getCSV(list, selectByLogistics, designpattern);

		String getCSVURL = createCSVfile("2018-2-1", "2018-2-3");
		System.out.println(getCSVURL);

	}

}

service层:

package com.custom.order.serviceimpl;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.custom.bean.Designpattern;
import com.custom.bean.DesignpatternExample;
import com.custom.bean.Logistics;
import com.custom.bean.Ordersummary;
import com.custom.common.utils.CSV;
import com.custom.mapper.DesignpatternMapper;
import com.custom.order.service.DownCSVService;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;

@Service
public class DownCSVServiceImpl implements DownCSVService {
	@Value("${weight}")
	private Double weight;// 权重
	@Autowired
	private DesignpatternMapper designpatternMapper;// 设计表mapper

	public String getCSV(Ordersummary list, Logistics selectByLogistics, Designpattern designpattern) throws Exception {

		String patternmemo = designpattern.getPatternmemo();
		List<Map<String, String>> exportData = new ArrayList<Map<String, String>>();
		LinkedHashMap<String, String> datamMap = new LinkedHashMap<String, String>();
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("1", "收货人姓名");
		map.put("2", "收货人详细地址");
		map.put("3", "电话");
		map.put("4", "总价");
		map.put("5", "产品编号");
		map.put("6", "订单编号");
		map.put("7", "下单日期");
		map.put("8", "出货日期");
		map.put("9", "产品名称");
		map.put("10", "数量");
		map.put("11", "尺寸");
		map.put("12", "材料");
		map.put("13", "电镀");
		map.put("14", "工艺");
		map.put("15", "厚度");
		map.put("16", "背模");
		map.put("17", "背字");
		map.put("18", "配件");
		map.put("19", "镶边");
		map.put("20", "抛光");
		map.put("21", "其他");
		map.put("22", "设计备注");
		map.put("23", "包装");
		map.put("24", "订单状况");
		map.put("25", "设计师");
		map.put("26", "模具师");
		map.put("27", "金工车间");
		map.put("28", "抛光车间");
		map.put("29", "焊针车间");
		map.put("30", "上色车间");
		map.put("31", "包装员");
		map.put("32", "厂长审核");
		map.put("33", "刻模不晚于");
		map.put("34", "打胚不晚于");
		map.put("35", "抛光不晚于");
		map.put("36", "电镀不晚于");
		map.put("37", "上色不晚于");
		map.put("38", "镭射不晚于");
		map.put("39", "包装不晚于");
		map.put("40", "出货不晚于");
		map.put("41", "注意事项");

		datamMap.put("1", selectByLogistics.getRecipient() != null ? selectByLogistics.getRecipient() : "");
		String state = selectByLogistics.getState();
		String province = selectByLogistics.getProvince();
		String city = selectByLogistics.getCity();
		String county = selectByLogistics.getCounty();
		String logisticsaddress1 = selectByLogistics.getLogisticsaddress1();
		String str;
		str = state + " " + province + " " + city + " " + county + " " + logisticsaddress1;
		datamMap.put("2", str);
		datamMap.put("3", selectByLogistics.getRecipienttele() != null ? selectByLogistics.getRecipienttele() : "");
		Long finalprice = list.getFinalprice();
		datamMap.put("4", "" + (finalprice / weight) + "");
		datamMap.put("5", "");
		datamMap.put("6", list.getOrderid() != null ? list.getOrderid() : "");
		datamMap.put("7", list.getPaytime() != null ? list.getPaytime() : "");
		datamMap.put("8", "" + (list.getDeadline() != null ? list.getDeadline() : "") + "");
		datamMap.put("9", list.getGoodsclass() != null ? list.getGoodsclass() : "");
		datamMap.put("10", "" + (list.getNumber() != null ? list.getNumber() : "") + "");
		datamMap.put("11", "" + list.getLength() + "*" + list.getWidth() + "*" + list.getHeight() + "");
		datamMap.put("12", list.getTexturename() != null ? list.getTexturename() : "");
		datamMap.put("13", list.getColor() != null ? list.getColor() : "");
		datamMap.put("14", list.getTechnology() != null ? list.getTechnology() : "");
		datamMap.put("15", "" + (list.getHeight() != null ? list.getHeight() : "") + "");
		datamMap.put("16", "");
		datamMap.put("17", "");
		datamMap.put("18", list.getAccessoriesname() != null ? list.getAccessoriesname() : "");
		datamMap.put("19", "");
		datamMap.put("20", "");
		datamMap.put("21", "");
		datamMap.put("22", patternmemo != null ? patternmemo : "");
		datamMap.put("23", "");
		datamMap.put("24", "");
		datamMap.put("25", "");
		datamMap.put("26", "");
		datamMap.put("27", "");
		datamMap.put("28", "");
		datamMap.put("29", "");
		datamMap.put("30", "");
		datamMap.put("31", "");
		datamMap.put("32", "");
		datamMap.put("33", "");
		datamMap.put("34", "");
		datamMap.put("35", "");
		datamMap.put("36", "");
		datamMap.put("37", "");
		datamMap.put("38", "");
		datamMap.put("39", "");
		datamMap.put("40", "");
		datamMap.put("41", list.getMemo() != null ? list.getMemo() : "");
		exportData.add(datamMap);
		String path = "D:/";
		String fileName = "订单信息表";
		File file = CSV.createCSVFile(exportData, map, path, fileName);
		String fileName2 = file.getName();

		String bucketName = "";
		String secretId = "";
		String secretKey = "";

		COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);

		ClientConfig clientConfig = new ClientConfig(new Region("ap-chengdu"));
		COSClient cosclient = new COSClient(cred, clientConfig);

		File localFile = new File(path + fileName2);

		String key = "/CSV/" + fileName2;

		PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
		try {
			PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);

			String etag = putObjectResult.getETag();
			System.out.println(etag);
		} catch (CosServiceException e) {
			e.printStackTrace();
		} catch (CosClientException e) {
			e.printStackTrace();
		}

		cosclient.shutdown();
		String returnurl = "http://" + bucketName + ".coscd.myqcloud.com" + key;
		// deleteFile(path, fileName2);
		return returnurl;
	}

	@Override
	public List<Designpattern> selectBycustomid(String customid) {

		DesignpatternExample example = new DesignpatternExample();
		example.createCriteria().andCustomidEqualTo(customid).andFeedbackstatusEqualTo(2);
		List<Designpattern> selectByExample = designpatternMapper.selectByExample(example);
		return selectByExample;
	}

}

web层:

package com.custom.order.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.custom.bean.Designpattern;
import com.custom.bean.Logistics;
import com.custom.bean.Ordersummary;
import com.custom.manager.service.LogisticsInformationService;
import com.custom.order.service.DownCSVService;

@Controller
public class DownCsv {
	@Autowired
	private LogisticsInformationService informationService;
	@Autowired
	private DownCSVService downCSVService;

	@RequestMapping("/order/downcsv.do")
	@ResponseBody
	public JSONObject downcsv(String customid) throws Exception {
		JSONObject json = new JSONObject();
		Ordersummary ordersummary = null;
		Logistics logistic = null;
		Designpattern design = null;
		List<Ordersummary> list = informationService.selectByCustomid(customid);
		List<Logistics> logistics = informationService.selectByLogistics(customid);
		List<Designpattern> designpattern = downCSVService.selectBycustomid(customid);
		if (list != null && list.size() > 0) {
			ordersummary = list.get(0);
		} else {
			Map<String, String> map = new HashMap<>();
			map.put("code", "1");
			map.put("msg", "此订单不存在于订单表。");
			json.put("status", map);
			return json;
		}
		if (logistics != null && logistics.size() > 0) {
			logistic = logistics.get(0);
		} else {

			Map<String, String> map = new HashMap<>();
			map.put("code", "2");
			map.put("msg", "此订单没有物流信息。");
			json.put("status", map);
			return json;
		}
		if (designpattern != null && designpattern.size() > 0) {
			design = designpattern.get(0);
		} else {
			Map<String, String> map = new HashMap<>();
			map.put("code", "3");
			map.put("msg", "此订单没有设计。");
			json.put("status", map);
			return json;
		}

		String csv = downCSVService.getCSV(ordersummary, logistic, design);
		if (!"".equals(csv) && csv.length() > 0) {
			Map<String, String> map = new HashMap<>();
			map.put("code", "0");
			map.put("msg", "获取csv地址成功。");
			map.put("addRess", csv);
			json.put("status", map);
			return json;
		} else {
			Map<String, String> map = new HashMap<>();
			map.put("code", "0");
			map.put("msg", "获取csv地址失败。");
			json.put("status", map);
			return json;
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值