This commit is contained in:
njdaoyehu 2024-11-22 13:35:39 +08:00
parent f4735025c6
commit 5e661d51e5
29 changed files with 70 additions and 41 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
var D=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var x=(s,d)=>{var i={};for(var e in s)M.call(s,e)&&d.indexOf(e)<0&&(i[e]=s[e]);if(s!=null&&D)for(var e of D(s))d.indexOf(e)<0&&P.call(s,e)&&(i[e]=s[e]);return i};import{j as $,k as j,S as N,l as A,_ as H}from"./index.js";import{u as O,B as V}from"./useTable-acfc2b97.js";import{T as z}from"./useForm-7410be87.js";import{j as h}from"./antd-029ed741.js";import{r as E,s as F}from"./deviceApi-af691457.js";import{u as K}from"./index-e0942325.js";import{D as G,c as U,s as C}from"./drawer-3216c8ce.js";import{d as W,a6 as Z,Z as S,_ as q,$ as Y,k as p,u as l,a5 as b,G as J,a4 as L,a8 as Q}from"./vue-72a104e4.js";import"./index-5157bbb9.js";import"./useWindowSizeFn-46f0db92.js";import"./onMountedOrActivated-ee461833.js";import"./sortable.esm-15c0a34e.js";import"./copyTextToClipboard-8577151f.js";const X={class:"header"},ee=W({__name:"index",setup(s){$(),j();const[d,{openDrawer:i}]=K(),[e,{reload:v,setSelectedRowKeys:te}]=O({api:t=>F(w(t)),columns:U,formConfig:{labelWidth:0,schemas:C,showAdvancedButton:!1},useSearchForm:!0,showTableSetting:!1,bordered:!0,showIndexColumn:!1,canResize:!1,rowKey:t=>t.id,actionColumn:{width:180,title:"操作",dataIndex:"action",fixed:void 0}}),w=t=>{const g=t,{pageNum:n,pageSize:u,field:f="id",order:m="descend"}=g,R=x(g,["pageNum","pageSize","field","order"]),a={pageNum:n,pageSize:u,orderByClause:`${f} ${m==="descend"?"desc":"asc"}`};return Object.keys(R).forEach(_=>{const c=C.find(I=>I.field===_),o=t[_],r=_;c?o!==void 0&&o!==""&&(c.component==="Input"?a[r]=`%${o.trim()}%`:["Select","ApiSelect","ApiTreeSelect"].includes(c.component)?a[r]=A(o)?o.value:o:c.component==="RangePicker"?(a[`${r}From`]=h(o[0]).startOf("d").format("YYYY-MM-DD HH:mm:ss"),a[`${r}To`]=h(o[1]).endOf("d").format("YYYY-MM-DD HH:mm:ss")):c.component==="DatePicker"?a[r]=h(o).format(c.componentProps.format||"YYYY-MM-DD"):a[r]=o):a[r]=o}),a},y=()=>{i(!0,{isUpdate:!1})},k=t=>{i(!0,{record:t,isUpdate:!0})},T=t=>{E(t.id).then(n=>{v()})},B=()=>{v()};return(t,n)=>{const u=Z("a-button");return S(),q("div",null,[Y("div",X,[p(l(N),{size:"19",name:"list"}),n[0]||(n[0]=Y("div",{class:"title"},"设备列表",-1))]),p(l(V),{onRegister:l(e)},{toolbar:b(()=>[p(u,{type:"primary",onClick:y},{default:b(()=>n[1]||(n[1]=[J("新增")])),_:1})]),bodyCell:b(({column:f,record:m})=>[f.dataIndex==="action"?(S(),L(l(z),{key:0,actions:[{label:"编辑",icon:"clarity:note-edit-line",onClick:k.bind(null,m),divider:!0},{label:"删除",icon:"ant-design:delete-outlined",color:"error",popConfirm:{title:"是否确认删除",confirm:T.bind(null,m),placement:"topRight"}}]},null,8,["actions"])):Q("",!0)]),_:1},8,["onRegister"]),p(G,{onRegister:l(d),onSuccess:B},null,8,["onRegister"])])}}});const he=H(ee,[["__scopeId","data-v-c43e7a7c"]]);export{he as default}; var D=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var x=(s,d)=>{var i={};for(var e in s)M.call(s,e)&&d.indexOf(e)<0&&(i[e]=s[e]);if(s!=null&&D)for(var e of D(s))d.indexOf(e)<0&&P.call(s,e)&&(i[e]=s[e]);return i};import{j as $,k as j,S as N,l as A,_ as H}from"./index.js";import{u as O,B as V}from"./useTable-acfc2b97.js";import{T as z}from"./useForm-7410be87.js";import{j as h}from"./antd-029ed741.js";import{r as E,s as F}from"./deviceApi-af691457.js";import{u as K}from"./index-e0942325.js";import{D as G,c as U,s as C}from"./drawer-8a793a9f.js";import{d as W,a6 as Z,Z as S,_ as q,$ as Y,k as p,u as l,a5 as b,G as J,a4 as L,a8 as Q}from"./vue-72a104e4.js";import"./index-5157bbb9.js";import"./useWindowSizeFn-46f0db92.js";import"./onMountedOrActivated-ee461833.js";import"./sortable.esm-15c0a34e.js";import"./copyTextToClipboard-8577151f.js";const X={class:"header"},ee=W({__name:"index",setup(s){$(),j();const[d,{openDrawer:i}]=K(),[e,{reload:v,setSelectedRowKeys:te}]=O({api:t=>F(w(t)),columns:U,formConfig:{labelWidth:0,schemas:C,showAdvancedButton:!1},useSearchForm:!0,showTableSetting:!1,bordered:!0,showIndexColumn:!1,canResize:!1,rowKey:t=>t.id,actionColumn:{width:180,title:"操作",dataIndex:"action",fixed:void 0}}),w=t=>{const g=t,{pageNum:n,pageSize:u,field:f="id",order:m="descend"}=g,R=x(g,["pageNum","pageSize","field","order"]),a={pageNum:n,pageSize:u,orderByClause:`${f} ${m==="descend"?"desc":"asc"}`};return Object.keys(R).forEach(_=>{const c=C.find(I=>I.field===_),o=t[_],r=_;c?o!==void 0&&o!==""&&(c.component==="Input"?a[r]=`%${o.trim()}%`:["Select","ApiSelect","ApiTreeSelect"].includes(c.component)?a[r]=A(o)?o.value:o:c.component==="RangePicker"?(a[`${r}From`]=h(o[0]).startOf("d").format("YYYY-MM-DD HH:mm:ss"),a[`${r}To`]=h(o[1]).endOf("d").format("YYYY-MM-DD HH:mm:ss")):c.component==="DatePicker"?a[r]=h(o).format(c.componentProps.format||"YYYY-MM-DD"):a[r]=o):a[r]=o}),a},y=()=>{i(!0,{isUpdate:!1})},k=t=>{i(!0,{record:t,isUpdate:!0})},T=t=>{E(t.id).then(n=>{v()})},B=()=>{v()};return(t,n)=>{const u=Z("a-button");return S(),q("div",null,[Y("div",X,[p(l(N),{size:"19",name:"list"}),n[0]||(n[0]=Y("div",{class:"title"},"设备列表",-1))]),p(l(V),{onRegister:l(e)},{toolbar:b(()=>[p(u,{type:"primary",onClick:y},{default:b(()=>n[1]||(n[1]=[J("新增")])),_:1})]),bodyCell:b(({column:f,record:m})=>[f.dataIndex==="action"?(S(),L(l(z),{key:0,actions:[{label:"编辑",icon:"clarity:note-edit-line",onClick:k.bind(null,m),divider:!0},{label:"删除",icon:"ant-design:delete-outlined",color:"error",popConfirm:{title:"是否确认删除",confirm:T.bind(null,m),placement:"topRight"}}]},null,8,["actions"])):Q("",!0)]),_:1},8,["onRegister"]),p(G,{onRegister:l(d),onSuccess:B},null,8,["onRegister"])])}}});const he=H(ee,[["__scopeId","data-v-c43e7a7c"]]);export{he as default};

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
var T=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var M=(r,b)=>{var f={};for(var n in r)U.call(r,n)&&b.indexOf(n)<0&&(f[n]=r[n]);if(r!=null&&T)for(var n of T(r))b.indexOf(n)<0&&z.call(r,n)&&(f[n]=r[n]);return f};import{j as F,k as J,S as G,m,l as Q,_ as W}from"./index.js";import{u as L,B as Z}from"./useTable-acfc2b97.js";import{T as q}from"./useForm-7410be87.js";import{N as X,O as ee,Q as te,R as se,j as _}from"./antd-029ed741.js";import{r as ne,s as ae,c as oe,a as Y}from"./schema-6fd16fbe.js";import{u as ie}from"./index-e0942325.js";import le from"./drawer-03037505.js";import{d as re,f as de,a6 as ce,Z as O,_ as ue,$ as h,k as c,u as i,a5 as p,l as v,G as y,a4 as me,a8 as pe}from"./vue-72a104e4.js";import"./index-5157bbb9.js";import"./useWindowSizeFn-46f0db92.js";import"./onMountedOrActivated-ee461833.js";import"./sortable.esm-15c0a34e.js";import"./copyTextToClipboard-8577151f.js";import"./deviceApi-af691457.js";const fe={class:"header"},ge=re({__name:"index",setup(r){const{hasPermission:b}=F(),f=J(),n=de([]),N=t=>{n.value=t.filter(e=>typeof e!="undefined")},[P,{openDrawer:C}]=ie(),[A,{reload:S}]=L({api:t=>ae(B(t)),columns:oe,formConfig:{labelWidth:0,schemas:Y,showAdvancedButton:!1},rowSelection:{type:"checkbox",onChange:N,getCheckboxProps:t=>({disabled:t.state!==0})},useSearchForm:!0,showTableSetting:!1,bordered:!0,showIndexColumn:!1,canResize:!1,rowKey:t=>t.id,actionColumn:{width:420,title:"操作",dataIndex:"action",fixed:void 0}}),B=t=>{const D=t,{pageNum:e,pageSize:s,field:g="id",order:a="descend"}=D,H=M(D,["pageNum","pageSize","field","order"]),d={pageNum:e,pageSize:s,orderByClause:`${g} ${a==="descend"?"desc":"asc"}`};return Object.keys(H).forEach(k=>{const u=Y.find(K=>K.field===k),o=t[k];let l=k;u?o!==void 0&&o!==""&&(u.component==="Input"?d[l]=`%${o.trim()}%`:["Select","ApiSelect","ApiTreeSelect"].includes(u.component)?d[l]=Q(o)?o.value:o:u.component==="RangePicker"?(l==="startTimeQuery"&&(l="startTime"),d[`${l}From`]=_(o[0]).startOf("d").format("YYYY-MM-DD HH:mm:ss"),d[`${l}To`]=_(o[1]).endOf("d").format("YYYY-MM-DD HH:mm:ss")):u.component==="DatePicker"?d[l]=_(o).format(u.componentProps.format||"YYYY-MM-DD"):d[l]=o):d[l]=o}),d},E=()=>{C(!0,{isUpdate:!1})},I=t=>{C(!0,{record:t,isUpdate:!0})},R=t=>{ne(t.id).then(e=>{S()})},V=()=>{S()},$=t=>{f("/data/task/"+t.id)},j=()=>{WebViewService.importExcel().then(t=>{m().createMessage.success("数据导入成功!");const e=JSON.parse(t);if(e.length===0)return;const s=e[0].name;e.forEach(a=>{delete a.name});const g={name:s,paramJson:JSON.stringify(e)};C(!0,{record:g,isUpdate:!1})},t=>{m().createMessage.error(t)})},w=t=>{const e=[...new Set([...t.id?[t.id]:[],...n.value.map(s=>s)])];DeviceClientService.assignTasks(e).then(()=>{m().createMessage.success("下发任务成功!")},s=>{m().createMessage.error(s)})},x=t=>{const e=[...new Set([...t.id?[t.id]:[],...n.value.map(s=>s)])];DeviceClientService.syncTasks(e).then(()=>{m().createMessage.success("同步任务成功!"),S()},s=>{m().createMessage.error(s)})};return(t,e)=>{const s=ce("a-button");return O(),ue("div",null,[h("div",fe,[c(i(G),{size:"19",name:"list"}),e[0]||(e[0]=h("div",{class:"title"},"任务列表",-1))]),c(i(Z),{onRegister:i(A)},{toolbar:p(()=>[c(s,{type:"primary",onClick:E,icon:v(i(X))},{default:p(()=>e[1]||(e[1]=[y("新增")])),_:1},8,["icon"]),e[5]||(e[5]=h("div",{style:{width:"10px"}},null,-1)),c(s,{type:"default",onClick:j,icon:v(i(ee))},{default:p(()=>e[2]||(e[2]=[y("导入数据")])),_:1},8,["icon"]),e[6]||(e[6]=h("div",{style:{width:"10px"}},null,-1)),c(s,{type:"default",onClick:w,icon:v(i(te)),disabled:n.value.length===0},{default:p(()=>e[3]||(e[3]=[y("下发数据")])),_:1},8,["icon","disabled"]),c(s,{type:"default",onClick:x,icon:v(i(se)),disabled:n.value.length===0},{default:p(()=>e[4]||(e[4]=[y("同步数据")])),_:1},8,["icon","disabled"])]),bodyCell:p(({column:g,record:a})=>[g.dataIndex==="action"?(O(),me(i(q),{key:0,actions:[{label:"编辑",icon:"clarity:note-edit-line",onClick:I.bind(null,a),divider:!0},{label:"删除",icon:"ant-design:delete-outlined",color:"error",popConfirm:{title:"是否确认删除",confirm:R.bind(null,a),placement:"topRight"},ifShow:i(b)("AUTH_DATA_TASK:DELETE")},{label:"详情",icon:"ant-design:eye-outlined",onClick:$.bind(null,a),divider:!0},{label:"下发数据",icon:"ant-design:download-outlined",onClick:w.bind(null,a),divider:!0,disabled:a.state!==0},{label:"同步数据",icon:"ant-design:sync-outlined",onClick:x.bind(null,a),divider:!0,disabled:a.state!==0}]},null,8,["actions"])):pe("",!0)]),_:1},8,["onRegister"]),c(le,{onRegister:i(P),onSuccess:V},null,8,["onRegister"])])}}});const Ne=W(ge,[["__scopeId","data-v-20fcca15"]]);export{Ne as default};

View File

@ -1 +1 @@
import{B as g,u as v}from"./useTable-acfc2b97.js";import{T as C}from"./useForm-7410be87.js";import{S as w,r as T,m as B,s as S,_ as R}from"./index.js";import{u as k}from"./index-e0942325.js";import{R as D,c as y,s as I}from"./drawer-956554d6.js";import{d as $,l as A,a6 as a,Z as _,_ as E,$ as h,k as r,a5 as m,G as F,a4 as N,a8 as V}from"./vue-72a104e4.js";import{N as x}from"./antd-029ed741.js";import"./index-5157bbb9.js";import"./useWindowSizeFn-46f0db92.js";import"./onMountedOrActivated-ee461833.js";import"./sortable.esm-15c0a34e.js";import"./copyTextToClipboard-8577151f.js";import"./authorityApi-323b0ce5.js";const P=$({name:"UserPage",methods:{PlusOutlined:x,h:A},components:{SvgIcon:w,BasicTable:g,RoleDrawer:D,TableAction:C},setup(){const{createMessage:e}=B(),[o,{openDrawer:i}]=k(),[p,{reload:l}]=v({api:S,columns:y,formConfig:{labelWidth:0,schemas:I,showAdvancedButton:!1},useSearchForm:!0,showTableSetting:!1,bordered:!0,showIndexColumn:!1,canResize:!1,pagination:!1,actionColumn:{width:180,title:"操作",dataIndex:"action",fixed:void 0}});function f(){i(!0,{isUpdate:!1})}function c(n){i(!0,{record:n,isUpdate:!0})}function u(n){T(n.id).then(t=>{e.success("删除用户成功!"),l()},t=>{e.error(`删除用户失败:${t}`)})}function d(){l()}return{registerTable:p,registerDrawer:o,handleCreate:f,handleEdit:c,handleDelete:u,handleSuccess:d}}});const U={class:"header"};function z(e,o,i,p,l,f){const c=a("SvgIcon"),u=a("a-button"),d=a("TableAction"),n=a("BasicTable"),t=a("RoleDrawer");return _(),E("div",null,[h("div",U,[r(c,{size:"19",name:"list"}),o[0]||(o[0]=h("div",{class:"title"},"用户列表",-1))]),r(n,{onRegister:e.registerTable},{toolbar:m(()=>[r(u,{type:"primary",onClick:e.handleCreate,icon:e.h(e.PlusOutlined)},{default:m(()=>o[1]||(o[1]=[F("新增")])),_:1},8,["onClick","icon"])]),bodyCell:m(({column:b,record:s})=>[b.key==="action"?(_(),N(d,{key:0,actions:[{label:"编辑",icon:"clarity:note-edit-line",onClick:e.handleEdit.bind(null,s),divider:!0,disabled:s.username==="admin"},{label:"删除",icon:"ant-design:delete-outlined",color:"error",popConfirm:{title:"是否确认删除",confirm:e.handleDelete.bind(null,s),placement:"topRight"},disabled:s.username==="admin"}]},null,8,["actions"])):V("",!0)]),_:1},8,["onRegister"]),r(t,{onRegister:e.registerDrawer,onSuccess:e.handleSuccess},null,8,["onRegister","onSuccess"])])}const Y=R(P,[["render",z],["__scopeId","data-v-87c55e0c"]]);export{Y as default}; import{B as g,u as v}from"./useTable-acfc2b97.js";import{T as C}from"./useForm-7410be87.js";import{S as w,r as T,m as B,s as S,_ as R}from"./index.js";import{u as k}from"./index-e0942325.js";import{R as D,c as y,s as I}from"./drawer-b049ab2a.js";import{d as $,l as A,a6 as a,Z as _,_ as E,$ as h,k as r,a5 as m,G as F,a4 as N,a8 as V}from"./vue-72a104e4.js";import{N as x}from"./antd-029ed741.js";import"./index-5157bbb9.js";import"./useWindowSizeFn-46f0db92.js";import"./onMountedOrActivated-ee461833.js";import"./sortable.esm-15c0a34e.js";import"./copyTextToClipboard-8577151f.js";import"./authorityApi-323b0ce5.js";const P=$({name:"UserPage",methods:{PlusOutlined:x,h:A},components:{SvgIcon:w,BasicTable:g,RoleDrawer:D,TableAction:C},setup(){const{createMessage:e}=B(),[o,{openDrawer:i}]=k(),[p,{reload:l}]=v({api:S,columns:y,formConfig:{labelWidth:0,schemas:I,showAdvancedButton:!1},useSearchForm:!0,showTableSetting:!1,bordered:!0,showIndexColumn:!1,canResize:!1,pagination:!1,actionColumn:{width:180,title:"操作",dataIndex:"action",fixed:void 0}});function f(){i(!0,{isUpdate:!1})}function c(n){i(!0,{record:n,isUpdate:!0})}function u(n){T(n.id).then(t=>{e.success("删除用户成功!"),l()},t=>{e.error(`删除用户失败:${t}`)})}function d(){l()}return{registerTable:p,registerDrawer:o,handleCreate:f,handleEdit:c,handleDelete:u,handleSuccess:d}}});const U={class:"header"};function z(e,o,i,p,l,f){const c=a("SvgIcon"),u=a("a-button"),d=a("TableAction"),n=a("BasicTable"),t=a("RoleDrawer");return _(),E("div",null,[h("div",U,[r(c,{size:"19",name:"list"}),o[0]||(o[0]=h("div",{class:"title"},"用户列表",-1))]),r(n,{onRegister:e.registerTable},{toolbar:m(()=>[r(u,{type:"primary",onClick:e.handleCreate,icon:e.h(e.PlusOutlined)},{default:m(()=>o[1]||(o[1]=[F("新增")])),_:1},8,["onClick","icon"])]),bodyCell:m(({column:b,record:s})=>[b.key==="action"?(_(),N(d,{key:0,actions:[{label:"编辑",icon:"clarity:note-edit-line",onClick:e.handleEdit.bind(null,s),divider:!0,disabled:s.username==="admin"},{label:"删除",icon:"ant-design:delete-outlined",color:"error",popConfirm:{title:"是否确认删除",confirm:e.handleDelete.bind(null,s),placement:"topRight"},disabled:s.username==="admin"}]},null,8,["actions"])):V("",!0)]),_:1},8,["onRegister"]),r(t,{onRegister:e.registerDrawer,onSuccess:e.handleSuccess},null,8,["onRegister","onSuccess"])])}const Y=R(P,[["render",z],["__scopeId","data-v-87c55e0c"]]);export{Y as default};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,15 +19,12 @@ public class DeviceClientService
ConnectAllDevices(); ConnectAllDevices();
Log.Information("DeviceClientService Initialize Done."); Log.Information("DeviceClientService Initialize Done.");
} }
private static DeviceClientService? _instance; private static DeviceClientService? _instance;
public static DeviceClientService Instance() public static DeviceClientService Instance()
{ {
if (_instance == null) return _instance ??= new DeviceClientService();
{
_instance = new DeviceClientService();
}
return _instance;
} }
/// <summary> /// <summary>
@ -39,10 +36,7 @@ public class DeviceClientService
var devices = deviceService.ListAll().Result!; var devices = deviceService.ListAll().Result!;
if (devices.Any()) if (devices.Any())
{ {
devices.ForEach(device => devices.ForEach(device => { ConnectDevice(device); });
{
ConnectDevice(device);
});
} }
} }
@ -56,7 +50,7 @@ public class DeviceClientService
client.DisConnectAsync(); client.DisConnectAsync();
} }
} }
/// <summary> /// <summary>
/// 根据设备id获取连接客户端 /// 根据设备id获取连接客户端
/// </summary> /// </summary>
@ -67,7 +61,7 @@ public class DeviceClientService
_deviceClients.TryGetValue(deviceId, out var deviceClient); _deviceClients.TryGetValue(deviceId, out var deviceClient);
return deviceClient; return deviceClient;
} }
/// <summary> /// <summary>
/// 刷新连接客户端,设备信息更新后调用 /// 刷新连接客户端,设备信息更新后调用
/// </summary> /// </summary>
@ -80,7 +74,7 @@ public class DeviceClientService
var eventService = Locator.Current.GetService<DetectDeviceService>()!; var eventService = Locator.Current.GetService<DetectDeviceService>()!;
return ConnectDevice(eventService.ListById(deviceId).Result!); return ConnectDevice(eventService.ListById(deviceId).Result!);
} }
/// <summary> /// <summary>
/// 刷新连接客户端,设备信息更新后调用 /// 刷新连接客户端,设备信息更新后调用
/// </summary> /// </summary>
@ -92,7 +86,7 @@ public class DeviceClientService
deviceClient?.DisConnectAsync(); deviceClient?.DisConnectAsync();
return ConnectDevice(device); return ConnectDevice(device);
} }
/// <summary> /// <summary>
/// 断开连接并释放 /// 断开连接并释放
/// </summary> /// </summary>
@ -104,7 +98,7 @@ public class DeviceClientService
deviceClient?.DisConnectAsync(); deviceClient?.DisConnectAsync();
_deviceClients.Remove(deviceId); _deviceClients.Remove(deviceId);
} }
/// <summary> /// <summary>
/// 连接云台设备 /// 连接云台设备
/// </summary> /// </summary>
@ -117,6 +111,7 @@ public class DeviceClientService
Log.Warning("设备【{Name}】没有配置ip不连接", device.Name); Log.Warning("设备【{Name}】没有配置ip不连接", device.Name);
return null; return null;
} }
_deviceClients.TryGetValue(device.Id!.Value, out var deviceClient); _deviceClients.TryGetValue(device.Id!.Value, out var deviceClient);
if (deviceClient == null) if (deviceClient == null)
{ {
@ -131,23 +126,24 @@ public class DeviceClientService
deviceClient.ConnectAsync(); deviceClient.ConnectAsync();
} }
} }
deviceClient.DeviceEvent += DeviceClientOnDeviceEvent; deviceClient.DeviceEvent += DeviceClientOnDeviceEvent;
return deviceClient; return deviceClient;
} }
private void DeviceClientOnDeviceEvent(object? sender, DeviceEvent e) private void DeviceClientOnDeviceEvent(object? sender, DeviceEvent e)
{ {
Log.Information("DeviceEvent-[{Name}]-{Address}:{@Result}", e.Name, (sender as DeviceClientSocket)!.Address, e.Result); Log.Information("DeviceEvent-[{Name}]-{Address}:{@Result}", e.Name, (sender as DeviceClientSocket)!.Address,
if (e.Name == detect.device.DeviceEvent.EventDeviceConnected) e.Result);
if (e.Name == DeviceEvent.EventDeviceConnected)
{ {
// var sysInfo = GetDeviceInfo(1).GetAwaiter().GetResult(); // var sysInfo = GetDeviceInfo(1).GetAwaiter().GetResult();
// Log.Information("device info: {@Info}", sysInfo); // Log.Information("device info: {@Info}", sysInfo);
// test // test
// AssignTasks(new long[] { 1 }).GetAwaiter(); // AssignTasks(new long[] { 1 }).GetAwaiter();
} }
// var deviceService = Locator.Current.GetService<VapDeviceService>()!; // var deviceService = Locator.Current.GetService<VapDeviceService>()!;
// var eventService = Locator.Current.GetService<VapEventService>()!; // var eventService = Locator.Current.GetService<VapEventService>()!;
// var constantService = Locator.Current.GetService<VapConstantService>()!; // var constantService = Locator.Current.GetService<VapConstantService>()!;
@ -193,6 +189,7 @@ public class DeviceClientService
} }
#region #region
/// <summary> /// <summary>
/// 查询设备信息 /// 查询设备信息
/// </summary> /// </summary>
@ -214,9 +211,10 @@ public class DeviceClientService
{ {
throw new Exception(resp.Message); throw new Exception(resp.Message);
} }
return resp.Result; return resp.Result;
} }
public async Task<Dictionary<string, object>?> AssignTasks(long[] taskIds) public async Task<Dictionary<string, object>?> AssignTasks(long[] taskIds)
{ {
var taskService = Locator.Current.GetService<DetectTaskService>()!; var taskService = Locator.Current.GetService<DetectTaskService>()!;
@ -233,15 +231,18 @@ public class DeviceClientService
{ {
throw new Exception("未找到设备!"); throw new Exception("未找到设备!");
} }
var deviceClient = GetDeviceClient(device.Id!.Value); var deviceClient = GetDeviceClient(device.Id!.Value);
if (deviceClient == null) if (deviceClient == null)
{ {
throw new Exception("设备未连接!"); throw new Exception("设备未连接!");
} }
if (!deviceClient.Connected()) if (!deviceClient.Connected())
{ {
throw new Exception("设备连接失败!"); throw new Exception("设备连接失败!");
} }
var req = DeviceClientRequestBuilder.Create().WithType("service").WithComponent("dat_task") var req = DeviceClientRequestBuilder.Create().WithType("service").WithComponent("dat_task")
.WithMethod("add_server_tasks").WithParam("tasks", taskList); .WithMethod("add_server_tasks").WithParam("tasks", taskList);
var resp = await deviceClient.RequestAction<Dictionary<string, object>>(req); var resp = await deviceClient.RequestAction<Dictionary<string, object>>(req);
@ -249,6 +250,7 @@ public class DeviceClientService
{ {
throw new Exception(resp.Message); throw new Exception(resp.Message);
} }
return resp.Result; return resp.Result;
} }
@ -261,21 +263,25 @@ public class DeviceClientService
{ {
throw new Exception("未选择需要同步的任务!"); throw new Exception("未选择需要同步的任务!");
} }
var deviceSn = taskList[0].DeviceSn!; var deviceSn = taskList[0].DeviceSn!;
var device = deviceService.ListBySn(deviceSn).Result!; var device = deviceService.ListBySn(deviceSn).Result!;
if (device == null) if (device == null)
{ {
throw new Exception("未找到设备!"); throw new Exception("未找到设备!");
} }
var deviceClient = GetDeviceClient(device.Id!.Value); var deviceClient = GetDeviceClient(device.Id!.Value);
if (deviceClient == null) if (deviceClient == null)
{ {
throw new Exception("设备未连接!"); throw new Exception("设备未连接!");
} }
if (!deviceClient.Connected()) if (!deviceClient.Connected())
{ {
throw new Exception("设备连接失败!"); throw new Exception("设备连接失败!");
} }
foreach (var task in taskList) foreach (var task in taskList)
{ {
var req = DeviceClientRequestBuilder.Create().WithType("service").WithComponent("dat_task") var req = DeviceClientRequestBuilder.Create().WithType("service").WithComponent("dat_task")
@ -286,13 +292,36 @@ public class DeviceClientService
{ {
throw new Exception(resp.Message); throw new Exception(resp.Message);
} }
if (resp.Result is null) continue; if (resp.Result is null) continue;
task.ResultJson = (string?)resp.Result!["result_json"]; task.ResultJson = (string?)resp.Result!["result_json"];
task.StartTime = Convert.ToDateTime(resp.Result!["start_time"]) == DateTime.MinValue ? null : Convert.ToDateTime(resp.Result!["start_time"]); task.StartTime = Convert.ToDateTime(resp.Result!["start_time"]) == DateTime.MinValue
task.EndTime = Convert.ToDateTime(resp.Result!["end_time"]) == DateTime.MinValue ? null : Convert.ToDateTime(resp.Result!["end_time"]); ? null
: Convert.ToDateTime(resp.Result!["start_time"]);
task.EndTime = Convert.ToDateTime(resp.Result!["end_time"]) == DateTime.MinValue
? null
: Convert.ToDateTime(resp.Result!["end_time"]);
task.State = Convert.ToInt32((long)resp.Result!["state"]); task.State = Convert.ToInt32((long)resp.Result!["state"]);
Locator.Current.GetService<DetectTaskService>()!.UpdateData(task); Locator.Current.GetService<DetectTaskService>()!.UpdateData(task);
} }
} }
public Task<Dictionary<string, bool>?> GetDeviceConnected()
{
var r = new Dictionary<string, bool>();
var deviceService = Locator.Current.GetService<DetectDeviceService>()!;
var devices = deviceService.ListAll().Result!;
if (devices.Count != 0)
{
devices.ForEach(device =>
{
_deviceClients.TryGetValue(device.Id!.Value, out var deviceClient);
if (device.DeviceSn != null) r.Add(device.DeviceSn, deviceClient != null && deviceClient.Connected());
});
}
return Task.FromResult(r.Count == 0 ? null : r);
}
#endregion #endregion
} }