修改同步计费
This commit is contained in:
+166
-1
@@ -1,24 +1,44 @@
|
||||
package com.bms.web.controller.monitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.bms.common.annotation.Log;
|
||||
import com.bms.common.constant.HttpStatus;
|
||||
import com.bms.common.core.controller.BaseController;
|
||||
import com.bms.common.core.domain.AjaxResult;
|
||||
import com.bms.common.core.page.PageDomain;
|
||||
import com.bms.common.core.page.TableDataInfo;
|
||||
import com.bms.common.core.page.TableSupport;
|
||||
import com.bms.common.enums.BusinessType;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.price.domain.PrcBillingTask;
|
||||
import com.bms.price.domain.PrcBillingTaskRetryTask;
|
||||
import com.bms.price.domain.vo.TabOrderMonitorQuery;
|
||||
import com.bms.price.domain.vo.TabOrderMonitorVo;
|
||||
import com.bms.price.enums.BillTaskSuccessStatus;
|
||||
import com.bms.price.oracle.TabOrderMonitorService;
|
||||
import com.bms.price.search.BillSearchPage;
|
||||
import com.bms.price.search.EsLogType;
|
||||
import com.bms.price.search.IBillSearchStore;
|
||||
import com.bms.price.search.TabOrderSyncEsLog;
|
||||
import com.bms.price.service.IPrcBillingTaskService;
|
||||
import com.bms.price.task.TabOrderSyncAsyncRunner;
|
||||
|
||||
/**
|
||||
* 订单数据源:查询上游 Oracle TAB_ORDER。
|
||||
* 订单数据源:查询上游 Oracle TAB_ORDER,并分批同步计费。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/monitor/orderSource")
|
||||
@@ -27,6 +47,15 @@ public class TabOrderMonitorController extends BaseController
|
||||
@Autowired
|
||||
private TabOrderMonitorService tabOrderMonitorService;
|
||||
|
||||
@Autowired
|
||||
private IPrcBillingTaskService billingTaskService;
|
||||
|
||||
@Autowired
|
||||
private TabOrderSyncAsyncRunner tabOrderSyncAsyncRunner;
|
||||
|
||||
@Autowired
|
||||
private IBillSearchStore billSearchStore;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(TabOrderMonitorQuery query)
|
||||
@@ -52,6 +81,142 @@ public class TabOrderMonitorController extends BaseController
|
||||
return rsp;
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:sync')")
|
||||
@Log(title = "order source sync filter", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/syncByFilter")
|
||||
public AjaxResult syncByFilter(@RequestBody TabOrderMonitorQuery query)
|
||||
{
|
||||
if (!hasRequiredFilters(query))
|
||||
{
|
||||
return error("customerCodes and pickup time required");
|
||||
}
|
||||
tabOrderMonitorService.count(query);
|
||||
String asyncTaskId = UUID.randomUUID().toString().replace("-", "");
|
||||
tabOrderSyncAsyncRunner.put(asyncTaskId, PrcBillingTaskRetryTask.STATUS_PENDING, 0, "queued",
|
||||
0, 0, 0, 0, null);
|
||||
tabOrderSyncAsyncRunner.run(asyncTaskId, query, TabOrderSyncAsyncRunner.clampBatch(query.getBatchSize()));
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("asyncTaskId", asyncTaskId);
|
||||
TabOrderSyncEsLog.save(billSearchStore, asyncTaskId, "FILTER", query, data, "SUCCESS", null);
|
||||
return success(data);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:sync') or @ss.hasPermi('monitor:orderSource:list')")
|
||||
@GetMapping("/syncTask/{asyncTaskId}")
|
||||
public AjaxResult syncTaskProgress(@PathVariable("asyncTaskId") String asyncTaskId)
|
||||
{
|
||||
PrcBillingTaskRetryTask task = tabOrderSyncAsyncRunner.get(asyncTaskId);
|
||||
if (task == null)
|
||||
{
|
||||
return error("sync task not found or expired");
|
||||
}
|
||||
return success(task);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:sync')")
|
||||
@Log(title = "order source sync selected", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/sync")
|
||||
public AjaxResult syncSelected(@RequestBody List<TabOrderMonitorVo> rows)
|
||||
{
|
||||
if (rows == null || rows.isEmpty())
|
||||
{
|
||||
return error("rows required");
|
||||
}
|
||||
if (rows.size() > 200)
|
||||
{
|
||||
return error("selected rows exceed 200");
|
||||
}
|
||||
int ok = 0;
|
||||
int fail = 0;
|
||||
List<Map<String, Object>> details = new ArrayList<Map<String, Object>>();
|
||||
for (TabOrderMonitorVo row : rows)
|
||||
{
|
||||
Map<String, Object> item = new HashMap<String, Object>();
|
||||
item.put("orderId", row == null ? null : row.getOrderId());
|
||||
item.put("transferOrderId", row == null ? null : row.getTransferOrderId());
|
||||
try
|
||||
{
|
||||
PrcBillingTask task = billingTaskService.submitAndProcess(TabOrderSyncAsyncRunner.toSubmit(row));
|
||||
item.put("successStatus", task == null ? null : task.getSuccessStatus());
|
||||
item.put("errorMessage", task == null ? null : task.getErrorMessage());
|
||||
if (task != null && BillTaskSuccessStatus.SUCCESS.getCode().equals(task.getSuccessStatus()))
|
||||
{
|
||||
ok++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
fail++;
|
||||
item.put("successStatus", "ERROR");
|
||||
item.put("errorMessage", e.getMessage());
|
||||
}
|
||||
details.add(item);
|
||||
}
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("ok", Integer.valueOf(ok));
|
||||
data.put("fail", Integer.valueOf(fail));
|
||||
data.put("details", details);
|
||||
String action = rows.size() == 1 ? "ONE" : "SELECTED";
|
||||
String bizId = firstOrderBizId(rows, action);
|
||||
String status = fail > 0 && ok == 0 ? "FAIL" : "SUCCESS";
|
||||
String err = fail > 0 ? ("fail=" + fail) : null;
|
||||
TabOrderSyncEsLog.save(billSearchStore, bizId, action, rows, data, status, err);
|
||||
return success(data);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:list')")
|
||||
@GetMapping("/syncLog/list")
|
||||
public TableDataInfo syncLogList(
|
||||
@RequestParam(value = "bizId", required = false) String bizId,
|
||||
@RequestParam(value = "status", required = false) String status)
|
||||
{
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
int pageNum = pageDomain.getPageNum() == null ? 1 : pageDomain.getPageNum().intValue();
|
||||
int pageSize = pageDomain.getPageSize() == null ? 10 : pageDomain.getPageSize().intValue();
|
||||
BillSearchPage page = billSearchStore.search(EsLogType.ORDER_SOURCE_SYNC, bizId, status, pageNum, pageSize);
|
||||
TableDataInfo rsp = new TableDataInfo();
|
||||
rsp.setCode(HttpStatus.SUCCESS);
|
||||
rsp.setMsg("\u67e5\u8be2\u6210\u529f");
|
||||
rsp.setRows(page.getRows());
|
||||
rsp.setTotal(page.getTotal());
|
||||
return rsp;
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('monitor:orderSource:list')")
|
||||
@GetMapping("/syncLog/{docId}")
|
||||
public AjaxResult syncLogInfo(@PathVariable("docId") String docId)
|
||||
{
|
||||
return success(billSearchStore.getByDocId(docId));
|
||||
}
|
||||
|
||||
private static String firstOrderBizId(List<TabOrderMonitorVo> rows, String action)
|
||||
{
|
||||
String prefix = action == null ? "SYNC" : action;
|
||||
if (rows != null)
|
||||
{
|
||||
for (TabOrderMonitorVo row : rows)
|
||||
{
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(row.getOrderId()))
|
||||
{
|
||||
return prefix + "_" + row.getOrderId();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(row.getTransferOrderId()))
|
||||
{
|
||||
return prefix + "_" + row.getTransferOrderId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return prefix + "_" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private static boolean hasRequiredFilters(TabOrderMonitorQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
|
||||
Reference in New Issue
Block a user