抽数服务
This commit is contained in:
parent
d0c46176de
commit
e309502115
@ -63,37 +63,35 @@ public class TicketingSamplingJob {
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
if (totalRows <= PAGE_SIZE) {
|
||||
for (int i = 0; i < ticketingSamplingRespVO.getTotalRows(); i++) {
|
||||
Map<String, Object> currentMap = mapList.get(i);
|
||||
// 装配数据
|
||||
SaleDataSaveReqDTO saleData = new SaleDataSaveReqDTO();
|
||||
saleData.setDataId((String) currentMap.get("dataId"));
|
||||
saleData.setSdno((String) currentMap.get("sdno"));
|
||||
saleData.setTransactiontypeno((String) currentMap.get("transactiontypeno"));
|
||||
saleData.setSddate((String) currentMap.get("sddate"));
|
||||
saleData.setSdtime((String) currentMap.get("sdtime"));
|
||||
saleData.setAmount(new BigDecimal(currentMap.get("amount").toString()));
|
||||
saleData.setQuantity((Integer) currentMap.get("quantity"));
|
||||
saleData.setCertificatetype((String) currentMap.get("certificatetype"));
|
||||
saleData.setCertificateno((String) currentMap.get("certificateno"));
|
||||
saleData.setProductbatchno((String) currentMap.get("productbatchno"));
|
||||
saleData.setItem((String) currentMap.get("item"));
|
||||
saleData.setItemtypename((String) currentMap.get("itemtypename"));
|
||||
saleData.setItemtype((String) currentMap.get("itemtype"));
|
||||
saleData.setItemname((String) currentMap.get("itemname"));
|
||||
saleData.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename"));
|
||||
saleData.setTenant_id(1L);
|
||||
if (ticketSaleDataApi.createSaleData(saleData).getCode() != 0) {
|
||||
failedCount++;
|
||||
XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap);
|
||||
failedCount += insertSaleData(mapList, totalRows, pageNumber);
|
||||
} else {
|
||||
// 总条数大于每页条数 执行完第一次插入后根据返回的页数继续进行请求和插入
|
||||
// 插入第一页的数据
|
||||
failedCount += insertSaleData(mapList, PAGE_SIZE, pageNumber);
|
||||
pageNumber++;
|
||||
// 获得总页数
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingReqVO.setPageNumber(pageNumber);
|
||||
str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO));
|
||||
ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class);
|
||||
|
||||
if (!ticketingSamplingRespVO.isPassflag()) {
|
||||
XxlJobHelper.log("抽数服务:销售数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg());
|
||||
XxlJobHelper.handleFail("销售数据抽数失败,请重试");
|
||||
return;
|
||||
}
|
||||
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
if (pageNumber != totalPages) {
|
||||
failedCount += insertSaleData(mapList, PAGE_SIZE, pageNumber);
|
||||
} else {
|
||||
failedCount += insertSaleData(mapList, totalRows % PAGE_SIZE, pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO 由于小于大于都要执行第一次插入数据,只是长度不同,同时小于执行完直接return就行
|
||||
// 总条数大于每页条数 执行完第一次插入后根据返回的页数继续进行请求和插入
|
||||
for (int i = pageNumber; i <= totalRows; i++) {
|
||||
// 请求
|
||||
// 插入
|
||||
|
||||
}
|
||||
|
||||
XxlJobHelper.log("抽数服务:销售数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount);
|
||||
@ -101,32 +99,130 @@ public class TicketingSamplingJob {
|
||||
|
||||
@XxlJob("getCheckTicket")
|
||||
public void getCheckTicketHandler() throws Exception {
|
||||
XxlJobHelper.log("抽数服务:检票数据开始抽数");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("service", "apiCheckService");
|
||||
map.put("method", "CheckDetail");
|
||||
map.put("queryDate", "20240707");
|
||||
map.put("pageNumber", 1);
|
||||
map.put("pageSize", 2000);
|
||||
String str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(map));
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class);
|
||||
int successNum = 0;
|
||||
for (Map<String, Object> stringObjectMap : ticketingSamplingRespVO.getDataMapList()) {
|
||||
int failedCount = 0;
|
||||
int pageNumber = 1;
|
||||
XxlJobHelper.log("抽数服务:检票数据开始抽数...");
|
||||
// 准备请求参数
|
||||
TicketingSamplingReqVO ticketingSamplingReqVO = new TicketingSamplingReqVO();
|
||||
ticketingSamplingReqVO.setService("apiCheckService");
|
||||
ticketingSamplingReqVO.setMethod("CheckDetail");
|
||||
ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getNowDayFormat());
|
||||
ticketingSamplingReqVO.setPageNumber(pageNumber);
|
||||
ticketingSamplingReqVO.setPageSize(PAGE_SIZE);
|
||||
// 先发起第一次请求
|
||||
String str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO));
|
||||
|
||||
// 解析读取响应数据
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class);
|
||||
// 如果访问失败则让调度中心重新调用
|
||||
if (!ticketingSamplingRespVO.isPassflag()) {
|
||||
// 让调度中心重新调用
|
||||
XxlJobHelper.log("抽数服务:检票数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg());
|
||||
XxlJobHelper.handleFail("销售数据抽数失败,请重试");
|
||||
return;
|
||||
}
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
if (totalRows <= PAGE_SIZE) {
|
||||
failedCount += insertCheckTicket(mapList, totalRows, pageNumber);
|
||||
} else {
|
||||
// 总条数大于每页条数 执行完第一次插入后根据返回的页数继续进行请求和插入
|
||||
// 插入第一页的数据
|
||||
failedCount += insertCheckTicket(mapList, PAGE_SIZE, pageNumber);
|
||||
pageNumber++;
|
||||
// 获得总页数
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingReqVO.setPageNumber(pageNumber);
|
||||
str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO));
|
||||
ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class);
|
||||
|
||||
if (!ticketingSamplingRespVO.isPassflag()) {
|
||||
XxlJobHelper.log("抽数服务:销售数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg());
|
||||
XxlJobHelper.handleFail("销售数据抽数失败,请重试");
|
||||
return;
|
||||
}
|
||||
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
if (pageNumber != totalPages) {
|
||||
failedCount += insertCheckTicket(mapList, PAGE_SIZE, pageNumber);
|
||||
} else {
|
||||
failedCount += insertCheckTicket(mapList, totalRows % PAGE_SIZE, pageNumber);
|
||||
}
|
||||
}
|
||||
|
||||
CheckTicketSaveReqDTO checkTicket = new CheckTicketSaveReqDTO();
|
||||
checkTicket.setDataId((String) stringObjectMap.get("dataId"));
|
||||
checkTicket.setTicket((String) stringObjectMap.get("ticket"));
|
||||
checkTicket.setCheckticketdate((String) stringObjectMap.get("checkticketdate"));
|
||||
checkTicket.setChecktickettime((String) stringObjectMap.get("checktickettime"));
|
||||
checkTicket.setPersoncount((Integer) stringObjectMap.get("personcount"));
|
||||
checkTicket.setCheckstation((String) stringObjectMap.get("checkstation"));
|
||||
checkTicket.setCheckstationname((String) stringObjectMap.get("checkstationname"));
|
||||
checkTicket.setSdshipping((String) stringObjectMap.get("sdshipping"));
|
||||
checkTicket.setSalepropetyvaluename((String) stringObjectMap.get("salepropetyvaluename"));
|
||||
checkTicket.setTenant_id(1L);
|
||||
ticketCheckTicketApi.createCheckTicket(checkTicket);
|
||||
successNum++;
|
||||
}
|
||||
|
||||
XxlJobHelper.log("抽数服务:检票数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount);
|
||||
}
|
||||
/**
|
||||
* 插入销售数据的方法
|
||||
* @param mapList 数据集合数组
|
||||
* @param listSize 实际个数
|
||||
* @param pageNumber 每页显示条数
|
||||
* @return int 失败条数
|
||||
*/
|
||||
private int insertSaleData(List<Map<String, Object>> mapList, int listSize, int pageNumber) {
|
||||
int failedCount = 0;
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
Map<String, Object> currentMap = mapList.get(i);
|
||||
SaleDataSaveReqDTO saleData = new SaleDataSaveReqDTO();
|
||||
saleData.setDataId((String) currentMap.get("dataId"));
|
||||
saleData.setSdno((String) currentMap.get("sdno"));
|
||||
saleData.setTransactiontypeno((String) currentMap.get("transactiontypeno"));
|
||||
saleData.setSddate((String) currentMap.get("sddate"));
|
||||
saleData.setSdtime((String) currentMap.get("sdtime"));
|
||||
saleData.setAmount(new BigDecimal(currentMap.get("amount").toString()));
|
||||
saleData.setQuantity((Integer) currentMap.get("quantity"));
|
||||
saleData.setCertificatetype((String) currentMap.get("certificatetype"));
|
||||
saleData.setCertificateno((String) currentMap.get("certificateno"));
|
||||
saleData.setProductbatchno((String) currentMap.get("productbatchno"));
|
||||
saleData.setItem((String) currentMap.get("item"));
|
||||
saleData.setItemtypename((String) currentMap.get("itemtypename"));
|
||||
saleData.setItemtype((String) currentMap.get("itemtype"));
|
||||
saleData.setItemname((String) currentMap.get("itemname"));
|
||||
saleData.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename"));
|
||||
saleData.setTenant_id(1L);
|
||||
|
||||
if (ticketSaleDataApi.createSaleData(saleData).getCode() != 0) {
|
||||
failedCount++;
|
||||
XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap);
|
||||
}
|
||||
}
|
||||
return failedCount;
|
||||
}
|
||||
/**
|
||||
* 插入检票数据的方法
|
||||
* @param mapList 数据集合数组
|
||||
* @param listSize 实际个数
|
||||
* @param pageNumber 每页显示条数
|
||||
* @return int 失败条数
|
||||
*/
|
||||
private int insertCheckTicket(List<Map<String, Object>> mapList, int listSize, int pageNumber) {
|
||||
int failedCount = 0;
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
Map<String, Object> currentMap = mapList.get(i);
|
||||
CheckTicketSaveReqDTO checkTicket = new CheckTicketSaveReqDTO();
|
||||
checkTicket.setDataId((String) currentMap.get("dataId"));
|
||||
checkTicket.setTicket((String) currentMap.get("ticket"));
|
||||
checkTicket.setCheckticketdate((String) currentMap.get("checkticketdate"));
|
||||
checkTicket.setChecktickettime((String) currentMap.get("checktickettime"));
|
||||
checkTicket.setPersoncount((Integer) currentMap.get("personcount"));
|
||||
checkTicket.setCheckstation((String) currentMap.get("checkstation"));
|
||||
checkTicket.setCheckstationname((String) currentMap.get("checkstationname"));
|
||||
checkTicket.setSdshipping((String) currentMap.get("sdshipping"));
|
||||
checkTicket.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename"));
|
||||
checkTicket.setTenant_id(1L);
|
||||
ticketCheckTicketApi.createCheckTicket(checkTicket);
|
||||
|
||||
if (ticketCheckTicketApi.createCheckTicket(checkTicket).getCode() != 0) {
|
||||
failedCount++;
|
||||
XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap);
|
||||
}
|
||||
}
|
||||
return failedCount;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ public class TicketingSamplingRespVO {
|
||||
private Integer pageNumber;
|
||||
@Schema(description = "分页,每页多少条,每页最多2000条")
|
||||
private Integer pageSize;
|
||||
@Schema(description = "总页数")
|
||||
private Integer totalPages;
|
||||
@Schema(description = "总条数")
|
||||
private Integer totalRows;
|
||||
@Schema(description = "数据数组")
|
||||
|
Loading…
Reference in New Issue
Block a user