Browse Source

1.test程序补推送到车入库数据demo

training
zhenghaoyu 1 year ago
parent
commit
91a6b7193c
  1. 147
      blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java
  2. 36
      blade-service/logpm-factory/src/test/java/com/logpm/factory/excel/ExcelMode14.java
  3. 79
      blade-service/logpm-factory/src/test/java/com/logpm/factory/listener/ExcelListener.java

147
blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java

@ -1,56 +1,33 @@
package com.logpm.factory;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.logpm.factory.comfac.controller.FactoryCommonController;
import com.logpm.factory.comfac.dto.UnloadCarDTO;
import com.logpm.factory.excel.ExcelMode;
import com.logpm.factory.excel.ExcelMode14;
import com.logpm.factory.excel.JpDataMode;
import com.logpm.factory.mt.entity.MtFactoryOrderMain;
import com.logpm.factory.mt.entity.MtOrderLogEntity;
import com.logpm.factory.mt.entity.MtPushData;
import com.logpm.factory.mt.service.IMtFactoryDataService;
import com.logpm.factory.mt.service.IMtFactoryOrderMainService;
import com.logpm.factory.mt.service.IMtPushDataService;
import com.logpm.factory.mt.service.impl.MtFactoryDataServiceImpl;
import com.logpm.factory.listener.ExcelListener;
import com.logpm.factory.oupai.entity.FactoryPackageEntity;
import com.logpm.factory.oupai.entity.OpOrderStatusLogEntity;
import com.logpm.factory.oupai.service.IFactoryPackageService;
import com.logpm.factory.oupai.service.IOuPaiFactoryService;
import com.logpm.factory.oupai.service.impl.OuPaiFactoryServiceImpl;
import com.logpm.factory.pan.service.IPanFactoryDataService;
import com.logpm.factory.props.ZbFactoryProperties;
import com.logpm.factory.snm.bean.Resp;
import com.logpm.factory.snm.vo.MTOrderPackageRelationVO;
import com.logpm.factory.zb.dto.ZBReceiptDTO;
import com.logpm.factory.zb.entity.ZbCategoryContrastEntity;
import com.logpm.factory.zb.entity.ZbFactoryLogEntity;
import com.logpm.factory.zb.entity.ZbOrderLogEntity;
import com.logpm.factory.zb.mapper.ZbCategoryContrastMapper;
import com.logpm.factory.zb.service.IZbFactoryDataService;
import com.logpm.factory.zb.service.IZbFactoryLogService;
import com.logpm.factory.zb.untils.QmSignUntil;
import com.logpm.oldproject.entity.AdvanceDetailEntity;
import com.logpm.oldproject.feign.IAdvanceDetailClient;
import com.rabbitmq.client.Channel;
import lombok.Data;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
@ -63,14 +40,10 @@ import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.test.BladeBootTest;
import org.springblade.core.test.BladeSpringExtension;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.api.ResultCode;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.resource.feign.IOssClient;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.http.MediaType;
@ -80,12 +53,9 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static com.logpm.factory.zb.untils.QmSignUntil.areNotEmpty;
@ -594,5 +564,114 @@ public class TestService {
}
@Test
public void test14() throws Exception {
// File file = new File("D://12345215.json");
//
// BufferedReader reader = new BufferedReader(new FileReader(file));
//
// StringBuffer sb = new StringBuffer();
//
// while (true) {
// String ms = reader.readLine();
// if (StringUtil.isBlank(ms)) {
// break;
// }
// sb.append(ms);
// }
// ExcelReader reader = EasyExcel.read("D://查询欧派补充推送数据2.xlsx", MyModel.class, new MyListener())
// .build();
FileInputStream fis;
try {
// fis = new FileInputStream("D://查询欧派补充推送数据2.xlsx");
fis = new FileInputStream("D://查询欧派补充推送数据2.xlsx");
readExcel(fis, ExcelMode14.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(11111);
// JSONObject object = JSONObject.parseObject(sb.toString());
//
// JSONArray records = object.getJSONArray("RECORDS");
//
// for (int i = 0; i < records.size(); i++) {
// JSONObject jsonObject = records.getJSONObject(i);
// Map<String,Object> reqMap = new HashMap<>();
// reqMap.put("authCode", jsonObject.getString("authCode"));
//
// // 收货单
// reqMap.put("op_shipNo", jsonObject.getString("op_shipNo"));
// //仓库ID
// reqMap.put("warehouse_id", jsonObject.getInteger("warehouse_id"));
// //订单自编号
// reqMap.put("orderSelfNum", jsonObject.getString("orderSelfNum"));
// //扫描时间
// reqMap.put("scan_time", jsonObject.getString("scan_time"));
// //扫描人
// reqMap.put("scan_user", "");
// //车次号
// reqMap.put("mctsTruck", jsonObject.getString("mctsTruck"));
// //发货基地
// reqMap.put("siteName", jsonObject.getString("siteName"));
// //一级品类
// reqMap.put("firstPackName", jsonObject.getString("firstPackName"));
// //二级品类
// reqMap.put("secondPackName", jsonObject.getString("secondPackName"));
// //三级品类
// reqMap.put("thirdPackName", jsonObject.getString("thirdPackName"));
// //物料名称
// reqMap.put("productname", jsonObject.getString("productname"));
// //包条码
// reqMap.put("unitNo", jsonObject.getString("CODE"));
//
// // 构建请求头
// String authCode = reqMap.get("authCode").toString();
//
// String url = "http://twms.huitongys.com/openApi/newSystem.OptimsWarehouseScan/index";
// String body = HttpRequest.post(url).form(reqMap).header("token", authCode).execute().body();
// if (jodd.util.StringUtil.isNotBlank(body)) {
//
// JSONObject res = JSON.parseObject(body);
// if ("200".equals(res.getString("code"))) {
// System.out.println("");
// }
//
// }
// }
}
public static Boolean readExcel(InputStream is, Class clazz){
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(is);
// 解析每行结果在listener中处理(所以我们接收逻辑需要在监听器里面处理)
AnalysisEventListener listener = new ExcelListener();
ExcelReader excelReader = EasyExcelFactory.getReader(bis, listener);
excelReader.read(new Sheet(1, 1, clazz));
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
}

36
blade-service/logpm-factory/src/test/java/com/logpm/factory/excel/ExcelMode14.java

@ -0,0 +1,36 @@
package com.logpm.factory.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class ExcelMode14 {
@ExcelProperty(index = 0)
private String authCode;
@ExcelProperty(index = 1)
private String op_shipNo;
@ExcelProperty(index = 2)
private Integer warehouse_id;
@ExcelProperty(index = 3)
private String orderSelfNum;
@ExcelProperty(index = 4)
private String scan_time;
@ExcelProperty(index = 5)
private String scan_user;
@ExcelProperty(index = 6)
private String mctsTruck;
@ExcelProperty(index = 7)
private String siteName;
@ExcelProperty(index = 8)
private String firstPackName;
@ExcelProperty(index = 9)
private String secondPackName;
@ExcelProperty(index = 10)
private String thirdPackName;
@ExcelProperty(index = 11)
private String productname;
@ExcelProperty(index = 12)
private String CODE;
}

79
blade-service/logpm-factory/src/test/java/com/logpm/factory/listener/ExcelListener.java

@ -0,0 +1,79 @@
package com.logpm.factory.listener;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ExcelListener extends AnalysisEventListener {
//自定义用于暂时存储data。
//定义成静态变量,不过要注意的是我们try-catch导入逻辑的时候记得要在finally手动调用clear()方法,因为我们可能在解析excel的时候抛异常了,这个时候doAfterAllAnalysed()方法是不会执行的,如果没有清空静态变量的数据就会有脏数据(也就是上次解析成功的数据还在)
public static List<Object> datas = new ArrayList<>();
@Override
public void invoke(Object object, AnalysisContext context) {
System.out.println("导入数据:"+ JSONUtil.toJsonStr(object));
// 这边可以进行其他操作,如直接存入数据库
String s = JSONUtil.toJsonStr(object);
JSONObject jsonObject = JSONObject.parseObject(s);
Map<String,Object> reqMap = new HashMap<>();
reqMap.put("authCode", jsonObject.getString("authCode"));
// 收货单
reqMap.put("op_shipNo", jsonObject.getString("op_shipNo"));
//仓库ID
reqMap.put("warehouse_id", jsonObject.getInteger("warehouse_id"));
//订单自编号
reqMap.put("orderSelfNum", jsonObject.getString("orderSelfNum"));
//扫描时间
reqMap.put("scan_time", jsonObject.getString("scan_time"));
//扫描人
reqMap.put("scan_user", "");
//车次号
reqMap.put("mctsTruck", jsonObject.getString("mctsTruck"));
//发货基地
reqMap.put("siteName", jsonObject.getString("siteName"));
//一级品类
reqMap.put("firstPackName", jsonObject.getString("firstPackName"));
//二级品类
reqMap.put("secondPackName", jsonObject.getString("secondPackName"));
//三级品类
reqMap.put("thirdPackName", jsonObject.getString("thirdPackName"));
//物料名称
reqMap.put("productname", jsonObject.getString("productname"));
//包条码
reqMap.put("unitNo", jsonObject.getString("CODE"));
// 构建请求头
String authCode = reqMap.get("authCode").toString();
String url = "http://twms.huitongys.com/openApi/newSystem.OptimsWarehouseScan/index";
String body = HttpRequest.post(url).form(reqMap).header("token", authCode).execute().body();
if (jodd.util.StringUtil.isNotBlank(body)) {
JSONObject res = JSON.parseObject(body);
if ("200".equals(res.getString("code"))) {
System.out.println("处理成功:"+jsonObject.getString("CODE"));
}
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
datas.clear();//解析结束销毁不用的资源
}
public static void clear(){
datas.clear();
}
}
Loading…
Cancel
Save