|
@@ -7,17 +7,11 @@ import com.malk.jiuan.entity.ConvertSales;
|
|
|
import com.malk.jiuan.entity.Sales;
|
|
import com.malk.jiuan.entity.Sales;
|
|
|
import com.malk.jiuan.entity.SalesReturn;
|
|
import com.malk.jiuan.entity.SalesReturn;
|
|
|
import com.malk.jiuan.service.JiuanService;
|
|
import com.malk.jiuan.service.JiuanService;
|
|
|
-import com.malk.server.dingtalk.DDR_New;
|
|
|
|
|
-import com.malk.service.dingtalk.DDClient;
|
|
|
|
|
-import com.malk.utils.UtilHttp;
|
|
|
|
|
-import com.malk.utils.UtilMap;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
import okhttp3.*;
|
|
|
import okio.BufferedSink;
|
|
import okio.BufferedSink;
|
|
|
import okio.Okio;
|
|
import okio.Okio;
|
|
|
-import okio.Sink;
|
|
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -26,12 +20,14 @@ import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -41,39 +37,18 @@ public class JiuanServiceImpl implements JiuanService {
|
|
|
private final static String SHOP_NUMBER = "TJMP1F140";//商铺号
|
|
private final static String SHOP_NUMBER = "TJMP1F140";//商铺号
|
|
|
private final static String CASH_REGISTER_Number = "1400";//收银机号
|
|
private final static String CASH_REGISTER_Number = "1400";//收银机号
|
|
|
private final static String GOODS_NUMBER = "00101701";//货品编码
|
|
private final static String GOODS_NUMBER = "00101701";//货品编码
|
|
|
-
|
|
|
|
|
private final static String DATE_PATTERN1 = "yyyy-MM-dd HH:mm:ss";
|
|
private final static String DATE_PATTERN1 = "yyyy-MM-dd HH:mm:ss";
|
|
|
- private final static String DATE_PATTERN2 = "yyyyMMddHHmmss";
|
|
|
|
|
- private final static String DATE_PATTERN3 = "yyyyMMdd";
|
|
|
|
|
-
|
|
|
|
|
- @Value(value = "${dingtalk.spaceId}")
|
|
|
|
|
- private String SPACE_ID;
|
|
|
|
|
|
|
|
|
|
- @Value(value = "${dingtalk.unionId}")
|
|
|
|
|
- private String UNION_ID;
|
|
|
|
|
|
|
+ @Value(value = "${uploadFile.path}")
|
|
|
|
|
+ private String uploadFilePath;
|
|
|
|
|
|
|
|
@Value(value = "${saveFile.path}")
|
|
@Value(value = "${saveFile.path}")
|
|
|
private String saveFilePath;
|
|
private String saveFilePath;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private DDClient ddClient;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void convertFile() {
|
|
public void convertFile() {
|
|
|
- // 获取当前时间
|
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
- // 定义格式:yyyyMMddhhmmss
|
|
|
|
|
- DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern(DATE_PATTERN2);
|
|
|
|
|
- // 定义格式:yyyyMMdd
|
|
|
|
|
- DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern(DATE_PATTERN3);
|
|
|
|
|
- // 格式化时间
|
|
|
|
|
- String formattedTime = now.format(formatter2);
|
|
|
|
|
-
|
|
|
|
|
- String formattedTime3 = now.format(formatter3);
|
|
|
|
|
-
|
|
|
|
|
//搜索钉盘文件
|
|
//搜索钉盘文件
|
|
|
- Map query = new HashMap();
|
|
|
|
|
|
|
+ /*Map query = new HashMap();
|
|
|
query.put("parentId",0);
|
|
query.put("parentId",0);
|
|
|
query.put("unionId", UNION_ID);
|
|
query.put("unionId", UNION_ID);
|
|
|
query.put("maxResults",10);
|
|
query.put("maxResults",10);
|
|
@@ -105,90 +80,114 @@ public class JiuanServiceImpl implements JiuanService {
|
|
|
|
|
|
|
|
List<String> resourceUrls = UtilMap.getList(headerSignatureInfo, "resourceUrls");
|
|
List<String> resourceUrls = UtilMap.getList(headerSignatureInfo, "resourceUrls");
|
|
|
|
|
|
|
|
- downloadDdFile(resourceUrls.get(0) ,headers, saveFilePath + fileName);
|
|
|
|
|
|
|
+ downloadDdFile(resourceUrls.get(0) ,headers, saveFilePath + fileName);*/
|
|
|
|
|
+ log.info("------------------开始转换文件---------------------");
|
|
|
|
|
|
|
|
- List<Sales> salesList = new ArrayList<>();
|
|
|
|
|
|
|
+ //读取文件夹下所有门店流水数据
|
|
|
|
|
+ File folder = new File(uploadFilePath);
|
|
|
|
|
|
|
|
- //销售单
|
|
|
|
|
- EasyExcel.read(saveFilePath + fileName, Sales.class, new PageReadListener<Sales>(dataList -> {
|
|
|
|
|
- for (Sales Sales : dataList) {
|
|
|
|
|
- log.info("读取到一条数据{}", JSON.toJSONString(Sales));
|
|
|
|
|
- salesList.add(Sales);
|
|
|
|
|
- }
|
|
|
|
|
- })).sheet(0).doRead();
|
|
|
|
|
-
|
|
|
|
|
- //退货单
|
|
|
|
|
- EasyExcel.read(saveFilePath + fileName, SalesReturn.class, new PageReadListener<SalesReturn>(dataList -> {
|
|
|
|
|
- for (SalesReturn salesReturn : dataList) {
|
|
|
|
|
- log.info("读取到一条数据{}", JSON.toJSONString(salesReturn));
|
|
|
|
|
- Sales sales = new Sales();
|
|
|
|
|
- sales.setZfze(salesReturn.getYtze());//应退金额
|
|
|
|
|
- sales.setZfsj(salesReturn.getTksj());//退款时间
|
|
|
|
|
- sales.setZffs(salesReturn.getZffs());//支付方式
|
|
|
|
|
- salesList.add(sales);
|
|
|
|
|
- }
|
|
|
|
|
- })).sheet(1).doRead();
|
|
|
|
|
|
|
+ if (folder.exists() && folder.isDirectory()) {
|
|
|
|
|
+ File[] files = folder.listFiles();
|
|
|
|
|
|
|
|
- //支付时间升序
|
|
|
|
|
- List<Sales> sortedSalesList = salesList.stream()
|
|
|
|
|
- .sorted(Comparator.comparing(Sales::getZfsj))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
+ if (files != null) {
|
|
|
|
|
+ for (File file : files) {
|
|
|
|
|
+ List<Sales> salesList = new ArrayList<>();
|
|
|
|
|
|
|
|
- AtomicInteger counter = new AtomicInteger(1);
|
|
|
|
|
- String currentDatePrefix = "";
|
|
|
|
|
|
|
+ //销售单
|
|
|
|
|
+ EasyExcel.read(file.getPath(), Sales.class, new PageReadListener<Sales>(dataList -> {
|
|
|
|
|
+ for (Sales Sales : dataList) {
|
|
|
|
|
+ log.info("读取到一条数据{}", JSON.toJSONString(Sales));
|
|
|
|
|
+ salesList.add(Sales);
|
|
|
|
|
+ }
|
|
|
|
|
+ })).sheet(0).doRead();
|
|
|
|
|
|
|
|
- List<ConvertSales> convertSalesList = new ArrayList<>();
|
|
|
|
|
|
|
+ //退货单
|
|
|
|
|
+ EasyExcel.read(file.getPath(), SalesReturn.class, new PageReadListener<SalesReturn>(dataList -> {
|
|
|
|
|
+ for (SalesReturn salesReturn : dataList) {
|
|
|
|
|
+ log.info("读取到一条数据{}", JSON.toJSONString(salesReturn));
|
|
|
|
|
+ Sales sales = new Sales();
|
|
|
|
|
+ sales.setZfze(salesReturn.getYtze());//应退金额
|
|
|
|
|
+ sales.setZfsj(salesReturn.getTksj());//退款时间
|
|
|
|
|
+ sales.setZffs(salesReturn.getZffs());//支付方式
|
|
|
|
|
+ salesList.add(sales);
|
|
|
|
|
+ }
|
|
|
|
|
+ })).sheet(1).doRead();
|
|
|
|
|
|
|
|
- for (Sales sales : sortedSalesList) {
|
|
|
|
|
- // 获取日期的YYMMDD部分
|
|
|
|
|
- LocalDate date = sales.getZfsj().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
- LocalDateTime localDateTime = sales.getZfsj().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
|
|
+ //支付时间升序
|
|
|
|
|
+ List<Sales> sortedSalesList = salesList.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(Sales::getZfsj))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
|
|
- String datePrefix = date.format(DateTimeFormatter.ofPattern("yyMMdd"));
|
|
|
|
|
|
|
+ AtomicInteger counter = new AtomicInteger(1);
|
|
|
|
|
+ String currentDatePrefix = "";
|
|
|
|
|
|
|
|
- // 如果日期变化,重置计数器
|
|
|
|
|
- if (!datePrefix.equals(currentDatePrefix)) {
|
|
|
|
|
- currentDatePrefix = datePrefix;
|
|
|
|
|
- counter.set(1);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<ConvertSales> convertSalesList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (Sales sales : sortedSalesList) {
|
|
|
|
|
+ // 获取日期的YYMMDD部分
|
|
|
|
|
+ LocalDate date = sales.getZfsj().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ LocalDateTime localDateTime = sales.getZfsj().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
+
|
|
|
|
|
+ String datePrefix = date.format(DateTimeFormatter.ofPattern("yyMMdd"));
|
|
|
|
|
+
|
|
|
|
|
+ // 如果日期变化,重置计数器
|
|
|
|
|
+ if (!datePrefix.equals(currentDatePrefix)) {
|
|
|
|
|
+ currentDatePrefix = datePrefix;
|
|
|
|
|
+ counter.set(1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 生成流水号:YYMMDD + 4位流水(不足补零)
|
|
|
|
|
- String serialNumber = String.format("%s%04d", datePrefix, counter.getAndIncrement());
|
|
|
|
|
|
|
+ // 生成流水号:YYMMDD + 4位流水(不足补零)
|
|
|
|
|
+ String serialNumber = String.format("%s%04d", datePrefix, counter.getAndIncrement());
|
|
|
|
|
|
|
|
- ConvertSales convertSales = new ConvertSales();
|
|
|
|
|
|
|
+ ConvertSales convertSales = new ConvertSales();
|
|
|
|
|
|
|
|
- convertSales.setRow1(CASH_REGISTER_Number);//收银机号
|
|
|
|
|
|
|
+ convertSales.setRow1(CASH_REGISTER_Number);//收银机号
|
|
|
|
|
|
|
|
- convertSales.setRow2(serialNumber);//交易流水号
|
|
|
|
|
|
|
+ convertSales.setRow2(serialNumber);//交易流水号
|
|
|
|
|
|
|
|
- convertSales.setRow3(localDateTime.format(DateTimeFormatter.ofPattern(DATE_PATTERN1)));//支付时间
|
|
|
|
|
|
|
+ convertSales.setRow3(localDateTime.format(DateTimeFormatter.ofPattern(DATE_PATTERN1)));//支付时间
|
|
|
|
|
|
|
|
- convertSales.setRow4(new DecimalFormat("0.00").format(sales.getZfze()));//整单实收金额
|
|
|
|
|
|
|
+ convertSales.setRow4(new DecimalFormat("0.00").format(sales.getZfze()));//整单实收金额
|
|
|
|
|
|
|
|
- convertSales.setRow5(GOODS_NUMBER);//货品编号
|
|
|
|
|
|
|
+ convertSales.setRow5(GOODS_NUMBER);//货品编号
|
|
|
|
|
|
|
|
- //交易方式
|
|
|
|
|
- if (Strings.isNotBlank(sales.getZffs())){
|
|
|
|
|
- switch (sales.getZffs()){
|
|
|
|
|
- case "现金支付" : convertSales.setRow6("01");break;
|
|
|
|
|
- case "其他" : convertSales.setRow6("06");break;
|
|
|
|
|
|
|
+ //交易方式
|
|
|
|
|
+ if (Strings.isNotBlank(sales.getZffs())){
|
|
|
|
|
+ switch (sales.getZffs()){
|
|
|
|
|
+ case "现金支付" : convertSales.setRow6("01");break;
|
|
|
|
|
+ case "其他" : convertSales.setRow6("06");break;
|
|
|
/*case "刷卡支付" : convertSales.setRow6("02");break;
|
|
/*case "刷卡支付" : convertSales.setRow6("02");break;
|
|
|
case "外挂POS机" : convertSales.setRow6("03");break;
|
|
case "外挂POS机" : convertSales.setRow6("03");break;
|
|
|
case "储值卡" : convertSales.setRow6("04");break;
|
|
case "储值卡" : convertSales.setRow6("04");break;
|
|
|
case "代金卷" : convertSales.setRow6("05");break;*/
|
|
case "代金卷" : convertSales.setRow6("05");break;*/
|
|
|
- default: convertSales.setRow6("03");break;//外挂pos机
|
|
|
|
|
|
|
+ default: convertSales.setRow6("03");break;//外挂pos机
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ convertSalesList.add(convertSales);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!convertSalesList.isEmpty()){
|
|
|
|
|
+ // 将对象列表写入文件
|
|
|
|
|
+ String newFileName = SHOP_NUMBER + "_" + file.getName().substring(0,12) + "00" + "_LIST.txt";
|
|
|
|
|
+ writeObjectsToFile(convertSalesList, saveFilePath + newFileName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //删除门店流水数据
|
|
|
|
|
+ boolean isDelete = file.delete();
|
|
|
|
|
+
|
|
|
|
|
+ if (isDelete) {
|
|
|
|
|
+ log.info("文件已删除");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ log.info("文件删除失败");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- convertSalesList.add(convertSales);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("指定的路径不存在或不是目录");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 将对象列表写入文件
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- String newFileName = SHOP_NUMBER + "_" + formattedTime + "_LIST.txt";
|
|
|
|
|
-// String newFileName = SHOP_NUMBER + "_" + "20250819235959" + "_LIST.txt";
|
|
|
|
|
- writeObjectsToFile(convertSalesList, "d:\\" + newFileName);
|
|
|
|
|
|
|
+ log.info("------------------转换文件结束---------------------");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|