fix Estimate

master
luoyang 6 years ago
parent 7ff7ad8058
commit 7ca7c0b3c9

@ -9,13 +9,15 @@ import java.util.List;
*/
public interface EstimateAnalysisService {
List<JSONObject> listFurtureInfo() throws Exception;
List<JSONObject> listFutureInfo() throws Exception;
void clearEstimateFutureCache();
void generateSettleAmount();
void generateTransactionData();
List<JSONObject> listEstimateLog(int logType);
List<JSONObject> listEstimateLog(int logType, String date);
void initSettleAmount(String date) throws Exception;

@ -0,0 +1,6 @@
package au.com.royalpay.payment.manage.analysis.core;
public interface EstimateCacheSupport {
void clearEstimateFutureCache();
}

@ -5,22 +5,29 @@ import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi;
import au.com.royalpay.payment.channels.wechat.runtime.beans.SettlementLog;
import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService;
import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport;
import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jsoup.helper.DataUtil;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@ -51,6 +58,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
@Resource
private ClearingDetailMapper clearingDetailMapper;
@Resource
private EstimateCacheSupport estimateCacheSupport;
@Resource
private TransactionMapper transactionMapper;
public static List<String> t1client;
@ -71,10 +82,16 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
private EstimateAnalysisMapper estimateAnalysisMapper;
@Override
public List<JSONObject> listFurtureInfo() throws Exception {
@Cacheable(value = ":estimate_analysis_future:", key = "''")
public List<JSONObject> listFutureInfo() throws Exception {
return listSettlementInfo();
}
@Override
public void clearEstimateFutureCache() {
estimateCacheSupport.clearEstimateFutureCache();
}
public List<JSONObject> listSettlementInfo() throws Exception {
initClient();
@ -102,6 +119,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
today.put("t2", realToday.getBigDecimal("t2"));
today.put("t3", realToday.getBigDecimal("t3"));
today.put("total", realToday.getBigDecimal("total"));
today.put("net_amount", realToday.getBigDecimal("net_amount"));
} catch (Exception e) {
logger.error("今日清算记录未生成,使用自助查询!");
}
@ -138,13 +156,13 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
dayInfo.put("t1", new BigDecimal(0.00));
dayInfo.put("t2", new BigDecimal(0.00));
dayInfo.put("t3", new BigDecimal(0.00));
dayInfo.put("net_amount", new BigDecimal(0.00));
//todo 支持多个清算记录
List<JSONObject> logs = clearingLogMapper.findByDate(settleDate);
if (logs == null || logs.size() <= 0) {
throw new NotFoundException();
}
for (JSONObject log : logs) {
dayInfo.put("total", log.getBigDecimal("net_amount"));
JSONObject details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t1client);
dayInfo.put("t1", dayInfo.getBigDecimal("t1").add(details.getBigDecimal("total_amount")));
details.clear();
@ -155,7 +173,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t3client);
dayInfo.put("t3", dayInfo.getBigDecimal("t3").add(details.getBigDecimal("total_amount")));
dayInfo.put("net_amount", dayInfo.getBigDecimal("net_amount").add(log.getBigDecimal("net_amount")));
}
dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3")));
return dayInfo;
}
@ -202,6 +223,30 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
}
dayInfo.put("estimate_date", endStr);
dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3")));
//预计到账金额
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
Date datefrom = cal.getTime();
if (new Date().getDate() == datefrom.getDate()) {
JSONObject params = new JSONObject();
params.put("datefrom", DateFormatUtils.format(datefrom, "yyyy-MM-dd HH:mm:ss"));
params.put("dateto", DateFormatUtils.format(DateUtils.addDays(datefrom, 1),"yyyy-MM-dd HH:mm:ss"));
List<JSONObject> lastDayClearingAmount = transactionMapper.getLastDaytransAmount(params);
BigDecimal total_clearing = BigDecimal.ZERO;
BigDecimal total_surcharge = BigDecimal.ZERO;
for (JSONObject e : lastDayClearingAmount) {
total_clearing = total_clearing.add(e.getBigDecimal("clearing_amount"));
total_surcharge = total_surcharge.add(e.getBigDecimal("channel_surcharge"));
}
dayInfo.put("total_clearing", total_clearing.subtract(total_surcharge));
dayInfo.put("clearing", lastDayClearingAmount);
}
return dayInfo;
}
@ -277,7 +322,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
@Override
public void generateSettleAmount() {
String report_date = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
String report_date = DateFormatUtils.format(DateUtils.addDays(new Date(),-1), "yyyy/MM/dd");
logger.info("系统开始生成[ " + report_date + " ]清算总额");
JSONObject isClearDay = estimateAnalysisMapper.checkIsClearDay(report_date);
@ -327,8 +372,19 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
}
@Override
public List<JSONObject> listEstimateLog(int logType) {
return estimateAnalysisMapper.listEstimateLog(logType);
public List<JSONObject> listEstimateLog(int logType, String date) {
Date monthDate;
try {
monthDate = DateUtils.parseDate(date, new String[] { "yyyy-MM" });
} catch (ParseException e) {
throw new BadRequestException("Invalid month format");
}
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(monthDate);
int year = monthCal.get(Calendar.YEAR);
int month = monthCal.get(Calendar.MONTH) + 1;
return estimateAnalysisMapper.listEstimateLog(logType, year, month);
}

@ -0,0 +1,14 @@
package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
@Service
public class EstimateCacheSupportImpl implements EstimateCacheSupport {
@Override
@CacheEvict(value = ":estimate_analysis_future:", key = "''")
public void clearEstimateFutureCache() {
}
}

@ -34,7 +34,7 @@ public interface EstimateAnalysisMapper {
JSONObject getCleanAmount(@Param("start_date") String start_date, @Param("end") String end_date);
List<JSONObject> listEstimateLog(@Param("log_type") int log_type);
List<JSONObject> listEstimateLog(@Param("log_type") int log_type, @Param("year") int year, @Param("month") int month);
List<JSONObject> findCleanLogsByDate(@Param("start_date") String start_date, @Param("end_date") String end_date);

@ -3,10 +3,7 @@ package au.com.royalpay.payment.manage.analysis.web;
import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -23,17 +20,23 @@ public class EstimateAnalysisController {
@ManagerMapping(value = "/future",method = RequestMethod.GET)
public List<JSONObject> getFutureSettleInfo() throws Exception {
return estimateAnalysisService.listFurtureInfo();
return estimateAnalysisService.listFutureInfo();
}
@ManagerMapping(value = "/log",method = RequestMethod.GET)
public List<JSONObject> getEstimateLogInfo() throws Exception {
return estimateAnalysisService.listEstimateLog(1);
@ManagerMapping(value = "/future/refresh", method = RequestMethod.PUT)
public void clearEstimateFutureCache() {
estimateAnalysisService.clearEstimateFutureCache();
}
@ManagerMapping(value = "/transaction/log",method = RequestMethod.GET)
public List<JSONObject> getTransactionLogInfo() throws Exception {
return estimateAnalysisService.listEstimateLog(2);
@ManagerMapping(value = "/log/{date}", method = RequestMethod.GET)
public List<JSONObject> getEstimateLogInfo(@PathVariable String date) throws Exception {
return estimateAnalysisService.listEstimateLog(1, date);
}
@ManagerMapping(value = "/transaction/log/{date}",method = RequestMethod.GET)
public List<JSONObject> getTransactionLogInfo(@PathVariable String date) throws Exception {
return estimateAnalysisService.listEstimateLog(2,date);
}
@ManagerMapping(value = "/query", method = RequestMethod.GET)

@ -174,5 +174,7 @@ public interface TransactionMapper {
List<JSONObject> getSettlementLogDetailList(@Param("clientOrders") List<Integer> clientOrders, @Param("client_id") int clientId);
List<JSONObject> getClientOrderByTransactionTime(JSONObject params);
List<JSONObject> getLastDaytransAmount(JSONObject params);
}

@ -86,6 +86,7 @@
( IFNULL(one_clean_amount,0) + IFNULL(two_clean_amount,0) +IFNULL(three_clean_amount,0)) total_amount
FROM log_clearing_estimate
WHERE log_type = #{log_type}
AND year(log_date) = #{year} AND month(log_date) = #{month}
ORDER BY log_date DESC
</select>

@ -1111,4 +1111,18 @@
<if test="from!=null">and t.transaction_time &gt;= #{from}</if>
<if test="to!=null">and t.transaction_time &lt; #{to}</if>
</select>
<select id="getLastDaytransAmount" resultType="com.alibaba.fastjson.JSONObject">
SELECT ifnull(SUM(IF(transaction_type='Credit',clearing_amount,-clearing_amount)),0) clearing_amount,
ifnull(SUM(IF(transaction_type='Credit',total_surcharge,-total_surcharge)),0) total_surcharge,
ifnull(SUM(IF(transaction_type='Credit',channel_surcharge,-channel_surcharge)),0) channel_surcharge,
channel
FROM pmt_transactions
WHERE channel!='Settlement'
AND channel!='System'
AND system_generate = 0
AND transaction_time >= #{datefrom}
AND transaction_time &lt; #{dateto}
GROUP BY channel
</select>
</mapper>

@ -13,8 +13,8 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', '
})
}]);
app.controller('estimateCtrl', ['$scope', '$http', '$filter','chartParser',function ($scope, $http, $filter,chartParser) {
$scope.listLogs = function () {
$http.get('/analysis/estimate/log').then(function (resp) {
$scope.listLogs = function (month) {
$http.get('/analysis/estimate/log/' + $filter('date')(month, 'yyyy-MM')).then(function (resp) {
$scope.logs = resp.data;
$scope.logArray = {};
angular.forEach($scope.logs, function (item) {
@ -22,7 +22,6 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', '
});
});
}
$scope.listLogs();
$scope.future_loading = true;
$scope.listEsitimate = function () {
$http.get('/analysis/estimate/future').then(function (resp) {
@ -34,6 +33,13 @@ define(['angular', 'static/commons/commons', 'static/commons/angular-ueditor', '
}
$scope.listEsitimate();
$scope.refresh = function () {
$http.put('/analysis/estimate/future/refresh').then(function (resp) {
$scope.listEsitimate();
$scope.future_loading = true;
});
}
$scope.params = {};
$scope.today = new Date();
$scope.chooseToday = function () {

@ -51,6 +51,10 @@
<span>Total: </span>
<span ng-bind="fut.total|currency:'$'" class="text-green"></span>
</div>
<!--<div ng-if="fut.net_amount">-->
<!--<span>Net Amount: </span>-->
<!--<span ng-bind="fut.net_amount|currency:'$'" class="text-green"></span>-->
<!--</div>-->
</div>
</div>
<div class="box-header" style="border-top: solid #f06010 1px;"
@ -99,11 +103,61 @@
总到账金额:<a class="text-green"
ng-bind="fut.platformGetSettleFee|currency:'AUD'"></a></p>
</div>
<div ng-if="fut.clearing.length >0">
<div class="box-header">
<span class="text-bold">预计到账金额详情:</span>
</div>
<div class="box-body">
<div ng-repeat="clearing in fut.clearing">
<p class="text-bold col-sm-12" align="left"
ng-if="clearing.channel=='Wechat'"><img
src="/static/images/wechatpay_sign.png"
/>到账金额:<a
class="text-green"
ng-bind="(clearing.clearing_amount - clearing.channel_surcharge)|currency:'AUD'"></a></p>
<p class="text-bold col-sm-12" align="left"
ng-if="clearing.channel=='Alipay'"><img
src="/static/images/alipay_sign.png"
/>到账金额:<a
class="text-green"
ng-bind="(clearing.clearing_amount - clearing.channel_surcharge)|currency:'AUD'"></a></p>
<p class="text-bold col-sm-12" align="left"
ng-if="clearing.channel=='AlipayOnline'"><img
src="/static/images/alipay_sign.png"
/>Alipay Online到账金额:<a
class="text-green"
ng-bind="(clearing.clearing_amount - clearing.channel_surcharge)|currency:'AUD'"></a></p>
<p class="text-bold col-sm-12" align="left"
ng-if="clearing.channel=='hf'"><img
src="/static/images/hf_sign.png"
/>到账金额:<a
class="text-green"
ng-bind="(clearing.clearing_amount - clearing.channel_surcharge)|currency:'AUD'"></a></p>
<p class="text-bold col-sm-12" align="left"
ng-if="clearing.channel=='rpay'"><img
src="/static/images/r_logo.svg"
/>到账金额:<a
class="text-green"
ng-bind="(clearing.clearing_amount - clearing.channel_surcharge)|currency:'AUD'"></a></p>
</div>
<p class="text-bold col-sm-12" align="left">总到账金额:<a
class="text-green"
ng-bind="fut.total_clearing|currency:'AUD'"></a></p>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
<div ng-if="future.length > 0">
<button class="btn btn-primary" ng-click="refresh()">
<i class="fa fa-refresh"></i>
</button>
</div>
</div>
</div>
<div ng-if="future.length > 0">
@ -183,7 +237,7 @@
<div class="box box-warning settle-forecast">
<div class="box-header">Settlement Logs</div>
<div class="box-body">
<div royal-calendar month-change="loadMonthLog($month)">
<div royal-calendar month-change="listLogs($month)">
<div ng-if="logArray[(day|date:'yyyy-MM-dd')]">
<span class="text-bold">总清算额:</span>
<span style="color: #f60;"

@ -256,7 +256,7 @@
<div class="box box-warning settle-forecast" ng-if="currentUser.org==null">
<div class="box-header">Transaction Logs</div>
<div class="box-body">
<div royal-calendar month-change="loadMonthLog($month)">
<div royal-calendar month-change="listTransLogs($month)">
<div ng-if="logArray[(day|date:'yyyy-MM-dd')]">
<span class="text-bold">总交易额:</span>
<span style="color: #f60;" ng-bind="logArray[(day|date:'yyyy-MM-dd')].total_amount|currency:'$'"></span>

@ -27,8 +27,8 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts','./transaction/an
$scope.switchScale = function (scale) {
$scope.currentScale = scale;
};
$scope.listTransLogs = function () {
$http.get('/analysis/estimate/transaction/log').then(function (resp) {
$scope.listTransLogs = function (month) {
$http.get('/analysis/estimate/transaction/log/' + $filter('date')(month, 'yyyy-MM')).then(function (resp) {
$scope.logs = resp.data;
$scope.logArray = {};
angular.forEach($scope.logs, function (item) {
@ -36,7 +36,6 @@ define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts','./transaction/an
});
});
}
$scope.listTransLogs();
$scope.params = {};
$scope.today = new Date(new Date().getTime() - 24*60*60*1000);

Loading…
Cancel
Save