first commit
This commit is contained in:
3
comm/Contract/WebContent/META-INF/MANIFEST.MF
Executable file
3
comm/Contract/WebContent/META-INF/MANIFEST.MF
Executable file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
245
comm/Contract/WebContent/contract_apply_order_list.jsp
Executable file
245
comm/Contract/WebContent/contract_apply_order_list.jsp
Executable file
@@ -0,0 +1,245 @@
|
||||
<%@ page language="java" pageEncoding="utf-8"%>
|
||||
<%@ include file="include/pagetop.jsp"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="include/head.jsp"%>
|
||||
</head>
|
||||
<body>
|
||||
<%@ include file="include/loading.jsp"%>
|
||||
<%@ include file="include/top.jsp"%>
|
||||
<%@ include file="include/menu_left.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTENT -->
|
||||
<div class="content">
|
||||
|
||||
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTAINER -->
|
||||
<div class="container-default">
|
||||
<h3>永续委托单</h3>
|
||||
<%@ include file="include/alert.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START queryForm -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询条件</div>
|
||||
<div class="panel-body">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_APPLY_ORDER_LIST")'>
|
||||
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminContractApplyOrderAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="order_no_para" name="order_no_para"
|
||||
cssClass="form-control " placeholder="订单号(完整)" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="name_para" name="name_para" cssClass="form-control " placeholder="用户名、UID"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:select id="rolename_para" cssClass="form-control "
|
||||
name="rolename_para"
|
||||
list="#{'MEMBER':'正式账号','GUEST':'演示账号'}" listKey="key"
|
||||
listValue="value" headerKey="" headerValue="所有账号"
|
||||
value="rolename_para" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="submit" class="btn btn-light btn-block">查询</button>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-12" style="margin-top: 10px;">
|
||||
<div class="mailbox clearfix">
|
||||
<div class="mailbox-menu">
|
||||
<ul class="menu">
|
||||
<li><a href="javascript:setState('')"> 全部</a></li>
|
||||
<li><a href="javascript:setState('submitted')"> 已提交</a></li>
|
||||
<li><a href="javascript:setState('canceled')"> 已撤销</a></li>
|
||||
<li><a href="javascript:setState('created')"> 委托完成</a></li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END queryForm -->
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询结果</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>用户</td>
|
||||
<td>UID</td>
|
||||
<td>账户类型</td>
|
||||
<td>品种</td>
|
||||
<td>操作</td>
|
||||
<td>委托张数</td>
|
||||
<td>杠杆</td>
|
||||
<td>报价类型</td>
|
||||
<td>限价</td>
|
||||
<td>止盈止损</td>
|
||||
<td>状态</td>
|
||||
<td>创建时间</td>
|
||||
<td width="130px"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<td><s:property value="username" /></td>
|
||||
<td><s:property value="usercode" /></td>
|
||||
<td><s:if test='rolename=="GUEST"'>
|
||||
<span class="right label label-warning">演示账号</span>
|
||||
</s:if>
|
||||
<s:if test='rolename=="MEMBER"'>
|
||||
<span class="right label label-success">正式账号</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<td><s:property value="itemname" /></td>
|
||||
<td><s:if test='offset=="open"'>开</s:if><s:if test='offset=="close"'>平</s:if><s:if test='direction=="buy"'>多</s:if><s:if
|
||||
test='direction=="sell"'>空</s:if></td>
|
||||
<td><fmt:formatNumber value="${volume_open}" pattern="#0.00" /></td>
|
||||
<td><fmt:formatNumber value="${lever_rate}" pattern="#0.00" /></td>
|
||||
<td><s:if test='order_price_type=="limit"'>限价</s:if><s:if test='order_price_type=="opponent"'>市价</s:if></td>
|
||||
<td><fmt:formatNumber
|
||||
value="${price}" pattern="#0.00" /></td>
|
||||
<td><s:property value="stop_price_profit" />/<s:property value="stop_price_loss" /></td>
|
||||
<td><s:if test='state=="submitted"'>
|
||||
已提交
|
||||
</s:if> <s:if test='state=="canceled"'>已撤销</s:if> <s:if test='state=="created"'>
|
||||
<span class="right label label-success">委托完成</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<td><s:date name="createTime" format="MM-dd HH:mm:ss " /></td>
|
||||
<td>
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-light">操作</button>
|
||||
<button type="button" class="btn btn-light dropdown-toggle"
|
||||
data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="caret"></span> <span class="sr-only">Toggle
|
||||
Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_APPLY_ORDER_CLOSE")'>
|
||||
<li><a
|
||||
href="javascript:onclose('<s:property value="order_no" />')">撤销</a></li>
|
||||
</s:if>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</s:iterator>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<%@ include file="include/page_simple.jsp"%>
|
||||
<nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Panel -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
|
||||
|
||||
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_APPLY_ORDER_CLOSE")'>
|
||||
<form action="normal/adminContractApplyOrderAction!close.action" method="post"
|
||||
id="onclose">
|
||||
<input type="hidden" name="pageNo" id="pageNo" value="${param.pageNo}">
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<s:hidden name="rolename_para"></s:hidden>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
function onclose(order_no) {
|
||||
$("#order_no").val(order_no);
|
||||
swal({
|
||||
title : "是否确认撤销?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
document.getElementById("onclose").submit();
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
</sec:authorize>
|
||||
<script type="text/javascript">
|
||||
function setState(state){
|
||||
document.getElementById("status_para").value=state;
|
||||
document.getElementById("queryForm").submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
363
comm/Contract/WebContent/contract_order_history_list.jsp
Executable file
363
comm/Contract/WebContent/contract_order_history_list.jsp
Executable file
@@ -0,0 +1,363 @@
|
||||
<%@ page language="java" pageEncoding="utf-8"%>
|
||||
<%@ include file="include/pagetop.jsp"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="include/head.jsp"%>
|
||||
</head>
|
||||
<body>
|
||||
<%@ include file="include/loading.jsp"%>
|
||||
<%@ include file="include/top.jsp"%>
|
||||
<%@ include file="include/menu_left.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTENT -->
|
||||
<div class="content">
|
||||
|
||||
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTAINER -->
|
||||
<div class="container-default">
|
||||
<h3>历史永续合约单</h3>
|
||||
<%@ include file="include/alert.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START queryForm -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-title">查询条件</div>
|
||||
<div class="panel-body">
|
||||
<s:if test='isResourceAccessible("ADMIN_HISTORY_CONTRACT_ORDER_LIST")'>
|
||||
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminHistoryContractOrderAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="order_no_para" name="order_no_para"
|
||||
cssClass="form-control " placeholder="订单号(完整)" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="name_para" name="name_para" cssClass="form-control " placeholder="用户名、UID"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:select id="rolename_para" cssClass="form-control "
|
||||
name="rolename_para"
|
||||
list="#{'MEMBER':'正式账号合约','GUEST':'演示账号合约'}" listKey="key"
|
||||
listValue="value" headerKey="" headerValue="所有合约"
|
||||
value="rolename_para" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-12" style="margin-top:10px;">
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<s:textfield id="start_time" name="start_time"
|
||||
cssClass="form-control " placeholder="开始日期" />
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<s:textfield id="end_time" name="end_time"
|
||||
cssClass="form-control " placeholder="结束日期" />
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="submit" class="btn btn-light btn-block">查询</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-12" style="margin-top: 10px;">
|
||||
<div class="mailbox clearfix">
|
||||
<div class="mailbox-menu">
|
||||
<ul class="menu">
|
||||
<li><a href="javascript:setState('')"> 全部</a></li>
|
||||
<li><a href="javascript:setState('submitted')"> 持仓</a></li>
|
||||
<li><a href="javascript:setState('created')"> 已平仓</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<%-- <sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-title">调整</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="mailbox clearfix">
|
||||
<div class="mailbox-menu">
|
||||
<ul class="menu">
|
||||
<s:iterator value="items" status="stat">
|
||||
<li><a href="#" data-toggle="modal"
|
||||
data-target="#myModal3"
|
||||
onclick="showModal('<s:property value="symbol" />','<s:property value="name" />');"
|
||||
id='<s:property value="symbol" />'> <s:property
|
||||
value="name" /></a></li>
|
||||
</s:iterator>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="myModal3" tabindex="-1"
|
||||
role="dialog" aria-hidden="true" style="display: none;">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="item_name">调整</h4>
|
||||
</div>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminContractOrderAction!adjust.action"
|
||||
method="post" id="mainForm">
|
||||
<input type="hidden" id="adjust_symbol" name="symbol" />
|
||||
<s:hidden name="pageNo"></s:hidden>
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<s:hidden name="start_time"></s:hidden>
|
||||
<s:hidden name="end_time"></s:hidden>
|
||||
<s:hidden name="rolename_para"></s:hidden>
|
||||
<div class="modal-body">
|
||||
<div class="form-area">
|
||||
请输入正负调整值 <input type="text" id="adjust" name="value"
|
||||
class="form-control" placeholder="正负调整值"
|
||||
onchange="getValue(2);">
|
||||
<button type="button"
|
||||
class="btn btn-default btn-icon btn-sm"
|
||||
style="margin-top: 6px;" id="adjust_add_button"
|
||||
onclick="getValue(0);"></button>
|
||||
|
||||
<button type="button"
|
||||
class="btn btn-default btn-icon btn-sm"
|
||||
style="margin-top: 6px;" id="adjust_sub_button"
|
||||
onclick="getValue(1);"></button>
|
||||
<div class="form-area">
|
||||
生效趋势(秒,0秒为即时生效) <input type="text" id="second"
|
||||
name="second" class="form-control" value="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-area">
|
||||
调整值
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>原值</td>
|
||||
<td>调整后</td>
|
||||
<td>累计修正值</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="adjust_value_before"><span
|
||||
class="label label-danger" id="adjust_value_before"></span></td>
|
||||
<td><span class="label label-danger"
|
||||
id="adjust_value_after"></span></td>
|
||||
<td id="adjust_value"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="form-area">
|
||||
生效趋势
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>待生效值</td>
|
||||
<td>时间(秒)</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="adjust_delay"></td>
|
||||
<td id="adjust_second"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-white"
|
||||
data-dismiss="modal">取消</button>
|
||||
<button type="submit" class="btn btn-danger">确定</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize> --%>
|
||||
|
||||
<div class="row" id="history_content">
|
||||
<%@ include file="contract_order_history_list_content.jsp"%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
|
||||
<script type="text/javascript">
|
||||
$.fn.datetimepicker.dates['zh'] = {
|
||||
days : [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" ],
|
||||
daysShort : [ "日", "一", "二", "三", "四", "五", "六", "日" ],
|
||||
daysMin : [ "日", "一", "二", "三", "四", "五", "六", "日" ],
|
||||
months : [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月",
|
||||
"十月", "十一月", "十二月" ],
|
||||
monthsShort : [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
|
||||
"十一", "十二" ],
|
||||
meridiem : [ "上午", "下午" ],
|
||||
//suffix: ["st", "nd", "rd", "th"],
|
||||
today : "今天",
|
||||
clear : "清空"
|
||||
};
|
||||
|
||||
$(function() {
|
||||
$('#start_time').datetimepicker({
|
||||
format : 'yyyy-mm-dd',
|
||||
language : 'zh',
|
||||
weekStart : 1,
|
||||
todayBtn : 1,
|
||||
autoclose : 1,
|
||||
todayHighlight : 1,
|
||||
startView : 2,
|
||||
clearBtn : true,
|
||||
minView : 2
|
||||
})
|
||||
|
||||
$('#end_time').datetimepicker({
|
||||
format : 'yyyy-mm-dd',
|
||||
language : 'zh',
|
||||
weekStart : 1,
|
||||
todayBtn : 1,
|
||||
autoclose : 1,
|
||||
todayHighlight : 1,
|
||||
startView : 2,
|
||||
clearBtn : true,
|
||||
minView : 2
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<s:if test='isResourceAccessible("ADMIN_HISTORY_CONTRACT_ORDER_CLOSE")'>
|
||||
<form action="normal/adminHistoryContractOrderAction!close.action" method="post"
|
||||
id="onclose">
|
||||
<input type="hidden" name="pageNo" id="pageNo" value="${param.pageNo}">
|
||||
<s:hidden name="order_no" id="order_no"></s:hidden>
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<s:hidden name="start_time"></s:hidden>
|
||||
<s:hidden name="end_time"></s:hidden>
|
||||
<s:hidden name="rolename_para"></s:hidden>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
/*5轮询读取函数*/
|
||||
/* setInterval(function() {
|
||||
var data = {"pageNo":$("#pageNo").val()
|
||||
,"rolename_para":$("#rolename_para").val()
|
||||
,"start_time":$("#start_time").val()
|
||||
,"end_time":$("#end_time").val()};
|
||||
goAjaxUrl($("#ajaxUrl").val(),data);
|
||||
}, 3000); */
|
||||
|
||||
function onclose(order_no) {
|
||||
$("#order_no").val(order_no);
|
||||
swal({
|
||||
title : "是否确认平仓?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
document.getElementById("onclose").submit();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function goAjaxUrl(targetUrl,data){
|
||||
$.ajax({
|
||||
url:targetUrl,
|
||||
data:data,
|
||||
type:'get',
|
||||
success: function (res) {
|
||||
// 一旦设置的 dataType 选项,就不再关心 服务端 响应的 Content-Type 了
|
||||
// 客户端会主观认为服务端返回的就是 JSON 格式的字符串
|
||||
// console.log(res)
|
||||
// $(".loading").hide();
|
||||
$("#history_content").html(res);
|
||||
/* $('#quote_currency').val(data.quote_currency);
|
||||
$('#base_currency').val(data.base_currency);
|
||||
|
||||
if(null==data.quote_currency||''==data.quote_currency||typeof(data.quote_currency) == "undefined"){
|
||||
$('.tr_quote:first').attr('style','background:#39ffff;');
|
||||
}else{
|
||||
$('#tr_'+data.quote_currency).attr('style','background:#39ffff;');
|
||||
} */
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
</sec:authorize>
|
||||
<script type="text/javascript">
|
||||
function setState(state){
|
||||
document.getElementById("status_para").value=state;
|
||||
document.getElementById("queryForm").submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
121
comm/Contract/WebContent/contract_order_history_list_content.jsp
Executable file
121
comm/Contract/WebContent/contract_order_history_list_content.jsp
Executable file
@@ -0,0 +1,121 @@
|
||||
<%@ page language="java" pageEncoding="utf-8"%>
|
||||
<%@taglib prefix="s" uri="/struts-tags"%>
|
||||
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询结果</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>用户</td>
|
||||
<td>UID</td>
|
||||
<td>账户类型</td>
|
||||
<!-- <td >订单号</td> -->
|
||||
<td>品种</td>
|
||||
<td>操作</td>
|
||||
<td>成交均价</td>
|
||||
<td>止盈止损</td>
|
||||
<td>剩余/委托金额</td>
|
||||
<td>剩余/委托保证金</td>
|
||||
<td>用户钱包余额</td>
|
||||
<td>盈亏</td>
|
||||
<td>状态</td>
|
||||
<td>创建时间</td>
|
||||
<td>平仓时间</td>
|
||||
<s:if test='isResourceAccessible("ADMIN_HISTORY_CONTRACT_ORDER_CLOSE")'>
|
||||
<td width="130px"></td>
|
||||
</s:if>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<td><s:property value="username" /></td>
|
||||
<td><s:property value="usercode" /></td>
|
||||
<td><s:if test='rolename=="GUEST"'>
|
||||
<span class="right label label-warning">演示账号</span>
|
||||
</s:if>
|
||||
<s:if test='rolename=="MEMBER"'>
|
||||
<span class="right label label-success">正式账号</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<%-- <td ><s:property value="order_no" /></td> --%>
|
||||
<td><s:property value="itemname" /></td>
|
||||
<td><s:if test='offset=="open"'>开</s:if><s:if test='offset=="close"'>平</s:if><s:if test='direction=="buy"'>多</s:if><s:if
|
||||
test='direction=="sell"'>空</s:if></td>
|
||||
<td><s:property value="trade_avg_price" /></td>
|
||||
<td><s:property value="stop_price_profit" />/<s:property value="stop_price_loss" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${volume*unit_amount}" pattern="#0.00" /></span>/<fmt:formatNumber value="${volume_open*unit_amount}" pattern="#0.00" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${deposit}" pattern="#0.00" /></span>/<fmt:formatNumber value="${deposit_open}" pattern="#0.00" /></td>
|
||||
<td><fmt:formatNumber value="${money}" pattern="#0.00" /></td>
|
||||
<td>
|
||||
<s:if test='state=="submitted"'>
|
||||
<s:if test="(amount_close+profit+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<s:if test="(amount_close+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:else>
|
||||
</td>
|
||||
<td><s:if test='state=="submitted"'>
|
||||
持仓
|
||||
</s:if> <s:if test='state=="created"'>
|
||||
<span class="right label label-success">已平仓</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<td><s:date name="createTime" format="MM-dd HH:mm:ss " /></td>
|
||||
<td><s:date name="closeTime" format="MM-dd HH:mm:ss " /></td>
|
||||
|
||||
<s:if test='isResourceAccessible("ADMIN_HISTORY_CONTRACT_ORDER_CLOSE")'>
|
||||
<td>
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-light">操作</button>
|
||||
<button type="button" class="btn btn-light dropdown-toggle"
|
||||
data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="caret"></span> <span class="sr-only">Toggle
|
||||
Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<s:if test='state=="submitted"'>
|
||||
|
||||
<li><a
|
||||
href="javascript:onclose('<s:property value="order_no" />')">平仓</a></li>
|
||||
|
||||
</s:if>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</td>
|
||||
</s:if>
|
||||
|
||||
</tr>
|
||||
</s:iterator>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<%@ include file="include/page_simple.jsp"%>
|
||||
<nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Panel -->
|
||||
|
||||
</div>
|
||||
607
comm/Contract/WebContent/contract_order_list.jsp
Executable file
607
comm/Contract/WebContent/contract_order_list.jsp
Executable file
@@ -0,0 +1,607 @@
|
||||
<%@ page language="java" pageEncoding="utf-8"%>
|
||||
<%@ include file="include/pagetop.jsp"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="include/head.jsp"%>
|
||||
</head>
|
||||
<body>
|
||||
<%@ include file="include/loading.jsp"%>
|
||||
<%@ include file="include/top.jsp"%>
|
||||
<%@ include file="include/menu_left.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTENT -->
|
||||
<div class="content">
|
||||
|
||||
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START CONTAINER -->
|
||||
<div class="container-default">
|
||||
<h3>当前永续持仓单</h3>
|
||||
<%@ include file="include/alert.jsp"%>
|
||||
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<!-- START queryForm -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询条件</div>
|
||||
<div class="panel-body">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_CONTENT")'>
|
||||
<input type="hidden" value="<%=basePath%>normal/adminContractOrderAction!content.action" id='ajaxUrl'/>
|
||||
</s:if>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_LIST")'>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminContractOrderAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="order_no_para" name="order_no_para"
|
||||
cssClass="form-control " placeholder="订单号(完整)" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="name_para" name="name_para" cssClass="form-control " placeholder="用户名、UID"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:select id="rolename_para" cssClass="form-control "
|
||||
name="rolename_para"
|
||||
list="#{'MEMBER':'正式账号合约','GUEST':'演示账号合约'}" listKey="key"
|
||||
listValue="value" headerKey="" headerValue="所有合约"
|
||||
value="rolename_para" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-12" style="margin-top:10px;">
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<s:textfield id="start_time" name="start_time"
|
||||
cssClass="form-control " placeholder="开始日期" />
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<s:textfield id="end_time" name="end_time"
|
||||
cssClass="form-control " placeholder="结束日期" />
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="submit" class="btn btn-light btn-block">查询</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_SHOWMODAL")'>
|
||||
<div class="col-md-12 col-lg-12" style="margin-top: 10px;">
|
||||
<div class="mailbox clearfix">
|
||||
<div class="panel-title" style="padding-left: 5px;margin-top: -10px;">操作</div>
|
||||
<div class="mailbox-menu" style="border-bottom: hidden;">
|
||||
<ul class="menu">
|
||||
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-12" >
|
||||
<!-- <div class="mailbox clearfix">
|
||||
<div class="mailbox-menu">
|
||||
<ul class="menu">
|
||||
<li><a href="javascript:setState('')"> 全部</a></li>
|
||||
<li><a href="javascript:setState('submitted')"> 持仓</a></li>
|
||||
<li><a href="javascript:setState('created')"> 已平仓</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls" style="margin-left: -15px;">
|
||||
<s:select id="para_symbol" cssClass="form-control "
|
||||
name="para_symbol"
|
||||
list="symbols" listKey="key"
|
||||
listValue="value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="button" class="btn btn-light btn-block" data-toggle="modal"
|
||||
data-target="#myModal3" onClick="showModal($('#para_symbol').val(),$('#para_symbol').find('option:selected').text());">调整</button>
|
||||
</div>
|
||||
<div class="modal fade" id="myModal3" tabindex="-1"
|
||||
role="dialog" aria-hidden="true" style="display: none;z-index: 99999;">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="item_name">调整</h4>
|
||||
</div>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminContractOrderAction!adjust.action"
|
||||
method="post" id="mainForm">
|
||||
<input type="hidden" id="adjust_symbol" name="symbol" />
|
||||
<s:hidden name="pageNo"></s:hidden>
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<s:hidden name="start_time"></s:hidden>
|
||||
<s:hidden name="end_time"></s:hidden>
|
||||
<s:hidden name="rolename_para"></s:hidden>
|
||||
<div class="modal-body">
|
||||
<div class="form-area">
|
||||
请输入正负调整值 <input type="text" id="adjust" name="value"
|
||||
class="form-control" placeholder="正负调整值"
|
||||
onchange="getValue(2);">
|
||||
<button type="button"
|
||||
class="btn btn-default btn-icon btn-sm"
|
||||
style="margin-top: 6px;" id="adjust_add_button"
|
||||
onclick="getValue(0);"></button>
|
||||
|
||||
<button type="button"
|
||||
class="btn btn-default btn-icon btn-sm"
|
||||
style="margin-top: 6px;" id="adjust_sub_button"
|
||||
onclick="getValue(1);"></button>
|
||||
<div class="form-area">
|
||||
生效趋势(秒,0秒为即时生效) <input type="text" id="second"
|
||||
name="second" class="form-control" value="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-area">
|
||||
调整值
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>原值</td>
|
||||
<td>调整后</td>
|
||||
<td>累计修正值</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="adjust_value_before"><span
|
||||
class="label label-danger" id="adjust_value_before"></span></td>
|
||||
<td><span class="label label-danger"
|
||||
id="adjust_value_after"></span></td>
|
||||
<td id="adjust_value"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="form-area">
|
||||
生效趋势
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>待生效值</td>
|
||||
<td>时间(秒)</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="adjust_delay"></td>
|
||||
<td id="adjust_second"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-white"
|
||||
data-dismiss="modal">取消</button>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_ADJUST")'>
|
||||
<button type="submit" class="btn btn-danger">确定</button>
|
||||
</s:if>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</s:if>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<%-- <sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-title">调整</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="mailbox clearfix">
|
||||
<div class="mailbox-menu">
|
||||
<ul class="menu">
|
||||
<s:iterator value="items" status="stat">
|
||||
<li><a href="#" data-toggle="modal"
|
||||
data-target="#myModal3"
|
||||
onclick="showModal('<s:property value="symbol" />','<s:property value="name" />');"
|
||||
id='<s:property value="symbol" />'> <s:property
|
||||
value="name" /></a></li>
|
||||
</s:iterator>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize> --%>
|
||||
<div class="row" >
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
<div class="col-md-12 col-lg-12" style="margin-top: 10px;margin-bottom: 10px;display:none;" id="sysmbol_tool">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_SHOWMODAL")'>
|
||||
<div class="col-md-12 col-lg-3">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls" style="margin-left: -15px;">
|
||||
<s:select id="para_symbol_2" cssClass="form-control "
|
||||
name="para_symbol_2"
|
||||
list="symbols" listKey="key"
|
||||
listValue="value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="button" class="btn btn-light btn-block" data-toggle="modal"
|
||||
data-target="#myModal3" onClick="showModal($('#para_symbol_2').val(),$('#para_symbol_2').find('option:selected').text());">调整</button>
|
||||
</div>
|
||||
</s:if>
|
||||
</div>
|
||||
<div class="panel-title">查询结果</div>
|
||||
<ul class="panel-tools">
|
||||
<li><a class="icon minimise-tool"><i
|
||||
class="fa fa-minus"></i></a></li>
|
||||
<li><a class="icon expand-tool" onClick="$('#sysmbol_tool').toggle();"><i class="fa fa-expand"></i></a></li>
|
||||
</ul>
|
||||
<div class="panel-body" id="list_content">
|
||||
<%@ include file="contract_order_list_content.jsp"%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Panel -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<%-- <div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询结果</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>用户</td>
|
||||
<td>订单号</td>
|
||||
<td>品种</td>
|
||||
<td>操作</td>
|
||||
<td>成交均价</td>
|
||||
<td>止盈止损</td>
|
||||
<td>剩余/委托金额</td>
|
||||
<td>剩余/委托保证金</td>
|
||||
<td>用户钱包余额</td>
|
||||
<td>盈亏</td>
|
||||
<td>状态</td>
|
||||
<td width="130px"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<td><s:property value="username" /></td>
|
||||
<td><s:property value="order_no" /></td>
|
||||
<td><s:property value="itemname" /></td>
|
||||
<td><s:if test='offset=="open"'>开</s:if><s:if test='offset=="close"'>平</s:if><s:if test='direction=="buy"'>多</s:if><s:if
|
||||
test='direction=="sell"'>空</s:if></td>
|
||||
<td><s:property value="trade_avg_price" /></td>
|
||||
<td><s:property value="stop_price_profit" />/<s:property value="stop_price_loss" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${volume*unit_amount}" pattern="#0.00" /></span>/<fmt:formatNumber value="${volume_open*unit_amount}" pattern="#0.00" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${deposit}" pattern="#0.00" /></span>/<fmt:formatNumber value="${deposit_open}" pattern="#0.00" /></td>
|
||||
<td><fmt:formatNumber value="${money}" pattern="#0.00" /></td>
|
||||
<td>
|
||||
<s:if test='state=="submitted"'>
|
||||
<s:if test="(amount_close+profit+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<s:if test="(amount_close+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:else>
|
||||
</td>
|
||||
<td><s:if test='state=="submitted"'>
|
||||
持仓
|
||||
</s:if> <s:if test='state=="created"'>
|
||||
<span class="right label label-success">已平仓</span>
|
||||
</s:if> </td>
|
||||
<td>
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-light">操作</button>
|
||||
<button type="button" class="btn btn-light dropdown-toggle"
|
||||
data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="caret"></span> <span class="sr-only">Toggle
|
||||
Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a
|
||||
href="javascript:onclose('<s:property value="order_no" />')">平仓</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</s:iterator>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<%@ include file="include/page_simple.jsp"%>
|
||||
<nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Panel -->
|
||||
|
||||
</div>
|
||||
</div> --%>
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
|
||||
<script type="text/javascript">
|
||||
$.fn.datetimepicker.dates['zh'] = {
|
||||
days : [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" ],
|
||||
daysShort : [ "日", "一", "二", "三", "四", "五", "六", "日" ],
|
||||
daysMin : [ "日", "一", "二", "三", "四", "五", "六", "日" ],
|
||||
months : [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月",
|
||||
"十月", "十一月", "十二月" ],
|
||||
monthsShort : [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
|
||||
"十一", "十二" ],
|
||||
meridiem : [ "上午", "下午" ],
|
||||
//suffix: ["st", "nd", "rd", "th"],
|
||||
today : "今天",
|
||||
clear : "清空"
|
||||
};
|
||||
|
||||
$(function() {
|
||||
$('#start_time').datetimepicker({
|
||||
format : 'yyyy-mm-dd',
|
||||
language : 'zh',
|
||||
weekStart : 1,
|
||||
todayBtn : 1,
|
||||
autoclose : 1,
|
||||
todayHighlight : 1,
|
||||
startView : 2,
|
||||
clearBtn : true,
|
||||
minView : 2
|
||||
})
|
||||
|
||||
$('#end_time').datetimepicker({
|
||||
format : 'yyyy-mm-dd',
|
||||
language : 'zh',
|
||||
weekStart : 1,
|
||||
todayBtn : 1,
|
||||
autoclose : 1,
|
||||
todayHighlight : 1,
|
||||
startView : 2,
|
||||
clearBtn : true,
|
||||
minView : 2
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_CLOSE")'>
|
||||
<form action="<%=basePath%>normal/adminContractOrderAction!close.action" method="post"
|
||||
id="onclose">
|
||||
<input type="hidden" name="pageNo" id="pageNo" value="${param.pageNo}">
|
||||
<s:hidden name="order_no" id="order_no"></s:hidden>
|
||||
<s:hidden name="status_para"></s:hidden>
|
||||
<s:hidden name="start_time"></s:hidden>
|
||||
<s:hidden name="end_time"></s:hidden>
|
||||
<s:hidden name="rolename_para"></s:hidden>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
function onclose(order_no) {
|
||||
$("#order_no").val(order_no);
|
||||
swal({
|
||||
title : "是否确认平仓?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
document.getElementById("onclose").submit();
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
</sec:authorize>
|
||||
<!-- <script type="text/javascript">
|
||||
function setState(state){
|
||||
document.getElementById("status_para").value=state;
|
||||
document.getElementById("queryForm").submit();
|
||||
}
|
||||
</script> -->
|
||||
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_SHOWMODAL")'>
|
||||
<script type="text/javascript">
|
||||
function showModal(symbol,name){
|
||||
// var name = $("#para_symbol").find("option:selected").text();
|
||||
// var symbol = $("#para_symbol").val();
|
||||
$("#adjust_symbol").val(symbol);
|
||||
$("#adjust").val(0);
|
||||
$("#item_name").html("调整"+name);
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "<%=basePath%>normal/adminContractOrderAction!showModal.action?random=" + Math.random(),
|
||||
dataType: "json",
|
||||
data: {"symbol":symbol},
|
||||
success: function(data) {
|
||||
var temp = $.parseJSON(data)
|
||||
$("#adjust_add_button").html("加" +temp.pips);
|
||||
$("#adjust_sub_button").html("减" +temp.pips);
|
||||
$("#adjust_value_before").html(temp.new_price);
|
||||
$("#adjust_value_after").html(temp.new_price+temp.adjust_value);
|
||||
$("#adjust_value").html(temp.adjust_value);
|
||||
$("#adjust_delay").html(temp.delay_value);
|
||||
$("#adjust_second").html(temp.delay_second);
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
console.log("请求错误");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_GETVALUE")'>
|
||||
<script type="text/javascript">
|
||||
function getValue(type){
|
||||
var value = $("#adjust").val();
|
||||
var symbol = $("#adjust_symbol").val();
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "<%=basePath%>normal/adminContractOrderAction!getValue.action?random="
|
||||
+ Math.random(),
|
||||
dataType : "json",
|
||||
data : {
|
||||
"symbol" : symbol,
|
||||
"type" : type,
|
||||
"value" : value
|
||||
},
|
||||
success : function(data) {
|
||||
var temp = $.parseJSON(data);
|
||||
$("#adjust").val(temp.adjust_current_value);
|
||||
$("#adjust_value_before").html(temp.new_price);
|
||||
$("#adjust_value_after").html(
|
||||
temp.adjust_value_after);
|
||||
$("#adjust_value").html(temp.adjust_value);
|
||||
$("#adjust_delay").html(temp.delay_value);
|
||||
$("#adjust_second").html(temp.delay_second);
|
||||
},
|
||||
error : function(XMLHttpRequest, textStatus,
|
||||
errorThrown) {
|
||||
console.log("请求错误");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</s:if>
|
||||
</sec:authorize>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_CONTENT")'>
|
||||
<script type="text/javascript">
|
||||
/*5轮询读取函数*/
|
||||
setInterval(function() {
|
||||
var data = {"pageNo":$("#pageNo").val()
|
||||
,"rolename_para":$("#rolename_para").val()
|
||||
,"start_time":$("#start_time").val()
|
||||
,"end_time":$("#end_time").val()
|
||||
,"name_para":$("#name_para").val()
|
||||
,"order_no_para":$("#order_no_para").val()};
|
||||
goAjaxUrl($("#ajaxUrl").val(),data);
|
||||
}, 3000);
|
||||
function csPage(pageNo){
|
||||
$("#pageNo").val(pageNo);
|
||||
var url = $("#ajaxUrl").val();
|
||||
pageNo = Number(pageNo)<=0?1:pageNo;
|
||||
var data = {"pageNo":pageNo
|
||||
,"rolename_para":$("#rolename_para").val()
|
||||
,"start_time":$("#start_time").val()
|
||||
,"end_time":$("#end_time").val()
|
||||
,"name_para":$("#name_para").val()
|
||||
,"order_no_para":$("#order_no_para").val()};
|
||||
goAjaxUrl(url,data);
|
||||
}
|
||||
function goAjaxUrl(targetUrl,data){
|
||||
$.ajax({
|
||||
url:targetUrl,
|
||||
data:data,
|
||||
type:'get',
|
||||
success: function (res) {
|
||||
// 一旦设置的 dataType 选项,就不再关心 服务端 响应的 Content-Type 了
|
||||
// 客户端会主观认为服务端返回的就是 JSON 格式的字符串
|
||||
// console.log(res)
|
||||
// $(".loading").hide();
|
||||
$("#list_content").html(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
</body>
|
||||
</html>
|
||||
136
comm/Contract/WebContent/contract_order_list_content.jsp
Executable file
136
comm/Contract/WebContent/contract_order_list_content.jsp
Executable file
@@ -0,0 +1,136 @@
|
||||
<%@ page language="java" pageEncoding="utf-8"%>
|
||||
<%@taglib prefix="s" uri="/struts-tags"%>
|
||||
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
|
||||
<!-- <div class="col-md-12">
|
||||
Start Panel
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">查询结果</div>
|
||||
<ul class="panel-tools">
|
||||
<li><a class="icon minimise-tool"><i
|
||||
class="fa fa-minus"></i></a></li>
|
||||
<li><a class="icon expand-tool"><i class="fa fa-expand"></i></a></li>
|
||||
</ul>
|
||||
<div class="panel-body"> -->
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>用户</td>
|
||||
<td>UID</td>
|
||||
<td>账户类型</td>
|
||||
<!-- <td>订单号</td> -->
|
||||
<td>品种</td>
|
||||
<td>操作</td>
|
||||
<td>成交均价</td>
|
||||
<td>止盈止损</td>
|
||||
<td>剩余/委托金额</td>
|
||||
<td>剩余/委托保证金</td>
|
||||
<td>用户钱包余额</td>
|
||||
<td>盈亏</td>
|
||||
<td>状态</td>
|
||||
<td>创建时间</td>
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_CLOSE")'>
|
||||
<td width="130px"></td>
|
||||
</s:if>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<td><s:property value="username" /></td>
|
||||
<td><s:property value="usercode" /></td>
|
||||
<td><s:if test='rolename=="GUEST"'>
|
||||
<span class="right label label-warning">演示账号</span>
|
||||
</s:if>
|
||||
<s:if test='rolename=="MEMBER"'>
|
||||
<span class="right label label-success">正式账号</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<%-- <td><s:property value="order_no" /></td> --%>
|
||||
<td><s:property value="itemname" /></td>
|
||||
<td><s:if test='offset=="open"'>开</s:if><s:if test='offset=="close"'>平</s:if><s:if test='direction=="buy"'>多</s:if><s:if
|
||||
test='direction=="sell"'>空</s:if></td>
|
||||
<td><s:property value="trade_avg_price" /></td>
|
||||
<td><s:property value="stop_price_profit" />/<s:property value="stop_price_loss" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${volume*unit_amount}" pattern="#0.00" /></span>/<fmt:formatNumber value="${volume_open*unit_amount}" pattern="#0.00" /></td>
|
||||
<td><span class="right label label-success"><fmt:formatNumber value="${deposit}" pattern="#0.00" /></span>/<fmt:formatNumber value="${deposit_open}" pattern="#0.00" /></td>
|
||||
<td><fmt:formatNumber value="${money}" pattern="#0.00" /></td>
|
||||
<td>
|
||||
<s:if test='state=="submitted"'>
|
||||
<s:if test="(amount_close+profit+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+profit+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<s:if test="(amount_close+deposit) >=deposit_open">
|
||||
<span class="right label label-danger"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<span class="right label label-success"><fmt:formatNumber
|
||||
value="${amount_close+deposit-deposit_open}" pattern="#0.00" /> </span>
|
||||
</s:else>
|
||||
</s:else>
|
||||
</td>
|
||||
<td><s:if test='state=="submitted"'>
|
||||
持仓
|
||||
</s:if> <s:if test='state=="created"'>
|
||||
<span class="right label label-success">已平仓</span>
|
||||
</s:if>
|
||||
</td>
|
||||
<td><s:date name="createTime" format="MM-dd HH:mm:ss " /></td>
|
||||
|
||||
<s:if test='isResourceAccessible("ADMIN_CONTRACT_ORDER_CLOSE")'>
|
||||
<td>
|
||||
<s:if test='state=="submitted"'>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
|
||||
|
||||
<a href="javascript:onclose('<s:property value="order_no" />')" class="btn btn-light">平仓</a>
|
||||
|
||||
</sec:authorize>
|
||||
</s:if>
|
||||
</td>
|
||||
</s:if>
|
||||
<%-- <td>
|
||||
<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_ROOT">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-light">操作</button>
|
||||
<button type="button" class="btn btn-light dropdown-toggle"
|
||||
data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="caret"></span> <span class="sr-only">Toggle
|
||||
Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a
|
||||
href="javascript:onclose('<s:property value="order_no" />')">平仓</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</td> --%>
|
||||
|
||||
</tr>
|
||||
</s:iterator>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="pager" style="text-align: left;">
|
||||
<li><a href="javascript:csPage('1')">首页</a></li>
|
||||
<li><a href="javascript:csPage('${pageNo-1}')">上一页</a></li>
|
||||
|
||||
<li><a href="javascript:csPage('${pageNo+1}')">下一页</a></li>
|
||||
<%-- <li><a href="javascript:csPage('${1000000}')">尾页</a></li> --%>
|
||||
</ul>
|
||||
<%-- <%@ include file="include/page_simple.jsp"%> --%>
|
||||
<!-- <nav> -->
|
||||
<!-- </div>
|
||||
|
||||
</div>
|
||||
End Panel
|
||||
|
||||
</div> -->
|
||||
39
comm/Contract/config/spring/applicationContext-contract.xml
Executable file
39
comm/Contract/config/spring/applicationContext-contract.xml
Executable file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://code.alibabatech.com/schema/dubbo
|
||||
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
|
||||
|
||||
<bean id="contractOrderService"
|
||||
class="project.contract.internal.ContractOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="userDataService" ref="userDataService" />
|
||||
<property name="contractApplyOrderService"
|
||||
ref="contractApplyOrderService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
<bean id="contractApplyOrderService"
|
||||
class="project.contract.internal.ContractApplyOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="partyService" ref="partyService" />
|
||||
<property name="sysparaService" ref="sysparaService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
60
comm/Contract/config/spring/applicationContext-contract_admin.xml
Executable file
60
comm/Contract/config/spring/applicationContext-contract_admin.xml
Executable file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://code.alibabatech.com/schema/dubbo
|
||||
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
|
||||
|
||||
|
||||
<bean id="adminContractOrderService"
|
||||
class="project.contract.internal.AdminContractOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="userRecomService" ref="userRecomService" />
|
||||
</bean>
|
||||
|
||||
<bean id="adminContractApplyOrderService"
|
||||
class="project.contract.internal.AdminContractApplyOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="userRecomService" ref="userRecomService" />
|
||||
</bean>
|
||||
<bean id="adminMarketQuotationsService"
|
||||
class="project.contract.internal.AdminMarketQuotationsServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="adminItemService" ref="adminItemService" />
|
||||
<property name="adjustmentValueService" ref="adjustmentValueService" />
|
||||
<property name="dataService" ref="dataService" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="contractOrderService"
|
||||
class="project.contract.internal.ContractOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="userDataService" ref="userDataService" />
|
||||
<property name="contractApplyOrderService"
|
||||
ref="contractApplyOrderService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
<bean id="contractApplyOrderService"
|
||||
class="project.contract.internal.ContractApplyOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="partyService" ref="partyService" />
|
||||
<property name="sysparaService" ref="sysparaService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
74
comm/Contract/config/spring/applicationContext-contract_data.xml
Executable file
74
comm/Contract/config/spring/applicationContext-contract_data.xml
Executable file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://code.alibabatech.com/schema/dubbo
|
||||
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
|
||||
|
||||
<!-- init-method="init" -->
|
||||
|
||||
<bean id="contractLoadCacheService"
|
||||
class="data.loadcache.ContractLoadCacheService">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="contractOrderService"
|
||||
class="project.contract.internal.ContractOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="userDataService" ref="userDataService" />
|
||||
<property name="contractApplyOrderService"
|
||||
ref="contractApplyOrderService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
<bean id="contractApplyOrderService"
|
||||
class="project.contract.internal.ContractApplyOrderServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedQueryDao" ref="pagedDao" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
<property name="partyService" ref="partyService" />
|
||||
<property name="sysparaService" ref="sysparaService" />
|
||||
<property name="itemService" ref="itemService" />
|
||||
<property name="moneyLogService" ref="moneyLogService" />
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="contractApplyOrderHandleJob"
|
||||
class="project.contract.job.ContractApplyOrderHandleJob">
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
<property name="dataService" ref="dataService" />
|
||||
<property name="contractApplyOrderService"
|
||||
ref="contractApplyOrderService" />
|
||||
</bean>
|
||||
|
||||
<bean id="contractOrderCalculationJob"
|
||||
class="project.contract.job.ContractOrderCalculationJob">
|
||||
<property name="contractOrderCalculationService"
|
||||
ref="contractOrderCalculationService" />
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="contractOrderCalculationService"
|
||||
class="project.contract.job.ContractOrderCalculationServiceImpl">
|
||||
<property name="contractOrderService"
|
||||
ref="contractOrderService" />
|
||||
<property name="dataService" ref="dataService" />
|
||||
<property name="sysparaService" ref="sysparaService" />
|
||||
<property name="walletService" ref="walletService" />
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
15
comm/Contract/config/spring/applicationContext-hibernate.xml
Executable file
15
comm/Contract/config/spring/applicationContext-hibernate.xml
Executable file
@@ -0,0 +1,15 @@
|
||||
|
||||
admin
|
||||
|
||||
<!-- contract -->
|
||||
<value>adminContractOrderService</value>
|
||||
<value>adminContractApplyOrderService</value>
|
||||
<value>adminMarketQuotationsService</value>
|
||||
<value>contractOrderService</value>
|
||||
<value>contractApplyOrderService</value>
|
||||
|
||||
api
|
||||
<!-- contract -->
|
||||
<value>contractOrderService</value>
|
||||
<value>contractApplyOrderService</value>
|
||||
<value>contractOrderCalculationService</value>
|
||||
18
comm/Contract/config/spring/normal.xml
Executable file
18
comm/Contract/config/spring/normal.xml
Executable file
@@ -0,0 +1,18 @@
|
||||
|
||||
admin
|
||||
|
||||
<action name="adminExchangeRateAction"
|
||||
class="project.wallet.rate.web.AdminExchangeRateAction">
|
||||
<result name="list">/exchangerate_list.jsp</result>
|
||||
<result name="update">/exchangerate_update.jsp</result>
|
||||
</action>
|
||||
|
||||
api
|
||||
<action name="exchangerate"
|
||||
class="project.wallet.rate.web.ExchangeRateAction">
|
||||
</action>
|
||||
<action name="exchangerateuserconfig"
|
||||
class="project.wallet.rate.web.ExchangeRateUserConfigAction">
|
||||
</action>
|
||||
<action name="wallet" class="project.wallet.web.WalletAction">
|
||||
</action>
|
||||
60
comm/Contract/dbscript/1.1/CONTRACT-DDL-MYSQL.SQL
Executable file
60
comm/Contract/dbscript/1.1/CONTRACT-DDL-MYSQL.SQL
Executable file
@@ -0,0 +1,60 @@
|
||||
DROP TABLE IF EXISTS `T_CONTRACT_ORDER`;
|
||||
CREATE TABLE `T_CONTRACT_ORDER` (
|
||||
`UUID` varchar(32) NOT NULL COMMENT '主键',
|
||||
`PARTY_ID` varchar(32) ,
|
||||
`SYMBOL` varchar(32) COMMENT '代码',
|
||||
`ORDER_NO` varchar(64) ,
|
||||
`DIRECTION`varchar(32),
|
||||
`UNIT_AMOUNT` double ,
|
||||
`AMOUNT_CLOSE` double ,
|
||||
`FEE` double ,
|
||||
`DEPOSIT` double ,
|
||||
`DEPOSIT_OPEN` double ,
|
||||
`PROFIT` double ,
|
||||
`TRADE_AVG_PRICE` double ,
|
||||
`STOP_PRICE_PROFIT` double ,
|
||||
`STOP_PRICE_LOSS`double ,
|
||||
`CREATE_TIME` datetime ,
|
||||
`PIPS` double ,
|
||||
`PIPS_AMOUNT` double ,
|
||||
`STATE` varchar(32) ,
|
||||
`LEVER_RATE` double ,
|
||||
`VOLUME` double ,
|
||||
`VOLUME_OPEN` double ,
|
||||
PRIMARY KEY (`UUID`),
|
||||
KEY `INDEX_CONTRACT_ORDER_STATUS` (`STATE`,`CREATE_TIME`),
|
||||
KEY `INDEX_CONTRACT_ORDER_ORDER_NO` (`ORDER_NO`),
|
||||
KEY `INDEX_CONTRACT_ORDER_PARTY_ID` (`PARTY_ID`,`STATE`,`DIRECTION`,`CREATE_TIME`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
create index INDEX_CONTRACT_PARTY_ID_STATE on T_CONTRACT_ORDER (
|
||||
`PARTY_ID`,`STATE`
|
||||
);
|
||||
|
||||
alter table T_CONTRACT_ORDER add CLOSE_TIME datetime;
|
||||
alter table T_CONTRACT_ORDER add CLOSE_AVG_PRICE double;
|
||||
|
||||
DROP TABLE IF EXISTS `T_CONTRACT_APPLY_ORDER`;
|
||||
CREATE TABLE `T_CONTRACT_APPLY_ORDER` (
|
||||
`UUID` varchar(32) NOT NULL COMMENT '主键',
|
||||
`PARTY_ID` varchar(32) ,
|
||||
`SYMBOL` varchar(32) COMMENT '代码',
|
||||
`ORDER_NO` varchar(64) ,
|
||||
`DIRECTION`varchar(32),
|
||||
`OFFSET`varchar(32),
|
||||
`VOLUME` double ,
|
||||
`VOLUME_OPEN` double ,
|
||||
`LEVER_RATE` double ,
|
||||
`PRICE` double ,
|
||||
`STOP_PRICE_PROFIT` double ,
|
||||
`STOP_PRICE_LOSS`double ,
|
||||
`ORDER_PRICE_TYPE`varchar(32),
|
||||
`STATE` varchar(32) ,
|
||||
`CREATE_TIME` datetime ,
|
||||
`UNIT_AMOUNT` double ,
|
||||
`FEE` double ,
|
||||
`DEPOSIT` double ,
|
||||
PRIMARY KEY (`UUID`),
|
||||
KEY `INDEX_CONTRACT_APPLY_ORDER_STATUS` (`STATE`,`CREATE_TIME`),
|
||||
KEY `INDEX_CONTRACT_APPLY_ORDER_ORDER_NO` (`ORDER_NO`),
|
||||
KEY `INDEX_CONTRACT_APPLY_ORDER_PARTY_ID` (`PARTY_ID`,`STATE`,`DIRECTION`,`CREATE_TIME`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
25
comm/Contract/dbscript/1.1/CONTRACT-DML-MYSQL.SQL
Executable file
25
comm/Contract/dbscript/1.1/CONTRACT-DML-MYSQL.SQL
Executable file
@@ -0,0 +1,25 @@
|
||||
|
||||
INSERT INTO `SCT_RESOURCE` (`UUID`, `RES_STRING`, `RES_TYPE`)
|
||||
VALUES
|
||||
('URL_ADMIN_WITHDRAW_SUCCESS', '/normal/adminWithdrawAction!success.action*', 'URL');
|
||||
/*root管理员*/
|
||||
INSERT INTO `SCT_ROLE_RESOURCE` (`ROLE_UUID`,`RESOURCE_UUID`)
|
||||
VALUES
|
||||
('SECURITY_ROLE_ROOT', 'URL_ADMIN_WITHDRAW_SUCCESS');
|
||||
/*admin管理员*/
|
||||
INSERT INTO `SCT_ROLE_RESOURCE` (`ROLE_UUID`,`RESOURCE_UUID`)
|
||||
VALUES
|
||||
('SECURITY_ROLE_ADMIN', 'URL_ADMIN_WITHDRAW_SUCCESS');
|
||||
|
||||
|
||||
INSERT INTO `SCT_RESOURCE` (`UUID`, `RES_STRING`, `RES_TYPE`)
|
||||
VALUES
|
||||
('URL_ADMIN_WITHDRAW_REJECT', '/normal/adminWithdrawAction!reject.action*', 'URL');
|
||||
/*root管理员*/
|
||||
INSERT INTO `SCT_ROLE_RESOURCE` (`ROLE_UUID`,`RESOURCE_UUID`)
|
||||
VALUES
|
||||
('SECURITY_ROLE_ROOT', 'URL_ADMIN_WITHDRAW_REJECT');
|
||||
/*admin管理员*/
|
||||
INSERT INTO `SCT_ROLE_RESOURCE` (`ROLE_UUID`,`RESOURCE_UUID`)
|
||||
VALUES
|
||||
('SECURITY_ROLE_ADMIN', 'URL_ADMIN_WITHDRAW_REJECT');
|
||||
10
comm/Contract/src/project/contract/AdminContractApplyOrderService.java
Executable file
10
comm/Contract/src/project/contract/AdminContractApplyOrderService.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package project.contract;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminContractApplyOrderService {
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String username,String orderNo);
|
||||
|
||||
public ContractApplyOrder get(String id);
|
||||
}
|
||||
10
comm/Contract/src/project/contract/AdminContractOrderService.java
Executable file
10
comm/Contract/src/project/contract/AdminContractOrderService.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package project.contract;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminContractOrderService {
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String startTime,String endTime,String username,String orderNo);
|
||||
|
||||
public ContractOrder get(String id);
|
||||
}
|
||||
16
comm/Contract/src/project/contract/AdminMarketQuotationsService.java
Executable file
16
comm/Contract/src/project/contract/AdminMarketQuotationsService.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminMarketQuotationsService {
|
||||
|
||||
/**
|
||||
* 行情列表
|
||||
* @return
|
||||
*/
|
||||
public Page pageQuery(int pageNo,int pageSize);
|
||||
|
||||
}
|
||||
72
comm/Contract/src/project/contract/ContractApplyOrder.hbm.xml
Executable file
72
comm/Contract/src/project/contract/ContractApplyOrder.hbm.xml
Executable file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="project.contract.ContractApplyOrder" table="T_CONTRACT_APPLY_ORDER">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="partyId" type="java.lang.String">
|
||||
<column name="PARTY_ID" />
|
||||
</property>
|
||||
<property name="order_no" type="java.lang.String">
|
||||
<column name="ORDER_NO" />
|
||||
</property>
|
||||
<property name="symbol" type="java.lang.String">
|
||||
<column name="SYMBOL" />
|
||||
</property>
|
||||
<property name="direction" type="java.lang.String">
|
||||
<column name="DIRECTION" />
|
||||
</property>
|
||||
<property name="offset" type="java.lang.String">
|
||||
<column name="OFFSET" />
|
||||
</property>
|
||||
<property name="volume" type="double">
|
||||
<column name="VOLUME" />
|
||||
</property>
|
||||
<property name="volume_open" type="double">
|
||||
<column name="VOLUME_OPEN" />
|
||||
</property>
|
||||
<property name="lever_rate" type="double">
|
||||
<column name="LEVER_RATE" />
|
||||
</property>
|
||||
<property name="price" type="double">
|
||||
<column name="PRICE" />
|
||||
</property>
|
||||
<property name="stop_price_profit" type="double">
|
||||
<column name="STOP_PRICE_PROFIT" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_loss" type="double">
|
||||
<column name="STOP_PRICE_LOSS" />
|
||||
</property>
|
||||
|
||||
<property name="order_price_type" type="java.lang.String">
|
||||
<column name="ORDER_PRICE_TYPE" />
|
||||
</property>
|
||||
|
||||
<property name="state" type="java.lang.String">
|
||||
<column name="STATE" />
|
||||
</property>
|
||||
|
||||
<property name="create_time" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
|
||||
|
||||
|
||||
<property name="unit_amount" type="double">
|
||||
<column name="UNIT_AMOUNT" />
|
||||
</property>
|
||||
|
||||
<property name="fee" type="double">
|
||||
<column name="FEE" />
|
||||
</property>
|
||||
<property name="deposit" type="double">
|
||||
<column name="DEPOSIT" />
|
||||
</property>
|
||||
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
253
comm/Contract/src/project/contract/ContractApplyOrder.java
Executable file
253
comm/Contract/src/project/contract/ContractApplyOrder.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.contract;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
|
||||
/**
|
||||
* 委托单
|
||||
*/
|
||||
public class ContractApplyOrder extends EntityObject {
|
||||
|
||||
public final static String STATE_SUBMITTED = "submitted";
|
||||
public final static String STATE_CANCELED = "canceled";
|
||||
public final static String STATE_CREATED = "created";
|
||||
/**
|
||||
* 多仓
|
||||
*/
|
||||
public final static String DIRECTION_BUY = "buy";
|
||||
/**
|
||||
* 空仓
|
||||
*/
|
||||
public final static String DIRECTION_SELL = "sell";
|
||||
/**
|
||||
* 开仓
|
||||
*/
|
||||
public final static String OFFSET_OPEN = "open";
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*/
|
||||
public final static String OFFSET_CLOSE = "close";
|
||||
|
||||
/**
|
||||
* 限价单
|
||||
*/
|
||||
public final static String ORDER_PRICE_TYPE_LIMIT = "limit";
|
||||
|
||||
/**
|
||||
* 对手价(市价)
|
||||
*/
|
||||
public final static String ORDER_PRICE_TYPE_OPPONENT = "opponent";
|
||||
|
||||
private static final long serialVersionUID = 3005514385287413248L;
|
||||
|
||||
private Serializable partyId;
|
||||
|
||||
/**
|
||||
* 订单 号
|
||||
*/
|
||||
private String order_no;
|
||||
|
||||
private String symbol;
|
||||
/**
|
||||
* "buy":多 "sell":空
|
||||
*/
|
||||
private String direction;
|
||||
|
||||
/**
|
||||
* "open":开 "close":平
|
||||
*/
|
||||
private String offset;
|
||||
/**
|
||||
* 委托数量(剩余)(张)
|
||||
*/
|
||||
private Double volume;
|
||||
/**
|
||||
* 委托数量(张)
|
||||
*/
|
||||
private Double volume_open;
|
||||
/**
|
||||
* 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单]
|
||||
*/
|
||||
private Double lever_rate;
|
||||
|
||||
/**
|
||||
* limit order的交易价格
|
||||
*/
|
||||
private Double price;
|
||||
/**
|
||||
* 止盈触发价格
|
||||
*/
|
||||
private Double stop_price_profit;
|
||||
/**
|
||||
* 止损触发价格
|
||||
*/
|
||||
private Double stop_price_loss;
|
||||
/**
|
||||
* 订单报价类型。 "limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
private String order_price_type;
|
||||
/**
|
||||
* 状态。submitted 已提交,canceled 已撤销, created 委托完成
|
||||
*/
|
||||
private String state = "submitted";
|
||||
|
||||
private Date create_time;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private double fee;
|
||||
|
||||
/**
|
||||
* 保证金
|
||||
*/
|
||||
private double deposit;
|
||||
|
||||
/**
|
||||
* 每手金额
|
||||
*/
|
||||
private double unit_amount;
|
||||
|
||||
public Serializable getPartyId() {
|
||||
return partyId;
|
||||
}
|
||||
|
||||
public void setPartyId(Serializable partyId) {
|
||||
this.partyId = partyId;
|
||||
}
|
||||
|
||||
public String getOrder_no() {
|
||||
return order_no;
|
||||
}
|
||||
|
||||
public void setOrder_no(String order_no) {
|
||||
this.order_no = order_no;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public String getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(String offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Double getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(Double volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public Double getLever_rate() {
|
||||
return lever_rate;
|
||||
}
|
||||
|
||||
public void setLever_rate(Double lever_rate) {
|
||||
if (lever_rate != null && lever_rate == 1) {
|
||||
lever_rate = null;
|
||||
}
|
||||
this.lever_rate = lever_rate;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Double getStop_price_profit() {
|
||||
return stop_price_profit;
|
||||
}
|
||||
|
||||
public void setStop_price_profit(Double stop_price_profit) {
|
||||
this.stop_price_profit = stop_price_profit;
|
||||
}
|
||||
|
||||
public Double getStop_price_loss() {
|
||||
return stop_price_loss;
|
||||
}
|
||||
|
||||
public void setStop_price_loss(Double stop_price_loss) {
|
||||
this.stop_price_loss = stop_price_loss;
|
||||
}
|
||||
|
||||
public String getOrder_price_type() {
|
||||
return order_price_type;
|
||||
}
|
||||
|
||||
public void setOrder_price_type(String order_price_type) {
|
||||
this.order_price_type = order_price_type;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Date getCreate_time() {
|
||||
return create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(Date create_time) {
|
||||
this.create_time = create_time;
|
||||
}
|
||||
|
||||
public double getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(double fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public double getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(double deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public Double getVolume_open() {
|
||||
return volume_open;
|
||||
}
|
||||
|
||||
public void setVolume_open(Double volume_open) {
|
||||
this.volume_open = volume_open;
|
||||
}
|
||||
|
||||
public double getUnit_amount() {
|
||||
return unit_amount;
|
||||
}
|
||||
|
||||
public void setUnit_amount(double unit_amount) {
|
||||
this.unit_amount = unit_amount;
|
||||
}
|
||||
|
||||
}
|
||||
48
comm/Contract/src/project/contract/ContractApplyOrderService.java
Executable file
48
comm/Contract/src/project/contract/ContractApplyOrderService.java
Executable file
@@ -0,0 +1,48 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ContractApplyOrderService {
|
||||
/**
|
||||
* 创建委托单
|
||||
*/
|
||||
public void saveCreate(ContractApplyOrder order);
|
||||
|
||||
/**
|
||||
* 撤单
|
||||
*
|
||||
* @param order_no
|
||||
*/
|
||||
public void saveCancel(String partyId, String order_no);
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCancelAllByPartyId(String partyId);
|
||||
|
||||
public void update(ContractApplyOrder order);
|
||||
|
||||
public ContractApplyOrder findByOrderNo(String order_no);
|
||||
|
||||
/**
|
||||
* APP查询订单列表
|
||||
*
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param partyId
|
||||
* @param type orders 当前委托单 ,hisorders 历史委托单
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type);
|
||||
|
||||
/**
|
||||
* 所有未处理状态的委托单
|
||||
*/
|
||||
public List<ContractApplyOrder> findSubmitted();
|
||||
|
||||
public List<ContractApplyOrder> findSubmitted(String partyId, String symbol, String offset, String direction);
|
||||
|
||||
}
|
||||
22
comm/Contract/src/project/contract/ContractLock.java
Executable file
22
comm/Contract/src/project/contract/ContractLock.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ContractLock {
|
||||
private static final Set<String> filter = new HashSet<String>();
|
||||
|
||||
public static boolean add(String order_no) {
|
||||
if (!filter.add(order_no)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(String order_no) {
|
||||
filter.remove(order_no);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
82
comm/Contract/src/project/contract/ContractOrder.hbm.xml
Executable file
82
comm/Contract/src/project/contract/ContractOrder.hbm.xml
Executable file
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="project.contract.ContractOrder" table="T_CONTRACT_ORDER">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="partyId" type="java.lang.String">
|
||||
<column name="PARTY_ID" />
|
||||
</property>
|
||||
<property name="order_no" type="java.lang.String">
|
||||
<column name="ORDER_NO" />
|
||||
</property>
|
||||
<property name="symbol" type="java.lang.String">
|
||||
<column name="SYMBOL" />
|
||||
</property>
|
||||
<property name="direction" type="java.lang.String">
|
||||
<column name="DIRECTION" />
|
||||
</property>
|
||||
<property name="unit_amount" type="double">
|
||||
<column name="UNIT_AMOUNT" />
|
||||
</property>
|
||||
<property name="amount_close" type="double">
|
||||
<column name="AMOUNT_CLOSE" />
|
||||
</property>
|
||||
<property name="fee" type="double">
|
||||
<column name="FEE" />
|
||||
</property>
|
||||
<property name="deposit" type="double">
|
||||
<column name="DEPOSIT" />
|
||||
</property>
|
||||
<property name="deposit_open" type="double">
|
||||
<column name="DEPOSIT_OPEN" />
|
||||
</property>
|
||||
<property name="profit" type="double">
|
||||
<column name="PROFIT" />
|
||||
</property>
|
||||
<property name="trade_avg_price" type="double">
|
||||
<column name="TRADE_AVG_PRICE" />
|
||||
</property>
|
||||
<property name="close_avg_price" type="double">
|
||||
<column name="CLOSE_AVG_PRICE" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_profit" type="double">
|
||||
<column name="STOP_PRICE_PROFIT" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_loss" type="double">
|
||||
<column name="STOP_PRICE_LOSS" />
|
||||
</property>
|
||||
|
||||
<property name="pips" type="double">
|
||||
<column name="PIPS" />
|
||||
</property>
|
||||
|
||||
<property name="pips_amount" type="double">
|
||||
<column name="PIPS_AMOUNT" />
|
||||
</property>
|
||||
|
||||
<property name="state" type="java.lang.String">
|
||||
<column name="STATE" />
|
||||
</property>
|
||||
<property name="create_time" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
<property name="close_time" type="timestamp">
|
||||
<column name="CLOSE_TIME" />
|
||||
</property>
|
||||
<property name="lever_rate" type="double">
|
||||
<column name="LEVER_RATE" />
|
||||
</property>
|
||||
<property name="volume" type="double">
|
||||
<column name="VOLUME" />
|
||||
</property>
|
||||
<property name="volume_open" type="double">
|
||||
<column name="VOLUME_OPEN" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
316
comm/Contract/src/project/contract/ContractOrder.java
Executable file
316
comm/Contract/src/project/contract/ContractOrder.java
Executable file
@@ -0,0 +1,316 @@
|
||||
package project.contract;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
import kernel.util.Arith;
|
||||
|
||||
public class ContractOrder extends EntityObject {
|
||||
public final static String STATE_SUBMITTED = "submitted";
|
||||
public final static String STATE_CREATED = "created";
|
||||
/**
|
||||
* 多仓
|
||||
*/
|
||||
public final static String DIRECTION_BUY = "buy";
|
||||
/**
|
||||
* 空仓
|
||||
*/
|
||||
public final static String DIRECTION_SELL = "sell";
|
||||
private static final long serialVersionUID = 8847718625460348172L;
|
||||
|
||||
private Serializable partyId;
|
||||
private String symbol;
|
||||
/**
|
||||
* 订单 号
|
||||
*/
|
||||
private String order_no;
|
||||
/**
|
||||
* "buy":买(多) "sell":卖(空)
|
||||
*/
|
||||
private String direction;
|
||||
|
||||
/**
|
||||
* 每手金额
|
||||
*/
|
||||
private double unit_amount;
|
||||
|
||||
/**
|
||||
* 平仓退回金额
|
||||
*/
|
||||
private double amount_close;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private double fee;
|
||||
|
||||
/**
|
||||
* 保证金(剩余)
|
||||
*/
|
||||
private double deposit;
|
||||
|
||||
/**
|
||||
* 保证金
|
||||
*/
|
||||
private double deposit_open;
|
||||
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
private double profit;
|
||||
|
||||
/**
|
||||
* 成交均价(成本)
|
||||
*/
|
||||
private Double trade_avg_price;
|
||||
|
||||
/**
|
||||
* 平仓均价
|
||||
*/
|
||||
private Double close_avg_price;
|
||||
|
||||
/**
|
||||
* 止盈触发价格
|
||||
*/
|
||||
private Double stop_price_profit;
|
||||
/**
|
||||
* 止损触发价格
|
||||
*/
|
||||
private Double stop_price_loss;
|
||||
|
||||
/**
|
||||
* 最小浮动
|
||||
*/
|
||||
private double pips;
|
||||
/**
|
||||
* 最小浮动金额(以交易金额计算)
|
||||
*/
|
||||
private double pips_amount;
|
||||
|
||||
/**
|
||||
* 状态。submitted 已提交(持仓), created 完成(平仓)
|
||||
*/
|
||||
private String state = "submitted";
|
||||
|
||||
private Date create_time;
|
||||
/**
|
||||
* 平仓时间
|
||||
*/
|
||||
private Date close_time;
|
||||
|
||||
/**
|
||||
* 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单]
|
||||
*/
|
||||
private Double lever_rate;
|
||||
|
||||
/**
|
||||
* 涨跌幅
|
||||
*/
|
||||
private double change_ratio;
|
||||
|
||||
/**
|
||||
* 委托数量(剩余)(张)
|
||||
*/
|
||||
private Double volume;
|
||||
/**
|
||||
* 委托数量(张)
|
||||
*/
|
||||
private Double volume_open;
|
||||
|
||||
public Double getChange_ratio() {
|
||||
if (STATE_SUBMITTED.equals(state)) {
|
||||
change_ratio = Arith.div(Arith.sub(Arith.add(Arith.add(amount_close, profit), deposit), deposit_open),
|
||||
deposit_open);
|
||||
} else {
|
||||
change_ratio = Arith.div(Arith.sub(Arith.add(amount_close, deposit), deposit_open), deposit_open);
|
||||
|
||||
}
|
||||
|
||||
change_ratio = Arith.mul(change_ratio, 100);
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return Double.valueOf(df.format(change_ratio));
|
||||
}
|
||||
|
||||
public Serializable getPartyId() {
|
||||
return partyId;
|
||||
}
|
||||
|
||||
public void setPartyId(Serializable partyId) {
|
||||
this.partyId = partyId;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getOrder_no() {
|
||||
return order_no;
|
||||
}
|
||||
|
||||
public void setOrder_no(String order_no) {
|
||||
this.order_no = order_no;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public double getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(double fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public double getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(double deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public double getProfit() {
|
||||
return profit;
|
||||
}
|
||||
|
||||
public void setProfit(double profit) {
|
||||
this.profit = profit;
|
||||
}
|
||||
|
||||
public Double getTrade_avg_price() {
|
||||
return trade_avg_price;
|
||||
}
|
||||
|
||||
public void setTrade_avg_price(Double trade_avg_price) {
|
||||
this.trade_avg_price = trade_avg_price;
|
||||
}
|
||||
|
||||
public Double getStop_price_profit() {
|
||||
return stop_price_profit;
|
||||
}
|
||||
|
||||
public void setStop_price_profit(Double stop_price_profit) {
|
||||
this.stop_price_profit = stop_price_profit;
|
||||
}
|
||||
|
||||
public Double getStop_price_loss() {
|
||||
return stop_price_loss;
|
||||
}
|
||||
|
||||
public void setStop_price_loss(Double stop_price_loss) {
|
||||
this.stop_price_loss = stop_price_loss;
|
||||
}
|
||||
|
||||
public double getPips() {
|
||||
return pips;
|
||||
}
|
||||
|
||||
public void setPips(double pips) {
|
||||
this.pips = pips;
|
||||
}
|
||||
|
||||
public double getPips_amount() {
|
||||
return pips_amount;
|
||||
}
|
||||
|
||||
public void setPips_amount(double pips_amount) {
|
||||
this.pips_amount = pips_amount;
|
||||
}
|
||||
|
||||
public Date getCreate_time() {
|
||||
return create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(Date create_time) {
|
||||
this.create_time = create_time;
|
||||
}
|
||||
|
||||
public Double getLever_rate() {
|
||||
return lever_rate;
|
||||
}
|
||||
|
||||
public void setLever_rate(Double lever_rate) {
|
||||
this.lever_rate = lever_rate;
|
||||
}
|
||||
|
||||
public void setChange_ratio(double change_ratio) {
|
||||
this.change_ratio = change_ratio;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public double getAmount_close() {
|
||||
return amount_close;
|
||||
}
|
||||
|
||||
public void setAmount_close(double amount_close) {
|
||||
this.amount_close = amount_close;
|
||||
}
|
||||
|
||||
public double getDeposit_open() {
|
||||
return deposit_open;
|
||||
}
|
||||
|
||||
public void setDeposit_open(double deposit_open) {
|
||||
this.deposit_open = deposit_open;
|
||||
}
|
||||
|
||||
public double getUnit_amount() {
|
||||
return unit_amount;
|
||||
}
|
||||
|
||||
public void setUnit_amount(double unit_amount) {
|
||||
this.unit_amount = unit_amount;
|
||||
}
|
||||
|
||||
public Double getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(Double volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public Double getVolume_open() {
|
||||
return volume_open;
|
||||
}
|
||||
|
||||
public void setVolume_open(Double volume_open) {
|
||||
this.volume_open = volume_open;
|
||||
}
|
||||
|
||||
public Double getClose_avg_price() {
|
||||
return close_avg_price;
|
||||
}
|
||||
|
||||
public void setClose_avg_price(Double close_avg_price) {
|
||||
this.close_avg_price = close_avg_price;
|
||||
}
|
||||
|
||||
public Date getClose_time() {
|
||||
return close_time;
|
||||
}
|
||||
|
||||
public void setClose_time(Date close_time) {
|
||||
this.close_time = close_time;
|
||||
}
|
||||
|
||||
}
|
||||
67
comm/Contract/src/project/contract/ContractOrderService.java
Executable file
67
comm/Contract/src/project/contract/ContractOrderService.java
Executable file
@@ -0,0 +1,67 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import project.data.model.Realtime;
|
||||
|
||||
public interface ContractOrderService {
|
||||
|
||||
/**
|
||||
* 开仓
|
||||
*/
|
||||
public void saveOpen(ContractApplyOrder applyOrder, Realtime realtime);
|
||||
|
||||
/**
|
||||
* 平仓,按金额进行平仓
|
||||
*/
|
||||
public ContractApplyOrder saveClose(ContractApplyOrder applyOrder, Realtime realtime, String order_no);
|
||||
|
||||
/**
|
||||
* 平仓,按订单进行平仓
|
||||
*/
|
||||
public ContractOrder saveClose(String partyId, String order_no);
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCloseRemoveAllByPartyId(String partyId);
|
||||
|
||||
/**
|
||||
* 持仓单
|
||||
*/
|
||||
public List<ContractOrder> findSubmitted(String partyId, String symbol, String direction);
|
||||
|
||||
/**
|
||||
* 所有持仓单
|
||||
*/
|
||||
public List<ContractOrder> findSubmitted();
|
||||
|
||||
public ContractOrder findByOrderNo(String order_no);
|
||||
|
||||
public Map<String, Object> bulidOne(ContractOrder order);
|
||||
|
||||
/**
|
||||
* APP查询订单列表
|
||||
*
|
||||
* @param type orders 当前委托单 ,hisorders 历史委托单
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type);
|
||||
|
||||
public void update(ContractOrder order);
|
||||
|
||||
public boolean lock(String order_no);
|
||||
|
||||
public void unlock(String order_no);
|
||||
|
||||
/**
|
||||
* 今日订单
|
||||
*
|
||||
* @param partyId
|
||||
* @return
|
||||
*/
|
||||
public List<ContractOrder> findByPartyIdAndToday(String partyId);
|
||||
}
|
||||
30
comm/Contract/src/project/contract/ContractRedisKeys.java
Executable file
30
comm/Contract/src/project/contract/ContractRedisKeys.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package project.contract;
|
||||
|
||||
public class ContractRedisKeys {
|
||||
|
||||
/**
|
||||
* 永续合约,orderNo做key
|
||||
*/
|
||||
public final static String CONTRACT_ORDERNO = "CONTRACT_ORDERNO_";
|
||||
|
||||
/**
|
||||
* 永续合约,查询订单map,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_SUBMITTED_ORDER_PARTY_ID = "CONTRACT_SUBMITTED_ORDER_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总资产,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_PARTY_ID = "CONTRACT_ASSETS_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总保证金,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_DEPOSIT_PARTY_ID = "CONTRACT_ASSETS_DEPOSIT_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总未实现盈利,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_PROFIT_PARTY_ID = "CONTRACT_ASSETS_PROFIT_PARTY_ID_";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package project.contract.data.loadcache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractRedisKeys;
|
||||
import project.redis.RedisHandler;
|
||||
import project.wallet.AssetService;
|
||||
|
||||
public class ContractLoadCacheService extends HibernateDaoSupport {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ContractLoadCacheService.class);
|
||||
|
||||
private RedisHandler redisHandler;
|
||||
private AssetService assetService;
|
||||
|
||||
public void loadcache() {
|
||||
load();
|
||||
logger.info("完成ContractOrder数据加载redis");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder ");
|
||||
List<ContractOrder> list = (List<ContractOrder>) this.getHibernateTemplate().find(queryString.toString());
|
||||
|
||||
Map<String, Map<String, ContractOrder>> cacheMap = new ConcurrentHashMap<String, Map<String, ContractOrder>>();
|
||||
|
||||
// 永续合约:总资产、总保证金、总未实现盈利
|
||||
Map<String, Map<String, Double>> contractAssetsMap = new ConcurrentHashMap<String, Map<String, Double>>();
|
||||
|
||||
for (ContractOrder order : list) {
|
||||
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
|
||||
if (cacheMap.containsKey(order.getPartyId())) {
|
||||
Map<String, ContractOrder> map = cacheMap.get(order.getPartyId().toString());
|
||||
map.put(order.getOrder_no(), order);
|
||||
cacheMap.put(order.getPartyId().toString(), map);
|
||||
} else {
|
||||
Map<String, ContractOrder> map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
map.put(order.getOrder_no(), order);
|
||||
cacheMap.put(order.getPartyId().toString(), map);
|
||||
}
|
||||
|
||||
// 获取 单个订单 永续合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
|
||||
if (contractAssetsMap.containsKey(order.getPartyId())) {
|
||||
Map<String, Double> contractAssetsOld = contractAssetsMap.get(order.getPartyId().toString());
|
||||
if (null == contractAssetsOld) {
|
||||
contractAssetsOld = new HashMap<String, Double>();
|
||||
contractAssetsOld.put("money_contract", 0.000D);
|
||||
contractAssetsOld.put("money_contract_deposit", 0.000D);
|
||||
contractAssetsOld.put("money_contract_profit", 0.000D);
|
||||
}
|
||||
contractAssetsOld.put("money_contract", Arith.add(contractAssetsOld.get("money_contract"), contractAssetsOrder.get("money_contract")));
|
||||
contractAssetsOld.put("money_contract_deposit", Arith.add(contractAssetsOld.get("money_contract_deposit"), contractAssetsOrder.get("money_contract_deposit")));
|
||||
contractAssetsOld.put("money_contract_profit", Arith.add(contractAssetsOld.get("money_contract_profit"), contractAssetsOrder.get("money_contract_profit")));
|
||||
contractAssetsMap.put(order.getPartyId().toString(), contractAssetsOld);
|
||||
} else {
|
||||
contractAssetsMap.put(order.getPartyId().toString(), contractAssetsOrder);
|
||||
}
|
||||
}
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
}
|
||||
|
||||
for (Entry<String, Map<String, ContractOrder>> entry : cacheMap.entrySet()) {
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
for (Entry<String, Map<String, Double>> entry : contractAssetsMap.entrySet()) {
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract"));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract_deposit"));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract_profit"));
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
public void setAssetService(AssetService assetService) {
|
||||
this.assetService = assetService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.contract.AdminContractApplyOrderService;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.party.recom.UserRecomService;
|
||||
|
||||
public class AdminContractApplyOrderServiceImpl extends HibernateDaoSupport implements AdminContractApplyOrderService {
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
private UserRecomService userRecomService;
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String username,String orderNo) {
|
||||
StringBuffer queryString = new StringBuffer(
|
||||
"SELECT orders.UUID id,orders.SYMBOL symbol,orders.ORDER_NO order_no,"
|
||||
+ "orders.DIRECTION direction,orders.OFFSET offset,"
|
||||
+ "orders.VOLUME_OPEN volume_open,orders.LEVER_RATE lever_rate,"
|
||||
+ "orders.STATE state,orders.ORDER_PRICE_TYPE order_price_type,"
|
||||
+ "orders.STOP_PRICE_LOSS stop_price_loss, orders.CREATE_TIME createTime,"
|
||||
+ "orders.STOP_PRICE_PROFIT stop_price_profit,"
|
||||
+ "orders.PRICE price,item.NAME itemname,");
|
||||
|
||||
queryString.append(
|
||||
" party.USERNAME username,party.USERCODE usercode,party.ROLENAME rolename ");
|
||||
|
||||
queryString.append(
|
||||
" FROM T_CONTRACT_APPLY_ORDER orders LEFT JOIN PAT_PARTY party ON orders.PARTY_ID = party.UUID LEFT JOIN T_ITEM item ON orders.SYMBOL=item.SYMBOL WHERE 1 = 1 ");
|
||||
|
||||
Map parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(loginPartyId)) {
|
||||
List children = this.userRecomService.findChildren(loginPartyId);
|
||||
if (children.size() == 0) {
|
||||
return Page.EMPTY_PAGE;
|
||||
}
|
||||
queryString.append(" and orders.PARTY_ID in (:children) ");
|
||||
parameters.put("children", children);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(state)) {
|
||||
queryString.append(" and orders.STATE = :state ");
|
||||
parameters.put("state", state);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(rolename)) {
|
||||
queryString.append(" and party.ROLENAME = :rolename ");
|
||||
parameters.put("rolename", rolename);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(orderNo)) {
|
||||
queryString.append(" and orders.ORDER_NO = :orderNo ");
|
||||
parameters.put("orderNo", orderNo);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(username)) {
|
||||
queryString.append("AND (party.USERNAME like:username OR party.USERCODE like:username ) ");
|
||||
parameters.put("username","%"+username+"%");
|
||||
}
|
||||
queryString.append(" order by orders.CREATE_TIME desc ");
|
||||
Page page = this.pagedQueryDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public ContractApplyOrder get(String id) {
|
||||
return getHibernateTemplate().get(ContractApplyOrder.class, id);
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setUserRecomService(UserRecomService userRecomService) {
|
||||
this.userRecomService = userRecomService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.party.recom.UserRecomService;
|
||||
|
||||
public class AdminContractOrderServiceImpl extends HibernateDaoSupport implements AdminContractOrderService {
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
private UserRecomService userRecomService;
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String status, String rolename, String loginPartyId,String startTime,String endTime,String username,String orderNo) {
|
||||
StringBuffer queryString = new StringBuffer(
|
||||
"SELECT orders.UUID id,orders.SYMBOL symbol,orders.AMOUNT_CLOSE amount_close,"
|
||||
+ "orders.STOP_PRICE_PROFIT stop_price_profit,orders.STOP_PRICE_LOSS stop_price_loss,"
|
||||
+ "orders.ORDER_NO order_no,orders.TRADE_AVG_PRICE trade_avg_price,"
|
||||
+ "orders.DIRECTION direction,orders.UNIT_AMOUNT unit_amount,"
|
||||
+ "orders.STATE state,orders.FEE fee,orders.PROFIT profit,orders.CREATE_TIME createTime,"
|
||||
+ "orders.DEPOSIT deposit,orders.DEPOSIT_OPEN deposit_open,orders.CLOSE_TIME closeTime,"
|
||||
+ "orders.VOLUME_OPEN volume_open,orders.VOLUME volume,item.NAME itemname,");
|
||||
queryString.append(" wallet.MONEY money, ");
|
||||
queryString.append(" party.USERNAME username,party.USERCODE usercode,party.ROLENAME rolename ");
|
||||
|
||||
queryString.append(
|
||||
" FROM T_CONTRACT_ORDER orders LEFT JOIN PAT_PARTY party ON orders.PARTY_ID = party.UUID LEFT JOIN T_WALLET wallet ON wallet.PARTY_ID = party.UUID LEFT JOIN T_ITEM item ON orders.SYMBOL=item.SYMBOL WHERE 1 = 1 ");
|
||||
|
||||
Map parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(loginPartyId)) {
|
||||
List children = this.userRecomService.findChildren(loginPartyId);
|
||||
if (children.size() == 0) {
|
||||
return Page.EMPTY_PAGE;
|
||||
}
|
||||
queryString.append(" and orders.PARTY_ID in (:children) ");
|
||||
parameters.put("children", children);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(status)) {
|
||||
queryString.append(" and orders.STATE = :status ");
|
||||
parameters.put("status", status);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(rolename)) {
|
||||
queryString.append(" and party.ROLENAME = :rolename ");
|
||||
parameters.put("rolename", rolename);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(startTime)) {
|
||||
queryString.append(" and DATE(party.CREATE_TIME) >= DATE(:startTime) ");
|
||||
parameters.put("startTime", startTime);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(endTime)) {
|
||||
queryString.append(" and DATE(party.CREATE_TIME) <= DATE(:endTime) ");
|
||||
parameters.put("endTime", endTime);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(orderNo)) {
|
||||
queryString.append(" and orders.ORDER_NO = :orderNo ");
|
||||
parameters.put("orderNo", orderNo);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(username)) {
|
||||
queryString.append("AND (party.USERNAME like:username OR party.USERCODE like:username ) ");
|
||||
parameters.put("username","%"+username+"%");
|
||||
}
|
||||
queryString.append(" order by orders.CREATE_TIME desc ");
|
||||
Page page = this.pagedQueryDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public ContractOrder get(String id) {
|
||||
return getHibernateTemplate().get(ContractOrder.class, id);
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setUserRecomService(UserRecomService userRecomService) {
|
||||
this.userRecomService = userRecomService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.AdminMarketQuotationsService;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataCache;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.AdminItemService;
|
||||
import project.item.model.Item;
|
||||
|
||||
public class AdminMarketQuotationsServiceImpl extends HibernateDaoSupport implements AdminMarketQuotationsService{
|
||||
|
||||
private AdminItemService adminItemService;
|
||||
private DataService dataService;
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
|
||||
public Page pageQuery(int pageNo,int pageSize) {
|
||||
Page page = adminItemService.pagedQuerySymbolsByMarket(pageNo, pageSize, null);
|
||||
// Page pagedQuery = adminItemService.pagedQuery(pageNo, pageSize);
|
||||
page.setElements(this.marketQuotationslist(page.getElements()));
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 行情列表
|
||||
* @param symbols
|
||||
* @return
|
||||
*/
|
||||
private List<Map<String,Object>> marketQuotationslist(List<String> symbols) {
|
||||
if(CollectionUtils.isEmpty(symbols)) return null;
|
||||
// List<String> symbols = new LinkedList<String>();
|
||||
// for(Item i:items) {
|
||||
// symbols.add(i.getSymbol());
|
||||
// }
|
||||
List<Map<String,Object>> resultList = new LinkedList<Map<String,Object>>();
|
||||
Map<String,Object> resultMap = new HashMap<String,Object>();
|
||||
List<Realtime> realtimes = this.dataService.realtime(StringUtils.join(symbols,","));
|
||||
Set<String> symbolKey =new HashSet<String>();
|
||||
for(Realtime realtime:realtimes) {
|
||||
if(symbolKey.contains(realtime.getSymbol())) continue;
|
||||
resultMap = new HashMap<String,Object>();
|
||||
resultMap.put("symbol", realtime.getSymbol());
|
||||
resultMap.put("name", realtime.getName());
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(realtime.getSymbol());
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", 0);
|
||||
resultMap.put("new_price", new BigDecimal(String.valueOf(realtime.getClose())).toPlainString());
|
||||
} else {
|
||||
resultMap.put("adjust_value", new BigDecimal(String.valueOf(currentValue)).toPlainString());
|
||||
resultMap.put("new_price", new BigDecimal(String.valueOf(Arith.sub(realtime.getClose(), currentValue))).toPlainString());
|
||||
}
|
||||
resultMap.put("after_value", new BigDecimal(String.valueOf(realtime.getClose())).toPlainString());
|
||||
// resultMap.put("url","http://192.168.43.170:8080/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// resultMap.put("url","http://172.20.10.2:8080/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// resultMap.put("url","http://45.76.212.230:8089/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
resultMap.put("url",Constants.WEB_URL+"#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// if (currentValue == null) {
|
||||
// resultMap.put("new_price", realtime.getClose());
|
||||
// } else {
|
||||
// resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
// }
|
||||
resultList.add(resultMap);
|
||||
symbolKey.add(realtime.getSymbol());
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
public void setAdminItemService(AdminItemService adminItemService) {
|
||||
this.adminItemService = adminItemService;
|
||||
}
|
||||
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
|
||||
public void setAdjustmentValueService(AdjustmentValueService adjustmentValueService) {
|
||||
this.adjustmentValueService = adjustmentValueService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
427
comm/Contract/src/project/contract/internal/ContractApplyOrderServiceImpl.java
Executable file
427
comm/Contract/src/project/contract/internal/ContractApplyOrderServiceImpl.java
Executable file
@@ -0,0 +1,427 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.item.model.ItemLever;
|
||||
import project.log.MoneyLog;
|
||||
import project.log.MoneyLogService;
|
||||
import project.party.PartyService;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
import util.DateUtil;
|
||||
import util.RandomUtil;
|
||||
|
||||
public class ContractApplyOrderServiceImpl extends HibernateDaoSupport implements ContractApplyOrderService {
|
||||
private SysparaService sysparaService;
|
||||
private PartyService partyService;
|
||||
private ItemService itemService;
|
||||
private MoneyLogService moneyLogService;
|
||||
private WalletService walletService;
|
||||
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
@Override
|
||||
public void saveCreate(ContractApplyOrder order) {
|
||||
|
||||
if (order.getVolume_open() % 1 != 0) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
if (order.getVolume_open() <= 0) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
boolean order_open = this.sysparaService.find("order_open").getBoolean();
|
||||
if (!order_open) {
|
||||
throw new BusinessException("不在交易时段");
|
||||
}
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), true);
|
||||
if (item == null) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
if (ContractApplyOrder.OFFSET_OPEN.equals(order.getOffset())) {
|
||||
this.open(order);
|
||||
} else if (ContractApplyOrder.OFFSET_CLOSE.equals(order.getOffset())) {
|
||||
this.close(order);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 开仓委托
|
||||
*/
|
||||
public void open(ContractApplyOrder order) {
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), false);
|
||||
List<ItemLever> levers = itemService.findLever(item.getId().toString());
|
||||
|
||||
if (order.getLever_rate() != null && order.getLever_rate() != 1) {
|
||||
boolean findlevers = false;
|
||||
/**
|
||||
* 杠杆有配置
|
||||
*/
|
||||
for (int i = 0; i < levers.size(); i++) {
|
||||
if (order.getLever_rate() == levers.get(i).getLever_rate()) {
|
||||
findlevers = true;
|
||||
}
|
||||
}
|
||||
if (!findlevers) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), order.getDirection());
|
||||
for (int i = 0; i < order_state0_list.size(); i++) {
|
||||
Double source_lever_rate = order.getLever_rate();
|
||||
source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
|
||||
|
||||
Double target_lever_rate = order_state0_list.get(i).getLever_rate();
|
||||
target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
|
||||
if (source_lever_rate.compareTo(target_lever_rate) != 0) {
|
||||
throw new BusinessException("存在不同杠杆的持仓单");
|
||||
}
|
||||
// if (order.getLever_rate() != order_state0_list.get(i).getLever_rate()) {
|
||||
// throw new BusinessException("存在不同杠杆的持仓单");
|
||||
// }
|
||||
}
|
||||
List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), "open", order.getDirection());
|
||||
for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
|
||||
Double source_lever_rate = order.getLever_rate();
|
||||
source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
|
||||
|
||||
Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate();
|
||||
target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
|
||||
if (source_lever_rate.compareTo(target_lever_rate) != 0) {
|
||||
throw new BusinessException("存在不同杠杆的持仓单");
|
||||
}
|
||||
// if (order.getLever_rate() != applyOrder_submitted_list.get(i).getLever_rate()) {
|
||||
// throw new BusinessException("存在不同杠杆的委托单");
|
||||
// }
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
|
||||
order.setUnit_amount(item.getUnit_amount());
|
||||
|
||||
order.setFee(Arith.mul(item.getUnit_fee(), order.getVolume()));
|
||||
order.setDeposit(Arith.mul(item.getUnit_amount(), order.getVolume()));
|
||||
if (order.getLever_rate() != null) {
|
||||
/**
|
||||
* 加上杠杆
|
||||
*/
|
||||
order.setVolume(Arith.mul(order.getVolume(), order.getLever_rate()));
|
||||
order.setFee(Arith.mul(order.getFee(), order.getLever_rate()));
|
||||
}
|
||||
order.setVolume_open(order.getVolume());
|
||||
|
||||
order.setCreate_time(new Date());
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
if (wallet.getMoney() < Arith.add(order.getDeposit(), order.getFee())) {
|
||||
throw new BusinessException("余额不足");
|
||||
}
|
||||
|
||||
// wallet.setMoney(Arith.sub(wallet.getMoney(), order.getDeposit()));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.sub(0, order.getDeposit()));
|
||||
/*
|
||||
* 保存资金日志
|
||||
*/
|
||||
MoneyLog moneylog_deposit = new MoneyLog();
|
||||
moneylog_deposit.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog_deposit.setAmount_before(amount_before);
|
||||
moneylog_deposit.setAmount(Arith.sub(0, order.getDeposit()));
|
||||
moneylog_deposit.setAmount_after(Arith.sub(amount_before, order.getDeposit()));
|
||||
moneylog_deposit.setLog("委托单,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog_deposit.setPartyId(order.getPartyId());
|
||||
moneylog_deposit.setWallettype(Constants.WALLET);
|
||||
moneylog_deposit.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_OPEN);
|
||||
|
||||
moneyLogService.save(moneylog_deposit);
|
||||
|
||||
amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.sub(wallet.getMoney(), order.getFee()));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.sub(0, order.getFee()));
|
||||
|
||||
MoneyLog moneylog_fee = new MoneyLog();
|
||||
moneylog_fee.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog_fee.setAmount_before(amount_before);
|
||||
moneylog_fee.setAmount(Arith.sub(0, order.getFee()));
|
||||
moneylog_fee.setAmount_after(Arith.sub(amount_before, order.getFee()));
|
||||
moneylog_fee.setLog("手续费,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog_fee.setPartyId(order.getPartyId());
|
||||
moneylog_fee.setWallettype(Constants.WALLET);
|
||||
moneylog_fee.setContent_type(Constants.MONEYLOG_CONTENT_FEE);
|
||||
|
||||
moneyLogService.save(moneylog_fee);
|
||||
|
||||
getHibernateTemplate().save(order);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓委托
|
||||
*/
|
||||
public void close(ContractApplyOrder order) {
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), false);
|
||||
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
order.setCreate_time(new Date());
|
||||
order.setUnit_amount(item.getUnit_amount());
|
||||
|
||||
double volume = 0;
|
||||
List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), order.getDirection());
|
||||
for (int i = 0; i < order_state0_list.size(); i++) {
|
||||
volume = Arith.add(volume, order_state0_list.get(i).getVolume());
|
||||
}
|
||||
List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), ContractApplyOrder.OFFSET_CLOSE, order.getDirection());
|
||||
for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
|
||||
volume = Arith.sub(volume, applyOrder_submitted_list.get(i).getVolume());
|
||||
}
|
||||
|
||||
if (order.getVolume() > volume) {
|
||||
throw new BusinessException("可平仓合约张数不足");
|
||||
// throw new BusinessException("可平仓合约数量不足");
|
||||
}
|
||||
|
||||
getHibernateTemplate().save(order);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCancelAllByPartyId(String partyId) {
|
||||
List<ContractApplyOrder> findSubmittedContractApplyOrders = findSubmitted(partyId, null, null, null);
|
||||
if (!CollectionUtils.isEmpty(findSubmittedContractApplyOrders)) {
|
||||
for (ContractApplyOrder applyOrder : findSubmittedContractApplyOrders) {
|
||||
saveCancel(applyOrder.getPartyId().toString(), applyOrder.getOrder_no());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCancel(String partyId, String order_no) {
|
||||
|
||||
ContractApplyOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !"submitted".equals(order.getState()) || !partyId.equals(order.getPartyId().toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
order.setState("canceled");
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), Arith.add(order.getDeposit(), order.getFee())));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.add(order.getDeposit(), order.getFee()));
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(Arith.add(order.getDeposit(), order.getFee()));
|
||||
moneylog.setAmount_after(Arith.add(amount_before, Arith.add(order.getDeposit(), order.getFee())));
|
||||
moneylog.setLog("撤单,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CONCEL);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
update(order);
|
||||
}
|
||||
|
||||
public void update(ContractApplyOrder order) {
|
||||
this.getHibernateTemplate().update(order);
|
||||
|
||||
}
|
||||
|
||||
public ContractApplyOrder findByOrderNo(String order_no) {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractApplyOrder where order_no=?0");
|
||||
List<ContractApplyOrder> list = (List<ContractApplyOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
if (list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type) {
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractApplyOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
// Date date = DateUtils.addDay(new Date(), -1);
|
||||
|
||||
if ("orders".equals(type)) {
|
||||
// queryString.append(" and create_time >=:date");
|
||||
// parameters.put("date", date);
|
||||
queryString.append(" AND state =:state ");
|
||||
parameters.put("state", ContractApplyOrder.STATE_SUBMITTED);
|
||||
} else if ("hisorders".equals(type)) {
|
||||
// queryString.append(" and create_time <=:date");
|
||||
// parameters.put("date", date);
|
||||
queryString.append(" AND state in(:state) ");
|
||||
parameters.put("state",
|
||||
new String[] { ContractApplyOrder.STATE_CREATED, ContractApplyOrder.STATE_CANCELED });
|
||||
}
|
||||
|
||||
queryString.append(" order by create_time desc ");
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
List<Map<String, Object>> data = this.bulidData(page.getElements());
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> bulidData(List<ContractApplyOrder> list) {
|
||||
List<Map<String, Object>> data = new ArrayList();
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractApplyOrder order = list.get(i);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("offset", order.getOffset());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("price", order.getPrice());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("order_price_type", order.getOrder_price_type());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
|
||||
data.add(map);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContractApplyOrder> findSubmitted() {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractApplyOrder where state=?0");
|
||||
return (List<ContractApplyOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { "submitted" });
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 未处理状态的委托单
|
||||
*/
|
||||
public List<ContractApplyOrder> findSubmitted(String partyId, String symbol, String offset, String direction) {
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractApplyOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(offset)) {
|
||||
queryString.append(" and offset =:offset ");
|
||||
parameters.put("offset", offset);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(direction)) {
|
||||
queryString.append(" and direction =:direction ");
|
||||
parameters.put("direction", direction);
|
||||
}
|
||||
|
||||
queryString.append(" and state =:state ");
|
||||
parameters.put("state", "submitted");
|
||||
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(0, Integer.MAX_VALUE, queryString.toString(), parameters);
|
||||
return page.getElements();
|
||||
|
||||
}
|
||||
|
||||
public void setSysparaService(SysparaService sysparaService) {
|
||||
this.sysparaService = sysparaService;
|
||||
}
|
||||
|
||||
public void setPartyService(PartyService partyService) {
|
||||
this.partyService = partyService;
|
||||
}
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public void setMoneyLogService(MoneyLogService moneyLogService) {
|
||||
this.moneyLogService = moneyLogService;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
}
|
||||
637
comm/Contract/src/project/contract/internal/ContractOrderServiceImpl.java
Executable file
637
comm/Contract/src/project/contract/internal/ContractOrderServiceImpl.java
Executable file
@@ -0,0 +1,637 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.contract.ContractRedisKeys;
|
||||
import project.data.model.Realtime;
|
||||
import project.follow.Trader;
|
||||
import project.follow.TraderFollowUserOrder;
|
||||
import project.follow.TraderFollowUserOrderService;
|
||||
import project.follow.TraderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.MoneyLog;
|
||||
import project.log.MoneyLogService;
|
||||
import project.party.PartyService;
|
||||
import project.party.model.Party;
|
||||
import project.redis.RedisHandler;
|
||||
import project.tip.TipConstants;
|
||||
import project.tip.TipService;
|
||||
import project.user.UserDataService;
|
||||
import project.wallet.AssetService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
import util.DateUtil;
|
||||
import util.RandomUtil;
|
||||
|
||||
public class ContractOrderServiceImpl extends HibernateDaoSupport implements ContractOrderService {
|
||||
protected PagedQueryDao pagedQueryDao;
|
||||
protected WalletService walletService;
|
||||
protected UserDataService userDataService;
|
||||
|
||||
protected ItemService itemService;
|
||||
protected MoneyLogService moneyLogService;
|
||||
|
||||
protected ContractApplyOrderService contractApplyOrderService;
|
||||
|
||||
protected RedisHandler redisHandler;
|
||||
|
||||
protected TraderService traderService;
|
||||
protected TraderFollowUserOrderService traderFollowUserOrderService;
|
||||
|
||||
protected PartyService partyService;
|
||||
|
||||
protected TipService tipService;
|
||||
|
||||
protected AssetService assetService;
|
||||
|
||||
public void saveOpen(ContractApplyOrder applyOrder, Realtime realtime) {
|
||||
Item item = this.itemService.cacheBySymbol(applyOrder.getSymbol(), false);
|
||||
|
||||
ContractOrder order = new ContractOrder();
|
||||
order.setPartyId(applyOrder.getPartyId());
|
||||
order.setSymbol(applyOrder.getSymbol());
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
order.setDirection(applyOrder.getDirection());
|
||||
order.setLever_rate(applyOrder.getLever_rate());
|
||||
order.setVolume(applyOrder.getVolume());
|
||||
order.setVolume_open(applyOrder.getVolume_open());
|
||||
order.setUnit_amount(applyOrder.getUnit_amount());
|
||||
order.setFee(applyOrder.getFee());
|
||||
order.setDeposit(applyOrder.getDeposit());
|
||||
order.setDeposit_open(applyOrder.getDeposit());
|
||||
|
||||
order.setTrade_avg_price(realtime.getClose());
|
||||
order.setStop_price_profit(applyOrder.getStop_price_profit());
|
||||
order.setStop_price_loss(applyOrder.getStop_price_loss());
|
||||
|
||||
order.setPips(item.getPips());
|
||||
order.setPips_amount(item.getPips_amount());
|
||||
|
||||
order.setCreate_time(new Date());
|
||||
|
||||
this.getHibernateTemplate().save(order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
if (map == null) {
|
||||
map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
}
|
||||
map.put(order.getOrder_no(), order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, contractAssetsOrder.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, contractAssetsOrder.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, contractAssetsOrder.get("money_contract_profit")));
|
||||
|
||||
/**
|
||||
* 进入市场
|
||||
*/
|
||||
applyOrder.setVolume(0D);
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
|
||||
this.contractApplyOrderService.update(applyOrder);
|
||||
|
||||
/**
|
||||
* 如果是跟单订单,将持仓订单号也存入数据表
|
||||
*/
|
||||
/**
|
||||
* 交易员带单
|
||||
*/
|
||||
Trader trader = traderService.findByPartyId(applyOrder.getPartyId().toString());
|
||||
if (trader != null) {
|
||||
this.traderFollowUserOrderService.traderOpen(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否是跟单订单,如果是需要将TraderFollowUserOrder里的用户委托单号修改成用户持仓单号
|
||||
*
|
||||
*/
|
||||
TraderFollowUserOrder traderFollowUserOrder = this.traderFollowUserOrderService
|
||||
.findByPartyIdAndOrderNo(applyOrder.getPartyId().toString(), applyOrder.getOrder_no());
|
||||
if (traderFollowUserOrder != null) {
|
||||
traderFollowUserOrder.setUser_order_no(order.getOrder_no());
|
||||
this.traderFollowUserOrderService.update(traderFollowUserOrder);
|
||||
}
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRolename())) {
|
||||
tipService.saveTip(order.getId().toString(), TipConstants.CONTRACT_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
public ContractApplyOrder saveClose(ContractApplyOrder applyOrder, Realtime realtime, String order_no) {
|
||||
ContractOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState()) || order.getVolume() <= 0) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return applyOrder;
|
||||
}
|
||||
double volume;
|
||||
if (applyOrder.getVolume() > order.getVolume()) {
|
||||
volume = order.getVolume();
|
||||
} else {
|
||||
volume = applyOrder.getVolume();
|
||||
}
|
||||
/**
|
||||
* 平仓退回的金额
|
||||
*/
|
||||
double profit = this.settle(order, volume);
|
||||
update(order);
|
||||
// if (profit > 0) {
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), profit));/
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
|
||||
this.walletService.update(wallet.getPartyId().toString(), profit);
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(profit);
|
||||
moneylog.setAmount_after(Arith.add(amount_before, profit));
|
||||
moneylog.setLog("平仓,平仓合约数[" + volume + "],订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CLOSE);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
// }
|
||||
applyOrder.setVolume(Arith.sub(applyOrder.getVolume(), volume));
|
||||
if (applyOrder.getVolume() <= 0) {
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
}
|
||||
contractApplyOrderService.update(applyOrder);
|
||||
|
||||
/**
|
||||
* 交易员带单,用户跟单
|
||||
*/
|
||||
this.traderFollowUserOrderService.traderClose(order);
|
||||
|
||||
return applyOrder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCloseRemoveAllByPartyId(String partyId) {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where partyId=?0");
|
||||
List<ContractOrder> orders = (List<ContractOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { partyId });
|
||||
List<ContractOrder> findSubmittedContractOrders = findSubmitted(partyId, null, null);
|
||||
if (!CollectionUtils.isEmpty(findSubmittedContractOrders)) {
|
||||
for (ContractOrder order : orders) {
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
}
|
||||
redisHandler.remove(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no());
|
||||
}
|
||||
redisHandler.remove(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + partyId);
|
||||
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + partyId);
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + partyId);
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + partyId);
|
||||
}
|
||||
}
|
||||
|
||||
public ContractOrder saveClose(String partyId, String order_no) {
|
||||
/*
|
||||
* 平仓
|
||||
*/
|
||||
ContractOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState())
|
||||
|| !partyId.equals(order.getPartyId().toString()) || order.getVolume() <= 0) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
double volume = order.getVolume();
|
||||
double profit = this.settle(order, order.getVolume());
|
||||
|
||||
// if (profit > 0) {
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), profit));
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
|
||||
// this.walletService.update(wallet);
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
this.walletService.update(wallet.getPartyId().toString(), profit);
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(profit);
|
||||
moneylog.setAmount_after(Arith.add(amount_before, profit));
|
||||
moneylog.setLog("平仓,平仓合约数[" + volume + "],订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CLOSE);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
// }
|
||||
|
||||
order.setState(ContractOrder.STATE_CREATED);
|
||||
order.setVolume(0D);
|
||||
order.setDeposit(0);
|
||||
order.setClose_time(new Date());
|
||||
update(order);
|
||||
|
||||
// this.userDataService.saveClose(order);
|
||||
|
||||
/**
|
||||
* 交易员带单,用户跟单
|
||||
*/
|
||||
this.traderFollowUserOrderService.traderClose(order);
|
||||
|
||||
/**
|
||||
* 合约产品平仓后添加当前流水
|
||||
*/
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
party.setWithdraw_limit_now_amount(Arith.add(party.getWithdraw_limit_now_amount(), order.getDeposit_open()));
|
||||
partyService.update(party);
|
||||
|
||||
return order;
|
||||
|
||||
}
|
||||
|
||||
public void update(ContractOrder order) {
|
||||
// this.getHibernateTemplate().update(order);
|
||||
this.getHibernateTemplate().merge(order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
if (null == map) {
|
||||
map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
}
|
||||
|
||||
ContractOrder orderOld = map.get(order.getOrder_no());
|
||||
|
||||
map.put(order.getOrder_no(), order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
Map<String, Double> contractAssetsOrderOld = this.assetService.getMoneyContractByOrder(orderOld);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, contractAssetsOrder.get("money_contract") - contractAssetsOrderOld.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, contractAssetsOrder.get("money_contract_deposit") - contractAssetsOrderOld.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, contractAssetsOrder.get("money_contract_profit") - contractAssetsOrderOld.get("money_contract_profit")));
|
||||
|
||||
} else if (ContractOrder.STATE_CREATED.equals(order.getState())) {
|
||||
// 平仓后,移除持仓列表
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
ContractOrder orderOld = null;
|
||||
if (map != null && !map.isEmpty()) {
|
||||
orderOld = map.get(order.getOrder_no());
|
||||
map.remove(order.getOrder_no());
|
||||
}
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrderOld = this.assetService.getMoneyContractByOrder(orderOld);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, 0.000D - contractAssetsOrderOld.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, 0.000D - contractAssetsOrderOld.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, 0.000D - contractAssetsOrderOld.get("money_contract_profit")));
|
||||
|
||||
// 平仓则纪录数据(委托平仓,订单直接平仓)
|
||||
this.userDataService.saveClose(order);
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRolename())) {
|
||||
tipService.deleteTip(order.getId().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益结算,平仓时计算
|
||||
*
|
||||
* @param closevolume 平仓的张数
|
||||
*/
|
||||
public double settle(ContractOrder order, double volume) {
|
||||
double profit = 0;
|
||||
/**
|
||||
* 平仓比率
|
||||
*/
|
||||
double rate = Arith.div(volume, order.getVolume_open());
|
||||
|
||||
profit = Arith.mul(Arith.add(order.getDeposit(), order.getProfit()), rate);
|
||||
|
||||
order.setAmount_close(Arith.add(order.getAmount_close(), profit));
|
||||
|
||||
order.setVolume(Arith.sub(order.getVolume(), volume));
|
||||
order.setDeposit(Arith.sub(order.getDeposit(), Arith.mul(order.getDeposit_open(), rate)));
|
||||
|
||||
if (order.getVolume() <= 0) {
|
||||
order.setState(ContractOrder.STATE_CREATED);
|
||||
order.setClose_time(new Date());
|
||||
}
|
||||
|
||||
return profit;
|
||||
|
||||
}
|
||||
|
||||
public ContractOrder findByOrderNo(String order_no) {
|
||||
|
||||
// return (ContractOrder) redisHandler.get(ContractRedisKeys.CONTRACT_ORDERNO + order_no);
|
||||
//// StringBuffer queryString = new StringBuffer(" FROM ContractOrder where order_no=?");
|
||||
//// List<ContractOrder> list = getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
//// if (list.size() > 0) {
|
||||
//// return list.get(0);
|
||||
//// }
|
||||
//// return null;
|
||||
|
||||
ContractOrder order = (ContractOrder) this.redisHandler.get(ContractRedisKeys.CONTRACT_ORDERNO + order_no);
|
||||
if (null != order) {
|
||||
return order;
|
||||
}
|
||||
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where order_no=?0");
|
||||
List<ContractOrder> list = (List<ContractOrder>) this.getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
if (list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ContractOrder> findSubmitted(String partyId, String symbol, String direction) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {// 如果有partyId,走缓存查询
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + partyId);
|
||||
List<ContractOrder> list = new ArrayList<ContractOrder>();
|
||||
if (map != null && !map.isEmpty()) {
|
||||
for (ContractOrder order : map.values()) {
|
||||
boolean valify = true;// 验证
|
||||
if (valify && !StringUtils.isNullOrEmpty(symbol)) {// 币种是否相同
|
||||
valify = symbol.equals(order.getSymbol());
|
||||
}
|
||||
if (valify && !StringUtils.isNullOrEmpty(direction)) {
|
||||
valify = direction.equals(order.getDirection());
|
||||
}
|
||||
if (valify) {// 条件全部满足,添加
|
||||
list.add(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(direction)) {
|
||||
queryString.append(" and direction =:direction ");
|
||||
parameters.put("direction", direction);
|
||||
}
|
||||
|
||||
queryString.append(" and state =:state ");
|
||||
parameters.put("state", "submitted");
|
||||
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(0, Integer.MAX_VALUE, queryString.toString(), parameters);
|
||||
return page.getElements();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type) {
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
|
||||
Date date = DateUtils.addDay(new Date(), -1);
|
||||
|
||||
if ("orders".equals(type)) {
|
||||
queryString.append(" and state =:state");
|
||||
parameters.put("state", "submitted");
|
||||
} else if ("hisorders".equals(type)) {
|
||||
queryString.append(" and state =:state");
|
||||
parameters.put("state", "created");
|
||||
}
|
||||
|
||||
queryString.append(" order by create_time desc ");
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
List<Map<String, Object>> data = this.bulidData(page.getElements());
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> bulidData(List<ContractOrder> list) {
|
||||
List<Map<String, Object>> data = new ArrayList();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
Map<String, Object> map = bulidOne(order);
|
||||
data.add(map);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Map<String, Object> bulidOne(ContractOrder order) {
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
if (order.getClose_time() != null) {
|
||||
map.put("close_time", DateUtils.format(order.getClose_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
} else {
|
||||
map.put("close_time", "");
|
||||
}
|
||||
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("trade_avg_price", order.getTrade_avg_price());
|
||||
map.put("close_avg_price", order.getClose_avg_price());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
map.put("deposit_open", order.getDeposit_open());
|
||||
map.put("change_ratio", order.getChange_ratio());
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
map.put("profit",
|
||||
df.format(Arith.sub(
|
||||
Arith.add(Arith.add(order.getAmount_close(), order.getProfit()), order.getDeposit()),
|
||||
order.getDeposit_open())));
|
||||
} else {
|
||||
map.put("profit", df.format(
|
||||
Arith.sub(Arith.add(order.getAmount_close(), order.getDeposit()), order.getDeposit_open())));
|
||||
}
|
||||
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContractOrder> findSubmitted() {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where state=?0");
|
||||
return (List<ContractOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { ContractOrder.STATE_SUBMITTED });
|
||||
}
|
||||
|
||||
public List<ContractOrder> findByPartyIdAndToday(String partyId) {
|
||||
List<ContractOrder> list = (List<ContractOrder>) getHibernateTemplate().find(
|
||||
" FROM ContractOrder WHERE partyId=?0 and DateDiff(create_time,NOW())=0 ", new Object[] { partyId });
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setUserDataService(UserDataService userDataService) {
|
||||
this.userDataService = userDataService;
|
||||
}
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public void setMoneyLogService(MoneyLogService moneyLogService) {
|
||||
this.moneyLogService = moneyLogService;
|
||||
}
|
||||
|
||||
public void setContractApplyOrderService(ContractApplyOrderService contractApplyOrderService) {
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lock(String order_no) {
|
||||
return ContractLock.add(order_no);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock(String order_no) {
|
||||
ContractLock.remove(order_no);
|
||||
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
public void setTraderService(TraderService traderService) {
|
||||
this.traderService = traderService;
|
||||
}
|
||||
|
||||
public void setTraderFollowUserOrderService(TraderFollowUserOrderService traderFollowUserOrderService) {
|
||||
this.traderFollowUserOrderService = traderFollowUserOrderService;
|
||||
}
|
||||
|
||||
public void setPartyService(PartyService partyService) {
|
||||
this.partyService = partyService;
|
||||
}
|
||||
|
||||
public void setTipService(TipService tipService) {
|
||||
this.tipService = tipService;
|
||||
}
|
||||
|
||||
public void setAssetService(AssetService assetService) {
|
||||
this.assetService = assetService;
|
||||
}
|
||||
|
||||
}
|
||||
163
comm/Contract/src/project/contract/job/ContractApplyOrderHandleJob.java
Executable file
163
comm/Contract/src/project/contract/job/ContractApplyOrderHandleJob.java
Executable file
@@ -0,0 +1,163 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
|
||||
/**
|
||||
*
|
||||
* 委托单进入市场
|
||||
*/
|
||||
public class ContractApplyOrderHandleJob implements Runnable {
|
||||
private static Log logger = LogFactory.getLog(ContractApplyOrderHandleJob.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
private DataService dataService;
|
||||
|
||||
public void run() {
|
||||
/*
|
||||
* 系统启动先暂停30秒
|
||||
*/
|
||||
ThreadUtils.sleep(1000 * 30);
|
||||
while (true)
|
||||
try {
|
||||
List<ContractApplyOrder> list = this.contractApplyOrderService.findSubmitted();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractApplyOrder order = list.get(i);
|
||||
List<Realtime> realtime_list = this.dataService.realtime(order.getSymbol());
|
||||
Realtime realtime = null;
|
||||
if (realtime_list.size() > 0) {
|
||||
realtime = realtime_list.get(0);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("limit".equals(order.getOrder_price_type())) {
|
||||
/**
|
||||
* 限价单
|
||||
*/
|
||||
if ("buy".equals(order.getDirection())) {
|
||||
/**
|
||||
* 买涨
|
||||
*/
|
||||
if (realtime.getClose() <= order.getPrice()) {
|
||||
|
||||
this.handle(order, realtime);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
if (realtime.getClose() >= order.getPrice()) {
|
||||
this.handle(order, realtime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* 非限制,直接进入市 场
|
||||
*/
|
||||
this.handle(order, realtime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("run fail", e);
|
||||
} finally {
|
||||
ThreadUtils.sleep(1000 * 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void handle(ContractApplyOrder applyOrder, Realtime realtime) {
|
||||
boolean lock = false;
|
||||
try {
|
||||
if (!ContractLock.add(applyOrder.getOrder_no())) {
|
||||
return;
|
||||
}
|
||||
lock = true;
|
||||
if ("open".equals(applyOrder.getOffset())) {
|
||||
this.contractOrderService.saveOpen(applyOrder, realtime);
|
||||
} else if ("close".equals(applyOrder.getOffset())) {
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*/
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted(applyOrder.getPartyId().toString(),
|
||||
applyOrder.getSymbol(), applyOrder.getDirection());
|
||||
if (list.size() == 0) {
|
||||
applyOrder.setVolume(0D);
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
this.contractApplyOrderService.update(applyOrder);
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
boolean lock_order = false;
|
||||
try {
|
||||
if (!ContractLock.add(order.getOrder_no())) {
|
||||
continue;
|
||||
}
|
||||
lock_order = true;
|
||||
applyOrder = this.contractOrderService.saveClose(applyOrder, realtime, order.getOrder_no());
|
||||
|
||||
if (ContractApplyOrder.STATE_CREATED.equals(applyOrder.getState())) {
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock_order) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(order.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(applyOrder.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void start(){
|
||||
new Thread(this, "ContractApplyOrderHandleJob").start();
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("委托单处理线程启动!");
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setContractApplyOrderService(ContractApplyOrderService contractApplyOrderService) {
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
}
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
}
|
||||
78
comm/Contract/src/project/contract/job/ContractOrderCalculationJob.java
Executable file
78
comm/Contract/src/project/contract/job/ContractOrderCalculationJob.java
Executable file
@@ -0,0 +1,78 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
|
||||
public class ContractOrderCalculationJob implements Runnable {
|
||||
private static Log logger = LogFactory.getLog(ContractOrderCalculationJob.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private ContractOrderCalculationService contractOrderCalculationService;
|
||||
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
|
||||
boolean lock = false;
|
||||
try {
|
||||
if (!ContractLock.add(order.getOrder_no())) {
|
||||
continue;
|
||||
}
|
||||
lock = true;
|
||||
this.contractOrderCalculationService.saveCalculation(order.getOrder_no());
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock) {
|
||||
/**
|
||||
* 每秒处理20个订单
|
||||
*/
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(order.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
logger.error("run fail", e);
|
||||
} finally {
|
||||
/**
|
||||
* 暂停0.1秒
|
||||
*/
|
||||
ThreadUtils.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start(){
|
||||
|
||||
new Thread(this, "ContractOrderCalculationJob").start();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("持仓单盈亏计算线程启动!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setContractOrderCalculationService(ContractOrderCalculationService contractOrderCalculationService) {
|
||||
this.contractOrderCalculationService = contractOrderCalculationService;
|
||||
}
|
||||
|
||||
}
|
||||
17
comm/Contract/src/project/contract/job/ContractOrderCalculationService.java
Executable file
17
comm/Contract/src/project/contract/job/ContractOrderCalculationService.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package project.contract.job;
|
||||
|
||||
/**
|
||||
* 合约盈亏计算
|
||||
*/
|
||||
public interface ContractOrderCalculationService {
|
||||
|
||||
/*
|
||||
* 订单盈亏计算
|
||||
*/
|
||||
public void saveCalculation(String order_no);
|
||||
|
||||
public void setOrder_close_line(double order_close_line);
|
||||
|
||||
public void setOrder_close_line_type(int order_close_line_type);
|
||||
|
||||
}
|
||||
253
comm/Contract/src/project/contract/job/ContractOrderCalculationServiceImpl.java
Executable file
253
comm/Contract/src/project/contract/job/ContractOrderCalculationServiceImpl.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
|
||||
public class ContractOrderCalculationServiceImpl implements ContractOrderCalculationService {
|
||||
private static Log logger = LogFactory.getLog(ContractOrderCalculationServiceImpl.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private DataService dataService;
|
||||
private WalletService walletService;
|
||||
/**
|
||||
* 平仓线 110%(订金价值 /收益=110%)
|
||||
*/
|
||||
public double order_close_line = 1.1;
|
||||
/**
|
||||
* 平仓方式 1全仓 2单个持仓
|
||||
*/
|
||||
public int order_close_line_type = 1;
|
||||
private SysparaService sysparaService;
|
||||
|
||||
public void saveCalculation(String order_no) {
|
||||
|
||||
try {
|
||||
ContractOrder order = contractOrderService.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return;
|
||||
}
|
||||
List<Realtime> list = this.dataService.realtime(order.getSymbol());
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Realtime realtime = list.get(0);
|
||||
|
||||
double close = realtime.getClose();
|
||||
|
||||
if (ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 0 买涨
|
||||
*/
|
||||
if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "profit", close);
|
||||
}
|
||||
|
||||
if (close <= Arith.sub(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "loss", close);
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* 1 买跌
|
||||
*/
|
||||
if (close <= Arith.sub(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "profit", close);
|
||||
}
|
||||
if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "loss", close);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("OrderCalculationServiceImpll run fail", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 盈亏计算
|
||||
*
|
||||
* @param profit_loss profit 盈 loss亏
|
||||
* @param currentPrice 当前点位
|
||||
*/
|
||||
public void settle(ContractOrder order, String profit_loss, double currentPrice) {
|
||||
|
||||
/**
|
||||
* 偏差点位
|
||||
*/
|
||||
double point = Arith.div(Math.abs(Arith.sub(currentPrice, order.getTrade_avg_price())), order.getPips());
|
||||
|
||||
/*
|
||||
* 根据偏 差点数和手数算出盈亏金额
|
||||
*/
|
||||
double amount = Arith.mul(Arith.mul(order.getPips_amount(), point), order.getVolume());
|
||||
|
||||
if ("profit".equals(profit_loss)) {
|
||||
/**
|
||||
* 盈 正数
|
||||
*/
|
||||
order.setProfit(Arith.add(0.0D, amount));
|
||||
} else if ("loss".equals(profit_loss)) {
|
||||
order.setProfit(Arith.sub(0.0D, amount));
|
||||
}
|
||||
/**
|
||||
* 多次平仓价格不对,后续修
|
||||
*/
|
||||
order.setClose_avg_price(currentPrice);
|
||||
this.contractOrderService.update(order);
|
||||
/**
|
||||
* 止盈价
|
||||
*/
|
||||
Double profit_stop = order.getStop_price_profit();
|
||||
if (profit_stop != null && profit_stop > 0 && ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 买涨
|
||||
*/
|
||||
if (currentPrice >= profit_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
} else if (profit_stop != null && profit_stop > 0
|
||||
&& ContractOrder.DIRECTION_SELL.equals(order.getDirection())) {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
if (currentPrice <= profit_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 止亏线
|
||||
*/
|
||||
Double loss_stop = order.getStop_price_loss();
|
||||
|
||||
if (loss_stop != null && loss_stop > 0 && ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 买涨
|
||||
*/
|
||||
if (currentPrice <= loss_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
|
||||
}
|
||||
} else if (loss_stop != null && loss_stop > 0 && ContractOrder.DIRECTION_SELL.equals(order.getDirection())) {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
|
||||
if (currentPrice >= loss_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (order_close_line_type == 1) {
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
double profit = 0;
|
||||
|
||||
List<ContractOrder> list = contractOrderService.findSubmitted(order.getPartyId().toString(), null, null);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder close_line = list.get(i);
|
||||
profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
|
||||
}
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId().toString());
|
||||
|
||||
if (Arith.add(profit, wallet.getMoney()) <= 0) {
|
||||
/**
|
||||
* 触发全仓强平
|
||||
*/
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
ThreadUtils.sleep(100);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder close_line = list.get(i);
|
||||
if (!order.getOrder_no().equals(close_line.getOrder_no())) {
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (ContractLock.add(close_line.getOrder_no())) {
|
||||
this.contractOrderService.saveClose(close_line.getPartyId().toString(),
|
||||
close_line.getOrder_no());
|
||||
/**
|
||||
* 处理完退出
|
||||
*/
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
ContractLock.remove(close_line.getOrder_no());
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (order.getProfit() < 0 && (Arith.div(order.getDeposit(), Math.abs(order.getProfit())) <= Arith
|
||||
.div(order_close_line, 100))) {
|
||||
/**
|
||||
* 低于系统默认平仓线,进行强平
|
||||
*/
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void afterPropertiesSet() throws Exception {
|
||||
// order_close_line = this.sysparaService.find("order_close_line").getDouble();
|
||||
// order_close_line_type = this.sysparaService.find("order_close_line_type").getInteger();
|
||||
//
|
||||
// }
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
public void setSysparaService(SysparaService sysparaService) {
|
||||
this.sysparaService = sysparaService;
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setOrder_close_line(double order_close_line) {
|
||||
this.order_close_line = order_close_line;
|
||||
}
|
||||
|
||||
public void setOrder_close_line_type(int order_close_line_type) {
|
||||
this.order_close_line_type = order_close_line_type;
|
||||
}
|
||||
|
||||
}
|
||||
128
comm/Contract/src/project/web/admin/AdminContractApplyOrderController.java
Executable file
128
comm/Contract/src/project/web/admin/AdminContractApplyOrderController.java
Executable file
@@ -0,0 +1,128 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractApplyOrderService;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
|
||||
/**
|
||||
* 永续合约委托
|
||||
*/
|
||||
@RestController
|
||||
public class AdminContractApplyOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminContractApplyOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractApplyOrderService adminContractApplyOrderService;
|
||||
@Autowired
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
|
||||
private final String action = "normal/adminContractApplyOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续合约委托列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String status_para = request.getParameter("status_para");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_apply_order_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
|
||||
this.page = this.adminContractApplyOrderService.pagedQuery(this.pageNo, this.pageSize, status_para,
|
||||
rolename_para, loginPartyId, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("status_para", status_para);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractApplyOrder order = this.contractApplyOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
this.contractApplyOrderService.saveCancel(order.getPartyId().toString(), order_no);
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
}
|
||||
557
comm/Contract/src/project/web/admin/AdminContractOrderController.java
Executable file
557
comm/Contract/src/project/web/admin/AdminContractOrderController.java
Executable file
@@ -0,0 +1,557 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.Log;
|
||||
import project.log.LogService;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
/**
|
||||
* 永续持仓单 当前单
|
||||
*/
|
||||
@RestController
|
||||
public class AdminContractOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractOrderService adminContractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
@Autowired
|
||||
private SecUserService secUserService;
|
||||
|
||||
private final String action = "normal/adminContractOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续合约持仓单列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, ContractOrder.STATE_SUBMITTED,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
List<Item> items = this.itemService.cacheGetAll();
|
||||
Item item_turn = null;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
item_turn = items.get(i);
|
||||
|
||||
if ("knc".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(1);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(1);
|
||||
items.add(1, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("abcoin".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(0);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(0);
|
||||
items.add(0, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("oxtrx".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(0);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(0);
|
||||
items.add(0, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> symbols = new LinkedHashMap<String, String>();
|
||||
for (Item item : items) {
|
||||
symbols.put(item.getSymbol(), item.getName());
|
||||
}
|
||||
|
||||
modelAndView.addObject("symbols", symbols);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 永续合约持仓单列表内容
|
||||
*/
|
||||
@RequestMapping(action + "content.action")
|
||||
public ModelAndView content(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_list_content");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = getLoginPartyId();
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, ContractOrder.STATE_SUBMITTED,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示 调整页面
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整 页面计算
|
||||
*
|
||||
* type 0增加一个pips;1减少一个pips;2直接修改调整值;
|
||||
* value 调整值
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
String value = request.getParameter("value");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
String error = this.verif(type, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
int type_int = Integer.valueOf(request.getParameter("type")).intValue();
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
|
||||
if (0 == type_int) {
|
||||
temp = Arith.add(value_double, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (1 == type_int) {
|
||||
temp = Arith.sub(value_double, item.getPips());
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value_double;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*
|
||||
* value 调整值
|
||||
* second 延迟秒
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String value = request.getParameter("value");
|
||||
String second = request.getParameter("second");
|
||||
String username_login = request.getParameter("username_login");
|
||||
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verifAdjust(second, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double value_double = Double.valueOf(request.getParameter("value"));
|
||||
double second_double = Double.valueOf(request.getParameter("second"));
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
currentValue = realtime.getClose();
|
||||
}
|
||||
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
|
||||
String log = MessageFormat.format("ip:" + this.getIp() + ",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}", symbol,
|
||||
new BigDecimal(currentValue).toPlainString(), new BigDecimal(value_double).toPlainString(), second_double);
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, value_double, second_double);
|
||||
|
||||
saveLog(sec, username_login, log);
|
||||
ThreadUtils.sleep(1000);
|
||||
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(order.getPartyId().toString(), order_no, this.contractOrderService);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
public void saveLog(SecUser secUser, String operator, String context) {
|
||||
Log log = new Log();
|
||||
log.setCategory(Constants.LOG_CATEGORY_OPERATION);
|
||||
log.setOperator(operator);
|
||||
log.setUsername(secUser.getUsername());
|
||||
log.setPartyId(secUser.getPartyId());
|
||||
log.setLog(context);
|
||||
log.setCreateTime(new Date());
|
||||
this.logService.saveSync(log);
|
||||
}
|
||||
|
||||
protected String verif(String type, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(type)) {
|
||||
return "限制天数必填";
|
||||
}
|
||||
if (!StringUtils.isInteger(type)) {
|
||||
return "限制天数输入错误,请输入整数";
|
||||
}
|
||||
if (Integer.valueOf(type).intValue() < 0) {
|
||||
return "限制天数不能小于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
// if (Double.valueOf(value).doubleValue() < 0) {
|
||||
// return "调整值不能小于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String verifAdjust(String second, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(second)) {
|
||||
return "调整时间必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(second)) {
|
||||
return "调整时间不是浮点数";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
// if (Double.valueOf(value).doubleValue() <= 0) {
|
||||
// return "调整值不能小于等于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
|
||||
if (this.contractOrderService.lock(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
this.contractOrderService.unlock(order_no);
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
425
comm/Contract/src/project/web/admin/AdminHistoryContractOrderController.java
Executable file
425
comm/Contract/src/project/web/admin/AdminHistoryContractOrderController.java
Executable file
@@ -0,0 +1,425 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.PropertiesUtil;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
|
||||
/**
|
||||
* 永续持仓单 历史单
|
||||
*/
|
||||
@RestController
|
||||
public class AdminHistoryContractOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminHistoryContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractOrderService adminContractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
|
||||
private final String action = "normal/adminHistoryContractOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续持仓历史单列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
String status_para = request.getParameter("status_para");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_history_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
// 直接取最大不做分页
|
||||
// this.pageSize = Integer.MAX_VALUE-1;
|
||||
|
||||
// if (StringUtils.isEmptyString(rolename_para)) {
|
||||
// rolename_para = Constants.SECURITY_ROLE_MEMBER;
|
||||
// }
|
||||
|
||||
String basePath = PropertiesUtil.getProperty("admin_url");
|
||||
basePath = this.getPath(request);
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, status_para,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> symbols = new LinkedHashMap<String, String>();
|
||||
for (Item item : this.itemService.cacheGetAll()) {
|
||||
symbols.put(item.getSymbol(), item.getName());
|
||||
}
|
||||
|
||||
modelAndView.addObject("symbols", symbols);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
modelAndView.addObject("status_para", status_para);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示 调整页面
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整 页面计算
|
||||
*
|
||||
* type 0增加一个pips;1减少一个pips;2直接修改调整值;
|
||||
* value 调整值
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
String value = request.getParameter("value");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
String error = this.verif(type, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
int type_int = Integer.valueOf(request.getParameter("type")).intValue();
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
|
||||
if (0 == type_int) {
|
||||
temp = Arith.add(value_double, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (1 == type_int) {
|
||||
temp = Arith.sub(value_double, item.getPips());
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value_double;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*
|
||||
* value 调整值
|
||||
* second 延迟秒
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String value = request.getParameter("value");
|
||||
String second = request.getParameter("second");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verifAdjust(second, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
double second_double = Double.valueOf(request.getParameter("second")).doubleValue();
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, value_double, second_double);
|
||||
|
||||
ThreadUtils.sleep(1000);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(order.getPartyId().toString(), order_no, this.contractOrderService);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
private String getPath(HttpServletRequest request) {
|
||||
return String.format("%s://%s:%s%s", request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath());
|
||||
}
|
||||
|
||||
protected String verif(String type, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(type)) {
|
||||
return "限制天数必填";
|
||||
}
|
||||
if (!StringUtils.isInteger(type)) {
|
||||
return "限制天数输入错误,请输入整数";
|
||||
}
|
||||
if (Integer.valueOf(type).intValue() < 0) {
|
||||
return "限制天数不能小于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(value).doubleValue() < 0) {
|
||||
return "调整值不能小于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String verifAdjust(String second, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(second)) {
|
||||
return "调整时间必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(second)) {
|
||||
return "调整时间不是浮点数";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(value).doubleValue() <= 0) {
|
||||
return "调整值不能小于等于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
|
||||
if (this.contractOrderService.lock(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
this.contractOrderService.unlock(order_no);
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
253
comm/Contract/src/project/web/admin/AdminMarketQuotationsManageController.java
Executable file
253
comm/Contract/src/project/web/admin/AdminMarketQuotationsManageController.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.providers.encoding.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminMarketQuotationsService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataCache;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.LogService;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
/**
|
||||
* 行情数据
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class AdminMarketQuotationsManageController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminMarketQuotationsManageController.class);
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
@Autowired
|
||||
private AdminMarketQuotationsService adminMarketQuotationsService;
|
||||
@Autowired
|
||||
private SecUserService secUserService;
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
private final String action = "normal/adminMarketQuotationsManageAction!";
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
|
||||
this.checkAndSetPageNo(request.getParameter("pageNo"));
|
||||
this.pageSize = 30;
|
||||
this.page = this.adminMarketQuotationsService.pageQuery(this.pageNo, this.pageSize);
|
||||
|
||||
ModelAndView model = new ModelAndView();
|
||||
model.addObject("pageNo", this.pageNo);
|
||||
model.addObject("pageSize", this.pageSize);
|
||||
model.addObject("page", this.page);
|
||||
model.addObject("message", message);
|
||||
model.addObject("error", error);
|
||||
model.setViewName("market_quotations_list");
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 行情管理-调整弹框显示
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(getLoginPartyId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Double> resultMap = new HashMap<String, Double>();
|
||||
Realtime realtime = DataCache.getRealtime(symbol);
|
||||
if (realtime == null) {
|
||||
realtime = this.dataService.realtime(symbol).get(0);
|
||||
}
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
}
|
||||
if (currentValue == null) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面计算
|
||||
*
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(getLoginPartyId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String symbol = request.getParameter("symbol");
|
||||
// 0增加一个pips 1减少一个pips 2直接修改调整值
|
||||
String type_temp = request.getParameter("type");
|
||||
String value_temp = request.getParameter("value");
|
||||
|
||||
Double type = Double.valueOf(type_temp);
|
||||
Double value = Double.valueOf(value_temp);
|
||||
|
||||
Map<String, Double> resultMap = new HashMap<String, Double>();
|
||||
|
||||
Realtime realtime = null;
|
||||
|
||||
if (realtime == null) {
|
||||
realtime = this.dataService.realtime(symbol).get(0);
|
||||
}
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
if (type == 0) {
|
||||
temp = Arith.add(value, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (type == 1) {
|
||||
temp = Arith.sub(value, item.getPips());
|
||||
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
|
||||
ModelAndView model = new ModelAndView();
|
||||
String message = "";
|
||||
String error = "";
|
||||
|
||||
// 调整值
|
||||
String value = request.getParameter("value");
|
||||
String symbol = request.getParameter("symbol");
|
||||
// 延迟秒
|
||||
String second = request.getParameter("second");
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)
|
||||
|| !StringUtils.isDouble(value)) {
|
||||
throw new BusinessException("请输入正确的调整值");
|
||||
}
|
||||
try {
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);;
|
||||
currentValue=realtime.getClose();
|
||||
}
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
String log = MessageFormat.format("ip:"+this.getIp()+",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}",
|
||||
symbol,new BigDecimal(currentValue).toPlainString(),new BigDecimal(value).toPlainString(),second);
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, Double.valueOf(value), Double.valueOf(second));
|
||||
saveLog(sec, this.getUsername_login(), log);
|
||||
|
||||
ThreadUtils.sleep(1000);
|
||||
message = "操作成功";
|
||||
} catch (BusinessException e) {
|
||||
error = e.getMessage();
|
||||
} catch (Exception e) {
|
||||
logger.error("error ", e);
|
||||
error = "程序错误";
|
||||
}
|
||||
model.addObject("message", message);
|
||||
model.addObject("error", error);
|
||||
model.setViewName("redirect:/" + action + "list.action");
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public void saveLog(SecUser secUser, String operator,String context) {
|
||||
project.log.Log log = new project.log.Log();
|
||||
log.setCategory(Constants.LOG_CATEGORY_OPERATION);
|
||||
log.setOperator(operator);
|
||||
log.setUsername(secUser.getUsername());
|
||||
log.setPartyId(secUser.getPartyId());
|
||||
log.setLog(context);
|
||||
log.setCreateTime(new Date());
|
||||
logService.saveSync(log);
|
||||
}
|
||||
|
||||
}
|
||||
705
comm/Contract/src/project/web/api/ContractApplyOrderController.java
Executable file
705
comm/Contract/src/project/web/api/ContractApplyOrderController.java
Executable file
@@ -0,0 +1,705 @@
|
||||
package project.web.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.sessiontoken.SessionTokenService;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.BaseAction;
|
||||
import kernel.web.ResultObject;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.item.model.ItemLever;
|
||||
import project.party.PartyService;
|
||||
import project.party.model.Party;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
|
||||
/**
|
||||
* 永续合约委托单
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class ContractApplyOrderController extends BaseAction {
|
||||
|
||||
private Logger logger = LogManager.getLogger(ContractApplyOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private WalletService walletService;
|
||||
@Autowired
|
||||
private PartyService partyService;
|
||||
@Autowired
|
||||
private SessionTokenService sessionTokenService;
|
||||
@Autowired
|
||||
protected SysparaService sysparaService;
|
||||
|
||||
private final String action = "/api/contractApplyOrder!";
|
||||
|
||||
/**
|
||||
* 开仓页面参数
|
||||
*
|
||||
* symbol 币种
|
||||
*/
|
||||
@RequestMapping(action + "openview.action")
|
||||
public Object openview(HttpServletRequest request) throws IOException {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
data.put("amount", item.getUnit_amount());
|
||||
data.put("fee", item.getUnit_fee());
|
||||
|
||||
List<ItemLever> list = this.itemService.findLever(item.getId().toString());
|
||||
data.put("lever", list);
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
|
||||
|
||||
// 账户剩余资 金
|
||||
double use_amount = Arith.add(item.getUnit_amount(), item.getUnit_fee());
|
||||
double volume = Arith.div(wallet.getMoney(), use_amount);
|
||||
volume = new BigDecimal(volume).setScale(0, RoundingMode.DOWN).doubleValue();
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#");
|
||||
data.put("volume", df.format(volume));
|
||||
|
||||
String session_token = this.sessionTokenService.savePut(partyId);
|
||||
data.put("session_token", session_token);
|
||||
} else {
|
||||
data.put("volume", 0.00D);
|
||||
}
|
||||
|
||||
double contract_open_limit_min = Double.valueOf(this.sysparaService.find("contract_open_limit_min").getValue());
|
||||
data.put("contract_open_limit_min", contract_open_limit_min);
|
||||
double contract_open_limit_max = Double.valueOf(this.sysparaService.find("contract_open_limit_max").getValue());
|
||||
data.put("contract_open_limit_max", contract_open_limit_max);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓页面参数
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
*/
|
||||
@RequestMapping(action + "closeview.action")
|
||||
public Object closeview(HttpServletRequest request) throws IOException {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted(partyId, symbol, direction);
|
||||
|
||||
double ordervolume = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ordervolume = Arith.add(ordervolume, list.get(i).getVolume());
|
||||
}
|
||||
data.put("amount", ordervolume);
|
||||
|
||||
String session_token = this.sessionTokenService.savePut(partyId);
|
||||
data.put("session_token", session_token);
|
||||
} else {
|
||||
data.put("amount", 0);
|
||||
}
|
||||
|
||||
double contract_close_limit_min = Double.valueOf(this.sysparaService.find("contract_close_limit_min").getValue());
|
||||
data.put("contract_close_limit_min", contract_close_limit_min);
|
||||
double contract_close_limit_max = Double.valueOf(this.sysparaService.find("contract_close_limit_max").getValue());
|
||||
data.put("contract_close_limit_max", contract_close_limit_max);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开仓
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
* amount 委托数量(张)
|
||||
* lever_rate 杠杆倍数
|
||||
* price 交易价格
|
||||
* stop_price_profit 止盈触发价格
|
||||
* stop_price_loss 止损触发价格
|
||||
* price_type 订单报价类型:"limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
@RequestMapping(action + "open.action")
|
||||
public Object open(HttpServletRequest request) throws IOException {
|
||||
String session_token = request.getParameter("session_token");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
String amount = request.getParameter("amount");
|
||||
String lever_rate = request.getParameter("lever_rate");
|
||||
String price = request.getParameter("price");
|
||||
String stop_price_profit = request.getParameter("stop_price_profit");
|
||||
String stop_price_loss = request.getParameter("stop_price_loss");
|
||||
String price_type = request.getParameter("price_type");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
boolean lock = false;
|
||||
|
||||
try {
|
||||
|
||||
if (!ContractLock.add(partyId)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
lock = true;
|
||||
|
||||
Object object = this.sessionTokenService.cacheGet(session_token);
|
||||
this.sessionTokenService.delete(session_token);
|
||||
if (null == object || !this.getLoginPartyId().equals((String) object)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(lever_rate)) {
|
||||
lever_rate = "1";
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(stop_price_profit)) {
|
||||
stop_price_profit = "0";
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(stop_price_loss)) {
|
||||
stop_price_loss = "0";
|
||||
}
|
||||
|
||||
String error = this.verifOpen(amount, lever_rate, price, stop_price_profit, stop_price_loss);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double amount_double = Double.valueOf(request.getParameter("amount")).doubleValue();
|
||||
double lever_rate_double = Double.valueOf(lever_rate).doubleValue();
|
||||
double price_double = Double.valueOf(request.getParameter("price")).doubleValue();
|
||||
double stop_price_profit_double = Double.valueOf(stop_price_profit).doubleValue();
|
||||
double stop_price_loss_double = Double.valueOf(stop_price_loss).doubleValue();
|
||||
|
||||
Party party = this.partyService.cachePartyBy(partyId, false);
|
||||
if (!party.getEnabled()) {
|
||||
resultObject.setCode("506");
|
||||
resultObject.setMsg("用户已锁定");
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
// double contract_open_limit_min = Double.valueOf(this.sysparaService.find("contract_open_limit_min").getValue());
|
||||
// if (amount_double < contract_open_limit_min) {
|
||||
// throw new BusinessException("开仓金额不得小于开仓最小限额");
|
||||
// }
|
||||
// double contract_open_limit_max = Double.valueOf(this.sysparaService.find("contract_open_limit_max").getValue());
|
||||
// if (amount_double > contract_open_limit_max) {
|
||||
// throw new BusinessException("开仓金额不得大于开仓最大限额");
|
||||
// }
|
||||
|
||||
ContractApplyOrder order = new ContractApplyOrder();
|
||||
order.setPartyId(partyId);
|
||||
order.setSymbol(symbol);
|
||||
order.setDirection(direction);
|
||||
order.setOffset(ContractApplyOrder.OFFSET_OPEN);
|
||||
order.setVolume(amount_double);
|
||||
order.setVolume_open(amount_double);
|
||||
order.setLever_rate(lever_rate_double);
|
||||
order.setPrice(price_double);
|
||||
order.setStop_price_profit(stop_price_profit_double);
|
||||
order.setStop_price_loss(stop_price_loss_double);
|
||||
order.setOrder_price_type(price_type);
|
||||
|
||||
this.contractApplyOrderService.saveCreate(order);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(partyId);
|
||||
}
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
* amount 委托数量(张)
|
||||
* price 交易价格
|
||||
* order_price_type 订单报价类型:"limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public Object close(HttpServletRequest request) throws IOException {
|
||||
String session_token = request.getParameter("session_token");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
String amount = request.getParameter("amount");
|
||||
String price = request.getParameter("price");
|
||||
String price_type = request.getParameter("price_type");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
boolean lock = false;
|
||||
|
||||
try {
|
||||
|
||||
if (!ContractLock.add(partyId)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
lock = true;
|
||||
|
||||
Object object = this.sessionTokenService.cacheGet(session_token);
|
||||
this.sessionTokenService.delete(session_token);
|
||||
if (null == object || !this.getLoginPartyId().equals((String) object)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
String error = this.verifClose(amount, price);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double amount_double = Double.valueOf(request.getParameter("amount")).doubleValue();
|
||||
double price_double = Double.valueOf(request.getParameter("price")).doubleValue();
|
||||
|
||||
Party party = this.partyService.cachePartyBy(partyId, false);
|
||||
if (!party.getEnabled()) {
|
||||
resultObject.setCode("506");
|
||||
resultObject.setMsg("用户已锁定");
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
// double contract_close_limit_min = Double.valueOf(this.sysparaService.find("contract_close_limit_min").getValue());
|
||||
// if (amount_double < contract_close_limit_min) {
|
||||
// throw new BusinessException("平仓金额不得小于平仓最小限额");
|
||||
// }
|
||||
// double contract_close_limit_max = Double.valueOf(this.sysparaService.find("contract_close_limit_max").getValue());
|
||||
// if (amount_double > contract_close_limit_max) {
|
||||
// throw new BusinessException("平仓金额不得大于平仓最大限额");
|
||||
// }
|
||||
|
||||
ContractApplyOrder order = new ContractApplyOrder();
|
||||
order.setPartyId(partyId);
|
||||
order.setSymbol(symbol);
|
||||
order.setDirection(direction);
|
||||
order.setOffset(ContractApplyOrder.OFFSET_CLOSE);
|
||||
order.setVolume(amount_double);
|
||||
order.setVolume_open(amount_double);
|
||||
order.setPrice(price_double);
|
||||
order.setOrder_price_type(price_type);
|
||||
|
||||
this.contractApplyOrderService.saveCreate(order);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(partyId);
|
||||
}
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤单
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "cancel.action")
|
||||
public Object cancel(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CancelDelayThread lockDelayThread = new CancelDelayThread(this.getLoginPartyId(), order_no, this.contractApplyOrderService, false);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键撤单
|
||||
*/
|
||||
@RequestMapping(action + "cancelAll.action")
|
||||
public Object cancelAll(HttpServletRequest request) throws IOException {
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CancelDelayThread lockDelayThread = new CancelDelayThread(this.getLoginPartyId(), "", this.contractApplyOrderService, true);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单详情
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "get.action")
|
||||
public Object get(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(order_no)) {
|
||||
logger.info("contractApplyOrder!get order_no null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
ContractApplyOrder order = this.contractApplyOrderService.findByOrderNo(order_no);
|
||||
|
||||
if (null == order) {
|
||||
logger.info("contractApplyOrder!get order_no:" + order_no + ", order null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
resultObject.setData(this.bulidData(order));
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单列表
|
||||
*
|
||||
* page_no 页码
|
||||
* symbol 币种
|
||||
* type 查询类型:orders 当前委托单 ,hisorders 历史委托单
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public Object list(HttpServletRequest request) throws IOException {
|
||||
String page_no = request.getParameter("page_no");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
|
||||
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
resultObject.setData(data);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(page_no)) {
|
||||
page_no = "1";
|
||||
}
|
||||
if (!StringUtils.isInteger(page_no)) {
|
||||
throw new BusinessException("页码不是整数");
|
||||
}
|
||||
if (Integer.valueOf(page_no).intValue() <= 0) {
|
||||
throw new BusinessException("页码不能小于等于0");
|
||||
}
|
||||
|
||||
int page_no_int = Integer.valueOf(page_no).intValue();
|
||||
|
||||
data = this.contractApplyOrderService.getPaged(page_no_int, 10, this.getLoginPartyId(), symbol, type);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
private Map<String, Object> bulidData(ContractApplyOrder order) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", this.itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("offset", order.getOffset());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("price", order.getPrice());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("price_type", order.getOrder_price_type());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
return map;
|
||||
}
|
||||
|
||||
private String verifOpen(String amount, String lever_rate, String price, String stop_price_profit, String stop_price_loss) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(amount)) {
|
||||
return "委托金额必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(amount)) {
|
||||
return "委托金额不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(amount).doubleValue() <= 0) {
|
||||
return "委托金额不能小于等于0";
|
||||
}
|
||||
|
||||
// if (StringUtils.isNullOrEmpty(lever_rate)) {
|
||||
// return "杠杆倍数必填";
|
||||
// }
|
||||
if (!StringUtils.isDouble(lever_rate)) {
|
||||
return "杠杆倍数不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(lever_rate).doubleValue() <= 0) {
|
||||
return "杠杆倍数不能小于等于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(price)) {
|
||||
return "交易价格必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(price)) {
|
||||
return "交易价格不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(price).doubleValue() <= 0) {
|
||||
return "交易价格不能小于等于0";
|
||||
}
|
||||
|
||||
// if (StringUtils.isNullOrEmpty(stop_price_profit)) {
|
||||
// return "止盈触发价格必填";
|
||||
// }
|
||||
// if (!StringUtils.isDouble(stop_price_profit)) {
|
||||
// return "止盈触发价格不是浮点数";
|
||||
// }
|
||||
// if (Double.valueOf(stop_price_profit).doubleValue() < 0) {
|
||||
// return "止盈触发价格不能小于0";
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.isNullOrEmpty(stop_price_loss)) {
|
||||
// return "止损触发价格必填";
|
||||
// }
|
||||
// if (!StringUtils.isDouble(stop_price_loss)) {
|
||||
// return "止损触发价格不是浮点数";
|
||||
// }
|
||||
// if (Double.valueOf(stop_price_loss).doubleValue() < 0) {
|
||||
// return "止损触发价格不能小于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String verifClose(String amount, String price) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(amount)) {
|
||||
return "委托金额必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(amount)) {
|
||||
return "委托金额不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(amount).doubleValue() <= 0) {
|
||||
return "委托金额不能小于等于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(price)) {
|
||||
return "交易价格必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(price)) {
|
||||
return "交易价格不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(price).doubleValue() <= 0) {
|
||||
return "交易价格不能小于等于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CancelDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
private boolean all = false;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (true == all) {
|
||||
// 一键撤单
|
||||
if (ContractLock.add("all")) {
|
||||
this.contractApplyOrderService.saveCancelAllByPartyId(partyId);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(100);
|
||||
} else {
|
||||
if (ContractLock.add(order_no)) {
|
||||
this.contractApplyOrderService.saveCancel(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
ThreadUtils.sleep(100);
|
||||
if (true == all) {
|
||||
ContractLock.remove("all");
|
||||
} else {
|
||||
ContractLock.remove(order_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CancelDelayThread(String partyId, String order_no, ContractApplyOrderService contractApplyOrderService, boolean all) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
this.all = all;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
294
comm/Contract/src/project/web/api/ContractOrderController.java
Executable file
294
comm/Contract/src/project/web/api/ContractOrderController.java
Executable file
@@ -0,0 +1,294 @@
|
||||
package project.web.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.BaseAction;
|
||||
import kernel.web.ResultObject;
|
||||
import project.Constants;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
|
||||
/**
|
||||
* 永续合约持仓单
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class ContractOrderController extends BaseAction {
|
||||
|
||||
private Logger logger = LogManager.getLogger(ContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
|
||||
private final String action = "/api/contractOrder!";
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public Object close(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(this.getLoginPartyId(), order_no, this.contractOrderService, false);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键平仓
|
||||
*/
|
||||
@RequestMapping(action + "closeAll.action")
|
||||
public Object closeAll(HttpServletRequest request) throws IOException {
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(this.getLoginPartyId(), "", this.contractOrderService, true);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*
|
||||
* page_no 页码
|
||||
* symbol 币种
|
||||
* type 查询类型:orders 当前持仓单;hisorders 历史持仓单;
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public Object list(HttpServletRequest request) throws IOException {
|
||||
String page_no = request.getParameter("page_no");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
|
||||
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(page_no)) {
|
||||
page_no = "1";
|
||||
}
|
||||
if (!StringUtils.isInteger(page_no)) {
|
||||
throw new BusinessException("页码不是整数");
|
||||
}
|
||||
if (Integer.valueOf(page_no).intValue() <= 0) {
|
||||
throw new BusinessException("页码不能小于等于0");
|
||||
}
|
||||
|
||||
int page_no_int = Integer.valueOf(page_no).intValue();
|
||||
|
||||
data = this.contractOrderService.getPaged(page_no_int, 10, this.getLoginPartyId(), symbol, type);
|
||||
|
||||
String symbolsStr = "";
|
||||
Set<String> symbols = new HashSet<String>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
String sym = data.get(i).get("symbol").toString();
|
||||
if (!symbols.contains(sym)) {
|
||||
symbols.add(sym);
|
||||
if (i != 0) {
|
||||
symbolsStr = symbolsStr + "," + sym;
|
||||
} else {
|
||||
symbolsStr = sym;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Realtime> realtime_all = this.dataService.realtime(symbolsStr);
|
||||
if (realtime_all.size() <= 0) {
|
||||
realtime_all = new ArrayList<Realtime>();
|
||||
// throw new BusinessException("系统错误,请稍后重试");
|
||||
}
|
||||
|
||||
Map<String, Realtime> realtimeMap = new HashMap<String, Realtime>();
|
||||
for (int i = 0; i < realtime_all.size(); i++) {
|
||||
realtimeMap.put(realtime_all.get(i).getSymbol(), realtime_all.get(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Map<String, Object> map = data.get(i);
|
||||
|
||||
// 标记价格
|
||||
Realtime realtime = realtimeMap.get(map.get("symbol"));
|
||||
if (null == realtime) {
|
||||
map.put("mark_price", 0);
|
||||
} else {
|
||||
map.put("mark_price", realtime.getClose());
|
||||
}
|
||||
}
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "get.action")
|
||||
public Object get(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(order_no)) {
|
||||
logger.info("contractOrder!get order_no null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
|
||||
if (null == order) {
|
||||
logger.info("contractOrder!get order_no:" + order_no + ", order null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
resultObject.setData(this.contractOrderService.bulidOne(order));
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
private boolean all = false;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (true == all) {
|
||||
// 一键平仓
|
||||
if (ContractLock.add("all")) {
|
||||
this.contractOrderService.saveCloseRemoveAllByPartyId(partyId);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
} else {
|
||||
if (ContractLock.add(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (true == all) {
|
||||
ContractLock.remove("all");
|
||||
} else {
|
||||
ContractLock.remove(order_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService, boolean all) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
this.all = all;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user