|
|
|
@ -2,51 +2,54 @@ package au.com.royalpay.payment.manage.dev.core.impl;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.dev.core.HfClearAmountService;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class HfClearAmountServiceImpl implements HfClearAmountService{
|
|
|
|
|
private final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
|
|
|
|
|
public class HfClearAmountServiceImpl implements HfClearAmountService {
|
|
|
|
|
@Resource
|
|
|
|
|
private TransactionMapper transactionMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject hfjsonobject(String dateto,String datefrom) {
|
|
|
|
|
JSONObject hfAmountInfo = new JSONObject();
|
|
|
|
|
JSONObject parms = new JSONObject();
|
|
|
|
|
parms.put("dateto", dateto + " 02:00:00");
|
|
|
|
|
parms.put("datefrom", datefrom + " 02:00:00");
|
|
|
|
|
List<JSONObject> hflist = transactionMapper.getHfClearAmount(parms);
|
|
|
|
|
Double payallAmount = 0.0;
|
|
|
|
|
Double refundAllAmount = 0.0;
|
|
|
|
|
Double paySurAmount = 0.0;
|
|
|
|
|
Double refundSurAllAmount = 0.0;
|
|
|
|
|
if (hflist.isEmpty()) {
|
|
|
|
|
hfAmountInfo.put("PayAmount", 0);
|
|
|
|
|
hfAmountInfo.put("RefundAmount", 0);
|
|
|
|
|
public JSONObject hfjsonobject(String dateto, String datefrom) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
params.put("datefrom", DateUtils.addMinutes(DateUtils.parseDate(datefrom), PlatformEnvironment.getEnv().getTimeZoneOffsetMinutes()));
|
|
|
|
|
params.put("dateto", DateUtils.addMinutes(DateUtils.parseDate(dateto), PlatformEnvironment.getEnv().getTimeZoneOffsetMinutes()));
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new ServerErrorException("时间转换异常");
|
|
|
|
|
}
|
|
|
|
|
for(JSONObject hfAmount : hflist){
|
|
|
|
|
if ("Credit".equals(hfAmount.getString("transaction_type"))) {
|
|
|
|
|
hfAmountInfo.put("PayAmount",hfAmount.getBigDecimal("clearingamount").setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
payallAmount = hfAmount.getDouble("clearingamount");
|
|
|
|
|
paySurAmount = hfAmount.getDouble("suramount");
|
|
|
|
|
List<JSONObject> hfClearAmountResult = transactionMapper.getHfClearAmount(params);
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
result.put("payment_amount", BigDecimal.ZERO);
|
|
|
|
|
result.put("refund_amount", BigDecimal.ZERO);
|
|
|
|
|
result.put("gross_amount", BigDecimal.ZERO);
|
|
|
|
|
result.put("charge_amount", BigDecimal.ZERO);
|
|
|
|
|
result.put("clear_amount", BigDecimal.ZERO);
|
|
|
|
|
if (hfClearAmountResult.isEmpty()) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
hfClearAmountResult.forEach(dbResult -> {
|
|
|
|
|
if ("Credit".equals(dbResult.getString("transaction_type"))) {
|
|
|
|
|
result.put("payment_amount", dbResult.getBigDecimal("clear_amount"));
|
|
|
|
|
result.put("payment_surcharge", dbResult.getBigDecimal("charge_amount"));
|
|
|
|
|
}
|
|
|
|
|
if ("Debit".equals(hfAmount.getString("transaction_type"))) {
|
|
|
|
|
hfAmountInfo.put("RefundAmount",hfAmount.getBigDecimal("clearingamount").setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
refundAllAmount = hfAmount.getDouble("clearingamount");
|
|
|
|
|
refundSurAllAmount = hfAmount.getDouble("suramount");
|
|
|
|
|
if ("Debit".equals(dbResult.getString("transaction_type"))) {
|
|
|
|
|
result.put("refund_amount", dbResult.getBigDecimal("clear_amount"));
|
|
|
|
|
result.put("refund_surcharge", dbResult.getBigDecimal("charge_amount"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hfAmountInfo.put("realAmount", new BigDecimal(payallAmount - refundAllAmount).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
hfAmountInfo.put("surAmount", new BigDecimal(paySurAmount - refundSurAllAmount).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
hfAmountInfo.put("hfAmount", new BigDecimal(((payallAmount - refundAllAmount) - (paySurAmount - refundSurAllAmount))).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
return hfAmountInfo;
|
|
|
|
|
});
|
|
|
|
|
result.put("gross_amount", result.getBigDecimal("payment_amount").subtract(result.getBigDecimal("refund_amount")));
|
|
|
|
|
result.put("real_charge", result.getBigDecimal("payment_surcharge").subtract(result.getBigDecimal("refund_surcharge")));
|
|
|
|
|
result.put("clear_amount", result.getBigDecimal("gross_amount").subtract(result.getBigDecimal("real_charge")));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|