Commit da4fcc8b by 孙龙

up

parent f092bbdb
...@@ -3,6 +3,7 @@ namespace App\Http\Controllers; ...@@ -3,6 +3,7 @@ namespace App\Http\Controllers;
use App\Exceptions\IcException; use App\Exceptions\IcException;
use App\Exceptions\MicroException; use App\Exceptions\MicroException;
use App\Model\AsyncTaskModel;
use App\Model\OfflinePrintModel; use App\Model\OfflinePrintModel;
use App\Model\ServiceLoadBalanceModel; use App\Model\ServiceLoadBalanceModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
...@@ -12,6 +13,7 @@ use Log; ...@@ -12,6 +13,7 @@ use Log;
use App\Model\MicroServiceInfoModel; use App\Model\MicroServiceInfoModel;
use App\Model\ServiceAccessControlModel; use App\Model\ServiceAccessControlModel;
use App\Model\ServiceHttpRuleModel; use App\Model\ServiceHttpRuleModel;
use GuzzleHttp\Client;
Class AjaxController extends Controller Class AjaxController extends Controller
{ {
...@@ -214,9 +216,68 @@ Class AjaxController extends Controller ...@@ -214,9 +216,68 @@ Class AjaxController extends Controller
}else{ }else{
return $this->_addMicroService($request); return $this->_addMicroService($request);
} }
}
//任务列表
public function getAsyncTaskList(Request $request){
$page = $request->input("page",1);
$limit = $request->input("limit",10);
$query = AsyncTaskModel::select('*') ->OrderBy("id","desc");
$query = $query->paginate($limit,[],'page',$page);
$list = $query->toArray();
foreach($list["data"] as &$item){
$item["fail_reason"] = htmlspecialchars(mb_strcut($item["fail_reason"],0,100,'utf-8'));
}
return ['code'=>0, 'count'=>$list['total'],'data'=>$list["data"]];
}
/*
* 推送服务
*/
public function repeatPush(Request $request){
$id = $request->input("id","");
if(intval($id) <= 0){
return $this->ajaxReturn(-1,"没有找到该条任务信息");
}
$info = AsyncTaskModel::find(intval($id));
$client = new Client();
$res = $client->request("post",env("ASYNC_TASK_URL"),[
"form_params"=>[
"callbackDomain"=>$info->callback_domain,
"callbackUri"=>$info->callback_uri,
"requestType"=>$info->request_type,
"data"=>$info->data,
"method"=>$info->method,
"serviceType"=>$info->service_type,
"header"=>$info->header,
"isHttpJson"=>$info->is_http_json,
"remark"=>$info->remark,
"callback_func"=>$info->callback_func,
],
"headers"=>[
"api-key"=>"async task qwert12345",
],
]);
$result = $res->getBody()->getContents();
try{
$result = json_decode($result,true);
if(isset($result["err_code"]) && $result["err_code"] == 0){
return $this->ajaxReturn(0,"推送成功");
}else{
return $this->ajaxReturn($result["err_code"],$result["err_msg"]);
} }
}catch(\Exception $e){
return $this->ajaxReturn(-1,sprintf("请求失败,:%s",$e->getMessage()));
}
}
} }
\ No newline at end of file
...@@ -98,6 +98,12 @@ class WebController extends Controller ...@@ -98,6 +98,12 @@ class WebController extends Controller
} }
public function asyncTask($request, $info){
$info['title'] = '任务列表';
return view('web', $info);
}
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class AsyncTaskModel extends Model{
protected $connection = 'async_task'; //库名
protected $table = 'async_task';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = null;
protected $dateFormat = 'Y-m-d H:i:s';
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
}
\ No newline at end of file
...@@ -84,6 +84,19 @@ return [ ...@@ -84,6 +84,19 @@ return [
'strict' => false, 'strict' => false,
], ],
'async_task' => [
'driver' => 'mysql',
'host' => env('DB_ASYNCTASK_HOST', ''),
'database' => env('DB_ASYNCTASK_DATABASE', ''),
'username' => env('DB_ASYNCTASK_USERNAME', ''),
'password' => env('DB_ASYNCTASK_PASSWORD', ''),
'port' => env('DB_PORT', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lie_',
'strict' => false,
],
'web' => [ 'web' => [
'driver' => 'mysql', 'driver' => 'mysql',
'host' => env('DB_WEB_HOST', ''), 'host' => env('DB_WEB_HOST', ''),
......
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
form.render();
table.render({
elem: '#list'
,url: '/ajax/getAsyncTaskList' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,where: {
}
,defaultToolbar:{}
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,cols: [[ //表头
{title: 'ID',field:"id",fixed: 'left', width: 80}
,{field: 'service_type', title: '服务编码',width: 120}
,{field: 'remark', title: '服务描述',width: 160}
,{field: 'request_type', title: '请求类型',width: 120}
,{field: 'callback_domain', title: '请求域',width: 200}
,{field: 'callback_uri', title: '请求uri',width: 120}
,{field: 'callback_func', title: 'rpc回调函数',width: 120}
,{field: 'data', title: '请求参数data',width: 120}
,{field: 'header', title: 'header',width: 200}
,{field: 'method', title: 'method',width: 100}
,{field: 'is_http_json', title: '是否json请求',width: 120,templet:"#is_http_json"}
,{field: 'status', title: '状态',width: 100,templet:"#status"}
,{field: 'fail_reason', title: '返回结果',width: 120}
,{field: 'create_time', title: '创建时间', width: 200}
,{ title: '操作', fixed: 'right', toolbar: '#action',width: 120}
]]
,limit: 10
,limits: [10, 20, 50,]
});
form.on('submit(load)', function(data) {
//console.log(data)
//执行重载
table.reload('list', {
page: {
curr: 1
},
url: '/ajax/labelList' //数据接口
,where: data.field
});
return false;
});
var enable_tool = function (title,content,url,datax){
layer.open({
title: title,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
$.ajax({
url : url,
type: 'post',
data: datax,
success: function(resp) {
if (resp.err_code == 0) {
layer.msg(resp.err_msg);
// renderTable(); // 重新加载table
//$('.search').trigger("click"); // 触发搜索按钮
window.location.reload()
return false;
}
layer.alert(resp.err_msg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
//监听工具条
table.on('tool(list)', function(obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的 DOM 对象(如果有的话)
if (layEvent == "edit"){
id = data.id
window.location.href="/web/addMicroService?load_type=0&type=edit&id="+id
}else if (layEvent == "repeatPush"){
title = '推送任务';
content = "确定推送任务?";
url = '/ajax/repeatPush';
datax = {id:data.id}
enable_tool(title,content,url,datax);
}
})
//头工具栏事件
table.on('toolbar(list)', function(obj){
//var checkStatus = table.checkStatus(obj.config.id);
//switch(obj.event){
// case 'getCheckData':
// window.location.href= "/web/addMicroService?load_type=0&type=add"
// break;
//};
});
});
\ No newline at end of file
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<div class=" layui-form layui-form-text"> <div class=" layui-form layui-form-text">
<label class="layui-form-label">客户端限流</label> <label class="layui-form-label">客户端限流</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="clientip_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->clientip_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制" autocomplete="off" class="layui-input"> <input type="text" name="clientip_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->clientip_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制; 速率QPS/秒" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<div class=" layui-form-item layui-form-text"> <div class=" layui-form-item layui-form-text">
<label class="layui-form-label">服务端限流</label> <label class="layui-form-label">服务端限流</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="service_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->service_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制" autocomplete="off" class="layui-input"> <input type="text" name="service_flow_limit" required value="{{isset($microInfo) ? $microInfo->service_access_control->service_flow_limit : 0}}" lay-verify="required" placeholder="0表示不限制 ;速率QPS/秒" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
......
@if (session('showTemplateerror'))
<div class="alert alert-success">
{{ session('showTemplateerror') }}
</div>
@endif
<table id="list" lay-filter="list"></table>
{{--<script type="text/html" id="toolbarDemo">--}}
{{--<div class="layui-btn-container">--}}
{{--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加http服务</button>--}}
{{--</div>--}}
{{--</script>--}}
<script type="text/html" id="action">
<a title="删除" class="btn btn-xs btn-outline btn-info" lay-event="repeatPush">重新推送</a>
</script>
<script type="text/html" id="status">
@{{# if (d.status == 0) { }}
等待处理
@{{# }else if (d.status == 1) { }}
处理中
@{{# }else if (d.status == 3) { }}
处理失败
@{{# }else if (d.status == 5) { }}
处理成功
@{{# } }}
</script>
<script type="text/html" id="is_http_json">
@{{# if (d.is_http_json == 0) { }}
@{{# }else if (d.is_http_json == 1) { }}
@{{# } }}
</script>
...@@ -107,7 +107,7 @@ class MonitorDingClient { ...@@ -107,7 +107,7 @@ class MonitorDingClient {
$data = json_decode(curl_exec($ch), true); $data = json_decode(curl_exec($ch), true);
curl_close($ch); curl_close($ch);
if ($data['errcode']) { if (isset($data['errcode']) && $data['errcode']) {
throw new SendErrorException($data['errmsg']); throw new SendErrorException($data['errmsg']);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment