| 
					
				 | 
			
			
				@@ -1,31 +1,28 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.ym.mec.web.controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.HfMemberDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.thirdparty.adapay.ConfigInit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.thirdparty.adapay.CorpMember; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.controller.BaseController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.util.upload.UploadUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.thirdparty.adapay.Payment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.util.excel.POIUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiOperation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.apache.commons.io.FileUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.io.IOUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.core.io.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.poi.hssf.usermodel.HSSFWorkbook; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.security.access.prepost.PreAuthorize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.GetMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.PostMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.RequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.RestController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.File; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.FileOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.servlet.http.HttpServletResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @RequestMapping("adapay") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Api(tags = "汇付服务") 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -81,5 +78,87 @@ public class AdapayController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return succeed(new CorpMember().executeQueryMember(memberId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApiOperation("查询企业用户信息") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @GetMapping(value = "exportBill") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PreAuthorize("@pcs.hasPermissions('adapay/exportBill')") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void exportBill(Date startTime, Date endTime, HttpServletResponse response) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long createdGte = startTime.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long createdLte = DateUtil.getLastSecondWithDay(endTime).getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int pageIndex = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Map<String, Object>> data = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        while (true) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, Object> paymentList = Payment.queryList(pageIndex, createdGte, createdLte); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            JSONArray payments = (JSONArray) paymentList.get("payments"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!paymentList.get("status").equals("succeeded")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new BizException("查询失败,请重试"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (payments != null && payments.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (Object payment : payments) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Map<String, Object> paymentMap = (Map<String, Object>) payment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    paymentMap.put("created_time", DateUtil.timeStamp2Date(paymentMap.get("created_time").toString(), null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (paymentMap.get("pay_channel").equals("alipay_qr")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("pay_channel", "支付宝正扫"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (paymentMap.get("pay_channel").equals("alipay_wap")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("pay_channel", "支付宝H5支付"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("pay_channel", "微信公众号支付"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (paymentMap.get("status").equals("pending")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("status", "交易处理中"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (paymentMap.get("status").equals("succeeded")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("status", "交易成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("status", "交易失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    JSONArray divMembers = (JSONArray) paymentMap.get("div_members"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    for (Object divMember : divMembers) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        Map<String, Object> divMemberMap = (Map<String, Object>) divMember; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("member_id", divMemberMap.get("member_id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (divMemberMap.get("member_id").equals("0")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            paymentMap.put("member_id", ConfigInit.merNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("fee_amount", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (divMemberMap.get("fee_flag").equals("Y")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            paymentMap.put("fee_amount", paymentMap.get("fee_amt")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("route_amount", divMemberMap.get("amount")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        paymentMap.put("fee_flag", divMemberMap.get("fee_flag")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        data.add(paymentMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (paymentList.get("has_more").equals(false)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pageIndex++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        OutputStream outputStream = response.getOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] header = {"支付流水号", "订单号", "支付渠道", "交易金额", "商户号", "分润金额", "是否承担手续费", "手续费", "第三方订单号", "支付宝/微信订单号", "交易时间", "交易状态"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] body = {"id", "order_no", "pay_channel", "pay_amt", "member_id", "route_amount", "fee_flag", "fee_amount", "party_order_id", "out_trans_id", "created_time", "status"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            HSSFWorkbook workbook = POIUtil.exportExcel(header, body, data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            response.setContentType("application/octet-stream"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            response.setHeader("Content-Disposition", "attachment;filename=bill-" + DateUtil.getDate(new Date()) + ".xls"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            response.flushBuffer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            outputStream = response.getOutputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            workbook.write(outputStream); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            outputStream.flush(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (outputStream != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    outputStream.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |