limin 7 years ago
parent
commit
2d5a4cc0d2

+ 196 - 0
src/main/java/com/goafanti/common/utils/ExportExcelUtil.java

@@ -0,0 +1,196 @@
+package com.goafanti.common.utils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.Map;
+
+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.ss.util.CellRangeAddress;
+
+import com.goafanti.common.model.TOrderBillNew;
+
+public class ExportExcelUtil {
+	
+	//设置单元格格式
+	private static HSSFCellStyle setCellStyle1(HSSFWorkbook workbook){
+		// 设置字体  
+		HSSFFont font = workbook.createFont();  
+		// font.setColor(HSSFFont.COLOR_RED);  
+		font.setFontName("微软雅黑");
+		font.setFontHeightInPoints((short) 10);//字体大小  
+		  
+		// 设置样式  
+		HSSFCellStyle cellStyle = workbook.createCellStyle();  
+		cellStyle.setFont(font);  //字体
+		
+		//设置自动换行
+		cellStyle.setWrapText(true);
+		return cellStyle;
+	}
+	//设置单元格格式
+	private static HSSFCellStyle setCellStyle2(HSSFWorkbook workbook){
+		// 设置字体  
+		HSSFFont font = workbook.createFont();  
+		font.setFontName("微软雅黑");
+		font.setFontHeightInPoints((short) 14);//字体大小  
+		font.setFontHeight((short) 600);
+		// 设置样式  
+		HSSFCellStyle cellStyle = workbook.createCellStyle();  
+		cellStyle.setFont(font);  //字体
+		return cellStyle;
+	}
+	
+	//下载课表
+	public static void download(String path, HttpServletResponse response,String filename) { 
+		try {  
+            // path是指欲下载的文件的路径。  
+            File file = new File(path);  
+            // 取得文件名。  
+            // 以流的形式下载文件。  
+            InputStream fis = new BufferedInputStream(new FileInputStream(path));  
+            byte[] buffer = new byte[fis.available()];  
+            fis.read(buffer);  
+            fis.close();  
+            // 清空response  
+            response.reset();  
+            // 设置response的Header  
+            response.addHeader("Content-Disposition", "attachment;filename="  
+                    + new String(filename.getBytes(),"iso-8859-1"));  //防止中文乱码或者中文忽略的情况
+            response.addHeader("Content-Length", "" + file.length());  
+            OutputStream toClient = new BufferedOutputStream(  
+                    response.getOutputStream());  
+            response.setContentType("application/octet-stream;charset=utf-8");  
+            toClient.write(buffer);  
+            toClient.flush();  
+            toClient.close();  
+            
+          
+        } catch (IOException ex) {  
+            ex.printStackTrace();  
+        }  
+		
+	}
+	public static void download(String path, HttpServletResponse response) {  
+        try {  
+            // path是指欲下载的文件的路径。  
+            File file = new File(path);  
+            // 取得文件名。  
+            String filename = file.getName();  
+            // 以流的形式下载文件。  
+            InputStream fis = new BufferedInputStream(new FileInputStream(path));  
+            byte[] buffer = new byte[fis.available()];  
+            fis.read(buffer);  
+            fis.close();  
+            // 清空response  
+            response.reset();  
+            // 设置response的Header  
+            response.addHeader("Content-Disposition", "attachment;filename="  
+                    + new String(filename.getBytes(),"iso-8859-1"));  
+            response.addHeader("Content-Length", "" + file.length());  
+            OutputStream toClient = new BufferedOutputStream(  
+                    response.getOutputStream());  
+            response.setContentType("application/octet-stream;charset=utf-8");  
+            toClient.write(buffer);  
+            toClient.flush();  
+            toClient.close();  
+        } catch (IOException ex) {  
+            ex.printStackTrace();  
+        }  
+    }  
+	
+	//=========================================================此处分割线===========================================================================//
+	/**
+	 * 导出部门流水数据
+	 * @param map 数据
+	 * @param deptnames 部门名称数组
+	 * @param comment 表头(列名)
+	 * @param filePath 生成文件路径
+	 */
+	public static void exportDeptBillInfo(Map<String,List<TOrderBillNew>> map,String[] deptnames,String[] comment,String filePath){
+		//map 数据 ,deptnames 部门名称,comment表头 (列名称)
+ 		//1,创建一个workbook,对应的是一个excel文件
+		HSSFWorkbook wb = new HSSFWorkbook();
+		int count = 0;
+		//遍历map
+		for (Map.Entry<String,List<TOrderBillNew>> entry : map.entrySet()) {
+			//2.创建一个sheet
+			HSSFSheet sheet = wb.createSheet(entry.getKey());
+			//3。创建一个row
+			HSSFRow row = sheet.createRow(0);
+			//4.创建一个cell
+			HSSFCell cell = row.createCell(0);
+			cell.setCellValue(deptnames[count]+" 流水记录");
+			count ++;
+			HSSFCellStyle style1 = setCellStyle1(wb);
+			cell.setCellStyle(style1);
+			//合并列
+			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, comment.length-1));//合并单元格
+			//创建表头
+			HSSFRow row2 = sheet.createRow(1);
+			for(int i = 0; i < comment.length; i++){
+				sheet.setColumnWidth(i, 3000);//设置列宽
+				HSSFCell c = row2.createCell(i);
+				c.setCellValue(comment[i]);
+				c.setCellStyle(style1);
+			}
+			//填充表格数据
+			//int rowmnum = sheet.getLastRowNum();//获得当前行数据
+			List<TOrderBillNew> list = entry.getValue();
+			if(list == null){
+				continue;
+			}
+			for (TOrderBillNew ob : list) {
+				//新增一行
+				HSSFRow r = sheet.createRow(sheet.getLastRowNum()+1);
+				for (int i = 0; i < comment.length; i++) {
+					//当前列的只
+					String o ;
+					switch (comment[i]) {
+					case "平台流水编号": o = ob.getBillNo(); break;
+					case "平台流水时间": o = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ob.getCreateTime()); break;
+					case "交易金额": o = ob.getTransactionAmount().toString(); break;
+					case "付款方": o = ob.getPayerName(); break;
+					case "收款方": o = ob.getPayeeName(); break;
+					case "流水科目": o = ob.getTransactionSubject().toString(); break;
+					case "交易渠道": o = ob.getTransactionChannel().toString(); break;
+					case "交易时间": o = ob.getFinancialPayTimes(); break;
+					case "财务流水号": o = ob.getFinancialPayNo();break;
+					case "订单编号": o = ob.getOrderNo(); break;
+					case "订单负责人": o = ob.getSaleName(); break;
+					default: o = ""; break;
+					}
+					HSSFCell c = r.createCell(i);
+					c.setCellValue(o);
+				}
+			}
+		}
+		
+		//将表格数据放入文件中
+		try {
+			FileOutputStream fos = new FileOutputStream(filePath);
+			wb.write(fos);
+			fos.close();
+			System.out.println("已经创建文件");
+		} catch (Exception e) {
+			System.out.println("发生了异常");
+			e.printStackTrace();
+		}
+	}
+	
+	
+}

+ 23 - 0
src/main/java/com/goafanti/order/service/OrderBillService.java

@@ -0,0 +1,23 @@
+package com.goafanti.order.service;
+
+import com.goafanti.common.model.TOrderBillNew;
+import com.goafanti.core.mybatis.page.Pagination;
+
+public interface OrderBillService {
+	
+	/**
+	 * 查看自己的流水
+	 * @param billNew
+	 * @param pageNo
+	 * @param pageSize
+	 * @return
+	 */
+	Pagination<TOrderBillNew> myBillList(TOrderBillNew billNew, Integer pageNo, Integer pageSize);
+	
+	/**
+	 * 导出流水数据
+	 * @param billNew
+	 * @return
+	 */
+	String exportBillData(TOrderBillNew billNew);
+}

+ 16 - 0
src/main/java/com/goafanti/order/service/OrderRefundService.java

@@ -0,0 +1,16 @@
+package com.goafanti.order.service;
+
+import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.order.bo.OrderRefundBo;
+
+public interface OrderRefundService {
+	
+	/**
+	 * 财务专员查看自己要处理的退单数据
+	 * @param refund
+	 * @param pageNo
+	 * @param pageSize
+	 * @return
+	 */
+	Pagination<OrderRefundBo> getRefundList(OrderRefundBo refund, Integer pageNo, Integer pageSize);
+}

+ 75 - 0
src/main/java/com/goafanti/order/service/impl/OrderBillServiceImpl.java

@@ -0,0 +1,75 @@
+package com.goafanti.order.service.impl;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.goafanti.common.dao.TOrderBillNewMapper;
+import com.goafanti.common.model.TOrderBillNew;
+import com.goafanti.common.utils.ExportExcelUtil;
+import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.order.service.OrderBillService;
+
+@Service
+public class OrderBillServiceImpl extends BaseMybatisDao<TOrderBillNewMapper> implements OrderBillService {
+	
+	@Autowired
+	private TOrderBillNewMapper billNewMapper;
+//	@Value(value = "${upload.path}")
+//	private String	uploadPath = null;
+
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<TOrderBillNew> myBillList(TOrderBillNew billNew,
+			Integer pageNo, Integer pageSize) {
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("b", billNew);
+		Pagination<TOrderBillNew> data = (Pagination<TOrderBillNew>)findPage("myBillList", "myBillCount", params, pageNo, pageSize);
+		return data;
+	}
+
+
+	@Override
+	public String exportBillData(TOrderBillNew billNew) {
+		// 判断导出是否有部门
+		String deptid = billNew.getDepartmentId();
+		Map<String, List<TOrderBillNew>> map = new HashMap<String, List<TOrderBillNew>>();
+		String[] deptnames = null; 
+		if(StringUtils.isBlank(deptid)){
+			//获得所有有数据的部门
+			List<TOrderBillNew> dlist = billNewMapper.getDeptBySome(billNew);
+			if(null == dlist || dlist.size() == 0){
+				return "null";
+			}
+			deptnames = new String[dlist.size()];
+			for (int i = 0; i < dlist.size(); i++) {
+				TOrderBillNew ob = dlist.get(i);
+				deptnames[i] = ob.getDepartmentName();
+				billNew.setDepartmentId(ob.getDepartmentId());
+				map.put(ob.getDepartmentName(), billNewMapper.getBillData(billNew));
+			}
+		}else{
+			deptnames = new String[1];
+			map.put(billNew.getDepartmentName(), billNewMapper.getBillData(billNew));
+		}
+		String[] comment = {"平台流水编号","平台流水时间","交易金额","付款方","收款方","流水科目","交易渠道","交易时间","财务流水号","订单编号","订单负责人"};
+		String filePath = "F:/data/public/upload" + "/billtemp";
+		File f = new File(filePath);
+		if(!f.exists()){
+			f.mkdirs();
+		}
+		filePath += "/" + System.nanoTime() +".xls";
+		ExportExcelUtil.exportDeptBillInfo(map, deptnames, comment, filePath);
+		return filePath;
+	}
+	
+
+	
+}

+ 35 - 0
src/main/java/com/goafanti/order/service/impl/OrderRefundServiceImpl.java

@@ -0,0 +1,35 @@
+package com.goafanti.order.service.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.goafanti.common.dao.TOrderBillNewMapper;
+import com.goafanti.common.dao.TOrderRefundMapper;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.order.bo.OrderRefundBo;
+import com.goafanti.order.service.OrderRefundService;
+
+@Service
+public class OrderRefundServiceImpl extends BaseMybatisDao<TOrderRefundMapper> implements OrderRefundService {
+	
+	@Autowired
+	private TOrderBillNewMapper billNewMapper;
+
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<OrderRefundBo> getRefundList(OrderRefundBo refund,
+			Integer pageNo, Integer pageSize) {
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("r", refund);
+		Pagination<OrderRefundBo> data = (Pagination<OrderRefundBo>)findPage("getRefundList", "getRefundCount", params, pageNo, pageSize);
+		return data;
+	}
+	
+
+	
+}