bugfix:微信医保数据入库
This commit is contained in:
@@ -138,5 +138,17 @@ public class BankbillHistory implements Serializable {
|
||||
* 对账表名
|
||||
*/
|
||||
private String billTableName;
|
||||
/**
|
||||
* 医保统筹金额
|
||||
*/
|
||||
private String fundPaySumamt;
|
||||
/**
|
||||
* 医保账户金额
|
||||
*/
|
||||
private String acctPay;
|
||||
/**
|
||||
* 医疗总费用
|
||||
*/
|
||||
private String medfeeSumamt;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,12 @@ public class BankGetData implements Job {
|
||||
Thread thread = new Thread(() -> new BankGetDataByWXAPI().getDate(id, name, trade_date, hashMap));
|
||||
thread.start();
|
||||
}
|
||||
|
||||
//微信医保账单
|
||||
if ("BankGetDataByMedicalInsuranceAPI".equals(execute_class)) {
|
||||
Thread thread = new Thread(() -> new BankGetDataByMedicalInsuranceAPI().getDate(id, name, trade_date, hashMap));
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < wlConfigList.size(); i++) {
|
||||
|
||||
@@ -137,6 +143,11 @@ public class BankGetData implements Job {
|
||||
if ("BankGetDataByWXAPI".equals(execute_class)) {
|
||||
return new BankGetDataByWXAPI().getDate(id, name, trade_date, hashMap);
|
||||
}
|
||||
|
||||
//微信医保账单
|
||||
if ("BankGetDataByMedicalInsuranceAPI".equals(execute_class)) {
|
||||
return new BankGetDataByMedicalInsuranceAPI().getDate(id, name, trade_date, hashMap);
|
||||
}
|
||||
//
|
||||
// //商户营销联盟对账单
|
||||
// if ("BankGetDataBySHYXLM".equals(execute_class)){
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.saye.hospitalgd.scheduler.jobMethod;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.saye.hospitalgd.commons.date.DateDUtil;
|
||||
import com.saye.hospitalgd.commons.getBean.GetBeanUtil;
|
||||
import com.saye.hospitalgd.commons.log.LogUtil;
|
||||
import com.saye.hospitalgd.commons.string.StringDUtil;
|
||||
import com.saye.hospitalgd.entity.BankbillHistory;
|
||||
import com.saye.hospitalgd.service.BankbillGetinfoService;
|
||||
import com.saye.hospitalgd.service.BankbillHistoryService;
|
||||
import com.saye.hospitalgd.service.impl.BankbillGetinfoServiceImpl;
|
||||
import com.saye.hospitalgd.service.impl.BankbillHistoryServiceImpl;
|
||||
import com.saye.hospitalgd.service.system.ServiceParamsService;
|
||||
import com.saye.hospitalgd.service.system.impl.ServiceParamsServiceImpl;
|
||||
import com.saye.hospitalgd.util.HttpDutil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 银行医保账单获取(通过中转服务)
|
||||
*
|
||||
* @author Mr.zs
|
||||
* @date 2025/11/17
|
||||
*/
|
||||
@Slf4j
|
||||
public class BankGetDataByMedicalInsuranceAPI {
|
||||
|
||||
public HashMap<Object, Object> getDate(String id, String name, String trade_date, HashMap<Object, Object> map) {
|
||||
|
||||
HashMap<Object, Object> resultMap = new HashMap<>();
|
||||
String errCode = "0";
|
||||
String errMsg = "";
|
||||
|
||||
BankbillHistoryService bankbillHistoryService = GetBeanUtil.getBean(BankbillHistoryServiceImpl.class);
|
||||
BankbillGetinfoService bankbillGetinfoService = GetBeanUtil.getBean(BankbillGetinfoServiceImpl.class);
|
||||
ServiceParamsService serviceParamsService = GetBeanUtil.getBean(ServiceParamsServiceImpl.class);
|
||||
|
||||
boolean isOk = false;
|
||||
|
||||
int num = "".equals(trade_date) ? 0 : 9;
|
||||
while (!isOk && num < 10) {
|
||||
num++;
|
||||
|
||||
String bill_table_name = StringDUtil.changeNullToEmpty(map.get("BILL_TABLE_NAME"));
|
||||
String thirdConfigId = StringDUtil.changeNullToEmpty(map.get("ID"));
|
||||
String dateStr = "";
|
||||
|
||||
if (StrUtil.isNotBlank(trade_date)) {
|
||||
DateTime parse = DateUtil.parse(trade_date);
|
||||
dateStr = DateUtil.format(parse, "yyyyMMdd");
|
||||
} else {
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
dateStr = DateUtil.format(yesterday, "yyyyMMdd");
|
||||
trade_date = DateUtil.format(yesterday, "yyyy-MM-dd");
|
||||
}
|
||||
map.put("trade_date", dateStr);
|
||||
|
||||
try {
|
||||
List<HashMap<Object, Object>> serviceParams = serviceParamsService.findParamValByParamCode("hgd_dmz");
|
||||
String dmz_url = StringDUtil.changeNullToEmpty(serviceParams.get(0).get("PARAM_VAL"));
|
||||
|
||||
log.info("开始调用中转服务获取银行医保账单,URL: {}", dmz_url + "/getBankDataByMedicalInsuranceAPI");
|
||||
String result = HttpDutil.post(dmz_url + "/getBankDataByMedicalInsuranceAPI", map);
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
|
||||
errCode = StringDUtil.changeNullToEmpty(jsonObject.get("errCode"));
|
||||
errMsg = StringDUtil.changeNullToEmpty(jsonObject.get("errMsg"));
|
||||
|
||||
if ("0".equals(errCode)) {
|
||||
String listStr = StringDUtil.changeNullToEmpty(jsonObject.get("list"));
|
||||
log.info("微信医保账单获取成功,返回数据: {}", listStr);
|
||||
List<BankbillHistory> bankbillHistories = JSONArray.parseArray(listStr, BankbillHistory.class);
|
||||
|
||||
if (bankbillHistories != null && !bankbillHistories.isEmpty()) {
|
||||
bankbillHistoryService.insertBankBillOriginal(bankbillHistories, trade_date, bill_table_name);
|
||||
bankbillHistoryService.insertAllBankHistory(bankbillHistories, trade_date, bill_table_name);
|
||||
}
|
||||
isOk = true;
|
||||
} else {
|
||||
isOk = false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
errCode = "999";
|
||||
errMsg = "处理数据错误,原因:" + e.getMessage();
|
||||
isOk = false;
|
||||
}
|
||||
|
||||
HashMap<Object, Object> addMap = new HashMap<>();
|
||||
addMap.put("trade_date", trade_date);
|
||||
addMap.put("quartz_id", id);
|
||||
addMap.put("quartz_name", name);
|
||||
addMap.put("bill_table_name", bill_table_name);
|
||||
addMap.put("thirdConfigId", thirdConfigId);
|
||||
addMap.put("is_ok", isOk ? "1" : "0");
|
||||
addMap.put("modify_time", DateDUtil.getCurrentDate(DateDUtil.yyyy_MM_dd_HH_mm_ss));
|
||||
|
||||
bankbillGetinfoService.insertBankbillGetinfo(addMap);
|
||||
|
||||
if (!isOk && num < 10) {
|
||||
try {
|
||||
LogUtil.error(this.getClass(), errMsg);
|
||||
System.out.println("获取对账记录没有成功,1小时后重新执行");
|
||||
Thread.sleep(1000 * 60 * 60);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
resultMap.put("errCode", errCode);
|
||||
resultMap.put("errMsg", errMsg);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import com.saye.hospitalgd.commons.string.StringDUtil;
|
||||
import com.saye.hospitalgd.entity.BankbillHistory;
|
||||
import com.saye.hospitalgd.service.BankbillGetinfoService;
|
||||
import com.saye.hospitalgd.service.BankbillHistoryService;
|
||||
import com.saye.hospitalgd.service.datamanager.DataManagerService;
|
||||
import com.saye.hospitalgd.service.impl.BankbillGetinfoServiceImpl;
|
||||
import com.saye.hospitalgd.service.impl.BankbillHistoryServiceImpl;
|
||||
import com.saye.hospitalgd.service.system.ServiceParamsService;
|
||||
@@ -40,7 +39,7 @@ public class BankGetDataBySHPOS {
|
||||
BankbillGetinfoService bankbillGetinfoService = GetBeanUtil.getBean(BankbillGetinfoServiceImpl.class);
|
||||
|
||||
ServiceParamsService serviceParamsService = GetBeanUtil.getBean(ServiceParamsServiceImpl.class);
|
||||
DataManagerService dataManagerService = GetBeanUtil.getBean(DataManagerService.class);
|
||||
|
||||
|
||||
|
||||
boolean isOk = false;
|
||||
@@ -104,9 +103,6 @@ public class BankGetDataBySHPOS {
|
||||
List<HashMap<Object, Object>> serviceParams = serviceParamsService.findParamValByParamCode("hgd_dmz");
|
||||
String dmz_url = StringDUtil.changeNullToEmpty(serviceParams.get(0).get("PARAM_VAL"));
|
||||
|
||||
// HashMap<Object, Object> bankDataBySHPOS = dataManagerService.getBankDataBySHPOS(map);
|
||||
|
||||
|
||||
String result = HttpDutil.post(dmz_url + "/getBankDataBySHPOS", map);
|
||||
|
||||
// 解析返回的json字符串
|
||||
|
||||
@@ -577,10 +577,10 @@ public class BankGetDataMethodByJHLZF {
|
||||
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
|
||||
// 根据你提供的Excel列位置映射:
|
||||
// 终端号: CD列(索引2-3), 发卡行: EFGH列(索引4-7), 卡种: IJ列(索引8-9),
|
||||
// 卡号: KLM列(索引10-12), 交易日期: N列(索引13), 交易时间: P列(索引15),
|
||||
// 交易类型: QR列(索引16-17), 授权号: ST列(索引18-19), 交易金额: U列(索引20)⭐,
|
||||
// 根据实际Excel列位置映射(从日志分析得出):
|
||||
// 终端号: C列(索引2), 发卡行: E列(索引4), 卡种: I列(索引8),
|
||||
// 卡号: K列(索引10), 交易日期: N列(索引13), 交易时间: O列(索引14)⭐,
|
||||
// 交易类型: Q列(索引16), 授权号: S列(索引18), 交易金额: U列(索引20)⭐,
|
||||
// 小费: VW列(索引21-22), 分期期数: X列(索引23), 银行手续费: Y列(索引24),
|
||||
// DCC返还手续费: Z列(索引25), 划账金额: AA列(索引26), 凭证号: AB列(索引27),
|
||||
// 批次号: AC列(索引28), POS交易序号: AD列(索引29)⭐, 结算账号: AE列(索引30),
|
||||
@@ -589,7 +589,7 @@ public class BankGetDataMethodByJHLZF {
|
||||
|
||||
// 交易日期和时间
|
||||
jyrq = s1.length > 13 ? s1[13] : "";
|
||||
String jysj = s1.length > 15 ? s1[15] : "";
|
||||
String jysj = s1.length > 14 ? s1[14] : ""; // 交易时间在第14列(索引14)
|
||||
|
||||
// 如果交易时间为空,尝试从交易日期中提取时间部分
|
||||
if (jysj == null || jysj.trim().isEmpty()) {
|
||||
@@ -1129,43 +1129,7 @@ public class BankGetDataMethodByJHLZF {
|
||||
// 输出Excel的基本信息
|
||||
log.info("Excel总行数: " + sheet.getLastRowNum());
|
||||
|
||||
// 输出第24行的表头信息(真正的列标题)
|
||||
Row headerRow24 = sheet.getRow(23); // 第24行,索引是23
|
||||
if (headerRow24 != null) {
|
||||
StringBuilder headerLine = new StringBuilder();
|
||||
for (int col = 0; col < headerRow24.getLastCellNum(); col++) {
|
||||
Cell cell = headerRow24.getCell(col);
|
||||
if (cell != null) {
|
||||
headerLine.append("[列").append(col).append("]=");
|
||||
try {
|
||||
headerLine.append(cell.toString());
|
||||
} catch (Exception e) {
|
||||
headerLine.append("ERROR");
|
||||
}
|
||||
headerLine.append(" | ");
|
||||
}
|
||||
}
|
||||
log.info("第24行(真正的表头): " + headerLine.toString());
|
||||
}
|
||||
|
||||
// 输出第25行的第一条数据示例
|
||||
Row dataRow25 = sheet.getRow(24); // 第25行,索引是24
|
||||
if (dataRow25 != null) {
|
||||
StringBuilder dataLine = new StringBuilder();
|
||||
for (int col = 0; col < Math.min(20, dataRow25.getLastCellNum()); col++) {
|
||||
Cell cell = dataRow25.getCell(col);
|
||||
if (cell != null) {
|
||||
dataLine.append("[列").append(col).append("]=");
|
||||
try {
|
||||
dataLine.append(cell.toString());
|
||||
} catch (Exception e) {
|
||||
dataLine.append("ERROR");
|
||||
}
|
||||
dataLine.append(" | ");
|
||||
}
|
||||
}
|
||||
log.info("第25行(第1条数据): " + dataLine.toString());
|
||||
}
|
||||
|
||||
|
||||
// 遍历所有行
|
||||
for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
||||
@@ -1183,59 +1147,35 @@ public class BankGetDataMethodByJHLZF {
|
||||
String cellValue = "";
|
||||
|
||||
if (cell != null) {
|
||||
// 根据单元格类型获取值(JDK 8兼容方式)
|
||||
int cellType = cell.getCellType();
|
||||
|
||||
if (cellType == Cell.CELL_TYPE_STRING) {
|
||||
cellValue = cell.getStringCellValue();
|
||||
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
|
||||
// 检查是否为日期格式
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
try {
|
||||
// 使用SimpleDateFormat格式化日期时间
|
||||
java.util.Date dateValue = cell.getDateCellValue();
|
||||
|
||||
// 检查是否只有时间(日期部分为1899-12-31或1900-01-01)
|
||||
java.util.Calendar cal = java.util.Calendar.getInstance();
|
||||
cal.setTime(dateValue);
|
||||
int year = cal.get(java.util.Calendar.YEAR);
|
||||
|
||||
if (year == 1899 || year == 1900) {
|
||||
// 只有时间,格式化为 HH:mm:ss
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm:ss");
|
||||
cellValue = sdf.format(dateValue);
|
||||
} else {
|
||||
// 完整的日期时间,格式化为 yyyy-MM-dd HH:mm:ss
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
cellValue = sdf.format(dateValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
cellValue = cell.getDateCellValue().toString();
|
||||
}
|
||||
} else {
|
||||
// 数字格式,避免科学计数法
|
||||
cellValue = String.valueOf(cell.getNumericCellValue());
|
||||
// 如果是整数,去掉小数点
|
||||
if (cellValue.endsWith(".0")) {
|
||||
cellValue = cellValue.substring(0, cellValue.length() - 2);
|
||||
}
|
||||
// 直接使用 toString() 获取单元格显示的文本值,这样可以获取格式化后的值
|
||||
// 例如时间 "00:22:49"、日期 "2025-10-23" 等都会按显示格式返回
|
||||
try {
|
||||
cellValue = cell.toString();
|
||||
// 如果是空白,设置为空字符串
|
||||
if (cellValue == null) {
|
||||
cellValue = "";
|
||||
}
|
||||
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
|
||||
cellValue = String.valueOf(cell.getBooleanCellValue());
|
||||
} else if (cellType == Cell.CELL_TYPE_FORMULA) {
|
||||
} catch (Exception e) {
|
||||
// 如果 toString 失败,尝试根据类型获取
|
||||
int cellType = cell.getCellType();
|
||||
try {
|
||||
cellValue = String.valueOf(cell.getNumericCellValue());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (cellType == Cell.CELL_TYPE_STRING) {
|
||||
cellValue = cell.getStringCellValue();
|
||||
} catch (Exception e2) {
|
||||
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
|
||||
cellValue = String.valueOf(cell.getNumericCellValue());
|
||||
if (cellValue.endsWith(".0")) {
|
||||
cellValue = cellValue.substring(0, cellValue.length() - 2);
|
||||
}
|
||||
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
|
||||
cellValue = String.valueOf(cell.getBooleanCellValue());
|
||||
} else if (cellType == Cell.CELL_TYPE_BLANK) {
|
||||
cellValue = "";
|
||||
} else {
|
||||
cellValue = "";
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
cellValue = "";
|
||||
}
|
||||
} else if (cellType == Cell.CELL_TYPE_BLANK) {
|
||||
cellValue = "";
|
||||
} else {
|
||||
cellValue = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.saye.hospitalgd.service.datamanager;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Mr.zs
|
||||
* @date 2024/12/26
|
||||
*/
|
||||
public interface DataManagerService {
|
||||
HashMap<Object, Object> getBankDataBySH(HashMap<Object, Object> map);
|
||||
|
||||
HashMap<Object, Object> getBankDataBySHPOS(HashMap<Object, Object> map);
|
||||
|
||||
HashMap<Object, Object> getBankDataBySHYLK(HashMap<Object, Object> map);
|
||||
|
||||
HashMap<Object, Object> getBankDataByWXAPI(HashMap<Object, Object> map);
|
||||
}
|
||||
@@ -1,896 +0,0 @@
|
||||
package com.saye.hospitalgd.service.datamanager.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.text.csv.CsvData;
|
||||
import cn.hutool.core.text.csv.CsvReader;
|
||||
import cn.hutool.core.text.csv.CsvRow;
|
||||
import cn.hutool.core.text.csv.CsvUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.saye.hospitalgd.commons.date.DateDUtil;
|
||||
import com.saye.hospitalgd.commons.string.StringDUtil;
|
||||
import com.saye.hospitalgd.entity.BankbillHistory;
|
||||
import com.saye.hospitalgd.service.datamanager.DataManagerService;
|
||||
import com.saye.hospitalgd.util.DownloadFtpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mr.zs
|
||||
* @date 2024/12/26
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DataManagerServiceImpl implements DataManagerService {
|
||||
private static String grant_type = "client_credential";
|
||||
private static String appid = "wx83bc9715be856b14";
|
||||
private static String secret = "8b2d3e8cb0e590c9884d2c278519a200";
|
||||
|
||||
/**
|
||||
* 获取银行端商户对账数据
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Object, Object> getBankDataBySH(@RequestBody HashMap<Object, Object> map) {
|
||||
HashMap<Object, Object> responseMap = new HashMap<>();
|
||||
String errCode = "0";
|
||||
String errMsg = "";
|
||||
|
||||
// 先下载文件
|
||||
String host = StringDUtil.changeNullToEmpty(map.get("FTP_HOST"));
|
||||
String portStr = StringDUtil.changeNullToEmpty(map.get("FTP_PORT"));
|
||||
int port = Integer.parseInt("".equals(portStr) ? "21" : portStr);
|
||||
String username = StringDUtil.changeNullToEmpty(map.get("FTP_USER"));
|
||||
String password = StringDUtil.changeNullToEmpty(map.get("FTP_PASSWORD"));
|
||||
String localPath = StringDUtil.changeNullToEmpty(map.get("LOCAL_PATH"));
|
||||
String mch_id = StringDUtil.changeNullToEmpty(map.get("MCH_ID"));
|
||||
String ftp_path = StringDUtil.changeNullToEmpty(map.get("FTP_PATH"));
|
||||
String ftp_file_name = StringDUtil.changeNullToEmpty(map.get("FTP_FILE_NAME"));
|
||||
String bill_table_name = StringDUtil.changeNullToEmpty(map.get("BILL_TABLE_NAME"));
|
||||
String thirdConfigId = StringDUtil.changeNullToEmpty(map.get("ID"));
|
||||
String trade_date = StringDUtil.changeNullToEmpty(map.get("trade_date"));
|
||||
|
||||
HSSFWorkbook sheets = null;
|
||||
try {
|
||||
// 下载文件
|
||||
boolean b = DownloadFtpUtil.downloadFtpFile(host, username, password, port, ftp_path, localPath, ftp_file_name);
|
||||
// 判断是否下载到文件
|
||||
if (!b) {
|
||||
throw new RuntimeException("没有下载到文件" + ftp_file_name);
|
||||
}
|
||||
|
||||
// 判断本地是否有文件
|
||||
File file = new File(localPath + "/" + ftp_file_name);
|
||||
if (file.exists()) {
|
||||
// 存在 开始解析 存入数据库
|
||||
FileInputStream fileInputStream = new FileInputStream(localPath + "/" + ftp_file_name);
|
||||
|
||||
sheets = new HSSFWorkbook(fileInputStream);
|
||||
HSSFSheet sheet = sheets.getSheetAt(0);
|
||||
// 获取sheet中第一行行号
|
||||
int firstRowNum = sheet.getFirstRowNum();
|
||||
// 获取sheet中最后一行行号
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
List<BankbillHistory> list = new ArrayList<>();
|
||||
|
||||
for (int i = firstRowNum + 3; i <= lastRowNum - 2; i++) {// 因为表格中第一行为说明,第二行为列标题
|
||||
HSSFRow row = sheet.getRow(i);
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
|
||||
// 清算日期
|
||||
HSSFCell qsrq = row.getCell(0);
|
||||
qsrq.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsrqStr = qsrq.getStringCellValue().trim();
|
||||
|
||||
// 拿第一个字段判断这条记录是否为空 如果为空直接跳出 一般这字段为空就是数据结束了或根本没有
|
||||
// 为合计也跳出
|
||||
if ("".equals(qsrqStr) || "合计".equals(qsrqStr)) {
|
||||
break;
|
||||
}
|
||||
|
||||
bankbillHistory.setCQsrq(qsrqStr);
|
||||
|
||||
// 交易日期
|
||||
HSSFCell jyrq = row.getCell(1);
|
||||
String jyrqStr = "";
|
||||
jyrq.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
if (HSSFDateUtil.isCellDateFormatted(jyrq)) {
|
||||
Date dateCellValue = jyrq.getDateCellValue();
|
||||
jyrqStr = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd, dateCellValue);
|
||||
}
|
||||
bankbillHistory.setCJyrq(jyrqStr);
|
||||
|
||||
if (i == 0) {
|
||||
trade_date = jyrqStr;
|
||||
}
|
||||
|
||||
// 交易时间
|
||||
HSSFCell jysj = row.getCell(2);
|
||||
jysj.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jysjStr = jysj.getStringCellValue().trim();
|
||||
bankbillHistory.setCJysj(jysjStr);
|
||||
|
||||
// 卡号
|
||||
HSSFCell card = row.getCell(3);
|
||||
card.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String khStr = card.getStringCellValue().trim();
|
||||
bankbillHistory.setCCard(khStr);
|
||||
|
||||
// 交易类型
|
||||
HSSFCell jylx = row.getCell(4);
|
||||
jylx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jylxStr = jylx.getStringCellValue().trim();
|
||||
bankbillHistory.setCJylx(jylxStr);
|
||||
|
||||
// 交易金额
|
||||
HSSFCell jyje = row.getCell(5);
|
||||
jyje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jyjeStr = jyje.getStringCellValue().trim();
|
||||
bankbillHistory.setCJyje(jyjeStr);
|
||||
|
||||
// 终端号
|
||||
HSSFCell zdh = row.getCell(6);
|
||||
zdh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zdhStr = zdh.getStringCellValue().trim();
|
||||
bankbillHistory.setCZdh(zdhStr);
|
||||
|
||||
// 清算金额
|
||||
HSSFCell qsje = row.getCell(7);
|
||||
qsje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsjeStr = qsje.getStringCellValue().trim();
|
||||
bankbillHistory.setCQsje(qsjeStr);
|
||||
|
||||
// 手续费
|
||||
HSSFCell sxf = row.getCell(8);
|
||||
sxf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String sxfStr = sxf.getStringCellValue().trim();
|
||||
bankbillHistory.setCSxf(sxfStr);
|
||||
|
||||
// 参考号
|
||||
HSSFCell ckh = row.getCell(9);
|
||||
ckh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String ckhStr = ckh.getStringCellValue().trim();
|
||||
bankbillHistory.setCCkh(ckhStr);
|
||||
|
||||
// 流水号
|
||||
HSSFCell lsh = row.getCell(10);
|
||||
lsh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String lshStr = lsh.getStringCellValue().trim();
|
||||
bankbillHistory.setCLsh(lshStr);
|
||||
|
||||
// 卡类型
|
||||
HSSFCell klx = row.getCell(11);
|
||||
klx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String klxStr = klx.getStringCellValue().trim();
|
||||
bankbillHistory.setCKlx(klxStr);
|
||||
|
||||
// 商户订单号
|
||||
HSSFCell shddh = row.getCell(12);
|
||||
shddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String shddhStr = shddh.getStringCellValue().trim();
|
||||
bankbillHistory.setCShddh(shddhStr);
|
||||
|
||||
// 支付方式
|
||||
HSSFCell zffs = row.getCell(13);
|
||||
zffs.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zffsStr = zffs.getStringCellValue().trim();
|
||||
bankbillHistory.setCZffs(zffsStr);
|
||||
|
||||
// 银商订单号
|
||||
HSSFCell ysddh = row.getCell(14);
|
||||
ysddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String ysddhStr = ysddh.getStringCellValue().trim();
|
||||
bankbillHistory.setCYsddh(ysddhStr);
|
||||
|
||||
// 退货订单号
|
||||
HSSFCell thddh = row.getCell(15);
|
||||
thddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String thddhStr = thddh.getStringCellValue().trim();
|
||||
bankbillHistory.setCThddh(thddhStr);
|
||||
|
||||
// 实际支付金额
|
||||
HSSFCell sjzfje = row.getCell(16);
|
||||
sjzfje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String sjzfjeStr = sjzfje.getStringCellValue().trim();
|
||||
bankbillHistory.setCSjzfje(sjzfjeStr);
|
||||
|
||||
// 备注字段
|
||||
HSSFCell bzzd = row.getCell(17);
|
||||
bzzd.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String bzzdStr = bzzd.getStringCellValue().trim();
|
||||
bankbillHistory.setCBzzd(bzzdStr);
|
||||
|
||||
// 付款附言
|
||||
HSSFCell fkfy = row.getCell(18);
|
||||
fkfy.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fkfyStr = fkfy.getStringCellValue().trim();
|
||||
bankbillHistory.setCFkfy(fkfyStr);
|
||||
|
||||
// 钱包优惠金额
|
||||
HSSFCell qbyhje = row.getCell(19);
|
||||
qbyhje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qbyhjeStr = qbyhje.getStringCellValue().trim();
|
||||
bankbillHistory.setCQbyhje(qbyhjeStr);
|
||||
|
||||
// 商户优惠金额
|
||||
HSSFCell shyhje = row.getCell(20);
|
||||
shyhje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String shyhjeStr = shyhje.getStringCellValue().trim();
|
||||
bankbillHistory.setCShyhje(shyhjeStr);
|
||||
|
||||
// 发卡行
|
||||
HSSFCell fkh = row.getCell(21);
|
||||
fkh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fkhStr = fkh.getStringCellValue().trim();
|
||||
bankbillHistory.setCFkh(fkhStr);
|
||||
|
||||
// 分店简称
|
||||
HSSFCell fdjc = row.getCell(22);
|
||||
fdjc.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fdjcStr = fdjc.getStringCellValue().trim();
|
||||
bankbillHistory.setCFdjc(fdjcStr);
|
||||
|
||||
// 其他优惠金额
|
||||
HSSFCell qtyhje = row.getCell(23);
|
||||
qtyhje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qtyhjeStr = qtyhje.getStringCellValue().trim();
|
||||
bankbillHistory.setCQtyhje(qtyhjeStr);
|
||||
|
||||
|
||||
// 分期期数
|
||||
HSSFCell fqqs = row.getCell(24);
|
||||
fqqs.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fqqsStr = fqqs.getStringCellValue().trim();
|
||||
bankbillHistory.setCFqqs(fqqsStr);
|
||||
|
||||
// 分期手续费
|
||||
HSSFCell fqsxf = row.getCell(25);
|
||||
fqsxf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fqsxfStr = fqsxf.getStringCellValue().trim();
|
||||
bankbillHistory.setCFqsxf(fqsxfStr);
|
||||
|
||||
// 分期服务方
|
||||
HSSFCell fqfwf = row.getCell(26);
|
||||
fqfwf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fqfwfStr = fqfwf.getStringCellValue().trim();
|
||||
bankbillHistory.setCFqfwf(fqfwfStr);
|
||||
|
||||
// 分期付息方
|
||||
HSSFCell fqfxf = row.getCell(27);
|
||||
fqfxf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fqfxfStr = fqfxf.getStringCellValue().trim();
|
||||
bankbillHistory.setCFqfxf(fqfxfStr);
|
||||
|
||||
// 子订单号
|
||||
HSSFCell zddh = row.getCell(28);
|
||||
zddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zddhStr = zddh.getStringCellValue().trim();
|
||||
bankbillHistory.setCZddh(zddhStr);
|
||||
|
||||
// 表名
|
||||
bankbillHistory.setBillTableName(bill_table_name);
|
||||
|
||||
list.add(bankbillHistory);
|
||||
}
|
||||
|
||||
responseMap.put("list", list);
|
||||
} else {
|
||||
System.out.println("执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name);
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("执行失败,原因:" + e.getMessage());
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:" + e.getMessage();
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (sheets != null) {
|
||||
sheets.close();
|
||||
}
|
||||
} catch (Exception ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
responseMap.put("errCode", errCode);
|
||||
responseMap.put("errMsg", errMsg);
|
||||
|
||||
|
||||
return responseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取银行端商户POS对账数据
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Object, Object> getBankDataBySHPOS(@RequestBody HashMap<Object, Object> map) {
|
||||
HashMap<Object, Object> responseMap = new HashMap<>();
|
||||
String errCode = "0";
|
||||
String errMsg = "";
|
||||
|
||||
// 先下载文件
|
||||
String host = StringDUtil.changeNullToEmpty(map.get("FTP_HOST"));
|
||||
String portStr = StringDUtil.changeNullToEmpty(map.get("FTP_PORT"));
|
||||
int port = Integer.parseInt("".equals(portStr) ? "21" : portStr);
|
||||
String username = StringDUtil.changeNullToEmpty(map.get("FTP_USER"));
|
||||
String password = StringDUtil.changeNullToEmpty(map.get("FTP_PASSWORD"));
|
||||
String localPath = StringDUtil.changeNullToEmpty(map.get("LOCAL_PATH"));
|
||||
String mch_id = StringDUtil.changeNullToEmpty(map.get("MCH_ID"));
|
||||
String ftp_path = StringDUtil.changeNullToEmpty(map.get("FTP_PATH"));
|
||||
String ftp_file_name = StringDUtil.changeNullToEmpty(map.get("FTP_FILE_NAME"));
|
||||
String bill_table_name = StringDUtil.changeNullToEmpty(map.get("BILL_TABLE_NAME"));
|
||||
String thirdConfigId = StringDUtil.changeNullToEmpty(map.get("ID"));
|
||||
String trade_date = StringDUtil.changeNullToEmpty(map.get("trade_date"));
|
||||
|
||||
|
||||
HSSFWorkbook sheets = null;
|
||||
try {
|
||||
// 下载文件
|
||||
boolean b = DownloadFtpUtil.downloadFtpFile(host, username, password, port, ftp_path, localPath, ftp_file_name);
|
||||
// 判断是否下载到文件
|
||||
if (!b) {
|
||||
throw new RuntimeException("没有下载到文件" + ftp_file_name);
|
||||
}
|
||||
|
||||
// 判断本地是否有文件
|
||||
File file = new File(localPath + "/" + ftp_file_name);
|
||||
if (file.exists()) {
|
||||
// 存在 开始解析 存入数据库
|
||||
FileInputStream fileInputStream = new FileInputStream(localPath + "/" + ftp_file_name);
|
||||
|
||||
sheets = new HSSFWorkbook(fileInputStream);
|
||||
HSSFSheet sheet = sheets.getSheetAt(0);
|
||||
// 获取sheet中第一行行号
|
||||
int firstRowNum = sheet.getFirstRowNum();
|
||||
// 获取sheet中最后一行行号
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
List<BankbillHistory> list = new ArrayList<>();
|
||||
|
||||
for (int i = firstRowNum + 3; i <= lastRowNum - 4; i++) {
|
||||
log.info("正在解析第" + i + "行数据");// 因为表格中第一行为说明,第二行为列标题
|
||||
HSSFRow row = sheet.getRow(i);
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
|
||||
// 清算日期
|
||||
HSSFCell qsrq = row.getCell(0);
|
||||
qsrq.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsrqStr = qsrq.getStringCellValue().trim();
|
||||
|
||||
// 拿第一个字段判断这条记录是否为空 如果为空直接跳出 一般这字段为空就是数据结束了或根本没有
|
||||
if ("".equals(qsrqStr) || "汇总信息".equals(qsrqStr)) {
|
||||
break;
|
||||
}
|
||||
bankbillHistory.setCQsrq(qsrqStr);
|
||||
|
||||
// 交易日期
|
||||
HSSFCell jyrq = row.getCell(1);
|
||||
String jyrqStr = "";
|
||||
jyrq.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
if (HSSFDateUtil.isCellDateFormatted(jyrq)) {
|
||||
Date dateCellValue = jyrq.getDateCellValue();
|
||||
jyrqStr = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd, dateCellValue);
|
||||
}
|
||||
bankbillHistory.setCJyrq(jyrqStr);
|
||||
|
||||
if (i == 0) {
|
||||
trade_date = jyrqStr;
|
||||
}
|
||||
|
||||
// 交易时间
|
||||
HSSFCell jysj = row.getCell(2);
|
||||
jysj.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jysjStr = jysj.getStringCellValue().trim();
|
||||
bankbillHistory.setCJysj(jysjStr);
|
||||
|
||||
// 终端号
|
||||
HSSFCell zdh = row.getCell(3);
|
||||
zdh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zdhStr = zdh.getStringCellValue().trim();
|
||||
bankbillHistory.setCZdh(zdhStr);
|
||||
|
||||
// 卡号
|
||||
HSSFCell card = row.getCell(4);
|
||||
card.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String khStr = card.getStringCellValue().trim();
|
||||
bankbillHistory.setCCard(khStr);
|
||||
|
||||
// 交易类型
|
||||
HSSFCell jylx = row.getCell(5);
|
||||
jylx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jylxStr = jylx.getStringCellValue().trim();
|
||||
bankbillHistory.setCJylx(jylxStr);
|
||||
|
||||
// 交易金额
|
||||
HSSFCell jyje = row.getCell(6);
|
||||
jyje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jyjeStr = jyje.getStringCellValue().trim();
|
||||
log.info("jyjeStr:" + jyjeStr);
|
||||
bankbillHistory.setCJyje(jyjeStr);
|
||||
|
||||
// 清算金额
|
||||
HSSFCell qsje = row.getCell(7);
|
||||
qsje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsjeStr = qsje.getStringCellValue().trim();
|
||||
bankbillHistory.setCQsje(qsjeStr);
|
||||
|
||||
// 手续费
|
||||
HSSFCell sxf = row.getCell(8);
|
||||
sxf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String sxfStr = sxf.getStringCellValue().trim();
|
||||
bankbillHistory.setCSxf(sxfStr);
|
||||
|
||||
// 参考号
|
||||
HSSFCell ckh = row.getCell(9);
|
||||
ckh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String ckhStr = ckh.getStringCellValue().trim();
|
||||
bankbillHistory.setCCkh(ckhStr);
|
||||
|
||||
// 流水号
|
||||
HSSFCell lsh = row.getCell(10);
|
||||
lsh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String lshStr = lsh.getStringCellValue().trim();
|
||||
bankbillHistory.setCLsh(lshStr);
|
||||
|
||||
// 卡类型
|
||||
HSSFCell klx = row.getCell(11);
|
||||
klx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String klxStr = klx.getStringCellValue().trim();
|
||||
bankbillHistory.setCKlx(klxStr);
|
||||
|
||||
// 发卡行
|
||||
HSSFCell fkh = row.getCell(12);
|
||||
fkh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fkhStr = fkh.getStringCellValue().trim();
|
||||
bankbillHistory.setCFkh(fkhStr);
|
||||
|
||||
// 支付方式
|
||||
HSSFCell zffs = row.getCell(13);
|
||||
zffs.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zffsStr = zffs.getStringCellValue().trim();
|
||||
bankbillHistory.setCZffs(zffsStr);
|
||||
|
||||
// 银商订单号
|
||||
HSSFCell ysddh = row.getCell(15);
|
||||
ysddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String ysddhStr = ysddh.getStringCellValue().trim();
|
||||
log.info("ysddhStr:" + ysddhStr);
|
||||
bankbillHistory.setCYsddh(ysddhStr);
|
||||
|
||||
// 商户订单号
|
||||
HSSFCell shddh = row.getCell(16);
|
||||
shddh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String shddhStr = shddh.getStringCellValue().trim();
|
||||
bankbillHistory.setCShddh(shddhStr);
|
||||
|
||||
// 备注字段
|
||||
HSSFCell bzzd = row.getCell(18);
|
||||
bzzd.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String bzzdStr = bzzd.getStringCellValue().trim();
|
||||
bankbillHistory.setCBzzd(bzzdStr);
|
||||
|
||||
// 钱包优惠金额
|
||||
HSSFCell fdmcjj = row.getCell(19);
|
||||
fdmcjj.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fdmcjjStr = fdmcjj.getStringCellValue().trim();
|
||||
bankbillHistory.setCFdjc(fdmcjjStr);
|
||||
|
||||
// 表名
|
||||
bankbillHistory.setBillTableName(bill_table_name);
|
||||
|
||||
list.add(bankbillHistory);
|
||||
}
|
||||
responseMap.put("list", list);
|
||||
} else {
|
||||
System.out.println("执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name);
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("执行失败,原因:" + e.getMessage());
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:" + e.getMessage();
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (sheets != null) {
|
||||
sheets.close();
|
||||
}
|
||||
} catch (Exception ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
responseMap.put("errCode", errCode);
|
||||
responseMap.put("errMsg", errMsg);
|
||||
|
||||
|
||||
return responseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取银行端商户银联卡对账数据
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Object, Object> getBankDataBySHYLK(@RequestBody HashMap<Object, Object> map) {
|
||||
HashMap<Object, Object> responseMap = new HashMap<>();
|
||||
String errCode = "0";
|
||||
String errMsg = "";
|
||||
|
||||
// 先下载文件
|
||||
String host = StringDUtil.changeNullToEmpty(map.get("FTP_HOST"));
|
||||
String portStr = StringDUtil.changeNullToEmpty(map.get("FTP_PORT"));
|
||||
int port = Integer.parseInt("".equals(portStr) ? "21" : portStr);
|
||||
String username = StringDUtil.changeNullToEmpty(map.get("FTP_USER"));
|
||||
String password = StringDUtil.changeNullToEmpty(map.get("FTP_PASSWORD"));
|
||||
String localPath = StringDUtil.changeNullToEmpty(map.get("LOCAL_PATH"));
|
||||
String mch_id = StringDUtil.changeNullToEmpty(map.get("MCH_ID"));
|
||||
String ftp_path = StringDUtil.changeNullToEmpty(map.get("FTP_PATH"));
|
||||
String ftp_file_name = StringDUtil.changeNullToEmpty(map.get("FTP_FILE_NAME"));
|
||||
String bill_table_name = StringDUtil.changeNullToEmpty(map.get("BILL_TABLE_NAME"));
|
||||
String thirdConfigId = StringDUtil.changeNullToEmpty(map.get("ID"));
|
||||
String trade_date = StringDUtil.changeNullToEmpty(map.get("trade_date"));
|
||||
|
||||
|
||||
HSSFWorkbook sheets = null;
|
||||
try {
|
||||
// 下载文件
|
||||
boolean b = DownloadFtpUtil.downloadFtpFile(host, username, password, port, ftp_path, localPath, ftp_file_name);
|
||||
// 判断是否下载到文件
|
||||
if (!b) {
|
||||
throw new RuntimeException("没有下载到文件" + ftp_file_name);
|
||||
}
|
||||
|
||||
// 判断本地是否有文件
|
||||
File file = new File(localPath + "/" + ftp_file_name);
|
||||
if (file.exists()) {
|
||||
// 存在 开始解析 存入数据库
|
||||
FileInputStream fileInputStream = new FileInputStream(localPath + "/" + ftp_file_name);
|
||||
|
||||
sheets = new HSSFWorkbook(fileInputStream);
|
||||
HSSFSheet sheet = sheets.getSheetAt(0);
|
||||
// 获取sheet中第一行行号
|
||||
int firstRowNum = sheet.getFirstRowNum();
|
||||
// 获取sheet中最后一行行号
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
List<BankbillHistory> list = new ArrayList<>();
|
||||
|
||||
for (int i = firstRowNum + 3; i <= lastRowNum - 2; i++) {// 因为表格中第一行为说明,第二行为列标题
|
||||
HSSFRow row = sheet.getRow(i);
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
|
||||
// 清算日期
|
||||
HSSFCell qsrq = row.getCell(0);
|
||||
qsrq.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsrqStr = qsrq.getStringCellValue().trim();
|
||||
|
||||
// 拿第一个字段判断这条记录是否为空 如果为空直接跳出 一般这字段为空就是数据结束了或根本没有
|
||||
if ("".equals(qsrqStr) || "合计".equals(qsrqStr)) {
|
||||
break;
|
||||
}
|
||||
bankbillHistory.setCQsrq(qsrqStr);
|
||||
|
||||
// 交易日期
|
||||
HSSFCell jyrq = row.getCell(1);
|
||||
String jyrqStr = "";
|
||||
jyrq.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
if (HSSFDateUtil.isCellDateFormatted(jyrq)) {
|
||||
Date dateCellValue = jyrq.getDateCellValue();
|
||||
jyrqStr = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd, dateCellValue);
|
||||
}
|
||||
bankbillHistory.setCJyrq(jyrqStr);
|
||||
|
||||
if (i == 0) {
|
||||
trade_date = jyrqStr;
|
||||
}
|
||||
|
||||
// 交易时间
|
||||
HSSFCell jysj = row.getCell(2);
|
||||
jysj.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jysjStr = jysj.getStringCellValue().trim();
|
||||
bankbillHistory.setCJysj(jysjStr);
|
||||
|
||||
// 终端号
|
||||
HSSFCell zdh = row.getCell(3);
|
||||
zdh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String zdhStr = zdh.getStringCellValue().trim();
|
||||
bankbillHistory.setCZdh(zdhStr);
|
||||
|
||||
// 卡号
|
||||
HSSFCell card = row.getCell(4);
|
||||
card.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String khStr = card.getStringCellValue().trim();
|
||||
bankbillHistory.setCCard(khStr);
|
||||
|
||||
// 交易类型
|
||||
HSSFCell jylx = row.getCell(5);
|
||||
jylx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jylxStr = jylx.getStringCellValue().trim();
|
||||
bankbillHistory.setCJylx(jylxStr);
|
||||
|
||||
// 交易金额
|
||||
HSSFCell jyje = row.getCell(6);
|
||||
jyje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String jyjeStr = jyje.getStringCellValue().trim();
|
||||
bankbillHistory.setCJyje(jyjeStr);
|
||||
|
||||
// 清算金额
|
||||
HSSFCell qsje = row.getCell(7);
|
||||
qsje.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String qsjeStr = qsje.getStringCellValue().trim();
|
||||
bankbillHistory.setCQsje(qsjeStr);
|
||||
|
||||
// 手续费
|
||||
HSSFCell sxf = row.getCell(8);
|
||||
sxf.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String sxfStr = sxf.getStringCellValue().trim();
|
||||
bankbillHistory.setCSxf(sxfStr);
|
||||
|
||||
// 流水号
|
||||
HSSFCell lsh = row.getCell(9);
|
||||
lsh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String lshStr = lsh.getStringCellValue().trim();
|
||||
bankbillHistory.setCLsh(lshStr);
|
||||
|
||||
// 卡类型
|
||||
HSSFCell klx = row.getCell(10);
|
||||
klx.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String klxStr = klx.getStringCellValue().trim();
|
||||
bankbillHistory.setCKlx(klxStr);
|
||||
|
||||
// 发卡行
|
||||
HSSFCell fkh = row.getCell(11);
|
||||
fkh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String fkhStr = fkh.getStringCellValue().trim();
|
||||
bankbillHistory.setCFkh(fkhStr);
|
||||
|
||||
// 系统参考号 (对应银商订单号)
|
||||
HSSFCell xtckh = row.getCell(12);
|
||||
xtckh.setCellType(Cell.CELL_TYPE_STRING);
|
||||
String xtckhStr = xtckh.getStringCellValue().trim();
|
||||
|
||||
// 支付方式
|
||||
bankbillHistory.setCZffs("银行卡支付");
|
||||
|
||||
// 银商订单号
|
||||
bankbillHistory.setCYsddh(xtckhStr);
|
||||
|
||||
// 表名
|
||||
bankbillHistory.setBillTableName(bill_table_name);
|
||||
|
||||
list.add(bankbillHistory);
|
||||
}
|
||||
responseMap.put("list", list);
|
||||
} else {
|
||||
System.out.println("执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name);
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:路径" + ftp_path + "下无下载文件" + ftp_file_name;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("执行失败,原因:" + e.getMessage());
|
||||
|
||||
errCode = "999";
|
||||
errMsg = "执行失败,原因:" + e.getMessage();
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (sheets != null) {
|
||||
sheets.close();
|
||||
}
|
||||
} catch (Exception ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
responseMap.put("errCode", errCode);
|
||||
responseMap.put("errMsg", errMsg);
|
||||
return responseMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信支付对账数据
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Object, Object> getBankDataByWXAPI(@RequestBody HashMap<Object, Object> map) {
|
||||
List<BankbillHistory> list = new ArrayList<>();
|
||||
log.info("开始获取微信账单");
|
||||
HashMap<Object, Object> responseMap = new HashMap<>();
|
||||
String errCode = "0";
|
||||
String errMsg = "";
|
||||
|
||||
String localPath = StringDUtil.changeNullToEmpty(map.get("LOCAL_PATH"));
|
||||
String mch_id = StringDUtil.changeNullToEmpty(map.get("MCH_ID"));
|
||||
String trade_date = StringDUtil.changeNullToEmpty(map.get("trade_date"));
|
||||
|
||||
HashMap<String, Object> reqMap = new HashMap<>();
|
||||
reqMap.put("grant_type", grant_type);
|
||||
reqMap.put("appid", appid);
|
||||
reqMap.put("secret", secret);
|
||||
|
||||
String randomStr = RandomUtil.randomString(32);
|
||||
|
||||
String signString = "appid=" + appid + "&bill_date=" + trade_date + "&bill_type=ALL&mch_id=" + mch_id + "&nonce_str=" + randomStr + "&key=9b996ad13a7d11ee8c2b000c29686702";
|
||||
String sign = SecureUtil.md5(signString).toUpperCase();
|
||||
String reqXml = "<xml>\n" +
|
||||
" <appid>" + appid + "</appid>\n" +
|
||||
" <bill_date>" + trade_date + "</bill_date>\n" +
|
||||
" <bill_type>ALL</bill_type>\n" +
|
||||
" <mch_id>" + mch_id + "</mch_id>\n" +
|
||||
" <nonce_str>" + randomStr + "</nonce_str>\n" +
|
||||
" <sign>" + sign + "</sign>\n" +
|
||||
"</xml>";
|
||||
// 获取access_token
|
||||
String body1 = HttpUtil.createPost("https://api.mch.weixin.qq.com/pay/downloadbill").header("Content-Type", "text/xml").body(reqXml).execute().body();
|
||||
String[] split = body1.split("\n");
|
||||
for (int i = 1; i < split.length - 2; i++) {
|
||||
String[] split1 = split[i].split(",");
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
int flag = 0;
|
||||
for (int j = 0; j < split1.length; j++) {
|
||||
if (j == 0) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
String[] split2 = s.split(" ");
|
||||
bankbillHistory.setCQsrq(split2[0]);
|
||||
bankbillHistory.setCJyrq(split2[0]);
|
||||
bankbillHistory.setCJysj(split2[1]);
|
||||
}
|
||||
if (j == 1) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
bankbillHistory.setCZdh(s);
|
||||
}
|
||||
if (j == 2) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
bankbillHistory.setCCkh(s);
|
||||
}
|
||||
if (j == 5) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
bankbillHistory.setCYsddh(s);
|
||||
}
|
||||
if (j == 6) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
bankbillHistory.setCShddh(s);
|
||||
}
|
||||
if (j == 7) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
bankbillHistory.setCCard(s);
|
||||
}
|
||||
if (j == 9) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
if (s.equals("REFUND")) {
|
||||
flag = -1;
|
||||
}
|
||||
}
|
||||
if (j == 21) {
|
||||
String s = split1[j].replaceAll("`", "");
|
||||
String s1 = s.replaceAll(" ", ",").replaceAll("\\\\", "");
|
||||
JSONObject entries = JSONUtil.parseObj(s1);
|
||||
Object zfje = entries.get("zfje");
|
||||
if (flag < 0) {
|
||||
bankbillHistory.setCJyje("-" + Convert.toDouble(zfje));
|
||||
} else {
|
||||
bankbillHistory.setCJyje(Convert.toDouble(zfje).toString());
|
||||
}
|
||||
}
|
||||
bankbillHistory.setBillTableName("微信支付账单");
|
||||
}
|
||||
list.add(bankbillHistory);
|
||||
}
|
||||
// 获取access_token
|
||||
String body = HttpUtil.createPost("https://api.weixin.qq.com/cgi-bin/stable_token").body(JSONUtil.toJsonStr(reqMap)).execute().body();
|
||||
|
||||
String access_token = JSONUtil.parseObj(body).getStr("access_token");
|
||||
// 获取医保账单下载地址
|
||||
// https://api.weixin.qq.com/payinsurance/billdownload?access_token=ACCESS_TOKEN
|
||||
String signYBString = "appid=" + appid + "&bill_date=" + trade_date + "&bill_type=ALL&mch_id=" + mch_id + "&nonce_str=" + randomStr + "&key=f6d394fbc881fee73172232a08dc9c03";
|
||||
String signYB = SecureUtil.md5(signYBString).toUpperCase();
|
||||
String reqYbXml = "<xml>\n" +
|
||||
" <appid>" + appid + "</appid>\n" +
|
||||
" <bill_date>" + trade_date + "</bill_date>\n" +
|
||||
" <bill_type>ALL</bill_type>\n" +
|
||||
" <mch_id>" + mch_id + "</mch_id>\n" +
|
||||
" <nonce_str>" + randomStr + "</nonce_str>\n" +
|
||||
" <sign>" + signYB + "</sign>\n" +
|
||||
"</xml>";
|
||||
String resBody = HttpUtil.createPost("https://api.weixin.qq.com/payinsurance/billdownload?access_token=" + access_token).header("Content-Type", "text/xml").body(reqYbXml).execute().body();
|
||||
Document document = XmlUtil.parseXml(resBody);
|
||||
Element elementG = XmlUtil.getRootElement(document);
|
||||
Element returnCode = XmlUtil.getElement(elementG, "return_code");
|
||||
if (returnCode.getTextContent().equals("SUCCESS")) {// 响应成功
|
||||
// 下载文件
|
||||
Element downloadUrl = XmlUtil.getElement(elementG, "download_url");
|
||||
String dwUrl = downloadUrl.getTextContent();
|
||||
log.info("开始下载文件");
|
||||
HttpUtil.downloadFileFromUrl(dwUrl, localPath + File.separator + trade_date + ".csv");
|
||||
HttpUtil.downloadFileFromUrl(dwUrl, localPath + File.separator + trade_date + ".txt");
|
||||
// HttpUtil.downloadFileFromUrl(dwUrl, localPath);
|
||||
log.info("下载文件成功");
|
||||
CsvReader reader = CsvUtil.getReader();
|
||||
try {
|
||||
|
||||
CsvData read = reader.read(FileUtil.file(localPath + File.separator + trade_date + ".csv"));
|
||||
List<CsvRow> rows = read.getRows();
|
||||
|
||||
for (int i = 1; i < rows.size(); i++) {
|
||||
CsvRow row = rows.get(i);
|
||||
BankbillHistory bankbillHistory = new BankbillHistory();
|
||||
String s = row.get(0).replaceAll("`", "");
|
||||
String[] s1 = s.split(" ");
|
||||
bankbillHistory.setCJyrq(s1[0]);
|
||||
bankbillHistory.setCQsrq(s1[0]);
|
||||
bankbillHistory.setCJysj(s1[1]);
|
||||
bankbillHistory.setCZdh(row.get(1).replaceAll("`", ""));
|
||||
bankbillHistory.setCCkh(row.get(2).replaceAll("`", ""));
|
||||
bankbillHistory.setCLsh(row.get(5).replaceAll("`", ""));
|
||||
bankbillHistory.setCShddh(row.get(6).replaceAll("`", ""));
|
||||
bankbillHistory.setCCard(row.get(7).replaceAll("`", ""));
|
||||
bankbillHistory.setCYsddh(row.get(25).replaceAll("`", ""));
|
||||
if (row.get(46).replaceAll("`", "").equals("0.00")) {
|
||||
continue;
|
||||
}
|
||||
if (row.get(45).replaceAll("`", "").equals("REFUND")) {
|
||||
bankbillHistory.setCJyje("-" + row.get(46).replaceAll("`", ""));
|
||||
} else {
|
||||
bankbillHistory.setCJyje(row.get(46).replaceAll("`", ""));
|
||||
}
|
||||
bankbillHistory.setBillTableName("微信支付账单");
|
||||
list.add(bankbillHistory);
|
||||
}
|
||||
responseMap.put("list", list);
|
||||
} catch (IORuntimeException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 返回响应结果
|
||||
Element returnMsg = XmlUtil.getElement(elementG, "return_msg");
|
||||
errCode = "999";
|
||||
errMsg = returnMsg.getTextContent();
|
||||
}
|
||||
responseMap.put("errCode", errCode);
|
||||
responseMap.put("errMsg", errMsg);
|
||||
return responseMap;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user