|
|
|
@@ -75,13 +75,11 @@ import com.bms.ar.mapper.ArBankAccountMapper;
|
|
|
|
|
import com.bms.ar.mapper.ArExportTemplateMapper;
|
|
|
|
|
import com.bms.ar.service.IArBillLogService;
|
|
|
|
|
import com.bms.ar.service.IArBillService;
|
|
|
|
|
import com.bms.ar.service.ArBillDataScopeService;
|
|
|
|
|
import com.bms.ar.domain.vo.ArBillActionRequest;
|
|
|
|
|
import com.bms.ar.domain.vo.ArBillGenerateQuery;
|
|
|
|
|
import com.bms.ar.domain.vo.ArBillGenerateRequest;
|
|
|
|
|
import com.bms.ar.domain.vo.ArBillQuery;
|
|
|
|
|
import com.bms.common.config.BmsConfig;
|
|
|
|
|
import com.bms.common.annotation.DataScope;
|
|
|
|
|
import com.bms.common.exception.ServiceException;
|
|
|
|
|
import com.bms.common.utils.DateUtils;
|
|
|
|
|
import com.bms.common.utils.SecurityUtils;
|
|
|
|
@@ -199,8 +197,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IArBillLogService logService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ArBillDataScopeService dataScopeService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ApplicationEventPublisher eventPublisher;
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrcOrderBillMapper sourceBillMapper;
|
|
|
|
@@ -215,7 +211,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
* 查询账单列表,并对返回给前端的收款账号做脱敏。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@DataScope(deptAlias = "ar_scope_user", userAlias = "ar_scope_user", permission = "ar:bill:list")
|
|
|
|
|
public List<ArBill> selectArBillList(ArBillQuery query) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
List<ArBill> bills = billMapper.selectArBillList(query);
|
|
|
|
@@ -234,7 +229,10 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public ArBill selectArBillById(Long arBillId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
ArBill bill = requireBillDataScope(arBillId);
|
|
|
|
|
ArBill bill = billMapper.selectArBillById(arBillId);
|
|
|
|
|
if (bill == null) {
|
|
|
|
|
throw new ServiceException("应收账单不存在");
|
|
|
|
|
}
|
|
|
|
|
bill.setBankAccountNo(maskAccount(bill.getBankAccountNo()));
|
|
|
|
|
bill.setExports(exportMapper.selectByBillId(arBillId));
|
|
|
|
|
log.debug("应收账单详情查询完成,arBillId={}, status={}, exportCount={}, costMs={}",
|
|
|
|
@@ -249,7 +247,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<ArBillDetail> selectArBillDetails(Long arBillId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
requireBillDataScope(arBillId);
|
|
|
|
|
List<ArBillDetail> details = detailMapper.selectByBillId(arBillId);
|
|
|
|
|
log.debug("应收账单明细查询完成,arBillId={}, resultCount={}, costMs={}",
|
|
|
|
|
arBillId, details.size(), elapsedMillis(startedAt));
|
|
|
|
@@ -262,7 +259,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<ArBillDetailFee> selectArBillDetailFees(Long arBillId, Long detailId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
requireBillDataScope(arBillId);
|
|
|
|
|
List<ArBillDetailFee> fees = detailFeeMapper.selectByBillIdAndDetailId(arBillId, detailId);
|
|
|
|
|
log.debug("应收账单费用明细查询完成,arBillId={}, detailId={}, resultCount={}, costMs={}",
|
|
|
|
|
arBillId, detailId, fees.size(), elapsedMillis(startedAt));
|
|
|
|
@@ -303,7 +299,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
public List<PrcOrderBill> previewBill(ArBillGenerateQuery query) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
validatePreviewQuery(query);
|
|
|
|
|
requireCustomerDataScope(query.getCustomerId());
|
|
|
|
|
List<String> orderIdentifiers = normalizeOrderIdentifiers(query.getOrderOrTrackingNo());
|
|
|
|
|
List<String> excludeOrderIdentifiers = normalizeOrderIdentifiers(query.getExcludeOrderOrTrackingNo());
|
|
|
|
|
List<PrcOrderBill> result = sourceBillMapper.selectPrcOrderBillByCustomerPeriod(query.getCustomerId(),
|
|
|
|
@@ -332,7 +327,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
public BigDecimal sumPreviewBill(ArBillGenerateQuery query) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
validatePreviewQuery(query);
|
|
|
|
|
requireCustomerDataScope(query.getCustomerId());
|
|
|
|
|
List<String> orderIdentifiers = normalizeOrderIdentifiers(query.getOrderOrTrackingNo());
|
|
|
|
|
List<String> excludeOrderIdentifiers = normalizeOrderIdentifiers(query.getExcludeOrderOrTrackingNo());
|
|
|
|
|
BigDecimal total = nvl(sourceBillMapper.sumPrcOrderBillIncomeByCustomerPeriod(query.getCustomerId(),
|
|
|
|
@@ -356,13 +350,8 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
Long createUserId = SecurityUtils.getUserId();
|
|
|
|
|
validatePeriod(request);
|
|
|
|
|
requireCustomerDataScope(request.getCustomerId());
|
|
|
|
|
ArBillGenerateTask existed = generateTaskMapper.selectByRequestToken(requestId);
|
|
|
|
|
if (existed != null) {
|
|
|
|
|
ArBill existedBill = requireBillDataScope(existed.getArBillId());
|
|
|
|
|
if (!request.getCustomerId().equals(existedBill.getCustomerId())) {
|
|
|
|
|
throw new ServiceException("请求标识已用于其他客户,请重新发起");
|
|
|
|
|
}
|
|
|
|
|
log.info("应收账单生成请求命中幂等记录,operator={}, requestId={}, taskId={}, status={}, costMs={}",
|
|
|
|
|
safeLogValue(operator), safeLogValue(requestId), existed.getTaskId(), existed.getStatus(),
|
|
|
|
|
elapsedMillis(startedAt));
|
|
|
|
@@ -482,7 +471,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
if (task == null) {
|
|
|
|
|
throw new ServiceException("账单生成任务不存在");
|
|
|
|
|
}
|
|
|
|
|
requireBillDataScope(task.getArBillId());
|
|
|
|
|
log.debug("应收账单生成任务状态查询,taskId={}, status={}, processedCount={}, totalCount={}, costMs={}",
|
|
|
|
|
taskId, task.getStatus(), task.getProcessedCount(), task.getTotalCount(), elapsedMillis(startedAt));
|
|
|
|
|
return task;
|
|
|
|
@@ -494,7 +482,7 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<ArBillGenerateTask> selectActiveGenerateTasks(String operator) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
List<ArBillGenerateTask> tasks = dataScopeService.selectActiveGenerateTasks(new ArBillQuery(), operator);
|
|
|
|
|
List<ArBillGenerateTask> tasks = generateTaskMapper.selectActiveByCreateBy(operator);
|
|
|
|
|
log.debug("当前用户应收账单生成任务查询,operator={}, taskCount={}, costMs={}",
|
|
|
|
|
safeLogValue(operator), tasks.size(), elapsedMillis(startedAt));
|
|
|
|
|
return tasks;
|
|
|
|
@@ -925,7 +913,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ArBill confirmBill(Long arBillId, ArBillActionRequest request, String operator, String requestId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
requireBillDataScope(arBillId);
|
|
|
|
|
ArBill bill = billMapper.selectArBillByIdForUpdate(arBillId);
|
|
|
|
|
if (bill == null) {
|
|
|
|
|
throw failure(arBillId, ArLogObjectType.BILL, String.valueOf(arBillId), ArLogOperationType.CONFIRM,
|
|
|
|
@@ -970,7 +957,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ArBill voidBill(Long arBillId, ArBillActionRequest request, String operator, String requestId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
requireBillDataScope(arBillId);
|
|
|
|
|
String remark = request == null ? null : request.getRemark();
|
|
|
|
|
if (StringUtils.isEmpty(remark)) {
|
|
|
|
|
throw failure(arBillId, ArLogObjectType.BILL, String.valueOf(arBillId), ArLogOperationType.VOID,
|
|
|
|
@@ -1015,22 +1001,23 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ArBillExport exportBill(Long arBillId, String operator, String requestId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
ArBill bill = requireBillDataScope(arBillId);
|
|
|
|
|
Long exportUserId = SecurityUtils.getUserId();
|
|
|
|
|
ArBillLog previous = logMapper.selectSuccessByRequestId(requestId, ArLogObjectType.EXPORT.getCode(),
|
|
|
|
|
ArLogResult.SUCCESS.getCode());
|
|
|
|
|
if (previous != null && isNumber(previous.getObjectId())) {
|
|
|
|
|
ArBillExport previousExport = exportMapper.selectById(Long.valueOf(previous.getObjectId()));
|
|
|
|
|
if (previousExport != null) {
|
|
|
|
|
if (!arBillId.equals(previousExport.getArBillId())) {
|
|
|
|
|
throw new ServiceException("请求标识已用于其他账单,请重新发起");
|
|
|
|
|
}
|
|
|
|
|
log.info("应收账单导出请求命中幂等记录,operator={}, requestId={}, arBillId={}, exportId={}, status={}, costMs={}",
|
|
|
|
|
safeLogValue(operator), safeLogValue(requestId), arBillId, previousExport.getExportId(),
|
|
|
|
|
previousExport.getExportStatus(), elapsedMillis(startedAt));
|
|
|
|
|
return previousExport;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ArBill bill = billMapper.selectArBillById(arBillId);
|
|
|
|
|
if (bill == null) {
|
|
|
|
|
throw failure(arBillId, ArLogObjectType.EXPORT, String.valueOf(arBillId), ArLogOperationType.EXPORT,
|
|
|
|
|
null, "应收账单不存在", operator, requestId);
|
|
|
|
|
}
|
|
|
|
|
if (!ArBillGenerationStatus.READY.equals(bill.getGenerationStatus())) {
|
|
|
|
|
throw failure(arBillId, ArLogObjectType.EXPORT, String.valueOf(arBillId), ArLogOperationType.EXPORT,
|
|
|
|
|
bill.getStatus(), "账单尚未生成完成,暂不能导出", operator, requestId);
|
|
|
|
@@ -1091,7 +1078,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
if (export == null) {
|
|
|
|
|
throw new ServiceException("导出任务不存在");
|
|
|
|
|
}
|
|
|
|
|
requireBillDataScope(export.getArBillId());
|
|
|
|
|
log.debug("应收账单导出任务状态查询,exportId={}, status={}, costMs={}",
|
|
|
|
|
exportId, export.getExportStatus(), elapsedMillis(startedAt));
|
|
|
|
|
return export;
|
|
|
|
@@ -1172,7 +1158,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<ArBillExport> selectExports(Long arBillId) {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
requireBillDataScope(arBillId);
|
|
|
|
|
List<ArBillExport> exports = exportMapper.selectByBillId(arBillId);
|
|
|
|
|
log.debug("应收账单导出记录查询,arBillId={}, exportCount={}, costMs={}",
|
|
|
|
|
arBillId, exports.size(), elapsedMillis(startedAt));
|
|
|
|
@@ -1182,8 +1167,8 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
@Override
|
|
|
|
|
public void downloadExport(Long exportId, HttpServletResponse response) throws Exception {
|
|
|
|
|
long startedAt = System.nanoTime();
|
|
|
|
|
ArBillExport export = selectExport(exportId);
|
|
|
|
|
if (!ArExportStatus.SUCCESS.getCode().equals(export.getExportStatus()) || StringUtils.isEmpty(export.getStorageKey())) {
|
|
|
|
|
ArBillExport export = exportMapper.selectById(exportId);
|
|
|
|
|
if (export == null || !ArExportStatus.SUCCESS.getCode().equals(export.getExportStatus()) || StringUtils.isEmpty(export.getStorageKey())) {
|
|
|
|
|
throw new ServiceException("导出文件不存在或尚未生成成功");
|
|
|
|
|
}
|
|
|
|
|
String resource = export.getStorageKey();
|
|
|
|
@@ -1212,18 +1197,6 @@ public class ArBillServiceImpl implements IArBillService {
|
|
|
|
|
return logs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ArBill requireBillDataScope(Long arBillId) {
|
|
|
|
|
ArBillQuery query = new ArBillQuery();
|
|
|
|
|
query.setArBillId(arBillId);
|
|
|
|
|
return dataScopeService.requireBill(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void requireCustomerDataScope(Long customerId) {
|
|
|
|
|
ArBillQuery query = new ArBillQuery();
|
|
|
|
|
query.setCustomerId(customerId);
|
|
|
|
|
dataScopeService.requireCustomer(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String exportFailureMessage(Exception e) {
|
|
|
|
|
String message = StringUtils.isEmpty(e.getMessage()) ? "账单导出失败" : e.getMessage();
|
|
|
|
|
return message.length() > 500 ? message.substring(0, 500) : message;
|
|
|
|
|