first commit
This commit is contained in:
280
comm/Cms/WebContent/banner_add.jsp
Executable file
280
comm/Cms/WebContent/banner_add.jsp
Executable file
@@ -0,0 +1,280 @@
|
||||
<%@ 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 -->
|
||||
<form action="<%=basePath%>normal/adminBannerAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">
|
||||
新增横幅
|
||||
<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>
|
||||
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminBannerAction!add.action"
|
||||
method="post" name="mainForm" id="mainForm" enctype="multipart/form-data">
|
||||
<s:hidden name="id" id="id"></s:hidden>
|
||||
<s:hidden name="img" id="img"></s:hidden>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">业务代码</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="content_code" name="content_code" cssClass="form-control "
|
||||
placeholder="业务代码(同种内容不同语言代码相同)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">图片</label>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<input type="file" id="fileName" name="fileName" onchange="upload();" style="position:absolute;opacity:0;">
|
||||
<label for="fileName">
|
||||
|
||||
<img width="150px" height="55px" id="show_img" style="float: left;"
|
||||
|
||||
src="<%=base%>/image/add.png" alt="点击上传图片" />
|
||||
|
||||
</label>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">路径</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="url" name="url" cssClass="form-control "
|
||||
placeholder="路径" />
|
||||
</div>
|
||||
</div>
|
||||
<p class="ballon color1">排序索引,数字越小越靠前</p>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">排序索引</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="sort_index" name="sort_index" cssClass="form-control "
|
||||
placeholder="排序索引" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">模块</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="model" cssClass="form-control "
|
||||
name="model" list="modelMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">语言</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="language" cssClass="form-control "
|
||||
name="language" list="languageMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">是否可点击</label>
|
||||
<div class="col-sm-3">
|
||||
<div class="input-group">
|
||||
<s:select id="click" cssClass="form-control "
|
||||
name="click" list="#{'0':'否','1':'是'}"
|
||||
listKey="key" listValue="value" value="on_sale" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">是否展示</label>
|
||||
<div class="col-sm-3">
|
||||
<div class="input-group">
|
||||
<s:select id="on_show" cssClass="form-control "
|
||||
name="on_show" list="#{'0':'否','1':'是'}"
|
||||
listKey="key" listValue="value" value="on_sale" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-1">
|
||||
<!-- 模态框(Modal) -->
|
||||
<div class="modal fade" id="modal_succeeded" tabindex="-1"
|
||||
role="dialog" aria-labelledby="myModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content" >
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close"
|
||||
data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel">确认新增</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">登录人资金密码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="login_safeword" type="password" name="login_safeword"
|
||||
class="login_safeword" placeholder="请输入登录人资金密码" >
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="form-group" style="">
|
||||
|
||||
<label for="input002" class="col-sm-3 control-label form-label">验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="email_code" type="text" name="email_code"
|
||||
class="login_safeword" placeholder="请输入验证码" >
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<button id="email_code_button"
|
||||
class="btn btn-light " onClick="sendCode();" >获取验证码</button>
|
||||
<a id="email_code_button" href="javascript:sendCode();" class="btn btn-light" style="margin-bottom: 10px" >获取超级签验证码</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">超级谷歌验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="super_google_auth_code" name="super_google_auth_code"
|
||||
placeholder="请输入超级谷歌验证码" >
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="modal-footer" style="margin-top: 0;">
|
||||
<button type="button" class="btn "
|
||||
data-dismiss="modal">关闭</button>
|
||||
<button id="sub" type="submit"
|
||||
class="btn btn-default" >确认</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<a href="javascript:goUrl(<s:property value="pageNo" />)"
|
||||
class="btn">取消</a> <a href="javascript:submit()"
|
||||
class="btn btn-default">保存</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
<script src="<%=basePath%>js/util.js" type="text/javascript"></script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
function submit() {
|
||||
/* swal({
|
||||
title : "是否保存?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
var sHTML = $('#content_text').val();
|
||||
$("#content").val(sHTML);
|
||||
document.getElementById("mainForm").submit();
|
||||
}); */
|
||||
$('#modal_succeeded').modal("show");
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
//初始化执行一次
|
||||
setTimeout(function() {
|
||||
start();
|
||||
}, 100);
|
||||
function start(){
|
||||
var img = $("#img").val();
|
||||
if(img!=null&&img!=""){
|
||||
var show_img = document.getElementById('show_img');
|
||||
show_img.src="<%=base%>wap/public/showimg!showImg.action?imagePath="+img;
|
||||
}
|
||||
}
|
||||
function upload(){
|
||||
var fileReader = new FileReader();
|
||||
var formData = new FormData();
|
||||
var file = document.getElementById('fileName').files[0];
|
||||
formData.append("file", file);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<%=basePath%>normal/uploadimg!execute.action?random="
|
||||
+ Math.random(),
|
||||
data: formData,
|
||||
dataType: "json",
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success : function(data) {
|
||||
console.log(data);
|
||||
$("#img").val(data.data)
|
||||
var show_img = document.getElementById('show_img');
|
||||
show_img.src="<%=base%>wap/public/showimg!showImg.action?imagePath="+data.data;
|
||||
|
||||
},
|
||||
error : function(XMLHttpRequest, textStatus,
|
||||
errorThrown) {
|
||||
console.log("请求错误");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
262
comm/Cms/WebContent/banner_list.jsp
Executable file
262
comm/Cms/WebContent/banner_list.jsp
Executable file
@@ -0,0 +1,262 @@
|
||||
<%@ 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">
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminBannerAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<s:hidden name="pageNo" id="pageNo"></s:hidden>
|
||||
<%-- <div class="col-md-12 col-lg-4">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="para_title" name="para_title" cssClass="form-control " placeholder="标题"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div> --%>
|
||||
|
||||
<div class="col-md-12 col-lg-4">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:select id="para_language" cssClass="form-control "
|
||||
name="para_language"
|
||||
list="languageMap" listKey="key"
|
||||
listValue="value" headerKey="" headerValue="所有语言"
|
||||
value="para_language" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="submit" class="btn btn-block btn-light">确定</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<%-- <form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminCmsAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form> --%>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-title">查询结果</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<a href="<%=basePath%>normal/adminBannerAction!toAdd.action"
|
||||
class="btn btn-light" style="margin-bottom: 10px"><i
|
||||
class="fa fa-pencil"></i>新增横幅</a>
|
||||
</sec:authorize>
|
||||
<div class="panel-body">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<td >业务代码</td>
|
||||
<td >模块</td>
|
||||
</sec:authorize>
|
||||
<td class="col-md-2">语言</td>
|
||||
<!-- <td >访问路径</td> -->
|
||||
<td >图片</td>
|
||||
<td >可否点击</td>
|
||||
<td >是否展示</td>
|
||||
<td >排序</td>
|
||||
<!-- <td class="col-md-2" width="150px">日期</td> -->
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
|
||||
<td class="col-md-2"></td>
|
||||
</sec:authorize>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<td><s:property value="content_code" /></td>
|
||||
<td><s:property value="model" /></td>
|
||||
</sec:authorize>
|
||||
<td class="col-md-2"><s:property value="language" /></td>
|
||||
<%-- <td class="col-md-2"><s:property value="url" /></td> --%>
|
||||
<td class="col-md-2"><img alt="" width="150px" height="55px" src="<s:property value="image" />"></td>
|
||||
<td>
|
||||
<s:if test="click==1"><span class="right label label-success">是</span></s:if>
|
||||
<s:else><span class="right label label-danger">否</span></s:else>
|
||||
</td>
|
||||
<td>
|
||||
<s:if test="on_show==1"><span class="right label label-success">是</span></s:if>
|
||||
<s:else><span class="right label label-danger">否</span></s:else>
|
||||
</td>
|
||||
<td><s:property value="sort_index" /></td>
|
||||
<%-- <td><s:date name="createTime" format="yyyy-MM-dd " /></td> --%>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
|
||||
<td>
|
||||
<%-- <a href="<%=basePath%>normal/adminCmsAction!toUpdate.action?id=<s:property value="id" />"
|
||||
class="btn btn-light" style="margin-bottom: 10px">修改</a> --%>
|
||||
<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="<%=basePath%>normal/adminBannerAction!toUpdate.action?id=<s:property value="id" />">修改</a></li>
|
||||
|
||||
<li><a
|
||||
href="javascript:ondelete('<s:property value="id" />')">删除</a></li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</sec:authorize>
|
||||
</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"%>
|
||||
|
||||
<form action="<%=basePath%>normal/adminBannerAction!delete.action"
|
||||
method="post" id="ondelete">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
<s:hidden name="id" id="news_id"></s:hidden>
|
||||
<div class="col-sm-1">
|
||||
<!-- 模态框(Modal) -->
|
||||
<div class="modal fade" id="modal_succeeded" tabindex="-1"
|
||||
role="dialog" aria-labelledby="myModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content" >
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close"
|
||||
data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel">确认新增</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">登录人资金密码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="login_safeword" type="password" name="login_safeword"
|
||||
class="login_safeword" placeholder="请输入登录人资金密码" >
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="form-group" style="">
|
||||
|
||||
<label for="input002" class="col-sm-3 control-label form-label">验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="email_code" type="text" name="email_code"
|
||||
class="login_safeword" placeholder="请输入验证码" >
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<button id="email_code_button"
|
||||
class="btn btn-light " onClick="sendCode();" >获取验证码</button>
|
||||
<a id="email_code_button" href="javascript:sendCode();" class="btn btn-light" style="margin-bottom: 10px" >获取超级签验证码</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">超级谷歌验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="super_google_auth_code" name="super_google_auth_code"
|
||||
placeholder="请输入超级谷歌验证码" >
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="modal-footer" style="margin-top: 0;">
|
||||
<button type="button" class="btn "
|
||||
data-dismiss="modal">关闭</button>
|
||||
<button id="sub" type="submit"
|
||||
class="btn btn-default" >确认</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal -->
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
function ondelete(id) {
|
||||
$("#news_id").val(id);
|
||||
$('#modal_succeeded').modal("show");
|
||||
/* swal({
|
||||
title : "是否确认删除?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
document.getElementById("ondelete").submit();
|
||||
}); */
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
289
comm/Cms/WebContent/banner_update.jsp
Executable file
289
comm/Cms/WebContent/banner_update.jsp
Executable file
@@ -0,0 +1,289 @@
|
||||
<%@ 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 -->
|
||||
<form action="<%=basePath%>normal/adminBannerAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">
|
||||
修改公告
|
||||
<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>
|
||||
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminBannerAction!update.action"
|
||||
method="post" name="mainForm" id="mainForm" enctype="multipart/form-data">
|
||||
<s:hidden name="id" id="id"></s:hidden>
|
||||
<s:hidden name="img" id="img"></s:hidden>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">业务代码</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="content_code" name="content_code" cssClass="form-control "
|
||||
placeholder="业务代码(同种内容不同语言代码相同)" />
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">图片</label>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<input type="file" id="fileName" name="fileName" onchange="upload();" style="position:absolute;opacity:0;">
|
||||
<label for="fileName">
|
||||
|
||||
<img width="150px" height="55px" id="show_img" style="float: left;"
|
||||
|
||||
src="<%=base%>/image/add.png" alt="点击上传图片" />
|
||||
|
||||
</label>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">路径</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="url" name="url" cssClass="form-control "
|
||||
placeholder="路径" />
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
<p class="ballon color1">排序索引,数字越小越靠前</p>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">排序索引</label>
|
||||
<div class="col-sm-4">
|
||||
<s:textfield id="sort_index" name="sort_index" cssClass="form-control "
|
||||
placeholder="排序索引" />
|
||||
</div>
|
||||
</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">模块</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="model" cssClass="form-control "
|
||||
name="model" list="modelMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">语言</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="language" cssClass="form-control "
|
||||
name="language" list="languageMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">是否可点击</label>
|
||||
<div class="col-sm-3">
|
||||
<div class="input-group">
|
||||
<s:select id="click" cssClass="form-control "
|
||||
name="click" list="#{'0':'否','1':'是'}"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label form-label">是否展示</label>
|
||||
<div class="col-sm-3">
|
||||
<div class="input-group">
|
||||
<s:select id="on_show" cssClass="form-control "
|
||||
name="on_show" list="#{'0':'否','1':'是'}"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-1">
|
||||
<!-- 模态框(Modal) -->
|
||||
<div class="modal fade" id="modal_succeeded" tabindex="-1"
|
||||
role="dialog" aria-labelledby="myModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content" >
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close"
|
||||
data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel">确认新增</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">登录人资金密码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="login_safeword" type="password" name="login_safeword"
|
||||
class="login_safeword" placeholder="请输入登录人资金密码" >
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="form-group" style="">
|
||||
|
||||
<label for="input002" class="col-sm-3 control-label form-label">验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="email_code" type="text" name="email_code"
|
||||
class="login_safeword" placeholder="请输入验证码" >
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<button id="email_code_button"
|
||||
class="btn btn-light " onClick="sendCode();" >获取验证码</button>
|
||||
<a id="email_code_button" href="javascript:sendCode();" class="btn btn-light" style="margin-bottom: 10px" >获取超级签验证码</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" >
|
||||
<label for="input002" class="col-sm-3 control-label form-label">超级谷歌验证码</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="super_google_auth_code" name="super_google_auth_code"
|
||||
placeholder="请输入超级谷歌验证码" >
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="modal-footer" style="margin-top: 0;">
|
||||
<button type="button" class="btn "
|
||||
data-dismiss="modal">关闭</button>
|
||||
<button id="sub" type="submit"
|
||||
class="btn btn-default" >确认</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<a href="javascript:goUrl(<s:property value="pageNo" />)"
|
||||
class="btn">取消</a> <a href="javascript:submit()"
|
||||
class="btn btn-default">保存</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
<script src="<%=basePath%>js/util.js" type="text/javascript"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function submit() {
|
||||
/* swal({
|
||||
title : "是否保存?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
var sHTML = $('#content_text').val();
|
||||
$("#content").val(sHTML);
|
||||
document.getElementById("mainForm").submit();
|
||||
}); */
|
||||
$('#modal_succeeded').modal("show");
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
//初始化执行一次
|
||||
setTimeout(function() {
|
||||
start();
|
||||
}, 100);
|
||||
function start(){
|
||||
var img = $("#img").val();
|
||||
if(img!=null&&img!=""){
|
||||
var show_img = document.getElementById('show_img');
|
||||
<%-- show_img.src="<%=base%>wap/public/showimg!showImg.action?imagePath="+img; --%>
|
||||
show_img.src=img;
|
||||
}
|
||||
}
|
||||
function upload(){
|
||||
var fileReader = new FileReader();
|
||||
var formData = new FormData();
|
||||
var file = document.getElementById('fileName').files[0];
|
||||
formData.append("file", file);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<%=basePath%>normal/uploadimg!execute.action?random="
|
||||
+ Math.random(),
|
||||
data: formData,
|
||||
dataType: "json",
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success : function(data) {
|
||||
console.log(data);
|
||||
// $("#img").val(data.data)
|
||||
// var show_img = document.getElementById('show_img');
|
||||
<%-- show_img.src="<%=base%>wap/public/showimg!showImg.action?imagePath="+data.data; --%>
|
||||
|
||||
$("#img").val("<%=base%>wap/public/showimg!showImg.action?imagePath="+data.data)
|
||||
var show_img = document.getElementById('show_img');
|
||||
show_img.src=$("#img").val();
|
||||
|
||||
},
|
||||
error : function(XMLHttpRequest, textStatus,
|
||||
errorThrown) {
|
||||
console.log("请求错误");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
165
comm/Cms/WebContent/cms_add.jsp
Executable file
165
comm/Cms/WebContent/cms_add.jsp
Executable file
@@ -0,0 +1,165 @@
|
||||
<%@ 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 -->
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_LIST")'>
|
||||
<form action="<%=basePath%>normal/adminCmsAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form>
|
||||
</s:if>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">
|
||||
新增公告
|
||||
<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>
|
||||
|
||||
<div class="panel-body">
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_ADD")'>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminCmsAction!add.action"
|
||||
method="post" name="mainForm" id="mainForm">
|
||||
<s:hidden name="id" id="id"></s:hidden>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">标题</label>
|
||||
<div class="col-sm-10">
|
||||
<s:textfield id="title" name="title" cssClass="form-control "
|
||||
placeholder="标题" />
|
||||
</div>
|
||||
</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">业务代码</label>
|
||||
<div class="col-sm-10">
|
||||
<s:textfield id="content_code" name="content_code" cssClass="form-control "
|
||||
placeholder="业务代码(同种内容不同语言代码相同)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">模块</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="model" cssClass="form-control "
|
||||
name="model" list="modelMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">语言</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="language" cssClass="form-control "
|
||||
name="language" list="languageMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-11">
|
||||
<div id="summernote"></div>
|
||||
</div>
|
||||
<s:hidden name="content" id="content"></s:hidden>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<a href="javascript:goUrl(<s:property value="pageNo" />)"
|
||||
class="btn">取消</a> <a href="javascript:submit()"
|
||||
class="btn btn-default">保存</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
<script src="<%=basePath%>js/util.js" type="text/javascript"></script>
|
||||
<script type="text/javascript"
|
||||
src="<%=basePath%>js/summernote/summernote.min.js"></script>
|
||||
|
||||
<script>
|
||||
/* SUMMERNOTE*/
|
||||
$(document).ready(function() {
|
||||
$('#summernote').summernote();
|
||||
var content=$("#content").val();
|
||||
$('#summernote').code(content)
|
||||
});
|
||||
</script>
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_ADD")'>
|
||||
<script type="text/javascript">
|
||||
function submit() {
|
||||
swal({
|
||||
title : "是否保存?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
var sHTML = $('#summernote').code();
|
||||
$("#content").val(sHTML);
|
||||
document.getElementById("mainForm").submit();
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
206
comm/Cms/WebContent/cms_list.jsp
Executable file
206
comm/Cms/WebContent/cms_list.jsp
Executable file
@@ -0,0 +1,206 @@
|
||||
<%@ 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_CMS_LIST")'>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminCmsAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<s:hidden name="pageNo" id="pageNo"></s:hidden>
|
||||
<div class="col-md-12 col-lg-4">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:textfield id="para_title" name="para_title" cssClass="form-control " placeholder="标题"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-4">
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<s:select id="para_language" cssClass="form-control "
|
||||
name="para_language"
|
||||
list="languageMap" listKey="key"
|
||||
listValue="value" headerKey="" headerValue="所有语言"
|
||||
value="para_language" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-2">
|
||||
<button type="submit" class="btn btn-block btn-default">确定</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<%-- <form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminCmsAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form> --%>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- Start Panel -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-title">查询结果</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_TOADD")'>
|
||||
<a href="<%=basePath%>normal/adminCmsAction!toAdd.action"
|
||||
class="btn btn-light" style="margin-bottom: 10px"><i
|
||||
class="fa fa-pencil"></i>新增公告</a>
|
||||
</s:if>
|
||||
</sec:authorize>
|
||||
<div class="panel-body">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td >标题</td>
|
||||
<!-- <td>内容</td> -->
|
||||
<!-- <td class="col-md-1">模块</td> -->
|
||||
<td class="col-md-2">语言</td>
|
||||
<!-- <td class="col-md-2" width="150px">日期</td> -->
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
|
||||
<td class="col-md-2"></td>
|
||||
</sec:authorize>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<s:iterator value="page.elements" status="stat">
|
||||
<tr>
|
||||
<%-- <td><a
|
||||
href="<%=basePath%>normal/adminCmsAction!toAdd.action?id=<s:property value="id" />"
|
||||
target="_blank"><s:property value="title" /></a></td> --%>
|
||||
<td><s:property value="title" /></td>
|
||||
<%-- <td title="<s:property value="content"/>">
|
||||
<s:if test="content.length()>=17">
|
||||
<s:property value="content.substring(0,17)+'....'" />
|
||||
</s:if>
|
||||
<s:else><s:property value="content"/></s:else>
|
||||
</td> --%>
|
||||
<%-- <td><s:property value="model" /></td> --%>
|
||||
<td class="col-md-2"><s:property value="language" /></td>
|
||||
<%-- <td><s:date name="createTime" format="yyyy-MM-dd " /></td> --%>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
|
||||
<td>
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_TOUPDATE")'>
|
||||
<a href="<%=basePath%>normal/adminCmsAction!toUpdate.action?id=<s:property value="id" />"
|
||||
class="btn btn-light" style="margin-bottom: 10px">修改</a>
|
||||
</s:if>
|
||||
<%-- <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="<%=basePath%>normal/adminCmsAction!toAdd.action?id=<s:property value="id" />">修改</a></li>
|
||||
|
||||
<li><a
|
||||
href="javascript:ondelete('<s:property value="id" />')">删除</a></li>
|
||||
|
||||
</ul>
|
||||
</div> --%>
|
||||
</td>
|
||||
</sec:authorize>
|
||||
</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">
|
||||
<form action="<%=basePath%>normal/adminCmsAction!delete.action"
|
||||
method="post" id="ondelete">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
<s:hidden name="id" id="news_id"></s:hidden>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
function ondelete(id) {
|
||||
$("#news_id").val(id);
|
||||
swal({
|
||||
title : "是否确认删除?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
document.getElementById("ondelete").submit();
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</sec:authorize>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
165
comm/Cms/WebContent/cms_update.jsp
Executable file
165
comm/Cms/WebContent/cms_update.jsp
Executable file
@@ -0,0 +1,165 @@
|
||||
<%@ 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 -->
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_LIST")'>
|
||||
<form action="<%=basePath%>normal/adminCmsAction!list.action"
|
||||
method="post" id="queryForm">
|
||||
<input type="hidden" name="pageNo" id="pageNo"
|
||||
value="${param.pageNo}">
|
||||
</form>
|
||||
</s:if>
|
||||
<!-- END queryForm -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-title">
|
||||
修改公告
|
||||
<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>
|
||||
|
||||
<div class="panel-body">
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_UPDATE")'>
|
||||
<form class="form-horizontal"
|
||||
action="<%=basePath%>normal/adminCmsAction!update.action"
|
||||
method="post" name="mainForm" id="mainForm">
|
||||
<s:hidden name="id" id="id"></s:hidden>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">标题</label>
|
||||
<div class="col-sm-10">
|
||||
<s:textfield id="title" name="title" cssClass="form-control "
|
||||
placeholder="标题" />
|
||||
</div>
|
||||
</div>
|
||||
<sec:authorize ifAnyGranted="ROLE_ROOT">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">业务代码</label>
|
||||
<div class="col-sm-10">
|
||||
<s:textfield id="content_code" name="content_code" cssClass="form-control "
|
||||
placeholder="业务代码(同种内容不同语言代码相同)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">模块</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="model" cssClass="form-control "
|
||||
name="model" list="modelMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label form-label">语言</label>
|
||||
<div class="col-sm-2">
|
||||
<s:select id="language" cssClass="form-control "
|
||||
name="language" list="languageMap"
|
||||
listKey="key" listValue="value" />
|
||||
</div>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-11">
|
||||
<div id="summernote"></div>
|
||||
</div>
|
||||
<s:hidden name="content" id="content"></s:hidden>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<a href="javascript:goUrl(<s:property value="pageNo" />)"
|
||||
class="btn">取消</a> <a href="javascript:submit()"
|
||||
class="btn btn-default">保存</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</s:if>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- END CONTAINER -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
<%@ include file="include/footer.jsp"%>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- End Content -->
|
||||
<!-- //////////////////////////////////////////////////////////////////////////// -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%@ include file="include/js.jsp"%>
|
||||
<script src="<%=basePath%>js/util.js" type="text/javascript"></script>
|
||||
<script type="text/javascript"
|
||||
src="<%=basePath%>js/summernote/summernote.min.js"></script>
|
||||
|
||||
<script>
|
||||
/* SUMMERNOTE*/
|
||||
$(document).ready(function() {
|
||||
$('#summernote').summernote();
|
||||
var content=$("#content").val();
|
||||
$('#summernote').code(content)
|
||||
});
|
||||
</script>
|
||||
<s:if test='isResourceAccessible("ADMIN_CMS_UPDATE")'>
|
||||
<script type="text/javascript">
|
||||
function submit() {
|
||||
swal({
|
||||
title : "是否保存?",
|
||||
text : "",
|
||||
type : "warning",
|
||||
showCancelButton : true,
|
||||
confirmButtonColor : "#DD6B55",
|
||||
confirmButtonText : "确认",
|
||||
closeOnConfirm : false
|
||||
}, function() {
|
||||
var sHTML = $('#summernote').code();
|
||||
$("#content").val(sHTML);
|
||||
document.getElementById("mainForm").submit();
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</s:if>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
27
comm/Cms/config/applicationContext-cms.xml
Executable file
27
comm/Cms/config/applicationContext-cms.xml
Executable file
@@ -0,0 +1,27 @@
|
||||
<?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="cmsService"
|
||||
class="project.cms.internal.CmsServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
<bean id="bannerService"
|
||||
class="project.cms.internal.BannerServiceImpl" init-method="init" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<!-- <property name="redisHandler" ref="redisHandler" /> -->
|
||||
</bean>
|
||||
|
||||
<dubbo:service
|
||||
interface="project.cms.BannerService"
|
||||
ref="bannerService" />
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
37
comm/Cms/config/applicationContext-cms_admin.xml
Executable file
37
comm/Cms/config/applicationContext-cms_admin.xml
Executable file
@@ -0,0 +1,37 @@
|
||||
<?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="cmsService"
|
||||
class="project.cms.internal.CmsServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
<!-- <property name="pagedDao" ref="pagedDao" /> -->
|
||||
</bean>
|
||||
<bean id="adminCmsService"
|
||||
class="project.cms.internal.AdminCmsServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedDao" ref="pagedDao" />
|
||||
<property name="cmsService" ref="cmsService" />
|
||||
</bean>
|
||||
|
||||
<!-- <bean id="bannerService"
|
||||
class="project.cms.internal.BannerServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean> -->
|
||||
<bean id="adminBannerService"
|
||||
class="project.cms.internal.AdminBannerServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedDao" ref="pagedDao" />
|
||||
</bean>
|
||||
|
||||
<dubbo:reference id="bannerService"
|
||||
interface="project.cms.BannerService" check="false" />
|
||||
|
||||
</beans>
|
||||
23
comm/Cms/config/applicationContext-cms_data.xml
Executable file
23
comm/Cms/config/applicationContext-cms_data.xml
Executable file
@@ -0,0 +1,23 @@
|
||||
<?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="cmsService"
|
||||
class="project.cms.internal.CmsServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
<bean id="cmsLoadCacheService"
|
||||
class="data.loadcache.CmsLoadCacheService">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
11
comm/Cms/config/applicationContext-hibernate.xml
Executable file
11
comm/Cms/config/applicationContext-hibernate.xml
Executable file
@@ -0,0 +1,11 @@
|
||||
|
||||
admin
|
||||
|
||||
<!-- cms -->
|
||||
<value>cmsService</value>
|
||||
<value>adminCmsService</value>
|
||||
<value>adminBannerService</value>
|
||||
api
|
||||
<!-- cms -->
|
||||
<value>cmsService</value>
|
||||
<value>bannerService</value>
|
||||
2
comm/Cms/config/cms.properties
Executable file
2
comm/Cms/config/cms.properties
Executable file
@@ -0,0 +1,2 @@
|
||||
system_cms_language=chinese
|
||||
system_cms_model_list=system,info,help_center,knowledge
|
||||
13
comm/Cms/config/normal.xml
Executable file
13
comm/Cms/config/normal.xml
Executable file
@@ -0,0 +1,13 @@
|
||||
|
||||
admin
|
||||
<action name="adminCmsAction"
|
||||
class="project.cms.web.AdminCmsAction">
|
||||
<result name="list">/cms_list.jsp</result>
|
||||
<result name="add">/cms_add.jsp</result>
|
||||
<result name="update">/cms_update.jsp</result>
|
||||
</action>
|
||||
|
||||
api
|
||||
|
||||
<action name="cms" class="project.cms.web.CmsAction">
|
||||
</action>
|
||||
26
comm/Cms/dbscript/1.0/DDL-MYSQL.SQL
Executable file
26
comm/Cms/dbscript/1.0/DDL-MYSQL.SQL
Executable file
@@ -0,0 +1,26 @@
|
||||
DROP TABLE IF EXISTS `T_CMS`;
|
||||
CREATE TABLE `T_CMS` (
|
||||
`UUID` varchar(32) NOT NULL,
|
||||
`TITLE` varchar(128) NOT NULL COMMENT '标题',
|
||||
`CONTENT` longtext COMMENT '内容',
|
||||
`CREATE_TIME` datetime DEFAULT NULL COMMENT '时间',
|
||||
`MODEL` varchar(32) DEFAULT NULL COMMENT '模块',
|
||||
PRIMARY KEY (`UUID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `T_BANNER`;
|
||||
CREATE TABLE `T_BANNER` (
|
||||
`UUID` varchar(32) NOT NULL,
|
||||
`LANGUAGE` varchar(32) DEFAULT NULL COMMENT '语言',
|
||||
`CONTENT_CODE` varchar(16) DEFAULT NULL,
|
||||
`IMAGE` longtext COMMENT '标题',
|
||||
`URL` varchar(256) DEFAULT NULL,
|
||||
`MODEL` varchar(32) DEFAULT NULL COMMENT '模块',
|
||||
`ON_SHOW` int(2) DEFAULT NULL COMMENT '时间',
|
||||
`SORT_INDEX` int(11) DEFAULT NULL,
|
||||
`CLICK` int(2) DEFAULT NULL,
|
||||
`CREATE_TIME` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`UUID`),
|
||||
KEY `INDEX_MODEL` (`MODEL`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
13
comm/Cms/dbscript/2.1/CMS-DDL-MYSQL.SQL
Executable file
13
comm/Cms/dbscript/2.1/CMS-DDL-MYSQL.SQL
Executable file
@@ -0,0 +1,13 @@
|
||||
DROP TABLE IF EXISTS `T_CMS`;
|
||||
CREATE TABLE `T_CMS` (
|
||||
`UUID` varchar(32) NOT NULL,
|
||||
`TITLE` varchar(128) NOT NULL COMMENT '标题',
|
||||
`CONTENT` longtext COMMENT '内容',
|
||||
`CREATE_TIME` datetime DEFAULT NULL COMMENT '时间',
|
||||
`MODEL` varchar(32) DEFAULT NULL COMMENT '模块',
|
||||
PRIMARY KEY (`UUID`),
|
||||
`LANGUAGE` varchar(32) DEFAULT NULL COMMENT '语言',
|
||||
KEY `INDEX_MODEL` (`MODEL`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE T_CMS ADD `CONTENT_CODE` varchar(16) ;
|
||||
71
comm/Cms/dbscript/2.1/CMS-DML-MYSQL.SQL
Executable file
71
comm/Cms/dbscript/2.1/CMS-DML-MYSQL.SQL
Executable file
File diff suppressed because one or more lines are too long
19
comm/Cms/spring/applicationContext-cms.xml
Executable file
19
comm/Cms/spring/applicationContext-cms.xml
Executable file
@@ -0,0 +1,19 @@
|
||||
<?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="cmsService"
|
||||
class="project.cms.internal.CmsServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
23
comm/Cms/spring/applicationContext-cms_admin.xml
Executable file
23
comm/Cms/spring/applicationContext-cms_admin.xml
Executable file
@@ -0,0 +1,23 @@
|
||||
<?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="adminCmsService"
|
||||
class="project.cms.internal.AdminCmsServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="pagedDao" ref="pagedDao" />
|
||||
<property name="cmsService" ref="cmsService" />
|
||||
</bean>
|
||||
|
||||
<bean id="cmsService" class="project.cms.internal.CmsServiceImpl">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
23
comm/Cms/spring/applicationContext-cms_data.xml
Executable file
23
comm/Cms/spring/applicationContext-cms_data.xml
Executable file
@@ -0,0 +1,23 @@
|
||||
<?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="cmsService"
|
||||
class="project.cms.internal.CmsServiceImpl" >
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
<bean id="cmsLoadCacheService"
|
||||
class="project.data.loadcache.CmsLoadCacheService">
|
||||
<property name="hibernateTemplate" ref="hibernateTemplate" />
|
||||
<property name="redisHandler" ref="redisHandler" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
10
comm/Cms/spring/applicationContext-hibernate.xml
Executable file
10
comm/Cms/spring/applicationContext-hibernate.xml
Executable file
@@ -0,0 +1,10 @@
|
||||
|
||||
admin
|
||||
|
||||
<!-- cms -->
|
||||
<value>cmsService</value>
|
||||
<value>adminCmsService</value>
|
||||
|
||||
api
|
||||
<!-- cms -->
|
||||
<value>cmsService</value>
|
||||
11
comm/Cms/src/project/cms/AdminBannerService.java
Executable file
11
comm/Cms/src/project/cms/AdminBannerService.java
Executable file
@@ -0,0 +1,11 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminBannerService {
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize,String language);
|
||||
|
||||
}
|
||||
21
comm/Cms/src/project/cms/AdminCmsService.java
Executable file
21
comm/Cms/src/project/cms/AdminCmsService.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminCmsService {
|
||||
|
||||
|
||||
public void saveOrUpdate(Cms entity);
|
||||
|
||||
|
||||
public Cms findById(String id);
|
||||
|
||||
public void delete(Cms cms);
|
||||
|
||||
public Map<String, String> getModelDatasDictionary();
|
||||
|
||||
|
||||
Page pagedQuery(int pageNo, int pageSize, String language, String title, String startTime, String endTime, Integer type, Integer status);
|
||||
}
|
||||
39
comm/Cms/src/project/cms/Banner.hbm.xml
Executable file
39
comm/Cms/src/project/cms/Banner.hbm.xml
Executable file
@@ -0,0 +1,39 @@
|
||||
<?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.cms.Banner" table="T_BANNER">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="language" type="java.lang.String">
|
||||
<column name="LANGUAGE" />
|
||||
</property>
|
||||
<property name="content_code" type="java.lang.String">
|
||||
<column name="CONTENT_CODE" />
|
||||
</property>
|
||||
<property name="image" type="java.lang.String">
|
||||
<column name="IMAGE" />
|
||||
</property>
|
||||
<property name="url" type="java.lang.String">
|
||||
<column name="URL" />
|
||||
</property>
|
||||
<property name="model" type="java.lang.String">
|
||||
<column name="MODEL" />
|
||||
</property>
|
||||
<property name="on_show" type="int">
|
||||
<column name="ON_SHOW" />
|
||||
</property>
|
||||
<property name="sort_index" type="int">
|
||||
<column name="SORT_INDEX" />
|
||||
</property>
|
||||
<property name="click" type="int">
|
||||
<column name="CLICK" />
|
||||
</property>
|
||||
<property name="createTime" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
128
comm/Cms/src/project/cms/Banner.java
Executable file
128
comm/Cms/src/project/cms/Banner.java
Executable file
@@ -0,0 +1,128 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
|
||||
public class Banner extends EntityObject implements Comparable<Banner> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8252272898082376329L;
|
||||
|
||||
/**
|
||||
* 语言
|
||||
*/
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* 业务代码, 同种内容 不同语言下的code相同
|
||||
*/
|
||||
private String content_code;
|
||||
/**
|
||||
* 展示图片
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 访问路径
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 是否展示
|
||||
*/
|
||||
private int on_show;
|
||||
/**
|
||||
* 排列顺序(数字相同按时间排,越小排越前)
|
||||
*/
|
||||
private int sort_index;
|
||||
/**
|
||||
* 类型,top:顶部展示,other:其他地方展示,poster:弹窗海报
|
||||
*/
|
||||
private String model;
|
||||
/**
|
||||
* 是否可以点击跳转
|
||||
*/
|
||||
private int click;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public String getContent_code() {
|
||||
return content_code;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public void setContent_code(String content_code) {
|
||||
this.content_code = content_code;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public int getClick() {
|
||||
return click;
|
||||
}
|
||||
|
||||
public void setClick(int click) {
|
||||
this.click = click;
|
||||
}
|
||||
|
||||
public int getSort_index() {
|
||||
return sort_index;
|
||||
}
|
||||
|
||||
public void setSort_index(int sort_index) {
|
||||
this.sort_index = sort_index;
|
||||
}
|
||||
|
||||
public int getOn_show() {
|
||||
return on_show;
|
||||
}
|
||||
|
||||
public void setOn_show(int on_show) {
|
||||
this.on_show = on_show;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Banner paramT) {
|
||||
// TODO Auto-generated method stub
|
||||
return this.sort_index - paramT.getSort_index();
|
||||
}
|
||||
|
||||
}
|
||||
37
comm/Cms/src/project/cms/BannerService.java
Executable file
37
comm/Cms/src/project/cms/BannerService.java
Executable file
@@ -0,0 +1,37 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface BannerService {
|
||||
|
||||
public void save(Banner entity);
|
||||
|
||||
public void update(Banner entity);
|
||||
|
||||
public void delete(String id);
|
||||
|
||||
// public Banner findById(String id);
|
||||
public Banner cacheById(String id);
|
||||
|
||||
/**
|
||||
* 获取cms根据相关模块和国际化语言
|
||||
*
|
||||
* @param model
|
||||
* @param language
|
||||
* @return
|
||||
*/
|
||||
public List<Banner> cacheListByModelAndLanguage(String model, String language);
|
||||
|
||||
/**
|
||||
* 获取cms根据相关业务code和国际化语言
|
||||
*
|
||||
* @param contentCode
|
||||
* @param language
|
||||
* @return
|
||||
*/
|
||||
public Banner cacheByCodeAndLanguage(String contentCode, String language);
|
||||
|
||||
public Map<String,Object> bindOne(Banner entity);
|
||||
|
||||
}
|
||||
30
comm/Cms/src/project/cms/Cms.hbm.xml
Executable file
30
comm/Cms/src/project/cms/Cms.hbm.xml
Executable file
@@ -0,0 +1,30 @@
|
||||
<?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.cms.Cms" table="T_CMS">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="title" type="java.lang.String">
|
||||
<column name="TITLE" />
|
||||
</property>
|
||||
<property name="content" type="java.lang.String">
|
||||
<column name="CONTENT" />
|
||||
</property>
|
||||
<property name="createTime" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
<property name="language" type="java.lang.String">
|
||||
<column name="LANGUAGE" />
|
||||
</property>
|
||||
<property name="type" type="java.lang.Integer">
|
||||
<column name="TYPE" />
|
||||
</property>
|
||||
<property name="status" type="java.lang.Integer">
|
||||
<column name="STATUS" />
|
||||
</property>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
81
comm/Cms/src/project/cms/Cms.java
Executable file
81
comm/Cms/src/project/cms/Cms.java
Executable file
@@ -0,0 +1,81 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Cms extends EntityObject {
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* 模块所属类型 '类型 0-公告管理,1-文章管理'
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* '0-启用,1-禁用'
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
22
comm/Cms/src/project/cms/CmsRedisKeys.java
Executable file
22
comm/Cms/src/project/cms/CmsRedisKeys.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package project.cms;
|
||||
|
||||
public class CmsRedisKeys {
|
||||
/**
|
||||
* CMS,查询语言的map
|
||||
*/
|
||||
public final static String CMS_LANGUAGE = "CMS_LANGUAGE_";
|
||||
/**
|
||||
* CMS,language+contentCode 做key
|
||||
*/
|
||||
public final static String CMS_ID = "CMS_ID";
|
||||
|
||||
/**
|
||||
* Banner,查询语言的map
|
||||
*/
|
||||
public final static String Banner_LANGUAGE = "BANNER_LANGUAGE_";
|
||||
/**
|
||||
* Banner,language+contentCode 做key
|
||||
*/
|
||||
public final static String Banner_LANGUAGE_CONTENTCODE = "BANNER_LANGUAGE_CONTENTCODE_";
|
||||
|
||||
}
|
||||
34
comm/Cms/src/project/cms/CmsService.java
Executable file
34
comm/Cms/src/project/cms/CmsService.java
Executable file
@@ -0,0 +1,34 @@
|
||||
package project.cms;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CmsService {
|
||||
|
||||
public void saveOrUpdate(Cms entity);
|
||||
|
||||
public void delete(Cms cms);
|
||||
|
||||
/**
|
||||
* 获取cms根据相关模块和国际化语言
|
||||
* @param language
|
||||
* @return
|
||||
*/
|
||||
public List<Cms> cacheListByModelAndLanguage(String language);
|
||||
|
||||
/**
|
||||
* 根据国际化语言获取cms
|
||||
* @param lang
|
||||
* @return
|
||||
*/
|
||||
public List<Cms> findCmsListByLang(String lang);
|
||||
|
||||
/**
|
||||
* 获取cms根据相关业务code和国际化语言
|
||||
*
|
||||
* @param contentCode
|
||||
* @param language
|
||||
* @return
|
||||
*/
|
||||
public Cms cacheByCodeAndLanguage(String contentCode, String language);
|
||||
|
||||
}
|
||||
138
comm/Cms/src/project/cms/PropertiesUtilCms.java
Executable file
138
comm/Cms/src/project/cms/PropertiesUtilCms.java
Executable file
@@ -0,0 +1,138 @@
|
||||
package project.cms;
|
||||
|
||||
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Properties;
|
||||
|
||||
import kernel.util.JsonUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import project.mall.seller.dto.MallLevelCondExpr;
|
||||
|
||||
/**
|
||||
* 读取Properties综合类,默认绑定到classpath下的config.properties文件。
|
||||
*/
|
||||
public class PropertiesUtilCms {
|
||||
private static Log log = LogFactory.getLog(PropertiesUtilCms.class);
|
||||
private static String CONFIG_FILENAME = "config/cms.properties";
|
||||
private static Properties prop = null;
|
||||
|
||||
public PropertiesUtilCms() {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
};
|
||||
|
||||
private synchronized static void loadProperties() {
|
||||
byte buff[]=null;
|
||||
try {
|
||||
//Open the props file
|
||||
InputStream is=PropertiesUtilCms.class.getResourceAsStream("/" + CONFIG_FILENAME);
|
||||
prop = new Properties();
|
||||
//Read in the stored properties
|
||||
prop.load(is);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("读取配置文件失败!!!");
|
||||
prop = null;
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到属性值
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key) {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
String value = prop.getProperty(key);
|
||||
if(value ==null){
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到内容包含汉字的属性值
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getGBKProperty(String key) {
|
||||
String value = getProperty(key);
|
||||
try {
|
||||
value = new String(value.getBytes("ISO8859-1"),"GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
|
||||
if(value ==null){
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到属性值,
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
String value = prop.getProperty(key, defaultValue);
|
||||
if(value ==null){
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到内容包含汉字的属性值,如果不存在则使用默认值
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getGBKProperty(String key, String defaultValue) {
|
||||
try {
|
||||
defaultValue = new String(defaultValue.getBytes("GBK"), "ISO8859-1");
|
||||
String value = getProperty(key, defaultValue);
|
||||
value = new String(value.getBytes("ISO8859-1"), "GBK");
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUTFProperty(String key, String defaultValue) {
|
||||
try {
|
||||
defaultValue = new String(defaultValue.getBytes("UTF-8"),
|
||||
"ISO8859-1");
|
||||
String value = getProperty(key, defaultValue);
|
||||
value = new String(value.getBytes("ISO8859-1"), "UTF-8");
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String json = "{\"params\":[{\"code\":\"rechargeAmount\",\"title\":\"运行资金\",\"value\":5000},{\"code\":\"popularizeUserCount\",\"title\":\"分店数\",\"value\":3}],\"expression\":\"popularizeUserCount >= 3 || rechargeAmount >= 5000\"}";
|
||||
MallLevelCondExpr mallLevelCondExpr = JsonUtils.json2Object(json, MallLevelCondExpr.class);
|
||||
}
|
||||
}
|
||||
47
comm/Cms/src/project/cms/data/loadcache/CmsLoadCacheService.java
Executable file
47
comm/Cms/src/project/cms/data/loadcache/CmsLoadCacheService.java
Executable file
@@ -0,0 +1,47 @@
|
||||
package project.cms.data.loadcache;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import project.cms.Cms;
|
||||
import project.cms.CmsRedisKeys;
|
||||
import project.redis.RedisHandler;
|
||||
|
||||
public class CmsLoadCacheService extends HibernateDaoSupport {
|
||||
private static final Log logger = LogFactory.getLog(CmsLoadCacheService.class);
|
||||
|
||||
private RedisHandler redisHandler;
|
||||
|
||||
public void loadcache() {
|
||||
load();
|
||||
logger.info("完成Cms数据加载redis");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
StringBuffer queryString = new StringBuffer(" FROM Cms WHERE STATUS = 0");
|
||||
List<Cms> list = (List<Cms>)this.getHibernateTemplate().find(queryString.toString());
|
||||
for (Cms cms : list) {
|
||||
redisHandler.setSync(CmsRedisKeys.CMS_ID + cms.getId(), cms);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(list)){
|
||||
Map<String, List<Cms>> collect = list.stream().collect(Collectors.groupingBy(Cms::getLanguage));
|
||||
for (Map.Entry<String, List<Cms>> entry : collect.entrySet()) {
|
||||
redisHandler.setSync(CmsRedisKeys.CMS_LANGUAGE + entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
}
|
||||
40
comm/Cms/src/project/cms/internal/AdminBannerServiceImpl.java
Executable file
40
comm/Cms/src/project/cms/internal/AdminBannerServiceImpl.java
Executable file
@@ -0,0 +1,40 @@
|
||||
package project.cms.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.cms.AdminBannerService;
|
||||
|
||||
public class AdminBannerServiceImpl extends HibernateDaoSupport implements AdminBannerService {
|
||||
|
||||
private PagedQueryDao pagedDao;
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String language) {
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM Banner WHERE 1=1 ");
|
||||
Map parameters = new HashMap();
|
||||
|
||||
if (StringUtils.isNotEmpty(language)) {
|
||||
queryString.append("AND language=:language ");
|
||||
parameters.put("language", language);
|
||||
}
|
||||
// if (StringUtils.isNotEmpty(title)) {
|
||||
// queryString.append("AND title like:title ");
|
||||
// parameters.put("title", "%" + title + "%");
|
||||
// }
|
||||
queryString.append(" order by sort_index ASC, createTime desc ");
|
||||
Page page = this.pagedDao.pagedQueryHql(pageNo, pageSize, queryString.toString(), parameters);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
public void setPagedDao(PagedQueryDao pagedDao) {
|
||||
this.pagedDao = pagedDao;
|
||||
}
|
||||
|
||||
}
|
||||
99
comm/Cms/src/project/cms/internal/AdminCmsServiceImpl.java
Executable file
99
comm/Cms/src/project/cms/internal/AdminCmsServiceImpl.java
Executable file
@@ -0,0 +1,99 @@
|
||||
package project.cms.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import kernel.util.DateUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.cms.*;
|
||||
import project.redis.RedisHandler;
|
||||
|
||||
public class AdminCmsServiceImpl extends HibernateDaoSupport implements AdminCmsService {
|
||||
|
||||
private CmsService cmsService;
|
||||
private PagedQueryDao pagedDao;
|
||||
|
||||
private RedisHandler redisHandler;
|
||||
|
||||
@Override
|
||||
public Page pagedQuery(int pageNo, int pageSize, String language, String title, String startTime, String endTime, Integer type, Integer status) {
|
||||
StringBuffer queryString = new StringBuffer(" SELECT ");
|
||||
queryString.append(" UUID id, TITLE title, CONTENT content, CREATE_TIME createTime, LANGUAGE language, TYPE type, STATUS status FROM T_CMS WHERE 1=1 ");
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
if (StringUtils.isNotEmpty(language)) {
|
||||
queryString.append("AND LANGUAGE=:language ");
|
||||
parameters.put("language", language);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(title)) {
|
||||
queryString.append("AND TITLE like:title ");
|
||||
parameters.put("title", "%" + title + "%");
|
||||
}
|
||||
if (-2 != status) {
|
||||
queryString.append(" and STATUS =:status");
|
||||
parameters.put("status", status);
|
||||
}
|
||||
if (-2 != type) {
|
||||
queryString.append(" and TYPE =:type");
|
||||
parameters.put("type", type);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(startTime)) {
|
||||
queryString.append(" AND DATE(CREATE_TIME) >= DATE(:startTime) ");
|
||||
parameters.put("startTime", DateUtils.toDate(startTime));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(endTime)) {
|
||||
queryString.append(" AND DATE(CREATE_TIME) <= DATE(:endTime) ");
|
||||
parameters.put("endTime", DateUtils.toDate(endTime));
|
||||
}
|
||||
queryString.append(" order by CREATE_TIME desc ");
|
||||
Page page = this.pagedDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
public void saveOrUpdate(Cms entity) {
|
||||
cmsService.saveOrUpdate(entity);
|
||||
redisHandler.setSync(CmsRedisKeys.CMS_ID + entity.getId(),entity);
|
||||
}
|
||||
|
||||
public Cms findById(String id) {
|
||||
Cms cms = (Cms) redisHandler.get(CmsRedisKeys.CMS_ID + id);
|
||||
if (Objects.isNull(cms)){
|
||||
cms = getHibernateTemplate().get(Cms.class, id);
|
||||
redisHandler.setSync(CmsRedisKeys.CMS_ID + id, cms);
|
||||
}
|
||||
return cms;
|
||||
}
|
||||
|
||||
public Map<String, String> getModelDatasDictionary() {
|
||||
String datas = PropertiesUtilCms.getProperty("system_cms_model_list");
|
||||
String[] splits = datas.split(",");
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (String data : splits) {
|
||||
map.put(data, data);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void delete(Cms cms) {
|
||||
cmsService.delete(cms);
|
||||
}
|
||||
|
||||
public void setCmsService(CmsService cmsService) {
|
||||
this.cmsService = cmsService;
|
||||
}
|
||||
|
||||
public void setPagedDao(PagedQueryDao pagedDao) {
|
||||
this.pagedDao = pagedDao;
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
}
|
||||
96
comm/Cms/src/project/cms/internal/BannerServiceImpl.java
Executable file
96
comm/Cms/src/project/cms/internal/BannerServiceImpl.java
Executable file
@@ -0,0 +1,96 @@
|
||||
package project.cms.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.criterion.DetachedCriteria;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.DateUtils;
|
||||
import project.cms.Banner;
|
||||
import project.cms.BannerService;
|
||||
|
||||
public class BannerServiceImpl extends HibernateDaoSupport implements BannerService {
|
||||
|
||||
/**
|
||||
* base64过大,不适合做redis
|
||||
*/
|
||||
private Map<String, Banner> cache = new ConcurrentHashMap<String, Banner>();
|
||||
|
||||
public void init() {
|
||||
DetachedCriteria query = DetachedCriteria.forClass(Banner.class);
|
||||
List<Banner> list = (List<Banner>) getHibernateTemplate().findByCriteria(query);
|
||||
for (Banner banner : list) {
|
||||
cache.put(banner.getId().toString(), banner);
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Banner entity) {
|
||||
|
||||
this.getHibernateTemplate().save(entity);
|
||||
cache.put(entity.getId().toString(), entity);
|
||||
}
|
||||
|
||||
public void update(Banner entity) {
|
||||
getHibernateTemplate().update(entity);
|
||||
cache.put(entity.getId().toString(), entity);
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
Banner entity = cacheById(id);
|
||||
getHibernateTemplate().delete(entity);
|
||||
cache.remove(id);
|
||||
}
|
||||
|
||||
public Banner cacheById(String id) {
|
||||
return cache.get(id);
|
||||
// return (Banner) getHibernateTemplate().get(Banner.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Banner> cacheListByModelAndLanguage(String model, String language) {
|
||||
// TODO Auto-generated method stub
|
||||
List<Banner> list = new ArrayList<Banner>();
|
||||
for (Banner banner : cache.values()) {
|
||||
if (banner.getOn_show() == 1 && model.equals(banner.getModel()) && language.equals(banner.getLanguage())) {
|
||||
list.add(banner);
|
||||
}
|
||||
}
|
||||
Collections.sort(list);
|
||||
// List<Banner> list = this.getHibernateTemplate().find(" FROM Banner WHERE on_show=1 AND model=? AND language=? ORDER BY sort_index ASC",new Object[] {model,language});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Banner cacheByCodeAndLanguage(String contentCode, String language) {
|
||||
// TODO Auto-generated method stub
|
||||
for (Banner banner : cache.values()) {
|
||||
if (banner.getOn_show() == 1 && contentCode.equals(banner.getContent_code())
|
||||
&& language.equals(banner.getLanguage())) {
|
||||
return banner;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// List<Banner> list = this.getHibernateTemplate().find(" FROM Banner WHERE on_show=1 AND content_code=? AND language=?",new Object[] {contentCode,language});
|
||||
// return CollectionUtils.isEmpty(list)?null:list.get(0);
|
||||
}
|
||||
|
||||
public Map<String, Object> bindOne(Banner entity) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("content_code", entity.getContent_code());
|
||||
result.put("image", entity.getImage());
|
||||
result.put("index", entity.getSort_index());
|
||||
result.put("language", entity.getLanguage());
|
||||
result.put("model", entity.getModel());
|
||||
result.put("url", entity.getUrl());
|
||||
result.put("click", entity.getClick());
|
||||
result.put("create_time", DateUtils.format(entity.getCreateTime(), DateUtils.DF_yyyyMMddHHmm));
|
||||
result.put("id", entity.getId());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
107
comm/Cms/src/project/cms/internal/CmsServiceImpl.java
Executable file
107
comm/Cms/src/project/cms/internal/CmsServiceImpl.java
Executable file
@@ -0,0 +1,107 @@
|
||||
package project.cms.internal;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import kernel.exception.BusinessException;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
import project.cms.Cms;
|
||||
import project.cms.CmsRedisKeys;
|
||||
import project.cms.CmsService;
|
||||
import project.redis.RedisHandler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class CmsServiceImpl extends HibernateDaoSupport implements CmsService {
|
||||
private RedisHandler redisHandler;
|
||||
|
||||
public void saveOrUpdate(Cms entity) {
|
||||
getHibernateTemplate().saveOrUpdate(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setCmsLanguageList(String Language){
|
||||
List<Cms> cmsList = findCmsList(Language);
|
||||
if (CollectionUtils.isNotEmpty(cmsList)){
|
||||
redisHandler.setSync(CmsRedisKeys.CMS_LANGUAGE+Language,cmsList);
|
||||
} else {
|
||||
redisHandler.remove(CmsRedisKeys.CMS_LANGUAGE+Language);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Cms> findCmsList(String lang) {
|
||||
Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Cms.class);
|
||||
if(!kernel.util.StringUtils.isEmptyString(lang)){
|
||||
criteria.add( Restrictions.eq("language", lang) );
|
||||
}
|
||||
criteria.add( Restrictions.eq("status", 0 ) );
|
||||
if(CollectionUtils.isNotEmpty(criteria.list())){
|
||||
return criteria.list();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Cms> findCmsListByLang(String lang) {
|
||||
Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Cms.class);
|
||||
if(!kernel.util.StringUtils.isEmptyString(lang)){
|
||||
criteria.add( Restrictions.eq("language", lang) );
|
||||
}
|
||||
criteria.add( Restrictions.eq("status", 0 ) );
|
||||
criteria.addOrder(Order.desc("createTime"));
|
||||
if(CollectionUtils.isNotEmpty(criteria.list())){
|
||||
return criteria.list();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Cms cacheByCodeAndLanguage(String contentCode, String language) {
|
||||
Cms cms = (Cms) redisHandler.get(CmsRedisKeys.CMS_ID + language);
|
||||
return cms;
|
||||
}
|
||||
|
||||
public List<Cms> cacheListByModelAndLanguage(String language) {
|
||||
language = StringUtils.isEmpty(language) ? "en" : language;
|
||||
|
||||
JSONArray jsonArray = (JSONArray) redisHandler.get(CmsRedisKeys.CMS_LANGUAGE + language);
|
||||
if (null == jsonArray) {
|
||||
throw new BusinessException("无该语种的配置");
|
||||
}
|
||||
List<Cms> cacheLanguage = jsonArray.toJavaList(Cms.class);
|
||||
// 按时间降序
|
||||
Collections.sort(cacheLanguage, new Comparator<Cms>() {
|
||||
@Override
|
||||
public int compare(Cms paramT1, Cms paramT2) {
|
||||
// TODO Auto-generated method stub
|
||||
return -paramT1.getCreateTime().compareTo(paramT2.getCreateTime());
|
||||
}
|
||||
|
||||
});
|
||||
return cacheLanguage;
|
||||
}
|
||||
|
||||
public void delete(Cms entity) {
|
||||
this.getHibernateTemplate().delete(entity);
|
||||
// if (entity != null) {
|
||||
|
||||
// redisHandler.remove(CmsRedisKeys.CMS_ID+entity.getId());
|
||||
// List<Cms> cmsList = findCmsList(entity.getLanguage());
|
||||
// if (CollectionUtils.isNotEmpty(cmsList)){
|
||||
// redisHandler.setSync(CmsRedisKeys.CMS_LANGUAGE+entity.getLanguage(),cmsList);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
470
comm/Cms/src/project/cms/web/AdminBannerAction.java
Executable file
470
comm/Cms/src/project/cms/web/AdminBannerAction.java
Executable file
@@ -0,0 +1,470 @@
|
||||
package project.cms.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.security.providers.encoding.PasswordEncoder;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.ImageUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.cms.AdminBannerService;
|
||||
import project.cms.Banner;
|
||||
import project.cms.BannerService;
|
||||
import project.cms.PropertiesUtilCms;
|
||||
import project.log.LogService;
|
||||
import security.Role;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
public class AdminBannerAction extends PageActionSupport {
|
||||
private static final Log logger = LogFactory.getLog(AdminBannerAction.class);
|
||||
private static final long serialVersionUID = 5666899648868642390L;
|
||||
private AdminBannerService adminBannerService;
|
||||
private BannerService bannerService;
|
||||
private SecUserService secUserService;
|
||||
private LogService logService;
|
||||
private PasswordEncoder passwordEncoder;
|
||||
private String id;
|
||||
/**
|
||||
* 类型,top:顶部展示,other:其他地方展示
|
||||
*/
|
||||
private String model;
|
||||
/**
|
||||
* 语言
|
||||
*/
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* 业务代码
|
||||
*/
|
||||
private String content_code;
|
||||
/**
|
||||
* 展示图片
|
||||
*/
|
||||
private String img;
|
||||
/**
|
||||
* 访问路径
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 是否展示
|
||||
*/
|
||||
private int on_show;
|
||||
/**
|
||||
* 排列顺序(数字相同按时间排,越小排越前)
|
||||
*/
|
||||
private int sort_index;
|
||||
|
||||
/**
|
||||
* 是否可以点击跳转
|
||||
*/
|
||||
private int click;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String para_language;
|
||||
|
||||
private String para_title;
|
||||
|
||||
private File fileName;
|
||||
|
||||
private Map<String, String> modelMap = Constants.BANNER_MODEL;
|
||||
private Map<String, String> languageMap = Constants.LANGUAGE;
|
||||
private String login_safeword;
|
||||
|
||||
public String list() {
|
||||
this.pageSize = 30;
|
||||
this.page = this.adminBannerService.pagedQuery(this.pageNo, this.pageSize, this.para_language);
|
||||
for (Banner banner : (List<Banner>) this.page.getElements()) {
|
||||
banner.setLanguage(Constants.LANGUAGE.get(banner.getLanguage()));
|
||||
banner.setModel(Constants.BANNER_MODEL.get(banner.getModel()));
|
||||
}
|
||||
return "list";
|
||||
|
||||
}
|
||||
|
||||
public String toAdd() {
|
||||
// this.modelMap = this.adminBannerService.getModelDatasDictionary();
|
||||
// this.modelMap = Constants.CMS_MODEL;
|
||||
// this.languageMap = Constants.LANGUAGE;
|
||||
if (!checkIsRoot()) {
|
||||
this.error = "root 权限下才可添加";
|
||||
return list();
|
||||
}
|
||||
// if (!StringUtils.isNullOrEmpty(this.id)) {
|
||||
// Banner entity = this.adminBannerService.findById(this.id);
|
||||
// if (null == entity) {
|
||||
// this.error = "内容不存在或已删除";
|
||||
// return "add";
|
||||
// }
|
||||
// this.title = entity.getTitle();
|
||||
// this.content = entity.getContent();
|
||||
// this.model = entity.getModel();
|
||||
// this.language = entity.getLanguage();
|
||||
// this.content_code = entity.getContent_code();
|
||||
// } else {
|
||||
language = PropertiesUtilCms.getProperty("system_cms_language");
|
||||
// }
|
||||
return "add";
|
||||
}
|
||||
|
||||
public String add() {
|
||||
try {
|
||||
this.error = verif();
|
||||
if (!StringUtils.isNullOrEmpty(this.error)) {
|
||||
return "add";
|
||||
}
|
||||
if (!checkIsRoot()) {
|
||||
throw new BusinessException("root 权限下才可添加");
|
||||
}
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
checkLoginSafeword(sec, this.getUsername_login(), this.login_safeword);
|
||||
Banner entity = new Banner();
|
||||
// if (!StringUtils.isNullOrEmpty(this.id)) {
|
||||
// entity = this.adminBannerService.findById(this.id);
|
||||
//
|
||||
// } else {
|
||||
// entity.setCreateTime(new Date());
|
||||
// }
|
||||
if (StringUtils.isEmptyString(this.model))
|
||||
throw new BusinessException("请选择模块");
|
||||
if (StringUtils.isEmptyString(this.language))
|
||||
throw new BusinessException("请选择语言");
|
||||
if (StringUtils.isEmptyString(this.content_code))
|
||||
throw new BusinessException("请填写业务码");
|
||||
entity.setCreateTime(new Date());
|
||||
entity.setModel(this.model);
|
||||
entity.setLanguage(this.language);
|
||||
entity.setContent_code(this.content_code);
|
||||
entity.setUrl(url);
|
||||
entity.setClick(click);
|
||||
entity.setOn_show(on_show);
|
||||
entity.setSort_index(sort_index);
|
||||
entity.setImage(ImageUtils.reduceImg(fileName, 1f));
|
||||
// ImageUtils.
|
||||
this.bannerService.save(entity);
|
||||
String log = MessageFormat.format(
|
||||
"ip:" + this.getIp() + ",管理员新增banner,id:{0},路径:{1},语言:{2},模块:{3},业务代码:{4},索引:{5},可否点击:{6},是否展示:{7}", entity.getId(),
|
||||
entity.getUrl(), entity.getLanguage(), entity.getModel(), entity.getContent_code(),
|
||||
entity.getSort_index(),entity.getClick(),entity.getOn_show());
|
||||
saveLog(sec, this.username_login, log);
|
||||
this.message = "操作成功";
|
||||
} catch (BusinessException e) {
|
||||
this.error = e.getMessage();
|
||||
return toAdd();
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
this.error = ("[ERROR] 服务器错误");
|
||||
return toAdd();
|
||||
}
|
||||
return list();
|
||||
}
|
||||
|
||||
public String toUpdate() {
|
||||
if (!StringUtils.isNullOrEmpty(this.id)) {
|
||||
Banner entity = this.bannerService.cacheById(this.id);
|
||||
if (null == entity) {
|
||||
this.error = "内容不存在或已删除";
|
||||
return list();
|
||||
}
|
||||
// this.title = entity.getTitle();
|
||||
// this.content = entity.getContent();
|
||||
this.img = entity.getImage();
|
||||
this.on_show = entity.getOn_show();
|
||||
this.click = entity.getClick();
|
||||
this.sort_index = entity.getSort_index();
|
||||
if (this.checkIsRoot()) {
|
||||
this.model = entity.getModel();
|
||||
this.language = entity.getLanguage();
|
||||
this.content_code = entity.getContent_code();
|
||||
this.url = entity.getUrl();
|
||||
}
|
||||
} else {
|
||||
this.error = "内容不存在或已删除";
|
||||
return list();
|
||||
}
|
||||
return "update";
|
||||
}
|
||||
|
||||
public String update() {
|
||||
try {
|
||||
this.error = verif();
|
||||
if (!StringUtils.isNullOrEmpty(this.error)) {
|
||||
return "update";
|
||||
}
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
checkLoginSafeword(sec, this.getUsername_login(), this.login_safeword);
|
||||
|
||||
Banner entity = new Banner();
|
||||
if (!StringUtils.isNullOrEmpty(this.id)) {
|
||||
entity = this.bannerService.cacheById(this.id);
|
||||
if (null == entity)
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
} else {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
String log = MessageFormat.format(
|
||||
"ip:" + this.getIp() + ",管理员修改banner,id:{0},原路径:{1},原语言:{2},原模块:{3},原业务代码:{4},原索引:{5},原可否点击:{6},原是否展示:{7}",
|
||||
entity.getId(), entity.getUrl(), entity.getLanguage(), entity.getModel(), entity.getContent_code(),
|
||||
entity.getSort_index(),entity.getClick(),entity.getOn_show());
|
||||
// entity.setTitle(this.title);
|
||||
// entity.setContent(this.content);
|
||||
entity.setClick(click);
|
||||
entity.setOn_show(on_show);
|
||||
entity.setSort_index(sort_index);
|
||||
if(fileName!=null) {
|
||||
entity.setImage(ImageUtils.reduceImg(fileName, 1f));
|
||||
}
|
||||
if (this.checkIsRoot()) {
|
||||
if (StringUtils.isEmptyString(this.model))
|
||||
throw new BusinessException("请选择模块");
|
||||
if (StringUtils.isEmptyString(this.language))
|
||||
throw new BusinessException("请选择语言");
|
||||
if (StringUtils.isEmptyString(this.content_code))
|
||||
throw new BusinessException("请填写业务码");
|
||||
entity.setModel(this.model);
|
||||
entity.setLanguage(this.language);
|
||||
entity.setContent_code(this.content_code);
|
||||
entity.setUrl(url);
|
||||
}
|
||||
this.bannerService.update(entity);
|
||||
log += MessageFormat.format(",新路径:{0},新语言:{1},新模块:{2},新业务代码:{3},新索引:{4},新可否点击:{5},新是否展示:{6}", entity.getUrl(),
|
||||
entity.getLanguage(), entity.getModel(), entity.getContent_code(), entity.getSort_index(),entity.getClick(),entity.getOn_show());
|
||||
saveLog(sec, this.username_login, log);
|
||||
this.message = "操作成功";
|
||||
} catch (BusinessException e) {
|
||||
this.error = e.getMessage();
|
||||
return toUpdate();
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
this.error = ("[ERROR] 服务器错误");
|
||||
return toUpdate();
|
||||
}
|
||||
return list();
|
||||
}
|
||||
|
||||
private boolean checkIsRoot() {
|
||||
String username = this.getUsername_login();
|
||||
// root才可以改动
|
||||
SecUser secUser = secUserService.findUserByLoginName(username);
|
||||
for (Role role : secUser.getRoles()) {
|
||||
if (Constants.SECURITY_ROLE_ROOT.equals(role.getRoleName())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
public String delete() {
|
||||
try {
|
||||
if (!checkIsRoot()) {
|
||||
throw new BusinessException("权限不足");
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(this.id)) {
|
||||
throw new BusinessException("请传入id");
|
||||
}
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
checkLoginSafeword(sec, this.getUsername_login(), this.login_safeword);
|
||||
Banner entity = this.bannerService.cacheById(this.id);
|
||||
if (null == entity) {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
this.bannerService.delete(this.id);
|
||||
String log = MessageFormat.format(
|
||||
"ip:" + this.getIp() + ",管理员删除banner,id:{0},路径:{1},语言:{2},模块:{3},业务代码:{4},索引:{5},可否点击:{6},是否展示:{7}", entity.getId(),
|
||||
entity.getUrl(), entity.getLanguage(), entity.getModel(), entity.getContent_code(),
|
||||
entity.getSort_index(),entity.getClick(),entity.getOn_show());
|
||||
saveLog(sec, this.username_login, log);
|
||||
this.message = "操作成功";
|
||||
} catch (BusinessException e) {
|
||||
this.error = e.getMessage();
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
this.error = ("[ERROR] 服务器错误");
|
||||
}
|
||||
return list();
|
||||
}
|
||||
|
||||
public String verif() {
|
||||
if (StringUtils.isNullOrEmpty(this.img)) {
|
||||
return "请上传图片!";
|
||||
}
|
||||
// if (this.index < 0) {
|
||||
// return "请输入正确的排序索引!";
|
||||
// }
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录人资金密码
|
||||
*
|
||||
* @param operatorUsername
|
||||
* @param loginSafeword
|
||||
*/
|
||||
protected void checkLoginSafeword(SecUser secUser, String operatorUsername, String loginSafeword) {
|
||||
// SecUser sec = this.secUserService.findUserByLoginName(operatorUsername);
|
||||
String sysSafeword = secUser.getSafeword();
|
||||
String safeword_md5 = passwordEncoder.encodePassword(loginSafeword, operatorUsername);
|
||||
if (!safeword_md5.equals(sysSafeword)) {
|
||||
throw new BusinessException("登录人资金密码错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setAdminBannerService(AdminBannerService adminBannerService) {
|
||||
this.adminBannerService = adminBannerService;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public Map<String, String> getModelMap() {
|
||||
return modelMap;
|
||||
}
|
||||
|
||||
public void setModelMap(Map<String, String> modelMap) {
|
||||
this.modelMap = modelMap;
|
||||
}
|
||||
|
||||
public String getPara_language() {
|
||||
return para_language;
|
||||
}
|
||||
|
||||
public void setPara_language(String para_language) {
|
||||
this.para_language = para_language;
|
||||
}
|
||||
|
||||
public String getPara_title() {
|
||||
return para_title;
|
||||
}
|
||||
|
||||
public void setPara_title(String para_title) {
|
||||
this.para_title = para_title;
|
||||
}
|
||||
|
||||
public Map<String, String> getLanguageMap() {
|
||||
return languageMap;
|
||||
}
|
||||
|
||||
public void setLanguageMap(Map<String, String> languageMap) {
|
||||
this.languageMap = languageMap;
|
||||
}
|
||||
|
||||
public String getContent_code() {
|
||||
return content_code;
|
||||
}
|
||||
|
||||
public void setContent_code(String content_code) {
|
||||
this.content_code = content_code;
|
||||
}
|
||||
|
||||
public void setSecUserService(SecUserService secUserService) {
|
||||
this.secUserService = secUserService;
|
||||
}
|
||||
|
||||
public void setLogService(LogService logService) {
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public void setLogin_safeword(String login_safeword) {
|
||||
this.login_safeword = login_safeword;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public int getClick() {
|
||||
return click;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
public void setClick(int click) {
|
||||
this.click = click;
|
||||
}
|
||||
|
||||
public void setBannerService(BannerService bannerService) {
|
||||
this.bannerService = bannerService;
|
||||
}
|
||||
|
||||
public void setFileName(File fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public int getOn_show() {
|
||||
return on_show;
|
||||
}
|
||||
|
||||
public void setOn_show(int on_show) {
|
||||
this.on_show = on_show;
|
||||
}
|
||||
|
||||
public int getSort_index() {
|
||||
return sort_index;
|
||||
}
|
||||
|
||||
public void setSort_index(int sort_index) {
|
||||
this.sort_index = sort_index;
|
||||
}
|
||||
|
||||
// public void setFile(File file) {
|
||||
// this.file = file;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
110
comm/Cms/src/project/cms/web/BannerAction.java
Executable file
110
comm/Cms/src/project/cms/web/BannerAction.java
Executable file
@@ -0,0 +1,110 @@
|
||||
package project.cms.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
// import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.web.BaseAction;
|
||||
import kernel.web.ResultObject;
|
||||
import project.cms.Banner;
|
||||
import project.cms.BannerService;
|
||||
|
||||
public class BannerAction extends BaseAction {
|
||||
|
||||
private static Log logger = LogFactory.getLog(BannerAction.class);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7047628687006590684L;
|
||||
private BannerService bannerService;
|
||||
private String id;
|
||||
private String model;
|
||||
private String language;
|
||||
/**
|
||||
* 业务代码, 同种内容 不同语言下的code相同
|
||||
*/
|
||||
private String content_code;
|
||||
|
||||
// public String get() throws IOException {
|
||||
// HttpServletResponse response = ServletActionContext.getResponse();
|
||||
// response.setContentType("application/json;charset=UTF-8");
|
||||
// response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// ResultObject resultObject = new ResultObject();
|
||||
// PrintWriter out = response.getWriter();
|
||||
// Map<String, Object> data = new HashMap<String, Object>();
|
||||
// try {
|
||||
// Banner banner = bannerService.cacheByCodeAndLanguage(this.content_code, this.language);
|
||||
// resultObject.setData(bannerService.bindOne(banner));
|
||||
// } catch (BusinessException e) {
|
||||
// resultObject.setCode("1");
|
||||
// resultObject.setMsg(e.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// resultObject.setCode("1");
|
||||
// resultObject.setMsg("程序错误");
|
||||
// logger.error("error:", e);
|
||||
// }
|
||||
// this.result = JsonUtils.getJsonString(resultObject);
|
||||
// out.println(this.result);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public String list() throws IOException {
|
||||
// HttpServletResponse response = ServletActionContext.getResponse();
|
||||
// response.setContentType("application/json;charset=UTF-8");
|
||||
// response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// ResultObject resultObject = new ResultObject();
|
||||
// PrintWriter out = response.getWriter();
|
||||
// try {
|
||||
// List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
|
||||
// List<Banner> cacheListByModel = bannerService.cacheListByModelAndLanguage(this.model, this.language);
|
||||
//
|
||||
// for (Banner banner : cacheListByModel) {
|
||||
// result.add(bannerService.bindOne(banner));
|
||||
// }
|
||||
// resultObject.setData(result);
|
||||
// } catch (BusinessException e) {
|
||||
// resultObject.setCode("1");
|
||||
// resultObject.setMsg(e.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// resultObject.setCode("1");
|
||||
// resultObject.setMsg("程序错误");
|
||||
// logger.error("error:", e);
|
||||
// }
|
||||
// this.result = JsonUtils.getJsonString(resultObject);
|
||||
// out.println(this.result);
|
||||
// return null;
|
||||
// }
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public void setContent_code(String content_code) {
|
||||
this.content_code = content_code;
|
||||
}
|
||||
|
||||
public void setBannerService(BannerService bannerService) {
|
||||
this.bannerService = bannerService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
389
comm/Cms/src/project/web/admin/AdminCmsController.java
Executable file
389
comm/Cms/src/project/web/admin/AdminCmsController.java
Executable file
@@ -0,0 +1,389 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.StringUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.cms.AdminCmsService;
|
||||
import project.cms.Cms;
|
||||
import project.cms.PropertiesUtilCms;
|
||||
import project.log.LogService;
|
||||
import project.news.News;
|
||||
import security.Role;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
/**
|
||||
* 用户端内容管理
|
||||
*/
|
||||
@RestController
|
||||
public class AdminCmsController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminCmsController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminCmsService adminCmsService;
|
||||
@Autowired
|
||||
private SecUserService secUserService;
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
private final String action = "normal/adminCmsAction!";
|
||||
|
||||
/**
|
||||
* 获取 用户端内容管理 列表
|
||||
*/
|
||||
@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 language = request.getParameter("language");
|
||||
String title = request.getParameter("title");
|
||||
String startTime = request.getParameter("startTime");
|
||||
String endTime = request.getParameter("endTime");
|
||||
Integer status = request.getParameter("status") == null ? -2 : Integer.parseInt(request.getParameter("status"));
|
||||
Integer type = request.getParameter("type") == null ? -2 : Integer.parseInt(request.getParameter("type"));
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("cms_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 20;
|
||||
|
||||
this.page = this.adminCmsService.pagedQuery(this.pageNo, this.pageSize, language, title, startTime, endTime, type, status);
|
||||
|
||||
|
||||
} 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("title", title);
|
||||
modelAndView.addObject("language",language);
|
||||
modelAndView.addObject("startTime", startTime);
|
||||
modelAndView.addObject("endTime", endTime);
|
||||
modelAndView.addObject("type", type);
|
||||
modelAndView.addObject("status", status);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增 用户端内容管理 页面
|
||||
*/
|
||||
@RequestMapping(action + "toAdd.action")
|
||||
public ModelAndView toAdd(HttpServletRequest request) {
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
|
||||
try {
|
||||
|
||||
// if (!this.checkIsRoot()) {
|
||||
// throw new BusinessException("root 权限下才可添加");
|
||||
// }
|
||||
|
||||
// modelAndView.addObject("language", PropertiesUtilCms.getProperty("system_cms_language"));
|
||||
// modelAndView.addObject("modelMap", Constants.CMS_MODEL);
|
||||
// modelAndView.addObject("languageMap", Constants.LANGUAGE);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.setViewName("cms_add");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增 用户端内容管理
|
||||
*
|
||||
* title 标题
|
||||
* content 内容
|
||||
* model 模块
|
||||
* language 语言
|
||||
* content_code 业务代码
|
||||
*/
|
||||
@RequestMapping(action + "add.action")
|
||||
public ModelAndView add(HttpServletRequest request, Cms cms) {
|
||||
String login_safeword = request.getParameter("login_safeword");
|
||||
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verif(cms.getTitle(), cms.getContent());
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
// if (!this.checkIsRoot()) {
|
||||
// throw new BusinessException("root 权限下才可添加");
|
||||
// }
|
||||
|
||||
String username_login = this.getUsername_login();
|
||||
|
||||
SecUser sec = this.secUserService.findUserByLoginName(username_login);
|
||||
|
||||
cms.setCreateTime(new Date());
|
||||
this.adminCmsService.saveOrUpdate(cms);
|
||||
|
||||
String log = null;
|
||||
log = MessageFormat.format("ip:" + this.getIp() + ",管理员新增cms,id:{0},标题:{1},语言:{2},模块:{3}",
|
||||
cms.getId(), cms.getTitle(), cms.getLanguage());
|
||||
this.saveLog(sec, username_login, log);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
// modelAndView.addObject("model", model);
|
||||
// modelAndView.addObject("language", language);
|
||||
// modelAndView.addObject("content_code", content_code);
|
||||
// modelAndView.addObject("title", title);
|
||||
// modelAndView.addObject("content", content);
|
||||
// modelAndView.addObject("modelMap", Constants.CMS_MODEL);
|
||||
// modelAndView.addObject("languageMap", Constants.LANGUAGE);
|
||||
modelAndView.setViewName("cms_add");
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
// modelAndView.addObject("model", model);
|
||||
// modelAndView.addObject("language", language);
|
||||
// modelAndView.addObject("content_code", content_code);
|
||||
// modelAndView.addObject("title", title);
|
||||
// modelAndView.addObject("content", content);
|
||||
// modelAndView.addObject("modelMap", Constants.CMS_MODEL);
|
||||
// modelAndView.addObject("languageMap", Constants.LANGUAGE);
|
||||
modelAndView.setViewName("cms_add");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 用户端内容管理 页面
|
||||
*
|
||||
* title 标题
|
||||
* content 内容
|
||||
* model 模块
|
||||
* language 语言
|
||||
* content_code 业务代码
|
||||
*/
|
||||
@RequestMapping(action + "toUpdate.action")
|
||||
public ModelAndView toUpdate(HttpServletRequest request) {
|
||||
String id = request.getParameter("id");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(id)) {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
|
||||
Cms cms = this.adminCmsService.findById(id);
|
||||
if (null == cms) {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
|
||||
modelAndView.addObject("cms", cms);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.setViewName("cms_update");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 用户端内容管理
|
||||
*
|
||||
* title 标题
|
||||
* content 内容
|
||||
* model 模块
|
||||
* language 语言
|
||||
* content_code 业务代码
|
||||
*/
|
||||
@RequestMapping(action + "update.action")
|
||||
public ModelAndView update(HttpServletRequest request, Cms cms) {
|
||||
String login_safeword = request.getParameter("login_safeword");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verif(cms.getTitle(), cms.getContent());
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
String username_login = this.getUsername_login();
|
||||
|
||||
SecUser sec = this.secUserService.findUserByLoginName(username_login);
|
||||
|
||||
this.checkLoginSafeword(sec, username_login, login_safeword);
|
||||
|
||||
if (StringUtils.isNullOrEmpty(cms.getId().toString())) {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
|
||||
Cms entity = this.adminCmsService.findById(cms.getId().toString());
|
||||
if (null == entity) {
|
||||
throw new BusinessException("内容不存在或已删除");
|
||||
}
|
||||
cms.setCreateTime(entity.getCreateTime());
|
||||
|
||||
String log = null;
|
||||
log = MessageFormat.format("ip:" + this.getIp() + ",管理员修改cms,id:{0},原标题:{1},原语言:{2},原模块:{3}",
|
||||
entity.getId(), entity.getTitle(), entity.getLanguage());
|
||||
|
||||
this.adminCmsService.saveOrUpdate(cms);
|
||||
saveLog(sec, username_login, log);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("cms", cms);
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
modelAndView.setViewName("cms_update");
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("cms", cms);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
modelAndView.setViewName("cms_update");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 新闻管理
|
||||
*/
|
||||
@RequestMapping(action + "delete.action")
|
||||
public ModelAndView delete(HttpServletRequest request) {
|
||||
String id = request.getParameter("id");
|
||||
String login_safeword = request.getParameter("login_safeword");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
String userNameLogin = this.getUsername_login();
|
||||
|
||||
SecUser sec = this.secUserService.findUserByLoginName(userNameLogin);
|
||||
this.checkLoginSafeword(sec, userNameLogin, login_safeword);
|
||||
|
||||
Cms cms = this.adminCmsService.findById(id);
|
||||
|
||||
String log = MessageFormat.format("ip:" + this.getIp() + ",管理员删除公告,id:{0},原标题:{1},原语言:{2},原模块:{3}",
|
||||
cms.getId(), cms.getTitle(), cms.getLanguage(), cms.getType());
|
||||
this.saveLog(sec, userNameLogin, log);
|
||||
this.adminCmsService.delete(cms);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error("update error ", t);
|
||||
modelAndView.addObject("error", "程序错误");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
private boolean checkIsRoot() {
|
||||
String username = this.getUsername_login();
|
||||
// root才可以改动
|
||||
SecUser secUser = this.secUserService.findUserByLoginName(username);
|
||||
for (Role role : secUser.getRoles()) {
|
||||
if (Constants.SECURITY_ROLE_ROOT.equals(role.getRoleName())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
public String verif(String title, String content) {
|
||||
if (StringUtils.isNullOrEmpty(title)) {
|
||||
return "请输入标题!";
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(content)) {
|
||||
return "请输入内容!";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录人资金密码
|
||||
*/
|
||||
protected void checkLoginSafeword(SecUser secUser, String operatorUsername, String loginSafeword) {
|
||||
// SecUser sec = this.secUserService.findUserByLoginName(operatorUsername);
|
||||
String sysSafeword = secUser.getSafeword();
|
||||
String safeword_md5 = this.passwordEncoder.encodePassword(loginSafeword, operatorUsername);
|
||||
if (!safeword_md5.equals(sysSafeword)) {
|
||||
throw new BusinessException("登录人资金密码错误");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
88
comm/Cms/src/project/web/api/CmsController.java
Executable file
88
comm/Cms/src/project/web/api/CmsController.java
Executable file
@@ -0,0 +1,88 @@
|
||||
package project.web.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.DateUtils;
|
||||
import kernel.web.ResultObject;
|
||||
import project.cms.Cms;
|
||||
import project.cms.CmsService;
|
||||
|
||||
/**
|
||||
* 用户端内容管理
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class CmsController {
|
||||
|
||||
private Logger logger = LogManager.getLogger(CmsController.class);
|
||||
|
||||
@Autowired
|
||||
private CmsService cmsService;
|
||||
|
||||
private final String action = "/api/cms!";
|
||||
|
||||
/**
|
||||
* 获取 用户端内容管理
|
||||
*/
|
||||
@RequestMapping(action + "get.action")
|
||||
public Object get(HttpServletRequest request) {
|
||||
String language = request.getParameter("lang");
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
if (null == language){
|
||||
throw new BusinessException("语言参数错误");
|
||||
}
|
||||
List<Cms> list = this.cmsService.findCmsListByLang(language);
|
||||
if (null != list) {
|
||||
resultObject.setData(list.get(0));
|
||||
}
|
||||
} 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 + "list.action")
|
||||
public Object list(HttpServletRequest request) {
|
||||
String language = request.getParameter("lang");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
|
||||
List<Cms> cacheListByModel = this.cmsService.cacheListByModelAndLanguage(language);
|
||||
resultObject.setData(cacheListByModel);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
9
comm/DB/bin/config/db.properties
Executable file
9
comm/DB/bin/config/db.properties
Executable file
@@ -0,0 +1,9 @@
|
||||
|
||||
#\u5907\u4efd\u6570\u636e\u5e93
|
||||
db.ip=127.0.0.1
|
||||
db.port=6306
|
||||
db.database.name=demo
|
||||
db.username=root
|
||||
db.password=2uVS6UkYyV7Do4JbN9zebDUMoF4w88q3CNxanZ0wEnY%3D
|
||||
db.backup.path=/backup
|
||||
|
||||
15
comm/DB/src/db/Constants.java
Executable file
15
comm/DB/src/db/Constants.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package db;
|
||||
|
||||
public class Constants {
|
||||
|
||||
/**
|
||||
* 备份时间格式
|
||||
*/
|
||||
public final static String DB_BACKUP_TIME_FORMAT = "yyyyMMddHHmmss-SSS";
|
||||
|
||||
/**
|
||||
* File.separator 正则 "\\"
|
||||
*/
|
||||
public static final String FILE_SEPARATOR_REGEX = "\\\\";
|
||||
|
||||
}
|
||||
23
comm/DB/src/db/DBBackup.java
Executable file
23
comm/DB/src/db/DBBackup.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package db;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface DBBackup {
|
||||
|
||||
/**
|
||||
* <p>Description: 数据库备份 </p>
|
||||
*
|
||||
* @param params 参数(若缺省则使用系统默认配置) <pre>
|
||||
* ip -- IP地址
|
||||
* port -- 端口
|
||||
* databaseName -- 数据库名
|
||||
* username -- 用户名
|
||||
* password -- 密码
|
||||
* backupPath -- 备份存储路径</pre>
|
||||
*
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean backup(Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
}
|
||||
15
comm/DB/src/db/DBBackupBeanHandler.java
Executable file
15
comm/DB/src/db/DBBackupBeanHandler.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package db;
|
||||
|
||||
public interface DBBackupBeanHandler {
|
||||
|
||||
/**
|
||||
* @param backupRecordService The backupRecordService to set.
|
||||
*/
|
||||
public void setBackupRecordService(DBBackupRecordService backupRecordService);
|
||||
|
||||
/**
|
||||
* @param operatorEvent The operatorEvent to set.
|
||||
*/
|
||||
public void setOperatorEvent(DBOperatorEvent operatorEvent);
|
||||
|
||||
}
|
||||
25
comm/DB/src/db/DBBackupLock.java
Executable file
25
comm/DB/src/db/DBBackupLock.java
Executable file
@@ -0,0 +1,25 @@
|
||||
package db;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DBBackupLock {
|
||||
public static final String ALL_DB_LOCK = "ALL_DB_LOCK";
|
||||
private static final Set<String> filter = new HashSet<String>();
|
||||
|
||||
public static boolean add(String lock) {
|
||||
if (!filter.add(lock)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(String lock) {
|
||||
filter.remove(lock);
|
||||
|
||||
}
|
||||
public static boolean getLock(String lock) {
|
||||
return filter.contains(lock);
|
||||
}
|
||||
}
|
||||
172
comm/DB/src/db/DBBackupRecord.java
Executable file
172
comm/DB/src/db/DBBackupRecord.java
Executable file
@@ -0,0 +1,172 @@
|
||||
package db;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import db.util.FileUtil;
|
||||
|
||||
|
||||
public class DBBackupRecord {
|
||||
|
||||
/**
|
||||
* UUID
|
||||
*/
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* 备份名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 备份时间
|
||||
*/
|
||||
private Date backupTime;
|
||||
|
||||
/**
|
||||
* 备份文件路径
|
||||
*/
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 备份文件大小(B)
|
||||
*/
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Gets the UUID.
|
||||
*
|
||||
* @return Returns the uuid.
|
||||
*/
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the UUID.
|
||||
*
|
||||
* @param uuid The uuid to set.
|
||||
*/
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 备份名称.
|
||||
*
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 备份名称.
|
||||
*
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 备份时间.
|
||||
*
|
||||
* @return Returns the backupTime.
|
||||
*/
|
||||
public Date getBackupTime() {
|
||||
return backupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 备份时间.
|
||||
*
|
||||
* @param backupTime The backupTime to set.
|
||||
*/
|
||||
public void setBackupTime(Date backupTime) {
|
||||
this.backupTime = backupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 备份文件路径.
|
||||
*
|
||||
* @return Returns the filePath.
|
||||
*/
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 备份文件路径.
|
||||
*
|
||||
* @param filePath The filePath to set.
|
||||
*/
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 备份文件大小(B).
|
||||
*
|
||||
* @return Returns the fileSize.
|
||||
*/
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 备份文件大小(B).
|
||||
*
|
||||
* @param fileSize The fileSize to set.
|
||||
*/
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 备注.
|
||||
*
|
||||
* @return Returns the description.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 备注.
|
||||
*
|
||||
* @param description The description to set.
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer str = new StringBuffer("\n");
|
||||
str.append("===============================================================================");
|
||||
str.append("\n");
|
||||
str.append("<< ").append(getClass().getSimpleName()).append(" >>");
|
||||
str.append("\n");
|
||||
str.append("-------------------------------------------------------------------------------");
|
||||
str.append("\n");
|
||||
str.append(" UUID: ").append(getUuid());
|
||||
str.append("\n");
|
||||
str.append(" Name: ").append(getName());
|
||||
str.append("\n");
|
||||
str.append(" BackupTime: ").append(getBackupTime());
|
||||
str.append("\n");
|
||||
str.append(" FilePath: ").append(getFilePath());
|
||||
str.append("\n");
|
||||
str.append(" FileSize: ").append(FileUtil.formetFileSize(getFileSize(), null));
|
||||
str.append("\n");
|
||||
str.append(" Description: ").append(getDescription());
|
||||
str.append("\n");
|
||||
str.append("-------------------------------------------------------------------------------");
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
57
comm/DB/src/db/DBBackupRecordService.java
Executable file
57
comm/DB/src/db/DBBackupRecordService.java
Executable file
@@ -0,0 +1,57 @@
|
||||
package db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface DBBackupRecordService {
|
||||
|
||||
/**
|
||||
* <p>Description: 从缓存中获取所有备份记录信息 </p>
|
||||
* @return 备份记录信息集合
|
||||
*/
|
||||
public Collection<DBBackupRecord> findAll();
|
||||
|
||||
/**
|
||||
* <p>Description: 从缓存中获取备份记录 </p>
|
||||
* @param uuid 备份记录ID
|
||||
* @return 备份记录详情
|
||||
*/
|
||||
public DBBackupRecord findByUuid(Serializable uuid);
|
||||
|
||||
/**
|
||||
* <p>Description: 添加备份记录信息,要同步添加缓存 </p>
|
||||
* @param record 备份记录信息
|
||||
*/
|
||||
public void add(DBBackupRecord record);
|
||||
|
||||
/**
|
||||
* <p>Description: 删除备份记录,要同步删除缓存和文件 </p>
|
||||
* @param uuid 备份记录ID
|
||||
*/
|
||||
public void delete(Serializable uuid);;
|
||||
|
||||
/**
|
||||
* <p>Description: 批量删除备份,要同步删除缓存和文件 </p>
|
||||
* @param ids 备份记录ID数组
|
||||
* @return 删除记录条数
|
||||
*/
|
||||
public int deleteByIds(Serializable[] ids);
|
||||
|
||||
/**
|
||||
* <p>Description: 获取最大备份记录保存限值 </p>
|
||||
* @return 最大备份记录限值
|
||||
*/
|
||||
public Integer getMaxLimitNum();
|
||||
|
||||
/**
|
||||
* <p>Description: 设置最大备份记录保存限值 </p>
|
||||
* @param limitNum 限值
|
||||
*/
|
||||
public void setMaxLimitNum(Integer limitNum);
|
||||
|
||||
/**
|
||||
* <p>Description: 初始化 </p>
|
||||
*/
|
||||
public void initialize();
|
||||
|
||||
}
|
||||
80
comm/DB/src/db/DBBeanFactory.java
Executable file
80
comm/DB/src/db/DBBeanFactory.java
Executable file
@@ -0,0 +1,80 @@
|
||||
package db;
|
||||
|
||||
import db.backup.internal.MysqlBackupImpl;
|
||||
import db.restore.MysqlRestoreImpl;
|
||||
import db.util.ConfigUtils;
|
||||
|
||||
public class DBBeanFactory {
|
||||
|
||||
/**
|
||||
* <p>Description: 创建DBBackup实例 </p>
|
||||
*
|
||||
* @param backupRecordService 备份记录信息管理接口
|
||||
* @param operatorEvent 数据库操作事件
|
||||
* @return DBBackup实例
|
||||
*/
|
||||
public static Object buildBackupBean(DBBackupRecordService backupRecordService, //
|
||||
DBOperatorEvent operatorEvent) {
|
||||
SupportDBTypeEnum dbType = ConfigUtils.getCurrentDBType(); // 当前数据库类型
|
||||
DBBackup backupService = null;
|
||||
switch (dbType) {
|
||||
case mysql:
|
||||
backupService = new MysqlBackupImpl();
|
||||
break;
|
||||
// case oracle:
|
||||
// backupService = new OracleBackupImpl();
|
||||
// break;
|
||||
// case postgre:
|
||||
// backupService = new PostgreBackupImpl();
|
||||
// break;
|
||||
// case sqlserver:
|
||||
// backupService = new SQLServerBackupImpl();
|
||||
// break;
|
||||
}
|
||||
|
||||
if (backupService == null) {
|
||||
throw new IllegalArgumentException("The DB backupService can not be NULL");
|
||||
}
|
||||
|
||||
if (backupService instanceof DBBackupBeanHandler) {
|
||||
((DBBackupBeanHandler) backupService).setBackupRecordService(backupRecordService);
|
||||
((DBBackupBeanHandler) backupService).setOperatorEvent(operatorEvent);
|
||||
}
|
||||
return backupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 创建DBRestore实例 </p>
|
||||
*
|
||||
* @param operatorEvent 数据库操作事件
|
||||
* @return DBRestore实例
|
||||
*/
|
||||
public static Object buildRestoreBean(DBOperatorEvent operatorEvent) {
|
||||
SupportDBTypeEnum dbType = ConfigUtils.getCurrentDBType(); // 当前数据库类型
|
||||
DBRestore restoreService = null;
|
||||
switch (dbType) {
|
||||
case mysql:
|
||||
restoreService = new MysqlRestoreImpl();
|
||||
break;
|
||||
// case oracle:
|
||||
// restoreService = new OracleRestoreImpl();
|
||||
// break;
|
||||
// case postgre:
|
||||
// restoreService = new PostgreRestoreImpl();
|
||||
// break;
|
||||
// case sqlserver:
|
||||
// restoreService = new SQLServerRestoreImpl();
|
||||
// break;
|
||||
}
|
||||
|
||||
if (restoreService == null) {
|
||||
throw new IllegalArgumentException("The DB restoreService can not be NULL");
|
||||
}
|
||||
|
||||
if (restoreService instanceof DBRestoreBeanHandler) {
|
||||
((DBRestoreBeanHandler) restoreService).setOperatorEvent(operatorEvent);
|
||||
}
|
||||
return restoreService;
|
||||
}
|
||||
|
||||
}
|
||||
35
comm/DB/src/db/DBOperatorEvent.java
Executable file
35
comm/DB/src/db/DBOperatorEvent.java
Executable file
@@ -0,0 +1,35 @@
|
||||
package db;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DBOperatorEvent {
|
||||
|
||||
/**
|
||||
* 开始备份前
|
||||
* @param params 参数
|
||||
*/
|
||||
public void beforeBackup(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 备份后事件
|
||||
* @param record 备份记录
|
||||
* @param params 参数
|
||||
*/
|
||||
public void afterBackup(DBBackupRecord record, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 数据库还原操作前
|
||||
* @param file 备份文件
|
||||
* @param params 参数
|
||||
*/
|
||||
public void beforeRestore(File file, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 数据库还原操作后
|
||||
* @param file 备份文件
|
||||
* @param params 参数
|
||||
*/
|
||||
public void afterRestore(File file, Map<String, Object> params);
|
||||
|
||||
}
|
||||
41
comm/DB/src/db/DBRestore.java
Executable file
41
comm/DB/src/db/DBRestore.java
Executable file
@@ -0,0 +1,41 @@
|
||||
package db;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DBRestore {
|
||||
|
||||
/**
|
||||
* <p>Description: 从文件还原数据库 </p>
|
||||
* @param file 待还原的文件
|
||||
* @param params 参数(若缺省则使用系统默认配置)<pre>
|
||||
* ip -- IP地址
|
||||
* port -- 端口
|
||||
* databaseName -- 数据库名
|
||||
* username -- 用户名
|
||||
* password -- 密码</pre>
|
||||
*
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean restore(File file, Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
/**
|
||||
* <p>Description: 从文件还原数据库 </p>
|
||||
* @param filePath 待还原的文件路径
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean restore(String filePath, Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
/**
|
||||
<p>Description: 从备份记录还原数据库 </p>
|
||||
* @param record 备份记录
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean restore(DBBackupRecord record, Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
}
|
||||
10
comm/DB/src/db/DBRestoreBeanHandler.java
Executable file
10
comm/DB/src/db/DBRestoreBeanHandler.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package db;
|
||||
|
||||
public interface DBRestoreBeanHandler {
|
||||
|
||||
/**
|
||||
* @param operatorEvent The operatorEvent to set.
|
||||
*/
|
||||
public void setOperatorEvent(DBOperatorEvent operatorEvent);
|
||||
|
||||
}
|
||||
31
comm/DB/src/db/OpertProcessListener.java
Executable file
31
comm/DB/src/db/OpertProcessListener.java
Executable file
@@ -0,0 +1,31 @@
|
||||
package db;
|
||||
|
||||
import db.support.MessageOutputListener;
|
||||
|
||||
public interface OpertProcessListener {
|
||||
|
||||
/**
|
||||
* <p>Description: 输出信息监听器 </p>
|
||||
*
|
||||
* @return 输出信息监听器
|
||||
*/
|
||||
public MessageOutputListener getOutputListener();
|
||||
|
||||
/**
|
||||
* <p>Description: 操作结束 </p>
|
||||
*/
|
||||
public void onExit();
|
||||
|
||||
/**
|
||||
* <p>Description: 备份操作中止 </p>
|
||||
*/
|
||||
public void onInterrupt();
|
||||
|
||||
/**
|
||||
* <p>Description: 操作过程是否结束 </p>
|
||||
*
|
||||
* @return 是否结束
|
||||
*/
|
||||
public boolean isFinish();
|
||||
|
||||
}
|
||||
130
comm/DB/src/db/PropertiesUtilDB.java
Executable file
130
comm/DB/src/db/PropertiesUtilDB.java
Executable file
@@ -0,0 +1,130 @@
|
||||
package db;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* 读取Properties综合类,默认绑定到classpath下的config.properties文件。
|
||||
*/
|
||||
public class PropertiesUtilDB {
|
||||
private static Logger logger = LogManager.getLogger(PropertiesUtilDB.class);
|
||||
private static String CONFIG_FILENAME = "config/db.properties";
|
||||
private static Properties prop = null;
|
||||
|
||||
public PropertiesUtilDB() {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
};
|
||||
|
||||
private synchronized static void loadProperties() {
|
||||
byte buff[] = null;
|
||||
try {
|
||||
// Open the props file
|
||||
InputStream is = PropertiesUtilDB.class.getResourceAsStream("/" + CONFIG_FILENAME);
|
||||
prop = new Properties();
|
||||
// Read in the stored properties
|
||||
prop.load(is);
|
||||
} catch (Exception e) {
|
||||
System.err.println("读取配置文件失败!!!");
|
||||
prop = null;
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到属性值
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key) {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
String value = prop.getProperty(key);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到内容包含汉字的属性值
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getGBKProperty(String key) {
|
||||
String value = getProperty(key);
|
||||
try {
|
||||
value = new String(value.getBytes("ISO8859-1"), "GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到属性值,
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
if (prop == null) {
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
String value = prop.getProperty(key, defaultValue);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到内容包含汉字的属性值,如果不存在则使用默认值
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getGBKProperty(String key, String defaultValue) {
|
||||
try {
|
||||
defaultValue = new String(defaultValue.getBytes("GBK"), "ISO8859-1");
|
||||
String value = getProperty(key, defaultValue);
|
||||
value = new String(value.getBytes("ISO8859-1"), "GBK");
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUTFProperty(String key, String defaultValue) {
|
||||
try {
|
||||
defaultValue = new String(defaultValue.getBytes("UTF-8"), "ISO8859-1");
|
||||
String value = getProperty(key, defaultValue);
|
||||
value = new String(value.getBytes("ISO8859-1"), "UTF-8");
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.trim();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
comm/DB/src/db/SupportDBTypeEnum.java
Executable file
52
comm/DB/src/db/SupportDBTypeEnum.java
Executable file
@@ -0,0 +1,52 @@
|
||||
package db;
|
||||
|
||||
public enum SupportDBTypeEnum {
|
||||
/**
|
||||
* MySQL数据库
|
||||
*/
|
||||
mysql,
|
||||
|
||||
/**
|
||||
* Oracle数据库
|
||||
*/
|
||||
oracle,
|
||||
|
||||
/**
|
||||
* Postgre数据库
|
||||
*/
|
||||
postgre,
|
||||
|
||||
/**
|
||||
* SQLServer数据库
|
||||
*/
|
||||
sqlserver;
|
||||
|
||||
/**
|
||||
* @param type 数据库类型名
|
||||
* @return support DBType
|
||||
*/
|
||||
public static SupportDBTypeEnum getEnum(String type) {
|
||||
if (type == null || "".equals(type = type.trim())) {
|
||||
throw new IllegalArgumentException("The database type can not be NULL");
|
||||
}
|
||||
|
||||
SupportDBTypeEnum result = null;
|
||||
try {
|
||||
result = SupportDBTypeEnum.valueOf(type);
|
||||
return result;
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
for (SupportDBTypeEnum supportType : SupportDBTypeEnum.values()) {
|
||||
if (supportType.name().equalsIgnoreCase(type)) {
|
||||
return supportType;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
throw new IllegalArgumentException("The database type with name '" + type + "' is not support");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
234
comm/DB/src/db/backup/internal/AbstractBackupImpl.java
Executable file
234
comm/DB/src/db/backup/internal/AbstractBackupImpl.java
Executable file
@@ -0,0 +1,234 @@
|
||||
package db.backup.internal;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import db.Constants;
|
||||
import db.DBBackup;
|
||||
import db.DBBackupBeanHandler;
|
||||
import db.DBBackupRecord;
|
||||
import db.DBBackupRecordService;
|
||||
import db.DBOperatorEvent;
|
||||
import db.OpertProcessListener;
|
||||
import db.support.DBBackupRecordServiceImpl;
|
||||
import db.util.FileUtil;
|
||||
import db.util.PathUtil;
|
||||
import db.util.UUIDGenerator;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
|
||||
|
||||
public abstract class AbstractBackupImpl implements DBBackup, DBBackupBeanHandler {
|
||||
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* 默认备份路径
|
||||
*/
|
||||
protected final static String DEFAULT_BACKUP_PATH = PathUtil.getDbBackupPath();
|
||||
|
||||
/**
|
||||
* 事件通知
|
||||
*/
|
||||
protected DBOperatorEvent operatorEvent;
|
||||
|
||||
/**
|
||||
* 数据库备份记录信息管理接口
|
||||
*/
|
||||
protected DBBackupRecordService backupRecordService = new DBBackupRecordServiceImpl();
|
||||
|
||||
@Override
|
||||
public boolean backup(Map<String, Object> params, OpertProcessListener processListener) {
|
||||
if (params == null) {
|
||||
params = new HashMap<String, Object>();
|
||||
}
|
||||
params = parserMapParams(params); // 解析参数
|
||||
|
||||
// operatorEvent.beforeBackup(params); // 备份前事件通知
|
||||
|
||||
boolean result = false;
|
||||
DBBackupRecord record = null;
|
||||
backupRecordService = new DBBackupRecordServiceImpl();
|
||||
try {
|
||||
if (doEnvironmentCheck(params, processListener)) {
|
||||
Date backupTime = new Date(); // 备份时间
|
||||
params.put("backupTime", backupTime);
|
||||
|
||||
String backupName = (String) params.get("backupName"); // 备份名称
|
||||
if (backupName == null) {
|
||||
String databaseName = (String) params.get("databaseName");
|
||||
DateFormat sdf = DateUtils.createDateFormat(Constants.DB_BACKUP_TIME_FORMAT);
|
||||
backupName = databaseName + "_" + sdf.format(backupTime);
|
||||
params.put("backupName", backupName);
|
||||
}
|
||||
|
||||
result = doBackup(params, processListener); // 执行备份操作
|
||||
|
||||
record = createNewBackupRecord(params); // 新建备份记录
|
||||
backupRecordService.add(record); // 保存备份文件信息
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
result = false;
|
||||
logger.error("backup database error", e);
|
||||
// throw new FastFailException(e);
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
String msg = "Finished - " + (result ? "Successfully" : "Failed");
|
||||
try {
|
||||
onOutputAndLog(processListener, msg, Level.INFO);
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
if (processListener != null) {
|
||||
processListener.onExit();
|
||||
}
|
||||
|
||||
clearAfterBackup(params); // 备份后清理
|
||||
}
|
||||
|
||||
params.put("result", result); // 结果
|
||||
// operatorEvent.afterBackup(record, params); // 备份后事件通知
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 备份清理工作(清除临时目录、不完整备份文件等操作) </p>
|
||||
* <p>Create Time: 2013-2-20 </p>
|
||||
* @author weiminghua
|
||||
* @param params 参数
|
||||
*/
|
||||
protected void clearAfterBackup(Map<String, Object> params) {
|
||||
// default do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份文件后缀
|
||||
* @return 备份文件后缀名
|
||||
*/
|
||||
protected abstract String getBackupFileSuffix();
|
||||
|
||||
/**
|
||||
* 解析参数
|
||||
*
|
||||
* @param params 参数
|
||||
* @return 参数
|
||||
*/
|
||||
protected abstract Map<String, Object> parserMapParams(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 运行环境检测
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
protected abstract boolean doEnvironmentCheck(Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
/**
|
||||
* 执行备份
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
* @throws InterruptedException 中断异常
|
||||
*/
|
||||
protected abstract boolean doBackup(Map<String, Object> params, OpertProcessListener processListener)
|
||||
throws InterruptedException;
|
||||
|
||||
/**
|
||||
* @param operatorEvent The operatorEvent to set.
|
||||
*/
|
||||
public void setOperatorEvent(DBOperatorEvent operatorEvent) {
|
||||
this.operatorEvent = operatorEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param backupRecordService The backupRecordService to set.
|
||||
*/
|
||||
public void setBackupRecordService(DBBackupRecordService backupRecordService) {
|
||||
this.backupRecordService = backupRecordService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成备份记录
|
||||
* @param params 参数
|
||||
* @return 备份记录
|
||||
*/
|
||||
protected DBBackupRecord createNewBackupRecord(Map<String, Object> params) {
|
||||
DBBackupRecord record = new DBBackupRecord();
|
||||
record.setUuid(UUIDGenerator.getUUID());
|
||||
String backupName = (String) params.get("backupName");
|
||||
record.setName(backupName);
|
||||
record.setBackupTime((Date) params.get("backupTime")); // 备份时间
|
||||
String description = (String) params.get("description"); // 备份描述
|
||||
record.setDescription(description);
|
||||
|
||||
String backupPath = (String) params.get("backupPath"); // 备份存储路径
|
||||
String filePath = backupPath + "/" + backupName + getBackupFileSuffix(); // 备份文件路径
|
||||
record.setFilePath(filePath);
|
||||
try {
|
||||
record.setFileSize(FileUtil.getFileSize(filePath));
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("get backup file[" + filePath + "] size error");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出监听,同时添加日志信息
|
||||
* @param processListener 过程监听
|
||||
* @param msg 日志信息
|
||||
* @param log4jLevel 日志级别
|
||||
* @throws InterruptedException 备份中断异常
|
||||
*/
|
||||
protected void onOutputAndLog(OpertProcessListener processListener, String msg, Level log4jLevel)
|
||||
throws InterruptedException {
|
||||
if (StringUtils.isNullOrEmpty(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processListener != null) {
|
||||
if (processListener.isFinish()) {
|
||||
throw new InterruptedException("interrupt databse backup"); // 备份中断
|
||||
}
|
||||
|
||||
if (processListener.getOutputListener() != null) {
|
||||
processListener.getOutputListener().onOutput(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (log4jLevel == null) {
|
||||
try {
|
||||
Thread.sleep(200); // 延迟加载信息
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 输出日志信息
|
||||
if (Level.ERROR.equals(log4jLevel)) {
|
||||
logger.error(msg);
|
||||
}
|
||||
else if (Level.WARN.equals(log4jLevel)) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
else if (Level.INFO.equals(log4jLevel)) {
|
||||
logger.info(msg);
|
||||
}
|
||||
else if (Level.DEBUG.equals(log4jLevel)) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
302
comm/DB/src/db/backup/internal/MysqlBackupImpl.java
Executable file
302
comm/DB/src/db/backup/internal/MysqlBackupImpl.java
Executable file
@@ -0,0 +1,302 @@
|
||||
package db.backup.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.jcraft.jsch.SftpException;
|
||||
|
||||
import db.Constants;
|
||||
import db.DBBackup;
|
||||
import db.OpertProcessListener;
|
||||
import db.PropertiesUtilDB;
|
||||
import db.util.CMDUtil;
|
||||
import db.util.FileUtil;
|
||||
import db.util.SFTPUtil;
|
||||
import db.util.ZipUtils;
|
||||
import db.util.jdbc.DBTools;
|
||||
import db.util.jdbc.MysqlTools;
|
||||
|
||||
public class MysqlBackupImpl extends AbstractBackupImpl {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Override
|
||||
protected String getBackupFileSuffix() {
|
||||
return ".zip";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> parserMapParams(Map<String, Object> params) {
|
||||
Assert.notNull(params);
|
||||
// 读取参数
|
||||
if (params.get("ip") == null) {
|
||||
// String ip = System.getProperty(DBPorperties.ENV_IP, MySQLConfig.DEFAULT_IP);
|
||||
String ip = PropertiesUtilDB.getProperty("db.ip");
|
||||
params.put("ip", ip);
|
||||
}
|
||||
|
||||
if (params.get("port") == null) {
|
||||
// String port = System.getProperty(DBPorperties.ENV_PORT, MySQLConfig.DEFAULT_PORT);
|
||||
String port = PropertiesUtilDB.getProperty("db.port");
|
||||
params.put("port", port);
|
||||
}
|
||||
|
||||
if (params.get("databaseName") == null) {
|
||||
// String databaseName = System.getProperty(DBPorperties.ENV_DBNAME, MySQLConfig.DEFAULT_DBNAME);
|
||||
String databaseName = PropertiesUtilDB.getProperty("db.databaseName");
|
||||
params.put("databaseName", databaseName);
|
||||
}
|
||||
|
||||
if (params.get("username") == null) {
|
||||
// String username = System.getProperty(DBPorperties.RUIJIE_JDBC_USERNAME);
|
||||
String username = PropertiesUtilDB.getProperty("db.username");
|
||||
params.put("username", username);
|
||||
}
|
||||
|
||||
if (params.get("password") == null) {
|
||||
// String password = System.getProperty(DBPorperties.RUIJIE_JDBC_PASSWORD);
|
||||
String password = PropertiesUtilDB.getProperty("db.password");
|
||||
params.put("password", password);
|
||||
}
|
||||
|
||||
// 备份存储路径
|
||||
if (params.get("backupPath") == null) {
|
||||
String backupPath = DEFAULT_BACKUP_PATH;
|
||||
params.put("backupPath", backupPath);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEnvironmentCheck(Map<String, Object> params, OpertProcessListener processListener) {
|
||||
Assert.notNull(params);
|
||||
// TODO:doEnvironmentCheck
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doBackup(Map<String, Object> params, OpertProcessListener processListener)
|
||||
throws InterruptedException {
|
||||
Assert.notNull(params);
|
||||
onOutputAndLog(processListener, "Starting backup...", Level.INFO);
|
||||
|
||||
String backupPath = (String) params.get("backupPath"); // 备份路径
|
||||
String backupName = (String) params.get("backupName");
|
||||
String realBackupPath = backupPath + "/" + backupName; // 实际备份路径
|
||||
FileUtil.deleteDir(realBackupPath, false); // 删除旧备份
|
||||
File backUpdir = new File(realBackupPath);
|
||||
if (!backUpdir.exists()) {
|
||||
backUpdir.mkdirs();
|
||||
}
|
||||
|
||||
// 备份数据库结构
|
||||
// backupDBStruct(params, realBackupPath, processListener);
|
||||
|
||||
// 备份数据库表数据
|
||||
// backupDBData(params, realBackupPath, processListener);
|
||||
|
||||
backupDBDataByShell(params, realBackupPath, processListener);
|
||||
|
||||
// 压缩备份文件
|
||||
String zipName = backupName + getBackupFileSuffix(); // 备份文件名
|
||||
String filePath = backupPath + "/" + zipName;
|
||||
ZipUtils.createZip(filePath, realBackupPath);
|
||||
// String zip="zip -m "+filePath+" "+realBackupPath;
|
||||
sftp(filePath);
|
||||
// onOutputAndLog(processListener, "Finished - Successfully", Level.INFO);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearAfterBackup(Map<String, Object> params) {
|
||||
String backupPath = (String) params.get("backupPath"); // 备份路径
|
||||
String backupName = (String) params.get("backupName"); // 备份名称
|
||||
String realBackupPath = backupPath + "/" + backupName;
|
||||
|
||||
// 生成压缩文件后,删除临时目录
|
||||
FileUtil.deleteDir(realBackupPath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据库结构
|
||||
* @param params 参数
|
||||
* @param realPath 实际备份路径
|
||||
* @param processListener 监听器
|
||||
* @throws InterruptedException 中断异常
|
||||
*/
|
||||
private void backupDBStruct(Map<String, Object> params, String realPath, OpertProcessListener processListener)
|
||||
throws InterruptedException {
|
||||
onOutputAndLog(processListener, "backup database struct...", Level.INFO);
|
||||
|
||||
StringBuffer cmdBuf = new StringBuffer();
|
||||
cmdBuf.append(DBTools.formatDBClientCmd("mysqldump", "exe")); // 客户端命令
|
||||
|
||||
cmdBuf.append(" -h ").append((String) params.get("ip"));
|
||||
cmdBuf.append(" -P ").append((String) params.get("port"));
|
||||
cmdBuf.append(" --user=").append((String) params.get("username"));
|
||||
cmdBuf.append(" --password=").append((String) params.get("password"));
|
||||
cmdBuf.append(" --opt "); // 同--quick --add-drop-table --add-locks --extended-insert --lock-tables。
|
||||
cmdBuf.append(" --no-data "); // 不备份表数据
|
||||
// cmdBuf.append(" --add-drop-database "); //
|
||||
|
||||
cmdBuf.append(" --result-file=")//
|
||||
.append(DBTools.formatRuntimeCmdPath(realPath)) // 处理空格
|
||||
.append("/db_struct.sql");
|
||||
|
||||
String databaseName = (String) params.get("databaseName");
|
||||
cmdBuf.append(" ").append(databaseName);
|
||||
|
||||
try {
|
||||
// if (processListener == null || processListener.getOutputListener() == null) {
|
||||
// RuntimeExecutorResult result = RuntimeExecutor.execute(cmdBuf.toString(), "GB2312");
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// logger.debug(result.getOutput());
|
||||
// logger.debug(result.getError());
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// MessageOutputListener outputListener = new MessageOutputListener();
|
||||
// RuntimeExecutor.execute(cmdBuf.toString(), "GB2312", outputListener);
|
||||
// while (!outputListener.isFinish()) {
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
logger.info(cmdBuf.toString());
|
||||
String cmdResult = CMDUtil.runCMD(cmdBuf.toString());
|
||||
logger.info("result:"+cmdResult);
|
||||
} catch (Exception e) {
|
||||
logger.error("backup DataBase Struct error");
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 导出数据库结构
|
||||
* @param params 参数
|
||||
* @param realPath 实际备份路径
|
||||
* @param processListener 监听器
|
||||
* @throws InterruptedException 中断异常
|
||||
*/
|
||||
private String backupDBDataByShell(Map<String, Object> params, String realPath, OpertProcessListener processListener)
|
||||
throws InterruptedException {
|
||||
onOutputAndLog(processListener, "backup database struct...", Level.INFO);
|
||||
|
||||
StringBuffer cmdBuf = new StringBuffer();
|
||||
cmdBuf.append(DBTools.formatDBClientCmd("mysqldump", "exe")); // 客户端命令
|
||||
|
||||
cmdBuf.append(" -h ").append((String) params.get("ip"));
|
||||
cmdBuf.append(" -P ").append((String) params.get("port"));
|
||||
cmdBuf.append(" -u").append((String) params.get("username"));
|
||||
cmdBuf.append(" -p").append("'"+(String) params.get("password")+"'");
|
||||
cmdBuf.append(" ").append((String) params.get("databaseName"));
|
||||
// cmdBuf.append(" --opt "); // 同--quick --add-drop-table --add-locks --extended-insert --lock-tables。
|
||||
// cmdBuf.append(" --no-data "); // 不备份表数据
|
||||
// cmdBuf.append(" --add-drop-database "); //
|
||||
|
||||
cmdBuf.append(" > ")//
|
||||
.append(DBTools.formatRuntimeCmdPath(realPath)) // 处理空格
|
||||
.append("/home") // 处理空格
|
||||
.append("//")
|
||||
.append((String) params.get("databaseName"))
|
||||
.append(".sql");
|
||||
|
||||
// String databaseName = (String) params.get("databaseName");
|
||||
// cmdBuf.append(" ").append(databaseName);
|
||||
|
||||
try {
|
||||
// if (processListener == null || processListener.getOutputListener() == null) {
|
||||
// RuntimeExecutorResult result = RuntimeExecutor.execute(cmdBuf.toString(), "GB2312");
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// logger.debug(result.getOutput());
|
||||
// logger.debug(result.getError());
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// MessageOutputListener outputListener = new MessageOutputListener();
|
||||
// RuntimeExecutor.execute(cmdBuf.toString(), "GB2312", outputListener);
|
||||
// while (!outputListener.isFinish()) {
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
logger.info(cmdBuf.toString());
|
||||
String cmdResult = CMDUtil.runCMD(cmdBuf.toString());
|
||||
logger.info("result:"+cmdResult);
|
||||
} catch (Exception e) {
|
||||
logger.error("backup DataBase error");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return cmdBuf.toString();
|
||||
}
|
||||
/**
|
||||
* 导出数据
|
||||
* @param params 参数
|
||||
* @param realPath 实际备份路径
|
||||
* @param processListener 监听器
|
||||
* @throws InterruptedException 中断异常
|
||||
*/
|
||||
private void backupDBData(Map<String, Object> params, String realPath, OpertProcessListener processListener)
|
||||
throws InterruptedException {
|
||||
onOutputAndLog(processListener, "Prepare writing data...", Level.INFO);
|
||||
|
||||
String ip = (String) params.get("ip");
|
||||
String port = (String) params.get("port");
|
||||
String databaseName = (String) params.get("databaseName");
|
||||
String username = (String) params.get("username");
|
||||
String password = (String) params.get("password");
|
||||
|
||||
// 获取所有数据库表
|
||||
List<String> tables = MysqlTools.findAllDBTables(ip, port, databaseName, username, password);
|
||||
|
||||
onOutputAndLog(processListener, "Writing data...", Level.INFO);
|
||||
String rootPath = realPath.replaceAll(Constants.FILE_SEPARATOR_REGEX, "/");
|
||||
|
||||
BasicDataSource ds = MysqlTools.createDataSource(ip, port, databaseName, username, password);
|
||||
JdbcTemplate jt = new JdbcTemplate(ds);
|
||||
for (int index = 0; index < tables.size(); index++) {
|
||||
String tableName = tables.get(index);
|
||||
String fileName = rootPath + "/" + tableName + ".txt";
|
||||
|
||||
onOutputAndLog(processListener, "Writing table " + tableName + " data...", Level.INFO);
|
||||
StringBuffer sqlBuf = new StringBuffer();
|
||||
sqlBuf.append("select * from ").append(tableName);
|
||||
sqlBuf.append(" INTO OUTFILE \"").append(fileName).append("\" ");
|
||||
sqlBuf.append(" FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"'");
|
||||
jt.execute(sqlBuf.toString());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void sftp(String filePath) {
|
||||
String sftpBackupPath= PropertiesUtilDB.getProperty("sftp.backup.path");
|
||||
String sftpUsername= PropertiesUtilDB.getProperty("sftp.username");
|
||||
String sftpPassword= PropertiesUtilDB.getProperty("sftp.password");
|
||||
String sftpIp= PropertiesUtilDB.getProperty("sftp.ip");
|
||||
int sftpPort= Integer.valueOf(PropertiesUtilDB.getProperty("sftp.port"));
|
||||
SFTPUtil sftp = new SFTPUtil(sftpUsername, sftpPassword, sftpIp, sftpPort);
|
||||
sftp.login(SFTPUtil.SFTP);
|
||||
try {
|
||||
sftp.upload(sftpBackupPath, filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SftpException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
sftp.logout();
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
DBBackup dbBack = new MysqlBackupImpl();
|
||||
dbBack.backup(null, null);
|
||||
}
|
||||
}
|
||||
67
comm/DB/src/db/job/BackupJob.java
Executable file
67
comm/DB/src/db/job/BackupJob.java
Executable file
@@ -0,0 +1,67 @@
|
||||
package db.job;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import db.DBBackupLock;
|
||||
import db.util.BackupUtil;
|
||||
import kernel.util.DateUtils;
|
||||
import project.log.SysLogService;
|
||||
import project.syspara.SysparaService;
|
||||
|
||||
public class BackupJob {
|
||||
private Logger log = LoggerFactory.getLogger(BackupJob.class);
|
||||
protected SysLogService sysLogService;
|
||||
protected SysparaService sysparaService;
|
||||
|
||||
public void taskJob() {
|
||||
try {
|
||||
// log.info("BackupJob taskJob start,time:"+DateUtils.dateToStr(new Date(), DateUtils.DF_yyyyMMddHHmmss)+",isBackup:"+isBackup()+",lock:"+DBBackupLock.getLock(DBBackupLock.ALL_DB_LOCK));
|
||||
//未被锁
|
||||
if(isBackup() && !DBBackupLock.getLock(DBBackupLock.ALL_DB_LOCK)) {
|
||||
BackupUtil.backupPart(sysLogService,sysparaService);
|
||||
}
|
||||
log.info("BackupJob taskJob end");
|
||||
}catch (Throwable t) {
|
||||
log.error("BackupJob taskJob fail t:"+t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前是否执行局部备份,true:开启,false:不开启
|
||||
* @return
|
||||
*/
|
||||
private boolean isBackup() {
|
||||
//例如, 01:55-02:35,04:00-05:08,13:55-14:45 表示多个时间段内不备份
|
||||
try {
|
||||
String not_part_backup_times = sysparaService.find("not_part_backup_times").getValue();
|
||||
String[] times = not_part_backup_times.split(",");
|
||||
Date now = new Date();
|
||||
String nowDate = DateUtils.getDateStr(now);
|
||||
for (int i = 0; i < times.length; i++) {
|
||||
String[] timePart = times[i].split("-");
|
||||
Date startTime = DateUtils.strToDate(nowDate+" "+timePart[0]);
|
||||
Date endTime = DateUtils.strToDate(nowDate+" "+timePart[1]);
|
||||
if(now.after(startTime)&&now.before(endTime)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
log.error("BackupJob isBackup fail,e:",e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void setSysLogService(SysLogService sysLogService) {
|
||||
this.sysLogService = sysLogService;
|
||||
}
|
||||
|
||||
public void setSysparaService(SysparaService sysparaService) {
|
||||
this.sysparaService = sysparaService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
95
comm/DB/src/db/map/CacheMap.java
Executable file
95
comm/DB/src/db/map/CacheMap.java
Executable file
@@ -0,0 +1,95 @@
|
||||
package db.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class CacheMap<K, V> {
|
||||
|
||||
/**
|
||||
* map cache
|
||||
*/
|
||||
private final Map<K, V> map = Collections.synchronizedMap(new ConcurrentHashMap<K, V>());
|
||||
|
||||
// private final Map<K, V> map = new ConcurrentHashMap<K, V>();
|
||||
|
||||
/**
|
||||
* Associates the specified value with the specified key in this map
|
||||
*
|
||||
* @param key key with which the specified value is to be associated
|
||||
* @param value value to be associated with the specified key
|
||||
*/
|
||||
public void put(K key, V value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the mapping for a key from this map if it is present
|
||||
*
|
||||
* @param key key whose mapping is to be removed from the map
|
||||
*/
|
||||
public void remove(K key) {
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of key-value mappings in this map.
|
||||
*
|
||||
* @return the size of map
|
||||
*/
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all of the mappings from this map.
|
||||
*/
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Collection} view of the values contained in this map.
|
||||
*
|
||||
* @return a collection view of the values contained in this map
|
||||
*/
|
||||
public Collection<V> values() {
|
||||
return map.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a the values contained in this map to a list.
|
||||
*
|
||||
* @return a list of the values contained in this map
|
||||
*/
|
||||
public List<V> valuesCopy() {
|
||||
Collection<V> values = map.values();
|
||||
|
||||
return new ArrayList<V>(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped
|
||||
*
|
||||
* @param key the key whose associated value is to be returned
|
||||
* @return the value to which the specified key is mapped, or
|
||||
* {@code null} if this map contains no mapping for the key
|
||||
*/
|
||||
public V get(K key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if this map contains a mapping for the specified
|
||||
* key.
|
||||
* @param key key whose presence in this map is to be tested
|
||||
* @return <tt>true</tt> if this map contains a mapping for the specified
|
||||
* key
|
||||
*/
|
||||
public boolean containsKey(K key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
}
|
||||
182
comm/DB/src/db/restore/AbstractRestoreImpl.java
Executable file
182
comm/DB/src/db/restore/AbstractRestoreImpl.java
Executable file
@@ -0,0 +1,182 @@
|
||||
package db.restore;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import db.DBBackupRecord;
|
||||
import db.DBOperatorEvent;
|
||||
import db.DBRestore;
|
||||
import db.DBRestoreBeanHandler;
|
||||
import db.OpertProcessListener;
|
||||
import kernel.util.StringUtils;
|
||||
|
||||
public abstract class AbstractRestoreImpl implements DBRestore, DBRestoreBeanHandler {
|
||||
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* 事件通知
|
||||
*/
|
||||
protected DBOperatorEvent operatorEvent;
|
||||
|
||||
/**
|
||||
* 备份文件后缀
|
||||
* @return 备份文件后缀名
|
||||
*/
|
||||
protected abstract String getBackupFileSuffix();
|
||||
|
||||
@Override
|
||||
public boolean restore(File file, Map<String, Object> params, OpertProcessListener processListener) {
|
||||
if (params == null) {
|
||||
params = new HashMap<String, Object>();
|
||||
}
|
||||
params = parserMapParams(params); // 解析参数
|
||||
|
||||
// operatorEvent.beforeRestore(file, params); // 操作前事件通知
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
if (doEnvironmentCheck(file, params, processListener)) {
|
||||
result = doResotre(file, params, processListener); // 执行还原操作
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
result = false;
|
||||
logger.error("restore database error", e);
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (processListener != null) {
|
||||
processListener.onExit();
|
||||
}
|
||||
|
||||
clearAfterRestore(file, params); // 还原后清理
|
||||
}
|
||||
|
||||
String msg = "Finished - " + (result ? "Successfully" : "Failed");
|
||||
onOutputAndLog(processListener, msg, (result ? Level.INFO : Level.ERROR));
|
||||
|
||||
params.put("result", result); // 结果
|
||||
// operatorEvent.afterRestore(file, params);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原清理工作(清除临时目录、临时文件等操作
|
||||
* @param file 备份文件
|
||||
* @param params 参数
|
||||
*/
|
||||
protected void clearAfterRestore(File file, Map<String, Object> params) {
|
||||
// default do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restore(String filePath, Map<String, Object> params, OpertProcessListener processListener) {
|
||||
return restore(new File(filePath), params, processListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restore(DBBackupRecord record, Map<String, Object> params, OpertProcessListener processListener) {
|
||||
Assert.isTrue(record != null && record.getFilePath() != null);
|
||||
return restore(new File(record.getFilePath()), params, processListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 解析参数 </p>
|
||||
* <p>Create Time: 2013-2-7 </p>
|
||||
* @author weiminghua
|
||||
* @param params 参数
|
||||
* @return 参数
|
||||
*/
|
||||
protected abstract Map<String, Object> parserMapParams(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 运行环境检测
|
||||
* @param file 待还原的文件
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
protected boolean doEnvironmentCheck(File file, Map<String, Object> params, OpertProcessListener processListener) {
|
||||
Assert.isTrue(params != null && file != null);
|
||||
|
||||
// TODO:doEnvironmentCheck
|
||||
if (!file.exists()) {
|
||||
logger.error("restore database failed for file[" + file.getPath() + "] not exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
String suffix = getBackupFileSuffix();
|
||||
if (-1 == file.getPath().indexOf(suffix)) {
|
||||
logger.error("The file[" + file.getPath() + "] not end of [" + suffix + "]");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行备份
|
||||
* @param file 待还原的文件
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
* @return 结果
|
||||
*/
|
||||
protected abstract boolean doResotre(File file, Map<String, Object> params, OpertProcessListener processListener);
|
||||
|
||||
/**
|
||||
* @param operatorEvent The operatorEvent to set.
|
||||
*/
|
||||
public void setOperatorEvent(DBOperatorEvent operatorEvent) {
|
||||
this.operatorEvent = operatorEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出监听,同时添加日志信息
|
||||
* @param processListener 过程监听
|
||||
* @param msg 日志信息
|
||||
* @param log4jLevel 日志级别
|
||||
*/
|
||||
protected void onOutputAndLog(OpertProcessListener processListener, String msg, Level log4jLevel) {
|
||||
if (StringUtils.isNullOrEmpty(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processListener != null) {
|
||||
// 不支持中断
|
||||
if (processListener.getOutputListener() != null) {
|
||||
processListener.getOutputListener().onOutput(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (log4jLevel == null) {
|
||||
try {
|
||||
Thread.sleep(200); // 延迟加载信息
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 输出日志信息
|
||||
if (Level.ERROR.equals(log4jLevel)) {
|
||||
logger.error(msg);
|
||||
}
|
||||
else if (Level.WARN.equals(log4jLevel)) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
else if (Level.INFO.equals(log4jLevel)) {
|
||||
logger.info(msg);
|
||||
}
|
||||
else if (Level.DEBUG.equals(log4jLevel)) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
241
comm/DB/src/db/restore/MysqlRestoreImpl.java
Executable file
241
comm/DB/src/db/restore/MysqlRestoreImpl.java
Executable file
@@ -0,0 +1,241 @@
|
||||
package db.restore;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import db.Constants;
|
||||
import db.DBRestore;
|
||||
import db.OpertProcessListener;
|
||||
import db.PropertiesUtilDB;
|
||||
import db.util.CMDUtil;
|
||||
import db.util.FileUtil;
|
||||
import db.util.ZipUtils;
|
||||
import db.util.jdbc.DBTools;
|
||||
import db.util.jdbc.MysqlTools;
|
||||
|
||||
public class MysqlRestoreImpl extends AbstractRestoreImpl {
|
||||
|
||||
@Override
|
||||
protected String getBackupFileSuffix() {
|
||||
return ".zip";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> parserMapParams(Map<String, Object> params) {
|
||||
Assert.notNull(params);
|
||||
// 读取参数
|
||||
if (params.get("ip") == null) {
|
||||
// String ip = System.getProperty(DBPorperties.ENV_IP, MySQLConfig.DEFAULT_IP);
|
||||
String ip = PropertiesUtilDB.getProperty("db.ip");
|
||||
params.put("ip", ip);
|
||||
}
|
||||
|
||||
if (params.get("port") == null) {
|
||||
// String port = System.getProperty(DBPorperties.ENV_PORT, MySQLConfig.DEFAULT_PORT);
|
||||
String port = PropertiesUtilDB.getProperty("db.port");
|
||||
params.put("port", port);
|
||||
}
|
||||
|
||||
if (params.get("databaseName") == null) {
|
||||
// String databaseName = System.getProperty(DBPorperties.ENV_DBNAME, MySQLConfig.DEFAULT_DBNAME);
|
||||
String databaseName = PropertiesUtilDB.getProperty("db.databaseName");
|
||||
params.put("databaseName", databaseName);
|
||||
}
|
||||
|
||||
if (params.get("username") == null) {
|
||||
// String username = System.getProperty(DBPorperties.RUIJIE_JDBC_USERNAME);
|
||||
String username = PropertiesUtilDB.getProperty("db.username");
|
||||
params.put("username", username);
|
||||
}
|
||||
|
||||
if (params.get("password") == null) {
|
||||
// String password = System.getProperty(DBPorperties.RUIJIE_JDBC_PASSWORD);
|
||||
String password = PropertiesUtilDB.getProperty("db.password");
|
||||
params.put("password", password);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doResotre(File file, Map<String, Object> params, OpertProcessListener processListener) {
|
||||
Assert.notNull(params);
|
||||
onOutputAndLog(processListener, "Starting restore...", Level.INFO);
|
||||
|
||||
String filePath = file.getAbsolutePath();
|
||||
String restorePath = formatFilePath(filePath);
|
||||
FileUtil.deleteDir(restorePath, true);
|
||||
|
||||
// 解压备份文件
|
||||
ZipUtils.unZip(filePath, file.getParent() + File.separator);
|
||||
|
||||
// 删除旧数据
|
||||
// clearOldData(params, processListener);
|
||||
|
||||
// 还原数据库结构
|
||||
// restoreDBStruct(params, restorePath, processListener);
|
||||
|
||||
// 还原数据库表数据
|
||||
restoreDBData(params, restorePath, processListener);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearAfterRestore(File file, Map<String, Object> params) {
|
||||
// 数据库还原后,删除临时目录
|
||||
FileUtil.deleteDir(formatFilePath(file.getAbsolutePath()), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化待还原文件路径
|
||||
* @param filePath 待还原文件路径
|
||||
* @return 路径
|
||||
*/
|
||||
private String formatFilePath(String filePath) {
|
||||
String restorePath = filePath.substring(0, filePath.indexOf(getBackupFileSuffix()));
|
||||
restorePath = restorePath.replaceAll(Constants.FILE_SEPARATOR_REGEX, "/");
|
||||
return restorePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除旧数据(防止数据冲突)
|
||||
* @param params 参数
|
||||
* @param processListener 监听器
|
||||
*/
|
||||
private void clearOldData(Map<String, Object> params, OpertProcessListener processListener) {
|
||||
onOutputAndLog(processListener, "Clear old database data...", Level.INFO);
|
||||
|
||||
StringBuffer cmdBuf = new StringBuffer();
|
||||
cmdBuf.append(DBTools.formatDBClientCmd("mysql", "exe"));
|
||||
cmdBuf.append(" -h ").append((String) params.get("ip"));
|
||||
cmdBuf.append(" -P ").append((String) params.get("port")); // 端口
|
||||
cmdBuf.append(" --user=").append((String) params.get("username")); // 用户名
|
||||
cmdBuf.append(" --password=").append((String) params.get("password")); // 密码
|
||||
// cmdBuf.append(" --verbose -v "); // 详情信息模式
|
||||
|
||||
String dbName = (String) params.get("databaseName");
|
||||
cmdBuf.append(" ").append("-e \"DROP DATABASE IF EXISTS ").append(dbName).append(";");
|
||||
cmdBuf.append("CREATE DATABASE ").append(dbName).append(" DEFAULT CHARACTER SET utf8; \" ");
|
||||
executeRuntimeCmd(cmdBuf.toString(), processListener);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原数据库结构
|
||||
* @param params 参数
|
||||
* @param restorePath 备份文件目录
|
||||
* @param processListener 监听器
|
||||
*/
|
||||
private void restoreDBStruct(Map<String, Object> params, String restorePath, OpertProcessListener processListener) {
|
||||
onOutputAndLog(processListener, "Restore database structs...", Level.INFO);
|
||||
|
||||
StringBuffer cmdBuf = new StringBuffer();
|
||||
cmdBuf.append(DBTools.formatDBClientCmd("mysql", "exe"));
|
||||
cmdBuf.append(" -h ").append((String) params.get("ip"));
|
||||
cmdBuf.append(" -P ").append((String) params.get("port")); // 端口
|
||||
cmdBuf.append(" --user=").append((String) params.get("username")); // 用户名
|
||||
cmdBuf.append(" --password=").append((String) params.get("password")); // 密码
|
||||
// cmdBuf.append(" --verbose -v "); // 详情信息模式
|
||||
|
||||
String databaseName = (String) params.get("databaseName");
|
||||
cmdBuf.append(" ").append(databaseName);
|
||||
cmdBuf.append(" ").append("-e \"SET FOREIGN_KEY_CHECKS=0;");
|
||||
cmdBuf.append("SOURCE ").append(restorePath).append("/db_struct.sql ; \" ");
|
||||
|
||||
executeRuntimeCmd(cmdBuf.toString(), processListener); // 执行CMD
|
||||
|
||||
onOutputAndLog(processListener, "restore Structs finished", Level.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原数据库数据
|
||||
* @param params 参数
|
||||
* @param restorePath 备份文件目录
|
||||
* @param processListener 监听器
|
||||
*/
|
||||
private void restoreDBData(Map<String, Object> params, String restorePath, OpertProcessListener processListener) {
|
||||
onOutputAndLog(processListener, "Importing Data...", Level.INFO);
|
||||
|
||||
String ip = (String) params.get("ip");
|
||||
String port = (String) params.get("port");
|
||||
String databaseName = (String) params.get("databaseName");
|
||||
String username = (String) params.get("username");
|
||||
String password = (String) params.get("password");
|
||||
|
||||
StringBuffer preCmd = new StringBuffer();
|
||||
preCmd.append(DBTools.formatDBClientCmd("mysql", "exe"));
|
||||
preCmd.append(" -h ").append(ip);
|
||||
preCmd.append(" -P ").append(port); // 端口
|
||||
preCmd.append(" --user=").append(username); // 用户名
|
||||
preCmd.append(" --password=").append(password); // 密码
|
||||
// preCmd.append(" --verbose -v "); // 详情信息模式
|
||||
preCmd.append(" ").append(databaseName);
|
||||
preCmd.append(" ").append("-e ");
|
||||
|
||||
// 获取数据库表
|
||||
List<String> tables = MysqlTools.findAllDBTables(ip, port, databaseName, username, password);
|
||||
for (int index = 0; index < tables.size(); index++) {
|
||||
String tableName = tables.get(index);
|
||||
onOutputAndLog(processListener, "Table Restored: " + tableName, Level.INFO);
|
||||
|
||||
String tableDataFilePath = restorePath + "/" + tableName + ".txt";
|
||||
StringBuilder cmdBuf = new StringBuilder();
|
||||
cmdBuf.append(preCmd);
|
||||
cmdBuf.append(" \"LOCK TABLES " + tableName + " WRITE;"); // 锁表
|
||||
cmdBuf.append("SET FOREIGN_KEY_CHECKS=0;"); // 不进行外键检查
|
||||
|
||||
// 导入表数据
|
||||
cmdBuf.append("LOAD DATA INFILE '");
|
||||
cmdBuf.append(tableDataFilePath).append("'");
|
||||
cmdBuf.append("INTO TABLE ").append(tableName);
|
||||
cmdBuf.append(" FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"';");
|
||||
|
||||
cmdBuf.append(" UNLOCK TABLES;").append(" \" "); // 解锁表
|
||||
// cmdBuf.append("\n");
|
||||
executeRuntimeCmd(cmdBuf.toString(), processListener); // 执行CMD
|
||||
}
|
||||
|
||||
onOutputAndLog(processListener, "Importing Data finished", Level.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行CMD
|
||||
* @param cmd cmd命令
|
||||
* @param processListener 监听器
|
||||
*/
|
||||
private void executeRuntimeCmd(String cmd, OpertProcessListener processListener) {
|
||||
try {
|
||||
// if (processListener == null || processListener.getOutputListener() == null) {
|
||||
// RuntimeExecutorResult result = RuntimeExecutor.execute(cmd, "GB2312");
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// logger.debug(result.getOutput());
|
||||
// logger.debug(result.getError());
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// MessageOutputListener outputListener = new MessageOutputListener();
|
||||
// RuntimeExecutor.execute(cmd, "GB2312", outputListener);
|
||||
// while (!outputListener.isFinish()) {
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
// onOutputAndLog(processListener, outputListener.getOutputString(), null);
|
||||
// }
|
||||
logger.info(cmd);
|
||||
String cmdResult = CMDUtil.runCMD(cmd);
|
||||
logger.info("result:"+cmdResult);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DBRestore dbBack = new MysqlRestoreImpl();
|
||||
String filePath = "C:\\e\\backup\\blockchain_nes_20201030161757-734.zip";
|
||||
dbBack.restore(filePath, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
302
comm/DB/src/db/support/DBBackupRecordServiceImpl.java
Executable file
302
comm/DB/src/db/support/DBBackupRecordServiceImpl.java
Executable file
@@ -0,0 +1,302 @@
|
||||
package db.support;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.DateFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import db.Constants;
|
||||
import db.DBBackupRecord;
|
||||
import db.DBBackupRecordService;
|
||||
import db.map.CacheMap;
|
||||
import db.util.ConfigUtils;
|
||||
import db.util.HandleXML;
|
||||
import db.util.IOUtil;
|
||||
import kernel.util.DateUtils;
|
||||
|
||||
public class DBBackupRecordServiceImpl implements DBBackupRecordService {
|
||||
|
||||
/**
|
||||
* LOG
|
||||
*/
|
||||
private Logger logger = LogManager.getLogger(this.getClass().getName());
|
||||
|
||||
/**
|
||||
* 备份信息XML存储路径
|
||||
*/
|
||||
private final static String BACKUP_RECORD_XML_PATH = ConfigUtils.getBackupRecordXMLPath();
|
||||
|
||||
/**
|
||||
* 文件锁
|
||||
*/
|
||||
private ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
/**
|
||||
* 备份信息缓存
|
||||
*/
|
||||
private static CacheMap<Serializable, DBBackupRecord> BKRECORD_CACHE = new CacheMap<Serializable, DBBackupRecord>();
|
||||
|
||||
/**
|
||||
* 备份文件保存个数最大限值
|
||||
*/
|
||||
private static Integer MAX_LIMIT_NUM;
|
||||
|
||||
/**
|
||||
* 默认备份文件个数最大限值
|
||||
*/
|
||||
private static Integer DEFAULT_MAX_LIMITNUM = 20;
|
||||
|
||||
@Override
|
||||
public Integer getMaxLimitNum() {
|
||||
if (MAX_LIMIT_NUM == null) {
|
||||
MAX_LIMIT_NUM = DEFAULT_MAX_LIMITNUM;
|
||||
}
|
||||
return MAX_LIMIT_NUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxLimitNum(Integer limitNum) {
|
||||
if (limitNum == null) {
|
||||
throw new RuntimeException("database_maxLimitNum_setting_null");
|
||||
}
|
||||
MAX_LIMIT_NUM = limitNum;
|
||||
|
||||
lock.writeLock().lock();
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
File file = new File(BACKUP_RECORD_XML_PATH);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
fis = new FileInputStream(BACKUP_RECORD_XML_PATH);
|
||||
Document document = HandleXML.getDocument(fis, "DbBackupRecordList");
|
||||
|
||||
Element maxLimitNumE = (Element) document.selectSingleNode("/DbBackupRecordList/maxLimitNum");
|
||||
if (maxLimitNumE == null) {
|
||||
maxLimitNumE = document.getRootElement().addElement("maxLimitNum");
|
||||
}
|
||||
maxLimitNumE.setText(String.valueOf(MAX_LIMIT_NUM));
|
||||
|
||||
HandleXML.writeToXML(document, BACKUP_RECORD_XML_PATH);
|
||||
} catch (Exception e) {
|
||||
logger.error("error", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(fis);
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DBBackupRecord> findAll() {
|
||||
return BKRECORD_CACHE.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBBackupRecord findByUuid(Serializable uuid) {
|
||||
if (uuid == null) {
|
||||
throw new RuntimeException("database_backuprecord_uuid_null");
|
||||
// throw new FastFailException(MessageFormat.format("database_backuprecord_uuid_null"));
|
||||
}
|
||||
return BKRECORD_CACHE.get(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DBBackupRecord record) {
|
||||
if (record == null) {
|
||||
throw new RuntimeException("database_backuprecord_add_null");
|
||||
// throw new FastFailException(MessageFormat.format("database_backuprecord_add_null"));
|
||||
}
|
||||
|
||||
lock.writeLock().lock();
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(BACKUP_RECORD_XML_PATH);
|
||||
Document document = HandleXML.getDocument(fis, "DbBackupRecordList");
|
||||
Element root = document.getRootElement();
|
||||
Element recordNode = root.addElement("DbBackupRecord");
|
||||
String uuid = record.getUuid();
|
||||
recordNode.addAttribute("uuid", uuid != null ? uuid : "");
|
||||
|
||||
Element nameNode = recordNode.addElement("name");
|
||||
nameNode.setText(record.getName() != null ? record.getName() : "");
|
||||
|
||||
Element filePathNode = recordNode.addElement("filePath");
|
||||
filePathNode.setText(record.getFilePath() != null ? record.getFilePath() : "");
|
||||
|
||||
DateFormat sdf = DateUtils.createDateFormat(Constants.DB_BACKUP_TIME_FORMAT);
|
||||
Element timePathNode = recordNode.addElement("backupTime");
|
||||
timePathNode.setText(record.getBackupTime() != null ? sdf.format(record.getBackupTime()) : "");
|
||||
|
||||
Element fileSizeNode = recordNode.addElement("fileSize");
|
||||
fileSizeNode.setText(String.valueOf(record.getFileSize()));
|
||||
|
||||
Element descriptionNode = recordNode.addElement("description");
|
||||
String description = record.getDescription();
|
||||
descriptionNode.setText(description == null ? "" : description);
|
||||
|
||||
// 超过最大限制值,去除旧备份
|
||||
if (BKRECORD_CACHE.size() >= getMaxLimitNum()) {
|
||||
HandleXML.deleteFirstNode("/DbBackupRecordList/DbBackupRecord", document);
|
||||
}
|
||||
|
||||
HandleXML.writeToXML(document, BACKUP_RECORD_XML_PATH);
|
||||
} catch (Exception e) {
|
||||
logger.error("error", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(fis);
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
putBackupRecordCache(record);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Serializable uuid) {
|
||||
if (uuid == null) {
|
||||
throw new RuntimeException("database_backuprecord_delete_null");
|
||||
// throw new FastFailException(MessageFormat.format("database_backuprecord_delete_null"));
|
||||
}
|
||||
|
||||
DBBackupRecord record = BKRECORD_CACHE.get(uuid);
|
||||
if (record == null) {
|
||||
throw new RuntimeException("database_backuprecord_delete_null");
|
||||
// throw new FastFailException(MessageFormat.format("database_backuprecord_delete_null"));
|
||||
}
|
||||
|
||||
// 删除备份文件
|
||||
File file = new File(record.getFilePath());
|
||||
if (file.exists()) {
|
||||
if (file.delete()) {
|
||||
String msg = MessageFormat.format("database_backuprecord_delete_file_failed", file.getAbsoluteFile());
|
||||
throw new RuntimeException(msg);
|
||||
// throw new FastFailException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
lock.writeLock().lock();
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(BACKUP_RECORD_XML_PATH);
|
||||
Document document = HandleXML.getDocument(fis, "DbBackupRecordList");
|
||||
String xpathExpression = "/DbBackupRecordList/DbBackupRecord[@uuid=\"" + uuid + "\"]";
|
||||
Element ele = (Element) document.selectSingleNode(xpathExpression);
|
||||
if (ele != null) {
|
||||
ele.getParent().remove(ele);
|
||||
}
|
||||
|
||||
HandleXML.writeToXML(document, BACKUP_RECORD_XML_PATH);
|
||||
} catch (Exception e) {
|
||||
logger.error("error", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(fis);
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
removeBackupRecordCache(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByIds(Serializable[] ids) {
|
||||
int count = 0;
|
||||
for (Serializable id : ids) {
|
||||
delete(id);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 存入缓存 </p>
|
||||
* <p>Create Time: 2013-2-5 </p>
|
||||
* @author weiminghua
|
||||
* @param record 备份记录
|
||||
*/
|
||||
private void putBackupRecordCache(DBBackupRecord record) {
|
||||
BKRECORD_CACHE.put(record.getUuid(), record);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 从缓存中删除数据 </p>
|
||||
* <p>Create Time: 2013-2-5 </p>
|
||||
* @author weiminghua
|
||||
* @param uuid 备份记录ID
|
||||
*/
|
||||
private void removeBackupRecordCache(Serializable uuid) {
|
||||
BKRECORD_CACHE.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
lock.readLock().lock();
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
File file = new File(BACKUP_RECORD_XML_PATH);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
fis = new FileInputStream(BACKUP_RECORD_XML_PATH);
|
||||
Document document = HandleXML.getDocument(fis, "DbBackupRecordList");
|
||||
|
||||
Element maxLimitNumE = (Element) document.selectSingleNode("/DbBackupRecordList/maxLimitNum");
|
||||
if (maxLimitNumE != null) {
|
||||
MAX_LIMIT_NUM = Integer.parseInt(maxLimitNumE.getText());
|
||||
}
|
||||
|
||||
// 读取已有备份信息
|
||||
List<?> list = document.selectNodes("/DbBackupRecordList/DbBackupRecord");
|
||||
Iterator<?> iter = list.iterator();
|
||||
|
||||
DateFormat sdf = DateUtils.createDateFormat(Constants.DB_BACKUP_TIME_FORMAT);
|
||||
while (iter.hasNext()) {
|
||||
Element e = (Element) iter.next();
|
||||
DBBackupRecord record = new DBBackupRecord();
|
||||
record.setUuid(e.attribute("uuid").getValue());
|
||||
|
||||
Element nameE = e.element("name");
|
||||
if (nameE != null) {
|
||||
record.setName(nameE.getText());
|
||||
}
|
||||
|
||||
Element backupTimeE = e.element("backupTime");
|
||||
if (backupTimeE != null) {
|
||||
record.setBackupTime(sdf.parse(backupTimeE.getText()));
|
||||
}
|
||||
|
||||
Element filePathE = e.element("filePath");
|
||||
if (filePathE != null) {
|
||||
record.setFilePath(filePathE.getText());
|
||||
}
|
||||
|
||||
Element fileSizeE = e.element("fileSize");
|
||||
if (fileSizeE != null) {
|
||||
record.setFileSize(Long.valueOf(fileSizeE.getText()));
|
||||
}
|
||||
|
||||
Element descriptionE = e.element("description");
|
||||
if (descriptionE != null) {
|
||||
record.setDescription(descriptionE.getText());
|
||||
}
|
||||
|
||||
putBackupRecordCache(record); // 加入缓存
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("error", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(fis);
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
44
comm/DB/src/db/support/DefaultOpertProcessListener.java
Executable file
44
comm/DB/src/db/support/DefaultOpertProcessListener.java
Executable file
@@ -0,0 +1,44 @@
|
||||
package db.support;
|
||||
|
||||
import db.OpertProcessListener;
|
||||
|
||||
public class DefaultOpertProcessListener implements OpertProcessListener {
|
||||
|
||||
/**
|
||||
* 输出信息监听器
|
||||
*/
|
||||
private MessageOutputListener outputListener = new MessageOutputListener();
|
||||
|
||||
/**
|
||||
* 是否结束
|
||||
*/
|
||||
private boolean isFinish = false;
|
||||
|
||||
/**
|
||||
* @return 输出信息监听器
|
||||
*/
|
||||
@Override
|
||||
public MessageOutputListener getOutputListener() {
|
||||
return outputListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt() {
|
||||
onExit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit() {
|
||||
isFinish = true;
|
||||
outputListener.onExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否中止
|
||||
*/
|
||||
@Override
|
||||
public boolean isFinish() {
|
||||
return isFinish;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user