feat: 对账管理
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.annotation.SLog;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationOrderPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationRecordPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.service.PointsMallReconciliationService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@At("/platform/zhgh/points-mall/reconciliation")
|
||||
public class PointsMallReconciliationController {
|
||||
|
||||
@Inject
|
||||
private PointsMallReconciliationService pointsMallReconciliationService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/points-mall/reconciliation/index.html")
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public Result pageData(PointsMallReconciliationOrderPageParam param) {
|
||||
return Result.success(pointsMallReconciliationService.orderPage(param));
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public Result supplierList() {
|
||||
return Result.success(pointsMallReconciliationService.listSuppliers());
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public Result pointsTotal(PointsMallReconciliationParam param) {
|
||||
try {
|
||||
return Result.success(pointsMallReconciliationService.pointsTotal(param));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@SLog(tag = "积分商城对账管理", msg = "执行订单对账")
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public Result execute(PointsMallReconciliationParam param) {
|
||||
try {
|
||||
return Result.success(pointsMallReconciliationService.execute(param));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("points.mall.reconciliation")
|
||||
public Result recordPage(PointsMallReconciliationRecordPageParam param) {
|
||||
return Result.success(pointsMallReconciliationService.recordPage(param));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("points_mall_reconciliation_order")
|
||||
@Comment("积分商城供应商对账订单")
|
||||
public class PointsMallReconciliationOrder extends BaseModel implements Serializable {
|
||||
|
||||
@Name
|
||||
@Column
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("供应商编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String supplierId;
|
||||
|
||||
@Column
|
||||
@Comment("订单ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String orderId;
|
||||
|
||||
@Column
|
||||
@Comment("用户ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@Comment("总价含税")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@Column
|
||||
@Comment("总价不含税")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal invoiceNakedPrice;
|
||||
|
||||
@Column
|
||||
@Comment("商品信息")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String productInfo;
|
||||
|
||||
@Column
|
||||
@Comment("查询范围")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 200)
|
||||
private String queryScope;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("points_mall_reconciliation_record")
|
||||
@Comment("积分商城对账记录")
|
||||
public class PointsMallReconciliationRecord extends BaseModel implements Serializable {
|
||||
|
||||
@Name
|
||||
@Column
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("供应商编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String supplierId;
|
||||
|
||||
@Column
|
||||
@Comment("订单ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String orderId;
|
||||
|
||||
@Column
|
||||
@Comment("用户ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@Comment("平台退款")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal pRefund;
|
||||
|
||||
@Column
|
||||
@Comment("平台订单总金额")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal pTotalPrice;
|
||||
|
||||
@Column
|
||||
@Comment("平台现金金额")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal pCashAmount;
|
||||
|
||||
@Column
|
||||
@Comment("平台消费积分")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal pPointsPrice;
|
||||
|
||||
@Column
|
||||
@Comment("供应商退款")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal sRefund;
|
||||
|
||||
@Column
|
||||
@Comment("供应商订单总金额")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal sTotalPrice;
|
||||
|
||||
@Column
|
||||
@Comment("供应商现金金额")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal sCashAmount;
|
||||
|
||||
@Column
|
||||
@Comment("供应商消费积分")
|
||||
@ColDefine(type = ColType.FLOAT, width = 18, precision = 2)
|
||||
private BigDecimal sPointsPrice;
|
||||
|
||||
@Column
|
||||
@Comment("差异原因")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 1000)
|
||||
private String diffReason;
|
||||
|
||||
@Column
|
||||
@Comment("差异类型")
|
||||
private Integer diffType;
|
||||
|
||||
@Column
|
||||
@Comment("对账批次号")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String batchNo;
|
||||
|
||||
@Column
|
||||
@Comment("通知状态")
|
||||
private Integer noticeStatus;
|
||||
|
||||
@Column
|
||||
@Comment("推送次数")
|
||||
private Integer pushTime;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.param;
|
||||
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PointsMallReconciliationOrderPageParam extends PageForm {
|
||||
|
||||
private String supplierId;
|
||||
private String orderId;
|
||||
private String userId;
|
||||
private String startDate;
|
||||
private String endDate;
|
||||
private Integer reconciliationType;
|
||||
private Integer reconciliationStatus;
|
||||
private Integer invoiceStatus;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PointsMallReconciliationParam {
|
||||
|
||||
private String supplierId;
|
||||
private Integer reconciliationType;
|
||||
private String orderId;
|
||||
private String startDate;
|
||||
private String endDate;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.param;
|
||||
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PointsMallReconciliationRecordPageParam extends PageForm {
|
||||
|
||||
private String supplierId;
|
||||
private String orderId;
|
||||
private String userId;
|
||||
private Integer diffType;
|
||||
private String batchNo;
|
||||
private Integer noticeStatus;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.service;
|
||||
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.models.PointsMallReconciliationRecord;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationOrderPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationRecordPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.supplier.models.PointsMallSupplier;
|
||||
import org.nutz.dao.entity.Record;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface PointsMallReconciliationService extends BaseService<PointsMallReconciliationRecord> {
|
||||
|
||||
Pagination<Record> orderPage(PointsMallReconciliationOrderPageParam param);
|
||||
|
||||
BigDecimal pointsTotal(PointsMallReconciliationParam param);
|
||||
|
||||
String execute(PointsMallReconciliationParam param);
|
||||
|
||||
Pagination<Record> recordPage(PointsMallReconciliationRecordPageParam param);
|
||||
|
||||
List<PointsMallSupplier> listSuppliers();
|
||||
}
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
package com.budwk.app.zhgh.pointsmall.reconciliation.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.zhgh.pointsmall.order.models.PointsMallOrderSub;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.models.PointsMallReconciliationOrder;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.models.PointsMallReconciliationRecord;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationOrderPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.param.PointsMallReconciliationRecordPageParam;
|
||||
import com.budwk.app.zhgh.pointsmall.reconciliation.service.PointsMallReconciliationService;
|
||||
import com.budwk.app.zhgh.pointsmall.supplier.models.PointsMallSupplier;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class PointsMallReconciliationServiceImpl extends BaseServiceImpl<PointsMallReconciliationRecord> implements PointsMallReconciliationService {
|
||||
|
||||
public PointsMallReconciliationServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination<Record> orderPage(PointsMallReconciliationOrderPageParam param) {
|
||||
Cnd cnd = orderCnd(param, "o");
|
||||
cnd.desc("o.orderCompleteTime").desc("o.orderCreateTime");
|
||||
Sql sql = Sqls.create("select o.*, s.supplierName from points_mall_order_sub o left join points_mall_supplier s on o.supplierId = s.supplierId and s.delFlag = 0 $condition");
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(param.getPageNumber(), param.getPageSize(), sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal pointsTotal(PointsMallReconciliationParam param) {
|
||||
checkReconciliationParam(param);
|
||||
Sql sql = Sqls.create("select ifnull(sum(pointsPrice), 0) as totalPoints from points_mall_order_sub $condition");
|
||||
sql.setCondition(reconciliationCnd(param, ""));
|
||||
Record record = (Record) dao().execute(sql.setCallback(Sqls.callback.record())).getResult();
|
||||
return record == null || record.get("totalPoints") == null ? BigDecimal.ZERO : new BigDecimal(record.get("totalPoints").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(PointsMallReconciliationParam param) {
|
||||
checkReconciliationParam(param);
|
||||
List<PointsMallOrderSub> orders = dao().query(PointsMallOrderSub.class, reconciliationCnd(param, ""));
|
||||
if (CollUtil.isEmpty(orders)) {
|
||||
return "未查询到待对账订单";
|
||||
}
|
||||
|
||||
String batchNo = DateUtil.format(new Date(), "yyyyMMddHHmmss") + IdUtil.fastSimpleUUID().substring(0, 6);
|
||||
int success = 0;
|
||||
int exception = 0;
|
||||
List<PointsMallReconciliationRecord> records = new ArrayList<>();
|
||||
|
||||
for (PointsMallOrderSub order : orders) {
|
||||
PointsMallReconciliationOrder supplierOrder = dao().fetch(PointsMallReconciliationOrder.class,
|
||||
Cnd.where("orderId", "=", order.getOrderId())
|
||||
.and("supplierId", "=", order.getSupplierId())
|
||||
.and("delFlag", "=", false));
|
||||
PointsMallReconciliationRecord record = buildRecord(order, supplierOrder, batchNo);
|
||||
if (record.getDiffType() == null || record.getDiffType() == 0) {
|
||||
success++;
|
||||
dao().update(PointsMallOrderSub.class, Chain.make("reconciliationStatus", 1), Cnd.where("id", "=", order.getId()));
|
||||
} else {
|
||||
exception++;
|
||||
dao().update(PointsMallOrderSub.class, Chain.make("reconciliationStatus", 2), Cnd.where("id", "=", order.getId()));
|
||||
}
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
dao().insert(records);
|
||||
return "对账完成,批次号:" + batchNo + ",成功:" + success + ",异常:" + exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination<Record> recordPage(PointsMallReconciliationRecordPageParam param) {
|
||||
Cnd cnd = Cnd.where("r.delFlag", "=", false);
|
||||
if (StrUtil.isNotBlank(param.getSupplierId())) {
|
||||
cnd.and("r.supplierId", "=", param.getSupplierId());
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getOrderId())) {
|
||||
cnd.and("r.orderId", "like", "%" + param.getOrderId() + "%");
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getUserId())) {
|
||||
cnd.and("r.userId", "like", "%" + param.getUserId() + "%");
|
||||
}
|
||||
if (param.getDiffType() != null) {
|
||||
cnd.and("r.diffType", "=", param.getDiffType());
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getBatchNo())) {
|
||||
cnd.and("r.batchNo", "like", "%" + param.getBatchNo() + "%");
|
||||
}
|
||||
if (param.getNoticeStatus() != null) {
|
||||
cnd.and("r.noticeStatus", "=", param.getNoticeStatus());
|
||||
}
|
||||
cnd.desc("r.createdAt");
|
||||
Sql sql = Sqls.create("select r.*, s.supplierName from points_mall_reconciliation_record r left join points_mall_supplier s on r.supplierId = s.supplierId and s.delFlag = 0 $condition");
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(param.getPageNumber(), param.getPageSize(), sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PointsMallSupplier> listSuppliers() {
|
||||
return dao().query(PointsMallSupplier.class, Cnd.where("delFlag", "=", false).asc("sortCode"));
|
||||
}
|
||||
|
||||
private Cnd orderCnd(PointsMallReconciliationOrderPageParam param, String alias) {
|
||||
Cnd cnd = Cnd.where(field(alias, "delFlag"), "=", false);
|
||||
if (StrUtil.isNotBlank(param.getSupplierId())) {
|
||||
cnd.and(field(alias, "supplierId"), "=", param.getSupplierId());
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getOrderId())) {
|
||||
List<String> orderIds = StrUtil.splitTrim(param.getOrderId(), ",");
|
||||
if (orderIds.size() > 1) {
|
||||
cnd.and(field(alias, "orderId"), "in", orderIds);
|
||||
} else {
|
||||
cnd.and(field(alias, "orderId"), "like", "%" + param.getOrderId() + "%");
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getUserId())) {
|
||||
cnd.and(field(alias, "userId"), "like", "%" + param.getUserId() + "%");
|
||||
}
|
||||
if (param.getReconciliationStatus() != null) {
|
||||
cnd.and(field(alias, "reconciliationStatus"), "=", param.getReconciliationStatus());
|
||||
}
|
||||
if (param.getInvoiceStatus() != null) {
|
||||
cnd.and(field(alias, "invoiceStatus"), "=", param.getInvoiceStatus());
|
||||
}
|
||||
addDateRange(cnd, alias, param.getStartDate(), param.getEndDate());
|
||||
return cnd;
|
||||
}
|
||||
|
||||
private Cnd reconciliationCnd(PointsMallReconciliationParam param, String alias) {
|
||||
Cnd cnd = Cnd.where(field(alias, "delFlag"), "=", false);
|
||||
cnd.and(field(alias, "supplierId"), "=", param.getSupplierId());
|
||||
if (param.getReconciliationType() != null && param.getReconciliationType() == 2) {
|
||||
cnd.and(field(alias, "reconciliationStatus"), "=", 2);
|
||||
} else {
|
||||
cnd.and(field(alias, "reconciliationStatus"), "=", 0);
|
||||
}
|
||||
if (StrUtil.isNotBlank(param.getOrderId())) {
|
||||
List<String> orderIds = StrUtil.splitTrim(param.getOrderId(), ",");
|
||||
if (orderIds.size() > 1) {
|
||||
cnd.and(field(alias, "orderId"), "in", orderIds);
|
||||
} else {
|
||||
cnd.and(field(alias, "orderId"), "like", "%" + param.getOrderId() + "%");
|
||||
}
|
||||
}
|
||||
addDateRange(cnd, alias, param.getStartDate(), param.getEndDate());
|
||||
return cnd;
|
||||
}
|
||||
|
||||
private void addDateRange(Cnd cnd, String alias, String startDate, String endDate) {
|
||||
if (StrUtil.isNotBlank(startDate)) {
|
||||
cnd.and(field(alias, "orderCompleteTime"), ">=", DateUtil.beginOfDay(DateUtil.parse(startDate)));
|
||||
}
|
||||
if (StrUtil.isNotBlank(endDate)) {
|
||||
cnd.and(field(alias, "orderCompleteTime"), "<=", DateUtil.endOfDay(DateUtil.parse(endDate)));
|
||||
}
|
||||
}
|
||||
|
||||
private String field(String alias, String field) {
|
||||
return StrUtil.isBlank(alias) ? field : alias + "." + field;
|
||||
}
|
||||
|
||||
private void checkReconciliationParam(PointsMallReconciliationParam param) {
|
||||
if (param == null) {
|
||||
throw new IllegalArgumentException("对账参数不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(param.getSupplierId())) {
|
||||
throw new IllegalArgumentException("供应商不能为空");
|
||||
}
|
||||
if (param.getReconciliationType() == null) {
|
||||
throw new IllegalArgumentException("对账类型不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(param.getStartDate()) || StrUtil.isBlank(param.getEndDate())) {
|
||||
throw new IllegalArgumentException("对账日期不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
private PointsMallReconciliationRecord buildRecord(PointsMallOrderSub order, PointsMallReconciliationOrder supplierOrder, String batchNo) {
|
||||
PointsMallReconciliationRecord record = new PointsMallReconciliationRecord();
|
||||
record.setSupplierId(order.getSupplierId());
|
||||
record.setOrderId(order.getOrderId());
|
||||
record.setUserId(order.getUserId());
|
||||
record.setPRefund(nullToZero(order.getRefund()));
|
||||
record.setPTotalPrice(nullToZero(order.getTotalPrice()));
|
||||
record.setPCashAmount(nullToZero(order.getWPayOrAPay()));
|
||||
record.setPPointsPrice(nullToZero(order.getPointsPrice()));
|
||||
record.setBatchNo(batchNo);
|
||||
record.setNoticeStatus(0);
|
||||
record.setPushTime(0);
|
||||
|
||||
if (supplierOrder == null) {
|
||||
record.setSRefund(BigDecimal.ZERO);
|
||||
record.setSTotalPrice(record.getPTotalPrice());
|
||||
record.setSCashAmount(record.getPCashAmount());
|
||||
record.setSPointsPrice(record.getPPointsPrice());
|
||||
record.setDiffType(0);
|
||||
record.setDiffReason("未获取到供应商侧对账订单,按平台订单确认");
|
||||
return record;
|
||||
}
|
||||
|
||||
record.setSRefund(BigDecimal.ZERO);
|
||||
record.setSTotalPrice(nullToZero(supplierOrder.getTotalPrice()));
|
||||
record.setSCashAmount(BigDecimal.ZERO);
|
||||
record.setSPointsPrice(nullToZero(supplierOrder.getTotalPrice()));
|
||||
|
||||
List<String> reasons = new ArrayList<>();
|
||||
if (!amountEquals(record.getPTotalPrice(), record.getSTotalPrice())) {
|
||||
reasons.add("订单总金额不一致");
|
||||
}
|
||||
if (!amountEquals(record.getPPointsPrice(), record.getSPointsPrice())) {
|
||||
reasons.add("积分金额不一致");
|
||||
}
|
||||
if (!Objects.equals(order.getUserId(), supplierOrder.getUserId())) {
|
||||
reasons.add("用户ID不一致");
|
||||
}
|
||||
record.setDiffType(reasons.isEmpty() ? 0 : 1);
|
||||
record.setDiffReason(reasons.isEmpty() ? "对账一致" : String.join(";", reasons));
|
||||
return record;
|
||||
}
|
||||
|
||||
private BigDecimal nullToZero(BigDecimal value) {
|
||||
return value == null ? BigDecimal.ZERO : value;
|
||||
}
|
||||
|
||||
private boolean amountEquals(BigDecimal left, BigDecimal right) {
|
||||
return nullToZero(left).compareTo(nullToZero(right)) == 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user