generated from root/miduo_server
订单逻辑修改
parent
1c372e3f5e
commit
f2709bc5ca
|
@ -4,13 +4,16 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jmfy.WebSecurityConfig;
|
||||
import com.jmfy.dao.*;
|
||||
import com.jmfy.handler.HeFuManager;
|
||||
import com.jmfy.model.*;
|
||||
import com.jmfy.model.config.SRechargeCommodityConfig;
|
||||
import com.jmfy.model.vo.OrderExcelVo;
|
||||
import com.jmfy.redisProperties.RedisUserKey;
|
||||
import com.jmfy.utils.*;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import com.jmfy.utils.DateUtil;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -32,7 +35,6 @@ import java.net.HttpURLConnection;
|
|||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by huangds on 2017/10/24.
|
||||
|
@ -156,7 +158,7 @@ public class OrderInfoController {
|
|||
/**
|
||||
* 获取文件路径
|
||||
*/
|
||||
private String getPath(){
|
||||
private static String getPath(){
|
||||
// 文件路径
|
||||
String osName = System.getProperty("os.name");
|
||||
String path = "";
|
||||
|
@ -209,6 +211,8 @@ public class OrderInfoController {
|
|||
orderHashMap.putAll(map);
|
||||
});
|
||||
|
||||
Map<String, ServerInfo> serverMap = serverInfoDao.getAllServerMap();
|
||||
|
||||
// 渠道信息
|
||||
// List<ChannelInfo> channelInfos = channelInfoDao.getChannelInfoList();
|
||||
// Map<String, String> channelMap = channelInfos.stream().collect(Collectors.toMap(ChannelInfo::getId, ChannelInfo::getName, (key1, key2) -> key2));
|
||||
|
@ -259,7 +263,12 @@ public class OrderInfoController {
|
|||
corder.setRegisterTime("");
|
||||
corder.setOpenId("");
|
||||
// 渠道id赋值
|
||||
corder.setCc_id("");
|
||||
ServerInfo info = serverMap.get(String.valueOf(server));
|
||||
if (info != null){
|
||||
corder.setCc_id(info.getSub_channel());
|
||||
}else {
|
||||
corder.setCc_id("");
|
||||
}
|
||||
|
||||
// 获取订单配置
|
||||
SRechargeCommodityConfig config = SRechargeCommodityConfig.sdkRechargeCommodityConfigMap.get(cgPayOrder.getGoodsId());
|
||||
|
@ -301,119 +310,94 @@ public class OrderInfoController {
|
|||
|
||||
/**
|
||||
* 导出excel到文件目录
|
||||
* @param cgPayOrders
|
||||
* @param cgPayOrders 订单列表
|
||||
*/
|
||||
private void exportOrderExcel(String name,List<Corder> cgPayOrders){
|
||||
long start = DateUtil.now();
|
||||
FileOutputStream fOut = null;
|
||||
try
|
||||
{
|
||||
int excelId = seqUtils.getSequence("c_order_excel_id");
|
||||
String excel = getPath() + name + "_" + excelId + "_" + start + ".xls";
|
||||
LOGGER.info("开始导出订单操作,名称:{},长度:{}",excel, cgPayOrders.size());
|
||||
fOut = new FileOutputStream(excel);
|
||||
// 产生工作簿对象
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
HSSFCellStyle contextstyle = workbook.createCellStyle();
|
||||
//产生工作表对象
|
||||
HSSFSheet sheet = workbook.createSheet();
|
||||
int rowIndex = 1,cellIndex = 0;
|
||||
//获取实体类的所有属性,返回Field数组
|
||||
Field[] field = cgPayOrders.get(0).getClass().getDeclaredFields();
|
||||
//创建一行
|
||||
HSSFRow headerRow = sheet.createRow(0);
|
||||
while (cellIndex < field.length){
|
||||
//创建一列
|
||||
HSSFCell cell = headerRow.createCell(cellIndex);
|
||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||
cell.setCellValue(field[cellIndex].getAnnotation(Fields.class).value());
|
||||
cellIndex++;
|
||||
}
|
||||
|
||||
for (Corder cgPayOrder : cgPayOrders) {
|
||||
cellIndex = 0;
|
||||
//创建一行
|
||||
HSSFRow currentRow = sheet.createRow(rowIndex);
|
||||
while (cellIndex < field.length) {
|
||||
//创建一列
|
||||
HSSFCell cell = currentRow.createCell(cellIndex);
|
||||
try (FileOutputStream fOut = new FileOutputStream(getExcelFilePath(name, start))) {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
CellStyle contextStyle = workbook.createCellStyle();
|
||||
int rowIndex = 1, cellIndex = 0;
|
||||
Field[] fields = cgPayOrders.get(0).getClass().getDeclaredFields();
|
||||
Sheet sheet = workbook.createSheet();
|
||||
Row headerRow = sheet.createRow(0);
|
||||
while (cellIndex < fields.length) {
|
||||
Cell cell = headerRow.createCell(cellIndex);
|
||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||
//通过反射获取属性的value
|
||||
Object value = getFieldValueByName(field[cellIndex].getName(), cgPayOrder);
|
||||
//data是否为数值型
|
||||
boolean isNum = false;
|
||||
//data是否为整数
|
||||
boolean isInteger = false;
|
||||
//data是否为百分数
|
||||
boolean isPercent = false;
|
||||
//是否是时间
|
||||
boolean isDate = false;
|
||||
// 是否是大数
|
||||
boolean isBigNum = false;
|
||||
if (value != null) {
|
||||
//判断data是否为数值型
|
||||
isNum = value.toString().matches("^(-?\\d+)(\\.\\d+)?$");
|
||||
//判断data是否为整数(小数部分是否为0)
|
||||
isInteger = value.toString().matches("^[-\\+]?[\\d]*$");
|
||||
//判断data是否为百分数(是否包含“%”)
|
||||
isPercent = value.toString().contains("%");
|
||||
// 是否是时间
|
||||
isDate = value.getClass() == Date.class;
|
||||
// 大数字
|
||||
isBigNum = value.toString().length() >= 11;
|
||||
}
|
||||
|
||||
// 时间
|
||||
if (isDate) {
|
||||
cell.setCellValue(DateUtil.stampToString(value.toString()));
|
||||
}
|
||||
// 大数字
|
||||
else if (isBigNum) {
|
||||
cell.setCellValue(value.toString());
|
||||
}
|
||||
// 数字
|
||||
else if (isNum && !isPercent) {
|
||||
if (isInteger) {
|
||||
//数据格式只显示整数
|
||||
contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,#0"));
|
||||
} else {
|
||||
//保留两位小数点
|
||||
contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
|
||||
}
|
||||
cell.setCellStyle(contextstyle);
|
||||
cell.setCellValue(Double.parseDouble(value.toString()));
|
||||
}
|
||||
// 字符串
|
||||
else {
|
||||
cell.setCellStyle(contextstyle);
|
||||
cell.setCellValue(Optional.ofNullable(value).map(String::valueOf).orElse(""));
|
||||
}
|
||||
cell.setCellValue(fields[cellIndex].getAnnotation(Fields.class).value());
|
||||
cellIndex++;
|
||||
}
|
||||
rowIndex++;
|
||||
}
|
||||
workbook.write(fOut);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error("导出订单报错:{}",e.getMessage(),e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fOut != null){
|
||||
fOut.flush();
|
||||
}
|
||||
if (fOut != null){
|
||||
fOut.close();
|
||||
|
||||
for (Corder cgPayOrder : cgPayOrders) {
|
||||
if (rowIndex > 65535) {
|
||||
// 超过行数限制,创建新的工作表
|
||||
sheet = workbook.createSheet();
|
||||
headerRow = sheet.createRow(0);
|
||||
cellIndex = 0;
|
||||
while (cellIndex < fields.length) {
|
||||
Cell cell = headerRow.createCell(cellIndex);
|
||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||
cell.setCellValue(fields[cellIndex].getAnnotation(Fields.class).value());
|
||||
cellIndex++;
|
||||
}
|
||||
rowIndex = 1;
|
||||
}
|
||||
|
||||
cellIndex = 0;
|
||||
Row currentRow = sheet.createRow(rowIndex);
|
||||
while (cellIndex < fields.length) {
|
||||
Cell cell = currentRow.createCell(cellIndex);
|
||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||
Object value = getFieldValueByName(fields[cellIndex].getName(), cgPayOrder);
|
||||
setCellValue(cell, value, contextStyle);
|
||||
cellIndex++;
|
||||
}
|
||||
rowIndex++;
|
||||
}
|
||||
workbook.write(fOut);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOGGER.error("关闭输入流报错:{}",e.getMessage(),e);
|
||||
}
|
||||
LOGGER.info("导出订单操作,excel文件写入耗时:{}毫秒", DateUtil.now() - start);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("导出订单报错:{}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getExcelFilePath(String name, long start) throws Exception {
|
||||
int excelId = seqUtils.getSequence("c_order_excel_id");
|
||||
return getPath() + name + "_" + excelId + "_" + start + ".xlsx";
|
||||
}
|
||||
|
||||
private void setCellValue(Cell cell, Object value, CellStyle contextStyle) {
|
||||
boolean isNum = false;
|
||||
boolean isInteger = false;
|
||||
boolean isPercent = false;
|
||||
boolean isDate = false;
|
||||
boolean isBigNum = false;
|
||||
|
||||
if (value != null) {
|
||||
isNum = value.toString().matches("^(-?\\d+)(\\.\\d+)?$");
|
||||
isInteger = value.toString().matches("^[-\\+]?[\\d]*$");
|
||||
isPercent = value.toString().contains("%");
|
||||
isDate = value.getClass() == Date.class;
|
||||
isBigNum = value.toString().length() >= 11;
|
||||
}
|
||||
|
||||
if (isDate) {
|
||||
cell.setCellValue(DateUtil.stampToString(value.toString()));
|
||||
} else if (isBigNum) {
|
||||
cell.setCellValue(value.toString());
|
||||
} else if (isNum && !isPercent) {
|
||||
if (isInteger) {
|
||||
contextStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,#0"));
|
||||
} else {
|
||||
contextStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
|
||||
}
|
||||
cell.setCellStyle(contextStyle);
|
||||
cell.setCellValue(Double.parseDouble(value.toString()));
|
||||
} else {
|
||||
cell.setCellStyle(contextStyle);
|
||||
cell.setCellValue(Optional.ofNullable(value).map(String::valueOf).orElse(""));
|
||||
}
|
||||
// LoginController.addQueue("订单列表《"+name+"》导出完成!");
|
||||
LOGGER.info("导出订单操作,excel文件写入耗时:{}毫秒",DateUtil.now()-start);
|
||||
}
|
||||
|
||||
public static Object getFieldValueByName(String fieldName, Object o) {
|
||||
|
@ -427,26 +411,26 @@ public class OrderInfoController {
|
|||
}
|
||||
}
|
||||
|
||||
private static JSONObject sendGet(String params) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// URL url = new URL(URL);
|
||||
URL url = new URL("http://60.1.1.212:9991/delivery/callback");
|
||||
HttpURLConnection urlCon = (HttpURLConnection)url.openConnection();
|
||||
urlCon.setDoOutput(true);
|
||||
urlCon.setDoInput(true);
|
||||
urlCon.setRequestMethod("POST");
|
||||
urlCon.setRequestProperty("Cookie","lhuj1i5hcu80edg3fjhesj4ak3");
|
||||
OutputStreamWriter out = new OutputStreamWriter(urlCon.getOutputStream(), StandardCharsets.UTF_8);
|
||||
out.write(params);
|
||||
out.flush();
|
||||
out.close();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
return JSON.parseObject(sb.toString());
|
||||
}
|
||||
// private static JSONObject sendGet(String params) throws IOException {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
//// URL url = new URL(URL);
|
||||
// URL url = new URL("http://60.1.1.212:9991/delivery/callback");
|
||||
// HttpURLConnection urlCon = (HttpURLConnection)url.openConnection();
|
||||
// urlCon.setDoOutput(true);
|
||||
// urlCon.setDoInput(true);
|
||||
// urlCon.setRequestMethod("POST");
|
||||
// urlCon.setRequestProperty("Cookie","lhuj1i5hcu80edg3fjhesj4ak3");
|
||||
// OutputStreamWriter out = new OutputStreamWriter(urlCon.getOutputStream(), StandardCharsets.UTF_8);
|
||||
// out.write(params);
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// BufferedReader reader = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), StandardCharsets.UTF_8));
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// sb.append(line);
|
||||
// }
|
||||
// return JSON.parseObject(sb.toString());
|
||||
// }
|
||||
|
||||
@RequestMapping(value = "toOrderPage",method = RequestMethod.GET)
|
||||
public String toOrderPage(ModelMap map,HttpSession session) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue